Documentation
¶
Index ¶
- Constants
- Variables
- func NewBatch(cfg batchConfig, bk batchKit) *batch
- func NewBatchFromDB(cfg batchConfig, bk batchKit) (*batch, error)
- func UseLogger(logger btclog.Logger)
- type BaseDB
- type Batcher
- type BatcherStore
- type LoopOutFetcher
- type MuSig2SignSweep
- type Purger
- type SQLStore
- func (s *SQLStore) ConfirmBatch(ctx context.Context, id int32) error
- func (s *SQLStore) DropBatch(ctx context.Context, id int32) error
- func (s *SQLStore) FetchBatchSweeps(ctx context.Context, id int32) ([]*dbSweep, error)
- func (s *SQLStore) FetchUnconfirmedSweepBatches(ctx context.Context) ([]*dbBatch, error)
- func (s *SQLStore) GetParentBatch(ctx context.Context, swapHash lntypes.Hash) (*dbBatch, error)
- func (s *SQLStore) GetSweepStatus(ctx context.Context, swapHash lntypes.Hash) (bool, error)
- func (s *SQLStore) InsertSweepBatch(ctx context.Context, batch *dbBatch) (int32, error)
- func (s *SQLStore) TotalSweptAmount(ctx context.Context, id int32) (btcutil.Amount, error)
- func (s *SQLStore) UpdateSweepBatch(ctx context.Context, batch *dbBatch) error
- func (s *SQLStore) UpsertSweep(ctx context.Context, sweep *dbSweep) error
- type SpendDetail
- type SpendNotifier
- type StoreMock
- func (s *StoreMock) AssertSweepStored(id lntypes.Hash) bool
- func (s *StoreMock) Close() error
- func (s *StoreMock) ConfirmBatch(ctx context.Context, id int32) error
- func (s *StoreMock) DropBatch(ctx context.Context, id int32) error
- func (s *StoreMock) FetchBatchSweeps(ctx context.Context, id int32) ([]*dbSweep, error)
- func (s *StoreMock) FetchUnconfirmedSweepBatches(ctx context.Context) ([]*dbBatch, error)
- func (s *StoreMock) GetParentBatch(ctx context.Context, swapHash lntypes.Hash) (*dbBatch, error)
- func (s *StoreMock) GetSweepStatus(ctx context.Context, swapHash lntypes.Hash) (bool, error)
- func (s *StoreMock) InsertSweepBatch(ctx context.Context, batch *dbBatch) (int32, error)
- func (s *StoreMock) TotalSweptAmount(ctx context.Context, batchID int32) (btcutil.Amount, error)
- func (s *StoreMock) UpdateSweepBatch(ctx context.Context, batch *dbBatch) error
- func (s *StoreMock) UpsertSweep(ctx context.Context, sweep *dbSweep) error
- type SwapStoreWrapper
- type SweepFetcher
- type SweepInfo
- type SweepRequest
- type VerifySchnorrSig
Constants ¶
const ( // Open is the state in which the batch is able to accept new sweeps. Open batchState = 0 // Closed is the state in which the batch is no longer able to accept // new sweeps. Closed batchState = 1 // Confirmed is the state in which the batch transaction has reached the // configured conf height. Confirmed batchState = 2 )
Variables ¶
var (
ErrBatchShuttingDown = errors.New("batch shutting down")
)
var (
ErrBatcherShuttingDown = errors.New("batcher shutting down")
)
Functions ¶
func NewBatchFromDB ¶
func NewBatchFromDB(cfg batchConfig, bk batchKit) (*batch, error)
NewBatchFromDB creates a new batch that already existed in storage.
Types ¶
type BaseDB ¶
type BaseDB interface { // ConfirmBatch confirms a batch by setting the state to confirmed. ConfirmBatch(ctx context.Context, id int32) error // GetBatchSweeps fetches all the sweeps that are part a batch. GetBatchSweeps(ctx context.Context, batchID int32) ( []sqlc.Sweep, error) // GetBatchSweptAmount returns the total amount of sats swept by a // (confirmed) batch. GetBatchSweptAmount(ctx context.Context, batchID int32) (int64, error) // GetSweepStatus returns true if the sweep has been completed. GetSweepStatus(ctx context.Context, swapHash []byte) (bool, error) // GetParentBatch fetches the parent batch of a completed sweep. GetParentBatch(ctx context.Context, swapHash []byte) (sqlc.SweepBatch, error) // GetUnconfirmedBatches fetches all the batches from the // database that are not in a confirmed state. GetUnconfirmedBatches(ctx context.Context) ([]sqlc.SweepBatch, error) // InsertBatch inserts a batch into the database, returning the id of // the inserted batch. InsertBatch(ctx context.Context, arg sqlc.InsertBatchParams) ( int32, error) // DropBatch drops a batch from the database. DropBatch(ctx context.Context, id int32) error // UpdateBatch updates a batch in the database. UpdateBatch(ctx context.Context, arg sqlc.UpdateBatchParams) error // UpsertSweep inserts a sweep into the database, or updates an existing // sweep if it already exists. UpsertSweep(ctx context.Context, arg sqlc.UpsertSweepParams) error // ExecTx allows for executing a function in the context of a database // transaction. ExecTx(ctx context.Context, txOptions loopdb.TxOptions, txBody func(*sqlc.Queries) error) error }
type Batcher ¶
type Batcher struct { // verifySchnorrSig is a function that can be used to verify a schnorr // signature. VerifySchnorrSig VerifySchnorrSig // contains filtered or unexported fields }
Batcher is a system that is responsible for accepting sweep requests and placing them in appropriate batches. It will spin up new batches as needed.
func NewBatcher ¶
func NewBatcher(wallet lndclient.WalletKitClient, chainNotifier lndclient.ChainNotifierClient, signerClient lndclient.SignerClient, musig2ServerSigner MuSig2SignSweep, verifySchnorrSig VerifySchnorrSig, chainparams *chaincfg.Params, store BatcherStore, sweepStore SweepFetcher) *Batcher
NewBatcher creates a new Batcher instance.
func (*Batcher) AddSweep ¶
func (b *Batcher) AddSweep(sweepReq *SweepRequest) error
AddSweep adds a sweep request to the batcher for handling. This will either place the sweep in an existing batch or create a new one.
func (*Batcher) FetchUnconfirmedBatches ¶
FetchUnconfirmedBatches fetches all the batches from the database that are not in a confirmed state.
type BatcherStore ¶
type BatcherStore interface { // FetchUnconfirmedSweepBatches fetches all the batches from the // database that are not in a confirmed state. FetchUnconfirmedSweepBatches(ctx context.Context) ([]*dbBatch, error) // InsertSweepBatch inserts a batch into the database, returning the id // of the inserted batch. InsertSweepBatch(ctx context.Context, batch *dbBatch) (int32, error) // DropBatch drops a batch from the database. This should only be used // when a batch is empty. DropBatch(ctx context.Context, id int32) error // UpdateSweepBatch updates a batch in the database. UpdateSweepBatch(ctx context.Context, batch *dbBatch) error // ConfirmBatch confirms a batch by setting its state to confirmed. ConfirmBatch(ctx context.Context, id int32) error // FetchBatchSweeps fetches all the sweeps that belong to a batch. FetchBatchSweeps(ctx context.Context, id int32) ([]*dbSweep, error) // UpsertSweep inserts a sweep into the database, or updates an existing // sweep if it already exists. UpsertSweep(ctx context.Context, sweep *dbSweep) error // GetSweepStatus returns the completed status of the sweep. GetSweepStatus(ctx context.Context, swapHash lntypes.Hash) (bool, error) // GetParentBatch returns the parent batch of a (completed) sweep. GetParentBatch(ctx context.Context, swapHash lntypes.Hash) (*dbBatch, error) // TotalSweptAmount returns the total amount swept by a (confirmed) // batch. TotalSweptAmount(ctx context.Context, id int32) (btcutil.Amount, error) }
type LoopOutFetcher ¶
type LoopOutFetcher interface { // FetchLoopOutSwap returns the loop out swap with the given hash. FetchLoopOutSwap(ctx context.Context, hash lntypes.Hash) (*loopdb.LoopOut, error) }
LoopOutFetcher is used to load LoopOut swaps from the database. It is implemented by loopdb.SwapStore.
type MuSig2SignSweep ¶
type MuSig2SignSweep func(ctx context.Context, protocolVersion loopdb.ProtocolVersion, swapHash lntypes.Hash, paymentAddr [32]byte, nonce []byte, sweepTxPsbt []byte, prevoutMap map[wire.OutPoint]*wire.TxOut) ( []byte, []byte, error)
MuSig2SignSweep is a function that can be used to sign a sweep transaction cooperatively with the swap server.
type Purger ¶
type Purger func(sweepReq *SweepRequest) error
Purger is a function that takes a sweep request and feeds it back to the batcher main entry point. The name is inspired by its purpose, which is to purge the batch from sweeps that didn't make it to the confirmed tx.
type SQLStore ¶
type SQLStore struct {
// contains filtered or unexported fields
}
SQLStore manages the reservations in the database.
func NewSQLStore ¶
NewSQLStore creates a new SQLStore.
func (*SQLStore) ConfirmBatch ¶
ConfirmBatch confirms a batch by setting the state to confirmed.
func (*SQLStore) DropBatch ¶
DropBatch drops a batch from the database. Note that we only use this call for batches that have no sweeps and so we'd not be able to resume.
func (*SQLStore) FetchBatchSweeps ¶
FetchBatchSweeps fetches all the sweeps that are part a batch.
func (*SQLStore) FetchUnconfirmedSweepBatches ¶
FetchUnconfirmedSweepBatches fetches all the batches from the database that are not in a confirmed state.
func (*SQLStore) GetParentBatch ¶
GetParentBatch fetches the parent batch of a completed sweep.
func (*SQLStore) GetSweepStatus ¶
GetSweepStatus returns true if the sweep has been completed.
func (*SQLStore) InsertSweepBatch ¶
InsertSweepBatch inserts a batch into the database, returning the id of the inserted batch.
func (*SQLStore) TotalSweptAmount ¶
TotalSweptAmount returns the total amount swept by a (confirmed) batch.
func (*SQLStore) UpdateSweepBatch ¶
UpdateSweepBatch updates a batch in the database.
type SpendDetail ¶
type SpendDetail struct { // Tx is the transaction that spent the outpoint. Tx *wire.MsgTx // OnChainFeePortion is the fee portion that was paid to get this sweep // confirmed on chain. This is the difference between the value of the // outpoint and the value of all sweeps that were included in the batch // divided by the number of sweeps. OnChainFeePortion btcutil.Amount }
type SpendNotifier ¶
type SpendNotifier struct { // SpendChan is a channel where the spend details are received. SpendChan chan *SpendDetail // SpendErrChan is a channel where spend errors are received. SpendErrChan chan error // QuitChan is a channel that can be closed to stop the notifier. QuitChan chan bool }
SpendNotifier is a notifier that is used to notify the requester of a sweep that the sweep was successful.
type StoreMock ¶
type StoreMock struct {
// contains filtered or unexported fields
}
StoreMock implements a mock client swap store.
func (*StoreMock) AssertSweepStored ¶
AssertSweepStored asserts that a sweep is stored.
func (*StoreMock) ConfirmBatch ¶
ConfirmBatch confirms a batch.
func (*StoreMock) FetchBatchSweeps ¶
FetchBatchSweeps fetches all the sweeps that belong to a batch.
func (*StoreMock) FetchUnconfirmedSweepBatches ¶
FetchUnconfirmedSweepBatches fetches all the loop out sweep batches from the database that are not in a confirmed state.
func (*StoreMock) GetParentBatch ¶
GetParentBatch returns the parent batch of a swap.
func (*StoreMock) GetSweepStatus ¶
GetSweepStatus returns the status of a sweep.
func (*StoreMock) InsertSweepBatch ¶
InsertSweepBatch inserts a batch into the database, returning the id of the inserted batch.
func (*StoreMock) TotalSweptAmount ¶
TotalSweptAmount returns the total amount of BTC that has been swept from a batch.
func (*StoreMock) UpdateSweepBatch ¶
UpdateSweepBatch updates a batch in the database.
type SwapStoreWrapper ¶
type SwapStoreWrapper struct {
// contains filtered or unexported fields
}
SwapStoreWrapper is LoopOutFetcher wrapper providing SweepFetcher interface.
func NewSweepFetcherFromSwapStore ¶
func NewSweepFetcherFromSwapStore(swapStore LoopOutFetcher, chainParams *chaincfg.Params) (*SwapStoreWrapper, error)
NewSweepFetcherFromSwapStore accepts swapStore (e.g. loopdb) and returns a wrapper implementing SweepFetcher interface (suitable for NewBatcher).
func (*SwapStoreWrapper) FetchSweep ¶
func (f *SwapStoreWrapper) FetchSweep(ctx context.Context, swapHash lntypes.Hash) (*SweepInfo, error)
FetchSweep returns details of the sweep with the given hash. Implements SweepFetcher interface.
type SweepFetcher ¶
type SweepFetcher interface { // FetchSweep returns details of the sweep with the given hash. FetchSweep(ctx context.Context, hash lntypes.Hash) (*SweepInfo, error) }
SweepFetcher is used to get details of a sweep.
type SweepInfo ¶
type SweepInfo struct { // ConfTarget is the confirmation target of the sweep. ConfTarget int32 // Timeout is the timeout of the swap that the sweep belongs to. Timeout int32 // InitiationHeight is the height at which the swap was initiated. InitiationHeight int32 // HTLC is the HTLC that is being swept. HTLC swap.Htlc // Preimage is the preimage of the HTLC that is being swept. Preimage lntypes.Preimage // SwapInvoicePaymentAddr is the payment address of the swap invoice. SwapInvoicePaymentAddr [32]byte // HTLCKeys is the set of keys used to sign the HTLC. HTLCKeys loopdb.HtlcKeys // HTLCSuccessEstimator is a function that estimates the weight of the // HTLC success script. HTLCSuccessEstimator func(*input.TxWeightEstimator) error // ProtocolVersion is the protocol version of the swap that the sweep // belongs to. ProtocolVersion loopdb.ProtocolVersion // IsExternalAddr is true if the sweep spends to a non-wallet address. IsExternalAddr bool // DestAddr is the destination address of the sweep. DestAddr btcutil.Address }
SweepInfo stores any data related to sweeping a specific outpoint.
type SweepRequest ¶
type SweepRequest struct { // SwapHash is the hash of the swap that is being swept. SwapHash lntypes.Hash // Outpoint is the outpoint that is being swept. Outpoint wire.OutPoint // Value is the value of the outpoint that is being swept. Value btcutil.Amount // Notifier is a notifier that is used to notify the requester of this // sweep that the sweep was successful. Notifier *SpendNotifier }
SweepRequest is a request to sweep a specific outpoint.
type VerifySchnorrSig ¶
VerifySchnorrSig is a function that can be used to verify a schnorr signature.