Skip to content

Commit b1cfbb4

Browse files
committed
morph: fix error from CalculateNonceAndVUB
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]>
1 parent 653d9f8 commit b1cfbb4

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Changelog for NeoFS Node
2525
- `neofs_node_engine_list_objects_time_bucket` metric (#3120)
2626
- The correct role parameter to invocation (#3127)
2727
- nil pointer error for `storage sanity` command (#3151)
28+
- Calculation of VUB when it is impossible to get the transaction height (#3134)
2829

2930
### Changed
3031
- Number of cuncurrenly handled notifications from the chain was increased from 10 to 300 for IR (#3068)

pkg/innerring/state.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ func (s *Server) voteForFSChainValidator(validators keys.PublicKeys, trigger *ut
126126
)
127127

128128
if trigger != nil {
129-
nonce, vub, err = s.morphClient.CalculateNonceAndVUB(*trigger)
129+
nonce, vub, err = s.morphClient.CalculateNonceAndVUBWithFallback(*trigger)
130130
if err != nil {
131-
return fmt.Errorf("could not calculate nonce and `validUntilBlock` values: %w", err)
131+
return err
132132
}
133133
vubP = &vub
134134
}

pkg/morph/client/notary.go

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ const (
6565
)
6666

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

6971
func defaultNotaryConfig(c *Client) *notaryCfg {
7072
return &notaryCfg{
@@ -266,9 +268,9 @@ func (c *Client) UpdateNotaryList(notaries keys.PublicKeys, txHash util.Uint256)
266268
panic(notaryNotEnabledPanicMsg)
267269
}
268270

269-
nonce, vub, err := c.CalculateNonceAndVUB(txHash)
271+
nonce, vub, err := c.CalculateNonceAndVUBWithFallback(txHash)
270272
if err != nil {
271-
return fmt.Errorf("could not calculate nonce and `valicUntilBlock` values: %w", err)
273+
return err
272274
}
273275

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

293-
nonce, vub, err := c.CalculateNonceAndVUB(txHash)
295+
nonce, vub, err := c.CalculateNonceAndVUBWithFallback(txHash)
294296
if err != nil {
295-
return fmt.Errorf("could not calculate nonce and `valicUntilBlock` values: %w", err)
297+
return err
296298
}
297299

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

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

772+
if hash.Equals(util.Uint256{}) {
773+
c.logger.Debug("get zero hash to calculate nonce and vub")
774+
vub, err = c.notaryTxValidationLimit(conn)
775+
if err != nil {
776+
return 0, 0, fmt.Errorf("could not get vub validation limit: %w", err)
777+
}
778+
return nonce, vub, nil
779+
}
770780
height, err := c.getTransactionHeight(conn, hash)
771781
if err != nil {
772-
return 0, 0, fmt.Errorf("could not get transaction height: %w", err)
782+
return 0, 0, fmt.Errorf("%w: %w", errNoTxHeight, err)
773783
}
774784

775785
return nonce, height + c.notary.txValidTime, nil
@@ -786,3 +796,24 @@ func (c *Client) getTransactionHeight(conn *connection, h util.Uint256) (uint32,
786796
c.cache.txHeights.Add(h, height)
787797
return height, nil
788798
}
799+
800+
// CalculateNonceAndVUB calculates nonce and ValidUntilBlock values
801+
// based on transaction hash, and if it cannot get transaction height,
802+
// then it calculates alternatively rounded.
803+
func (c *Client) CalculateNonceAndVUBWithFallback(hash util.Uint256) (nonce uint32, vub uint32, err error) {
804+
nonce, vub, err = c.CalculateNonceAndVUB(hash)
805+
if err != nil {
806+
if !errors.Is(err, errNoTxHeight) {
807+
return 0, 0, fmt.Errorf("%w: %w", errNonceVubCalculation, err)
808+
}
809+
810+
c.logger.Debug(errNonceVubCalculation.Error(), zap.Error(err), zap.Stringer("hash", hash))
811+
var err2 error
812+
nonce, vub, err2 = c.CalculateNonceAndVUB(util.Uint256{})
813+
if err2 != nil {
814+
return 0, 0, fmt.Errorf("%w for %s: %w. And for zero hash: %w", errNonceVubCalculation, hash.String(), err, err2)
815+
}
816+
}
817+
818+
return nonce, vub, nil
819+
}

0 commit comments

Comments
 (0)