Skip to content

Commit 86ff29d

Browse files
committed
refactor consensus follower to use protocol db
1 parent ce72d37 commit 86ff29d

File tree

3 files changed

+18
-58
lines changed

3 files changed

+18
-58
lines changed

cmd/node_builder.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ type BaseConfig struct {
158158
pebbleDir string
159159
pebbleCheckpointsDir string
160160
DBOps string
161-
badgerDB *badger.DB
162-
pebbleDB *pebble.DB
161+
protocolDB storage.DB
163162
secretsdir string
164163
secretsDBEnabled bool
165164
InsecureSecretsDB bool
@@ -265,7 +264,7 @@ type StateExcerptAtBoot struct {
265264
}
266265

267266
func DefaultBaseConfig() *BaseConfig {
268-
datadir := "/data/protocol"
267+
datadir := "/data/protocol-pebble"
269268
pebbleDir := "/data/protocol-pebble"
270269

271270
// NOTE: if the codec used in the network component is ever changed any code relying on
@@ -285,8 +284,7 @@ func DefaultBaseConfig() *BaseConfig {
285284
datadir: datadir,
286285
pebbleDir: pebbleDir,
287286
DBOps: string(dbops.PebbleBatch), // "pebble-batch" (default) or "badger-batch" (deprecated)
288-
badgerDB: nil,
289-
pebbleDB: nil,
287+
protocolDB: nil,
290288
secretsdir: NotSet,
291289
secretsDBEnabled: true,
292290
level: "info",

cmd/scaffold.go

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,55 +1973,29 @@ func WithBindAddress(bindAddress string) Option {
19731973
}
19741974
}
19751975

1976-
// WithDataDir set the data directory for the badger database
1977-
// It will be ignored if WithBadgerDB is used
1978-
func WithDataDir(dataDir string) Option {
1976+
// WithProtocolDir set the protocol data directory for the database
1977+
// It will be ignored if WithProtocolDB is used
1978+
func WithProtocolDir(dataDir string) Option {
19791979
return func(config *BaseConfig) {
1980-
if config.badgerDB != nil {
1981-
log.Warn().Msgf("ignoring data directory %s as badger database is already set", dataDir)
1980+
if config.protocolDB != nil {
1981+
log.Warn().Msgf("ignoring data directory %s as storage database is already set", dataDir)
19821982
return
19831983
}
19841984

19851985
config.datadir = dataDir
19861986
}
19871987
}
19881988

1989-
// WithBadgerDB sets the badger database instance
1989+
// WithProtocolDB sets the storage database instance
19901990
// If used, then WithDataDir method will be ignored
1991-
func WithBadgerDB(db *badger.DB) Option {
1991+
func WithProtocolDB(db storage.DB) Option {
19921992
return func(config *BaseConfig) {
19931993
if config.datadir != "" && config.datadir != NotSet {
19941994
log.Warn().Msgf("ignoring data directory is already set for badger %v", config.datadir)
19951995
config.datadir = ""
19961996
}
19971997

1998-
config.badgerDB = db
1999-
}
2000-
}
2001-
2002-
// WithPebbleDir set the data directory for the pebble database
2003-
// It will be ignored if WithPebbleDB is used
2004-
func WithPebbleDir(dataDir string) Option {
2005-
return func(config *BaseConfig) {
2006-
if config.pebbleDB != nil {
2007-
log.Warn().Msgf("ignoring data directory %s as pebble database is already set", dataDir)
2008-
return
2009-
}
2010-
2011-
config.pebbleDir = dataDir
2012-
}
2013-
}
2014-
2015-
// WithPebbleDB sets the pebble database instance
2016-
// If used, then WithPebbleDir method will be ignored
2017-
func WithPebbleDB(db *pebble.DB) Option {
2018-
return func(config *BaseConfig) {
2019-
if config.pebbleDir != "" && config.pebbleDir != NotSet {
2020-
log.Warn().Msgf("ignoring data directory is already set for pebble %v", config.pebbleDir)
2021-
config.pebbleDir = ""
2022-
}
2023-
2024-
config.pebbleDB = db
1998+
config.protocolDB = db
20251999
}
20262000
}
20272001

follower/consensus_follower.go

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import (
55
"fmt"
66
"sync"
77

8-
"github.com/cockroachdb/pebble/v2"
9-
"github.com/dgraph-io/badger/v2"
108
"github.com/jordanschalm/lockctx"
119
"github.com/onflow/crypto"
1210
"github.com/rs/zerolog"
@@ -20,6 +18,7 @@ import (
2018
"github.com/onflow/flow-go/module/component"
2119
"github.com/onflow/flow-go/module/irrecoverable"
2220
"github.com/onflow/flow-go/module/util"
21+
"github.com/onflow/flow-go/storage"
2322
)
2423

2524
// ConsensusFollower is a standalone module run by third parties which provides
@@ -38,8 +37,7 @@ type Config struct {
3837
networkPrivKey crypto.PrivateKey // the network private key of this node
3938
bootstrapNodes []BootstrapNodeInfo // the bootstrap nodes to use
4039
bindAddr string // address to bind on
41-
badgerDB *badger.DB // badger instance
42-
pebbleDB *pebble.DB // pebble instance
40+
protocolDB storage.DB // badger instance
4341
bootstrapDir string // path to the bootstrap directory
4442
logLevel string // log level
4543
exposeMetrics bool // whether to expose metrics
@@ -53,15 +51,9 @@ type Config struct {
5351
type Option func(c *Config)
5452

5553
// currently used by rosetta
56-
func WithDB(db *badger.DB) Option {
54+
func WithProtocolDB(db storage.DB) Option {
5755
return func(cf *Config) {
58-
cf.badgerDB = db
59-
}
60-
}
61-
62-
func WithPebbleDB(db *pebble.DB) Option {
63-
return func(cf *Config) {
64-
cf.pebbleDB = db
56+
cf.protocolDB = db
6557
}
6658
}
6759

@@ -145,11 +137,8 @@ func getBaseOptions(config *Config) []cmd.Option {
145137
if config.bindAddr != "" {
146138
options = append(options, cmd.WithBindAddress(config.bindAddr))
147139
}
148-
if config.badgerDB != nil {
149-
options = append(options, cmd.WithBadgerDB(config.badgerDB))
150-
}
151-
if config.pebbleDB != nil {
152-
options = append(options, cmd.WithPebbleDB(config.pebbleDB))
140+
if config.protocolDB != nil {
141+
options = append(options, cmd.WithProtocolDB(config.protocolDB))
153142
}
154143
if config.logLevel != "" {
155144
options = append(options, cmd.WithLogLevel(config.logLevel))
@@ -196,8 +185,7 @@ func NewConsensusFollower(
196185
networkPrivKey: networkPrivKey,
197186
bootstrapNodes: bootstapIdentities,
198187
bindAddr: bindAddr,
199-
badgerDB: nil,
200-
pebbleDB: nil,
188+
protocolDB: nil,
201189
logLevel: "info",
202190
exposeMetrics: false,
203191
lockManager: nil, // default to nil, can be set optionally with WithLockManager in tests

0 commit comments

Comments
 (0)