Documentation ¶
Overview ¶
Package fsm implements the state transition logic in the Starlight spec.
Index ¶
- Variables
- func Close(u *Updater) error
- func MatchesFundingTx(c *Channel, tx *worizon.Tx) bool
- type AccountID
- func (id *AccountID) Address() string
- func (id *AccountID) Equals(other AccountID) bool
- func (id *AccountID) MarshalBinary() ([]byte, error)
- func (id *AccountID) MarshalText() ([]byte, error)
- func (id *AccountID) SetAddress(address string) error
- func (id *AccountID) UnmarshalBinary(data []byte) error
- func (id *AccountID) UnmarshalText(data []byte) error
- func (id *AccountID) XDR() *xdr.AccountId
- type Balance
- type Channel
- type ChannelAcceptMsg
- type ChannelProposeMsg
- type CloseMsg
- type Command
- type CommandName
- type Message
- type Outputter
- type PaymentAcceptMsg
- type PaymentCompleteMsg
- type PaymentProposeMsg
- type Role
- type State
- type Updater
- type WalletAcct
Constants ¶
This section is empty.
Variables ¶
var ( // Command errors ErrInsufficientFunds = errors.New("insufficient funds") // Message errors ErrChannelExists = errors.New("received channel propose message for channel that already exists") ErrInvalidVersion = errors.New("invalid version number") ErrUnusedSettleWithGuestSig = errors.New("unused settle with guest sig") ErrUnexpectedState = errors.New("unexpected state") )
Defines the FSM package errors
Functions ¶
Types ¶
type AccountID ¶
AccountID is a Stellar account ID.
func (*AccountID) MarshalBinary ¶
MarshalBinary satisfies interface BinaryMarshaler.
func (*AccountID) MarshalText ¶
MarshalText implements the TextMarshaler interface for the accountID type, allowing us to serialize the account IDs to their string addresses, rather than the default xdr Uint256 slice.
func (*AccountID) SetAddress ¶
SetAddress sets *id to the account ID corresponding to the given Stellar address.
func (*AccountID) UnmarshalBinary ¶
UnmarshalBinary satisfies interface BinaryUnmarshaler.
func (*AccountID) UnmarshalText ¶
UnmarshalText implements the TextMarshaler interface, taking our custom-serialized JSON for Channel objects and converting the string addresses back into xdr.AccountId types.
type Channel ¶
type Channel struct { ID string Role Role State, PrevState State CounterpartyAddress string // either the Guest's federation address, or the Host's public key address RemoteURL string Passphrase string Cursor string // where we are in watching escrowacct txs on the ledger BaseSequenceNumber xdr.SequenceNumber RoundNumber uint64 CounterpartyMsgIndex uint64 LastMsgIndex uint64 MaxRoundDuration time.Duration FinalityDelay time.Duration ChannelFeerate xlm.Amount HostFeerate xlm.Amount FundingTime time.Time FundingTimedOut bool FundingTxSeqnum xdr.SequenceNumber HostAmount xlm.Amount GuestAmount xlm.Amount TopUpAmount xlm.Amount PendingAmountSent xlm.Amount PendingAmountReceived xlm.Amount PaymentTime time.Time PendingPaymentTime time.Time HostAcct AccountID GuestAcct AccountID EscrowAcct AccountID HostRatchetAcct AccountID GuestRatchetAcct AccountID KeyIndex uint32 HostRatchetAcctSeqNum xdr.SequenceNumber GuestRatchetAcctSeqNum xdr.SequenceNumber // Ratchet transaction from the last completed round, including the // counterparty's signature. CurrentRatchetTx xdr.TransactionEnvelope // Latest settlement txes for which the counterparty has a valid // ratchet transaction and has provided their signature. // TODO(debnil): Convert SettleWithHostTx to a pointer, as it is // only set in some channel states, both here and below. CounterpartyLatestSettleWithGuestTx *xdr.TransactionEnvelope CounterpartyLatestSettleWithHostTx xdr.TransactionEnvelope // Settlement transaction from the latest completed round, including // the counterparty's signature. This only differs from // CounterPartyLatestSettlementTxes when the channel has transitioned // into the PaymentAccepted state, but has yet to receive the // PaymentCompleteMsg from the counterparty. CurrentSettleWithGuestTx *xdr.TransactionEnvelope CurrentSettleWithHostTx xdr.TransactionEnvelope // In a cooperative close, the counterparty's signature // is included in the Channel state so a Transaction Envelope // containing the transaction signed by each party can be submitted. CounterpartyCoopCloseSig xdr.DecoratedSignature }
Channel represents the point-in-time state of a single Starlight channel. It is pure data, and designed to be serializable to and from JSON.
func (*Channel) MarshalJSON ¶
MarshalJSON implements json.Marshaler. Required for genbolt.
func (*Channel) SetupAndFundingReserveAmount ¶
SetupAndFundingReserveAmount reports the amount in lumens needed to set up and fund the channel.
func (*Channel) TimerTime ¶
TimerTime returns the time at which a timer for the current state should fire, or nil if there is no timer associated with this state.
func (*Channel) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. Required for genbolt.
type ChannelAcceptMsg ¶
type ChannelAcceptMsg struct { GuestRatchetRound1Sig xdr.DecoratedSignature GuestSettleOnlyWithHostSig xdr.DecoratedSignature }
ChannelAcceptMsg contains Signatures for Guest accepting a proposal.
type ChannelProposeMsg ¶
type ChannelProposeMsg struct { HostAcct AccountID GuestAcct AccountID HostRatchetAcct AccountID GuestRatchetAcct AccountID MaxRoundDuration time.Duration FinalityDelay time.Duration BaseSequenceNumber xdr.SequenceNumber HostAmount xlm.Amount Feerate xlm.Amount FundingTime time.Time }
ChannelProposeMsg defines a JSON schema for proposal over a Channel.
type CloseMsg ¶
type CloseMsg struct {
CooperativeCloseSig xdr.DecoratedSignature
}
CloseMsg is the protocol message proposing a cooperative closure of the channel.
type Command ¶
type Command struct { Name CommandName Amount xlm.Amount // for TopUp, ChannelPay, or Pay Time time.Time Recipient string // for Pay AssetCode string // for AddAsset, RemoveAsset Issuer string // for AddAsset, RemoveAsset }
Command contains a command name and its required arguments.
type CommandName ¶
type CommandName string
CommandName is the type of a user-command constant.
const ( CreateChannel CommandName = "CreateChannel" CleanUp CommandName = "CleanUp" CloseChannel CommandName = "CloseChannel" TopUp CommandName = "TopUp" ChannelPay CommandName = "ChannelPay" ForceClose CommandName = "ForceClose" Pay CommandName = "Pay" AddAsset CommandName = "AddAsset" RemoveAsset CommandName = "RemoveAsset" )
User commands.
type Message ¶
type Message struct { ChannelID string MsgNum uint64 Version int ChannelProposeMsg *ChannelProposeMsg `json:",omitempty"` ChannelAcceptMsg *ChannelAcceptMsg `json:",omitempty"` PaymentProposeMsg *PaymentProposeMsg `json:",omitempty"` PaymentAcceptMsg *PaymentAcceptMsg `json:",omitempty"` PaymentCompleteMsg *PaymentCompleteMsg `json:",omitempty"` CloseMsg *CloseMsg `json:",omitempty"` // Signature is a signature over the JSON representation of the message // (minus the Signature field itself), made with the sender's key. Signature []byte `json:",omitempty"` }
Message defines a JSON schema for Starlight messages.
func (*Message) MarshalJSON ¶
MarshalJSON implements json.Marshaler. Required for genbolt.
func (*Message) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. Required for genbolt.
type Outputter ¶
type Outputter interface { // OutputMsg sends a message to the remote endpoint. OutputMsg(*Message) // OutputTx publishes a transaction to the ledger. OutputTx(xdr.TransactionEnvelope) }
Outputter accumulates side effects to be emitted to the outside world. This consists of zero or more messages to send to the peer, transactions to publish to the Stellar network, and timers to schedule.
type PaymentAcceptMsg ¶
type PaymentAcceptMsg struct { RoundNumber uint64 RecipientRatchetSig xdr.DecoratedSignature RecipientSettleWithGuestSig *xdr.DecoratedSignature RecipientSettleWithHostSig xdr.DecoratedSignature }
PaymentAcceptMsg is the protocol message accepting a proposed channel payment.
type PaymentCompleteMsg ¶
type PaymentCompleteMsg struct { RoundNumber uint64 SenderRatchetSig xdr.DecoratedSignature }
PaymentCompleteMsg is the protocol message acknowledging a PaymentAcceptMsg.
type PaymentProposeMsg ¶
type PaymentProposeMsg struct { RoundNumber uint64 PaymentTime time.Time PaymentAmount xlm.Amount SenderSettleWithGuestSig xdr.DecoratedSignature SenderSettleWithHostSig xdr.DecoratedSignature }
PaymentProposeMsg is the protocol message proposing a channel payment.
type State ¶
type State string
State is the type of a channel-state constant.
const ( // Start indicates a channel that does not (yet) exist. // // Note that no state transition enters the state Start, // so if a Channel has this state after running an Update // function in this package, the channel is invalid. Start State = "" Closed State = "Closed" AwaitingCleanup State = "AwaitingCleanup" AwaitingClose State = "AwaitingClose" AwaitingFunding State = "AwaitingFunding" AwaitingPaymentMerge State = "AwaitingPaymentMerge" AwaitingRatchet State = "AwaitingRatchet" AwaitingSettlement State = "AwaitingSettlement" AwaitingSettlementMintime State = "AwaitingSettlementMintime" ChannelProposed State = "ChannelProposed" Open State = "Open" PaymentAccepted State = "PaymentAccepted" PaymentProposed State = "PaymentProposed" SettingUp State = "SettingUp" )
Channel-state constants.
type Updater ¶
type Updater struct { C *Channel O Outputter H *WalletAcct Seed []byte LedgerTime time.Time Passphrase string // contains filtered or unexported fields }
Updater contains the state necessary to effect a state transition in a channel.
func (*Updater) Msg ¶
Msg causes the updater to update its channel in response to a protocol message received from a peer Agent.
type WalletAcct ¶
type WalletAcct struct { NativeBalance xlm.Amount Reserve xlm.Amount Seqnum xdr.SequenceNumber Address string // Stellar federation address Cursor string Balances map[string]Balance }
WalletAcct represents the point-in-time state of the channel's wallet account, passed to the FSM for state transitions that access or update host-level data.
func (*WalletAcct) MarshalJSON ¶
func (w *WalletAcct) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler. Required for genbolt.
func (*WalletAcct) UnmarshalJSON ¶
func (w *WalletAcct) UnmarshalJSON(b []byte) error
UnmarshalJSON implements json.Unmarshaler. Required for genbolt.