Conversation
akobrin1
left a comment
There was a problem hiding this comment.
I think we don't need lock for RequestAction
There was a problem hiding this comment.
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.
Review completed: changes look good. The mutex addition correctly serializes transaction operations to prevent race conditions.
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
Review completed: the introduction of
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| m.mu.Lock() | ||
| defer m.mu.Unlock() |
There was a problem hiding this comment.
Inside SimulateFinalizeCascadeAction, we are calling m.txHelper.GetAccountInfo(ctx) and then m.txHelper.GetCreatorAddress().
Note that GetAccountInfo internally calls GetCreatorAddress to look up the account. By calling GetCreatorAddress again explicitly on the next line (to pass creator to createFinalizeActionMessage), we are duplicating the keyring lookup overhead inside the lock.
Since this is running sequentially under a lock, it might be worth optimizing to fetch the address once and reuse it, or just accepting the overhead if it's negligible. Just a small observation.
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: