diff --git a/consensus/polybft/blockchain_wrapper.go b/consensus/polybft/blockchain_wrapper.go index 4cac1b626a..dfefe69b80 100644 --- a/consensus/polybft/blockchain_wrapper.go +++ b/consensus/polybft/blockchain_wrapper.go @@ -1,7 +1,6 @@ package polybft import ( - "bytes" "errors" "fmt" "math/big" @@ -89,44 +88,14 @@ func (p *blockchainWrapper) CommitBlock(block *types.FullBlock) error { // ProcessBlock builds a final block from given 'block' on top of 'parent' func (p *blockchainWrapper) ProcessBlock(parent *types.Header, block *types.Block) (*types.FullBlock, error) { - p.logger.Debug("[BlockchainWrapper.ProcessBlock]", - "block number", block.Number(), "block hash", block.Hash(), - "parent state root", parent.StateRoot, "block state root", block.Header.StateRoot) - header := block.Header.Copy() start := time.Now().UTC() - transition, err := p.executor.BeginTxn(parent.StateRoot, header, types.BytesToAddress(header.Miner)) + transition, err := p.executor.ProcessBlock(parent.StateRoot, block, types.Address(header.Miner)) if err != nil { - return nil, err - } - - var buf bytes.Buffer - - for i, t := range block.Transactions { - if err := transition.Write(t); err != nil { - p.logger.Error("failed to write transaction to the block", "tx", t, "err", err) - - return nil, fmt.Errorf("failed to write transaction %s to the block: %w", t.Hash(), err) - } - - if p.logger.GetLevel() <= hclog.Debug { - if p.logger.IsTrace() { - _, _ = buf.WriteString(t.String()) - } - - if p.logger.IsDebug() { - _, _ = buf.WriteString(t.Hash().String()) - } - - if i != len(block.Transactions)-1 { - _, _ = buf.WriteString("\n") - } - } + return nil, fmt.Errorf("failed to process block: %w", err) } - p.logger.Debug("[BlockchainWrapper.ProcessBlock]", "txs count", len(block.Transactions), "txs", buf.String()) - _, root, err := transition.Commit() if err != nil { return nil, fmt.Errorf("failed to commit the state changes: %w", err) diff --git a/go.mod b/go.mod index 661a79620d..66fe332022 100644 --- a/go.mod +++ b/go.mod @@ -199,7 +199,7 @@ require ( github.com/tyler-smith/go-bip39 v1.1.0 // indirect github.com/umbracle/ethgo v0.1.4-0.20231006072852-6b068360fc97 github.com/valyala/bytebufferpool v1.0.0 // indirect - github.com/valyala/fasthttp v1.50.0 // indirect + github.com/valyala/fasthttp v1.50.0 go.opencensus.io v0.24.0 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect diff --git a/state/executor.go b/state/executor.go index 54db8f45b2..2308dec3f1 100644 --- a/state/executor.go +++ b/state/executor.go @@ -134,16 +134,22 @@ func (e *Executor) ProcessBlock( block *types.Block, blockCreator types.Address, ) (*Transition, error) { - e.logger.Debug("[BlockchainWrapper.ProcessBlock]", - "block number", block.Number(), "block hash", block.Hash(), - "parent state root", parentRoot, "block state root", block.Header.StateRoot) + e.logger.Debug("[Executor.ProcessBlock] started...", + "block number", block.Number(), + "block hash", block.Hash(), + "parent state root", parentRoot, + "block state root", block.Header.StateRoot, + "txs count", len(block.Transactions)) txn, err := e.BeginTxn(parentRoot, block.Header, blockCreator) if err != nil { return nil, err } - var buf bytes.Buffer + var ( + buf bytes.Buffer + logLvl = e.logger.GetLevel() + ) for i, t := range block.Transactions { if t.Gas() > block.Header.GasLimit { @@ -156,7 +162,7 @@ func (e *Executor) ProcessBlock( return nil, err } - if e.logger.GetLevel() <= hclog.Debug { + if logLvl <= hclog.Debug { if e.logger.IsTrace() { _, _ = buf.WriteString(t.String()) } @@ -171,8 +177,13 @@ func (e *Executor) ProcessBlock( } } - if e.logger.IsDebug() { - e.logger.Debug("[Executor.ProcessBlock]", "txs count", len(block.Transactions), "txs", buf.String()) + var ( + logMsg = "[Executor.ProcessBlock] finished." + logArgs = []interface{}{"txs count", len(block.Transactions), "txs", buf.String()} + ) + + if logLvl <= hclog.Debug { + e.logger.Log(logLvl, logMsg, logArgs...) } return txn, nil