Skip to content

Commit

Permalink
op-node: static-peers test
Browse files Browse the repository at this point in the history
  • Loading branch information
protolambda committed Nov 2, 2023
1 parent 48962ac commit 14d154d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion op-node/p2p/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func (conf *Config) Host(log log.Logger, reporter metrics.Reporter, metrics Host
return nil, fmt.Errorf("bad peer address: %w", err)
}
if addr.ID == h.ID() {
log.Info("Static-peer list contains address of local peer, ignoring the address.", "address", addr)
log.Info("Static-peer list contains address of local peer, ignoring the address.", "peer_id", addr.ID, "addrs", addr.Addrs)
continue
}
staticPeers = append(staticPeers, addr)
Expand Down
11 changes: 11 additions & 0 deletions op-node/p2p/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
ma "github.com/multiformats/go-multiaddr"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"

Expand Down Expand Up @@ -139,13 +140,23 @@ func TestP2PFull(t *testing.T) {
confB.StaticPeers, err = peer.AddrInfoToP2pAddrs(&peer.AddrInfo{ID: hostA.ID(), Addrs: hostA.Addrs()})
require.NoError(t, err)

// Add address of host B itself, it shouldn't connect or cause issues.
idB, err := peer.IDFromPublicKey(confB.Priv.GetPublic())
require.NoError(t, err)
altAddrB, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/12345/p2p/" + idB.String())
require.NoError(t, err)
confB.StaticPeers = append(confB.StaticPeers, altAddrB)

logB := testlog.Logger(t, log.LvlError).New("host", "B")

nodeB, err := NewNodeP2P(context.Background(), &rollup.Config{}, logB, &confB, &mockGossipIn{}, nil, runCfgB, metrics.NoopMetrics)
require.NoError(t, err)
defer nodeB.Close()
hostB := nodeB.Host()

require.True(t, nodeB.IsStatic(hostA.ID()), "node A must be static peer of node B")
require.False(t, nodeB.IsStatic(hostB.ID()), "node B must not be static peer of node B itself")

select {
case <-time.After(time.Second):
t.Fatal("failed to connect new host")
Expand Down

0 comments on commit 14d154d

Please sign in to comment.