core: fix PrevHash calculation for MPTRoot

This was differing from C# notion of PrevHash. It's not a previous root, but
rather a hash of the previous serialized MPTRoot structure (that is to be
signed by CNs).
This commit is contained in:
Roman Khimov 2020-06-04 17:19:30 +03:00
parent 685d3eb870
commit 69ccca675d

View file

@ -835,7 +835,7 @@ func (bc *Blockchain) storeBlock(block *block.Block) error {
if err != nil { if err != nil {
return errors.WithMessagef(err, "can't get previous state root") return errors.WithMessagef(err, "can't get previous state root")
} }
prevHash = prev.Root prevHash = hash.DoubleSha256(prev.GetSignedPart())
} }
err := bc.AddStateRoot(&state.MPTRoot{ err := bc.AddStateRoot(&state.MPTRoot{
MPTRootBase: state.MPTRootBase{ MPTRootBase: state.MPTRootBase{
@ -1803,7 +1803,7 @@ func (bc *Blockchain) verifyStateRoot(r *state.MPTRoot) error {
prev, err := bc.GetStateRoot(r.Index - 1) prev, err := bc.GetStateRoot(r.Index - 1)
if err != nil { if err != nil {
return errors.New("can't get previous state root") return errors.New("can't get previous state root")
} else if !prev.Root.Equals(r.PrevHash) { } else if !r.PrevHash.Equals(hash.DoubleSha256(prev.GetSignedPart())) {
return errors.New("previous hash mismatch") return errors.New("previous hash mismatch")
} else if prev.Version != r.Version { } else if prev.Version != r.Version {
return errors.New("version mismatch") return errors.New("version mismatch")