mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 19:42:23 +00:00
native: don't register standby validators on initialization
C# doesn't do that since neo-project/neo#1762.
This commit is contained in:
parent
6e252fbaae
commit
fb97ea9458
4 changed files with 9 additions and 25 deletions
|
@ -8,7 +8,6 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
)
|
)
|
||||||
|
@ -73,7 +72,7 @@ func (g *GAS) Initialize(ic *interop.Context) error {
|
||||||
if g.nep5TokenNative.getTotalSupply(ic.DAO).Sign() != 0 {
|
if g.nep5TokenNative.getTotalSupply(ic.DAO).Sign() != 0 {
|
||||||
return errors.New("already initialized")
|
return errors.New("already initialized")
|
||||||
}
|
}
|
||||||
h, _, err := getStandbyValidatorsHash(ic)
|
h, err := getStandbyValidatorsHash(ic)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -103,13 +102,13 @@ func (g *GAS) OnPersist(ic *interop.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getStandbyValidatorsHash(ic *interop.Context) (util.Uint160, []*keys.PublicKey, error) {
|
func getStandbyValidatorsHash(ic *interop.Context) (util.Uint160, error) {
|
||||||
vs := ic.Chain.GetStandByValidators()
|
vs := ic.Chain.GetStandByValidators()
|
||||||
s, err := smartcontract.CreateMultiSigRedeemScript(len(vs)/2+1, vs)
|
s, err := smartcontract.CreateMultiSigRedeemScript(len(vs)/2+1, vs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return util.Uint160{}, nil, err
|
return util.Uint160{}, err
|
||||||
}
|
}
|
||||||
return hash.Hash160(s), vs, nil
|
return hash.Hash160(s), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func chainOnPersist(fs ...func(*interop.Context) error) func(*interop.Context) error {
|
func chainOnPersist(fs ...func(*interop.Context) error) func(*interop.Context) error {
|
||||||
|
|
|
@ -136,7 +136,7 @@ func (n *NEO) Initialize(ic *interop.Context) error {
|
||||||
return errors.New("already initialized")
|
return errors.New("already initialized")
|
||||||
}
|
}
|
||||||
|
|
||||||
h, vs, err := getStandbyValidatorsHash(ic)
|
h, err := getStandbyValidatorsHash(ic)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -147,12 +147,6 @@ func (n *NEO) Initialize(ic *interop.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range vs {
|
|
||||||
if err := n.RegisterCandidateInternal(ic, vs[i]); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,21 +62,10 @@ func TestNEO_Vote(t *testing.T) {
|
||||||
require.NoError(t, neo.VoteInternal(ic, h, candidates[i]))
|
require.NoError(t, neo.VoteInternal(ic, h, candidates[i]))
|
||||||
}
|
}
|
||||||
|
|
||||||
// First 3 validators must be the ones we have voted for.
|
// We still haven't voted enough validators in.
|
||||||
pubs, err = neo.GetValidatorsInternal(bc, ic.DAO)
|
pubs, err = neo.GetValidatorsInternal(bc, ic.DAO)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
for i := 1; i < sz; i++ {
|
require.Equal(t, bc.GetStandByValidators(), pubs)
|
||||||
require.Equal(t, pubs[i-1], candidates[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
var ok bool
|
|
||||||
for _, p := range bc.GetStandByValidators() {
|
|
||||||
if pubs[sz-1].Equal(p) {
|
|
||||||
ok = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
require.True(t, ok, "last validator must be stand by")
|
|
||||||
|
|
||||||
// Register and give some value to the last validator.
|
// Register and give some value to the last validator.
|
||||||
require.NoError(t, neo.RegisterCandidateInternal(ic, candidates[0]))
|
require.NoError(t, neo.RegisterCandidateInternal(ic, candidates[0]))
|
||||||
|
|
|
@ -451,6 +451,7 @@ var rpcTestCases = map[string][]rpcTestCase{
|
||||||
result: func(*executor) interface{} {
|
result: func(*executor) interface{} {
|
||||||
return &[]result.Validator{}
|
return &[]result.Validator{}
|
||||||
},
|
},
|
||||||
|
/* preview3 doesn't return any validators until there is a vote
|
||||||
check: func(t *testing.T, e *executor, validators interface{}) {
|
check: func(t *testing.T, e *executor, validators interface{}) {
|
||||||
var expected []result.Validator
|
var expected []result.Validator
|
||||||
sBValidators := e.chain.GetStandByValidators()
|
sBValidators := e.chain.GetStandByValidators()
|
||||||
|
@ -467,6 +468,7 @@ var rpcTestCases = map[string][]rpcTestCase{
|
||||||
|
|
||||||
assert.ElementsMatch(t, expected, *actual)
|
assert.ElementsMatch(t, expected, *actual)
|
||||||
},
|
},
|
||||||
|
*/
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"getversion": {
|
"getversion": {
|
||||||
|
|
Loading…
Reference in a new issue