From 9a4f40626cbfdbd00a77125ac57a9c4a8bef4797 Mon Sep 17 00:00:00 2001
From: Pavel Karpy
Date: Mon, 20 Mar 2023 19:58:11 +0300
Subject: [PATCH] [#128] IR: Do not try to emit GAS to nobody
Fix sending GAS to an empty extra wallets receivers list. Also, send GAS to
extra wallets even if netmap is empty.
Signed-off-by: Pavel Karpy
---
.../processors/alphabet/process_emit.go | 33 +++++++++++--------
1 file changed, 19 insertions(+), 14 deletions(-)
diff --git a/pkg/innerring/processors/alphabet/process_emit.go b/pkg/innerring/processors/alphabet/process_emit.go
index 867d9622..10dcf079 100644
--- a/pkg/innerring/processors/alphabet/process_emit.go
+++ b/pkg/innerring/processors/alphabet/process_emit.go
@@ -50,15 +50,18 @@ func (ap *Processor) processEmit() {
}
nmNodes := networkMap.Nodes()
+ nmLen := len(nmNodes)
+ extraLen := len(ap.parsedWallets)
- ln := len(nmNodes)
- if ln == 0 {
- ap.log.Debug("empty network map, do not emit gas")
+ ap.log.Debug("gas emission",
+ zap.Int("network_map", nmLen),
+ zap.Int("extra_wallets", extraLen))
+ if nmLen+extraLen == 0 {
return
}
- gasPerNode := fixedn.Fixed8(ap.storageEmission / uint64(ln+len(ap.parsedWallets)))
+ gasPerNode := fixedn.Fixed8(ap.storageEmission / uint64(nmLen+extraLen))
for i := range nmNodes {
keyBytes := nmNodes[i].PublicKey()
@@ -81,16 +84,18 @@ func (ap *Processor) processEmit() {
}
}
- err = ap.morphClient.BatchTransferGas(ap.parsedWallets, gasPerNode)
- if err != nil {
- receiversLog := make([]string, len(ap.parsedWallets))
- for i, addr := range ap.parsedWallets {
- receiversLog[i] = addr.StringLE()
+ if extraLen != 0 {
+ err = ap.morphClient.BatchTransferGas(ap.parsedWallets, gasPerNode)
+ if err != nil {
+ receiversLog := make([]string, extraLen)
+ for i, addr := range ap.parsedWallets {
+ receiversLog[i] = addr.StringLE()
+ }
+ ap.log.Warn("can't transfer gas to wallet",
+ zap.Strings("receivers", receiversLog),
+ zap.Int64("amount", int64(gasPerNode)),
+ zap.String("error", err.Error()),
+ )
}
- ap.log.Warn("can't transfer gas to wallet",
- zap.Strings("receivers", receiversLog),
- zap.Int64("amount", int64(gasPerNode)),
- zap.String("error", err.Error()),
- )
}
}