forked from TrueCloudLab/neoneo-go
core: add max nodes count restriction to designate contract
This commit is contained in:
parent
5bba9c158a
commit
7c232e2ddc
2 changed files with 12 additions and 1 deletions
|
@ -30,6 +30,9 @@ type Designate struct {
|
|||
const (
|
||||
designateContractID = -5
|
||||
designateName = "Designation"
|
||||
|
||||
// maxNodeCount is the maximum number of nodes to set the role for.
|
||||
maxNodeCount = 32
|
||||
)
|
||||
|
||||
// Role represents type of participant.
|
||||
|
@ -45,6 +48,7 @@ const (
|
|||
var (
|
||||
ErrInvalidRole = errors.New("invalid role")
|
||||
ErrEmptyNodeList = errors.New("node list is empty")
|
||||
ErrLargeNodeList = errors.New("node list is too large")
|
||||
)
|
||||
|
||||
func isValidRole(r Role) bool {
|
||||
|
@ -162,9 +166,13 @@ func (s *Designate) designateAsRole(ic *interop.Context, args []stackitem.Item)
|
|||
|
||||
// DesignateAsRole sets nodes for role r.
|
||||
func (s *Designate) DesignateAsRole(ic *interop.Context, r Role, pubs keys.PublicKeys) error {
|
||||
if len(pubs) == 0 {
|
||||
length := len(pubs)
|
||||
if length == 0 {
|
||||
return ErrEmptyNodeList
|
||||
}
|
||||
if length > maxNodeCount {
|
||||
return ErrLargeNodeList
|
||||
}
|
||||
if !isValidRole(r) {
|
||||
return ErrInvalidRole
|
||||
}
|
||||
|
|
|
@ -92,6 +92,9 @@ func TestDesignate_DesignateAsRole(t *testing.T) {
|
|||
err = des.DesignateAsRole(ic, native.RoleOracle, keys.PublicKeys{})
|
||||
require.True(t, errors.Is(err, native.ErrEmptyNodeList), "got: %v", err)
|
||||
|
||||
err = des.DesignateAsRole(ic, native.RoleOracle, make(keys.PublicKeys, 32+1))
|
||||
require.True(t, errors.Is(err, native.ErrLargeNodeList), "got: %v", err)
|
||||
|
||||
priv, err := keys.NewPrivateKey()
|
||||
require.NoError(t, err)
|
||||
pub := priv.PublicKey()
|
||||
|
|
Loading…
Reference in a new issue