From 56fd375c6d367864c411941c8988423de75b84f7 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 26 Mar 2021 22:55:08 +0300 Subject: [PATCH] core: move stateroot check into header check As it's a part of the header. --- pkg/core/blockchain.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index face98d17..e8ae39980 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -501,12 +501,6 @@ func (bc *Blockchain) AddBlock(block *block.Block) error { return fmt.Errorf("%w: %v != %v", ErrHdrStateRootSetting, bc.config.StateRootInHeader, block.StateRootEnabled) } - if bc.config.StateRootInHeader { - if sr := bc.stateRoot.CurrentLocalStateRoot(); block.PrevStateRoot != sr { - return fmt.Errorf("%w: %s != %s", - ErrHdrInvalidStateRoot, block.PrevStateRoot.StringLE(), sr.StringLE()) - } - } if block.Index == bc.HeaderHeight()+1 { err := bc.addHeaders(bc.config.VerifyBlocks, &block.Header) @@ -1391,6 +1385,12 @@ var ( ) func (bc *Blockchain) verifyHeader(currHeader, prevHeader *block.Header) error { + if bc.config.StateRootInHeader { + if sr := bc.stateRoot.CurrentLocalStateRoot(); currHeader.PrevStateRoot != sr { + return fmt.Errorf("%w: %s != %s", + ErrHdrInvalidStateRoot, currHeader.PrevStateRoot.StringLE(), sr.StringLE()) + } + } if prevHeader.Hash() != currHeader.PrevHash { return ErrHdrHashMismatch }