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:
yyforyongyu
2023-10-30 20:43:33 +08:00
parent 9d5ddf29f3
commit 1530fee9b3
4 changed files with 39 additions and 31 deletions

View File

@@ -33,10 +33,7 @@ type Cluster interface {
// CreateInputSets goes through the cluster's inputs and constructs
// sets of inputs that can be used to generate a sensible transaction.
CreateInputSets(wallet Wallet, maxFeeRate chainfee.SatPerKWeight,
maxInputs int) ([]inputSet, error)
// FeeRate returns the fee rate of the cluster.
FeeRate() chainfee.SatPerKWeight
maxInputs int) ([]InputSet, error)
}
// Compile-time constraint to ensure inputCluster implements Cluster.
@@ -50,11 +47,6 @@ type inputCluster struct {
inputs pendingInputs
}
// FeeRate returns the fee rate of the cluster.
func (c *inputCluster) FeeRate() chainfee.SatPerKWeight {
return c.sweepFeeRate
}
// GroupInputs goes through the cluster's inputs and constructs sets of inputs
// that can be used to generate a sensible transaction. Each set contains up to
// the configured maximum number of inputs. Negative yield inputs are skipped.
@@ -62,7 +54,7 @@ func (c *inputCluster) FeeRate() chainfee.SatPerKWeight {
// returned.
func (c *inputCluster) CreateInputSets(
wallet Wallet, maxFeeRate chainfee.SatPerKWeight,
maxInputs int) ([]inputSet, error) {
maxInputs int) ([]InputSet, error) {
// Turn the inputs into a slice so we can sort them.
inputList := make([]*pendingInput, 0, len(c.inputs))
@@ -110,7 +102,7 @@ func (c *inputCluster) CreateInputSets(
})
// Select blocks of inputs up to the configured maximum number.
var sets []inputSet
var sets []InputSet
for len(inputList) > 0 {
// Start building a set of positive-yield tx inputs under the
// condition that the tx will be published with the specified
@@ -156,7 +148,7 @@ func (c *inputCluster) CreateInputSets(
txInputs.totalOutput()-txInputs.walletInputTotal,
txInputs.weightEstimate(true).weight())
sets = append(sets, txInputs.inputs)
sets = append(sets, txInputs)
inputList = inputList[inputCount:]
}