[#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, AlphabetState: server,
EpochState: server, EpochState: server,
Voter: server, Voter: server,
IRFetcher: irf,
MorphClient: server.morphClient, MorphClient: server.morphClient,
MainnetClient: server.mainnetClient, MainnetClient: server.mainnetClient,
NotaryDisabled: server.sideNotaryConfig.disabled, NotaryDisabled: server.sideNotaryConfig.disabled,

View file

@ -54,7 +54,7 @@ func (gp *Processor) processAlphabetSync() {
} }
// 2. Update NeoFSAlphabet role in side chain. // 2. Update NeoFSAlphabet role in side chain.
innerRing, err := gp.morphClient.NeoFSAlphabetList() innerRing, err := gp.irFetcher.InnerRingKeys()
if err != nil { if err != nil {
gp.log.Error("can't fetch inner ring list from side chain", gp.log.Error("can't fetch inner ring list from side chain",
zap.String("error", err.Error())) zap.String("error", err.Error()))

View file

@ -36,6 +36,13 @@ type (
EpochCounter() uint64 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 of events related to governance in the network.
Processor struct { Processor struct {
log *zap.Logger log *zap.Logger
@ -46,6 +53,7 @@ type (
alphabetState AlphabetState alphabetState AlphabetState
epochState EpochState epochState EpochState
voter Voter voter Voter
irFetcher IRFetcher
mainnetClient *client.Client mainnetClient *client.Client
morphClient *client.Client morphClient *client.Client
@ -60,6 +68,7 @@ type (
AlphabetState AlphabetState AlphabetState AlphabetState
EpochState EpochState EpochState EpochState
Voter Voter Voter Voter
IRFetcher IRFetcher
MorphClient *client.Client MorphClient *client.Client
MainnetClient *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") return nil, errors.New("ir/governance: global state is not set")
case p.Voter == nil: case p.Voter == nil:
return nil, errors.New("ir/governance: global state is not set") 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)) pool, err := ants.NewPool(ProcessorPoolSize, ants.WithNonblocking(true))
@ -100,6 +111,7 @@ func New(p *Params) (*Processor, error) {
alphabetState: p.AlphabetState, alphabetState: p.AlphabetState,
epochState: p.EpochState, epochState: p.EpochState,
voter: p.Voter, voter: p.Voter,
irFetcher: p.IRFetcher,
mainnetClient: p.MainnetClient, mainnetClient: p.MainnetClient,
morphClient: p.MorphClient, morphClient: p.MorphClient,
notaryDisabled: p.NotaryDisabled, notaryDisabled: p.NotaryDisabled,