-
Notifications
You must be signed in to change notification settings - Fork 391
hotfix: batcher queue ord #1637
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
Conversation
MarcosNicolau
left a comment
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.
Pretty edgy situation... nice catch. Working on my machine.
| ) -> Result<(), BatcherError> { | ||
| for (vd_batch_idx, entry) in finalized_batch.iter().enumerate() { | ||
| // iter in reverse because each sender wants to receive responses in ascending nonce order | ||
| // and finalized_batch is ordered as the PriorityQueue , low max_nonce first && high nonce first. |
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.
| // and finalized_batch is ordered as the PriorityQueue , low max_nonce first && high nonce first. | |
| // and finalized_batch is ordered as the PriorityQueue , low max_nonce first && high nonce last. |
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.
PriorityQueue is ordered by which elements do we discard first.
So we first discard proofs of low max_fee and high nonce. Because we want the high max_fee and LOW nonce to go in first
JulianVentura
left a comment
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.
Code looks good and works on my machine
| ) -> Result<(), BatcherError> { | ||
| for (vd_batch_idx, entry) in finalized_batch.iter().enumerate() { | ||
| // iter in reverse because each sender wants to receive responses in ascending nonce order | ||
| // and finalized_batch is ordered as the PriorityQueue , low max_nonce first && high nonce first. |
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.
nit:
When we revert this vec, we are also reverting the orden of the proofs to low max_fee first, and higher max_fee last, too.
This shouldn't be a problem, since the sender is waiting until arrival of the last nonce, it doesn't care about the fees.
I think we should add a comment clarifying that.
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.
Priority queue orders first by max_fee.
This means the priorityQueue has ascending max_fee (we first eliminate those with low max_fee). And when max_fee is equal, it has descending nonce (we first eliminate those with high nonce)
This means priorityQueue.rev() has descending max_fee. And when the max_fee is equal, it will have ascending nonce.
This is the desired behaviour, since descending max_fee => ascending nonce, and equal fee => ascending nonce.
Important
This PR was rebased here: #1664
Fix batcher queue ord
Description
There was a bug in the batcher queue ordering of elements, which led to a wrong placement of proofs when a same sender sent proofs with same max_fee.
The consecuence of this bug was seen when the batcher queue is filled, the proofs sent to chain will be not from lowest to highest nonce, but the other way around.
To Test
You can view the unit tests.
Also you can add the following print statements (and can do before this PR so you can verify the bug indeed existed).
in
batcher/aligned-batcher/src/lib.rs, line 1175:in
messaging.rs, line 161:This will help to view the resulting state of the batcher queue.
To execute the bug you should send a burst bigger than the batch_qty limit. For this it is recommended to lower this value,
config-batcher.yaml:Then send a burst of size 8, so that the first batch is of size 5 and the second of size 3. (this ensures you don't get the
batch already submittedcontract revert).For this you can set
BURST_SIZE ?= 8in the Makefile.Type of change
Checklist
testnet, everything else tostaging