diff --git a/consensus/beacon/consensus.go b/consensus/beacon/consensus.go index e9252ecab4..1281b26650 100644 --- a/consensus/beacon/consensus.go +++ b/consensus/beacon/consensus.go @@ -336,6 +336,9 @@ func (beacon *Beacon) Finalize(chain consensus.ChainHeaderReader, header *types. } // Withdrawals processing. for _, w := range body.Withdrawals { + // always read the target account regardless of withdrawal amt to include it in the BAL + state.GetBalance(w.Address) + // Convert amount from gwei to wei. amount := new(uint256.Int).SetUint64(w.Amount) amount = amount.Mul(amount, uint256.NewInt(params.GWei)) @@ -361,6 +364,7 @@ func (beacon *Beacon) FinalizeAndAssemble(chain consensus.ChainHeaderReader, hea return nil, errors.New("withdrawals set before Shanghai activation") } } + // Finalize and assemble the block. beacon.Finalize(chain, header, state, body) diff --git a/core/blockchain.go b/core/blockchain.go index b80bc3ef0e..f09cdeaf22 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -100,21 +100,6 @@ var ( blockExecutionTimer = metrics.NewRegisteredResettingTimer("chain/execution", nil) blockWriteTimer = metrics.NewRegisteredResettingTimer("chain/write", nil) - // BAL-specific timers - blockPreprocessingTimer = metrics.NewRegisteredResettingTimer("chain/preprocess", nil) - txExecutionTimer = metrics.NewRegisteredResettingTimer("chain/txexecution", nil) - - stateTrieHashTimer = metrics.NewRegisteredResettingTimer("chain/statetriehash", nil) - accountTriesUpdateTimer = metrics.NewRegisteredResettingTimer("chain/accounttriesupdate", nil) - stateTriePrefetchTimer = metrics.NewRegisteredResettingTimer("chain/statetrieprefetch", nil) - stateTrieUpdateTimer = metrics.NewRegisteredResettingTimer("chain/statetrieupdate", nil) - originStorageLoadTimer = metrics.NewRegisteredResettingTimer("chain/originstorageload", nil) - - stateRootComputeTimer = metrics.NewRegisteredResettingTimer("chain/staterootcompute", nil) - stateCommitTimer = metrics.NewRegisteredResettingTimer("chain/statetriecommit", nil) - - blockPostprocessingTimer = metrics.NewRegisteredResettingTimer("chain/postprocess", nil) - blockReorgMeter = metrics.NewRegisteredMeter("chain/reorg/executes", nil) blockReorgAddMeter = metrics.NewRegisteredMeter("chain/reorg/add", nil) blockReorgDropMeter = metrics.NewRegisteredMeter("chain/reorg/drop", nil) @@ -2217,9 +2202,11 @@ func (bc *BlockChain) ProcessBlock(parentRoot common.Hash, block *types.Block, s vtime = time.Since(vstart) if enableBALFork { - computedAccessListHash := balTracer.AccessList().ToEncodingObj().Hash() + computedAccessList := balTracer.AccessList().ToEncodingObj() + computedAccessListHash := computedAccessList.Hash() if *block.Header().BlockAccessListHash != computedAccessListHash { + //fmt.Printf("remote:\n%s\nlocal:\n%s\n", block.Body().AccessList.JSONString(), computedAccessList.JSONString()) err := fmt.Errorf("block header access list hash mismatch with computed (header=%x computed=%x)", *block.Header().BlockAccessListHash, computedAccessListHash) bc.reportBadBlock(block, res, err) return nil, err diff --git a/core/state_transition.go b/core/state_transition.go index 622d66806d..934ff4fbf1 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -556,6 +556,10 @@ func (st *stateTransition) execute() (*ExecutionResult, error) { } else { fee := new(uint256.Int).SetUint64(st.gasUsed()) fee.Mul(fee, effectiveTipU256) + + // always read the coinbase account to include it in the BAL (TODO check this is actually part of the spec) + st.state.GetBalance(st.evm.Context.Coinbase) + st.state.AddBalance(st.evm.Context.Coinbase, fee, tracing.BalanceIncreaseRewardTransactionFee) // add the coinbase to the witness iff the fee is greater than 0 diff --git a/core/types/bal/bal_encoding.go b/core/types/bal/bal_encoding.go index fc23c12519..f6c5951015 100644 --- a/core/types/bal/bal_encoding.go +++ b/core/types/bal/bal_encoding.go @@ -69,6 +69,11 @@ func (e *BlockAccessList) DecodeRLP(dec *rlp.Stream) error { return nil } +func (e *BlockAccessList) JSONString() string { + res, _ := json.MarshalIndent(e.StringableRepresentation(), "", " ") + return string(res) +} + // StringableRepresentation returns an instance of the block access list // which can be converted to a human-readable JSON representation. func (e *BlockAccessList) StringableRepresentation() interface{} {