forked from TrueCloudLab/frostfs-node
[#139] Emit gas to the storage nodes at emission tick
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
d74aa807bf
commit
d193f1087c
2 changed files with 56 additions and 0 deletions
|
@ -1,6 +1,10 @@
|
|||
package alphabet
|
||||
|
||||
import (
|
||||
"crypto/elliptic"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/innerring/invoke"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
@ -9,15 +13,61 @@ func (np *Processor) processEmit() {
|
|||
index := np.irList.Index()
|
||||
if index < 0 {
|
||||
np.log.Info("passive mode, ignore gas emission event")
|
||||
|
||||
return
|
||||
} else if int(index) >= len(np.alphabetContracts) {
|
||||
np.log.Debug("node is out of alphabet range, ignore gas emission event",
|
||||
zap.Int32("index", index))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
err := invoke.AlphabetEmit(np.morphClient, np.alphabetContracts[index])
|
||||
if err != nil {
|
||||
np.log.Warn("can't invoke alphabet emit method")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if np.storageEmission == 0 {
|
||||
np.log.Info("storage node emission is off")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
networkMap, err := invoke.NetmapSnapshot(np.morphClient, np.netmapContract)
|
||||
if err != nil {
|
||||
np.log.Warn("can't get netmap snapshot to emit gas to storage nodes",
|
||||
zap.String("error", err.Error()))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
ln := len(networkMap.Nodes)
|
||||
if ln == 0 {
|
||||
np.log.Debug("empty network map, do not emit gas")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
gasPerNode := util.Fixed8(np.storageEmission / uint64(ln))
|
||||
|
||||
for i := range networkMap.Nodes {
|
||||
keyBytes := networkMap.Nodes[i].PublicKey()
|
||||
|
||||
key, err := keys.NewPublicKeyFromBytes(keyBytes, elliptic.P256())
|
||||
if err != nil {
|
||||
np.log.Warn("can't convert node public key to address",
|
||||
zap.String("error", err.Error()))
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
err = np.morphClient.TransferGas(key.GetScriptHash(), gasPerNode)
|
||||
if err != nil {
|
||||
np.log.Warn("can't transfer gas",
|
||||
zap.String("receiver", key.Address()),
|
||||
zap.Int64("amount", int64(gasPerNode)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,8 +21,10 @@ type (
|
|||
log *zap.Logger
|
||||
pool *ants.Pool
|
||||
alphabetContracts [7]util.Uint160
|
||||
netmapContract util.Uint160
|
||||
morphClient *client.Client
|
||||
irList Indexer
|
||||
storageEmission uint64
|
||||
}
|
||||
|
||||
// Params of the processor constructor.
|
||||
|
@ -30,8 +32,10 @@ type (
|
|||
Log *zap.Logger
|
||||
PoolSize int
|
||||
AlphabetContracts [7]util.Uint160
|
||||
NetmapContract util.Uint160
|
||||
MorphClient *client.Client
|
||||
IRList Indexer
|
||||
StorageEmission uint64
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -57,8 +61,10 @@ func New(p *Params) (*Processor, error) {
|
|||
log: p.Log,
|
||||
pool: pool,
|
||||
alphabetContracts: p.AlphabetContracts,
|
||||
netmapContract: p.NetmapContract,
|
||||
morphClient: p.MorphClient,
|
||||
irList: p.IRList,
|
||||
storageEmission: p.StorageEmission,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue