diff options
Diffstat (limited to 'p2p/simulations/adapters/inproc.go')
-rw-r--r-- | p2p/simulations/adapters/inproc.go | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/p2p/simulations/adapters/inproc.go b/p2p/simulations/adapters/inproc.go index bdfbf1c73..991573c2d 100644 --- a/p2p/simulations/adapters/inproc.go +++ b/p2p/simulations/adapters/inproc.go @@ -28,6 +28,7 @@ import ( "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/enode" + "github.com/ethereum/go-ethereum/p2p/enr" "github.com/ethereum/go-ethereum/p2p/simulations/pipes" "github.com/ethereum/go-ethereum/rpc" ) @@ -71,8 +72,13 @@ func (s *SimAdapter) NewNode(config *NodeConfig) (Node, error) { s.mtx.Lock() defer s.mtx.Unlock() - // check a node with the ID doesn't already exist id := config.ID + // verify that the node has a private key in the config + if config.PrivateKey == nil { + return nil, fmt.Errorf("node is missing private key: %s", id) + } + + // check a node with the ID doesn't already exist if _, exists := s.nodes[id]; exists { return nil, fmt.Errorf("node already exists: %s", id) } @@ -87,6 +93,24 @@ func (s *SimAdapter) NewNode(config *NodeConfig) (Node, error) { } } + // dialer in simulations based on ENR records + // doesn't work unless we explicitly set localhost record + ip := enr.IP(net.IPv4(127, 0, 0, 1)) + config.Record.Set(&ip) + tcpPort := enr.TCP(0) + config.Record.Set(&tcpPort) + + err := enode.SignV4(&config.Record, config.PrivateKey) + if err != nil { + return nil, fmt.Errorf("unable to generate ENR: %v", err) + } + nod, err := enode.New(enode.V4ID{}, &config.Record) + if err != nil { + return nil, fmt.Errorf("unable to create enode: %v", err) + } + log.Trace("simnode new", "record", config.Record) + config.node = nod + n, err := node.New(&node.Config{ P2P: p2p.Config{ PrivateKey: config.PrivateKey, |