-
Notifications
You must be signed in to change notification settings - Fork 227
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
More efficient implementation of the 'POST beacon_committee_subscriptions' API #3153
Conversation
@@ -503,30 +503,38 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) = | |||
if not(node.isSynced(node.dag.head)): | |||
return RestApiResponse.jsonError(Http503, BeaconNodeInSyncError) | |||
|
|||
let | |||
wallSlot = node.beaconClock.now.slotOrZero |
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.
Variables were hoisted outside of the loop.
for duty in tracker.duties.mitems(): | ||
if duty == newDuty: | ||
return | ||
if newDuty in tracker.duties: |
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.
Quadratic complexity was eliminated through switching to a HashSet
.
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 hashset is certainly an improvement - fwiw, there exists an alternative implementation that @tersec was employing before, that was lost in refactoring: instead of storing each duty in a collection one can assign the bit field of subnets to listen to with an or
operation, so that each duty sets bits for the slot within the epoch and those before - it makes for some ugly code but turns the new duty assignment into a constant operation with bounded memory - in hindsight it probably would have made sense to port that implementation to here.
No description provided.