[#9999] node: Break notary deposit wait after VUB
All checks were successful
Tests and linters / Run gofumpt (pull_request) Successful in 2m14s
DCO action / DCO (pull_request) Successful in 2m27s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m55s
Vulncheck / Vulncheck (pull_request) Successful in 2m47s
Tests and linters / gopls check (pull_request) Successful in 3m33s
Build / Build Components (pull_request) Successful in 3m43s
Tests and linters / Staticcheck (pull_request) Successful in 3m42s
Tests and linters / Lint (pull_request) Successful in 4m34s
Tests and linters / Tests (pull_request) Successful in 6m52s
Tests and linters / Tests with -race (pull_request) Successful in 6m52s
All checks were successful
Tests and linters / Run gofumpt (pull_request) Successful in 2m14s
DCO action / DCO (pull_request) Successful in 2m27s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m55s
Vulncheck / Vulncheck (pull_request) Successful in 2m47s
Tests and linters / gopls check (pull_request) Successful in 3m33s
Build / Build Components (pull_request) Successful in 3m43s
Tests and linters / Staticcheck (pull_request) Successful in 3m42s
Tests and linters / Lint (pull_request) Successful in 4m34s
Tests and linters / Tests (pull_request) Successful in 6m52s
Tests and linters / Tests with -race (pull_request) Successful in 6m52s
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
5bcf81d1cc
commit
6fced12a69
4 changed files with 26 additions and 16 deletions
|
@ -128,7 +128,7 @@ func makeAndWaitNotaryDeposit(ctx context.Context, c *cfg) {
|
|||
return
|
||||
}
|
||||
|
||||
tx, err := makeNotaryDeposit(c)
|
||||
tx, vub, err := makeNotaryDeposit(c)
|
||||
fatalOnErr(err)
|
||||
|
||||
if tx.Equals(util.Uint256{}) {
|
||||
|
@ -139,11 +139,11 @@ func makeAndWaitNotaryDeposit(ctx context.Context, c *cfg) {
|
|||
return
|
||||
}
|
||||
|
||||
err = waitNotaryDeposit(ctx, c, tx)
|
||||
err = waitNotaryDeposit(ctx, c, tx, vub)
|
||||
fatalOnErr(err)
|
||||
}
|
||||
|
||||
func makeNotaryDeposit(c *cfg) (util.Uint256, error) {
|
||||
func makeNotaryDeposit(c *cfg) (util.Uint256, uint32, error) {
|
||||
const (
|
||||
// gasMultiplier defines how many times more the notary
|
||||
// balance must be compared to the GAS balance of the node:
|
||||
|
@ -157,7 +157,7 @@ func makeNotaryDeposit(c *cfg) (util.Uint256, error) {
|
|||
|
||||
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 util.Uint256{}, 0, fmt.Errorf("could not calculate notary deposit: %w", err)
|
||||
}
|
||||
|
||||
return c.cfgMorph.client.DepositEndlessNotary(depositAmount)
|
||||
|
@ -168,7 +168,7 @@ var (
|
|||
errNotaryDepositTimeout = errors.New("notary deposit tx has not appeared in the network")
|
||||
)
|
||||
|
||||
func waitNotaryDeposit(ctx context.Context, c *cfg, tx util.Uint256) error {
|
||||
func waitNotaryDeposit(ctx context.Context, c *cfg, tx util.Uint256, vub uint32) error {
|
||||
for range notaryDepositRetriesAmount {
|
||||
c.log.Debug(logs.ClientAttemptToWaitForNotaryDepositTransactionToGetPersisted)
|
||||
select {
|
||||
|
@ -191,6 +191,14 @@ func waitNotaryDeposit(ctx context.Context, c *cfg, tx util.Uint256) error {
|
|||
if err != nil {
|
||||
return fmt.Errorf("could not wait for one block in chain: %w", err)
|
||||
}
|
||||
|
||||
currHeight, err := c.cfgMorph.client.BlockCount()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not get block count in chain: %w", err)
|
||||
}
|
||||
if currHeight > vub {
|
||||
return fmt.Errorf("current block height (%d) is greater than valid until block value (%d)", currHeight, vub)
|
||||
}
|
||||
}
|
||||
|
||||
return errNotaryDepositTimeout
|
||||
|
|
|
@ -192,7 +192,7 @@ func addNewEpochNotificationHandlers(c *cfg) {
|
|||
|
||||
if c.cfgMorph.notaryEnabled {
|
||||
addNewEpochAsyncNotificationHandler(c, func(_ event.Event) {
|
||||
_, err := makeNotaryDeposit(c)
|
||||
_, _, err := makeNotaryDeposit(c)
|
||||
if err != nil {
|
||||
c.log.Error(logs.FrostFSNodeCouldNotMakeNotaryDeposit,
|
||||
zap.String("error", err.Error()),
|
||||
|
|
|
@ -40,13 +40,14 @@ func (s *Server) depositMainNotary() (tx util.Uint256, err error) {
|
|||
)
|
||||
}
|
||||
|
||||
func (s *Server) depositSideNotary() (tx util.Uint256, err error) {
|
||||
func (s *Server) depositSideNotary() (util.Uint256, error) {
|
||||
depositAmount, err := client.CalculateNotaryDepositAmount(s.morphClient, gasMultiplier, gasDivisor)
|
||||
if err != nil {
|
||||
return util.Uint256{}, fmt.Errorf("could not calculate side notary deposit amount: %w", err)
|
||||
}
|
||||
|
||||
return s.morphClient.DepositEndlessNotary(depositAmount)
|
||||
tx, _, err := s.morphClient.DepositEndlessNotary(depositAmount)
|
||||
return tx, err
|
||||
}
|
||||
|
||||
func (s *Server) notaryHandler(_ event.Event) {
|
||||
|
|
|
@ -140,7 +140,7 @@ func (c *Client) ProbeNotary() (res bool) {
|
|||
// use this function.
|
||||
//
|
||||
// This function must be invoked with notary enabled otherwise it throws panic.
|
||||
func (c *Client) DepositNotary(amount fixedn.Fixed8, delta uint32) (res util.Uint256, err error) {
|
||||
func (c *Client) DepositNotary(amount fixedn.Fixed8, delta uint32) (util.Uint256, error) {
|
||||
c.switchLock.RLock()
|
||||
defer c.switchLock.RUnlock()
|
||||
|
||||
|
@ -163,7 +163,8 @@ func (c *Client) DepositNotary(amount fixedn.Fixed8, delta uint32) (res util.Uin
|
|||
}
|
||||
|
||||
till := max(int64(bc+delta), currentTill)
|
||||
return c.depositNotary(amount, till)
|
||||
res, _, err := c.depositNotary(amount, till)
|
||||
return res, err
|
||||
}
|
||||
|
||||
// DepositEndlessNotary calls notary deposit method. Unlike `DepositNotary`,
|
||||
|
@ -171,12 +172,12 @@ func (c *Client) DepositNotary(amount fixedn.Fixed8, delta uint32) (res util.Uin
|
|||
// This allows to avoid ValidAfterDeposit failures.
|
||||
//
|
||||
// This function must be invoked with notary enabled otherwise it throws panic.
|
||||
func (c *Client) DepositEndlessNotary(amount fixedn.Fixed8) (res util.Uint256, err error) {
|
||||
func (c *Client) DepositEndlessNotary(amount fixedn.Fixed8) (util.Uint256, uint32, error) {
|
||||
c.switchLock.RLock()
|
||||
defer c.switchLock.RUnlock()
|
||||
|
||||
if c.inactive {
|
||||
return util.Uint256{}, ErrConnectionLost
|
||||
return util.Uint256{}, 0, ErrConnectionLost
|
||||
}
|
||||
|
||||
if c.notary == nil {
|
||||
|
@ -187,7 +188,7 @@ func (c *Client) DepositEndlessNotary(amount fixedn.Fixed8) (res util.Uint256, e
|
|||
return c.depositNotary(amount, math.MaxUint32)
|
||||
}
|
||||
|
||||
func (c *Client) depositNotary(amount fixedn.Fixed8, till int64) (res util.Uint256, err error) {
|
||||
func (c *Client) depositNotary(amount fixedn.Fixed8, till int64) (util.Uint256, uint32, error) {
|
||||
txHash, vub, err := c.gasToken.Transfer(
|
||||
c.accAddr,
|
||||
c.notary.notary,
|
||||
|
@ -195,7 +196,7 @@ func (c *Client) depositNotary(amount fixedn.Fixed8, till int64) (res util.Uint2
|
|||
[]any{c.acc.PrivateKey().GetScriptHash(), till})
|
||||
if err != nil {
|
||||
if !errors.Is(err, neorpc.ErrAlreadyExists) {
|
||||
return util.Uint256{}, fmt.Errorf("can't make notary deposit: %w", err)
|
||||
return util.Uint256{}, 0, fmt.Errorf("can't make notary deposit: %w", err)
|
||||
}
|
||||
|
||||
// Transaction is already in mempool waiting to be processed.
|
||||
|
@ -205,7 +206,7 @@ func (c *Client) depositNotary(amount fixedn.Fixed8, till int64) (res util.Uint2
|
|||
zap.Int64("expire_at", till),
|
||||
zap.Uint32("vub", vub),
|
||||
zap.Error(err))
|
||||
return util.Uint256{}, nil
|
||||
return util.Uint256{}, 0, nil
|
||||
}
|
||||
|
||||
c.logger.Info(logs.ClientNotaryDepositInvoke,
|
||||
|
@ -214,7 +215,7 @@ func (c *Client) depositNotary(amount fixedn.Fixed8, till int64) (res util.Uint2
|
|||
zap.Uint32("vub", vub),
|
||||
zap.Stringer("tx_hash", txHash.Reverse()))
|
||||
|
||||
return txHash, nil
|
||||
return txHash, vub, nil
|
||||
}
|
||||
|
||||
// GetNotaryDeposit returns deposit of client's account in notary contract.
|
||||
|
|
Loading…
Reference in a new issue