Skip to content

Commit 064b158

Browse files
committed
some more changes, caller functions
1 parent a561bd6 commit 064b158

File tree

5 files changed

+76
-24
lines changed

5 files changed

+76
-24
lines changed

beacon_chain/gossip_processing/block_processor.nim

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ proc verifySidecars(
183183
): Result[void, VerifierError] =
184184
const consensusFork = typeof(signedBlock).kind
185185

186-
when consensusFork == ConsensusFork.Gloas:
186+
when sidecarsOpt is NoSidecars:
187+
static: doAssert consensusFork in ConsensusFork.Phase0 .. ConsensusFork.Capella
188+
elif consensusFork == ConsensusFork.Gloas:
187189
# For Gloas, we still need to store the columns if they're provided
188190
# but skip validation since we don't have kzg_commitments in the block
189191
debugGloasComment "potentially validate against payload envelope"
@@ -219,8 +221,6 @@ proc verifySidecars(
219221
signature = shortLog(signedBlock.signature),
220222
msg = r.error()
221223
return err(VerifierError.Invalid)
222-
elif consensusFork in ConsensusFork.Phase0 .. ConsensusFork.Capella:
223-
static: doAssert sidecarsOpt is NoSidecars
224224
else:
225225
{.error: "Unknown consensus fork " & $consensusFork.}
226226

@@ -394,7 +394,8 @@ proc enqueueQuarantine(self: ref BlockProcessor, parent: BlockRef) =
394394
withBlck(quarantined):
395395
when consensusFork == ConsensusFork.Gloas:
396396
debugGloasComment ""
397-
const sidecarsOpt = noSidecars
397+
# Representing only Phase0 -> Capella sidecars as `noSidecars` for now
398+
let sidecarsOpt = Opt.none(gloas.DataColumnSidecars)
398399
elif consensusFork == ConsensusFork.Fulu:
399400
let sidecarsOpt =
400401
if len(forkyBlck.message.body.blob_kzg_commitments) == 0:

beacon_chain/networking/eth2_network.nim

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2840,14 +2840,24 @@ proc broadcastBlobSidecar*(
28402840

28412841
proc broadcastDataColumnSidecar*(
28422842
node: Eth2Node, subnet_id: uint64,
2843-
data_column: fulu.DataColumnSidecar | gloas.DataColumnSidecar):
2843+
data_column: fulu.DataColumnSidecar):
28442844
Future[SendResult] {.async: (raises: [CancelledError], raw: true).} =
28452845
let
28462846
contextEpoch = data_column.signed_block_header.message.slot.epoch
28472847
topic = getDataColumnSidecarTopic(
28482848
node.forkDigestAtEpoch(contextEpoch), subnet_id)
28492849
node.broadcast(topic, data_column)
28502850

2851+
proc broadcastDataColumnSidecar*(
2852+
node: Eth2Node, subnet_id: uint64,
2853+
data_column: gloas.DataColumnSidecar):
2854+
Future[SendResult] {.async: (raises: [CancelledError], raw: true).} =
2855+
let
2856+
contextEpoch = data_column.slot.epoch
2857+
topic = getDataColumnSidecarTopic(
2858+
node.forkDigestAtEpoch(contextEpoch), subnet_id)
2859+
node.broadcast(topic, data_column)
2860+
28512861
proc broadcastSyncCommitteeMessage*(
28522862
node: Eth2Node, msg: SyncCommitteeMessage,
28532863
subcommitteeIdx: SyncSubcommitteeIndex):

beacon_chain/rpc/rest_beacon_api.nim

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,10 +1048,9 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
10481048
doAssert strictVerification notin node.dag.updateFlags
10491049
return RestApiResponse.jsonError(Http400, InvalidBlockObjectError)
10501050

1051-
when consensusFork in [ConsensusFork.Deneb, ConsensusFork.Electra]:
1051+
when consensusFork == ConsensusFork.Gloas:
10521052
await node.router.routeSignedBeaconBlock(
1053-
forkyBlck, Opt.some(
1054-
forkyBlck.create_blob_sidecars(kzg_proofs, blobs)),
1053+
forkyBlck, Opt.none(seq[gloas.DataColumnSidecar]),
10551054
checkValidator = true)
10561055
elif consensusFork >= ConsensusFork.Fulu and
10571056
consensusFork < ConsensusFork.Gloas:
@@ -1062,6 +1061,11 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
10621061
forkyBlck,
10631062
Opt.some(data_columns),
10641063
checkValidator = true)
1064+
elif consensusFork in [ConsensusFork.Deneb, ConsensusFork.Electra]:
1065+
await node.router.routeSignedBeaconBlock(
1066+
forkyBlck, Opt.some(
1067+
forkyBlck.create_blob_sidecars(kzg_proofs, blobs)),
1068+
checkValidator = true)
10651069
else:
10661070
await node.router.routeSignedBeaconBlock(
10671071
forkyBlck,
@@ -1198,8 +1202,12 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
11981202

11991203
let res = withBlck(forked):
12001204
forkyBlck.root = hash_tree_root(forkyBlck.message)
1201-
await node.router.routeSignedBeaconBlock(
1202-
forkyBlck, noSidecarsAtFork, checkValidator = true)
1205+
when consensusFork >= ConsensusFork.Bellatrix:
1206+
return RestApiResponse.jsonError(
1207+
Http400, $consensusFork & " builder API unsupported")
1208+
else:
1209+
await node.router.routeSignedBeaconBlock(
1210+
forkyBlck, noSidecarsAtFork, checkValidator = true)
12031211

12041212
if res.isErr():
12051213
return RestApiResponse.jsonError(

beacon_chain/validators/beacon_validators.nim

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -574,18 +574,21 @@ proc proposeBlockAux(
574574
message: engineBlock.blck, signature: signature, root: blockRoot
575575
)
576576

577-
when consensusFork in [ConsensusFork.Deneb, ConsensusFork.Electra]:
578-
let sidecarsOpt =
579-
Opt.some(
580-
signedBlock.create_blob_sidecars(
581-
engineBlock.blobsBundle.proofs,
582-
engineBlock.blobsBundle.blobs))
577+
when consensusFork == ConsensusFork.Gloas:
578+
# using noSidecars for Phase0 -> Capella blocks for now
579+
let sidecarsOpt = Opt.none(seq[gloas.DataColumnSidecar])
583580
elif consensusFork >= ConsensusFork.Fulu and
584581
consensusFork < ConsensusFork.Gloas:
585582
let sidecarsOpt =
586583
Opt.some(signedBlock.assemble_data_column_sidecars(
587584
engineBlock.blobsBundle.blobs.mapIt(kzg.KzgBlob(bytes: it)),
588585
@(engineBlock.blobsBundle.proofs.mapIt(kzg.KzgProof(it)))))
586+
elif consensusFork in [ConsensusFork.Deneb, ConsensusFork.Electra]:
587+
let sidecarsOpt =
588+
Opt.some(
589+
signedBlock.create_blob_sidecars(
590+
engineBlock.blobsBundle.proofs,
591+
engineBlock.blobsBundle.blobs))
589592
else:
590593
const sidecarsOpt = noSidecarsAtFork
591594

beacon_chain/validators/message_router.nim

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,43 @@ proc publishRouteBlock(
145145
signature = shortLog(blck.signature),
146146
delay
147147

148+
proc publishSidecars(
149+
router: ref MessageRouter,
150+
blck: gloas.SignedBeaconBlock,
151+
sidecarsOpt: Opt[seq[gloas.DataColumnSidecar]]
152+
): Future[Opt[gloas.DataColumnSidecars]] {.async: (raises: [CancelledError]).} =
153+
let cols = sidecarsOpt.get()
154+
var workers = newSeq[Future[SendResult]](len(cols))
155+
156+
for i, dc in cols:
157+
let subnet = compute_subnet_for_data_column_sidecar(dc.index)
158+
workers[i] = router[].network.broadcastDataColumnSidecar(subnet, dc)
159+
160+
let resAll = await allFinished(workers)
161+
162+
for i in 0..<resAll.len:
163+
let r = resAll[i]
164+
doAssert r.finished()
165+
if r.failed():
166+
notice "Data column not sent",
167+
data_column = shortLog(cols[i]), error = r.error[]
168+
else:
169+
notice "Data column sent",
170+
data_column = shortLog(cols[i])
171+
172+
# Custody filtering
173+
let metadata = router[].network.metadata.custody_group_count
174+
let allowed =
175+
router[].network.cfg.resolve_columns_from_custody_groups(
176+
router[].network.nodeId, metadata)
177+
178+
var finalCols: gloas.DataColumnSidecars
179+
for dc in cols:
180+
if dc.index in allowed:
181+
finalCols.add newClone(dc)
182+
183+
Opt.some(finalCols)
184+
148185
proc publishSidecars(
149186
router: ref MessageRouter,
150187
blck: fulu.SignedBeaconBlock,
@@ -267,15 +304,8 @@ proc routeSignedBeaconBlock*(
267304
await router.publishRouteBlock(blck)
268305

269306
# 3. Publish sidecars
270-
when someSidecarsOpt is NoSidecarsAtFork and
271-
typeof(blck).kind in ConsensusFork.Phase0..ConsensusFork.Capella:
307+
when someSidecarsOpt is NoSidecarsAtFork:
272308
const finalSidecars = noSidecars
273-
elif someSidecarsOpt is NoSidecarsAtFork and
274-
typeof(blck).kind in ConsensusFork.Deneb..ConsensusFork.Electra:
275-
let finalSidecars = Opt.none(BlobSidecars)
276-
elif someSidecarsOpt is NoSidecarsAtFork and
277-
typeof(blck).kind in ConsensusFork.Fulu..ConsensusFork.Gloas:
278-
let finalSidecars = Opt.none(fulu.DataColumnSidecars)
279309
else:
280310
let finalSidecars = await publishSidecars(router, blck, someSidecarsOpt)
281311

0 commit comments

Comments
 (0)