Skip to content

Commit

Permalink
Update Config To Latest Value (#14352)
Browse files Browse the repository at this point in the history
* Update values

* Update Spec To v1.5.0-alpha.5

* Fix Discovery Tests

* Hardcode Subnet Count For Tests

* Fix All Initial Sync Tests

* Gazelle

* Less Chaotic Service Initialization

* Gazelle
  • Loading branch information
nisdas authored and nalepae committed Aug 28, 2024
1 parent 9612e3a commit 1f5276a
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 126 deletions.
4 changes: 2 additions & 2 deletions beacon-chain/p2p/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func TestCreateLocalNode(t *testing.T) {
// Check custody_subnet_count config.
custodySubnetCount := new(uint64)
require.NoError(t, localNode.Node().Record().Load(enr.WithEntry(peerdas.CustodySubnetCountEnrKey, custodySubnetCount)))
require.Equal(t, uint64(1), *custodySubnetCount)
require.Equal(t, params.BeaconConfig().CustodyRequirement, *custodySubnetCount)
})
}
}
Expand Down Expand Up @@ -565,7 +565,7 @@ func TestRefreshPersistentSubnets(t *testing.T) {
eip7594ForkEpoch = 10
)

custodySubnetCount := uint64(1)
custodySubnetCount := params.BeaconConfig().CustodyRequirement

// Set up epochs.
defaultCfg := params.BeaconConfig()
Expand Down
5 changes: 3 additions & 2 deletions beacon-chain/p2p/testing/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const (
type TestP2P struct {
t *testing.T
BHost host.Host
EnodeID enode.ID
pubsub *pubsub.PubSub
joinedTopics map[string]*pubsub.Topic
BroadcastCalled atomic.Bool
Expand Down Expand Up @@ -277,8 +278,8 @@ func (*TestP2P) ENR() *enr.Record {
}

// NodeID returns the node id of the local peer.
func (*TestP2P) NodeID() enode.ID {
return [32]byte{}
func (p *TestP2P) NodeID() enode.ID {
return p.EnodeID
}

// DiscoveryAddresses --
Expand Down
35 changes: 30 additions & 5 deletions beacon-chain/sync/data_columns_sampling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"crypto/sha256"
"encoding/binary"
"fmt"
"testing"

"github.com/consensys/gnark-crypto/ecc/bls12-381/fr"
Expand Down Expand Up @@ -204,12 +205,14 @@ func TestDataColumnSampler1D_PeerManagement(t *testing.T) {
testCases := []struct {
numPeers int
custodyRequirement uint64
subnetCount uint64
expectedColumns [][]uint64
prunePeers map[int]bool // Peers to prune.
}{
{
numPeers: 3,
custodyRequirement: 1,
subnetCount: 32,
expectedColumns: [][]uint64{
{6, 38, 70, 102},
{3, 35, 67, 99},
Expand All @@ -222,6 +225,7 @@ func TestDataColumnSampler1D_PeerManagement(t *testing.T) {
{
numPeers: 3,
custodyRequirement: 2,
subnetCount: 32,
expectedColumns: [][]uint64{
{6, 16, 38, 48, 70, 80, 102, 112},
{3, 13, 35, 45, 67, 77, 99, 109},
Expand All @@ -233,7 +237,12 @@ func TestDataColumnSampler1D_PeerManagement(t *testing.T) {
},
}

params.SetupTestConfigCleanup(t)
for _, tc := range testCases {
cfg := params.BeaconConfig()
cfg.CustodyRequirement = tc.custodyRequirement
cfg.DataColumnSidecarSubnetCount = tc.subnetCount
params.OverrideBeaconConfig(cfg)
test, sampler := setupDataColumnSamplerTest(t, uint64(tc.numPeers))
for i := 0; i < tc.numPeers; i++ {
p := createAndConnectPeer(t, test.p2pSvc, test.chainSvc, test.dataColumnSidecars, tc.custodyRequirement, nil, i+1)
Expand Down Expand Up @@ -283,12 +292,14 @@ func TestDataColumnSampler1D_SampleDistribution(t *testing.T) {
testCases := []struct {
numPeers int
custodyRequirement uint64
subnetCount uint64
columnsToDistribute [][]uint64
expectedDistribution []map[int][]uint64
}{
{
numPeers: 3,
custodyRequirement: 1,
subnetCount: 32,
// peer custody maps
// p0: {6, 38, 70, 102},
// p1: {3, 35, 67, 99},
Expand Down Expand Up @@ -319,6 +330,7 @@ func TestDataColumnSampler1D_SampleDistribution(t *testing.T) {
{
numPeers: 3,
custodyRequirement: 2,
subnetCount: 32,
// peer custody maps
// p0: {6, 16, 38, 48, 70, 80, 102, 112},
// p1: {3, 13, 35, 45, 67, 77, 99, 109},
Expand All @@ -341,8 +353,12 @@ func TestDataColumnSampler1D_SampleDistribution(t *testing.T) {
},
},
}

params.SetupTestConfigCleanup(t)
for _, tc := range testCases {
cfg := params.BeaconConfig()
cfg.CustodyRequirement = tc.custodyRequirement
cfg.DataColumnSidecarSubnetCount = tc.subnetCount
params.OverrideBeaconConfig(cfg)
test, sampler := setupDataColumnSamplerTest(t, uint64(tc.numPeers))
for i := 0; i < tc.numPeers; i++ {
p := createAndConnectPeer(t, test.p2pSvc, test.chainSvc, test.dataColumnSidecars, tc.custodyRequirement, nil, i+1)
Expand All @@ -352,7 +368,7 @@ func TestDataColumnSampler1D_SampleDistribution(t *testing.T) {

for idx, columns := range tc.columnsToDistribute {
result := sampler.distributeSamplesToPeer(columns)
require.Equal(t, len(tc.expectedDistribution[idx]), len(result))
require.Equal(t, len(tc.expectedDistribution[idx]), len(result), fmt.Sprintf("%v - %v", tc.expectedDistribution[idx], result))

for peerIdx, dist := range tc.expectedDistribution[idx] {
for _, column := range dist {
Expand All @@ -365,6 +381,10 @@ func TestDataColumnSampler1D_SampleDistribution(t *testing.T) {
}

func TestDataColumnSampler1D_SampleDataColumns(t *testing.T) {
params.SetupTestConfigCleanup(t)
cfg := params.BeaconConfig()
cfg.DataColumnSidecarSubnetCount = 32
params.OverrideBeaconConfig(cfg)
test, sampler := setupDefaultDataColumnSamplerTest(t)
sampler.refreshPeerInfo()

Expand Down Expand Up @@ -392,6 +412,11 @@ func TestDataColumnSampler1D_SampleDataColumns(t *testing.T) {
}

func TestDataColumnSampler1D_IncrementalDAS(t *testing.T) {
params.SetupTestConfigCleanup(t)
cfg := params.BeaconConfig()
cfg.DataColumnSidecarSubnetCount = 32
params.OverrideBeaconConfig(cfg)

testCases := []struct {
name string
samplesCount uint64
Expand Down Expand Up @@ -451,9 +476,9 @@ func TestDataColumnSampler1D_IncrementalDAS(t *testing.T) {

for _, tc := range testCases {
test, sampler := setupDataColumnSamplerTest(t, 3)
p1 := createAndConnectPeer(t, test.p2pSvc, test.chainSvc, test.dataColumnSidecars, 1, tc.columnsNotToRespond, 1)
p2 := createAndConnectPeer(t, test.p2pSvc, test.chainSvc, test.dataColumnSidecars, 1, tc.columnsNotToRespond, 2)
p3 := createAndConnectPeer(t, test.p2pSvc, test.chainSvc, test.dataColumnSidecars, 1, tc.columnsNotToRespond, 3)
p1 := createAndConnectPeer(t, test.p2pSvc, test.chainSvc, test.dataColumnSidecars, params.BeaconConfig().CustodyRequirement, tc.columnsNotToRespond, 1)
p2 := createAndConnectPeer(t, test.p2pSvc, test.chainSvc, test.dataColumnSidecars, params.BeaconConfig().CustodyRequirement, tc.columnsNotToRespond, 2)
p3 := createAndConnectPeer(t, test.p2pSvc, test.chainSvc, test.dataColumnSidecars, params.BeaconConfig().CustodyRequirement, tc.columnsNotToRespond, 3)
test.peers = []*p2ptest.TestP2P{p1, p2, p3}

sampler.refreshPeerInfo()
Expand Down
Loading

0 comments on commit 1f5276a

Please sign in to comment.