Skip to content

Commit

Permalink
core: move P2PNotary node role out of P2PSigExtensions
Browse files Browse the repository at this point in the history
Port neo-project/neo#3172.

Signed-off-by: Anna Shaleva <[email protected]>
  • Loading branch information
AnnaShaleva committed May 21, 2024
1 parent 6a58337 commit 456deb7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkg/core/native/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func NewContracts(cfg config.ProtocolConfiguration) *Contracts {
cs.Policy = policy
cs.Contracts = append(cs.Contracts, neo, gas, policy)

desig := newDesignate(cfg.P2PSigExtensions, cfg.Genesis.Roles)
desig := newDesignate(cfg.Genesis.Roles)
desig.NEO = neo
cs.Designate = desig
cs.Contracts = append(cs.Contracts, desig)
Expand Down
16 changes: 4 additions & 12 deletions pkg/core/native/designate.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ type Designate struct {
interop.ContractMD
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
// deployment (initialization).
initialNodeRoles map[noderoles.Role]keys.PublicKeys
Expand Down Expand Up @@ -99,14 +97,13 @@ func copyDesignationCache(src, dst *DesignationCache) {

func (s *Designate) isValidRole(r noderoles.Role) bool {
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)}
defer s.BuildHFSpecificMD(s.ActiveIn())

s.p2pSigExtensionsEnabled = p2pSigExtensionsEnabled
s.initialNodeRoles = initialNodeRoles

desc := newDescriptor("getDesignatedByRole", smartcontract.ArrayType,
Expand Down Expand Up @@ -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.
func (s *Designate) InitializeCache(blockHeight uint32, d *dao.Simple) error {
cache := &DesignationCache{}
roles := []noderoles.Role{noderoles.Oracle, noderoles.NeoFSAlphabet, noderoles.StateValidator}
if s.p2pSigExtensionsEnabled {
roles = append(roles, noderoles.P2PNotary)
}
roles := []noderoles.Role{noderoles.Oracle, noderoles.NeoFSAlphabet, noderoles.StateValidator, noderoles.P2PNotary}
for _, r := range roles {
err := s.updateCachedRoleData(cache, d, r)
if err != nil {
Expand All @@ -189,9 +183,7 @@ func (s *Designate) PostPersist(ic *interop.Context) error {
s.notifyRoleChanged(&cache.oracles, noderoles.Oracle)
s.notifyRoleChanged(&cache.stateVals, noderoles.StateValidator)
s.notifyRoleChanged(&cache.neofsAlphabet, noderoles.NeoFSAlphabet)
if s.p2pSigExtensionsEnabled {
s.notifyRoleChanged(&cache.notaries, noderoles.P2PNotary)
}
s.notifyRoleChanged(&cache.notaries, noderoles.P2PNotary)

cache.rolesChangedFlag = false
return nil
Expand Down

0 comments on commit 456deb7

Please sign in to comment.