-
Notifications
You must be signed in to change notification settings - Fork 0
Add Action Lock #235
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
base: master
Are you sure you want to change the base?
Add Action Lock #235
Conversation
| return nil, err | ||
| } | ||
|
|
||
| m.mu.Lock() |
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.
I think we don't need lock here... RequestAction signed by user, not supernode.
This works just fine now with lots of accounts concurrently.
akobrin1
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.
I think we don't need lock for RequestAction
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.
Pull Request Overview
This PR introduces thread-safe mutex locking to the action module to prevent race conditions during concurrent transaction submissions. The primary concern is preventing nonce conflicts and transaction signing failures when multiple goroutines execute transactions simultaneously.
Key Changes:
- Added
sync.Mutexto the action module struct for mutual exclusion - Protected
RequestActionandFinalizeCascadeActionmethods with mutex locks around transaction execution - Lock is acquired after parameter validation and held during the entire transaction flow (account info retrieval, message creation, signing, and broadcasting)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| type module struct { | ||
| client actiontypes.MsgClient | ||
| txHelper *txmod.TxHelper | ||
| mu sync.Mutex | ||
| } |
Copilot
AI
Nov 20, 2025
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.
The SetTxHelperConfig and GetTxHelper methods access m.txHelper without mutex protection, which could cause race conditions if called concurrently with the now-protected RequestAction or FinalizeCascadeAction methods. Additionally, SimulateFinalizeCascadeAction also accesses m.txHelper without protection.
While the mutex correctly protects the transaction execution in the modified methods, consider whether these other methods that access the shared txHelper state should also be protected to ensure complete thread safety across the module.
Review completed: no blocking issues found in the action locking changes.
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
Summary
Add thread-safe mutex locking to the action module to prevent race conditions when submitting concurrent transactions to the blockchain mempool.
Problem
The action module was experiencing race conditions when multiple goroutines attempted to execute transactions concurrently (e.g., multiple
RequestActionorFinalizeCascadeActioncalls). This caused errors during transaction creation, signing, and broadcasting to the mempool, potentially leading to:Solution
This PR introduces a
sync.Mutexto the action module struct, ensuring that transaction execution is serialized. Thesync.Mutexis a Go synchronizationprimitive that provides mutual exclusion - only one goroutine can hold the lock at a time, forcing all others to wait until the lock is released.
Changes
syncfor mutex supportsync.Mutexin the module structTechnical Details
Each transaction goes through several steps:
Without synchronization, concurrent calls could: