sweep: add new interface Cluster to manage grouping inputs
This commit adds a new interface `Cluster` to manage cluster-level inputs grouping. This new interface replaces the `inputCluster` and will be futher refactored so the sweeper can use a much smaller coin selection lock.
This commit is contained in:
6 files changed
+171
-353
No files matched your search
@@ -1882,115 +1882,6 @@ func TestSweeperShutdownHandling(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
// TestGetInputLists checks that the expected input sets are returned based on
|
||||
// whether there are retried inputs or not.
|
||||
func TestGetInputLists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Create a test param with a dummy fee preference. This is needed so
|
||||
// `feeRateForPreference` won't throw an error.
|
||||
param := Params{Fee: FeeEstimateInfo{ConfTarget: 1}}
|
||||
|
||||
// Create a mock input and mock all the methods used in this test.
|
||||
testInput := &input.MockInput{}
|
||||
testInput.On("RequiredLockTime").Return(0, false)
|
||||
testInput.On("WitnessType").Return(input.CommitmentAnchor)
|
||||
testInput.On("OutPoint").Return(&wire.OutPoint{Index: 1})
|
||||
testInput.On("RequiredTxOut").Return(nil)
|
||||
testInput.On("UnconfParent").Return(nil)
|
||||
testInput.On("SignDesc").Return(&input.SignDescriptor{
|
||||
Output: &wire.TxOut{Value: 100_000},
|
||||
})
|
||||
|
||||
// Create a new and a retried input.
|
||||
//
|
||||
// NOTE: we use the same input.Input for both pending inputs as we only
|
||||
// test the logic of returning the correct non-nil input sets, and not
|
||||
// the content the of sets. To validate the content of the sets, we
|
||||
// should test `generateInputPartitionings` instead.
|
||||
newInput := &pendingInput{
|
||||
Input: testInput,
|
||||
params: param,
|
||||
}
|
||||
oldInput := &pendingInput{
|
||||
Input: testInput,
|
||||
params: param,
|
||||
publishAttempts: 1,
|
||||
}
|
||||
|
||||
// clusterNew contains only new inputs.
|
||||
clusterNew := pendingInputs{
|
||||
wire.OutPoint{Index: 1}: newInput,
|
||||
}
|
||||
|
||||
// clusterMixed contains a mixed of new and retried inputs.
|
||||
clusterMixed := pendingInputs{
|
||||
wire.OutPoint{Index: 1}: newInput,
|
||||
wire.OutPoint{Index: 2}: oldInput,
|
||||
}
|
||||
|
||||
// clusterOld contains only retried inputs.
|
||||
clusterOld := pendingInputs{
|
||||
wire.OutPoint{Index: 2}: oldInput,
|
||||
}
|
||||
|
||||
// Create a test sweeper.
|
||||
s := New(&UtxoSweeperConfig{
|
||||
MaxInputsPerTx: DefaultMaxInputsPerTx,
|
||||
})
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
cluster inputCluster
|
||||
expectedNilAllSet bool
|
||||
expectNilNewSet bool
|
||||
}{
|
||||
{
|
||||
// When there are only new inputs, we'd expect the
|
||||
// first returned set(allSets) to be empty.
|
||||
name: "new inputs only",
|
||||
cluster: inputCluster{inputs: clusterNew},
|
||||
expectedNilAllSet: true,
|
||||
expectNilNewSet: false,
|
||||
},
|
||||
{
|
||||
// When there are only retried inputs, we'd expect the
|
||||
// second returned set(newSet) to be empty.
|
||||
name: "retried inputs only",
|
||||
cluster: inputCluster{inputs: clusterOld},
|
||||
expectedNilAllSet: false,
|
||||
expectNilNewSet: true,
|
||||
},
|
||||
{
|
||||
// When there are mixed inputs, we'd expect two sets
|
||||
// are returned.
|
||||
name: "mixed inputs",
|
||||
cluster: inputCluster{inputs: clusterMixed},
|
||||
expectedNilAllSet: false,
|
||||
expectNilNewSet: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
allSets, newSets, err := s.getInputLists(tc.cluster)
|
||||
require.NoError(t, err)
|
||||
|
||||
if tc.expectNilNewSet {
|
||||
require.Nil(t, newSets)
|
||||
}
|
||||
|
||||
if tc.expectedNilAllSet {
|
||||
require.Nil(t, allSets)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestMarkInputsPendingPublish checks that given a list of inputs with
|
||||
// different states, only the non-terminal state will be marked as `Published`.
|
||||
func TestMarkInputsPendingPublish(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user