o1js icon indicating copy to clipboard operation
o1js copied to clipboard

Correcting order for actions occuring within the same block for the same account

Open 45930 opened this issue 6 months ago • 12 comments

The community has raised this issue where their reducer cannot correctly derive the action hash given the response from the archive node. This only happens when multiple actions are dispatched within the same block.

The zk noid team shared this minimal repro: https://github.com/aii23/actions_issue_poc

The issue is that events from the archive node arrive in the wrong order for producing the actions hash.

For example, running their script against a light node can produce a graphQL response like:

[
  {
    accountUpdateId: '3',
    data: [
      '23293912831932499872034135232525254163343702531942971872613724597787050731163',
      '1'
    ]
  }
]
[
  {
    accountUpdateId: '5',
    data: [
      '19698539030616983614904223910467017498097850769349730675723779555348012696719',
      '0'
    ]
  }
]
[
  {
    accountUpdateId: '7',
    data: [
      '23344670544599826568585832059189005555232761671965680539590523406038183782503',
      '1'
    ]
  },
  {
    accountUpdateId: '6',
    data: [
      '23379676726753250474018172284972553782392077412995035117267089127972991216710',
      '1'
    ]
  }
]

accountUpdateIds 3 and 5 were dispatched in separate blocks, while accountUpdateIds 6, and 7 were dispatched within the same block. Note the order of the actions top to bottom is [3, 5, 7, 6].

This PR corrects the order by sorting the array by account update id within a single block of actions to correctly represent the order as [3, 5, 6, 7]. I confirmed this fix by running the zk noid script locally against this build of o1js.

45930 avatar Jul 31 '24 16:07 45930