Skip to content

Commit

Permalink
Revert "Change Custody Count to Uint8 (#14386)" (#14415)
Browse files Browse the repository at this point in the history
This reverts commit bd7ec3f.
  • Loading branch information
nisdas authored and nalepae committed Nov 22, 2024
1 parent 75d2cb5 commit 89ab9be
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 89 deletions.
2 changes: 1 addition & 1 deletion beacon-chain/core/peerdas/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const (
)

// https://github.com/ethereum/consensus-specs/blob/dev/specs/_features/eip7594/p2p-interface.md#the-discovery-domain-discv5
type Csc uint8
type Csc uint64

func (Csc) ENRKey() string { return CustodySubnetCountEnrKey }

Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/p2p/custody.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (s *Service) CustodyCountFromRemotePeer(pid peer.ID) uint64 {
if metadata != nil {
custodyCount := metadata.CustodySubnetCount()
if custodyCount > 0 {
return uint64(custodyCount)
return custodyCount
}
}

Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/p2p/custody_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ func TestCustodyCountFromRemotePeer(t *testing.T) {

// Define a metadata with zero custody.
zeroMetadata := wrapper.WrappedMetadataV2(&pb.MetaDataV2{
CustodySubnetCount: []byte{0},
CustodySubnetCount: 0,
})

// Define a nominal metadata.
nominalMetadata := wrapper.WrappedMetadataV2(&pb.MetaDataV2{
CustodySubnetCount: []byte{uint8(expectedMetadata)},
CustodySubnetCount: expectedMetadata,
})

testCases := []struct {
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/p2p/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (s *Service) RefreshPersistentSubnets() {
// Get the custody subnet count in our metadata.
inMetadataCustodySubnetCount := s.Metadata().CustodySubnetCount()

isCustodySubnetCountUpToDate := custodySubnetCount == inRecordCustodySubnetCount && custodySubnetCount == uint64(inMetadataCustodySubnetCount)
isCustodySubnetCountUpToDate := (custodySubnetCount == inRecordCustodySubnetCount && custodySubnetCount == inMetadataCustodySubnetCount)

if isBitVUpToDate && isBitSUpToDate && isCustodySubnetCountUpToDate {
// Nothing to do, return early.
Expand Down
6 changes: 3 additions & 3 deletions beacon-chain/p2p/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ type check struct {
metadataSequenceNumber uint64
attestationSubnets []uint64
syncSubnets []uint64
custodySubnetCount *uint8
custodySubnetCount *uint64
}

func checkPingCountCacheMetadataRecord(
Expand Down Expand Up @@ -606,7 +606,7 @@ func checkPingCountCacheMetadataRecord(

if expected.custodySubnetCount != nil {
// Check custody subnet count in ENR.
var actualCustodySubnetCount uint8
var actualCustodySubnetCount uint64
err := service.dv5Listener.LocalNode().Node().Record().Load(enr.WithEntry(peerdas.CustodySubnetCountEnrKey, &actualCustodySubnetCount))
require.NoError(t, err)
require.Equal(t, *expected.custodySubnetCount, actualCustodySubnetCount)
Expand All @@ -629,7 +629,7 @@ func TestRefreshPersistentSubnets(t *testing.T) {
eip7594ForkEpoch = 10
)

custodySubnetCount := uint8(params.BeaconConfig().CustodyRequirement)
custodySubnetCount := params.BeaconConfig().CustodyRequirement

// Set up epochs.
defaultCfg := params.BeaconConfig()
Expand Down
3 changes: 1 addition & 2 deletions beacon-chain/p2p/subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,12 @@ func (s *Service) updateSubnetRecordWithMetadataV3(
localNode.Set(custodySubnetCountEntry)

newSeqNumber := s.metaData.SequenceNumber() + 1
cscBytes := []byte{uint8(custodySubnetCount)}

s.metaData = wrapper.WrappedMetadataV2(&pb.MetaDataV2{
SeqNumber: newSeqNumber,
Attnets: bitVAtt,
Syncnets: bitVSync,
CustodySubnetCount: cscBytes,
CustodySubnetCount: custodySubnetCount,
})
}

Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/sync/rpc_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ func (s *Service) metaDataHandler(_ context.Context, _ interface{}, stream libp2
Attnets: metadata.AttnetsBitfield(),
SeqNumber: metadata.SequenceNumber(),
Syncnets: bitfield.Bitvector4{byte(0x00)},
CustodySubnetCount: []byte{0},
CustodySubnetCount: 0,
})
case version.Altair:
metadata = wrapper.WrappedMetadataV2(
&pb.MetaDataV2{
Attnets: metadata.AttnetsBitfield(),
SeqNumber: metadata.SequenceNumber(),
Syncnets: metadata.SyncnetsBitfield(),
CustodySubnetCount: []byte{0},
CustodySubnetCount: 0,
})
}
}
Expand Down
12 changes: 6 additions & 6 deletions beacon-chain/sync/rpc_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func TestMetadataRPCHandler_SendMetadataRequest(t *testing.T) {
SeqNumber: seqNumber,
Attnets: attnets,
Syncnets: syncnets,
CustodySubnetCount: []byte{custodySubnetCount},
CustodySubnetCount: custodySubnetCount,
}),
expected: wrapper.WrappedMetadataV0(&pb.MetaDataV0{
SeqNumber: seqNumber,
Expand Down Expand Up @@ -200,7 +200,7 @@ func TestMetadataRPCHandler_SendMetadataRequest(t *testing.T) {
SeqNumber: seqNumber,
Attnets: attnets,
Syncnets: syncnets,
CustodySubnetCount: []byte{custodySubnetCount},
CustodySubnetCount: custodySubnetCount,
}),
expected: wrapper.WrappedMetadataV1(&pb.MetaDataV1{
SeqNumber: seqNumber,
Expand All @@ -221,7 +221,7 @@ func TestMetadataRPCHandler_SendMetadataRequest(t *testing.T) {
SeqNumber: seqNumber,
Attnets: attnets,
Syncnets: bitfield.Bitvector4{byte(0x00)},
CustodySubnetCount: []byte{0},
CustodySubnetCount: 0,
}),
},
{
Expand All @@ -238,7 +238,7 @@ func TestMetadataRPCHandler_SendMetadataRequest(t *testing.T) {
SeqNumber: seqNumber,
Attnets: attnets,
Syncnets: syncnets,
CustodySubnetCount: []byte{0},
CustodySubnetCount: 0,
}),
},
{
Expand All @@ -250,13 +250,13 @@ func TestMetadataRPCHandler_SendMetadataRequest(t *testing.T) {
SeqNumber: seqNumber,
Attnets: attnets,
Syncnets: syncnets,
CustodySubnetCount: []byte{custodySubnetCount},
CustodySubnetCount: custodySubnetCount,
}),
expected: wrapper.WrappedMetadataV2(&pb.MetaDataV2{
SeqNumber: seqNumber,
Attnets: attnets,
Syncnets: syncnets,
CustodySubnetCount: []byte{custodySubnetCount},
CustodySubnetCount: custodySubnetCount,
}),
},
}
Expand Down
1 change: 0 additions & 1 deletion consensus-types/wrapper/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v5/consensus-types/wrapper",
visibility = ["//visibility:public"],
deps = [
"//encoding/bytesutil:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v1alpha1/metadata:go_default_library",
"//runtime/version:go_default_library",
Expand Down
9 changes: 4 additions & 5 deletions consensus-types/wrapper/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package wrapper

import (
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
pb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/metadata"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
Expand Down Expand Up @@ -38,7 +37,7 @@ func (m MetadataV0) SyncnetsBitfield() bitfield.Bitvector4 {
}

// CustodySubnetCount returns custody subnet count from the metadata.
func (m MetadataV0) CustodySubnetCount() uint8 {
func (m MetadataV0) CustodySubnetCount() uint64 {
return 0
}

Expand Down Expand Up @@ -132,7 +131,7 @@ func (m MetadataV1) SyncnetsBitfield() bitfield.Bitvector4 {
}

// CustodySubnetCount returns custody subnet count from the metadata.
func (m MetadataV1) CustodySubnetCount() uint8 {
func (m MetadataV1) CustodySubnetCount() uint64 {
return 0
}

Expand Down Expand Up @@ -226,8 +225,8 @@ func (m MetadataV2) SyncnetsBitfield() bitfield.Bitvector4 {
}

// CustodySubnetCount returns custody subnet count from the metadata.
func (m MetadataV2) CustodySubnetCount() uint8 {
return bytesutil.FromBytes1(m.md.CustodySubnetCount)
func (m MetadataV2) CustodySubnetCount() uint64 {
return m.md.CustodySubnetCount
}

// InnerObject returns the underlying metadata protobuf structure.
Expand Down
8 changes: 0 additions & 8 deletions encoding/bytesutil/integers.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,6 @@ func Bytes32(x uint64) []byte {
return bytes
}

// FromBytes1 returns an integer from a byte slice with a size of 1.
func FromBytes1(x []byte) uint8 {
if len(x) < 1 {
return 0
}
return x[0]
}

// FromBytes2 returns an integer which is stored in the little-endian format(2, 'little')
// from a byte array.
func FromBytes2(x []byte) uint16 {
Expand Down
2 changes: 1 addition & 1 deletion proto/prysm/v1alpha1/metadata/metadata_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Metadata interface {
SequenceNumber() uint64
AttnetsBitfield() bitfield.Bitvector64
SyncnetsBitfield() bitfield.Bitvector4
CustodySubnetCount() uint8
CustodySubnetCount() uint64
InnerObject() interface{}
IsNil() bool
Copy() Metadata
Expand Down
21 changes: 5 additions & 16 deletions proto/prysm/v1alpha1/non-core.ssz.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 38 additions & 39 deletions proto/prysm/v1alpha1/p2p_messages.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/prysm/v1alpha1/p2p_messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ message MetaDataV2 {
uint64 seq_number = 1;
bytes attnets = 2 [(ethereum.eth.ext.ssz_size) = "8", (ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/go-bitfield.Bitvector64"];
bytes syncnets = 3 [(ethereum.eth.ext.ssz_size) = "1", (ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/go-bitfield.Bitvector4"];
bytes custody_subnet_count = 4 [(ethereum.eth.ext.ssz_size) = "1"];
uint64 custody_subnet_count = 4;
}

/*
Expand Down

0 comments on commit 89ab9be

Please sign in to comment.