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

Dispute-coordinator: fix underflow panic #4557

Merged
merged 3 commits into from
Dec 20, 2021

Conversation

slumber
Copy link
Contributor

@slumber slumber commented Dec 17, 2021

Resolves #4554

skip check-dependent-cumulus

@slumber slumber added F1-panic A0-please_review Pull request needs code review. 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 Dec 17, 2021
@slumber slumber added the B0-silent Changes should not be mentioned in any release notes label Dec 17, 2021
if idx == 0 {
// Return zero hash for the genesis block -- the same way
// Chain API does.
vec![Hash::zero()]
Copy link
Contributor

@drahnr drahnr Dec 18, 2021

Choose a reason for hiding this comment

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

I am not convinced that this is sane. What would we ever do withthe zero hash? The genesis should not return ancestors, not a garbage one. The bug is in ancestry.

Copy link
Member

Choose a reason for hiding this comment

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

I agree, although a check that we won't ever underflow at genesis is not a bad idea.

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.

Maybe remove the comment with regards to chain api (we should fix it), but instead add a comment check we are not underflowing at genesis, no matter what.

node/core/dispute-coordinator/src/real/ordering/mod.rs Outdated Show resolved Hide resolved
if idx == 0 {
// Return zero hash for the genesis block -- the same way
// Chain API does.
vec![Hash::zero()]
Copy link
Member

Choose a reason for hiding this comment

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

I agree, although a check that we won't ever underflow at genesis is not a bad idea.

@ordian
Copy link
Member

ordian commented Dec 18, 2021

is this obsolete by fixing the chain-api instead?

@slumber
Copy link
Contributor Author

slumber commented Dec 18, 2021

is this obsolete by fixing the chain-api instead?

It's a good thing to check for underflow anyway, also could use this branch to add some early returns when looking for ancestors is not necessary.

Comment on lines +282 to +295
let earliest_block_number = match head_number.checked_sub(hashes.len() as u32) {
Some(number) => number,
None => {
// It's assumed that it's impossible to retrieve
// more than N ancestors for block number N.
tracing::error!(
target: LOG_TARGET,
"Received {} ancestors for block number {} from Chain API",
hashes.len(),
head_number,
);
return Ok(ancestors)
},
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doing saturated_sub is bad since we will have invalid block number for the next iteration in case of underflow, so it's best to assume this is unreachable.

head_number,
);
return Ok(ancestors)
},
Copy link
Member

Choose a reason for hiding this comment

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

It is a bit weird to return Ok for an error in a function returning Result.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This branch is considered to be unreachable, so we log this at error level and return valid ancestors that we managed to fetch.
It does feel weird but still better than introducing an error variant for the match arm that can only happen in case of a bug in chain API

Copy link
Member

Choose a reason for hiding this comment

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

We actually have a quite a lot of those (errors that should actually be unreachable), but you have a point.

@eskimor
Copy link
Member

eskimor commented Dec 20, 2021

bot merge

@paritytech-processbot
Copy link

Error:
Error: When trying to meet the "Project Owners" approval requirements: this pull request does not belong to a project defined in Process.json.

Approval by "Project Owners" is only attempted if other means defined in the criteria for merge are not satisfied first.

The following errors might have affected the outcome of this attempt:

  • 'Batch: Availability and Validity' does not match any projects in polkadot's Process.json
  • 'Batch: Codebase Restructure' does not match any projects in polkadot's Process.json

Merge failed. Check out the criteria for merge. If you're not meeting the approval count, check if the approvers are members of substrateteamleads or core-devs.

@drahnr
Copy link
Contributor

drahnr commented Dec 20, 2021

bot merge

@paritytech-processbot
Copy link

Waiting for commit status.

@paritytech-processbot
Copy link

Merge cancelled due to error. Error: Checks failed for 0ac80cc

@drahnr drahnr merged commit 1c62880 into master Dec 20, 2021
@drahnr drahnr deleted the slumber-ordering-provider-panic branch December 20, 2021 10:52
ordian added a commit that referenced this pull request Dec 20, 2021
* master:
  dispute-coordinator: fix underflow panic (#4557)
  Bump futures from 0.3.18 to 0.3.19 (#4567)
  Bump lru from 0.7.0 to 0.7.1 (#4566)
  Update Polkadot (#4561)
  Suggest installing graphviz before book building (#4565)
  [Zombienet] fix test creds (#4562)
  chain-api: stop ancestors lookup at block #0 (#4560)
  use v1.0.2 of zombienet (#4553)
  remove invalid dispute subsystem replace (#4559)
  Bump hyper from 0.14.15 to 0.14.16 (#4550)
  Create a README for XCMv2 detailing notable changes (#4059)
  enable disputes for known chains, except for polkadot (#4464)
  dispute statements node side limiting (#4541)
  Bump serde from 1.0.131 to 1.0.132 (#4551)
  Bump nix from 0.23.0 to 0.23.1 (#4552)
  Dispute coordinator: look for included candidates in non-finalized chain (#4508)
drahnr pushed a commit that referenced this pull request Jan 4, 2022
Wizdave97 pushed a commit to ComposableFi/polkadot that referenced this pull request Feb 3, 2022
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.

Node panic at startup
4 participants