stateroot: reject validated root if it doesn't match local one
Prevent 2021-03-27T00:05:23.382+0300 WARN blockQueue: failed adding block into the blockchain {"error": "error while trying to apply MPT changes: key not found", "blockHeight": 12757, "nextIndex": 12758} after node restart (node reads "local" root hash that it doesn't have).
This commit is contained in:
parent
d143696328
commit
216513e14f
1 changed files with 11 additions and 0 deletions
|
@ -2,12 +2,20 @@ package stateroot
|
|||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrStateMismatch means that local state root doesn't match the one
|
||||
// signed by state validators.
|
||||
ErrStateMismatch = errors.New("stateroot mismatch")
|
||||
)
|
||||
|
||||
const (
|
||||
prefixGC = 0x01
|
||||
prefixLocal = 0x02
|
||||
|
@ -60,6 +68,9 @@ func (s *Module) AddStateRoot(sr *state.MPTRoot) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !local.Root.Equals(sr.Root) {
|
||||
return fmt.Errorf("%w at block %d: %v vs %v", ErrStateMismatch, sr.Index, local.Root, sr.Root)
|
||||
}
|
||||
if len(local.Witness) != 0 {
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue