sweep: add new inteface InputSet to manage inputs in a tx
Previously the fee rate is tracked at cluster level, which may not be accurate as each cluster is then divided into input sets. And these sets are what's actually included in the final sweeping tx. To properly reflect the final fee rate used in the sweeping tx, `InputSet` is added so more customized clustering logic can be implemented in the future. For intance, atm it's clustered by fee rates, while we may also cluster by deadlines, urgencies, etc.
This commit is contained in:
4 files changed
+39
-31
No files matched your search
@@ -30,6 +30,16 @@ const (
|
||||
constraintsForce
|
||||
)
|
||||
|
||||
// InputSet defines an interface that's responsible for filtering a set of
|
||||
// inputs that can be swept economically.
|
||||
type InputSet interface {
|
||||
// Inputs returns the set of inputs that should be used to create a tx.
|
||||
Inputs() []input.Input
|
||||
|
||||
// FeeRate returns the fee rate that should be used for the tx.
|
||||
FeeRate() chainfee.SatPerKWeight
|
||||
}
|
||||
|
||||
type txInputSetState struct {
|
||||
// feeRate is the fee rate to use for the sweep transaction.
|
||||
feeRate chainfee.SatPerKWeight
|
||||
@@ -121,6 +131,9 @@ type txInputSet struct {
|
||||
wallet Wallet
|
||||
}
|
||||
|
||||
// Compile-time constraint to ensure txInputSet implements InputSet.
|
||||
var _ InputSet = (*txInputSet)(nil)
|
||||
|
||||
// newTxInputSet constructs a new, empty input set.
|
||||
func newTxInputSet(wallet Wallet, feePerKW, maxFeeRate chainfee.SatPerKWeight,
|
||||
maxInputs int) *txInputSet {
|
||||
@@ -139,6 +152,16 @@ func newTxInputSet(wallet Wallet, feePerKW, maxFeeRate chainfee.SatPerKWeight,
|
||||
return &b
|
||||
}
|
||||
|
||||
// Inputs returns the inputs that should be used to create a tx.
|
||||
func (t *txInputSet) Inputs() []input.Input {
|
||||
return t.inputs
|
||||
}
|
||||
|
||||
// FeeRate returns the fee rate that should be used for the tx.
|
||||
func (t *txInputSet) FeeRate() chainfee.SatPerKWeight {
|
||||
return t.feeRate
|
||||
}
|
||||
|
||||
// enoughInput returns true if we've accumulated enough inputs to pay the fees
|
||||
// and have at least one output that meets the dust limit.
|
||||
func (t *txInputSet) enoughInput() bool {
|
||||
|
||||
Reference in new issue
Block a user