@@ -65,6 +65,8 @@ const (
65
65
)
66
66
67
67
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" )
68
70
69
71
func defaultNotaryConfig (c * Client ) * notaryCfg {
70
72
return & notaryCfg {
@@ -266,9 +268,9 @@ func (c *Client) UpdateNotaryList(notaries keys.PublicKeys, txHash util.Uint256)
266
268
panic (notaryNotEnabledPanicMsg )
267
269
}
268
270
269
- nonce , vub , err := c .CalculateNonceAndVUB (txHash )
271
+ nonce , vub , err := c .CalculateNonceAndVUBWithFallback (txHash )
270
272
if err != nil {
271
- return fmt . Errorf ( "could not calculate nonce and `valicUntilBlock` values: %w" , err )
273
+ return err
272
274
}
273
275
274
276
return c .notaryInvokeAsCommittee (
@@ -290,9 +292,9 @@ func (c *Client) UpdateNeoFSAlphabetList(alphas keys.PublicKeys, txHash util.Uin
290
292
panic (notaryNotEnabledPanicMsg )
291
293
}
292
294
293
- nonce , vub , err := c .CalculateNonceAndVUB (txHash )
295
+ nonce , vub , err := c .CalculateNonceAndVUBWithFallback (txHash )
294
296
if err != nil {
295
- return fmt . Errorf ( "could not calculate nonce and `valicUntilBlock` values: %w" , err )
297
+ return err
296
298
}
297
299
298
300
return c .notaryInvokeAsCommittee (
@@ -767,9 +769,17 @@ func (c *Client) CalculateNonceAndVUB(hash util.Uint256) (nonce uint32, vub uint
767
769
768
770
nonce = binary .LittleEndian .Uint32 (hash .BytesLE ())
769
771
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
+ }
770
780
height , err := c .getTransactionHeight (conn , hash )
771
781
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 )
773
783
}
774
784
775
785
return nonce , height + c .notary .txValidTime , nil
@@ -786,3 +796,24 @@ func (c *Client) getTransactionHeight(conn *connection, h util.Uint256) (uint32,
786
796
c .cache .txHeights .Add (h , height )
787
797
return height , nil
788
798
}
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