Skip to content

Commit

Permalink
Merge pull request #1239 from o1-labs/feat/fix-network-wait
Browse files Browse the repository at this point in the history
Make `tx.wait()` more reliable by increasing block length check to default of 20 blocks
  • Loading branch information
MartinMinkov authored Nov 14, 2023
2 parents 5ca4368 + e830e09 commit 4d98e5a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
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

0 comments on commit 4d98e5a

Please sign in to comment.