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

Make tx.wait() more reliable by increasing block length check to default of 20 blocks #1239

Merged
merged 4 commits into from
Nov 14, 2023
Merged
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased](https://github.com/o1-labs/o1js/compare/26363465d...HEAD)

> No unreleased changes yet
### Fixed

- Add a parameter to `checkZkappTransaction` for block length to check for transaction inclusion. This fixes a case where `Transaction.wait()` only checked the latest block, which led to an error once the transaction was included in a block that was not the latest. https://github.com/o1-labs/o1js/pull/1239

## [0.14.1](https://github.com/o1-labs/o1js/compare/e8e7510e1...26363465d)

Expand Down
12 changes: 6 additions & 6 deletions src/lib/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,8 @@ type LastBlockQueryFailureCheckResponse = {
}[];
};

const lastBlockQueryFailureCheck = `{
bestChain(maxLength: 1) {
const lastBlockQueryFailureCheck = (length: number) => `{
bestChain(maxLength: ${length}) {
transactions {
zkappCommands {
hash
Expand All @@ -496,10 +496,11 @@ const lastBlockQueryFailureCheck = `{
}`;

async function fetchLatestBlockZkappStatus(
blockLength: number,
graphqlEndpoint = networkConfig.minaEndpoint
) {
let [resp, error] = await makeGraphqlRequest(
lastBlockQueryFailureCheck,
lastBlockQueryFailureCheck(blockLength),
graphqlEndpoint,
networkConfig.minaFallbackEndpoints
);
Expand All @@ -513,9 +514,8 @@ async function fetchLatestBlockZkappStatus(
return bestChain;
}

async function checkZkappTransaction(txnId: string) {
let bestChainBlocks = await fetchLatestBlockZkappStatus();

async function checkZkappTransaction(txnId: string, blockLength = 20) {
let bestChainBlocks = await fetchLatestBlockZkappStatus(blockLength);
for (let block of bestChainBlocks.bestChain) {
for (let zkappCommand of block.transactions.zkappCommands) {
if (zkappCommand.hash === txnId) {
Expand Down
Loading