add: blob recovery logic
This commit is contained in:
parent
0b4cf1017b
commit
34a2478113
|
@ -140,6 +140,59 @@ proc recover_matrix*(partial_matrix: seq[MatrixEntry], blobCount: int): Result[s
|
||||||
cells.add(e.cell)
|
cells.add(e.cell)
|
||||||
proofs.add(e.kzg_proof)
|
proofs.add(e.kzg_proof)
|
||||||
|
|
||||||
|
proc recover_blobs*(
|
||||||
|
data_columns: seq[DataColumnSidecar],
|
||||||
|
columnCount: int,
|
||||||
|
blck: deneb.SignedBeaconBlock |
|
||||||
|
electra.SignedBeaconBlock |
|
||||||
|
ForkySignedBeaconBlock):
|
||||||
|
Result[seq[KzgBlob], cstring] =
|
||||||
|
|
||||||
|
# This helper recovers blobs from the data column sidecars
|
||||||
|
if not (data_columns.len != 0):
|
||||||
|
return err("DataColumnSidecar: Length should not be 0")
|
||||||
|
|
||||||
|
var blobCount = data_columns[0].len
|
||||||
|
for data_column in data_columns:
|
||||||
|
if not (blobCount == data_column.column.len):
|
||||||
|
return err ("DataColumns do not have the same length")
|
||||||
|
|
||||||
|
var recovered_blobs = newSeqOfCap[KzgBlob](blobCount)
|
||||||
|
|
||||||
|
for blobIdx in 0 ..< blobCount:
|
||||||
|
var
|
||||||
|
cell_ids = newSeqOfCap[CellID](columnCount)
|
||||||
|
ckzgCells = newSeqOfCap[KzgCell](columnCount)
|
||||||
|
|
||||||
|
for data_column in data_columns:
|
||||||
|
cell_ids.add(data_column.index)
|
||||||
|
|
||||||
|
let
|
||||||
|
column = data_column.column
|
||||||
|
cell = column[blobIdx]
|
||||||
|
|
||||||
|
# Transform the cell as a ckzg cell
|
||||||
|
var ckzgCell: Cell
|
||||||
|
for i in 0 ..< int(FIELD_ELEMENTS_PER_CELL):
|
||||||
|
ckzgCell[i] = cell[32*i ..< 32*(i+1)].toArray()
|
||||||
|
|
||||||
|
ckzgCells.add(ckzgCell)
|
||||||
|
|
||||||
|
# Recovering the blob
|
||||||
|
let recovered_cells = recoverAllCells(cell_ids, ckzgCells)
|
||||||
|
if not recovered_cells.isOk:
|
||||||
|
return err (fmt"Recovering all cells for blob - {blobIdx} failed: {recovered_cells.error}")
|
||||||
|
|
||||||
|
let recovered_blob_res = cellsToBlob(recovered_cells.get)
|
||||||
|
if not recovered_blob_res.isOk:
|
||||||
|
return err (fmt"Cells to blob for blob - {blobIdx} failed: {recovered_blob_res.error}")
|
||||||
|
|
||||||
|
recovered_blobs.add(recovered_blob_res.get)
|
||||||
|
|
||||||
|
ok(recovered_blobs)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/5f48840f4d768bf0e0a8156a3ed06ec333589007/specs/_features/eip7594/das-core.md#get_data_column_sidecars
|
# https://github.com/ethereum/consensus-specs/blob/5f48840f4d768bf0e0a8156a3ed06ec333589007/specs/_features/eip7594/das-core.md#get_data_column_sidecars
|
||||||
proc get_data_column_sidecars*(signed_block: deneb.SignedBeaconBlock | electra.SignedBeaconBlock | ForkySignedBeaconBlock, blobs: seq[KzgBlob]): Result[seq[DataColumnSidecar], cstring] =
|
proc get_data_column_sidecars*(signed_block: deneb.SignedBeaconBlock | electra.SignedBeaconBlock | ForkySignedBeaconBlock, blobs: seq[KzgBlob]): Result[seq[DataColumnSidecar], cstring] =
|
||||||
var
|
var
|
||||||
|
|
Loading…
Reference in New Issue