Skip to content

Conversation

@natanasow
Copy link
Member

@natanasow natanasow commented Nov 13, 2025

Description

Implement in-memory locking for single-instance deployments

  • Implement LocalLockStrategy with async-mutex wrapper
  • Add LRU cache for lock states (add number of maximum transactions)
  • Implement acquireLock()
  • Implement releaseLock()
  • Add force release mechanism with 30s execution timer

Related issue(s)

Fixes #4593

Testing Guide

Changes from original design (optional)

N/A

Additional work needed (optional)

N/A

Checklist

  • I've assigned an assignee to this PR and related issue(s) (if applicable)
  • I've assigned a label to this PR and related issue(s) (if applicable)
  • I've assigned a milestone to this PR and related issue(s) (if applicable)
  • I've updated documentation (code comments, README, etc. if applicable)
  • I've done sufficient testing (unit, integration, etc.)

Signed-off-by: nikolay <n.atanasow94@gmail.com>
@natanasow natanasow self-assigned this Nov 13, 2025
@natanasow natanasow added the enhancement New feature or request label Nov 13, 2025
@natanasow natanasow added this to the 0.74.0 milestone Nov 13, 2025
@natanasow natanasow changed the base branch from main to feat/nonce-ordering-with-locks November 13, 2025 15:12
Signed-off-by: nikolay <n.atanasow94@gmail.com>
Signed-off-by: nikolay <n.atanasow94@gmail.com>
Signed-off-by: nikolay <n.atanasow94@gmail.com>
@natanasow natanasow marked this pull request as ready for review November 13, 2025 15:19
@natanasow natanasow requested review from a team as code owners November 13, 2025 15:19
@natanasow natanasow requested a review from acuarica November 13, 2025 15:19
Signed-off-by: nikolay <n.atanasow94@gmail.com>
Signed-off-by: nikolay <n.atanasow94@gmail.com>
if (!this.localLockStates.has(address)) {
this.localLockStates.set(address, {
mutex: new Mutex(),
sessionKey: null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not pass the session key here when creating the state?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are defined here, but yeah, the sessionKey might be passed as a parameter. Will edit it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we pass the sessionKey here and only set it when address doesn’t exist yet, then how would we assign the sessionKey when the address already exists in localLockStates? Keep in mind we never delete entries from localLockStates we only reset their fields.

So to set the sessionKey for an existing address, we’d have to assign it again anyway. That feels unnecessary, and I think assigning the sessionKey after mutex.acquire() as we currently do makes more sense.

Signed-off-by: nikolay <n.atanasow94@gmail.com>
Signed-off-by: nikolay <n.atanasow94@gmail.com>
Copy link
Contributor

@quiet-node quiet-node left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool left couple of suggestions and comment, and one more thing we need to fix before merging.

*Update: seems like you reverted changes in TransactionService that's why my comment on that class is not showing.

if (!this.localLockStates.has(address)) {
this.localLockStates.set(address, {
mutex: new Mutex(),
sessionKey: null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we pass the sessionKey here and only set it when address doesn’t exist yet, then how would we assign the sessionKey when the address already exists in localLockStates? Keep in mind we never delete entries from localLockStates we only reset their fields.

So to set the sessionKey for an existing address, we’d have to assign it again anyway. That feels unnecessary, and I think assigning the sessionKey after mutex.acquire() as we currently do makes more sense.

@natanasow
Copy link
Member Author

Cool left couple of suggestions and comment, and one more thing we need to fix before merging.

*Update: seems like you reverted changes in TransactionService that's why my comment on that class is not showing.

Yep, it was part of #4595, and I used it for local test purposes only.

Signed-off-by: nikolay <n.atanasow94@gmail.com>
Signed-off-by: nikolay <n.atanasow94@gmail.com>
Signed-off-by: nikolay <n.atanasow94@gmail.com>
@natanasow natanasow requested a review from quiet-node November 18, 2025 14:05
@natanasow
Copy link
Member Author

@konstantinabl all comments are resolved ✅.

Signed-off-by: nikolay <n.atanasow94@gmail.com>
Copy link
Contributor

@quiet-node quiet-node left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM one small item can address in next follow up PR

Signed-off-by: nikolay <n.atanasow94@gmail.com>
Copy link
Contributor

@quiet-node quiet-node left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work as always!

@konstantinabl konstantinabl merged commit 6ae725a into feat/nonce-ordering-with-locks Nov 19, 2025
6 of 7 checks passed
@konstantinabl konstantinabl deleted the 4593-create-local-lock-strategy branch November 19, 2025 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create Local Lock Strategy

4 participants