core: move stateroot check into header check

As it's a part of the header.
This commit is contained in:
Roman Khimov 2021-03-26 22:55:08 +03:00
parent 1fdd406234
commit 56fd375c6d

View file

@ -501,12 +501,6 @@ func (bc *Blockchain) AddBlock(block *block.Block) error {
return fmt.Errorf("%w: %v != %v", return fmt.Errorf("%w: %v != %v",
ErrHdrStateRootSetting, bc.config.StateRootInHeader, block.StateRootEnabled) 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 { if block.Index == bc.HeaderHeight()+1 {
err := bc.addHeaders(bc.config.VerifyBlocks, &block.Header) err := bc.addHeaders(bc.config.VerifyBlocks, &block.Header)
@ -1391,6 +1385,12 @@ var (
) )
func (bc *Blockchain) verifyHeader(currHeader, prevHeader *block.Header) error { 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 { if prevHeader.Hash() != currHeader.PrevHash {
return ErrHdrHashMismatch return ErrHdrHashMismatch
} }