mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 05:47:59 -05:00
Fix CustodyColumns to comply with alpha-2 spectests. (#14008)
* Adding error wrapping * Fix `CustodyColumnSubnets` tests.
This commit is contained in:
@@ -501,7 +501,7 @@ func missingIndices(bs *filesystem.BlobStorage, root [32]byte, expected [][]byte
|
||||
}
|
||||
indices, err := bs.Indices(root)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "indices")
|
||||
}
|
||||
missing := make(map[uint64]struct{}, len(expected))
|
||||
for i := range expected {
|
||||
@@ -573,7 +573,7 @@ func (s *Service) isDataAvailable(ctx context.Context, root [32]byte, signed int
|
||||
// get a map of BlobSidecar indices that are not currently available.
|
||||
missing, err := missingIndices(s.blobStorage, root, kzgCommitments)
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.Wrap(err, "missing indices")
|
||||
}
|
||||
// If there are no missing indices, all BlobSidecars are available.
|
||||
if len(missing) == 0 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -57,7 +57,7 @@ func (s *Service) sendRecentBeaconBlocksRequest(ctx context.Context, requests *t
|
||||
}
|
||||
request, err := s.pendingBlobsRequestForBlock(blkRoot, blk)
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.Wrap(err, "pending blobs request for block")
|
||||
}
|
||||
if len(request) == 0 {
|
||||
continue
|
||||
@@ -181,7 +181,13 @@ func (s *Service) pendingBlobsRequestForBlock(root [32]byte, b interfaces.ReadOn
|
||||
if len(cc) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return s.constructPendingBlobsRequest(root, len(cc))
|
||||
|
||||
blobIdentifiers, err := s.constructPendingBlobsRequest(root, len(cc))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "construct pending blobs request")
|
||||
}
|
||||
|
||||
return blobIdentifiers, nil
|
||||
}
|
||||
|
||||
// constructPendingBlobsRequest creates a request for BlobSidecars by root, considering blobs already in DB.
|
||||
@@ -191,7 +197,7 @@ func (s *Service) constructPendingBlobsRequest(root [32]byte, commitments int) (
|
||||
}
|
||||
stored, err := s.cfg.blobStorage.Indices(root)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "indices")
|
||||
}
|
||||
|
||||
return requestsForMissingIndices(stored, commitments, root), nil
|
||||
|
||||
@@ -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.
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user