-
Notifications
You must be signed in to change notification settings - Fork 90
feat: create LocalLockStrategy using LRU and async-mutex
#4610
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
feat: create LocalLockStrategy using LRU and async-mutex
#4610
Conversation
Signed-off-by: nikolay <n.atanasow94@gmail.com>
packages/relay/src/lib/services/ethService/transactionService/TransactionService.ts
Outdated
Show resolved
Hide resolved
Signed-off-by: nikolay <n.atanasow94@gmail.com>
Signed-off-by: nikolay <n.atanasow94@gmail.com>
Signed-off-by: nikolay <n.atanasow94@gmail.com>
Signed-off-by: nikolay <n.atanasow94@gmail.com>
Signed-off-by: nikolay <n.atanasow94@gmail.com>
packages/relay/src/lib/services/lockService/LocalLockStrategy.ts
Outdated
Show resolved
Hide resolved
| if (!this.localLockStates.has(address)) { | ||
| this.localLockStates.set(address, { | ||
| mutex: new Mutex(), | ||
| sessionKey: null, |
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.
Why not pass the session key here when creating the state?
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.
They are defined here, but yeah, the sessionKey might be passed as a parameter. Will edit it.
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.
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.
packages/relay/tests/lib/services/lockService/LocalLockStrategy.spec.ts
Outdated
Show resolved
Hide resolved
Signed-off-by: nikolay <n.atanasow94@gmail.com>
Signed-off-by: nikolay <n.atanasow94@gmail.com>
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.
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, |
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.
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.
packages/relay/src/lib/services/lockService/LocalLockStrategy.ts
Outdated
Show resolved
Hide resolved
packages/relay/src/lib/services/lockService/LocalLockStrategy.ts
Outdated
Show resolved
Hide resolved
packages/relay/src/lib/services/lockService/LocalLockStrategy.ts
Outdated
Show resolved
Hide resolved
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>
packages/relay/tests/lib/services/lockService/LocalLockStrategy.spec.ts
Outdated
Show resolved
Hide resolved
packages/relay/tests/lib/services/lockService/LocalLockStrategy.spec.ts
Outdated
Show resolved
Hide resolved
packages/relay/tests/lib/services/lockService/LocalLockStrategy.spec.ts
Outdated
Show resolved
Hide resolved
packages/relay/tests/lib/services/lockService/LocalLockStrategy.spec.ts
Outdated
Show resolved
Hide resolved
packages/relay/tests/lib/services/lockService/LocalLockStrategy.spec.ts
Outdated
Show resolved
Hide resolved
packages/relay/tests/lib/services/lockService/LocalLockStrategy.spec.ts
Outdated
Show resolved
Hide resolved
packages/relay/tests/lib/services/lockService/LocalLockStrategy.spec.ts
Outdated
Show resolved
Hide resolved
Signed-off-by: nikolay <n.atanasow94@gmail.com>
|
@konstantinabl all comments are resolved ✅. |
Signed-off-by: nikolay <n.atanasow94@gmail.com>
quiet-node
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.
LGTM one small item can address in next follow up PR
packages/relay/src/lib/services/lockService/LocalLockStrategy.ts
Outdated
Show resolved
Hide resolved
Signed-off-by: nikolay <n.atanasow94@gmail.com>
quiet-node
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.
Great work as always!
6ae725a
into
feat/nonce-ordering-with-locks
Description
Implement in-memory locking for single-instance deployments
Related issue(s)
Fixes #4593
Testing Guide
Changes from original design (optional)
N/A
Additional work needed (optional)
N/A
Checklist