Skip to content

Commit

Permalink
Fix the wallets limit filter in the wallet maintainer redemptions code (
Browse files Browse the repository at this point in the history
#3683)

Closes: #3682

As described in #3682, the current logic is wrong. If the `WalletsLimit`
filter is on, always the same oldest 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.
  • Loading branch information
pdyraga authored Jul 14, 2023
2 parents 584f47c + df84a71 commit 08ee58c
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions pkg/maintainer/wallet/redemptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 08ee58c

Please sign in to comment.