Skip to content

Commit

Permalink
native: don't register standby validators on initialization
Browse files Browse the repository at this point in the history
C# doesn't do that since neo-project/neo#1762.
  • Loading branch information
roman-khimov committed Aug 10, 2020
1 parent 6e252fb commit fb97ea9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 25 deletions.
9 changes: 4 additions & 5 deletions pkg/core/native/native_gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"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/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/util"
)
Expand Down Expand Up @@ -73,7 +72,7 @@ func (g *GAS) Initialize(ic *interop.Context) error {
if g.nep5TokenNative.getTotalSupply(ic.DAO).Sign() != 0 {
return errors.New("already initialized")
}
h, _, err := getStandbyValidatorsHash(ic)
h, err := getStandbyValidatorsHash(ic)
if err != nil {
return err
}
Expand Down Expand Up @@ -103,13 +102,13 @@ func (g *GAS) OnPersist(ic *interop.Context) error {
return nil
}

func getStandbyValidatorsHash(ic *interop.Context) (util.Uint160, []*keys.PublicKey, error) {
func getStandbyValidatorsHash(ic *interop.Context) (util.Uint160, error) {
vs := ic.Chain.GetStandByValidators()
s, err := smartcontract.CreateMultiSigRedeemScript(len(vs)/2+1, vs)
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 {
Expand Down
8 changes: 1 addition & 7 deletions pkg/core/native/native_neo.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (n *NEO) Initialize(ic *interop.Context) error {
return errors.New("already initialized")
}

h, vs, err := getStandbyValidatorsHash(ic)
h, err := getStandbyValidatorsHash(ic)
if err != nil {
return err
}
Expand All @@ -147,12 +147,6 @@ func (n *NEO) Initialize(ic *interop.Context) error {
return err
}

for i := range vs {
if err := n.RegisterCandidateInternal(ic, vs[i]); err != nil {
return err
}
}

return nil
}

Expand Down
15 changes: 2 additions & 13 deletions pkg/core/native_neo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,10 @@ func TestNEO_Vote(t *testing.T) {
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)
require.NoError(t, err)
for i := 1; i < sz; i++ {
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")
require.Equal(t, bc.GetStandByValidators(), pubs)

// Register and give some value to the last validator.
require.NoError(t, neo.RegisterCandidateInternal(ic, candidates[0]))
Expand Down
2 changes: 2 additions & 0 deletions pkg/rpc/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ var rpcTestCases = map[string][]rpcTestCase{
result: func(*executor) interface{} {
return &[]result.Validator{}
},
/* preview3 doesn't return any validators until there is a vote
check: func(t *testing.T, e *executor, validators interface{}) {
var expected []result.Validator
sBValidators := e.chain.GetStandByValidators()
Expand All @@ -467,6 +468,7 @@ var rpcTestCases = map[string][]rpcTestCase{
assert.ElementsMatch(t, expected, *actual)
},
*/
},
},
"getversion": {
Expand Down

0 comments on commit fb97ea9

Please sign in to comment.