mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-22 09:29:38 +00:00
core: move P2PNotary node role out of P2PSigExtensions
Port https://github.com/neo-project/neo/pull/3172. Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
parent
6a5833759c
commit
7868578571
3 changed files with 6 additions and 15 deletions
|
@ -88,7 +88,7 @@ func NewContracts(cfg config.ProtocolConfiguration) *Contracts {
|
||||||
cs.Policy = policy
|
cs.Policy = policy
|
||||||
cs.Contracts = append(cs.Contracts, neo, gas, policy)
|
cs.Contracts = append(cs.Contracts, neo, gas, policy)
|
||||||
|
|
||||||
desig := newDesignate(cfg.P2PSigExtensions, cfg.Genesis.Roles)
|
desig := newDesignate(cfg.Genesis.Roles)
|
||||||
desig.NEO = neo
|
desig.NEO = neo
|
||||||
cs.Designate = desig
|
cs.Designate = desig
|
||||||
cs.Contracts = append(cs.Contracts, desig)
|
cs.Contracts = append(cs.Contracts, desig)
|
||||||
|
|
|
@ -32,8 +32,6 @@ type Designate struct {
|
||||||
interop.ContractMD
|
interop.ContractMD
|
||||||
NEO *NEO
|
NEO *NEO
|
||||||
|
|
||||||
// p2pSigExtensionsEnabled defines whether the P2P signature extensions logic is relevant.
|
|
||||||
p2pSigExtensionsEnabled bool
|
|
||||||
// initialNodeRoles defines a set of node roles that should be defined at the contract
|
// initialNodeRoles defines a set of node roles that should be defined at the contract
|
||||||
// deployment (initialization).
|
// deployment (initialization).
|
||||||
initialNodeRoles map[noderoles.Role]keys.PublicKeys
|
initialNodeRoles map[noderoles.Role]keys.PublicKeys
|
||||||
|
@ -99,14 +97,13 @@ func copyDesignationCache(src, dst *DesignationCache) {
|
||||||
|
|
||||||
func (s *Designate) isValidRole(r noderoles.Role) bool {
|
func (s *Designate) isValidRole(r noderoles.Role) bool {
|
||||||
return r == noderoles.Oracle || r == noderoles.StateValidator ||
|
return r == noderoles.Oracle || r == noderoles.StateValidator ||
|
||||||
r == noderoles.NeoFSAlphabet || (s.p2pSigExtensionsEnabled && r == noderoles.P2PNotary)
|
r == noderoles.NeoFSAlphabet || r == noderoles.P2PNotary
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDesignate(p2pSigExtensionsEnabled bool, initialNodeRoles map[noderoles.Role]keys.PublicKeys) *Designate {
|
func newDesignate(initialNodeRoles map[noderoles.Role]keys.PublicKeys) *Designate {
|
||||||
s := &Designate{ContractMD: *interop.NewContractMD(nativenames.Designation, designateContractID)}
|
s := &Designate{ContractMD: *interop.NewContractMD(nativenames.Designation, designateContractID)}
|
||||||
defer s.BuildHFSpecificMD(s.ActiveIn())
|
defer s.BuildHFSpecificMD(s.ActiveIn())
|
||||||
|
|
||||||
s.p2pSigExtensionsEnabled = p2pSigExtensionsEnabled
|
|
||||||
s.initialNodeRoles = initialNodeRoles
|
s.initialNodeRoles = initialNodeRoles
|
||||||
|
|
||||||
desc := newDescriptor("getDesignatedByRole", smartcontract.ArrayType,
|
desc := newDescriptor("getDesignatedByRole", smartcontract.ArrayType,
|
||||||
|
@ -160,10 +157,7 @@ func (s *Designate) Initialize(ic *interop.Context, hf *config.Hardfork, newMD *
|
||||||
// we can fetch the roles data right from the storage.
|
// we can fetch the roles data right from the storage.
|
||||||
func (s *Designate) InitializeCache(blockHeight uint32, d *dao.Simple) error {
|
func (s *Designate) InitializeCache(blockHeight uint32, d *dao.Simple) error {
|
||||||
cache := &DesignationCache{}
|
cache := &DesignationCache{}
|
||||||
roles := []noderoles.Role{noderoles.Oracle, noderoles.NeoFSAlphabet, noderoles.StateValidator}
|
roles := []noderoles.Role{noderoles.Oracle, noderoles.NeoFSAlphabet, noderoles.StateValidator, noderoles.P2PNotary}
|
||||||
if s.p2pSigExtensionsEnabled {
|
|
||||||
roles = append(roles, noderoles.P2PNotary)
|
|
||||||
}
|
|
||||||
for _, r := range roles {
|
for _, r := range roles {
|
||||||
err := s.updateCachedRoleData(cache, d, r)
|
err := s.updateCachedRoleData(cache, d, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -189,9 +183,7 @@ func (s *Designate) PostPersist(ic *interop.Context) error {
|
||||||
s.notifyRoleChanged(&cache.oracles, noderoles.Oracle)
|
s.notifyRoleChanged(&cache.oracles, noderoles.Oracle)
|
||||||
s.notifyRoleChanged(&cache.stateVals, noderoles.StateValidator)
|
s.notifyRoleChanged(&cache.stateVals, noderoles.StateValidator)
|
||||||
s.notifyRoleChanged(&cache.neofsAlphabet, noderoles.NeoFSAlphabet)
|
s.notifyRoleChanged(&cache.neofsAlphabet, noderoles.NeoFSAlphabet)
|
||||||
if s.p2pSigExtensionsEnabled {
|
|
||||||
s.notifyRoleChanged(&cache.notaries, noderoles.P2PNotary)
|
s.notifyRoleChanged(&cache.notaries, noderoles.P2PNotary)
|
||||||
}
|
|
||||||
|
|
||||||
cache.rolesChangedFlag = false
|
cache.rolesChangedFlag = false
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -22,7 +22,6 @@ const (
|
||||||
StateValidator Role = 4
|
StateValidator Role = 4
|
||||||
Oracle Role = 8
|
Oracle Role = 8
|
||||||
NeoFSAlphabet Role = 16
|
NeoFSAlphabet Role = 16
|
||||||
// P2PNotary is an extension of Neo protocol available on specifically configured NeoGo networks.
|
|
||||||
P2PNotary Role = 32
|
P2PNotary Role = 32
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue