avoid some futures and copies in processing pipeline (#2157)

`addLastNoWait` does the same thing with less task scheduling and
copying
This commit is contained in:
Jacek Sieka 2020-12-08 09:59:40 +01:00 committed by GitHub
parent 3b06e0f657
commit f10f29d829
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 15 deletions

View File

@ -79,13 +79,11 @@ proc updateHead*(self: var Eth2Processor, wallSlot: Slot) =
# justified and finalized # justified and finalized
let let
oldFinalized = self.chainDag.finalizedHead.blck oldFinalized = self.chainDag.finalizedHead.blck
oldHead = self.chainDag.head
self.chainDag.updateHead(newHead, self.quarantine) self.chainDag.updateHead(newHead, self.quarantine)
# Cleanup the fork choice v2 if we have a finalized head # Cleanup the fork choice v2 if we have a finalized head
if oldFinalized != self.chainDag.finalizedHead.blck: if oldFinalized != self.chainDag.finalizedHead.blck:
self.attestationPool[].prune() self.attestationPool[].prune()
proc dumpBlock[T]( proc dumpBlock[T](
@ -318,14 +316,19 @@ proc attestationValidator*(
beacon_attestation_delay.observe(delay.toFloatSeconds()) beacon_attestation_delay.observe(delay.toFloatSeconds())
while self.attestationsQueue.full(): while self.attestationsQueue.full():
let dropped = self.attestationsQueue.popFirst() try:
doAssert dropped.finished, "popFirst sanity" notice "Queue full, dropping attestation",
notice "Queue full, dropping attestation", dropped = shortLog(self.attestationsQueue[0].v)
dropped = shortLog(dropped.read().v) discard self.attestationsQueue.popFirstNoWait()
except CatchableError as exc:
raiseAssert "If queue is full, we have at least one item! " & exc.msg
trace "Attestation validated" trace "Attestation validated"
traceAsyncErrors self.attestationsQueue.addLast( try:
AttestationEntry(v: attestation, attesting_indices: v.get())) self.attestationsQueue.addLastNoWait(
AttestationEntry(v: attestation, attesting_indices: v.get()))
except CatchableError as exc:
raiseAssert "We just checked that queue is not full! " & exc.msg
ValidationResult.Accept ValidationResult.Accept
@ -361,15 +364,20 @@ proc aggregateValidator*(
beacon_aggregate_delay.observe(delay.toFloatSeconds()) beacon_aggregate_delay.observe(delay.toFloatSeconds())
while self.aggregatesQueue.full(): while self.aggregatesQueue.full():
let dropped = self.aggregatesQueue.popFirst() try:
doAssert dropped.finished, "popFirst sanity" notice "Queue full, dropping aggregate",
notice "Queue full, dropping aggregate", dropped = shortLog(self.aggregatesQueue[0].v)
dropped = shortLog(dropped.read().v) discard self.aggregatesQueue.popFirstNoWait()
except CatchableError as exc:
raiseAssert "We just checked that queue is not full! " & exc.msg
trace "Aggregate validated" trace "Aggregate validated"
traceAsyncErrors self.aggregatesQueue.addLast(AggregateEntry( try:
v: signedAggregateAndProof.message.aggregate, self.aggregatesQueue.addLastNoWait(AggregateEntry(
attesting_indices: v.get())) v: signedAggregateAndProof.message.aggregate,
attesting_indices: v.get()))
except CatchableError as exc:
raiseAssert "We just checked that queue is not full! " & exc.msg
ValidationResult.Accept ValidationResult.Accept