If there are closed/terminated wallets in the system, the redemption process takes a long time. This is what happens:
- The
findWalletForRedemption function must iterate over all wallets to check which one can handle the redemption: https://github.com/keep-network/tbtc-v2/blob/51094e4cdaefdf82a11b80f7e9e6899a6333a9ca/typescript/src/services/redemptions/redemptions-service.ts#L127
- To do the check, the above function must call
wallets to fetch data of the particular wallet: https://github.com/keep-network/tbtc-v2/blob/51094e4cdaefdf82a11b80f7e9e6899a6333a9ca/typescript/src/lib/ethereum/bridge.ts#L583
- The
wallets function calls getWalletCompressedPublicKey under the hood: https://github.com/keep-network/tbtc-v2/blob/51094e4cdaefdf82a11b80f7e9e6899a6333a9ca/typescript/src/lib/ethereum/bridge.ts#L607
- Closed/terminated wallets are no longer in the contract state so,
getWalletCompressedPublicKey throws while calling getWalletPublicKey: https://github.com/keep-network/tbtc-v2/blob/51094e4cdaefdf82a11b80f7e9e6899a6333a9ca/typescript/src/lib/ethereum/bridge.ts#L521
- The above is not a problem per se as the error is caught. However, the
getWalletPublicKey uses a backoff retry mechanism inside so the final throw is made after 3 internal retries which takes time and contributes to the long execution time of the entire process: https://github.com/keep-network/tbtc-v2/blob/51094e4cdaefdf82a11b80f7e9e6899a6333a9ca/typescript/src/lib/ethereum/wallet-registry.ts#L69
The solution is simple. The backoffRetrier function should not retry if the contract call reverts with Wallet with the given ID has not been registered error. This can be achieved by passing a custom errorMatcher argument to this specific backoffRetrier call: https://github.com/keep-network/tbtc-v2/blob/51094e4cdaefdf82a11b80f7e9e6899a6333a9ca/typescript/src/lib/utils/backoff.ts#L93
If there are closed/terminated wallets in the system, the redemption process takes a long time. This is what happens:
findWalletForRedemptionfunction must iterate over all wallets to check which one can handle the redemption: https://github.com/keep-network/tbtc-v2/blob/51094e4cdaefdf82a11b80f7e9e6899a6333a9ca/typescript/src/services/redemptions/redemptions-service.ts#L127walletsto fetch data of the particular wallet: https://github.com/keep-network/tbtc-v2/blob/51094e4cdaefdf82a11b80f7e9e6899a6333a9ca/typescript/src/lib/ethereum/bridge.ts#L583walletsfunction callsgetWalletCompressedPublicKeyunder the hood: https://github.com/keep-network/tbtc-v2/blob/51094e4cdaefdf82a11b80f7e9e6899a6333a9ca/typescript/src/lib/ethereum/bridge.ts#L607getWalletCompressedPublicKeythrows while callinggetWalletPublicKey: https://github.com/keep-network/tbtc-v2/blob/51094e4cdaefdf82a11b80f7e9e6899a6333a9ca/typescript/src/lib/ethereum/bridge.ts#L521getWalletPublicKeyuses a backoff retry mechanism inside so the final throw is made after 3 internal retries which takes time and contributes to the long execution time of the entire process: https://github.com/keep-network/tbtc-v2/blob/51094e4cdaefdf82a11b80f7e9e6899a6333a9ca/typescript/src/lib/ethereum/wallet-registry.ts#L69The solution is simple. The
backoffRetrierfunction should not retry if the contract call reverts withWallet with the given ID has not been registerederror. This can be achieved by passing a customerrorMatcherargument to this specificbackoffRetriercall: https://github.com/keep-network/tbtc-v2/blob/51094e4cdaefdf82a11b80f7e9e6899a6333a9ca/typescript/src/lib/utils/backoff.ts#L93