[#21] ir: Add config relay processor

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-09-08 12:01:38 +03:00
parent be9e7664f3
commit f11ae1035d
3 changed files with 58 additions and 0 deletions

View file

@ -55,3 +55,20 @@ func (np *Processor) handleCheque(ev event.Event) {
zap.Int("capacity", np.pool.Cap()))
}
}
func (np *Processor) handleConfig(ev event.Event) {
cfg := ev.(neofsEvent.Config) // todo: check panic in production
np.log.Info("notification",
zap.String("type", "set config"),
zap.String("key", hex.EncodeToString(cfg.Key())),
zap.String("value", hex.EncodeToString(cfg.Value())))
// send event to the worker pool
err := np.pool.Submit(func() { np.processConfig(&cfg) })
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,26 @@
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 config event by setting configuration value from main chain in
// side chain.
func (np *Processor) processConfig(config *neofsEvent.Config) {
if !np.activeState.IsActive() {
np.log.Info("passive mode, ignore deposit")
return
}
err := invoke.SetConfig(np.morphClient, np.netmapContract,
&invoke.SetConfigArgs{
Key: config.Key(),
Value: config.Value(),
},
)
if err != nil {
np.log.Error("can't relay set config event", zap.Error(err))
}
}

View file

@ -50,6 +50,7 @@ const (
depositNotification = "Deposit"
withdrawNotification = "Withdraw"
chequeNotification = "Cheque"
configNotification = "SetConfig"
)
// New creates neofs mainnet contract processor instance.
@ -109,6 +110,13 @@ func (np *Processor) ListenerParsers() []event.ParserInfo {
cheque.SetParser(neofsEvent.ParseCheque)
parsers = append(parsers, cheque)
// config event
config := event.ParserInfo{}
config.SetType(configNotification)
config.SetScriptHash(np.neofsContract)
config.SetParser(neofsEvent.ParseConfig)
parsers = append(parsers, config)
return parsers
}
@ -137,6 +145,13 @@ func (np *Processor) ListenerHandlers() []event.HandlerInfo {
cheque.SetHandler(np.handleCheque)
handlers = append(handlers, cheque)
// config handler
config := event.HandlerInfo{}
config.SetType(configNotification)
config.SetScriptHash(np.neofsContract)
config.SetHandler(np.handleConfig)
handlers = append(handlers, config)
return handlers
}