Merge pull request #1869 from nspcc-dev/testnet-storage-fixes

core: RC1 states dumps compatibility fixes
This commit is contained in:
Roman Khimov 2021-03-29 17:28:51 +03:00 committed by GitHub
commit 1bd3ee299c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 3 deletions

View file

@ -726,6 +726,28 @@ func (n *NEO) VoteInternal(ic *interop.Context, h util.Uint160, pub *keys.Public
if err != nil {
return err
}
// we should put it in storage anyway as it affects dumps
err = ic.DAO.PutStorageItem(n.ID, key, si)
if err != nil {
return err
}
if pub != nil {
valKey := makeValidatorKey(pub)
valSi := ic.DAO.GetStorageItem(n.ID, valKey)
if valSi == nil {
return errors.New("unknown validator")
}
cd := new(candidate).FromBytes(valSi)
// we should put it in storage anyway as it affects dumps
err = ic.DAO.PutStorageItem(n.ID, valKey, valSi)
if err != nil {
return err
}
if !cd.Registered {
return errors.New("validator must be registered")
}
}
if (acc.VoteTo == nil) != (pub == nil) {
val := &acc.Balance
if pub == nil {
@ -765,8 +787,6 @@ func (n *NEO) ModifyAccountVotes(acc *state.NEOBalanceState, d dao.DAO, value *b
if ok {
return err
}
} else if !cd.Registered {
return errors.New("validator must be registered")
}
n.validators.Store(keys.PublicKeys(nil))
return d.PutStorageItem(n.ID, key, cd.Bytes())

View file

@ -15,7 +15,7 @@ import (
"github.com/urfave/cli"
)
var ledgerContractID = -2
var ledgerContractID = -4
type dump []blockDump

View file

@ -0,0 +1,13 @@
package main
import (
"testing"
"github.com/nspcc-dev/neo-go/pkg/core/native"
"github.com/stretchr/testify/require"
)
func TestCompatibility(t *testing.T) {
cs := native.NewContracts(false, map[string][]uint32{})
require.Equal(t, cs.Ledger.ID, int32(ledgerContractID))
}