Documentation ¶
Index ¶
- Constants
- Variables
- func UseLogger(logger btclog.Logger)
- type AddressManager
- type Deposit
- func (d *Deposit) GetState() fsm.StateType
- func (d *Deposit) IsExpired(currentHeight, expiry uint32) bool
- func (d *Deposit) IsInFinalState() bool
- func (d *Deposit) IsInState(state fsm.StateType) bool
- func (d *Deposit) IsInStateNoLock(state fsm.StateType) bool
- func (d *Deposit) SetState(state fsm.StateType)
- func (d *Deposit) SetStateNoLock(state fsm.StateType)
- type FSM
- func (f *FSM) Debugf(format string, args ...interface{})
- func (f *FSM) DepositStatesV0() fsm.States
- func (f *FSM) Errorf(format string, args ...interface{})
- func (f *FSM) FinalizeDepositAction(ctx context.Context, _ fsm.EventContext) fsm.EventType
- func (f *FSM) Infof(format string, args ...interface{})
- func (f *FSM) PublishDepositExpirySweepAction(ctx context.Context, _ fsm.EventContext) fsm.EventType
- func (f *FSM) SignDescriptor(ctx context.Context) (*lndclient.SignDescriptor, error)
- func (f *FSM) SweptExpiredDepositAction(ctx context.Context, _ fsm.EventContext) fsm.EventType
- func (f *FSM) WaitForExpirySweepAction(ctx context.Context, _ fsm.EventContext) fsm.EventType
- type ID
- type Manager
- func (m *Manager) AllOutpointsActiveDeposits(outpoints []wire.OutPoint, targetState fsm.StateType) ([]*Deposit, bool)
- func (m *Manager) AllStringOutpointsActiveDeposits(outpoints []string, stateFilter fsm.StateType) ([]*Deposit, bool)
- func (m *Manager) GetActiveDepositsInState(stateFilter fsm.StateType) ([]*Deposit, error)
- func (m *Manager) GetAllDeposits(ctx context.Context) ([]*Deposit, error)
- func (m *Manager) Run(ctx context.Context, currentHeight uint32) error
- func (m *Manager) TransitionDeposits(ctx context.Context, deposits []*Deposit, event fsm.EventType, ...) error
- func (m *Manager) UpdateDeposit(ctx context.Context, d *Deposit) error
- func (m *Manager) WaitInitComplete()
- type ManagerConfig
- type SqlStore
- func (s *SqlStore) AllDeposits(ctx context.Context) ([]*Deposit, error)
- func (s *SqlStore) CreateDeposit(ctx context.Context, deposit *Deposit) error
- func (s *SqlStore) GetDeposit(ctx context.Context, id ID) (*Deposit, error)
- func (s *SqlStore) UpdateDeposit(ctx context.Context, deposit *Deposit) error
- type Store
Constants ¶
const ( // PollInterval is the interval in which we poll for new deposits to our // static address. PollInterval = 10 * time.Second // MinConfs is the minimum number of confirmations we require for a // deposit to be considered available for loop-ins, coop-spends and // timeouts. MinConfs = 6 // MaxConfs is unset since we don't require a max number of // confirmations for deposits. MaxConfs = 0 // DefaultTransitionTimeout is the default timeout for transitions in // the deposit state machine. DefaultTransitionTimeout = 5 * time.Second )
const (
DefaultConfTarget = 3
)
const (
DefaultObserverSize = 20
)
const (
IdLength = 32
)
const Subsystem = "SADDR"
Subsystem defines the sub system name of this package.
Variables ¶
var ( // Deposited signals that funds at a static address have reached the // confirmation height. Deposited = fsm.StateType("Deposited") // Withdrawing signals that the withdrawal transaction has been // broadcast, awaiting sufficient confirmations. Withdrawing = fsm.StateType("Withdrawing") // Withdrawn signals that the withdrawal transaction has been confirmed. Withdrawn = fsm.StateType("Withdrawn") // LoopingIn signals that the deposit is locked for a loop in swap. LoopingIn = fsm.StateType("LoopingIn") // LoopedIn signals that the loop in swap has been successfully // completed. It implies that we signed the sweepless sweep tx for the // server. LoopedIn = fsm.StateType("LoopedIn") // SweepHtlcTimeout signals that the htlc timeout path is in the // process of being swept. SweepHtlcTimeout = fsm.StateType("SweepHtlcTimeout") // HtlcTimeoutSwept signals that the htlc timeout path has been swept. HtlcTimeoutSwept = fsm.StateType("HtlcTimeoutSwept") // PublishExpirySweep signals that the deposit has expired, and we are // in the process of publishing the expiry sweep transaction. PublishExpirySweep = fsm.StateType("PublishExpirySweep") // WaitForExpirySweep signals that the expiry sweep transaction has been // published, and we are waiting for it to be confirmed. WaitForExpirySweep = fsm.StateType("WaitForExpirySweep") // Expired signals that the deposit has expired and the expiry sweep // transaction has been confirmed sufficiently. Expired = fsm.StateType("Expired") )
States.
var ( // OnStart is sent to the fsm once the deposit outpoint has been // sufficiently confirmed. It transitions the fsm into the Deposited // state from where we can trigger a withdrawal, a loopin or an expiry. OnStart = fsm.EventType("OnStart") // OnWithdrawInitiated is sent to the fsm when a withdrawal has been // initiated. OnWithdrawInitiated = fsm.EventType("OnWithdrawInitiated") // OnWithdrawn is sent to the fsm when a withdrawal has been confirmed. OnWithdrawn = fsm.EventType("OnWithdrawn") // OnLoopInInitiated is sent to the fsm when a loop in has been // initiated. OnLoopInInitiated = fsm.EventType("OnLoopInInitiated") // OnSweepingHtlcTimeout is sent to the fsm when the htlc timeout path // is being swept. This indicates that the server didn't pay the swap // invoice, but the htlc tx was published, from we which we need to // sweep the htlc timeout path. OnSweepingHtlcTimeout = fsm.EventType("OnSweepingHtlcTimeout") // OnHtlcTimeoutSwept is sent to the fsm when the htlc timeout path has // been swept. OnHtlcTimeoutSwept = fsm.EventType("OnHtlcTimeoutSwept") // OnLoopedIn is sent to the fsm when the user intents to use the // deposit for a loop in swap. OnLoopedIn = fsm.EventType("OnLoopedIn") // OnExpiry is sent to the fsm when the deposit has expired. OnExpiry = fsm.EventType("OnExpiry") // OnExpiryPublished is sent to the fsm when the expiry sweep tx has // been published. OnExpiryPublished = fsm.EventType("OnExpiryPublished") // OnExpirySwept is sent to the fsm when the expiry sweep tx has been // confirmed. OnExpirySwept = fsm.EventType("OnExpirySwept") // OnRecover is sent to the fsm when it should recover from client // restart. OnRecover = fsm.EventType("OnRecover") )
Events.
var (
ErrProtocolVersionNotSupported = errors.New("protocol version not " +
"supported")
)
Functions ¶
Types ¶
type AddressManager ¶
type AddressManager interface { // GetStaticAddressParameters returns the static address parameters. GetStaticAddressParameters(ctx context.Context) (*address.Parameters, error) // GetStaticAddress returns the deposit address for the given // client and server public keys. GetStaticAddress(ctx context.Context) (*script.StaticAddress, error) // ListUnspent returns a list of utxos at the static address. ListUnspent(ctx context.Context, minConfs, maxConfs int32) ([]*lnwallet.Utxo, error) // GetTaprootAddress returns a taproot address. GetTaprootAddress(clientPubkey, serverPubkey *btcec.PublicKey, expiry int64) (*btcutil.AddressTaproot, error) }
AddressManager handles fetching of address parameters.
type Deposit ¶
type Deposit struct { // ID is the unique identifier of the deposit. ID ID // Outpoint of the deposit. wire.OutPoint // Value is the amount of the deposit. Value btcutil.Amount // ConfirmationHeight is the absolute height at which the deposit was // first confirmed. ConfirmationHeight int64 // TimeOutSweepPkScript is the pk script that is used to sweep the // deposit to after it is expired. TimeOutSweepPkScript []byte // ExpirySweepTxid is the transaction id of the expiry sweep. ExpirySweepTxid chainhash.Hash // FinalizedWithdrawalTx is the coop signed withdrawal transaction. It // is republished on new block arrivals and on client restarts. FinalizedWithdrawalTx *wire.MsgTx sync.Mutex // contains filtered or unexported fields }
Deposit bundles an utxo at a static address together with manager-relevant data.
func (*Deposit) IsInFinalState ¶
IsInFinalState returns true if the deposit is final.
func (*Deposit) SetStateNoLock ¶
type FSM ¶
type FSM struct { *fsm.StateMachine // contains filtered or unexported fields }
FSM is the state machine that handles the instant out.
func NewFSM ¶
func NewFSM(ctx context.Context, deposit *Deposit, cfg *ManagerConfig, finalizedDepositChan chan wire.OutPoint, recoverStateMachine bool) (*FSM, error)
NewFSM creates a new state machine that can action on all static address feature requests.
func (*FSM) DepositStatesV0 ¶
DepositStatesV0 returns the states a deposit can be in.
func (*FSM) FinalizeDepositAction ¶
FinalizeDepositAction is the final action after a withdrawal. It signals to the manager that the deposit has been swept and the FSM can be removed.
func (*FSM) PublishDepositExpirySweepAction ¶
func (f *FSM) PublishDepositExpirySweepAction(ctx context.Context, _ fsm.EventContext) fsm.EventType
PublishDepositExpirySweepAction creates and publishes the timeout transaction that spends the deposit from the static address timeout leaf to the predefined timeout sweep pkscript.
func (*FSM) SignDescriptor ¶
SignDescriptor returns the sign descriptor for the static address output.
func (*FSM) SweptExpiredDepositAction ¶
SweptExpiredDepositAction is the final action of the FSM. It signals to the manager that the deposit has been swept and the FSM can be removed. It also ends the state machine main loop by cancelling its context.
func (*FSM) WaitForExpirySweepAction ¶
WaitForExpirySweepAction waits for a sufficient number of confirmations before a timeout sweep is considered successful.
type ID ¶
ID is a unique identifier for a deposit.
func GetRandomDepositID ¶
GetRandomDepositID generates a random deposit ID.
func (*ID) FromByteSlice ¶
FromByteSlice creates a deposit id from a byte slice.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages the address state machines.
func NewManager ¶
func NewManager(cfg *ManagerConfig) *Manager
NewManager creates a new deposit manager.
func (*Manager) AllOutpointsActiveDeposits ¶
func (m *Manager) AllOutpointsActiveDeposits(outpoints []wire.OutPoint, targetState fsm.StateType) ([]*Deposit, bool)
AllOutpointsActiveDeposits checks if all deposits referenced by the outpoints are in our in-mem active deposits map and in the specified state. If fsm.EmptyState is set as targetState all deposits are returned regardless of their state. Each existent deposit is locked during the check.
func (*Manager) AllStringOutpointsActiveDeposits ¶
func (m *Manager) AllStringOutpointsActiveDeposits(outpoints []string, stateFilter fsm.StateType) ([]*Deposit, bool)
AllStringOutpointsActiveDeposits converts outpoint strings of format txid:idx to wire outpoints and checks if all deposits referenced by the outpoints are active and in the specified state. If fsm.EmptyState is referenced as stateFilter all deposits are returned regardless of their state.
func (*Manager) GetActiveDepositsInState ¶
GetActiveDepositsInState returns all active deposits. This function is called on a client restart before the manager is fully initialized, hence we don't have to lock the deposits.
func (*Manager) GetAllDeposits ¶
GetAllDeposits returns all active deposits.
func (*Manager) TransitionDeposits ¶
func (m *Manager) TransitionDeposits(ctx context.Context, deposits []*Deposit, event fsm.EventType, expectedFinalState fsm.StateType) error
TransitionDeposits allows a caller to transition a set of deposits to a new state. Caveat: The action triggered by the state transitions should not compute heavy things or call external endpoints that can block for a long time. Deposits will be released if a transition takes longer than DefaultTransitionTimeout which is set to 5 seconds.
func (*Manager) UpdateDeposit ¶
UpdateDeposit overrides all fields of the deposit with given ID in the store.
func (*Manager) WaitInitComplete ¶
func (m *Manager) WaitInitComplete()
WaitInitComplete waits until the address manager has completed its setup.
type ManagerConfig ¶
type ManagerConfig struct { // AddressClient is the client that communicates with the loop server // to manage static addresses. AddressClient staticaddressrpc.StaticAddressServerClient // AddressManager is the address manager that is used to fetch static // address parameters. AddressManager AddressManager // SwapClient provides loop rpc functionality. SwapClient *loop.Client // Store is the database store that is used to store static address // related records. Store Store // WalletKit is the wallet client that is used to derive new keys from // lnd's wallet. WalletKit lndclient.WalletKitClient // ChainParams is the chain configuration(mainnet, testnet...) this // manager uses. ChainParams *chaincfg.Params // ChainNotifier is the chain notifier that is used to listen for new // blocks. ChainNotifier lndclient.ChainNotifierClient // Signer is the signer client that is used to sign transactions. Signer lndclient.SignerClient }
ManagerConfig holds the configuration for the address manager.
type SqlStore ¶
type SqlStore struct {
// contains filtered or unexported fields
}
SqlStore is the backing store for static address deposits.
func NewSqlStore ¶
NewSqlStore constructs a new SQLStore from a BaseDB. The BaseDB is agnostic to the underlying driver which can be postgres or sqlite.
func (*SqlStore) AllDeposits ¶
AllDeposits retrieves all known deposits to our static address.
func (*SqlStore) CreateDeposit ¶
CreateDeposit creates a static address deposit record in the database.
func (*SqlStore) GetDeposit ¶
GetDeposit retrieves the deposit from the database.
type Store ¶
type Store interface { // CreateDeposit inserts a new deposit into the store. CreateDeposit(ctx context.Context, deposit *Deposit) error // UpdateDeposit updates the deposit in the database. UpdateDeposit(ctx context.Context, deposit *Deposit) error // GetDeposit retrieves a deposit with depositID from the database. GetDeposit(ctx context.Context, depositID ID) (*Deposit, error) // AllDeposits retrieves all deposits from the store. AllDeposits(ctx context.Context) ([]*Deposit, error) }
Store is the database interface that is used to store and retrieve static address deposits.