From a46168e669888a2299b847abfc0799d314699991 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Wed, 12 Jul 2023 16:41:56 +0800 Subject: [PATCH] sweep: remove redundant map `inputFeeRates` when creating cluster This commit removes the map `inputFeeRates` inside `clusterByLockTime` as the fee rate can already be access via `input.lastFeeRate`. --- sweep/sweeper.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/sweep/sweeper.go b/sweep/sweeper.go index 487ad6cee..345121f68 100644 --- a/sweep/sweeper.go +++ b/sweep/sweeper.go @@ -928,7 +928,6 @@ func (s *UtxoSweeper) clusterByLockTime(inputs pendingInputs) ([]inputCluster, pendingInputs) { locktimes := make(map[uint32]pendingInputs) - inputFeeRates := make(map[wire.OutPoint]chainfee.SatPerKWeight) rem := make(pendingInputs) // Go through all inputs and check if they require a certain locktime. @@ -940,13 +939,13 @@ func (s *UtxoSweeper) clusterByLockTime(inputs pendingInputs) ([]inputCluster, } // Check if we already have inputs with this locktime. - p, ok := locktimes[lt] + cluster, ok := locktimes[lt] if !ok { - p = make(pendingInputs) + cluster = make(pendingInputs) } - p[op] = input - locktimes[lt] = p + cluster[op] = input + locktimes[lt] = cluster // We also get the preferred fee rate for this input. feeRate, err := s.feeRateForPreference(input.params.Fee) @@ -956,25 +955,24 @@ func (s *UtxoSweeper) clusterByLockTime(inputs pendingInputs) ([]inputCluster, } input.lastFeeRate = feeRate - inputFeeRates[op] = feeRate } // We'll then determine the sweep fee rate for each set of inputs by // calculating the average fee rate of the inputs within each set. inputClusters := make([]inputCluster, 0, len(locktimes)) - for lt, inputs := range locktimes { + for lt, cluster := range locktimes { lt := lt var sweepFeeRate chainfee.SatPerKWeight - for op := range inputs { - sweepFeeRate += inputFeeRates[op] + for _, input := range cluster { + sweepFeeRate += input.lastFeeRate } - sweepFeeRate /= chainfee.SatPerKWeight(len(inputs)) + sweepFeeRate /= chainfee.SatPerKWeight(len(cluster)) inputClusters = append(inputClusters, inputCluster{ lockTime: <, sweepFeeRate: sweepFeeRate, - inputs: inputs, + inputs: cluster, }) }