Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

disputes: fix relay chain selection sanity check #3750

Merged
5 commits merged into from
Sep 1, 2021

Conversation

drahnr
Copy link
Contributor

@drahnr drahnr commented Aug 31, 2021

  • adjust tests

@ordian
Copy link
Member

ordian commented Aug 31, 2021

duplicate of #3749

@Lldenaurois Lldenaurois added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit. labels Aug 31, 2021
@Lldenaurois Lldenaurois self-requested a review August 31, 2021 14:56
@Lldenaurois
Copy link
Contributor

I've burned in this on Roccoco, and the warnings immediately disappeared:

https://grafana.parity-mgmt.parity.io/goto/9tpTG147z?orgId=1

@ordian ordian linked an issue Aug 31, 2021 that may be closed by this pull request
@ordian
Copy link
Member

ordian commented Aug 31, 2021

It would be good to add a comment why the sanity check has this +-1

@drahnr drahnr changed the title disputes: fix relay chain selection sanity check DO NOT MERGE - disputes: fix relay chain selection sanity check Aug 31, 2021
@Lldenaurois Lldenaurois force-pushed the bernhard-fix-relay-chain-sel-check branch from 0d24180 to 77b3527 Compare September 1, 2021 03:55
@Lldenaurois
Copy link
Contributor

Lldenaurois commented Sep 1, 2021

Good morning gents...

I stayed up all night and fixed the issue.

There were a few things wrong, but the main one was actually a bug in the fn handle_approved_ancestor logic in approval voting. In that function, we would clear the descriptions after every unapproved block, but we wouldn't actually continue thereafter`, meaning we would push one description after every unapproved block.

Therefore, if all blocks are approved, the sanity check is correct as it is in master; but if the tip is unapproved, the sanity-check is off by one and we need to make the adjustment above.

After realizing this, I realized that the logic was somewhat copy/pasted into the fn highest_approved_ancestors(...) function in the service tests, so it needed to be adjusted there as well.

After that I just had to fix the tests to reflect the fact that the min_block_number is the BlockNumber of the target block, and that the fn undisputed_chain(...) function takes a leaf as an argument, rather than an approved ancestor.

Copy link
Contributor

@Lldenaurois Lldenaurois left a comment

Choose a reason for hiding this comment

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

Added a few comments to explain my reasoning

node/core/approval-voting/src/lib.rs Show resolved Hide resolved
node/service/src/tests.rs Show resolved Hide resolved
@@ -521,7 +508,7 @@ fn chain_0() -> CaseVars {

let a1 = builder.fast_forward_approved(0xA0, head, 1);
let a2 = builder.fast_forward_approved(0xA0, a1, 2);
let a3 = builder.fast_forward_approved(0xA0, a2, 3);
let a3 = builder.fast_forward_disputed(0xA0, a2, 3);
Copy link
Contributor

Choose a reason for hiding this comment

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

If 0xA3 is not disputed, then it is automatically undisputed_chain, since chain.disputes.is_empty() == true. However, this is contrary to the expectation that 0xA2 is the undisputed_chain.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as before, I'd prefer to keep the test case input the same as before, if there is a need for additional ones, C&P :)

node/service/src/tests.rs Show resolved Hide resolved
);

let expected = chain.undisputed_chain(
target_blocknumber,
Copy link
Contributor

Choose a reason for hiding this comment

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

Undisputed chain computes the parent of the first dispute after the target block. If there is no dispute after the target block, then highest_approved_ancestor == expected.

node/service/src/tests.rs Outdated Show resolved Hide resolved
Copy link
Member

@ordian ordian left a comment

Choose a reason for hiding this comment

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

I believe this is the correct fix considering #3484 (comment), block_descriptions should only represent fully approved range of blocks with no gaps.

@drahnr drahnr changed the title DO NOT MERGE - disputes: fix relay chain selection sanity check disputes: fix relay chain selection sanity check Sep 1, 2021
Copy link
Contributor Author

@drahnr drahnr left a comment

Choose a reason for hiding this comment

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

LGTM 👍 , since I opened the PR initially, I cannot approve. Had a call with @Lldenaurois to walk me through the details, thanks!

Copy link
Member

@eskimor eskimor left a comment

Choose a reason for hiding this comment

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

LGTM

node/service/src/tests.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
@ordian
Copy link
Member

ordian commented Sep 1, 2021

bot merge

@ghost
Copy link

ghost commented Sep 1, 2021

Waiting for commit status.

@ghost
Copy link

ghost commented Sep 1, 2021

Merge aborted: Head SHA changed from f7d891e to e4471f7

@ordian
Copy link
Member

ordian commented Sep 1, 2021

bot merge

@ghost
Copy link

ghost commented Sep 1, 2021

Waiting for commit status.

@ghost ghost merged commit 4764ec7 into master Sep 1, 2021
@ghost ghost deleted the bernhard-fix-relay-chain-sel-check branch September 1, 2021 16:09
ordian added a commit that referenced this pull request Sep 2, 2021
* master:
  dependabot: ignore yet another git dep (#3759)
  Bump serde_json from 1.0.66 to 1.0.67 (#3767)
  Bump syn from 1.0.74 to 1.0.75 (#3710)
  Companion for substrate #9371 (#3487)
  Fixes/improvements for disputes (#3753)
  chore: test helper arbitrary ordering for 2 (#3762)
  disputes: fix relay chain selection sanity check (#3750)
  technical committee is using the weight of council, but should have its own generated weight instead (#3511)
  new proxy for auctions, crowdloans, registrar, slots (#3683)
  Bump libc from 0.2.100 to 0.2.101 (#3726)
  Removed unneeded deps (#3658)
  Bump serde from 1.0.127 to 1.0.130 (#3739)
  Companion for Generate storage info for pallet authority_discovery #9428 (#3517)
  Return a Result in invert_location (#3730)
  XCM: Allow reclaim of assets dropped from holding (#3727)
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix off-by-one in expected approved block-descriptions
4 participants