[#416] innerring: Add gas threshold

On the `Deposit` events add gas balance check.
Make transfer only if the balance is greater
than the `GasTransferThreshold` that is defined
with environmental variable.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-03-18 20:42:35 +03:00 committed by Alex Vanin
parent 99d9544a64
commit b9892edd6e
4 changed files with 71 additions and 50 deletions

View file

@ -94,6 +94,7 @@ func defaultConfiguration(cfg *viper.Viper) {
cfg.SetDefault("emit.mint.cache_size", 1000)
cfg.SetDefault("emit.mint.threshold", 1)
cfg.SetDefault("emit.mint.value", 20000000) // 0.2 Fixed8
cfg.SetDefault("emit.gas.balance_threshold", 0)
cfg.SetDefault("audit.task.exec_pool_size", 10)
cfg.SetDefault("audit.task.queue_capacity", 100)

View file

@ -499,6 +499,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
MintEmitCacheSize: cfg.GetInt("emit.mint.cache_size"),
MintEmitThreshold: cfg.GetUint64("emit.mint.threshold"),
MintEmitValue: fixedn.Fixed8(cfg.GetInt64("emit.mint.value")),
GasBalanceThreshold: cfg.GetInt64("emit.gas.balance_threshold"),
})
if err != nil {
return nil, err

View file

@ -53,6 +53,22 @@ func (np *Processor) processDeposit(deposit *neofsEvent.Deposit) {
return
}
// get gas balance of the node
// before gas transfer check if the balance is greater than threshold
balance, err := np.morphClient.GasBalance()
if err != nil {
np.log.Error("can't get gas balance of the node", zap.Error(err))
return
}
if balance < np.gasBalanceThreshold {
np.log.Warn("gas balance threshold has been reached",
zap.Int64("balance", balance),
zap.Int64("threshold", np.gasBalanceThreshold))
return
}
err = np.morphClient.TransferGas(receiver, np.mintEmitValue)
if err != nil {
np.log.Error("can't transfer native gas to receiver",

View file

@ -45,6 +45,7 @@ type (
mintEmitCache *lru.Cache
mintEmitThreshold uint64
mintEmitValue fixedn.Fixed8
gasBalanceThreshold int64
}
// Params of the processor constructor.
@ -61,6 +62,7 @@ type (
MintEmitCacheSize int
MintEmitThreshold uint64 // in epochs
MintEmitValue fixedn.Fixed8
GasBalanceThreshold int64
}
)
@ -113,6 +115,7 @@ func New(p *Params) (*Processor, error) {
mintEmitCache: lruCache,
mintEmitThreshold: p.MintEmitThreshold,
mintEmitValue: p.MintEmitValue,
gasBalanceThreshold: p.GasBalanceThreshold,
}, nil
}