Skip to content

Commit

Permalink
refactor(fetch.ts): remove temporary fix for fetching event/action da…
Browse files Browse the repository at this point in the history
…ta from any block at the best tip

This change was made because the issue o1-labs/Archive-Node-API#7 has been resolved, making the temporary fix redundant.
  • Loading branch information
MartinMinkov committed Feb 8, 2024
1 parent d105637 commit 82c4913
Showing 1 changed file with 0 additions and 38 deletions.
38 changes: 0 additions & 38 deletions src/lib/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -957,25 +957,6 @@ async function fetchEvents(
);
}

// 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 event data or guarantee that the specific block data will not
// fork in anyway. If this happens, we delay fetching event data until another block has been added to the network.
let numberOfBestTipBlocks = 0;
for (let i = 0; i < fetchedEvents.length; i++) {
if (fetchedEvents[i].blockInfo.distanceFromMaxBlockHeight === 0) {
numberOfBestTipBlocks++;
}
if (numberOfBestTipBlocks > 1) {
fetchedEvents = fetchedEvents.filter((event) => {
return event.blockInfo.distanceFromMaxBlockHeight !== 0;
});
break;
}
}

return fetchedEvents.map((event) => {
let events = event.eventData.map(({ data, transactionInfo }) => {
return {
Expand Down Expand Up @@ -1028,25 +1009,6 @@ 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;
}
}

let actionsList: { actions: string[][]; hash: string }[] = [];
// correct for archive node sending one block too many
if (
Expand Down

0 comments on commit 82c4913

Please sign in to comment.