-
Notifications
You must be signed in to change notification settings - Fork 91
feat: integrates new lockService in sendRawTransaction #4627
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: feat/nonce-ordering-with-locks
Are you sure you want to change the base?
feat: integrates new lockService in sendRawTransaction #4627
Conversation
0aa4e24 to
8b8bd82
Compare
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## feat/nonce-ordering-with-locks #4627 +/- ##
=================================================================
Coverage ? 94.23%
=================================================================
Files ? 133
Lines ? 21271
Branches ? 1726
=================================================================
Hits ? 20044
Misses ? 1206
Partials ? 21
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
3e754ec to
204f50b
Compare
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
| if (lockSessionKey) { | ||
| //try/catch essential for not masking errors | ||
| try { | ||
| await this.lockService.releaseLock(originalCallerAddress, lockSessionKey); |
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.
Releasing the lock here aligns perfectly with the design doc and works correctly, but it looks like it'd require changing method signatures, even their constructors, across multiple classes, HapiService, SdkClient methods, etc.
Instead, we can simply release the lock in the TransactionService.sendRawTransactionProcessor() method, like this:
// in TransactionService.sendRawTransactionProcessor()
...
const { txSubmitted, submittedTransactionId, error } = await this.submitTransaction(
transactionBuffer,
originalCallerAddress,
networkGasPriceInWeiBars,
requestDetails,
lockSessionKey, // remove this
);
await this.lockService.releaseLock(...); // add release lock here
await this.transactionPoolService.removeTransaction(...);
...From our previous discussion during the txPool implementation, we know TransactionService.submitTransaction() does not throw and instead returns any error. It also doesn’t perform any critical async work. So it should be safe to call releaseLock immediately after it returns.
This approach avoids passing sessionKey and lockService through HapiService and SdkClient.
This'd make the code cleaner, scoped within TransactionService class, while keeping the behavior exactly the same.
Let me know what you think.
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.
Yeah, i will move it, I was wondering if it would affect performance even with a little bit, currently the locks slow down significantly the process of sending a transaction but the difference is under 100ms so its fine. Will fix
| await this.validateRawTransaction(parsedTx, networkGasPriceInWeiBars, requestDetails); | ||
| // Acquire lock FIRST - before any side effects or async operations | ||
| // This ensures proper nonce ordering for transactions from the same sender | ||
| if (parsedTx.from && ConfigService.get('ENABLE_NONCE_ORDERING')) { |
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.
Just as we did in the transaction pool implementation, would it make sense to abstract this feature-specific flag into its own service class?
In this case, ConfigService.get('ENABLE_NONCE_ORDERING') could be encapsulated within LockService, similar to how TransactionPoolService handles its flag.
packages/relay/src/lib/services/ethService/transactionService/TransactionService.ts
Outdated
Show resolved
Hide resolved
|
|
||
| // Create HAPI service | ||
| const hapiService = new HAPIService(this.logger, this.register, hbarLimitService); | ||
| const lockService = new LockService(LockStrategyFactory.create(this.redisClient, this.logger)); |
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: the comment above this line is misleading.
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.
fixed
Co-authored-by: Logan Nguyen <[email protected]> Signed-off-by: konstantinabl <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Description
This PR integrates a new LockService into eth_sendRawTransaction to ensure proper nonce ordering for transactions from the same sender address. The service uses a per-address locking mechanism that prevents concurrent execution of transactions from the same account, thereby avoiding nonce-related race conditions.
Related issue(s)
Fixes #4595
Testing
Changes from original design (optional)
N/A
Additional work needed (optional)
N/A
Checklist