-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #420 from reservoirprotocol/fix/chain-mismatch-race
Chain mismatch race condition fix
- Loading branch information
Showing
4 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@reservoir0x/relay-sdk': patch | ||
--- | ||
|
||
Improve robustness of pre tx chain id check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Repeat a function until the function returns true for a maximum set of attempts with a fixed interval | ||
* @param callback A function that returns true to exit the loop | ||
* @param maximumAttempts The maximum amount of tries for this poll | ||
* @param attemptCount The amount of attempts already done by the poll, should be left blank | ||
* @param pollingInterval The frequency of the loop | ||
* @returns When it has finished polling | ||
*/ | ||
export async function repeatUntilOk( | ||
callback: () => Promise<boolean>, | ||
maximumAttempts: number = 15, | ||
attemptCount: number = 0, | ||
pollingInterval: number = 5000 | ||
) { | ||
if (attemptCount >= maximumAttempts) { | ||
throw `Failed to get an ok response after ${attemptCount} attempt(s), aborting` | ||
} | ||
|
||
const response = await callback() | ||
|
||
if (response) { | ||
return true | ||
} else { | ||
await new Promise((resolve) => setTimeout(resolve, pollingInterval)) | ||
attemptCount++ | ||
await repeatUntilOk( | ||
callback, | ||
maximumAttempts, | ||
attemptCount, | ||
pollingInterval | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters