From 74ee8bb74d107dacb1edb487ed45c7275beed8bf Mon Sep 17 00:00:00 2001 From: Agnish Ghosh Date: Sat, 6 Jul 2024 13:24:51 +0530 Subject: [PATCH] refactor cells and proofs logic + fix edge cases --- beacon_chain/spec/eip7594_helpers.nim | 33 +++++++++++++--------- beacon_chain/sync/request_manager.nim | 4 +-- beacon_chain/validators/message_router.nim | 5 +++- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/beacon_chain/spec/eip7594_helpers.nim b/beacon_chain/spec/eip7594_helpers.nim index 483b6443e..79ad86281 100644 --- a/beacon_chain/spec/eip7594_helpers.nim +++ b/beacon_chain/spec/eip7594_helpers.nim @@ -214,43 +214,48 @@ proc compute_signed_block_header(signed_block: deneb.SignedBeaconBlock | proc get_data_column_sidecars*(signed_block: deneb.SignedBeaconBlock | electra.SignedBeaconBlock, blobs: seq[KzgBlob]): - seq[DataColumnSidecar] = + Result[seq[DataColumnSidecar], string] = var blck = signed_block.message signed_beacon_block_header = compute_signed_block_header(signed_block) cellsAndProofs: seq[KzgCellsAndKzgProofs] kzg_incl_proof: array[4, Eth2Digest] + if blobs.len == 0: + return err ("Blob sequence can't be empty") + for blob in blobs: let - computed_cell = computeCellsAndProofs(blob) + cell_and_proof = computeCellsAndProofs(blob) - if computed_cell.isErr(): + if cell_and_proof.isErr(): return err("EIP7549: Could not compute cells") - cellsAndProofs.add(computed_cell.get()) + if cell_and_proof.isOk: + cellsAndProofs.add(cell_and_proof.get()) let blobCount = blobs.len var - cells: seq[seq[Cell]] - proofs: seq[seq[KzgProof]] + cells = newSeqOfCap[seq[Cell]](blobs.len) + proofs = newSeqOfCap[seq[KzgProof]](blobs.len) for i in 0..= ConsensusFork.Deneb: if blobsOpt.isSome(): let blobs = blobsOpt.get() - let data_columns = get_data_column_sidecars(blck, blobs.mapIt(it.blob)) + let dataColumnsOpt = get_data_column_sidecars(blck, blobs.mapIt(it.blob)) + if not dataColumnsOpt.isOk: + debug "Issue with computing data column from blob bundle" + let data_columns = dataColumnsOpt.get() var das_workers = newSeq[Future[SendResult]](len(data_columns)) for i in 0..