fix quadratic seq assignment in fork choice (#1805)
this would reallocate the attestation queue on every attestation and other call to update_time, causing quite the overhead (~10% cpu spent when gossiping)
This commit is contained in:
parent
596600058a
commit
99afafecd7
|
@ -117,10 +117,11 @@ proc on_tick(self: var Checkpoints, dag: ChainDAGRef, time: Slot): FcResult[void
|
||||||
|
|
||||||
proc process_attestation_queue(self: var ForkChoice) {.gcsafe.}
|
proc process_attestation_queue(self: var ForkChoice) {.gcsafe.}
|
||||||
proc update_time(self: var ForkChoice, dag: ChainDAGRef, time: Slot): FcResult[void] =
|
proc update_time(self: var ForkChoice, dag: ChainDAGRef, time: Slot): FcResult[void] =
|
||||||
while time > self.checkpoints.time:
|
if time > self.checkpoints.time:
|
||||||
? on_tick(self.checkpoints, dag, self.checkpoints.time + 1)
|
while time > self.checkpoints.time:
|
||||||
|
? on_tick(self.checkpoints, dag, self.checkpoints.time + 1)
|
||||||
|
|
||||||
self.process_attestation_queue()
|
self.process_attestation_queue() # Only run if time changed!
|
||||||
|
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
|
@ -150,18 +151,14 @@ func process_attestation*(
|
||||||
new_vote = shortLog(vote)
|
new_vote = shortLog(vote)
|
||||||
|
|
||||||
proc process_attestation_queue(self: var ForkChoice) =
|
proc process_attestation_queue(self: var ForkChoice) =
|
||||||
var
|
self.queuedAttestations.keepItIf:
|
||||||
keep: seq[QueuedAttestation]
|
if it.slot < self.checkpoints.time:
|
||||||
for attestation in self.queuedAttestations:
|
for validator_index in it.attesting_indices:
|
||||||
if attestation.slot < self.checkpoints.time:
|
|
||||||
for validator_index in attestation.attesting_indices:
|
|
||||||
self.backend.process_attestation(
|
self.backend.process_attestation(
|
||||||
validator_index, attestation.block_root,
|
validator_index, it.block_root, it.slot.epoch())
|
||||||
attestation.slot.epoch())
|
false
|
||||||
else:
|
else:
|
||||||
keep.add attestation
|
true
|
||||||
|
|
||||||
self.queuedAttestations = keep
|
|
||||||
|
|
||||||
func contains*(self: ForkChoiceBackend, block_root: Eth2Digest): bool =
|
func contains*(self: ForkChoiceBackend, block_root: Eth2Digest): bool =
|
||||||
## Returns `true` if a block is known to the fork choice
|
## Returns `true` if a block is known to the fork choice
|
||||||
|
|
Loading…
Reference in New Issue