From 132d0032785a56753b40d3b13f00ba06f44a7867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Fri, 12 Apr 2024 12:18:00 +0200 Subject: [PATCH 1/9] Implement fmt.Stringer in the Header and Transaction --- types/header.go | 11 +++++++++++ types/transaction.go | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/types/header.go b/types/header.go index d3367741eb..21fddeed97 100644 --- a/types/header.go +++ b/types/header.go @@ -51,6 +51,17 @@ func (h *Header) IsGenesis() bool { return h.Hash != ZeroHash && h.Number == 0 } +func (h *Header) String() string { + return fmt.Sprintf("[Header#%d] ParentHash: %s, Hash: %s, BaseFee: %d, "+ + "Miner: %s, StateRoot: %s, TxRoot: %s, ReceiptsRoot: %s, "+ + "LogsBloom: %s, Difficulty: %d, GasLimit: %d, GasUsed: %d, "+ + "Timestamp: %d, ExtraData: %x, MixHash: %s, Nonce: %s, Sha3Uncles: %s", + h.Number, h.ParentHash, h.Hash, h.BaseFee, + BytesToAddress(h.Miner), h.StateRoot, h.TxRoot, + h.ReceiptsRoot, h.LogsBloom, h.Difficulty, h.GasLimit, + h.GasUsed, h.Timestamp, h.ExtraData, h.MixHash, h.Nonce, h.Sha3Uncles) +} + type Nonce [8]byte func (n Nonce) String() string { diff --git a/types/transaction.go b/types/transaction.go index a37e83f1be..cd0c235748 100644 --- a/types/transaction.go +++ b/types/transaction.go @@ -123,6 +123,21 @@ type TxData interface { copy() TxData } +func (tx *Transaction) String() string { + recipient := "" + if tx.To() != nil { + recipient = tx.To().String() + } + + v, r, s := tx.RawSignatureValues() + + return fmt.Sprintf("[%s] Nonce: %d, GasPrice: %d, GasTipCap: %d, GasFeeCap: %d, "+ + "Gas: %d, To: %s, Value: %d, Input: %x, V: %d, R: %d, S: %s, Hash: %s, From: %s", + tx.Type(), tx.Nonce(), tx.GasPrice(), tx.GasTipCap(), tx.GasFeeCap(), + tx.Gas(), recipient, tx.Value(), tx.Input(), + v, r, s, tx.Hash(), tx.From()) +} + func (t *Transaction) Type() TxType { return t.Inner.transactionType() } From 6152d15541dbcb17477cd116024917f6361eb268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Sun, 14 Apr 2024 08:54:21 +0200 Subject: [PATCH 2/9] Log block transactions when executing a block --- chain/params.go | 12 ++++++++++++ consensus/polybft/block_builder.go | 11 +++++++++++ consensus/polybft/blockchain_wrapper.go | 24 ++++++++++++++++++++--- consensus/polybft/polybft.go | 1 + state/executor.go | 26 ++++++++++++++++++++++--- types/header.go | 23 ++++++++++++++++++++++ 6 files changed, 91 insertions(+), 6 deletions(-) diff --git a/chain/params.go b/chain/params.go index 1847a0d1b2..63fc19a45f 100644 --- a/chain/params.go +++ b/chain/params.go @@ -2,6 +2,7 @@ package chain import ( "errors" + "fmt" "sort" "github.com/0xPolygon/polygon-edge/forkmanager" @@ -190,6 +191,17 @@ type ForksInTime struct { EIP3607 bool } +func (f ForksInTime) String() string { + return fmt.Sprintf("EIP150: %t, EIP158: %t, EIP155: %t, "+ + "Homestead: %t, Byzantium: %t, Constantinople: %t, "+ + "Petersburg: %t, Istanbul: %t, Berlin: %t, London: %t"+ + "Governance: %t, EIP3855: %t, EIP3607: %t", + f.EIP150, f.EIP158, f.EIP155, + f.Homestead, f.Byzantium, f.Constantinople, f.Petersburg, + f.Istanbul, f.Berlin, f.London, + f.Governance, f.EIP3855, f.EIP3607) +} + // AllForksEnabled should contain all supported forks by current edge version var AllForksEnabled = &Forks{ Homestead: NewFork(0), diff --git a/consensus/polybft/block_builder.go b/consensus/polybft/block_builder.go index 1849faa1db..d98efb0da4 100644 --- a/consensus/polybft/block_builder.go +++ b/consensus/polybft/block_builder.go @@ -1,6 +1,7 @@ package polybft import ( + "bytes" "fmt" "time" @@ -157,6 +158,8 @@ func (b *BlockBuilder) WriteTx(tx *types.Transaction) error { // Fill fills the block with transactions from the txpool func (b *BlockBuilder) Fill() { + var buf bytes.Buffer + blockTimer := time.NewTimer(b.params.BlockTime) b.params.TxPool.Prepare() @@ -168,6 +171,10 @@ write: default: tx := b.params.TxPool.Peek() + if b.params.Logger.IsDebug() && tx != nil { + _, _ = buf.WriteString(tx.String()) + } + // execute transactions one by one finished, err := b.writeTxPoolTransaction(tx) if err != nil { @@ -180,6 +187,10 @@ write: } } + if b.params.Logger.IsDebug() { + b.params.Logger.Debug("[BlockBuilder.Fill]", "block number", b.header.Number, "block txs", buf.String()) + } + // wait for the timer to expire <-blockTimer.C } diff --git a/consensus/polybft/blockchain_wrapper.go b/consensus/polybft/blockchain_wrapper.go index dd23b9b437..552b83293a 100644 --- a/consensus/polybft/blockchain_wrapper.go +++ b/consensus/polybft/blockchain_wrapper.go @@ -1,6 +1,7 @@ package polybft import ( + "bytes" "errors" "fmt" "math/big" @@ -71,6 +72,7 @@ type blockchainBackend interface { var _ blockchainBackend = &blockchainWrapper{} type blockchainWrapper struct { + logger hclog.Logger executor *state.Executor blockchain *blockchain.Blockchain } @@ -87,6 +89,10 @@ 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() @@ -95,11 +101,23 @@ func (p *blockchainWrapper) ProcessBlock(parent *types.Header, block *types.Bloc return nil, err } + var buf bytes.Buffer + // apply transactions from block - for _, tx := range block.Transactions { - if err = transition.Write(tx); err != nil { - return nil, fmt.Errorf("process block tx error, tx = %v, err = %w", tx.Hash(), err) + err = block.TxnIterator(func(t *types.Transaction) *types.IterationResult { + if err := transition.Write(t); err != nil { + return &types.IterationResult{Err: fmt.Errorf("process block tx error, tx = %s, err = %w", t.Hash(), err)} } + + if p.logger.IsDebug() { + _, _ = buf.WriteString(t.String()) + } + + return &types.IterationResult{} + }) + + if err != nil { + return nil, err } _, root, err := transition.Commit() diff --git a/consensus/polybft/polybft.go b/consensus/polybft/polybft.go index f1d8561569..3de2f1404d 100644 --- a/consensus/polybft/polybft.go +++ b/consensus/polybft/polybft.go @@ -462,6 +462,7 @@ func (p *Polybft) Initialize() error { // set blockchain backend p.blockchain = &blockchainWrapper{ + logger: p.logger.Named("blockchain_wrapper"), blockchain: p.config.Blockchain, executor: p.config.Executor, } diff --git a/state/executor.go b/state/executor.go index 5274549368..af80fb589f 100644 --- a/state/executor.go +++ b/state/executor.go @@ -1,6 +1,7 @@ package state import ( + "bytes" "errors" "fmt" "math" @@ -138,14 +139,32 @@ func (e *Executor) ProcessBlock( return nil, err } - for _, t := range block.Transactions { + var buf bytes.Buffer + + err = block.TxnIterator(func(t *types.Transaction) *types.IterationResult { if t.Gas() > block.Header.GasLimit { - continue + return &types.IterationResult{ShouldContinue: true} } if err = txn.Write(t); err != nil { - return nil, err + return &types.IterationResult{Err: err} + } + + if e.logger.IsDebug() { + _, _ = buf.WriteString(t.String()) } + + return &types.IterationResult{} + }) + + if err != nil { + return nil, err + } + + if e.logger.IsDebug() { + e.logger.Debug("[Executor.ProcessBlock]", + "block number", block.Number(), + "txs", buf.String()) } return txn, nil @@ -337,6 +356,7 @@ func (t *Transition) Write(txn *types.Transaction) error { } txn.SetFrom(from) + t.logger.Debug("[Transition.Write]", "recovered sender", from) } // Make a local copy and apply the transaction diff --git a/types/header.go b/types/header.go index 21fddeed97..7d0358eaaa 100644 --- a/types/header.go +++ b/types/header.go @@ -158,6 +158,29 @@ func (b *Block) String() string { return str } +type IterationResult struct { + ShouldContinue bool + ShouldBreak bool + Err error +} + +// TxnIterator represents an iterator for block transactions +func (b *Block) TxnIterator(handler func(*Transaction) *IterationResult) error { + for _, tx := range b.Transactions { + result := handler(tx) + + if result == nil || result.ShouldContinue { + continue + } + + if result.ShouldBreak || result.Err != nil { + return result.Err + } + } + + return nil +} + // WithSeal returns a new block with the data from b but the header replaced with // the sealed one. func (b *Block) WithSeal(header *Header) *Block { From bb7f3ff475cb90ccae907c401357c0ed5ff694b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Tue, 16 Apr 2024 08:09:53 +0200 Subject: [PATCH 3/9] Log genesis configuration on debug level --- server/server.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/server/server.go b/server/server.go index a02e81d549..756b90939e 100644 --- a/server/server.go +++ b/server/server.go @@ -147,13 +147,22 @@ func NewServer(config *Config) (*Server, error) { restoreProgression: progress.NewProgressionWrapper(progress.ChainSyncRestore), } - m.logger.Info("Data dir", "path", config.DataDir) - m.logger.Info("Version metadata", + m.logger.Info("data dir", "path", config.DataDir) + m.logger.Info("version metadata", "version", versioning.Version, "commit", versioning.Commit, "branch", versioning.Branch, "build time", versioning.BuildTime) + if m.logger.IsDebug() { + chainConfigJSON, err := json.MarshalIndent(config.Chain, "", "\t") + if err != nil { + return nil, fmt.Errorf("failed to marshal chain config to JSON: %w", err) + } + + m.logger.Debug(fmt.Sprintf("chain configuration %s", string(chainConfigJSON))) + } + var dirPaths = []string{ "blockchain", "trie", From e250e5c21667e9ea700d29f80dfe945be84b0132 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Tue, 16 Apr 2024 12:12:11 +0200 Subject: [PATCH 4/9] Changes in the FSM logs --- consensus/polybft/blockchain_wrapper.go | 31 ++++++++++++++------ consensus/polybft/fsm.go | 38 ++++++++++++++++++------- server/server.go | 2 +- state/executor.go | 24 ++++++++++++---- types/header.go | 6 ++-- 5 files changed, 71 insertions(+), 30 deletions(-) diff --git a/consensus/polybft/blockchain_wrapper.go b/consensus/polybft/blockchain_wrapper.go index 552b83293a..9c01531dcd 100644 --- a/consensus/polybft/blockchain_wrapper.go +++ b/consensus/polybft/blockchain_wrapper.go @@ -104,22 +104,35 @@ func (p *blockchainWrapper) ProcessBlock(parent *types.Header, block *types.Bloc var buf bytes.Buffer // apply transactions from block - err = block.TxnIterator(func(t *types.Transaction) *types.IterationResult { - if err := transition.Write(t); err != nil { - return &types.IterationResult{Err: fmt.Errorf("process block tx error, tx = %s, err = %w", t.Hash(), err)} - } + err = block.TxnIterator( + func(i int, t *types.Transaction) *types.IterationResult { + if err := transition.Write(t); err != nil { + return &types.IterationResult{Err: fmt.Errorf("process block tx error, tx = %s, err = %w", t.Hash(), err)} + } - if p.logger.IsDebug() { - _, _ = buf.WriteString(t.String()) - } + if p.logger.GetLevel() <= hclog.Debug { + if p.logger.IsTrace() { + _, _ = buf.WriteString(t.String()) + } - return &types.IterationResult{} - }) + if p.logger.IsDebug() { + _, _ = buf.WriteString(t.Hash().String()) + } + + if i != len(block.Transactions)-1 { + _, _ = buf.WriteString("\n") + } + } + + return &types.IterationResult{} + }) if err != nil { return nil, 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/consensus/polybft/fsm.go b/consensus/polybft/fsm.go index 262882d2f7..1d429acd6d 100644 --- a/consensus/polybft/fsm.go +++ b/consensus/polybft/fsm.go @@ -10,7 +10,7 @@ import ( "github.com/0xPolygon/go-ibft/messages" "github.com/0xPolygon/go-ibft/messages/proto" "github.com/armon/go-metrics" - hcf "github.com/hashicorp/go-hclog" + "github.com/hashicorp/go-hclog" "github.com/0xPolygon/polygon-edge/bls" "github.com/0xPolygon/polygon-edge/chain" @@ -101,7 +101,7 @@ type fsm struct { proposerCommitmentToRegister *CommitmentMessageSigned // logger instance - logger hcf.Logger + logger hclog.Logger // target is the block being computed target *types.FullBlock @@ -192,7 +192,7 @@ func (f *fsm) BuildProposal(currentRound uint64) ([]byte, error) { EventRoot: f.exitEventRootHash, } - f.logger.Debug("[Build Proposal]", "Current validators hash", currentValidatorsHash, + f.logger.Trace("[FSM.BuildProposal]", "Current validators hash", currentValidatorsHash, "Next validators hash", nextValidatorsHash) stateBlock, err := f.blockBuilder.Build(func(h *types.Header) { @@ -204,17 +204,33 @@ func (f *fsm) BuildProposal(currentRound uint64) ([]byte, error) { return nil, err } - if f.logger.IsDebug() { + if f.logger.GetLevel() <= hclog.Debug { checkpointHash, err := extra.Checkpoint.Hash(f.backend.GetChainID(), f.Height(), stateBlock.Block.Hash()) if err != nil { return nil, fmt.Errorf("failed to calculate proposal hash: %w", err) } - f.logger.Debug("[FSM Build Proposal]", - "block", stateBlock.Block.Number(), + var buf bytes.Buffer + + for i, tx := range stateBlock.Block.Transactions { + if f.logger.IsDebug() { + buf.WriteString(tx.Hash().String()) + } else if f.logger.IsTrace() { + buf.WriteString(tx.String()) + } + + if i != len(stateBlock.Block.Transactions) { + buf.WriteString("\n") + } + } + + f.logger.Debug("[FSM.BuildProposal]", + "block num", stateBlock.Block.Number(), "round", currentRound, - "txs", len(stateBlock.Block.Transactions), - "proposal hash", checkpointHash.String()) + "state root", stateBlock.Block.Header.StateRoot, + "proposal hash", checkpointHash.String(), + "txs count", len(stateBlock.Block.Transactions), + "txs", buf.String()) } f.target = stateBlock @@ -380,7 +396,7 @@ func (f *fsm) Validate(proposal []byte) error { return fmt.Errorf("failed to retrieve validators:%w", err) } - f.logger.Trace("[FSM Validate]", "Block", block.Number(), "parent validators", validators) + f.logger.Trace("[FSM.Validate]", "block num", block.Number(), "parent validators", validators) } stateBlock, err := f.backend.ProcessBlock(f.parent, &block) @@ -394,10 +410,10 @@ func (f *fsm) Validate(proposal []byte) error { return fmt.Errorf("failed to calculate proposal hash: %w", err) } - f.logger.Debug("[FSM Validate] Finish", + f.logger.Debug("[FSM.Validate]", "block num", block.Number(), + "state root", block.Header.StateRoot, "proposer", types.BytesToHash(block.Header.Miner), - "txs", len(block.Transactions), "proposal hash", checkpointHash) } diff --git a/server/server.go b/server/server.go index 756b90939e..e908cdd224 100644 --- a/server/server.go +++ b/server/server.go @@ -218,7 +218,7 @@ func NewServer(config *Config) (*Server, error) { st := itrie.NewState(stateStorage) m.state = st - m.executor = state.NewExecutor(config.Chain.Params, st, logger) + m.executor = state.NewExecutor(config.Chain.Params, st, logger.Named("executor")) // custom write genesis hook per consensus engine engineName := m.config.Chain.Params.GetEngine() diff --git a/state/executor.go b/state/executor.go index af80fb589f..7547ef28e2 100644 --- a/state/executor.go +++ b/state/executor.go @@ -134,6 +134,10 @@ 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) + txn, err := e.BeginTxn(parentRoot, block.Header, blockCreator) if err != nil { return nil, err @@ -141,7 +145,7 @@ func (e *Executor) ProcessBlock( var buf bytes.Buffer - err = block.TxnIterator(func(t *types.Transaction) *types.IterationResult { + err = block.TxnIterator(func(i int, t *types.Transaction) *types.IterationResult { if t.Gas() > block.Header.GasLimit { return &types.IterationResult{ShouldContinue: true} } @@ -150,8 +154,18 @@ func (e *Executor) ProcessBlock( return &types.IterationResult{Err: err} } - if e.logger.IsDebug() { - _, _ = buf.WriteString(t.String()) + if e.logger.GetLevel() <= hclog.Debug { + if e.logger.IsTrace() { + _, _ = buf.WriteString(t.String()) + } + + if e.logger.IsDebug() { + _, _ = buf.WriteString(t.Hash().String()) + } + + if i != len(block.Transactions)-1 { + _, _ = buf.WriteString("\n") + } } return &types.IterationResult{} @@ -162,9 +176,7 @@ func (e *Executor) ProcessBlock( } if e.logger.IsDebug() { - e.logger.Debug("[Executor.ProcessBlock]", - "block number", block.Number(), - "txs", buf.String()) + e.logger.Debug("[Executor.ProcessBlock]", "txs count", len(block.Transactions), "txs", buf.String()) } return txn, nil diff --git a/types/header.go b/types/header.go index 7d0358eaaa..9192df6c83 100644 --- a/types/header.go +++ b/types/header.go @@ -165,9 +165,9 @@ type IterationResult struct { } // TxnIterator represents an iterator for block transactions -func (b *Block) TxnIterator(handler func(*Transaction) *IterationResult) error { - for _, tx := range b.Transactions { - result := handler(tx) +func (b *Block) TxnIterator(handler func(int, *Transaction) *IterationResult) error { + for i, tx := range b.Transactions { + result := handler(i, tx) if result == nil || result.ShouldContinue { continue From 79c0e49d286636fca7bec125db980ace70d842f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Tue, 16 Apr 2024 13:59:02 +0200 Subject: [PATCH 5/9] Address comments --- consensus/polybft/blockchain_wrapper.go | 36 +++++++++++-------------- state/executor.go | 14 ++++------ types/access_list_tx.go | 18 +++++++++++++ types/header.go | 23 ---------------- types/transaction.go | 11 +++----- 5 files changed, 41 insertions(+), 61 deletions(-) diff --git a/consensus/polybft/blockchain_wrapper.go b/consensus/polybft/blockchain_wrapper.go index 9c01531dcd..4cac1b626a 100644 --- a/consensus/polybft/blockchain_wrapper.go +++ b/consensus/polybft/blockchain_wrapper.go @@ -103,32 +103,26 @@ func (p *blockchainWrapper) ProcessBlock(parent *types.Header, block *types.Bloc var buf bytes.Buffer - // apply transactions from block - err = block.TxnIterator( - func(i int, t *types.Transaction) *types.IterationResult { - if err := transition.Write(t); err != nil { - return &types.IterationResult{Err: fmt.Errorf("process block tx error, tx = %s, err = %w", t.Hash(), err)} - } - - if p.logger.GetLevel() <= hclog.Debug { - if p.logger.IsTrace() { - _, _ = buf.WriteString(t.String()) - } + 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) - if p.logger.IsDebug() { - _, _ = buf.WriteString(t.Hash().String()) - } + return nil, fmt.Errorf("failed to write transaction %s to the block: %w", t.Hash(), err) + } - if i != len(block.Transactions)-1 { - _, _ = buf.WriteString("\n") - } + if p.logger.GetLevel() <= hclog.Debug { + if p.logger.IsTrace() { + _, _ = buf.WriteString(t.String()) } - return &types.IterationResult{} - }) + if p.logger.IsDebug() { + _, _ = buf.WriteString(t.Hash().String()) + } - if err != nil { - return nil, err + if i != len(block.Transactions)-1 { + _, _ = buf.WriteString("\n") + } + } } p.logger.Debug("[BlockchainWrapper.ProcessBlock]", "txs count", len(block.Transactions), "txs", buf.String()) diff --git a/state/executor.go b/state/executor.go index 7547ef28e2..54db8f45b2 100644 --- a/state/executor.go +++ b/state/executor.go @@ -145,13 +145,15 @@ func (e *Executor) ProcessBlock( var buf bytes.Buffer - err = block.TxnIterator(func(i int, t *types.Transaction) *types.IterationResult { + for i, t := range block.Transactions { if t.Gas() > block.Header.GasLimit { - return &types.IterationResult{ShouldContinue: true} + continue } if err = txn.Write(t); err != nil { - return &types.IterationResult{Err: err} + e.logger.Error("failed to write transaction to the block", "tx", t, "err", err) + + return nil, err } if e.logger.GetLevel() <= hclog.Debug { @@ -167,12 +169,6 @@ func (e *Executor) ProcessBlock( _, _ = buf.WriteString("\n") } } - - return &types.IterationResult{} - }) - - if err != nil { - return nil, err } if e.logger.IsDebug() { diff --git a/types/access_list_tx.go b/types/access_list_tx.go index 257001cde7..8f045f7160 100644 --- a/types/access_list_tx.go +++ b/types/access_list_tx.go @@ -1,6 +1,7 @@ package types import ( + "bytes" "fmt" "math/big" @@ -165,6 +166,23 @@ func (t *TxAccessList) unmarshalJSON(v *fastjson.Value) error { return nil } +func (t *TxAccessList) String() string { + var buf bytes.Buffer + + for _, accessEntry := range *t { + buf.WriteString(fmt.Sprintf("address=%s", accessEntry.Address)) + for i, storageKey := range accessEntry.StorageKeys { + if i == 0 { + buf.WriteString("\n") + } + + buf.WriteString(fmt.Sprintf("\tkey=%s", storageKey)) + } + } + + return buf.String() +} + type AccessListTxn struct { *BaseTx GasPrice *big.Int diff --git a/types/header.go b/types/header.go index 9192df6c83..21fddeed97 100644 --- a/types/header.go +++ b/types/header.go @@ -158,29 +158,6 @@ func (b *Block) String() string { return str } -type IterationResult struct { - ShouldContinue bool - ShouldBreak bool - Err error -} - -// TxnIterator represents an iterator for block transactions -func (b *Block) TxnIterator(handler func(int, *Transaction) *IterationResult) error { - for i, tx := range b.Transactions { - result := handler(i, tx) - - if result == nil || result.ShouldContinue { - continue - } - - if result.ShouldBreak || result.Err != nil { - return result.Err - } - } - - return nil -} - // WithSeal returns a new block with the data from b but the header replaced with // the sealed one. func (b *Block) WithSeal(header *Header) *Block { diff --git a/types/transaction.go b/types/transaction.go index cd0c235748..332780d128 100644 --- a/types/transaction.go +++ b/types/transaction.go @@ -124,18 +124,13 @@ type TxData interface { } func (tx *Transaction) String() string { - recipient := "" - if tx.To() != nil { - recipient = tx.To().String() - } - v, r, s := tx.RawSignatureValues() return fmt.Sprintf("[%s] Nonce: %d, GasPrice: %d, GasTipCap: %d, GasFeeCap: %d, "+ - "Gas: %d, To: %s, Value: %d, Input: %x, V: %d, R: %d, S: %s, Hash: %s, From: %s", + "Gas: %d, To: %s, Value: %d, Input: %x, V: %d, R: %d, S: %s, Hash: %s, From: %s, AccessList: %s", tx.Type(), tx.Nonce(), tx.GasPrice(), tx.GasTipCap(), tx.GasFeeCap(), - tx.Gas(), recipient, tx.Value(), tx.Input(), - v, r, s, tx.Hash(), tx.From()) + tx.Gas(), tx.To(), tx.Value(), tx.Input(), + v, r, s, tx.Hash(), tx.From(), tx.AccessList()) } func (t *Transaction) Type() TxType { From 101a81af0054507463c12fdf7bd81812953e1b3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Tue, 16 Apr 2024 13:59:20 +0200 Subject: [PATCH 6/9] Remove unused param from test --- blockchain/blockchain_test.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/blockchain/blockchain_test.go b/blockchain/blockchain_test.go index 7f4cabdd9b..e80a6838fc 100644 --- a/blockchain/blockchain_test.go +++ b/blockchain/blockchain_test.go @@ -569,7 +569,6 @@ func TestBlockchainWriteBody(t *testing.T) { newChain := func( t *testing.T, txFromByTxHash map[types.Hash]types.Address, - path string, ) *Blockchain { t.Helper() @@ -604,7 +603,7 @@ func TestBlockchainWriteBody(t *testing.T) { txFromByTxHash := map[types.Hash]types.Address{} - chain := newChain(t, txFromByTxHash, "t1") + chain := newChain(t, txFromByTxHash) defer chain.db.Close() batchWriter := chain.db.NewWriter() @@ -633,7 +632,7 @@ func TestBlockchainWriteBody(t *testing.T) { txFromByTxHash := map[types.Hash]types.Address{} - chain := newChain(t, txFromByTxHash, "t2") + chain := newChain(t, txFromByTxHash) defer chain.db.Close() batchWriter := chain.db.NewWriter() @@ -665,7 +664,7 @@ func TestBlockchainWriteBody(t *testing.T) { tx.Hash(): addr, } - chain := newChain(t, txFromByTxHash, "t3") + chain := newChain(t, txFromByTxHash) defer chain.db.Close() batchWriter := chain.db.NewWriter() From 683a8134364146ebb4b620696bec08ed1e0aea2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Wed, 17 Apr 2024 08:30:38 +0200 Subject: [PATCH 7/9] Lint fix --- types/access_list_tx.go | 1 + 1 file changed, 1 insertion(+) diff --git a/types/access_list_tx.go b/types/access_list_tx.go index 8f045f7160..cc0174f3d1 100644 --- a/types/access_list_tx.go +++ b/types/access_list_tx.go @@ -171,6 +171,7 @@ func (t *TxAccessList) String() string { for _, accessEntry := range *t { buf.WriteString(fmt.Sprintf("address=%s", accessEntry.Address)) + for i, storageKey := range accessEntry.StorageKeys { if i == 0 { buf.WriteString("\n") From ec811e1f1bf3f03e3f5cd740f6ba29439ddcbb95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Wed, 17 Apr 2024 09:33:17 +0200 Subject: [PATCH 8/9] Minor change --- types/access_list_tx.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/access_list_tx.go b/types/access_list_tx.go index cc0174f3d1..55080431e1 100644 --- a/types/access_list_tx.go +++ b/types/access_list_tx.go @@ -170,14 +170,14 @@ func (t *TxAccessList) String() string { var buf bytes.Buffer for _, accessEntry := range *t { - buf.WriteString(fmt.Sprintf("address=%s", accessEntry.Address)) + _, _ = buf.WriteString(fmt.Sprintf("address=%s", accessEntry.Address)) for i, storageKey := range accessEntry.StorageKeys { if i == 0 { - buf.WriteString("\n") + _, _ = buf.WriteString("\n") } - buf.WriteString(fmt.Sprintf("\tkey=%s", storageKey)) + _, _ = buf.WriteString(fmt.Sprintf("\tstorage key=%s", storageKey)) } } From 8384281a104e7d53121aeb39a7869a18afc0ba07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Wed, 17 Apr 2024 14:15:28 +0200 Subject: [PATCH 9/9] Address comment --- consensus/polybft/fsm.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consensus/polybft/fsm.go b/consensus/polybft/fsm.go index 1d429acd6d..fa9075b6c8 100644 --- a/consensus/polybft/fsm.go +++ b/consensus/polybft/fsm.go @@ -219,7 +219,7 @@ func (f *fsm) BuildProposal(currentRound uint64) ([]byte, error) { buf.WriteString(tx.String()) } - if i != len(stateBlock.Block.Transactions) { + if i != len(stateBlock.Block.Transactions)-1 { buf.WriteString("\n") } }