Skip to content

Commit

Permalink
Less Chaotic Service Initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
nisdas committed Aug 22, 2024
1 parent 2ea7c37 commit a5cc0fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
12 changes: 2 additions & 10 deletions beacon-chain/p2p/testing/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/multiformats/go-multiaddr"
ssz "github.com/prysmaticlabs/fastssz"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/peerdas"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/encoder"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/peers"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/peers/scorers"
Expand All @@ -47,7 +46,7 @@ const (
type TestP2P struct {
t *testing.T
BHost host.Host
UseNodeID bool
EnodeID enode.ID
pubsub *pubsub.PubSub
joinedTopics map[string]*pubsub.Topic
BroadcastCalled atomic.Bool
Expand Down Expand Up @@ -280,14 +279,7 @@ func (*TestP2P) ENR() *enr.Record {

// NodeID returns the node id of the local peer.
func (p *TestP2P) NodeID() enode.ID {
if p.UseNodeID {
nodeID, err := p2p.ConvertPeerIDToNodeID(p.BHost.ID())
if err != nil {
p.t.Fatal(err)
}
return nodeID
}
return [32]byte{}
return p.EnodeID
}

// DiscoveryAddresses --
Expand Down
10 changes: 6 additions & 4 deletions beacon-chain/sync/initial-sync/blocks_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2071,13 +2071,15 @@ func TestFetchDataColumnsFromPeers(t *testing.T) {
chain, clock := defaultMockChain(t, tc.currentSlot)

// Create the P2P service.
p2p := p2ptest.NewTestP2P(t, swarmt.OptPeerPrivateKey(genFixedCustodyPeer(t)))
p2p.UseNodeID = true
p2pSvc := p2ptest.NewTestP2P(t, swarmt.OptPeerPrivateKey(genFixedCustodyPeer(t)))
nodeID, err := p2p.ConvertPeerIDToNodeID(p2pSvc.PeerID())
require.NoError(t, err)
p2pSvc.EnodeID = nodeID

// Connect the peers.
peers := make([]*p2ptest.TestP2P, 0, len(tc.peersParams))
for i, peerParams := range tc.peersParams {
peer := createAndConnectPeer(t, p2p, chain, dataColumnsSidecarFromSlot, peerParams, i)
peer := createAndConnectPeer(t, p2pSvc, chain, dataColumnsSidecarFromSlot, peerParams, i)
peers = append(peers, peer)
}

Expand All @@ -2097,7 +2099,7 @@ func TestFetchDataColumnsFromPeers(t *testing.T) {
blocksFetcher := newBlocksFetcher(ctx, &blocksFetcherConfig{
clock: clock,
ctxMap: map[[4]byte]int{{245, 165, 253, 66}: version.Deneb},
p2p: p2p,
p2p: p2pSvc,
bs: blobStorageSummarizer,
})

Expand Down

0 comments on commit a5cc0fd

Please sign in to comment.