[#873] node: Make deposits depend on epoch and balances

SN tries to keep 1:3 proportion of GAS and
notary balances respectively. If that proportion
has been messed(means that notary balance is
lower than required) it sends half of its
GAS balance to the notary service.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
remotes/fyrchik/container-alias-fee
Pavel Karpy 2021-09-30 22:11:20 +03:00 committed by Alex Vanin
parent d2096b392c
commit 5e816dc01a
2 changed files with 31 additions and 6 deletions

View File

@ -78,11 +78,6 @@ func initMorphComponents(c *cfg) {
),
)
fatalOnErr(err)
c.cfgMorph.notaryDepositAmount = morphconfig.Notary(c.appCfg).Amount()
c.cfgMorph.notaryDepositDuration = morphconfig.Notary(c.appCfg).Duration()
newDepositTimer(c)
}
c.log.Debug("notary support",
@ -122,8 +117,24 @@ func makeAndWaitNotaryDeposit(c *cfg) {
}
func makeNotaryDeposit(c *cfg) (util.Uint256, error) {
const (
// gasMultiplier defines how many times more the notary
// balance must be compared to the GAS balance of the node:
// notaryBalance = GASBalance * gasMultiplier
gasMultiplier = 3
// gasDivisor defines what part of GAS balance (1/gasDivisor)
// should be transferred to the notary service
gasDivisor = 2
)
depositAmount, err := client.CalculateNotaryDepositAmount(c.cfgMorph.client, gasMultiplier, gasDivisor)
if err != nil {
return util.Uint256{}, fmt.Errorf("could not calculate notary deposit: %w", err)
}
return c.cfgMorph.client.DepositNotary(
c.cfgMorph.notaryDepositAmount,
depositAmount,
c.cfgMorph.notaryDepositDuration+notaryDepositExtraBlocks,
)
}

View File

@ -7,6 +7,7 @@ import (
netmapSDK "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
netmapV2 "github.com/nspcc-dev/neofs-api-go/v2/netmap"
netmapGRPC "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc"
morphconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/morph"
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
@ -145,6 +146,19 @@ func initNetmapService(c *cfg) {
c.handleLocalNodeInfo(ni)
})
if c.cfgMorph.notaryEnabled {
c.cfgMorph.notaryDepositDuration = morphconfig.Notary(c.appCfg).Duration()
addNewEpochAsyncNotificationHandler(c, func(ev event.Event) {
_, err := makeNotaryDeposit(c)
if err != nil {
c.log.Error("could not make notary deposit",
zap.String("error", err.Error()),
)
}
})
}
}
func bootstrapNode(c *cfg) {