[#21] ir: Add inner ring list relay processor

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
remotes/KirillovDenis/release/v0.21.1
Alex Vanin 2020-09-08 12:06:34 +03:00
parent f11ae1035d
commit 4aee3de24e
3 changed files with 54 additions and 0 deletions

View File

@ -72,3 +72,19 @@ func (np *Processor) handleConfig(ev event.Event) {
zap.Int("capacity", np.pool.Cap()))
}
}
func (np *Processor) handleUpdateInnerRing(ev event.Event) {
updIR := ev.(neofsEvent.UpdateInnerRing) // todo: check panic in production
np.log.Info("notification",
zap.String("type", "update inner ring"),
)
// send event to the worker pool
err := np.pool.Submit(func() { np.processUpdateInnerRing(&updIR) })
if err != nil {
// todo: move into controlled degradation stage
np.log.Warn("neofs processor worker pool drained",
zap.Int("capacity", np.pool.Cap()))
}
}

View File

@ -0,0 +1,23 @@
package neofs
import (
"github.com/nspcc-dev/neofs-node/pkg/innerring/invoke"
neofsEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/neofs"
"go.uber.org/zap"
)
// Process update inner ring event by setting inner ring list value from
// main chain in side chain.
func (np *Processor) processUpdateInnerRing(list *neofsEvent.UpdateInnerRing) {
if !np.activeState.IsActive() {
np.log.Info("passive mode, ignore deposit")
return
}
err := invoke.UpdateInnerRing(np.morphClient, np.netmapContract,
list.Keys(),
)
if err != nil {
np.log.Error("can't relay update inner ring event", zap.Error(err))
}
}

View File

@ -51,6 +51,7 @@ const (
withdrawNotification = "Withdraw"
chequeNotification = "Cheque"
configNotification = "SetConfig"
updateIRNotification = "InnerRingUpdate"
)
// New creates neofs mainnet contract processor instance.
@ -117,6 +118,13 @@ func (np *Processor) ListenerParsers() []event.ParserInfo {
config.SetParser(neofsEvent.ParseConfig)
parsers = append(parsers, config)
// update inner ring event
updateIR := event.ParserInfo{}
updateIR.SetType(updateIRNotification)
updateIR.SetScriptHash(np.neofsContract)
updateIR.SetParser(neofsEvent.ParseUpdateInnerRing)
parsers = append(parsers, updateIR)
return parsers
}
@ -152,6 +160,13 @@ func (np *Processor) ListenerHandlers() []event.HandlerInfo {
config.SetHandler(np.handleConfig)
handlers = append(handlers, config)
// updateIR handler
updateIR := event.HandlerInfo{}
updateIR.SetType(updateIRNotification)
updateIR.SetScriptHash(np.neofsContract)
updateIR.SetHandler(np.handleUpdateInnerRing)
handlers = append(handlers, updateIR)
return handlers
}