From ddd3ef2ac4ad20ac77a266b4a65104e42e42b94f Mon Sep 17 00:00:00 2001 From: joeylichang Date: Mon, 15 Apr 2024 16:50:07 +0800 Subject: [PATCH] test: change set expected root --- core/blockchain.go | 1 + core/state/statedb.go | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index b0fcc71ee0..705205f430 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1448,6 +1448,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. // Make sure no inconsistent state is leaked during insertion externTd := new(big.Int).Add(block.Difficulty(), ptd) + state.SetExpectedStateRoot(block.Root()) // Irrelevant of the canonical status, write the block itself to the database. // // Note all the components of block(td, hash->number map, header, body, receipts) diff --git a/core/state/statedb.go b/core/state/statedb.go index 59238d822b..f98df2da19 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -1233,19 +1233,19 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er nodes = trienode.NewMergedNodeSet() incomplete map[common.Address]struct{} ) - if s.stateRoot = s.StateIntermediateRoot(); s.expectedRoot != s.stateRoot { - s.expectedRoot = s.stateRoot - //log.Error("Invalid merkle root", "remote", s.expectedRoot, "local", s.stateRoot) - //return fmt.Errorf("invalid merkle root (remote: %x local: %x)", s.expectedRoot, s.stateRoot) - } + //if s.stateRoot = s.StateIntermediateRoot(); s.expectedRoot != s.stateRoot { + // s.expectedRoot = s.stateRoot + // //log.Error("Invalid merkle root", "remote", s.expectedRoot, "local", s.stateRoot) + // //return fmt.Errorf("invalid merkle root (remote: %x local: %x)", s.expectedRoot, s.stateRoot) + //} commmitTrie := func() error { if metrics.EnabledExpensive { defer func(start time.Time) { s.TrieAllCommits += time.Since(start) }(time.Now()) } - //if s.stateRoot = s.StateIntermediateRoot(); s.expectedRoot != s.stateRoot { - // log.Error("Invalid merkle root", "remote", s.expectedRoot, "local", s.stateRoot) - // return fmt.Errorf("invalid merkle root (remote: %x local: %x)", s.expectedRoot, s.stateRoot) - //} + if s.stateRoot = s.StateIntermediateRoot(); s.expectedRoot != s.stateRoot { + log.Error("Invalid merkle root", "remote", s.expectedRoot, "local", s.stateRoot) + return fmt.Errorf("invalid merkle root (remote: %x local: %x)", s.expectedRoot, s.stateRoot) + } var err error // Handle all state deletions first