|
|
@ -348,27 +348,6 @@ func NewNode(config *cfg.Config, |
|
|
|
transport.AddChannelDescriptors(evReactorShim.GetChannels()) |
|
|
|
transport.AddChannelDescriptors(stateSyncReactorShim.GetChannels()) |
|
|
|
|
|
|
|
// setup Transport and Switch
|
|
|
|
sw := createSwitch( |
|
|
|
config, transport, p2pMetrics, mpReactorShim, bcReactorForSwitch, |
|
|
|
stateSyncReactorShim, csReactorShim, evReactorShim, proxyApp, nodeInfo, nodeKey, p2pLogger, |
|
|
|
) |
|
|
|
|
|
|
|
err = sw.AddPersistentPeers(strings.SplitAndTrimEmpty(config.P2P.PersistentPeers, ",", " ")) |
|
|
|
if err != nil { |
|
|
|
return nil, fmt.Errorf("could not add peers from persistent-peers field: %w", err) |
|
|
|
} |
|
|
|
|
|
|
|
err = sw.AddUnconditionalPeerIDs(strings.SplitAndTrimEmpty(config.P2P.UnconditionalPeerIDs, ",", " ")) |
|
|
|
if err != nil { |
|
|
|
return nil, fmt.Errorf("could not add peer ids from unconditional_peer_ids field: %w", err) |
|
|
|
} |
|
|
|
|
|
|
|
addrBook, err := createAddrBookAndSetOnSwitch(config, sw, p2pLogger, nodeKey) |
|
|
|
if err != nil { |
|
|
|
return nil, fmt.Errorf("could not create addrbook: %w", err) |
|
|
|
} |
|
|
|
|
|
|
|
// Optionally, start the pex reactor
|
|
|
|
//
|
|
|
|
// TODO:
|
|
|
@ -381,22 +360,46 @@ func NewNode(config *cfg.Config, |
|
|
|
//
|
|
|
|
// If PEX is on, it should handle dialing the seeds. Otherwise the switch does it.
|
|
|
|
// Note we currently use the addrBook regardless at least for AddOurAddress
|
|
|
|
|
|
|
|
var ( |
|
|
|
pexReactor *pex.Reactor |
|
|
|
pexReactorV2 *pex.ReactorV2 |
|
|
|
sw *p2p.Switch |
|
|
|
addrBook pex.AddrBook |
|
|
|
) |
|
|
|
|
|
|
|
if config.P2P.PexReactor { |
|
|
|
pexCh := pex.ChannelDescriptor() |
|
|
|
transport.AddChannelDescriptors([]*p2p.ChannelDescriptor{&pexCh}) |
|
|
|
if config.P2P.DisableLegacy { |
|
|
|
pexReactorV2, err = createPEXReactorV2(config, logger, peerManager, router) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} else { |
|
|
|
pexReactor = createPEXReactorAndAddToSwitch(addrBook, config, sw, logger) |
|
|
|
pexCh := pex.ChannelDescriptor() |
|
|
|
transport.AddChannelDescriptors([]*p2p.ChannelDescriptor{&pexCh}) |
|
|
|
|
|
|
|
if config.P2P.DisableLegacy { |
|
|
|
addrBook = nil |
|
|
|
pexReactorV2, err = createPEXReactorV2(config, logger, peerManager, router) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} else { |
|
|
|
// setup Transport and Switch
|
|
|
|
sw = createSwitch( |
|
|
|
config, transport, p2pMetrics, mpReactorShim, bcReactorForSwitch, |
|
|
|
stateSyncReactorShim, csReactorShim, evReactorShim, proxyApp, nodeInfo, nodeKey, p2pLogger, |
|
|
|
) |
|
|
|
|
|
|
|
err = sw.AddPersistentPeers(strings.SplitAndTrimEmpty(config.P2P.PersistentPeers, ",", " ")) |
|
|
|
if err != nil { |
|
|
|
return nil, fmt.Errorf("could not add peers from persistent-peers field: %w", err) |
|
|
|
} |
|
|
|
|
|
|
|
err = sw.AddUnconditionalPeerIDs(strings.SplitAndTrimEmpty(config.P2P.UnconditionalPeerIDs, ",", " ")) |
|
|
|
if err != nil { |
|
|
|
return nil, fmt.Errorf("could not add peer ids from unconditional_peer_ids field: %w", err) |
|
|
|
} |
|
|
|
|
|
|
|
addrBook, err = createAddrBookAndSetOnSwitch(config, sw, p2pLogger, nodeKey) |
|
|
|
if err != nil { |
|
|
|
return nil, fmt.Errorf("could not create addrbook: %w", err) |
|
|
|
} |
|
|
|
|
|
|
|
pexReactor = createPEXReactorAndAddToSwitch(addrBook, config, sw, logger) |
|
|
|
} |
|
|
|
|
|
|
|
if config.RPC.PprofListenAddress != "" { |
|
|
@ -609,9 +612,6 @@ func (n *Node) OnStart() error { |
|
|
|
time.Sleep(genTime.Sub(now)) |
|
|
|
} |
|
|
|
|
|
|
|
// Add private IDs to addrbook to block those peers being added
|
|
|
|
n.addrBook.AddPrivateIDs(strings.SplitAndTrimEmpty(n.config.P2P.PrivatePeerIDs, ",", " ")) |
|
|
|
|
|
|
|
// Start the RPC server before the P2P server
|
|
|
|
// so we can eg. receive txs for the first block
|
|
|
|
if n.config.RPC.ListenAddress != "" && n.config.Mode != cfg.ModeSeed { |
|
|
@ -643,6 +643,8 @@ func (n *Node) OnStart() error { |
|
|
|
if n.config.P2P.DisableLegacy { |
|
|
|
err = n.router.Start() |
|
|
|
} else { |
|
|
|
// Add private IDs to addrbook to block those peers being added
|
|
|
|
n.addrBook.AddPrivateIDs(strings.SplitAndTrimEmpty(n.config.P2P.PrivatePeerIDs, ",", " ")) |
|
|
|
err = n.sw.Start() |
|
|
|
} |
|
|
|
if err != nil { |
|
|
@ -682,12 +684,13 @@ func (n *Node) OnStart() error { |
|
|
|
if err := n.pexReactorV2.Start(); err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
// Always connect to persistent peers
|
|
|
|
err = n.sw.DialPeersAsync(strings.SplitAndTrimEmpty(n.config.P2P.PersistentPeers, ",", " ")) |
|
|
|
if err != nil { |
|
|
|
return fmt.Errorf("could not dial peers from persistent-peers field: %w", err) |
|
|
|
} |
|
|
|
|
|
|
|
// Always connect to persistent peers
|
|
|
|
err = n.sw.DialPeersAsync(strings.SplitAndTrimEmpty(n.config.P2P.PersistentPeers, ",", " ")) |
|
|
|
if err != nil { |
|
|
|
return fmt.Errorf("could not dial peers from persistent-peers field: %w", err) |
|
|
|
} |
|
|
|
|
|
|
|
// Run state sync
|
|
|
|