🧵 server: guarantee nonce order in proposal execution#771
Conversation
🦋 Changeset detectedLatest commit: 48a97e6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Summary of ChangesHello @cruzdanilo, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a potential race condition by ensuring that all proposals associated with a specific account are executed sequentially according to their nonce values. The changes modify the proposal scheduling logic to enforce strict ordering, thereby enhancing the reliability and predictability of proposal processing within the system. Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughA changeset adds a patch release entry for Changes
Sequence Diagram(s)sequenceDiagram
participant BlockHook as Block Hook
participant AccountGroup as Account Group
participant Scheduler as Proposal Scheduler
participant Mutex as Mutex
BlockHook->>AccountGroup: collect proposals (grouped by account)
AccountGroup->>Scheduler: iterate proposals in nonce order
Scheduler->>Mutex: runExclusive(processProposal, -nonce)
Mutex-->>Scheduler: acquire lock
Scheduler->>Scheduler: execute proposal (await)
Scheduler-->>Mutex: release lock
AccountGroup->>Scheduler: next proposal (sequential)
Note over Scheduler,Mutex: idle proposals handled similarly (sequential)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request aims to ensure that proposals are executed in the correct nonce order. However, the implementation has critical flaws related to the introduction of priority in the mutex acquisition. Specifically, there's incorrect library API usage and reversed priority logic, which could lead to inefficient execution or even a re-scheduling loop for accounts with multiple pending proposals. Additionally, converting bigint nonces to number for sorting and priority can cause precision loss for large nonces, further undermining the ordering guarantee.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #771 +/- ##
==========================================
+ Coverage 68.29% 68.46% +0.16%
==========================================
Files 207 207
Lines 6949 7059 +110
Branches 2167 2214 +47
==========================================
+ Hits 4746 4833 +87
- Misses 2013 2029 +16
- Partials 190 197 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
6081080 to
2002246
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@server/hooks/block.ts`:
- Line 396: idleProposals are iterated in the contract-return order and not
sorted by nonce before sequential scheduling; before the for loop that calls
scheduleProposal over idleProposals, sort the idleProposals array by the
proposal.nonce (consistent with the earlier .toSorted(...) usage) so scheduling
happens in nonce order; update the block where idleProposals is built/used
(referencing the idleProposals variable and the scheduleProposal(p) call) to
apply a stable numeric sort by nonce (e.g., use .toSorted or .sort with
(a,b)=>a.nonce-b.nonce) and then iterate the sorted array.
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
Summary by CodeRabbit