Browse Source

node: use db provider instead of mem db (#6362)

pull/6367/head
Callum Waters 4 years ago
committed by GitHub
parent
commit
8e8de2b2fb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 8 deletions
  1. +14
    -8
      node/node.go
  2. +1
    -0
      node/node_test.go
  3. +1
    -0
      test/e2e/app/main.go

+ 14
- 8
node/node.go View File

@ -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)
}


+ 1
- 0
node/node_test.go View File

@ -533,6 +533,7 @@ func TestNodeNewSeedNode(t *testing.T) {
require.NoError(t, err)
n, err := NewSeedNode(config,
DefaultDBProvider,
nodeKey,
DefaultGenesisDocProviderFunc(config),
log.TestingLogger(),


+ 1
- 0
test/e2e/app/main.go View File

@ -156,6 +156,7 @@ func startSeedNode(cfg *Config) error {
n, err := node.NewSeedNode(
tmcfg,
node.DefaultDBProvider,
*nodeKey,
node.DefaultGenesisDocProviderFunc(tmcfg),
nodeLogger,


Loading…
Cancel
Save