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

Fix fetchActions #844

Merged
merged 1 commit into from
Apr 11, 2023
Merged

Fix fetchActions #844

merged 1 commit into from
Apr 11, 2023

Conversation

Comdex
Copy link
Contributor

@Comdex Comdex commented Apr 11, 2023

@@ -837,7 +839,7 @@ async function fetchActions(
actions: currentActionList,
hash: Ledger.fieldToBase58(Field(latestActionsHash)),
});
currentAccountUpdateId = accountUpdateId;
Copy link
Collaborator

Choose a reason for hiding this comment

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

are we sure we want to remove this? if yes, why? in this else branch, we don't have accountUpdateId === currentAccountUpdateId so the line is not redundant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, sure, because the code after the end of this branch will also perform this operation.
You can see the code comments below:

fetchedActions.forEach((fetchedAction) => {
    const { actionData } = fetchedAction;
    let latestActionsHash = Field(fetchedAction.actionState.actionStateTwo);
    let actionState = Field(fetchedAction.actionState.actionStateOne);

    if (actionData.length === 0)
      throw new Error(
        `No action data was found for the account ${publicKey} with the latest action state ${actionState}`
      );

    let { accountUpdateId: currentAccountUpdateId } = actionData[0];
    let currentActionList: string[][] = [];

    actionData.forEach((action, i) => {
      const { accountUpdateId, data } = action;
      const isLastAction = i === actionData.length - 1;
      const isSameAccountUpdate = accountUpdateId === currentAccountUpdateId;

      if (isSameAccountUpdate && !isLastAction) {
        currentActionList.push(data);
        currentAccountUpdateId = accountUpdateId;
        return;
      } else if (isSameAccountUpdate && isLastAction) {
        currentActionList.push(data);
      } else if (!isSameAccountUpdate && isLastAction) {
        // branch 3
        latestActionsHash = processActionData(
          currentActionList,
          latestActionsHash
        );
        actionsList.push({
          actions: currentActionList,
          hash: Ledger.fieldToBase58(Field(latestActionsHash)),
        });
        // The following line of code is redundant
        currentAccountUpdateId = accountUpdateId;
        currentActionList = [data];
      }

      latestActionsHash = processActionData(
        currentActionList,
        latestActionsHash
      );
      actionsList.push({
        actions: currentActionList,
        hash: Ledger.fieldToBase58(Field(latestActionsHash)),
      });
      // After the above branch 3 is executed, the currentAccoutUpdateId will also be updated here
      currentAccountUpdateId = accountUpdateId;
      currentActionList = [data];
    });

Copy link
Collaborator

Choose a reason for hiding this comment

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

thanks!

Copy link
Collaborator

@mitschabaude mitschabaude left a comment

Choose a reason for hiding this comment

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

The fix makes sense to me -- previously, we reversed the blocks of fetched actions, now we're also reversing them within each block. But would be nice @MartinMinkov if you could also approve this

@Comdex
Copy link
Contributor Author

Comdex commented Apr 11, 2023

I just found another issue. The behavior of zkapp.reducer.getActions under LocalBlockChain and Berkeley is different. Under the Berkeley network, executing the getActions method will also get the action corresponding to fromActionState, but it does not under LocalBlockChain. In my personal opinion, the handling of LocalBlockChain is more user-friendly because the action that corresponds to fromActionState is typically already processed. If we want to solve this problem, there are two feasible solutions: handling it in the 'fetchActions' or processing it on the archive node side. What do you think about this? @mitschabaude @MartinMinkov

@mitschabaude
Copy link
Collaborator

I just found another issue. The behavior of zkapp.reducer.getActions under LocalBlockChain and Berkeley is different. Under the Berkeley network, executing the getActions method will also get the action corresponding to fromActionState, but it does not under LocalBlockChain. In my personal opinion, the handling of LocalBlockChain is more user-friendly because the action that corresponds to fromActionState is typically already processed. If we want to solve this problem, there are two feasible solutions: handling it in the 'fetchActions' or processing it on the archive node side. What do you think about this? @mitschabaude @MartinMinkov

Thanks for digging into this @Comdex. I agree - the actionState usually refers to the state after hashing some particular action. We don't want to include that action when we fetch fromActionState -- we want to start with the next one

@mitschabaude mitschabaude merged commit dc5c718 into o1-labs:main Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants