From d0a8f27d847a1623c3d496e77fa6907762e0c0f4 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Wed, 20 Mar 2024 05:56:56 +0800 Subject: [PATCH] sweep: change `MaxInputsPerTx` from `int` to `uint32` --- sweep/aggregator.go | 6 +++--- sweep/sweeper.go | 2 +- sweep/sweeper_test.go | 2 +- sweep/tx_input_set.go | 6 +++--- sweep/txgenerator.go | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sweep/aggregator.go b/sweep/aggregator.go index 9c6d7f5cb..379ff9829 100644 --- a/sweep/aggregator.go +++ b/sweep/aggregator.go @@ -35,7 +35,7 @@ type inputCluster struct { // inputs are skipped. No input sets with a total value after fees below the // dust limit are returned. func (c *inputCluster) createInputSets(maxFeeRate chainfee.SatPerKWeight, - maxInputs int) []InputSet { + maxInputs uint32) []InputSet { // Turn the inputs into a slice so we can sort them. inputList := make([]*pendingInput, 0, len(c.inputs)) @@ -138,7 +138,7 @@ type SimpleAggregator struct { // MaxInputsPerTx specifies the default maximum number of inputs allowed // in a single sweep tx. If more need to be swept, multiple txes are // created and published. - MaxInputsPerTx int + MaxInputsPerTx uint32 // FeeRateBucketSize is the default size of fee rate buckets we'll use // when clustering inputs into buckets with similar fee rates within @@ -158,7 +158,7 @@ var _ UtxoAggregator = (*SimpleAggregator)(nil) // NewSimpleUtxoAggregator creates a new instance of a SimpleAggregator. func NewSimpleUtxoAggregator(estimator chainfee.Estimator, - max chainfee.SatPerKWeight, maxTx int) *SimpleAggregator { + max chainfee.SatPerKWeight, maxTx uint32) *SimpleAggregator { return &SimpleAggregator{ FeeEstimator: estimator, diff --git a/sweep/sweeper.go b/sweep/sweeper.go index 8fb2c84c1..bd266aaa0 100644 --- a/sweep/sweeper.go +++ b/sweep/sweeper.go @@ -335,7 +335,7 @@ type UtxoSweeperConfig struct { // MaxInputsPerTx specifies the default maximum number of inputs allowed // in a single sweep tx. If more need to be swept, multiple txes are // created and published. - MaxInputsPerTx int + MaxInputsPerTx uint32 // MaxSweepAttempts specifies the maximum number of times an input is // included in a publish attempt before giving up and returning an error diff --git a/sweep/sweeper_test.go b/sweep/sweeper_test.go index f3e4fb16f..519bbdbb2 100644 --- a/sweep/sweeper_test.go +++ b/sweep/sweeper_test.go @@ -30,7 +30,7 @@ var ( testMaxSweepAttempts = 3 - testMaxInputsPerTx = 3 + testMaxInputsPerTx = uint32(3) defaultFeePref = Params{Fee: FeeEstimateInfo{ConfTarget: 1}} ) diff --git a/sweep/tx_input_set.go b/sweep/tx_input_set.go index 09367624f..b80ea2db0 100644 --- a/sweep/tx_input_set.go +++ b/sweep/tx_input_set.go @@ -139,7 +139,7 @@ type txInputSet struct { // maxInputs is the maximum number of inputs that will be accepted in // the set. - maxInputs int + maxInputs uint32 } // Compile-time constraint to ensure txInputSet implements InputSet. @@ -147,7 +147,7 @@ var _ InputSet = (*txInputSet)(nil) // newTxInputSet constructs a new, empty input set. func newTxInputSet(feePerKW, maxFeeRate chainfee.SatPerKWeight, - maxInputs int) *txInputSet { + maxInputs uint32) *txInputSet { state := txInputSetState{ feeRate: feePerKW, @@ -215,7 +215,7 @@ func (t *txInputSet) addToState(inp input.Input, // Stop if max inputs is reached. Do not count additional wallet inputs, // because we don't know in advance how many we may need. if constraints != constraintsWallet && - len(t.inputs) >= t.maxInputs { + uint32(len(t.inputs)) >= t.maxInputs { return nil } diff --git a/sweep/txgenerator.go b/sweep/txgenerator.go index 353513cb6..0cab9a6e2 100644 --- a/sweep/txgenerator.go +++ b/sweep/txgenerator.go @@ -19,7 +19,7 @@ var ( // DefaultMaxInputsPerTx specifies the default maximum number of inputs // allowed in a single sweep tx. If more need to be swept, multiple txes // are created and published. - DefaultMaxInputsPerTx = 100 + DefaultMaxInputsPerTx = uint32(100) // ErrLocktimeConflict is returned when inputs with different // transaction nLockTime values are included in the same transaction.