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
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.
  • Loading branch information
lukasz-zimnoch committed Jul 14, 2023
1 parent 584f47c commit df84a71
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 df84a71

Please sign in to comment.