Skip to content

Commit e201a73

Browse files
committed
feat: payload processing
1 parent cb4bbb4 commit e201a73

File tree

3 files changed

+53
-26
lines changed

3 files changed

+53
-26
lines changed

beacon_chain/gossip_processing/block_processor.nim

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,24 @@ proc verifySidecars(
194194
): Result[void, VerifierError] =
195195
const consensusFork = typeof(signedBlock).kind
196196

197-
when consensusFork == ConsensusFork.Gloas:
198-
# For Gloas, we still need to store the columns if they're provided
199-
# but skip validation since we don't have kzg_commitments in the block
200-
debugGloasComment "potentially validate against payload envelope"
197+
when consensusFork >= ConsensusFork.Gloas:
198+
if sidecarsOpt.isSome:
199+
let
200+
signedEnvelope = envelopeOpt.valueOr:
201+
return err(VerifierError.Invalid)
202+
columns = sidecarsOpt.get()
203+
kzgCommits = signedEnvelope.message.blob_kzg_commitments.asSeq
204+
if columns.len > 0 and kzgCommits.len > 0:
205+
for i in 0 ..< columns.len:
206+
let r = verify_data_column_sidecar_kzg_proofs(columns[i][])
207+
if r.isErr():
208+
debug "data column validation failed",
209+
blockRoot = shortLog(signedBlock.root),
210+
column_sidecar = shortLog(columns[i][]),
211+
blck = shortLog(signedBlock.message),
212+
signature = shortLog(signedBlock.signature),
213+
msg = r.error()
214+
return err(VerifierError.Invalid)
201215
elif consensusFork == ConsensusFork.Fulu:
202216
if sidecarsOpt.isSome:
203217
let columns = sidecarsOpt.get()
@@ -262,15 +276,18 @@ proc storeSidecars(self: BlockProcessor, sidecarsOpt: NoSidecars) =
262276
proc enqueuePayload*(self: ref BlockProcessor, blck: gloas.SignedBeaconBlock)
263277

264278
proc storeBackfillBlock(
265-
self: var BlockProcessor,
279+
self: ref BlockProcessor,
266280
signedBlock: ForkySignedBeaconBlock,
267281
sidecarsOpt: SomeOptSidecars,
268282
): Result[void, VerifierError] =
269283
let quarantine = self.consensusManager.quarantine
270284
# In case the block was added to any part of the quarantine..
271285
quarantine[].remove(signedBlock)
272286

273-
?verifySidecars(signedBlock, sidecarsOpt)
287+
const consensusFork = typeof(signedBlock).kind
288+
289+
when consensusFork <= ConsensusFork.Fulu:
290+
?verifySidecars(signedBlock, sidecarsOpt)
274291

275292
let res = self.consensusManager.dag.addBackfillBlock(signedBlock)
276293

@@ -300,8 +317,13 @@ proc storeBackfillBlock(
300317
of VerifierError.Duplicate:
301318
res
302319
else:
303-
# Only store side cars after successfully establishing block viability.
304-
self.storeSidecars(sidecarsOpt)
320+
when consensusFork >= ConsensusFork.Gloas:
321+
# Columns are in quarantine as they didn't pop from `rmanBlockVerifier`,
322+
# we simply enqueue with the valid block.
323+
self.enqueuePayload(signedBlock)
324+
else:
325+
# Only store side cars after successfully establishing block viability.
326+
self[].storeSidecars(sidecarsOpt)
305327

306328
res
307329

@@ -387,7 +409,7 @@ proc enqueueBlock*(
387409
if blck.message.slot <= self.consensusManager.dag.finalizedHead.slot:
388410
# let backfill blocks skip the queue - these are always "fast" to process
389411
# because there are no state rewinds to deal with
390-
discard self[].storeBackfillBlock(blck, sidecarsOpt)
412+
discard self.storeBackfillBlock(blck, sidecarsOpt)
391413
return
392414

393415
# `discard` here means that the `async` task will continue running even though
@@ -411,9 +433,8 @@ proc enqueueQuarantine(self: ref BlockProcessor, parent: BlockRef) =
411433
debug "Block from quarantine", parent, quarantined = shortLog(quarantined.root)
412434

413435
withBlck(quarantined):
414-
when consensusFork == ConsensusFork.Gloas:
415-
debugGloasComment ""
416-
const sidecarsOpt = noSidecars
436+
when consensusFork >= ConsensusFork.Gloas:
437+
let sidecarsOpt = Opt.none(gloas.DataColumnSidecars)
417438
elif consensusFork == ConsensusFork.Fulu:
418439
let sidecarsOpt =
419440
if len(forkyBlck.message.body.blob_kzg_commitments) == 0:
@@ -649,7 +670,8 @@ proc storeBlock(
649670

650671
let newPayloadTick = Moment.now()
651672

652-
?verifySidecars(signedBlock, sidecarsOpt)
673+
when consensusFork <= ConsensusFork.Fulu:
674+
?verifySidecars(signedBlock, sidecarsOpt)
653675

654676
let blck =
655677
?dag.addHeadBlockWithParent(
@@ -667,7 +689,8 @@ proc storeBlock(
667689
self[].lastPayload = signedBlock.message.slot
668690

669691
# write blobs now that block has been written.
670-
self[].storeSidecars(sidecarsOpt)
692+
when consensusFork <= ConsensusFork.Fulu:
693+
self[].storeSidecars(sidecarsOpt)
671694

672695
let addHeadBlockTick = Moment.now()
673696

@@ -717,6 +740,11 @@ proc storeBlock(
717740
blck = shortLog(blck),
718741
validationDur, queueDur, newPayloadDur, addHeadBlockDur, updateHeadDur
719742

743+
when consensusFork >= ConsensusFork.Gloas:
744+
# Enqueue payload here instead of `addBlock` for the consistency of payload
745+
# processing with backfilling.
746+
self.enqueuePayload(signedBlock)
747+
720748
ok(blck)
721749

722750
proc addBlock*(
@@ -749,7 +777,7 @@ proc addBlock*(
749777
if blck.message.slot <= dag.finalizedHead.slot:
750778
# let backfill blocks skip the queue - these are always "fast" to process
751779
# because there are no state rewinds to deal with
752-
return self[].storeBackfillBlock(blck, sidecarsOpt)
780+
return self.storeBackfillBlock(blck, sidecarsOpt)
753781

754782
let queueTick = Moment.now()
755783
let res =

beacon_chain/gossip_processing/eth2_processor.nim

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,11 @@ proc processSignedBeaconBlock*(
282282
if not (isNil(self.dag.onBlockGossipAdded)):
283283
self.dag.onBlockGossipAdded(ForkedSignedBeaconBlock.init(signedBlock))
284284

285-
when consensusFork == ConsensusFork.Gloas:
286-
debugGloasComment ""
287-
# gloas needs proper data column handling
288-
let sidecarsOpt = Opt.some(default(seq[ref gloas.DataColumnSidecar]))
285+
when consensusFork >= ConsensusFork.Gloas:
286+
# Passing none for Gloas to disable processing sidecars at block time. They
287+
# should be retrieved from quarantine and processed at the end of
288+
# `storeBlock` or `storeBackfillBlock`.
289+
let sidecarsOpt = Opt.none(gloas.DataColumnSidecars)
289290
elif consensusFork == ConsensusFork.Fulu:
290291
let sidecarsOpt =
291292
if len(signedBlock.message.body.blob_kzg_commitments) == 0:
@@ -340,7 +341,8 @@ proc processExecutionPayloadEnvelope*(
340341
execution_payload_envelopes_dropped.inc(1, [$error[0]])
341342
return err(error)
342343

343-
debugGloasComment("process execution payload")
344+
self.envelopeQuarantine[].addOrphan(signedEnvelope)
345+
self.blockProcessor.enqueuePayload(signedEnvelope.root)
344346

345347
execution_payload_envelopes_received.inc()
346348
execution_payload_envelope_delay.observe(delay.toFloatSeconds())
@@ -478,10 +480,8 @@ proc processDataColumnSidecar*(
478480
data_column_sidecars_dropped.inc(1, [$v.error[0]])
479481
return v
480482

481-
debugGloasComment ""
482-
# TODO: Implement quarantine logic for Gloas
483-
# For now, just validate and drop
484-
debug "Data column validated (not stored - quarantine TODO)"
483+
debugGloasComment("put into ColumnQuarantine")
484+
self.blockProcessor.enqueuePayload(dataColumnSidecar.beacon_block_root)
485485

486486
data_column_sidecars_received.inc()
487487
v

beacon_chain/nimbus_beacon_node.nim

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,7 @@ proc initFullNode(
475475
maybeFinalized: bool):
476476
Future[Result[void, VerifierError]] {.async: (raises: [CancelledError]).} =
477477
withBlck(signedBlock):
478-
when consensusFork == ConsensusFork.Gloas:
479-
debugGloasComment "no blob_kzg_commitments field for gloas"
478+
when consensusFork >= ConsensusFork.Gloas:
480479
let sidecarsOpt = Opt.none(gloas.DataColumnSidecars)
481480
elif consensusFork == ConsensusFork.Fulu:
482481
let sidecarsOpt =

0 commit comments

Comments
 (0)