protofsm: add String() method to ProtocolState

This commit is contained in:
Olaoluwa Osuntokun committed 2025-03-18 11:44:20 -05:00
1 parent 01382f4c2a
commit 1d2c22d140
3 files changed
+65 -3

No files matched your search

+53
View File
@@ -361,6 +361,9 @@ type ProtocolState interface {
// ProcessEvent takes a protocol event, and implements a state
// transition for the state.
ProcessEvent(ProtocolEvent, *Environment) (*CloseStateTransition, error)
// String returns the name of the state.
String() string
}
// AsymmetricPeerState is an extension of the normal ProtocolState interface
@@ -401,6 +404,11 @@ type ProtocolStates interface {
type ChannelActive struct {
}
// String returns the name of the state for ChannelActive.
func (c *ChannelActive) String() string {
return "ChannelActive"
}
// IsTerminal returns true if the target state is a terminal state.
func (c *ChannelActive) IsTerminal() bool {
return false
@@ -443,6 +451,11 @@ type ShutdownPending struct {
IdealFeeRate fn.Option[chainfee.SatPerVByte]
}
// String returns the name of the state for ShutdownPending.
func (s *ShutdownPending) String() string {
return "ShutdownPending"
}
// IsTerminal returns true if the target state is a terminal state.
func (s *ShutdownPending) IsTerminal() bool {
return false
@@ -478,6 +491,11 @@ type ChannelFlushing struct {
IdealFeeRate fn.Option[chainfee.SatPerVByte]
}
// String returns the name of the state for ChannelFlushing.
func (c *ChannelFlushing) String() string {
return "ChannelFlushing"
}
// protocolStateSealed indicates that this struct is a ProtocolEvent instance.
func (c *ChannelFlushing) protocolStateSealed() {}
@@ -507,6 +525,15 @@ type ClosingNegotiation struct {
PeerState lntypes.Dual[AsymmetricPeerState]
}
// String returns the name of the state for ClosingNegotiation.
func (c *ClosingNegotiation) String() string {
localState := c.PeerState.GetForParty(lntypes.Local)
remoteState := c.PeerState.GetForParty(lntypes.Remote)
return fmt.Sprintf("ClosingNegotiation(local=%v, remote=%v)",
localState, remoteState)
}
// IsTerminal returns true if the target state is a terminal state.
func (c *ClosingNegotiation) IsTerminal() bool {
return false
@@ -594,6 +621,12 @@ type LocalCloseStart struct {
CloseChannelTerms
}
// String returns the name of the state for LocalCloseStart, including proposed
// fee details.
func (l *LocalCloseStart) String() string {
return "LocalCloseStart"
}
// ShouldRouteTo returns true if the target state should process the target
// event.
func (l *LocalCloseStart) ShouldRouteTo(event ProtocolEvent) bool {
@@ -634,6 +667,11 @@ type LocalOfferSent struct {
LocalSig lnwire.Sig
}
// String returns the name of the state for LocalOfferSent, including proposed.
func (l *LocalOfferSent) String() string {
return fmt.Sprintf("LocalOfferSent(proposed_fee=%v)", l.ProposedFee)
}
// ShouldRouteTo returns true if the target state should process the target
// event.
func (l *LocalOfferSent) ShouldRouteTo(event ProtocolEvent) bool {
@@ -670,6 +708,11 @@ type ClosePending struct {
CloseTx *wire.MsgTx
}
// String returns the name of the state for ClosePending.
func (c *ClosePending) String() string {
return fmt.Sprintf("ClosePending(txid=%v)", c.CloseTx.TxHash())
}
// ShouldRouteTo returns true if the target state should process the target
// event.
func (c *ClosePending) ShouldRouteTo(event ProtocolEvent) bool {
@@ -696,6 +739,11 @@ type CloseFin struct {
ConfirmedTx *wire.MsgTx
}
// String returns the name of the state for CloseFin.
func (c *CloseFin) String() string {
return "CloseFin"
}
// protocolStateSealed indicates that this struct is a ProtocolEvent instance.
func (c *CloseFin) protocolStateSealed() {}
@@ -714,6 +762,11 @@ type RemoteCloseStart struct {
CloseChannelTerms
}
// String returns the name of the state for RemoteCloseStart.
func (r *RemoteCloseStart) String() string {
return "RemoteCloseStart"
}
// ShouldRouteTo returns true if the target state should process the target
// event.
func (l *RemoteCloseStart) ShouldRouteTo(event ProtocolEvent) bool {