From 8e8de2b2fb91ce45f5838223b29eaa376add5692 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Fri, 16 Apr 2021 19:07:18 +0200 Subject: [PATCH] node: use db provider instead of mem db (#6362) --- node/node.go | 22 ++++++++++++++-------- node/node_test.go | 1 + test/e2e/app/main.go | 1 + 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/node/node.go b/node/node.go index 7d8555a25..79d971f2b 100644 --- a/node/node.go +++ b/node/node.go @@ -96,6 +96,7 @@ func DefaultNewNode(config *cfg.Config, logger log.Logger) (*Node, error) { } if config.Mode == cfg.ModeSeed { return NewSeedNode(config, + DefaultDBProvider, nodeKey, DefaultGenesisDocProviderFunc(config), logger, @@ -240,10 +241,6 @@ func initDBs(config *cfg.Config, dbProvider DBProvider) (blockStore *store.Block blockStore = store.NewBlockStore(blockStoreDB) stateDB, err = dbProvider(&DBContext{"state", config}) - if err != nil { - return - } - return } @@ -584,7 +581,11 @@ func createTransport(logger log.Logger, config *cfg.Config) *p2p.MConnTransport ) } -func createPeerManager(config *cfg.Config, p2pLogger log.Logger, nodeID p2p.NodeID) (*p2p.PeerManager, error) { +func createPeerManager( + config *cfg.Config, + dbProvider DBProvider, + p2pLogger log.Logger, + nodeID p2p.NodeID) (*p2p.PeerManager, error) { var maxConns uint16 switch { case config.P2P.MaxConnections > 0: @@ -628,7 +629,11 @@ func createPeerManager(config *cfg.Config, p2pLogger log.Logger, nodeID p2p.Node options.PersistentPeers = append(options.PersistentPeers, address.NodeID) } - peerManager, err := p2p.NewPeerManager(nodeID, dbm.NewMemDB(), options) + peerDB, err := dbProvider(&DBContext{"peerstore", config}) + if err != nil { + return nil, err + } + peerManager, err := p2p.NewPeerManager(nodeID, peerDB, options) if err != nil { return nil, fmt.Errorf("failed to create peer manager: %w", err) } @@ -876,6 +881,7 @@ func startStateSync(ssR *statesync.Reactor, bcR fastSyncReactor, conR *cs.Reacto // NewSeedNode returns a new seed node, containing only p2p, pex reactor func NewSeedNode(config *cfg.Config, + dbProvider DBProvider, nodeKey p2p.NodeKey, genesisDocProvider GenesisDocProvider, logger log.Logger, @@ -920,7 +926,7 @@ func NewSeedNode(config *cfg.Config, return nil, fmt.Errorf("could not create addrbook: %w", err) } - peerManager, err := createPeerManager(config, p2pLogger, nodeKey.ID) + peerManager, err := createPeerManager(config, dbProvider, p2pLogger, nodeKey.ID) if err != nil { return nil, fmt.Errorf("failed to create peer manager: %w", err) } @@ -1081,7 +1087,7 @@ func NewNode(config *cfg.Config, p2pLogger := logger.With("module", "p2p") transport := createTransport(p2pLogger, config) - peerManager, err := createPeerManager(config, p2pLogger, nodeKey.ID) + peerManager, err := createPeerManager(config, dbProvider, p2pLogger, nodeKey.ID) if err != nil { return nil, fmt.Errorf("failed to create peer manager: %w", err) } diff --git a/node/node_test.go b/node/node_test.go index 3290dbcd2..21830804d 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -533,6 +533,7 @@ func TestNodeNewSeedNode(t *testing.T) { require.NoError(t, err) n, err := NewSeedNode(config, + DefaultDBProvider, nodeKey, DefaultGenesisDocProviderFunc(config), log.TestingLogger(), diff --git a/test/e2e/app/main.go b/test/e2e/app/main.go index cb49b8303..b1b96deeb 100644 --- a/test/e2e/app/main.go +++ b/test/e2e/app/main.go @@ -156,6 +156,7 @@ func startSeedNode(cfg *Config) error { n, err := node.NewSeedNode( tmcfg, + node.DefaultDBProvider, *nodeKey, node.DefaultGenesisDocProviderFunc(tmcfg), nodeLogger,