@@ -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.
337357func (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.
12151235func (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.
13611395func (c * DBFT ) EnforceECDSASignatures () {
0 commit comments