Skip to content

Commit

Permalink
Fix CustodyColumnSubnets tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
nalepae committed May 17, 2024
1 parent 1c6a6b3 commit 798769e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
26 changes: 10 additions & 16 deletions beacon-chain/core/peerdas/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,34 +82,28 @@ func CustodyColumnSubnets(nodeId enode.ID, custodySubnetCount uint64) (map[uint6
// First, compute the subnet IDs that the node should participate in.
subnetIds := make(map[uint64]bool, custodySubnetCount)

// Convert the node ID to a big int.
nodeIdUInt256 := new(uint256.Int).SetBytes(nodeId.Bytes())

// Handle the maximum value of a uint256 case.
if nodeIdUInt256.Cmp(maxUint256) == 0 {
nodeIdUInt256 = uint256.NewInt(0)
}

one := uint256.NewInt(1)

for i := uint256.NewInt(0); uint64(len(subnetIds)) < custodySubnetCount; i.Add(i, one) {
// Augment the node ID with the index.
augmentedNodeIdUInt256 := new(uint256.Int).Add(nodeIdUInt256, i)

for currentId := new(uint256.Int).SetBytes(nodeId.Bytes()); uint64(len(subnetIds)) < custodySubnetCount; currentId.Add(currentId, one) {
// Convert to big endian bytes.
augmentedNodeIdBytesBigEndian := augmentedNodeIdUInt256.Bytes()
currentIdBytesBigEndian := currentId.Bytes32()

// Convert to little endian.
augmentedNodeIdBytesLittleEndian := bytesutil.ReverseByteOrder(augmentedNodeIdBytesBigEndian)
currentIdBytesLittleEndian := bytesutil.ReverseByteOrder(currentIdBytesBigEndian[:])

// Hash the result.
hashedAugmentedNodeId := hash.Hash(augmentedNodeIdBytesLittleEndian)
hashedCurrentId := hash.Hash(currentIdBytesLittleEndian)

// Get the subnet ID.
subnetId := binary.LittleEndian.Uint64(hashedAugmentedNodeId[:8]) % dataColumnSidecarSubnetCount
subnetId := binary.LittleEndian.Uint64(hashedCurrentId[:8]) % dataColumnSidecarSubnetCount

// Add the subnet to the map.
subnetIds[subnetId] = true

// Overflow prevention.
if currentId.Cmp(maxUint256) == 0 {
currentId = uint256.NewInt(0)
}
}

return subnetIds, nil
Expand Down
1 change: 0 additions & 1 deletion beacon-chain/sync/rpc_beacon_blocks_by_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ func (s *Service) pendingBlobsRequestForBlock(root [32]byte, b interfaces.ReadOn
blobIdentifiers, err := s.constructPendingBlobsRequest(root, len(cc))
if err != nil {
return nil, errors.Wrap(err, "construct pending blobs request")

}

return blobIdentifiers, nil
Expand Down
10 changes: 6 additions & 4 deletions testing/spectest/shared/eip7594/networking/custody_columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func RunCustodyColumnsTest(t *testing.T, config string) {
for _, folder := range testFolders {
t.Run(folder.Name(), func(t *testing.T) {
var (
config Config
nodeIdBytes [32]byte
config Config
nodeIdBytes32 [32]byte
)

// Load the test vector.
Expand All @@ -45,8 +45,10 @@ func RunCustodyColumnsTest(t *testing.T, config string) {
require.NoError(t, err, "failed to unmarshal the YAML file")

// Get the node ID.
copy(nodeIdBytes[:], config.NodeId.Bytes())
nodeId := enode.ID(nodeIdBytes)
nodeIdBytes := make([]byte, 32)
config.NodeId.FillBytes(nodeIdBytes)
copy(nodeIdBytes32[:], nodeIdBytes)
nodeId := enode.ID(nodeIdBytes32)

// Compute the custodied columns.
actual, err := peerdas.CustodyColumns(nodeId, config.CustodySubnetCount)
Expand Down

0 comments on commit 798769e

Please sign in to comment.