Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the WalletRegistry.getWalletPublicKey function #821

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions typescript/api-reference/classes/EthereumWalletRegistry.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ WalletRegistry.getDkgResultApprovedEvents

#### Defined in

[lib/ethereum/wallet-registry.ts:126](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/wallet-registry.ts#L126)
[lib/ethereum/wallet-registry.ts:129](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/wallet-registry.ts#L129)

___

Expand All @@ -207,7 +207,7 @@ WalletRegistry.getDkgResultChallengedEvents

#### Defined in

[lib/ethereum/wallet-registry.ts:151](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/wallet-registry.ts#L151)
[lib/ethereum/wallet-registry.ts:154](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/wallet-registry.ts#L154)

___

Expand All @@ -234,7 +234,7 @@ WalletRegistry.getDkgResultSubmittedEvents

#### Defined in

[lib/ethereum/wallet-registry.ts:83](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/wallet-registry.ts#L83)
[lib/ethereum/wallet-registry.ts:86](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/wallet-registry.ts#L86)

___

Expand Down
19 changes: 11 additions & 8 deletions typescript/src/lib/ethereum/wallet-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ChainIdentifier,
Chains,
} from "../contracts"
import { backoffRetrier, Hex } from "../utils"
import { backoffRetrier, Hex, skipRetryWhenMatched } from "../utils"
import { Event as EthersEvent } from "@ethersproject/contracts"
import { BigNumber } from "ethers"
import {
Expand Down Expand Up @@ -66,13 +66,16 @@ export class EthereumWalletRegistry
* @see {WalletRegistry#getWalletPublicKey}
*/
async getWalletPublicKey(walletID: Hex): Promise<Hex> {
const publicKey = await backoffRetrier<string>(this._totalRetryAttempts)(
async () => {
return await this._instance.getWalletPublicKey(
walletID.toPrefixedString()
)
}
)
const publicKey = await backoffRetrier<string>(
this._totalRetryAttempts,
undefined,
undefined,
skipRetryWhenMatched(["Wallet with the given ID has not been registered"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we can safely skip this error. We want to work around the problem in the redemption process, but the getWalletPublicKey function can be used in other processes as well.
If someone calls getWalletPublicKey right after a fresh wallet creation there is a chance that chain endpoint hasn't synced yet and the retry would be desirable here.

Maybe we should add an optional argument skipRetryWhenNotRegistered = false and use this variant only in the redemption process?

)(async () => {
return await this._instance.getWalletPublicKey(
walletID.toPrefixedString()
)
})
return Hex.from(publicKey.substring(2))
}

Expand Down
Loading