diff --git a/cmd/neofs-node/morph.go b/cmd/neofs-node/morph.go index 2fce060f..c4cfda68 100644 --- a/cmd/neofs-node/morph.go +++ b/cmd/neofs-node/morph.go @@ -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, ) } diff --git a/cmd/neofs-node/netmap.go b/cmd/neofs-node/netmap.go index 66c4a310..206e3421 100644 --- a/cmd/neofs-node/netmap.go +++ b/cmd/neofs-node/netmap.go @@ -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) {