Skip to content

Commit bd7ec3f

Browse files
nisdasnalepae
authored andcommitted
Change Custody Count to Uint8 (#14386)
* Add Changes for Uint8 Csc * Fix Build * Fix Build for Sync * Fix Discovery Test
1 parent ef86a0e commit bd7ec3f

File tree

15 files changed

+90
-67
lines changed

15 files changed

+90
-67
lines changed

beacon-chain/core/peerdas/helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const (
3333
)
3434

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

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

beacon-chain/p2p/custody.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (s *Service) CustodyCountFromRemotePeer(pid peer.ID) uint64 {
8686
if metadata != nil {
8787
custodyCount := metadata.CustodySubnetCount()
8888
if custodyCount > 0 {
89-
return custodyCount
89+
return uint64(custodyCount)
9090
}
9191
}
9292

beacon-chain/p2p/custody_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ func TestCustodyCountFromRemotePeer(t *testing.T) {
121121

122122
// Define a metadata with zero custody.
123123
zeroMetadata := wrapper.WrappedMetadataV2(&pb.MetaDataV2{
124-
CustodySubnetCount: 0,
124+
CustodySubnetCount: []byte{0},
125125
})
126126

127127
// Define a nominal metadata.
128128
nominalMetadata := wrapper.WrappedMetadataV2(&pb.MetaDataV2{
129-
CustodySubnetCount: expectedMetadata,
129+
CustodySubnetCount: []byte{uint8(expectedMetadata)},
130130
})
131131

132132
testCases := []struct {

beacon-chain/p2p/discovery.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func (s *Service) RefreshPersistentSubnets() {
175175
// Get the custody subnet count in our metadata.
176176
inMetadataCustodySubnetCount := s.Metadata().CustodySubnetCount()
177177

178-
isCustodySubnetCountUpToDate := (custodySubnetCount == inRecordCustodySubnetCount && custodySubnetCount == inMetadataCustodySubnetCount)
178+
isCustodySubnetCountUpToDate := custodySubnetCount == inRecordCustodySubnetCount && custodySubnetCount == uint64(inMetadataCustodySubnetCount)
179179

180180
if isBitVUpToDate && isBitSUpToDate && isCustodySubnetCountUpToDate {
181181
// Nothing to do, return early.

beacon-chain/p2p/discovery_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ type check struct {
473473
metadataSequenceNumber uint64
474474
attestationSubnets []uint64
475475
syncSubnets []uint64
476-
custodySubnetCount *uint64
476+
custodySubnetCount *uint8
477477
}
478478

479479
func checkPingCountCacheMetadataRecord(
@@ -542,7 +542,7 @@ func checkPingCountCacheMetadataRecord(
542542

543543
if expected.custodySubnetCount != nil {
544544
// Check custody subnet count in ENR.
545-
var actualCustodySubnetCount uint64
545+
var actualCustodySubnetCount uint8
546546
err := service.dv5Listener.LocalNode().Node().Record().Load(enr.WithEntry(peerdas.CustodySubnetCountEnrKey, &actualCustodySubnetCount))
547547
require.NoError(t, err)
548548
require.Equal(t, *expected.custodySubnetCount, actualCustodySubnetCount)
@@ -565,7 +565,7 @@ func TestRefreshPersistentSubnets(t *testing.T) {
565565
eip7594ForkEpoch = 10
566566
)
567567

568-
custodySubnetCount := params.BeaconConfig().CustodyRequirement
568+
custodySubnetCount := uint8(params.BeaconConfig().CustodyRequirement)
569569

570570
// Set up epochs.
571571
defaultCfg := params.BeaconConfig()

beacon-chain/p2p/subnets.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,13 @@ func (s *Service) updateSubnetRecordWithMetadataV3(
239239
localNode.Set(custodySubnetCountEntry)
240240

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

243244
s.metaData = wrapper.WrappedMetadataV2(&pb.MetaDataV2{
244245
SeqNumber: newSeqNumber,
245246
Attnets: bitVAtt,
246247
Syncnets: bitVSync,
247-
CustodySubnetCount: custodySubnetCount,
248+
CustodySubnetCount: cscBytes,
248249
})
249250
}
250251

beacon-chain/sync/rpc_metadata.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ func (s *Service) metaDataHandler(_ context.Context, _ interface{}, stream libp2
104104
Attnets: metadata.AttnetsBitfield(),
105105
SeqNumber: metadata.SequenceNumber(),
106106
Syncnets: bitfield.Bitvector4{byte(0x00)},
107-
CustodySubnetCount: 0,
107+
CustodySubnetCount: []byte{0},
108108
})
109109
case version.Altair:
110110
metadata = wrapper.WrappedMetadataV2(
111111
&pb.MetaDataV2{
112112
Attnets: metadata.AttnetsBitfield(),
113113
SeqNumber: metadata.SequenceNumber(),
114114
Syncnets: metadata.SyncnetsBitfield(),
115-
CustodySubnetCount: 0,
115+
CustodySubnetCount: []byte{0},
116116
})
117117
}
118118
}

beacon-chain/sync/rpc_metadata_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func TestMetadataRPCHandler_SendMetadataRequest(t *testing.T) {
153153
SeqNumber: seqNumber,
154154
Attnets: attnets,
155155
Syncnets: syncnets,
156-
CustodySubnetCount: custodySubnetCount,
156+
CustodySubnetCount: []byte{custodySubnetCount},
157157
}),
158158
expected: wrapper.WrappedMetadataV0(&pb.MetaDataV0{
159159
SeqNumber: seqNumber,
@@ -200,7 +200,7 @@ func TestMetadataRPCHandler_SendMetadataRequest(t *testing.T) {
200200
SeqNumber: seqNumber,
201201
Attnets: attnets,
202202
Syncnets: syncnets,
203-
CustodySubnetCount: custodySubnetCount,
203+
CustodySubnetCount: []byte{custodySubnetCount},
204204
}),
205205
expected: wrapper.WrappedMetadataV1(&pb.MetaDataV1{
206206
SeqNumber: seqNumber,
@@ -221,7 +221,7 @@ func TestMetadataRPCHandler_SendMetadataRequest(t *testing.T) {
221221
SeqNumber: seqNumber,
222222
Attnets: attnets,
223223
Syncnets: bitfield.Bitvector4{byte(0x00)},
224-
CustodySubnetCount: 0,
224+
CustodySubnetCount: []byte{0},
225225
}),
226226
},
227227
{
@@ -238,7 +238,7 @@ func TestMetadataRPCHandler_SendMetadataRequest(t *testing.T) {
238238
SeqNumber: seqNumber,
239239
Attnets: attnets,
240240
Syncnets: syncnets,
241-
CustodySubnetCount: 0,
241+
CustodySubnetCount: []byte{0},
242242
}),
243243
},
244244
{
@@ -250,13 +250,13 @@ func TestMetadataRPCHandler_SendMetadataRequest(t *testing.T) {
250250
SeqNumber: seqNumber,
251251
Attnets: attnets,
252252
Syncnets: syncnets,
253-
CustodySubnetCount: custodySubnetCount,
253+
CustodySubnetCount: []byte{custodySubnetCount},
254254
}),
255255
expected: wrapper.WrappedMetadataV2(&pb.MetaDataV2{
256256
SeqNumber: seqNumber,
257257
Attnets: attnets,
258258
Syncnets: syncnets,
259-
CustodySubnetCount: custodySubnetCount,
259+
CustodySubnetCount: []byte{custodySubnetCount},
260260
}),
261261
},
262262
}

consensus-types/wrapper/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ go_library(
66
importpath = "github.com/prysmaticlabs/prysm/v5/consensus-types/wrapper",
77
visibility = ["//visibility:public"],
88
deps = [
9+
"//encoding/bytesutil:go_default_library",
910
"//proto/prysm/v1alpha1:go_default_library",
1011
"//proto/prysm/v1alpha1/metadata:go_default_library",
1112
"//runtime/version:go_default_library",

consensus-types/wrapper/metadata.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package wrapper
22

33
import (
44
"github.com/prysmaticlabs/go-bitfield"
5+
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
56
pb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
67
"github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/metadata"
78
"github.com/prysmaticlabs/prysm/v5/runtime/version"
@@ -37,7 +38,7 @@ func (m MetadataV0) SyncnetsBitfield() bitfield.Bitvector4 {
3738
}
3839

3940
// CustodySubnetCount returns custody subnet count from the metadata.
40-
func (m MetadataV0) CustodySubnetCount() uint64 {
41+
func (m MetadataV0) CustodySubnetCount() uint8 {
4142
return 0
4243
}
4344

@@ -131,7 +132,7 @@ func (m MetadataV1) SyncnetsBitfield() bitfield.Bitvector4 {
131132
}
132133

133134
// CustodySubnetCount returns custody subnet count from the metadata.
134-
func (m MetadataV1) CustodySubnetCount() uint64 {
135+
func (m MetadataV1) CustodySubnetCount() uint8 {
135136
return 0
136137
}
137138

@@ -225,8 +226,8 @@ func (m MetadataV2) SyncnetsBitfield() bitfield.Bitvector4 {
225226
}
226227

227228
// CustodySubnetCount returns custody subnet count from the metadata.
228-
func (m MetadataV2) CustodySubnetCount() uint64 {
229-
return m.md.CustodySubnetCount
229+
func (m MetadataV2) CustodySubnetCount() uint8 {
230+
return bytesutil.FromBytes1(m.md.CustodySubnetCount)
230231
}
231232

232233
// InnerObject returns the underlying metadata protobuf structure.

0 commit comments

Comments
 (0)