Skip to content

Commit 54e0d48

Browse files
authored
Merge pull request #419 from bane-labs/reduce-logs-verbosity
dBFT: add ability to customize log level
2 parents 4dc35d3 + c05fcb3 commit 54e0d48

File tree

6 files changed

+55
-2
lines changed

6 files changed

+55
-2
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ define run_node
107107
--metrics \
108108
--nat $(NAT_POLICY) \
109109
--netrestrict $(RESTRICTED_NETWORK) \
110+
--dbft.loglevel debug \
110111
$(7) > $(1)/$(2)/geth_node.log 2>&1 &
111112
endef
112113

cmd/geth/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ var (
131131
utils.AntiMEVKeyStoreFlag,
132132
utils.AntiMEVEnforceECDSABlockSignatureSchemeFlag,
133133
utils.AntiMEVPasswordFlag,
134+
utils.DBFTLogLevelFlag,
134135
utils.NATFlag,
135136
utils.NoDiscoverFlag,
136137
utils.DiscoveryV4Flag,

cmd/utils/flags.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,11 @@ var (
587587
Usage: "Disables db compaction after import",
588588
Category: flags.LoggingCategory,
589589
}
590+
DBFTLogLevelFlag = &cli.StringFlag{
591+
Name: "dbft.loglevel",
592+
Usage: `Logging level to use for dBFT consensus engine events. The following values are supported: "debug", "info" (default), "warn", "error", "dpanic", "panic", "fatal"`,
593+
Category: flags.LoggingCategory,
594+
}
590595

591596
// MISC settings
592597
SyncTargetFlag = &cli.StringFlag{
@@ -1742,6 +1747,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
17421747
if ctx.IsSet(AntiMEVEnforceECDSABlockSignatureSchemeFlag.Name) {
17431748
cfg.AntiMEVEnforceECDSABlockSignatureScheme = ctx.Bool(AntiMEVEnforceECDSABlockSignatureSchemeFlag.Name)
17441749
}
1750+
if ctx.IsSet(DBFTLogLevelFlag.Name) {
1751+
cfg.DBFTLogLevel = ctx.String(DBFTLogLevelFlag.Name)
1752+
}
17451753
if !ctx.Bool(SnapshotFlag.Name) || cfg.SnapshotCache == 0 {
17461754
// If snap-sync is requested, this flag is also required
17471755
if cfg.SyncMode == downloader.SnapSync {

consensus/dbft/dbft.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import (
6363
"github.com/nspcc-dev/dbft"
6464
"github.com/nspcc-dev/dbft/timer"
6565
"go.uber.org/zap"
66+
"go.uber.org/zap/zapcore"
6667
"golang.org/x/crypto/sha3"
6768
"golang.org/x/exp/slices"
6869
)
@@ -234,6 +235,7 @@ type config struct {
234235
dkgEnablingHeight int64
235236
antiMEVEnablingHeight int64
236237
enforceECDSASignatures bool
238+
logLevel *zap.AtomicLevel
237239
}
238240

239241
// New creates a DBFT proof-of-authority consensus engine with the initial
@@ -284,10 +286,11 @@ func New(chainCfg *params.ChainConfig, _ ethdb.Database) (*DBFT, error) {
284286
}
285287

286288
var err error
287-
logger, err := zap.NewDevelopment()
289+
logger, logLevel, err := buildLogger()
288290
if err != nil {
289291
return nil, fmt.Errorf("failed to initialize dBFT logger: %w", err)
290292
}
293+
c.config.logLevel = logLevel
291294
dbftCfg := []func(*dbft.Config[common.Hash]){
292295
dbft.WithTimer[common.Hash](timer.New()),
293296
dbft.WithLogger[common.Hash](logger),
@@ -333,6 +336,23 @@ func New(chainCfg *params.ChainConfig, _ ethdb.Database) (*DBFT, error) {
333336
return c, nil
334337
}
335338

339+
// buildLogger builds zap logger for dbft library events logging with Info level
340+
// used as a default.
341+
func buildLogger() (*zap.Logger, *zap.AtomicLevel, error) {
342+
cc := zap.NewProductionConfig()
343+
cc.DisableCaller = true
344+
cc.DisableStacktrace = true
345+
cc.EncoderConfig.EncodeDuration = zapcore.StringDurationEncoder
346+
cc.EncoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder
347+
cc.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
348+
cc.Encoding = "console"
349+
cc.Level = zap.NewAtomicLevelAt(zapcore.InfoLevel)
350+
cc.Sampling = nil
351+
352+
log, err := cc.Build()
353+
return log, &cc.Level, err
354+
}
355+
336356
// getKeyPairCb is a dbft library setting callback.
337357
func (c *DBFT) getKeyPairCb(keys []dbft.PublicKey) (int, dbft.PrivateKey, dbft.PublicKey) {
338358
c.lock.RLock()
@@ -1211,7 +1231,7 @@ func (c *DBFT) newLocalPool(parent *types.Header) *legacypool.LegacyPool {
12111231
return p
12121232
}
12131233

1214-
// ValidateDecryptedTx checks the validity of the transaction to determine whether the outer envelope transaction should be replaced.
1234+
// validateDecryptedTx checks the validity of the transaction to determine whether the outer envelope transaction should be replaced.
12151235
func (c *DBFT) validateDecryptedTx(head *types.Header, decryptedTx *types.Transaction, envelope *types.Transaction) error {
12161236
// Make sure the transaction is signed properly and has the same sender and nonce with envelope
12171237
if decryptedTx.Nonce() != envelope.Nonce() {
@@ -1356,6 +1376,20 @@ func (c *DBFT) WithEthAPIBackend(b ethapi.Backend) {
13561376
c.txAPI = ethapi.NewTransactionAPI(b, new(ethapi.AddrLocker))
13571377
}
13581378

1379+
// WithLogLevel updates dBFT logger log level to the provided one if specified.
1380+
func (c *DBFT) WithLogLevel(logLevel string) error {
1381+
if len(logLevel) == 0 {
1382+
return nil
1383+
}
1384+
1385+
level, err := zapcore.ParseLevel(logLevel)
1386+
if err != nil {
1387+
return fmt.Errorf("unexpected dBFT log level %s: %w", logLevel, err)
1388+
}
1389+
c.config.logLevel.SetLevel(level)
1390+
return nil
1391+
}
1392+
13591393
// EnforceECDSASignatures enforces ECDSA multisignature block signing scheme.
13601394
// This setting will be applied starting from NeoXAMEV fork.
13611395
func (c *DBFT) EnforceECDSASignatures() {

eth/backend.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
300300
bft.WithTxPool(eth.TxPool())
301301
bft.WithRequestTxs(eth.handler.BroadcastRequestTxs)
302302
bft.WithMux(eth.EventMux())
303+
err := bft.WithLogLevel(config.DBFTLogLevel)
304+
if err != nil {
305+
return nil, err
306+
}
303307
if config.AntiMEVEnforceECDSABlockSignatureScheme {
304308
bft.EnforceECDSASignatures()
305309
}

eth/ethconfig/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ type Config struct {
165165
// AntiMEVEnforceECDSABlockSignatureScheme enables ECDSA multisignatures for
166166
// block signing instead of threshold-based.
167167
AntiMEVEnforceECDSABlockSignatureScheme bool `toml:",omitempty"`
168+
169+
// DBFTLogLevel is a dBFT engine log level. The following values are allowed:
170+
// "debug", "info", "warn", "error", "dpanic", "panic", "fatal". If not specified,
171+
// "info" is used.
172+
DBFTLogLevel string `toml:",omitempty"`
168173
}
169174

170175
// CreateConsensusEngine creates a consensus engine for the given chain config.

0 commit comments

Comments
 (0)