Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error from CalculateNonceAndVUB #3134

Conversation

End-rey
Copy link
Contributor

@End-rey End-rey commented Feb 14, 2025

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.

@End-rey End-rey self-assigned this Feb 14, 2025
@End-rey End-rey marked this pull request as draft February 14, 2025 19:01
Copy link

codecov bot commented Feb 14, 2025

Codecov Report

Attention: Patch coverage is 6.25000% with 15 lines in your changes missing coverage. Please review.

Project coverage is 23.03%. Comparing base (653d9f8) to head (0ddb375).
Report is 12 commits behind head on master.

Files with missing lines Patch % Lines
pkg/morph/client/notary.go 0.00% 8 Missing ⚠️
pkg/innerring/state.go 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3134      +/-   ##
==========================================
- Coverage   23.04%   23.03%   -0.01%     
==========================================
  Files         756      756              
  Lines       60202    60212      +10     
==========================================
- Hits        13872    13870       -2     
- Misses      45334    45345      +11     
- Partials      996      997       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@End-rey End-rey force-pushed the 3113-designation-contract-changes-are-not-reflected-in-ir-configuration branch from 2257c3c to 8fa1b74 Compare February 17, 2025 18:11
@End-rey End-rey marked this pull request as ready for review February 17, 2025 19:07
Copy link
Member

@roman-khimov roman-khimov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we somehow do this only for this special main chain case? The problem is that in the vast majority of cases the original error is more appropriate, there has to be a transaction. Maybe we can pass zero hash in this case and then fallback to this scheme without transaction height query?

Copy link
Member

@carpawell carpawell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that we need to separate this logic for events from main and FS chains. For FS chains it is a real problem if no TX found while for main it should not be even tried. TBH I even cannot say if we have any non-notary notifications from FS chain but it should not change anything, they may appear at any time, morph client was meant to be for every chain (at least it is now, without additional chages i would keep this).

@End-rey End-rey force-pushed the 3113-designation-contract-changes-are-not-reflected-in-ir-configuration branch 2 times, most recently from 3aae148 to 435f64d Compare February 19, 2025 08:00
@@ -128,7 +128,11 @@ func (s *Server) voteForFSChainValidator(validators keys.PublicKeys, trigger *ut
if trigger != nil {
nonce, vub, err = s.morphClient.CalculateNonceAndVUB(*trigger)
if err != nil {
return fmt.Errorf("could not calculate nonce and `validUntilBlock` values: %w", err)
s.log.Debug("could not calculate nonce and `validUntilBlock` values", zap.Error(err))
nonce, vub, err = s.morphClient.CalculateNonceAndVUB(util.Uint256{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commit states

... an error is returned because there is no hash in the FSchain. Ignore the error and calculate the value in another way

but we switch to zero hash on any failure. Shouldnt we check the exact case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC we should always call CalculateNonceAndVUB with util.Uint256{} in voteForFSChainValidator if trigger == nil, because the only user of this method (not counting validator predefined in config) is governance processor reacting to main chain events.

@@ -128,7 +128,11 @@ func (s *Server) voteForFSChainValidator(validators keys.PublicKeys, trigger *ut
if trigger != nil {
nonce, vub, err = s.morphClient.CalculateNonceAndVUB(*trigger)
if err != nil {
return fmt.Errorf("could not calculate nonce and `validUntilBlock` values: %w", err)
s.log.Debug("could not calculate nonce and `validUntilBlock` values", zap.Error(err))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the hash can also be useful

s.log.Debug("could not calculate nonce and `validUntilBlock` values", zap.Error(err))
nonce, vub, err = s.morphClient.CalculateNonceAndVUB(util.Uint256{})
if err != nil {
return fmt.Errorf("could not calculate nonce and `validUntilBlock` values for zero hash: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about wrapping both errors?

@@ -128,7 +128,11 @@ func (s *Server) voteForFSChainValidator(validators keys.PublicKeys, trigger *ut
if trigger != nil {
nonce, vub, err = s.morphClient.CalculateNonceAndVUB(*trigger)
if err != nil {
return fmt.Errorf("could not calculate nonce and `validUntilBlock` values: %w", err)
s.log.Debug("could not calculate nonce and `validUntilBlock` values", zap.Error(err))
nonce, vub, err = s.morphClient.CalculateNonceAndVUB(util.Uint256{})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC we should always call CalculateNonceAndVUB with util.Uint256{} in voteForFSChainValidator if trigger == nil, because the only user of this method (not counting validator predefined in config) is governance processor reacting to main chain events.

@End-rey End-rey force-pushed the 3113-designation-contract-changes-are-not-reflected-in-ir-configuration branch from 435f64d to b1cfbb4 Compare February 19, 2025 14:26
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. So for designation event of the mainnet RoleManagement contract
transaction hash is set to zero.
`CalculateNonceAndVUB` can now handle zero hashes and calculate vub rounded.

Signed-off-by: Andrey Butusov <[email protected]>
Signed-off-by: Andrey Butusov <[email protected]>
@End-rey End-rey force-pushed the 3113-designation-contract-changes-are-not-reflected-in-ir-configuration branch from b1cfbb4 to 0ddb375 Compare February 19, 2025 18:32
@End-rey
Copy link
Contributor Author

End-rey commented Feb 19, 2025

Designation event of the mainnet RoleManagement contract contains a hash from the main chain, so I just made it zero, so that later it calculated vub as for the zero hash. Did I get it right?

@@ -40,6 +40,6 @@ func ParseDesignate(e *state.ContainedNotificationEvent) (event.Event, error) {

return Designate{
Role: noderoles.Role(bi.Int64()),
TxHash: e.Container,
TxHash: util.Uint256{},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not excited about this one because I'd expect this "real->fake" translation at some other layer dealing with the event. But it should work.

@roman-khimov roman-khimov merged commit d540de0 into master Feb 20, 2025
20 of 22 checks passed
@roman-khimov roman-khimov deleted the 3113-designation-contract-changes-are-not-reflected-in-ir-configuration branch February 20, 2025 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants