simplify usage of get custody columns
This commit is contained in:
parent
cf0cf815b6
commit
7d04142e4a
|
@ -26,13 +26,15 @@ type
|
||||||
CellBytes = array[eip7594.CELLS_PER_EXT_BLOB, Cell]
|
CellBytes = array[eip7594.CELLS_PER_EXT_BLOB, Cell]
|
||||||
ProofBytes = array[eip7594.CELLS_PER_EXT_BLOB, KzgProof]
|
ProofBytes = array[eip7594.CELLS_PER_EXT_BLOB, KzgProof]
|
||||||
|
|
||||||
proc sortedColumnIndices*(columnsPerSubnet: ColumnIndex, subnetIds: HashSet[uint64]): seq[ColumnIndex] =
|
proc sortedColumnIndices*(columnsPerSubnet: ColumnIndex,
|
||||||
|
subnetIds: HashSet[uint64]):
|
||||||
|
seq[ColumnIndex] =
|
||||||
var res: seq[ColumnIndex] = @[]
|
var res: seq[ColumnIndex] = @[]
|
||||||
for i in 0 ..< columnsPerSubnet:
|
for i in 0'u64 ..< columnsPerSubnet:
|
||||||
for subnetId in subnetIds:
|
for subnetId in subnetIds:
|
||||||
let index = DATA_COLUMN_SIDECAR_SUBNET_COUNT * i + subnetId
|
let index = DATA_COLUMN_SIDECAR_SUBNET_COUNT * i + subnetId
|
||||||
res.add(ColumnIndex(index))
|
res.add(ColumnIndex(index))
|
||||||
res.sort()
|
res.sort
|
||||||
res
|
res
|
||||||
|
|
||||||
proc sortedColumnIndexList*(columnsPerSubnet: ColumnIndex,
|
proc sortedColumnIndexList*(columnsPerSubnet: ColumnIndex,
|
||||||
|
@ -40,17 +42,15 @@ proc sortedColumnIndexList*(columnsPerSubnet: ColumnIndex,
|
||||||
List[ColumnIndex, NUMBER_OF_COLUMNS] =
|
List[ColumnIndex, NUMBER_OF_COLUMNS] =
|
||||||
var
|
var
|
||||||
res: seq[ColumnIndex]
|
res: seq[ColumnIndex]
|
||||||
list: List[ColumnIndex, NUMBER_OF_COLUMNS]
|
for i in 0'u64 ..< columnsPerSubnet:
|
||||||
for i in 0 ..< columnsPerSubnet:
|
|
||||||
for subnetId in subnetIds:
|
for subnetId in subnetIds:
|
||||||
let index = DATA_COLUMN_SIDECAR_SUBNET_COUNT * i + subnetId
|
let index = DATA_COLUMN_SIDECAR_SUBNET_COUNT * i + subnetId
|
||||||
res.add(ColumnIndex(index))
|
res.add(ColumnIndex(index))
|
||||||
res.sort()
|
res.sort()
|
||||||
for elem in res:
|
let list = List[ColumnIndex, NUMBER_OF_COLUMNS].init(res)
|
||||||
discard list.add(ColumnIndex(elem))
|
|
||||||
list
|
list
|
||||||
|
|
||||||
proc get_custody_column_subnet*(node_id: NodeId,
|
proc get_custody_column_subnets*(node_id: NodeId,
|
||||||
custody_subnet_count: uint64):
|
custody_subnet_count: uint64):
|
||||||
Result[HashSet[uint64], cstring] =
|
Result[HashSet[uint64], cstring] =
|
||||||
|
|
||||||
|
@ -65,23 +65,18 @@ proc get_custody_column_subnet*(node_id: NodeId,
|
||||||
subnet_ids: HashSet[uint64]
|
subnet_ids: HashSet[uint64]
|
||||||
current_id = node_id
|
current_id = node_id
|
||||||
|
|
||||||
while subnet_ids.len < int(custody_subnet_count):
|
while subnet_ids.lenu64 < custody_subnet_count:
|
||||||
|
|
||||||
var
|
var
|
||||||
current_id_bytes: array[32, byte]
|
|
||||||
hashed_bytes: array[8, byte]
|
hashed_bytes: array[8, byte]
|
||||||
|
|
||||||
current_id_bytes = current_id.toBytesBE()
|
|
||||||
current_id_bytes.reverse()
|
|
||||||
|
|
||||||
let
|
let
|
||||||
|
current_id_bytes = current_id.toBytesLE()
|
||||||
hashed_current_id = eth2digest(current_id_bytes)
|
hashed_current_id = eth2digest(current_id_bytes)
|
||||||
|
|
||||||
hashed_bytes[0..7] = hashed_current_id.data.toOpenArray(0,7)
|
hashed_bytes[0..7] = hashed_current_id.data.toOpenArray(0,7)
|
||||||
var subnet_id = bytes_to_uint64(hashed_bytes) mod
|
let subnet_id = bytes_to_uint64(hashed_bytes) mod
|
||||||
DATA_COLUMN_SIDECAR_SUBNET_COUNT
|
DATA_COLUMN_SIDECAR_SUBNET_COUNT
|
||||||
|
|
||||||
if subnet_id notin subnet_ids:
|
|
||||||
subnet_ids.incl(subnet_id)
|
subnet_ids.incl(subnet_id)
|
||||||
|
|
||||||
if current_id == UInt256.high.NodeId:
|
if current_id == UInt256.high.NodeId:
|
||||||
|
@ -91,29 +86,34 @@ proc get_custody_column_subnet*(node_id: NodeId,
|
||||||
|
|
||||||
ok(subnet_ids)
|
ok(subnet_ids)
|
||||||
|
|
||||||
|
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.5/specs/_features/eip7594/das-core.md#get_custody_columns
|
||||||
# https://github.com/ethereum/consensus-specs/blob/5f48840f4d768bf0e0a8156a3ed06ec333589007/specs/_features/eip7594/das-core.md#get_custody_columns
|
|
||||||
proc get_custody_columns*(node_id: NodeId,
|
proc get_custody_columns*(node_id: NodeId,
|
||||||
custody_subnet_count: uint64):
|
custody_subnet_count: uint64):
|
||||||
Result[seq[ColumnIndex], cstring] =
|
seq[ColumnIndex] =
|
||||||
|
let
|
||||||
|
subnet_ids =
|
||||||
|
get_custody_column_subnets(node_id, custody_subnet_count).get
|
||||||
|
const
|
||||||
|
columns_per_subnet =
|
||||||
|
NUMBER_OF_COLUMNS div DATA_COLUMN_SIDECAR_SUBNET_COUNT
|
||||||
|
|
||||||
let subnet_ids = get_custody_column_subnet(node_id, custody_subnet_count).get
|
sortedColumnIndices(ColumnIndex(columns_per_subnet), subnet_ids)
|
||||||
|
|
||||||
# columns_per_subnet = NUMBER_OF_COLUMNS // DATA_COLUMN_SIDECAR_SUBNET_COUNT
|
|
||||||
let columns_per_subnet = NUMBER_OF_COLUMNS div DATA_COLUMN_SIDECAR_SUBNET_COUNT
|
|
||||||
|
|
||||||
ok(sortedColumnIndices(ColumnIndex(columns_per_subnet), subnet_ids))
|
|
||||||
|
|
||||||
proc get_custody_column_list*(node_id: NodeId,
|
proc get_custody_column_list*(node_id: NodeId,
|
||||||
custody_subnet_count: uint64):
|
custody_subnet_count: uint64):
|
||||||
Result[List[ColumnIndex, NUMBER_OF_COLUMNS], cstring] =
|
List[ColumnIndex, NUMBER_OF_COLUMNS] =
|
||||||
|
|
||||||
let subnet_ids = get_custody_column_subnet(node_id, custody_subnet_count).get
|
# Not in spec in the exact format, but it is useful in sorting custody columns
|
||||||
|
# before sending, data_column_sidecars_by_range requests
|
||||||
|
let
|
||||||
|
subnet_ids =
|
||||||
|
get_custody_column_subnets(node_id, custody_subnet_count).get
|
||||||
|
const
|
||||||
|
columns_per_subnet =
|
||||||
|
NUMBER_OF_COLUMNS div DATA_COLUMN_SIDECAR_SUBNET_COUNT
|
||||||
|
|
||||||
# columns_per_subnet = NUMBER_OF_COLUMNS // DATA_COLUMN_SIDECAR_SUBNET_COUNT
|
sortedColumnIndexList(ColumnIndex(columns_per_subnet), subnet_ids)
|
||||||
let columns_per_subnet = NUMBER_OF_COLUMNS div DATA_COLUMN_SIDECAR_SUBNET_COUNT
|
|
||||||
|
|
||||||
ok(sortedColumnIndexList(ColumnIndex(columns_per_subnet), subnet_ids))
|
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.3/specs/_features/eip7594/das-core.md#compute_extended_matrix
|
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.3/specs/_features/eip7594/das-core.md#compute_extended_matrix
|
||||||
proc compute_extended_matrix* (blobs: seq[KzgBlob]): Result[seq[MatrixEntry], cstring] =
|
proc compute_extended_matrix* (blobs: seq[KzgBlob]): Result[seq[MatrixEntry], cstring] =
|
||||||
|
|
|
@ -282,7 +282,7 @@ proc constructValidCustodyPeers(rman: RequestManager,
|
||||||
let
|
let
|
||||||
localNodeId = rman.network.nodeId
|
localNodeId = rman.network.nodeId
|
||||||
localCustodyColumns =
|
localCustodyColumns =
|
||||||
localNodeId.get_custody_columns(localCustodySubnetCount).get
|
localNodeId.get_custody_columns(localCustodySubnetCount)
|
||||||
|
|
||||||
var validPeers: seq[Peer]
|
var validPeers: seq[Peer]
|
||||||
|
|
||||||
|
@ -296,7 +296,7 @@ proc constructValidCustodyPeers(rman: RequestManager,
|
||||||
let
|
let
|
||||||
remoteNodeId = getNodeIdFromPeer(peer)
|
remoteNodeId = getNodeIdFromPeer(peer)
|
||||||
remoteCustodyColumns =
|
remoteCustodyColumns =
|
||||||
remoteNodeId.get_custody_columns(remoteCustodySubnetCount).get
|
remoteNodeId.get_custody_columns(remoteCustodySubnetCount)
|
||||||
|
|
||||||
# If the remote peer custodies less columns than
|
# If the remote peer custodies less columns than
|
||||||
# our local node
|
# our local node
|
||||||
|
|
|
@ -213,7 +213,7 @@ proc routeSignedBeaconBlock*(
|
||||||
custody_columns = router[].network.nodeId.get_custody_columns(metadata)
|
custody_columns = router[].network.nodeId.get_custody_columns(metadata)
|
||||||
|
|
||||||
for dc in data_columns:
|
for dc in data_columns:
|
||||||
if dc.index in custody_columns.get:
|
if dc.index in custody_columns:
|
||||||
let dataColumnRefs = Opt.some(dataColumnsOpt[].get().mapIt(newClone(it)))
|
let dataColumnRefs = Opt.some(dataColumnsOpt[].get().mapIt(newClone(it)))
|
||||||
|
|
||||||
let added = await router[].blockProcessor[].addBlock(
|
let added = await router[].blockProcessor[].addBlock(
|
||||||
|
|
Binary file not shown.
|
@ -11,35 +11,14 @@
|
||||||
import
|
import
|
||||||
std/[json, streams],
|
std/[json, streams],
|
||||||
yaml,
|
yaml,
|
||||||
kzg4844/kzg_ex,
|
kzg4844/[kzg, kzg_abi],
|
||||||
stint,
|
stint,
|
||||||
chronicles,
|
|
||||||
eth/p2p/discoveryv5/[node],
|
eth/p2p/discoveryv5/[node],
|
||||||
stew/[byteutils, results],
|
|
||||||
../../beacon_chain/spec/eip7594_helpers,
|
../../beacon_chain/spec/eip7594_helpers,
|
||||||
../testutil,
|
../testutil,
|
||||||
./fixtures_utils, ./os_ops
|
./fixtures_utils, ./os_ops
|
||||||
|
|
||||||
from std/sequtils import anyIt, mapIt, toSeq
|
from std/sequtils import mapIt
|
||||||
from std/strutils import rsplit
|
|
||||||
|
|
||||||
func toUInt64(s: SomeInteger): Opt[uint64] =
|
|
||||||
if s < 0:
|
|
||||||
return Opt.none uint64
|
|
||||||
try:
|
|
||||||
Opt.some uint64(s)
|
|
||||||
except ValueError:
|
|
||||||
Opt.none uint64
|
|
||||||
|
|
||||||
func fromHex[N: static int](s: string): Opt[array[N, byte]] =
|
|
||||||
if s.len != 2*(N+1):
|
|
||||||
# 0x prefix
|
|
||||||
return Opt.none array[N, byte]
|
|
||||||
|
|
||||||
try:
|
|
||||||
Opt.some fromHex(array[N, byte], s)
|
|
||||||
except ValueError:
|
|
||||||
Opt.none array[N, byte]
|
|
||||||
|
|
||||||
proc runGetCustodyColumns(suiteName, path: string) =
|
proc runGetCustodyColumns(suiteName, path: string) =
|
||||||
let relativePathComponent = path.relativeTestPathComponent()
|
let relativePathComponent = path.relativeTestPathComponent()
|
||||||
|
@ -47,7 +26,7 @@ proc runGetCustodyColumns(suiteName, path: string) =
|
||||||
type TestMetaYaml = object
|
type TestMetaYaml = object
|
||||||
node_id: string
|
node_id: string
|
||||||
custody_subnet_count: uint64
|
custody_subnet_count: uint64
|
||||||
result: Option[seq[uint64]]
|
result: seq[uint64]
|
||||||
let
|
let
|
||||||
meta = block:
|
meta = block:
|
||||||
var s = openFileStream(path/"meta.yaml")
|
var s = openFileStream(path/"meta.yaml")
|
||||||
|
@ -56,20 +35,13 @@ proc runGetCustodyColumns(suiteName, path: string) =
|
||||||
yaml.load(s, res)
|
yaml.load(s, res)
|
||||||
res
|
res
|
||||||
node_id = UInt256.fromDecimal(meta.node_id)
|
node_id = UInt256.fromDecimal(meta.node_id)
|
||||||
custody_subnet_count = toUInt64(meta.custody_subnet_count)
|
custody_subnet_count = meta.custody_subnet_count
|
||||||
reslt = (meta.result.get).mapIt(uint64(it))
|
reslt = (meta.result).mapIt(it)
|
||||||
|
|
||||||
if custody_subnet_count.isNone:
|
let columns = get_custody_columns(node_id, custody_subnet_count)
|
||||||
check meta.result.isNone
|
|
||||||
else:
|
for i in 0..<columns.lenu64:
|
||||||
let columns = get_custody_columns(node_id, custody_subnet_count.get)
|
check columns[i] == reslt[i]
|
||||||
if columns.isErr:
|
|
||||||
check meta.result.isNone
|
|
||||||
else:
|
|
||||||
var count = 0
|
|
||||||
for column in columns.get:
|
|
||||||
check column == uint64(reslt[count])
|
|
||||||
count = count + 1
|
|
||||||
|
|
||||||
suite "EF - EIP7594 - Networking" & preset():
|
suite "EF - EIP7594 - Networking" & preset():
|
||||||
const presetPath = SszTestsDir/const_preset
|
const presetPath = SszTestsDir/const_preset
|
||||||
|
|
Loading…
Reference in New Issue