@@ -157,7 +157,7 @@ proc dumpInvalidBlock*(
157157proc dumpBlock (
158158 self: BlockProcessor ,
159159 signedBlock: ForkySignedBeaconBlock ,
160- res: Result [void , VerifierError ]) =
160+ res: Result [BlockRef , VerifierError ]) =
161161 if self.dumpEnabled and res.isErr:
162162 case res.error
163163 of VerifierError .Invalid :
@@ -168,7 +168,7 @@ proc dumpBlock(
168168 discard
169169
170170from ../ consensus_object_pools/ block_clearance import
171- addBackfillBlock, addHeadBlockWithParent, checkHeadBlock
171+ addBackfillBlock, addHeadBlockWithParent, checkHeadBlock, verifyBlockProposer
172172
173173proc verifySidecars (
174174 signedBlock: ForkySignedBeaconBlock ,
@@ -179,10 +179,7 @@ proc verifySidecars(
179179 when consensusFork == ConsensusFork .Gloas :
180180 # For Gloas, we still need to store the columns if they're provided
181181 # but skip validation since we don't have kzg_commitments in the block
182- if sidecarsOpt.isSome:
183- debugGloasComment " potentially validate against payload envelope"
184- let columns = sidecarsOpt.get ()
185- discard
182+ debugGloasComment " potentially validate against payload envelope"
186183 elif consensusFork == ConsensusFork .Fulu :
187184 if sidecarsOpt.isSome:
188185 let columns = sidecarsOpt.get ()
@@ -332,29 +329,6 @@ proc getExecutionValidity(
332329
333330 Opt .some (optimisticStatus)
334331
335- proc checkBlobOrColumnlessSignature (
336- self: BlockProcessor ,
337- signed_beacon_block: deneb.SignedBeaconBlock | electra.SignedBeaconBlock |
338- fulu.SignedBeaconBlock ):
339- Result [void , cstring ] =
340- let dag = self.consensusManager.dag
341- let parent = dag.getBlockRef (signed_beacon_block.message.parent_root).valueOr:
342- return err (" checkBlobOrColumnlessSignature called with orphan block" )
343- let proposer = getProposer (
344- dag, parent, signed_beacon_block.message.slot).valueOr:
345- return err (" checkBlobOrColumnlessSignature: Cannot compute proposer" )
346- if distinctBase (proposer) != signed_beacon_block.message.proposer_index:
347- return err (" checkBlobOrColumnlessSignature: Incorrect proposer" )
348- if not verify_block_signature (
349- dag.forkAtEpoch (signed_beacon_block.message.slot.epoch),
350- getStateField (dag.headState, genesis_validators_root),
351- signed_beacon_block.message.slot,
352- signed_beacon_block.root,
353- dag.validatorKey (proposer).get (),
354- signed_beacon_block.signature):
355- return err (" checkBlobOrColumnlessSignature: Invalid proposer signature" )
356- ok ()
357-
358332proc addBlock * (
359333 self: ref BlockProcessor ,
360334 src: MsgSource ,
@@ -387,55 +361,46 @@ proc enqueueBlock*(
387361 # `addBlock` should be used where managing backpressure is appropriate.
388362 discard self.addBlock (src, blck, sidecarsOpt, maybeFinalized, validationDur)
389363
390- proc enqueueQuarantine (self: ref BlockProcessor , root: Eth2Digest ) =
364+ proc enqueueQuarantine (self: ref BlockProcessor , parent: BlockRef ) =
391365 # # Enqueue blocks whose parent is `root` - ie when `root` has been added to
392366 # # the blockchain dag, its direct descendants are now candidates for
393367 # # processing
394- for quarantined in self.consensusManager.quarantine[].pop (root):
368+ let
369+ dag = self.consensusManager[].dag
370+ quarantine = self.consensusManager[].quarantine
371+ for quarantined in quarantine[].pop (parent.root):
395372 # Process the blocks that had the newly accepted block as parent
396- debug " Block from quarantine" ,
397- blockRoot = shortLog (root), quarantined = shortLog (quarantined.root)
373+ debug " Block from quarantine" , parent, quarantined = shortLog (quarantined.root)
398374
399375 withBlck (quarantined):
400376 when consensusFork == ConsensusFork .Gloas :
401377 debugGloasComment " "
402- self.enqueueBlock (
403- MsgSource .gossip, forkyBlck, Opt .none (gloas.DataColumnSidecars ))
378+ const sidecarsOpt = noSidecars
404379 elif consensusFork == ConsensusFork .Fulu :
405- if len (forkyBlck.message.body.blob_kzg_commitments) == 0 :
406- self.enqueueBlock (
407- MsgSource .gossip, forkyBlck, Opt .some (fulu.DataColumnSidecars @ [])
408- )
409- else :
410- if (let res = checkBlobOrColumnlessSignature (self[], forkyBlck); res.isErr):
411- warn " Failed to verify signature of unorphaned blobless block" ,
412- blck = shortLog (forkyBlck), error = res.error ()
413- continue
414- let cres = self.dataColumnQuarantine[].popSidecars (forkyBlck.root, forkyBlck)
415- if cres.isSome:
416- self.enqueueBlock (MsgSource .gossip, forkyBlck, cres)
417- else :
418- discard self.consensusManager.quarantine[].addSidecarless (
419- self.consensusManager[].dag.finalizedHead.slot, forkyBlck
420- )
380+ let sidecarsOpt =
381+ self.dataColumnQuarantine[].popSidecars (forkyBlck.root, forkyBlck)
421382 elif consensusFork in ConsensusFork .Deneb .. ConsensusFork .Electra :
422- if len (forkyBlck.message.body.blob_kzg_commitments) == 0 :
423- self.enqueueBlock (MsgSource .gossip, forkyBlck, Opt .some (BlobSidecars @ []))
424- else :
425- if (let res = checkBlobOrColumnlessSignature (self[], forkyBlck); res.isErr):
426- warn " Failed to verify signature of unorphaned columnless block" ,
427- blck = shortLog (forkyBlck), error = res.error ()
428- continue
429- let bres = self.blobQuarantine[].popSidecars (forkyBlck.root, forkyBlck)
430- if bres.isSome ():
431- self.enqueueBlock (MsgSource .gossip, forkyBlck, bres)
432- else :
433- self.consensusManager.quarantine[].addSidecarless (forkyBlck)
383+ let sidecarsOpt = self.blobQuarantine[].popSidecars (forkyBlck.root, forkyBlck)
434384 elif consensusFork in ConsensusFork .Phase0 .. ConsensusFork .Capella :
435- self. enqueueBlock ( MsgSource .gossip, forkyBlck, noSidecars)
385+ const sidecarsOpt = noSidecars
436386 else :
437387 {.error : " Unknown consensus fork " & $ consensusFork.}
438388
389+ when consensusFork in ConsensusFork .Deneb .. ConsensusFork .Fulu :
390+ if not sidecarsOpt.isSome ():
391+ dag.verifyBlockProposer (
392+ parent, forkyBlck.message.slot, forkyBlck.message.proposer_index,
393+ forkyBlck.root, forkyBlck.signature,
394+ ).isOkOr:
395+ warn " Failed to verify signature of unorphaned blobless block" ,
396+ blck = shortLog (forkyBlck), error = error.msg
397+ continue
398+
399+ discard quarantine[].addSidecarless (dag.finalizedHead.slot, forkyBlck)
400+ continue
401+
402+ self.enqueueBlock (MsgSource .gossip, forkyBlck, sidecarsOpt)
403+
439404proc onBlockAdded * (
440405 dag: ChainDAGRef ,
441406 consensusFork: static ConsensusFork ,
@@ -571,7 +536,7 @@ proc storeBlock(
571536 maybeFinalized: bool ,
572537 queueTick: Moment ,
573538 validationDur: Duration ,
574- ): Future [Result [void , VerifierError ]] {.async : (raises: [CancelledError ]).} =
539+ ): Future [Result [BlockRef , VerifierError ]] {.async : (raises: [CancelledError ]).} =
575540 # # storeBlock is the main entry point for unvalidated blocks - all untrusted
576541 # # blocks, regardless of origin, pass through here. When storing a block,
577542 # # we will add it to the dag and pass it to all block consumers that need
@@ -586,9 +551,9 @@ proc storeBlock(
586551 deadlineTime =
587552 block :
588553 let slotTime =
589- (wallSlot + 1 ).start_beacon_time (dag.timeParams) - 1 .seconds
554+ (wallSlot + 1 ).start_beacon_time (dag.timeParams) - chronos .seconds ( 1 )
590555 if slotTime <= wallTime:
591- 0 .seconds
556+ chronos .seconds ( 0 )
592557 else :
593558 chronos.nanoseconds ((slotTime - wallTime).nanoseconds)
594559 deadline = sleepAsync (deadlineTime)
@@ -725,7 +690,7 @@ proc storeBlock(
725690 blck = shortLog (blck),
726691 validationDur, queueDur, newPayloadDur, addHeadBlockDur, updateHeadDur
727692
728- ok ()
693+ ok (blck )
729694
730695proc addBlock * (
731696 self: ref BlockProcessor ,
@@ -776,7 +741,7 @@ proc addBlock*(
776741 # taking up all CPU - we don't want to _completely_ stop processing blocks
777742 # in this case - doing so also allows us to benefit from more batching /
778743 # larger network reads when under load.
779- idleTimeout = 10 .milliseconds
744+ idleTimeout = chronos .milliseconds ( 10 )
780745
781746 discard await idleAsync ().withTimeout (idleTimeout)
782747
@@ -799,15 +764,13 @@ proc addBlock*(
799764
800765 if res.isOk ():
801766 # Once a block is successfully stored, enqueue the direct descendants
802- self.enqueueQuarantine (blockRoot )
767+ self.enqueueQuarantine (res[] )
803768 else :
804769 case res.error ()
805770 of VerifierError .MissingParent :
806771 let finalizedSlot = self.consensusManager.dag.finalizedHead.slot
807772 if (
808- let r = self.consensusManager.quarantine[].addOrphan (
809- finalizedSlot, ForkedSignedBeaconBlock .init (blck)
810- )
773+ let r = self.consensusManager.quarantine[].addOrphan (finalizedSlot, blck)
811774 r.isErr ()
812775 ):
813776 debug " Could not add orphan" ,
@@ -838,4 +801,4 @@ proc addBlock*(
838801 else :
839802 discard
840803
841- res
804+ res. mapConvert ( void )
0 commit comments