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

Sort actions by tx sequence when available #1917

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
38 changes: 34 additions & 4 deletions src/lib/mina/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,15 @@ async function fetchActions(
graphqlEndpoint,
networkConfig.archiveFallbackEndpoints
);
if (error) throw Error(error.statusText);
if (error) {
// retry once without querying transaction info
[response, error] = await makeGraphqlRequest<ActionQueryResponse>(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than retry the query, perhaps we can set the archive node API version in the Mina.Network settings somewhere. Then we could make a different query based on which version we believe we're talking to.

For this specific example, after we get Minascan to update their version, the new query will work in nearly every case, but we ought to prepare for the case that different versions of the API could be running.

getActionsQuery(publicKey, actionStates, tokenId, undefined, true),
graphqlEndpoint,
networkConfig.archiveFallbackEndpoints
);
if (error) throw Error(error.statusText);
}
let fetchedActions = response?.data.actions;
if (fetchedActions === undefined) {
return {
Expand Down Expand Up @@ -757,9 +765,31 @@ export function createActionsList(
`No action data was found for the account ${publicKey} with the latest action state ${actionState}`
);

actionData = actionData.sort((a1, a2) => {
return Number(a1.accountUpdateId) < Number(a2.accountUpdateId) ? -1 : 1;
});
// DEPRECATED: In case the archive node is running an out-of-date version, best guess is to sort by the account update id
if (!actionData[0].transactionInfo) {
actionData = actionData.sort((a1, a2) => {
return Number(a1.accountUpdateId) - Number(a2.accountUpdateId);
});
} else {
// sort actions within one block by transaction sequence number and account update sequence
actionData = actionData.sort((a1, a2) => {
const a1TxSequence = a1.transactionInfo!.sequenceNumber;
const a2TxSequence = a2.transactionInfo!.sequenceNumber;
if (a1TxSequence === a2TxSequence) {
const a1AuSequence =
a1.transactionInfo!.zkappAccountUpdateIds.indexOf(
Number(a1.accountUpdateId)
);
const a2AuSequence =
a2.transactionInfo!.zkappAccountUpdateIds.indexOf(
Number(a2.accountUpdateId)
);
return a1AuSequence - a2AuSequence;
} else {
return a1TxSequence - a2TxSequence;
}
});
}

// split actions by account update
let actionsByAccountUpdate: string[][][] = [];
Expand Down
Loading
Loading