mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 13:41:37 +00:00
native: add NeoFSAlphabet
node role
This commit is contained in:
parent
1d70504003
commit
4195603257
2 changed files with 18 additions and 2 deletions
|
@ -31,6 +31,7 @@ type Designate struct {
|
||||||
rolesChangedFlag atomic.Value
|
rolesChangedFlag atomic.Value
|
||||||
oracles atomic.Value
|
oracles atomic.Value
|
||||||
stateVals atomic.Value
|
stateVals atomic.Value
|
||||||
|
neofsAlphabet atomic.Value
|
||||||
notaries atomic.Value
|
notaries atomic.Value
|
||||||
|
|
||||||
// p2pSigExtensionsEnabled defines whether the P2P signature extensions logic is relevant.
|
// p2pSigExtensionsEnabled defines whether the P2P signature extensions logic is relevant.
|
||||||
|
@ -61,6 +62,7 @@ type Role byte
|
||||||
const (
|
const (
|
||||||
RoleStateValidator Role = 4
|
RoleStateValidator Role = 4
|
||||||
RoleOracle Role = 8
|
RoleOracle Role = 8
|
||||||
|
RoleNeoFSAlphabet Role = 16
|
||||||
RoleP2PNotary Role = 128
|
RoleP2PNotary Role = 128
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -75,7 +77,8 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Designate) isValidRole(r Role) bool {
|
func (s *Designate) isValidRole(r Role) bool {
|
||||||
return r == RoleOracle || r == RoleStateValidator || (s.p2pSigExtensionsEnabled && r == RoleP2PNotary)
|
return r == RoleOracle || r == RoleStateValidator ||
|
||||||
|
r == RoleNeoFSAlphabet || (s.p2pSigExtensionsEnabled && r == RoleP2PNotary)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDesignate(p2pSigExtensionsEnabled bool) *Designate {
|
func newDesignate(p2pSigExtensionsEnabled bool) *Designate {
|
||||||
|
@ -120,6 +123,9 @@ func (s *Designate) PostPersist(ic *interop.Context) error {
|
||||||
if err := s.updateCachedRoleData(&s.stateVals, ic.DAO, RoleStateValidator); err != nil {
|
if err := s.updateCachedRoleData(&s.stateVals, ic.DAO, RoleStateValidator); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err := s.updateCachedRoleData(&s.neofsAlphabet, ic.DAO, RoleNeoFSAlphabet); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if s.p2pSigExtensionsEnabled {
|
if s.p2pSigExtensionsEnabled {
|
||||||
if err := s.updateCachedRoleData(&s.notaries, ic.DAO, RoleP2PNotary); err != nil {
|
if err := s.updateCachedRoleData(&s.notaries, ic.DAO, RoleP2PNotary); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -166,7 +172,7 @@ func (s *Designate) hashFromNodes(r Role, nodes keys.PublicKeys) util.Uint160 {
|
||||||
}
|
}
|
||||||
var script []byte
|
var script []byte
|
||||||
switch r {
|
switch r {
|
||||||
case RoleOracle:
|
case RoleOracle, RoleNeoFSAlphabet:
|
||||||
script, _ = smartcontract.CreateDefaultMultiSigRedeemScript(nodes.Copy())
|
script, _ = smartcontract.CreateDefaultMultiSigRedeemScript(nodes.Copy())
|
||||||
case RoleP2PNotary:
|
case RoleP2PNotary:
|
||||||
script, _ = smartcontract.CreateMultiSigRedeemScript(1, nodes.Copy())
|
script, _ = smartcontract.CreateMultiSigRedeemScript(1, nodes.Copy())
|
||||||
|
@ -206,6 +212,8 @@ func (s *Designate) getCachedRoleData(r Role) *roleData {
|
||||||
val = s.oracles.Load()
|
val = s.oracles.Load()
|
||||||
case RoleStateValidator:
|
case RoleStateValidator:
|
||||||
val = s.stateVals.Load()
|
val = s.stateVals.Load()
|
||||||
|
case RoleNeoFSAlphabet:
|
||||||
|
val = s.neofsAlphabet.Load()
|
||||||
case RoleP2PNotary:
|
case RoleP2PNotary:
|
||||||
val = s.notaries.Load()
|
val = s.notaries.Load()
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,6 +99,14 @@ func TestDesignate_DesignateAsRoleTx(t *testing.T) {
|
||||||
bc.setNodesByRole(t, true, native.RoleStateValidator, pubs)
|
bc.setNodesByRole(t, true, native.RoleStateValidator, pubs)
|
||||||
bc.getNodesByRole(t, true, native.RoleStateValidator, bc.BlockHeight()+1, 1)
|
bc.getNodesByRole(t, true, native.RoleStateValidator, bc.BlockHeight()+1, 1)
|
||||||
|
|
||||||
|
t.Run("neofs", func(t *testing.T) {
|
||||||
|
priv, err := keys.NewPrivateKey()
|
||||||
|
require.NoError(t, err)
|
||||||
|
pubs = keys.PublicKeys{priv.PublicKey()}
|
||||||
|
bc.setNodesByRole(t, true, native.RoleNeoFSAlphabet, pubs)
|
||||||
|
bc.getNodesByRole(t, true, native.RoleNeoFSAlphabet, bc.BlockHeight()+1, 1)
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDesignate_DesignateAsRole(t *testing.T) {
|
func TestDesignate_DesignateAsRole(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue