-
Notifications
You must be signed in to change notification settings - Fork 136
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
Correcting order for actions occuring within the same block for the same account #1784
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome that you fixed this @45930, I have a couple of small comments on code style
We found out that fix works not in all the scenarios. We used this patch on our backend. It started working. Then it thrown the same issue.
|
@asimaranov could you please recreate the graphQL JSON response that fails and the order that the patched o1js arrives at? |
You mean this? |
@asimaranov No, I mean can you log out the response from There are other reasons why we may fail to derive the hash, so this will help us pinpoint the issue. |
Tried to recreate issue, that @asimaranov mentioned with current fix. Run on background script that dispatch several actions at once first, and then dispatch 40 more actions one by one. |
Thanks @aii23! 40 should still be a processable number so we want to get to the bottom of it. When you do the test with 40, do all 40 actions show up in the graphql response? |
@aii23 , there is another theory that perhaps the archive node is inconsistent about the most recent actions for actions within the same block. If you do the same test but wait for 2-3 blocks for the archive node to get settled, does that work? Perhaps this can work in prod by setting an endActionState to a couple blocks in the past. |
I will check this later today, or maybe tomorrow, to find exact condition for it to happen. |
I believe from my experience that this number of actions depends upon the time when you check it again, for 128 actions you will see this problem even after an hour, for few actions it should go away almost immediately, so it is better to check the actions immediately after the block is created. |
I would also propose adding pagination to the action fetching logic, as it will be impossible to fetch a large number of actions from the archive node at once. You can see it, for example, trying to fetch events on mainnet for the contract B62qjwDWxjf4LtJ4YWJQDdTNPqZ69ZyeCzbpAFKN7EoZzYig5ZRz8JE: import { fetchEvents, UInt32 } from "o1js";
const contractAddress =
"B62qjwDWxjf4LtJ4YWJQDdTNPqZ69ZyeCzbpAFKN7EoZzYig5ZRz8JE";
describe("Should get events", () => {
it(`should get events`, async () => {
console.log("Fetching events for", contractAddress);
let blockHeight = 375561;
const interval = 1000;
while (blockHeight > 359609) {
try {
const events1 = await fetchEvents(
{ publicKey: contractAddress },
"https://api.minascan.io/archive/mainnet/v1/graphql",
{
from: UInt32.from(blockHeight - interval),
to: UInt32.from(blockHeight),
}
);
console.log("Events1:", blockHeight, events1?.length);
} catch (e) {
console.error("Error fetching events for blocks", blockHeight, e);
}
blockHeight -= interval;
await sleep(1000);
}
});
});
function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
} Increasing the interval to 2000 gives the error:
|
Still trying to find exact conditions on witch all of this happening. Is there a way to configure lightnode, so it produce block faster. Because now to ensure that all transaction goes into different blocks, I need to wait hell lot of time. |
@@ -14,8 +14,7 @@ case $TEST_TYPE in | |||
|
|||
"Reducer integration tests") | |||
echo "Running reducer integration tests" | |||
./run src/examples/zkapps/reducer/actions-as-merkle-list.ts --bundle | |||
./run src/examples/zkapps/reducer/actions-as-merkle-list-iterator.ts --bundle | |||
./run src/examples/zkapps/reducer/run.ts --bundle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change here is because previously these files would run a local test as they were imported. I wrapped the tests in an export and call them explicitly in this run file. This allows the run-live file to import the same smart contracts without too many excess diffs.
// push some actions | ||
|
||
tic('dispatch transactions'); | ||
let dispatchTx = await Mina.transaction(senderSpec, async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this transactions, one sender creates many actions to reduce in the same block
|
||
tic('building'); | ||
const txs = []; | ||
let dispatchTx1 = await Mina.transaction(senderSpec, async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In these transactions, different senders create actions to reduce within the same block
run-ci-live-tests.sh
Outdated
@@ -21,6 +21,8 @@ DEX_PROC=$! | |||
FETCH_PROC=$! | |||
./run src/tests/transaction-flow.ts --bundle | add_prefix "TRANSACTION_FLOW" & | |||
TRANSACTION_FLOW_PROC=$! | |||
./run src/examples/reducer/run-live.ts --bundle | add_prefix "REDUCER" & | |||
REDUCER_FLOW_PROC=$! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New reducer test in CI handles some action serialization cases using lightnet graphql API. The coverage on this is not ultra high, but it's a starting point, and covers the issue that zk noid originally isolated in their repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sure to update the bindings to the proper commit from main
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, good job! Left some comments - do you think we should test some other action-ranges? eg. maxing out all action field sizes and lengths?
@Trivo25 I don't know what this means. Is there a script to run or something? |
but it looks like in this particular instance we can just merge main into this branch to fix the discrepancy |
In general, that seems reasonable. I don't want to bloat the scope of this fix though. This fix is currently blocking usage of actions for devs,so I want to get the corrected functionality out ASAP. |
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:
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.