From df84a71491c461108d14b76faa2e81b4638cd069 Mon Sep 17 00:00:00 2001 From: Lukasz Zimnoch Date: Fri, 14 Jul 2023 14:31:21 +0200 Subject: [PATCH] Fix the wallets limit filter in the wallet maintainer redemptions code The current logic is wrong as, if the `WalletsLimit` filter is on, always the same wallets will be taken into account so redemption requests targeting newer wallets can be missed by the wallet maintainer. We are fixing that by applying the `WalletsLimit` filter at a later stage. --- pkg/maintainer/wallet/redemptions.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/pkg/maintainer/wallet/redemptions.go b/pkg/maintainer/wallet/redemptions.go index 0cb29917fc..b7628e860a 100644 --- a/pkg/maintainer/wallet/redemptions.go +++ b/pkg/maintainer/wallet/redemptions.go @@ -206,21 +206,11 @@ func FindPendingRedemptions( } logger.Infof( - "built an initial list of [%v] wallets that will be checked "+ + "built a list of [%v] wallets that will be checked "+ "for pending redemption requests", len(walletPublicKeyHashes), ) - // Apply the wallets number limit if needed. - if limit := int(filter.WalletsLimit); limit > 0 && len(walletPublicKeyHashes) > limit { - walletPublicKeyHashes = walletPublicKeyHashes[:limit] - - logger.Infof( - "limited the initial wallets list to [%v] wallets", - len(walletPublicKeyHashes), - ) - } - result := make(map[[20]byte][]bitcoin.Script) for _, walletPublicKeyHash := range walletPublicKeyHashes { @@ -265,6 +255,17 @@ func FindPendingRedemptions( pendingRedemption.RedeemerOutputScript, ) } + + // Apply the wallets number limit if needed. + if limit := int(filter.WalletsLimit); limit > 0 && len(result) == limit { + logger.Infof( + "aborting pending redemptions checks due to the "+ + "configured wallets limit; [%v] wallets with pending "+ + "redemptions were found so far", + len(result), + ) + break + } } return result, nil