init: add req/res domain for peerdas

This commit is contained in:
Agnish Ghosh 2024-06-14 18:30:16 +05:30
parent 6b0223b078
commit 02e5430468
No known key found for this signature in database
GPG Key ID: 7E927C221EBA4F6E
4 changed files with 56 additions and 0 deletions

View File

@ -254,6 +254,13 @@ func blobkey(root: Eth2Digest, index: BlobIndex) : array[40, byte] =
ret
func columnkey(root: Eth2Digest, index: ColumnIndex) : array[40, byte] =
var ret: array[40, byte]
ret[0..<8] = toBytes(index)
ret[8..<40] = root.data
ret
template expectDb(x: auto): untyped =
# There's no meaningful error handling implemented for a corrupt database or
# full disk - this requires manual intervention, so we'll panic for now
@ -808,11 +815,22 @@ proc putBlobSidecar*(
let block_root = hash_tree_root(value.signed_block_header.message)
db.blobs.putSZSSZ(blobkey(block_root, value.index), value)
proc putDataColumnSidecar*(
db: BeaconChainDB,
value: DataColumnSidecar) =
let block_root = hash_tree_root(value.signed_block_header.message)
db.blobs.putSZSSZ(columnkey(block_root, value.index), value)
proc delBlobSidecar*(
db: BeaconChainDB,
root: Eth2Digest, index: BlobIndex): bool =
db.blobs.del(blobkey(root, index)).expectDb()
proc delDataColumnSidecar*(
db: BeaconChainDB,
root: Eth2Digest, index: ColumnIndex): bool =
db.blobs.del(columnkey(root, index)).expectDb()
proc updateImmutableValidators*(
db: BeaconChainDB, validators: openArray[Validator]) =
# Must be called before storing a state that references the new validators
@ -1071,6 +1089,17 @@ proc getBlobSidecar*(db: BeaconChainDB, root: Eth2Digest, index: BlobIndex,
value: var BlobSidecar): bool =
db.blobs.getSZSSZ(blobkey(root, index), value) == GetResult.found
proc getDataColumnSidecarSZ*(db: BeaconChainDB, root: Eth2Digest,
index: ColumnIndex, data: var seq[byte]): bool =
let dataPtr = addr data # Short-lived
func decode(data: openArray[byte]) =
assign(dataPtr[], data)
db.blobs.get(columnkey(root, index), decode).expectDb()
proc getDataColumnSidecar*(db: BeaconChainDB, root: Eth2Digest, index: ColumnIndex,
value: var DataColumnSidecar): bool =
db.blobs.getSZSSZ(columnkey(root, index), value) == GetResult.found
proc getBlockSZ*(
db: BeaconChainDB, key: Eth2Digest, data: var seq[byte],
T: type phase0.TrustedSignedBeaconBlock): bool =

View File

@ -34,6 +34,10 @@ const
MAX_REQUEST_BLOB_SIDECARS*: uint64 =
MAX_REQUEST_BLOCKS_DENEB * MAX_BLOBS_PER_BLOCK
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.2/specs/_features/eip7594/p2p-interface.md#configuration
MAX_REQUEST_DATA_COLUMNS*: uint64 =
MAX_REQUEST_BLOCKS_DENEB * NUMBER_OF_COLUMNS
defaultEth2TcpPort* = 9000
defaultEth2TcpPortDesc* = $defaultEth2TcpPort

View File

@ -112,6 +112,12 @@ type
# TODO MAX_REQUEST_BLOCKS_DENEB*: uint64
# TODO MAX_REQUEST_BLOB_SIDECARS*: uint64
MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS*: uint64
# EIP-7594
# TODO MAX_REQUEST_BLOCKS_DENEB*: uint64
# TODO MAX_REQUEST_DATA_COLUMN_SIDECARS*: uint64
MIN_EPOCHS_FOR_DATA_COLUMN_SIDECARS_REQUESTS*: uint64
# TODO BLOB_SIDECAR_SUBNET_COUNT*: uint64
PresetFile* = object
@ -278,6 +284,14 @@ when const_preset == "mainnet":
MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS: 4096,
# `6`
# TODO BLOB_SIDECAR_SUBNET_COUNT: 6,
# EIP-7594
# `2**7` (=128)
# TODO MAX_REQUEST_BLOCKS_DENEB: 128,
# MAX_REQUEST_BLOCKS_DENEB * NUMBER_OF_COLUMNS
# TODO MAX_REQUEST_BLOB_SIDECARS: 768,
# `2**12` (= 4096 epochs, ~18 days)
MIN_EPOCHS_FOR_DATA_COLUMN_SIDECARS_REQUESTS: 4096
)
elif const_preset == "gnosis":
@ -575,6 +589,14 @@ elif const_preset == "minimal":
MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS: 4096,
# `6`
# TODO BLOB_SIDECAR_SUBNET_COUNT: 6,
# EIP-7594
# `2**7` (=128)
# TODO MAX_REQUEST_BLOCKS_DENEB: 128,
# MAX_REQUEST_BLOCKS_DENEB * NUMBER_OF_COLUMNS
# TODO MAX_REQUEST_BLOB_SIDECARS: 768,
# `2**12` (= 4096 epochs, ~18 days)
MIN_EPOCHS_FOR_DATA_COLUMN_SIDECARS_REQUESTS: 4096
)
else:

View File

@ -37,6 +37,7 @@ type
BlockRootsList* = List[Eth2Digest, Limit MAX_REQUEST_BLOCKS]
BlobIdentifierList* = List[BlobIdentifier, Limit (MAX_REQUEST_BLOB_SIDECARS)]
DataColumnIdentifierList* = List[DataColumnIdentifier, Limit (MAX_REQUEST_DATA_COLUMNS)]
proc readChunkPayload*(
conn: Connection, peer: Peer, MsgType: type (ref ForkedSignedBeaconBlock)):