From 8353b6fd6ed12db978cb0aa5f382c9f3e59c4885 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Fri, 13 Dec 2019 11:30:23 +0100 Subject: [PATCH] sweep: extract sweepCluster method Prepares for adding another level of nesting. --- sweep/sweeper.go | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/sweep/sweeper.go b/sweep/sweeper.go index 2abebbb8..a62447f1 100644 --- a/sweep/sweeper.go +++ b/sweep/sweeper.go @@ -599,27 +599,10 @@ func (s *UtxoSweeper) collector(blockEpochs <-chan *chainntnfs.BlockEpoch) { inputClusters[j].sweepFeeRate }) for _, cluster := range inputClusters { - // Examine pending inputs and try to construct - // lists of inputs. - inputLists, err := s.getInputLists( - cluster, bestHeight, - ) + err := s.sweepCluster(cluster, bestHeight) if err != nil { - log.Errorf("Unable to examine pending "+ - "inputs: %v", err) - continue - } - - // Sweep selected inputs. - for _, inputs := range inputLists { - err := s.sweep( - inputs, cluster.sweepFeeRate, - bestHeight, - ) - if err != nil { - log.Errorf("Unable to sweep "+ - "inputs: %v", err) - } + log.Errorf("input cluster sweep: %v", + err) } } @@ -645,6 +628,27 @@ func (s *UtxoSweeper) collector(blockEpochs <-chan *chainntnfs.BlockEpoch) { } } +// sweepCluster tries to sweep the given input cluster. +func (s *UtxoSweeper) sweepCluster(cluster inputCluster, + currentHeight int32) error { + + // Examine pending inputs and try to construct lists of inputs. + inputLists, err := s.getInputLists(cluster, currentHeight) + if err != nil { + return fmt.Errorf("unable to examine pending inputs: %v", err) + } + + // Sweep selected inputs. + for _, inputs := range inputLists { + err := s.sweep(inputs, cluster.sweepFeeRate, currentHeight) + if err != nil { + return fmt.Errorf("unable to sweep inputs: %v", err) + } + } + + return nil +} + // bucketForFeeReate determines the proper bucket for a fee rate. This is done // in order to batch inputs with similar fee rates together. func (s *UtxoSweeper) bucketForFeeRate(