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 {