[#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 <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-07-22 13:04:37 +03:00 committed by Alex Vanin
parent 73ba35b379
commit c8d58d56b9
3 changed files with 16 additions and 3 deletions

View file

@ -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,

View file

@ -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()))

View file

@ -36,6 +36,13 @@ type (
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,