From c8d58d56b97a4a56e1840af7da1ca0b66caea6d8 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Thu, 22 Jul 2021 13:04:37 +0300 Subject: [PATCH] [#705] innerring/governance: Hide fetching ir keys behind interface Add to governance processor IRFetcher interface. Implementation must deduct if notary enabled or not. Signed-off-by: Pavel Karpy --- pkg/innerring/innerring.go | 1 + .../processors/governance/process_update.go | 2 +- pkg/innerring/processors/governance/processor.go | 16 ++++++++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index 43cea11d6..ec166b4f3 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -547,6 +547,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error AlphabetState: server, EpochState: server, Voter: server, + IRFetcher: irf, MorphClient: server.morphClient, MainnetClient: server.mainnetClient, NotaryDisabled: server.sideNotaryConfig.disabled, diff --git a/pkg/innerring/processors/governance/process_update.go b/pkg/innerring/processors/governance/process_update.go index 4f9213cf3..442bddbfc 100644 --- a/pkg/innerring/processors/governance/process_update.go +++ b/pkg/innerring/processors/governance/process_update.go @@ -54,7 +54,7 @@ func (gp *Processor) processAlphabetSync() { } // 2. Update NeoFSAlphabet role in side chain. - innerRing, err := gp.morphClient.NeoFSAlphabetList() + innerRing, err := gp.irFetcher.InnerRingKeys() if err != nil { gp.log.Error("can't fetch inner ring list from side chain", zap.String("error", err.Error())) diff --git a/pkg/innerring/processors/governance/processor.go b/pkg/innerring/processors/governance/processor.go index 588403ad1..a7d2ede61 100644 --- a/pkg/innerring/processors/governance/processor.go +++ b/pkg/innerring/processors/governance/processor.go @@ -21,7 +21,7 @@ import ( const ProcessorPoolSize = 1 type ( - // AlphabetState is a callback interface for inner ring global state. + // AlphabetState is a callback interface for innerring global state. AlphabetState interface { IsAlphabet() bool } @@ -31,11 +31,18 @@ type ( VoteForSidechainValidator(keys keys.PublicKeys) error } - // EpochState is a callback interface for inner ring global state. + // EpochState is a callback interface for innerring global state. EpochState interface { EpochCounter() uint64 } + // IRFetcher is a callback interface for innerring keys. + // Implementation must take into account availability of + // the notary contract. + IRFetcher interface { + InnerRingKeys() (keys.PublicKeys, error) + } + // Processor of events related to governance in the network. Processor struct { log *zap.Logger @@ -46,6 +53,7 @@ type ( alphabetState AlphabetState epochState EpochState voter Voter + irFetcher IRFetcher mainnetClient *client.Client morphClient *client.Client @@ -60,6 +68,7 @@ type ( AlphabetState AlphabetState EpochState EpochState Voter Voter + IRFetcher IRFetcher MorphClient *client.Client MainnetClient *client.Client @@ -85,6 +94,8 @@ func New(p *Params) (*Processor, error) { return nil, errors.New("ir/governance: global state is not set") case p.Voter == nil: return nil, errors.New("ir/governance: global state is not set") + case p.IRFetcher == nil: + return nil, errors.New("ir/governance: innerring keys fetcher is not set") } pool, err := ants.NewPool(ProcessorPoolSize, ants.WithNonblocking(true)) @@ -100,6 +111,7 @@ func New(p *Params) (*Processor, error) { alphabetState: p.AlphabetState, epochState: p.EpochState, voter: p.Voter, + irFetcher: p.IRFetcher, mainnetClient: p.MainnetClient, morphClient: p.MorphClient, notaryDisabled: p.NotaryDisabled,