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

Remove multiple best tip blocks for actions, if they exist #817

Merged
merged 3 commits into from
Apr 4, 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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- This breaks deployed zkApps which use `MerkleWitness.calculateRoot()`, because the circuit is changed
- You can make your existing contracts compatible again by switching to `MerkleWitness.calculateRootSlow()`, which has the old circuit

### Fixed

- Removed multiple best tip blocks when fetching action data https://github.com/o1-labs/snarkyjs/pull/817
- Implemented a temporary fix that filters out multiple best tip blocks, if they exist, while fetching actions. This fix will be removed once the related issue in the Archive-Node-API repository (https://github.com/o1-labs/Archive-Node-API/issues/7) is resolved.

## [0.9.5](https://github.com/o1-labs/snarkyjs/compare/21de489...4573252d)

- Update the zkApp verification key from within one of its own methods, via proof https://github.com/o1-labs/snarkyjs/pull/812

### Breaking changes

- Change type of verification key returned by `SmartContract.compile()` to match `VerificationKey` https://github.com/o1-labs/snarkyjs/pull/812
Expand Down
25 changes: 25 additions & 0 deletions src/lib/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,9 @@ type FetchedEvents = {
}[];
};
type FetchedActions = {
blockInfo: {
distanceFromMaxBlockHeight: number;
};
actionState: string;
actionData: {
accountUpdateId: string;
Expand Down Expand Up @@ -616,6 +619,9 @@ const getActionsQuery = (
}
return `{
actions(input: { ${input} }) {
blockInfo {
distanceFromMaxBlockHeight
}
actionState
actionData {
accountUpdateId
Expand Down Expand Up @@ -731,6 +737,25 @@ async function fetchActions(
};
}

// TODO: This is a temporary fix. We should be able to fetch the event/action data from any block at the best tip.
// Once https://github.com/o1-labs/Archive-Node-API/issues/7 is resolved, we can remove this.
// If we have multiple blocks returned at the best tip (e.g. distanceFromMaxBlockHeight === 0),
// then filter out the blocks at the best tip. This is because we cannot guarantee that every block
// at the best tip will have the correct action data or guarantee that the specific block data will not
// fork in anyway. If this happens, we delay fetching action data until another block has been added to the network.
let numberOfBestTipBlocks = 0;
for (let i = 0; i < fetchedActions.length; i++) {
if (fetchedActions[i].blockInfo.distanceFromMaxBlockHeight === 0) {
numberOfBestTipBlocks++;
}
if (numberOfBestTipBlocks > 1) {
fetchedActions = fetchedActions.filter((action) => {
return action.blockInfo.distanceFromMaxBlockHeight !== 0;
});
break;
}
}

const processActionData = (
currentActionList: string[][],
latestActionsHash: Field
Expand Down