Skip to content

Commit

Permalink
morph: fix error from CalculateNonceAndVUB
Browse files Browse the repository at this point in the history
The alphabetic key change event comes from the main chain with its hash, and
when calculating vub, an error is returned because there is no hash in the FS
chain. Ignore the error and calculate the value in another way.

Signed-off-by: Andrey Butusov <[email protected]>
  • Loading branch information
End-rey committed Feb 19, 2025
1 parent 653d9f8 commit b1cfbb4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Changelog for NeoFS Node
- `neofs_node_engine_list_objects_time_bucket` metric (#3120)
- The correct role parameter to invocation (#3127)
- nil pointer error for `storage sanity` command (#3151)
- Calculation of VUB when it is impossible to get the transaction height (#3134)

### Changed
- Number of cuncurrenly handled notifications from the chain was increased from 10 to 300 for IR (#3068)
Expand Down
4 changes: 2 additions & 2 deletions pkg/innerring/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ func (s *Server) voteForFSChainValidator(validators keys.PublicKeys, trigger *ut
)

if trigger != nil {
nonce, vub, err = s.morphClient.CalculateNonceAndVUB(*trigger)
nonce, vub, err = s.morphClient.CalculateNonceAndVUBWithFallback(*trigger)

Check warning on line 129 in pkg/innerring/state.go

View check run for this annotation

Codecov / codecov/patch

pkg/innerring/state.go#L129

Added line #L129 was not covered by tests
if err != nil {
return fmt.Errorf("could not calculate nonce and `validUntilBlock` values: %w", err)
return err

Check warning on line 131 in pkg/innerring/state.go

View check run for this annotation

Codecov / codecov/patch

pkg/innerring/state.go#L131

Added line #L131 was not covered by tests
}
vubP = &vub
}
Expand Down
41 changes: 36 additions & 5 deletions pkg/morph/client/notary.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ const (
)

var errUnexpectedItems = errors.New("invalid number of NEO VM arguments on stack")
var errNoTxHeight = errors.New("could not get transaction height")
var errNonceVubCalculation = errors.New("could not calculate nonce and validUntilBlock values")

func defaultNotaryConfig(c *Client) *notaryCfg {
return &notaryCfg{
Expand Down Expand Up @@ -266,9 +268,9 @@ func (c *Client) UpdateNotaryList(notaries keys.PublicKeys, txHash util.Uint256)
panic(notaryNotEnabledPanicMsg)
}

nonce, vub, err := c.CalculateNonceAndVUB(txHash)
nonce, vub, err := c.CalculateNonceAndVUBWithFallback(txHash)

Check warning on line 271 in pkg/morph/client/notary.go

View check run for this annotation

Codecov / codecov/patch

pkg/morph/client/notary.go#L271

Added line #L271 was not covered by tests
if err != nil {
return fmt.Errorf("could not calculate nonce and `valicUntilBlock` values: %w", err)
return err

Check warning on line 273 in pkg/morph/client/notary.go

View check run for this annotation

Codecov / codecov/patch

pkg/morph/client/notary.go#L273

Added line #L273 was not covered by tests
}

return c.notaryInvokeAsCommittee(
Expand All @@ -290,9 +292,9 @@ func (c *Client) UpdateNeoFSAlphabetList(alphas keys.PublicKeys, txHash util.Uin
panic(notaryNotEnabledPanicMsg)
}

nonce, vub, err := c.CalculateNonceAndVUB(txHash)
nonce, vub, err := c.CalculateNonceAndVUBWithFallback(txHash)

Check warning on line 295 in pkg/morph/client/notary.go

View check run for this annotation

Codecov / codecov/patch

pkg/morph/client/notary.go#L295

Added line #L295 was not covered by tests
if err != nil {
return fmt.Errorf("could not calculate nonce and `valicUntilBlock` values: %w", err)
return err

Check warning on line 297 in pkg/morph/client/notary.go

View check run for this annotation

Codecov / codecov/patch

pkg/morph/client/notary.go#L297

Added line #L297 was not covered by tests
}

return c.notaryInvokeAsCommittee(
Expand Down Expand Up @@ -767,9 +769,17 @@ func (c *Client) CalculateNonceAndVUB(hash util.Uint256) (nonce uint32, vub uint

nonce = binary.LittleEndian.Uint32(hash.BytesLE())

if hash.Equals(util.Uint256{}) {
c.logger.Debug("get zero hash to calculate nonce and vub")
vub, err = c.notaryTxValidationLimit(conn)
if err != nil {
return 0, 0, fmt.Errorf("could not get vub validation limit: %w", err)
}
return nonce, vub, nil

Check warning on line 778 in pkg/morph/client/notary.go

View check run for this annotation

Codecov / codecov/patch

pkg/morph/client/notary.go#L772-L778

Added lines #L772 - L778 were not covered by tests
}
height, err := c.getTransactionHeight(conn, hash)
if err != nil {
return 0, 0, fmt.Errorf("could not get transaction height: %w", err)
return 0, 0, fmt.Errorf("%w: %w", errNoTxHeight, err)

Check warning on line 782 in pkg/morph/client/notary.go

View check run for this annotation

Codecov / codecov/patch

pkg/morph/client/notary.go#L782

Added line #L782 was not covered by tests
}

return nonce, height + c.notary.txValidTime, nil
Expand All @@ -786,3 +796,24 @@ func (c *Client) getTransactionHeight(conn *connection, h util.Uint256) (uint32,
c.cache.txHeights.Add(h, height)
return height, nil
}

// CalculateNonceAndVUB calculates nonce and ValidUntilBlock values
// based on transaction hash, and if it cannot get transaction height,
// then it calculates alternatively rounded.
func (c *Client) CalculateNonceAndVUBWithFallback(hash util.Uint256) (nonce uint32, vub uint32, err error) {
nonce, vub, err = c.CalculateNonceAndVUB(hash)
if err != nil {
if !errors.Is(err, errNoTxHeight) {
return 0, 0, fmt.Errorf("%w: %w", errNonceVubCalculation, err)
}

Check warning on line 808 in pkg/morph/client/notary.go

View check run for this annotation

Codecov / codecov/patch

pkg/morph/client/notary.go#L803-L808

Added lines #L803 - L808 were not covered by tests

c.logger.Debug(errNonceVubCalculation.Error(), zap.Error(err), zap.Stringer("hash", hash))
var err2 error
nonce, vub, err2 = c.CalculateNonceAndVUB(util.Uint256{})
if err2 != nil {
return 0, 0, fmt.Errorf("%w for %s: %w. And for zero hash: %w", errNonceVubCalculation, hash.String(), err, err2)
}

Check warning on line 815 in pkg/morph/client/notary.go

View check run for this annotation

Codecov / codecov/patch

pkg/morph/client/notary.go#L810-L815

Added lines #L810 - L815 were not covered by tests
}

return nonce, vub, nil

Check warning on line 818 in pkg/morph/client/notary.go

View check run for this annotation

Codecov / codecov/patch

pkg/morph/client/notary.go#L818

Added line #L818 was not covered by tests
}

0 comments on commit b1cfbb4

Please sign in to comment.