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

Set uncles inherent#3317

Merged
arkpar merged 7 commits intomasterfrom
a-uncles
Aug 7, 2019
Merged

Set uncles inherent#3317
arkpar merged 7 commits intomasterfrom
a-uncles

Conversation

@arkpar
Copy link
Member

@arkpar arkpar commented Aug 6, 2019

Closes #2956

Inherent data is populated with all possible uncles for the best block. When authoring this list is additionally filtered to remove all uncles that the runtime considers invalid.
There a small issue with this implementation. Currently inherents are populated before the block to propose on is chosen. If canonical block changes after uncles are collected we might end up with no uncles included for this block.

@arkpar arkpar requested a review from rphmeier August 6, 2019 22:36
@arkpar arkpar added the A0-please_review Pull request needs code review. label Aug 6, 2019
/// filter.
fn filter_uncle(header: &Header, acc: Self::Accumulator)
-> Result<(Option<Author>, Self::Accumulator), &'static str>;
fn filter_uncle(header: &Header, acc: &mut Self::Accumulator)
Copy link
Member Author

Choose a reason for hiding this comment

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

Changed acc to be a mutable reference because we also need it in case of error so that filtering might be able to skip invalid uncle and continue. Returning acc for both Ok and Err results is way less readable and more verbose code.

Client::uncles(self, target_hash, max_generation)?
.into_iter()
.map(|hash| Client::header(self, &BlockId::Hash(hash))
.map(|maybe_header| maybe_header.expect("Each uncle exists in the database; qed")))
Copy link
Contributor

Choose a reason for hiding this comment

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

it would be much safer to filter_map. this expectation doesn't prove to me why the uncle will exist (in the future, it might race against block pruning or something similar)

pub use babe_primitives::AuthorityId;

/// Maximum uncles generations we may provide to the runtime.
const MAX_UNCLE_GENERATIONS: u32 = 8;
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be drawn from the runtime instead

Copy link
Member Author

Choose a reason for hiding this comment

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

Runtime calls are expensive. And this will be called for each block verification. My reasoning is that it is better to pick a hard limit, pass a few extra headers and let the runtime sort it out later rather than make another call into WASM.

Copy link
Contributor

@rphmeier rphmeier Aug 7, 2019

Choose a reason for hiding this comment

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

it will be called for every block creation only. but yeah, this is fine for now. The downside is that we'll do extra work looking for uncles and can't support more than 8 generations. This will be a barrier to having ultra-fast block time chains.

Copy link
Member Author

Choose a reason for hiding this comment

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

From what I see InherentData is populated for verification as well.

}

/// Register uncles inherent data provider, if not registered already.
fn register_uncles_inherent_data_provider<B, C, SC>(
Copy link
Contributor

Choose a reason for hiding this comment

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

putting this in the BABE crate doesn't seem right - other block production systems will also want uncles


if duplicate || in_chain { return Err("uncle already included") }
fn create_inherent(data: &InherentData) -> Option<Self::Call> {
let uncles = data.uncles().expect("Gets and decodes final number inherent data");
Copy link
Contributor

Choose a reason for hiding this comment

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

panicking here is wrong

Copy link
Member Author

Choose a reason for hiding this comment

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

Panic happens when the data has invalid encoding, not when it is missing.

Copy link
Contributor

@rphmeier rphmeier Aug 7, 2019

Choose a reason for hiding this comment

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

yes. still wrong IMO. what proves that the data will have correct encoding?

you could maybe make a case that the provider provides data that's correct, but it's a far-reaching assumption, since it can be broken by a change in provider implementation later.

since it can't be proven that the correct data is supplied, the panicker should be removed

Copy link
Contributor

@rphmeier rphmeier left a comment

Choose a reason for hiding this comment

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

looks good except for grumbles

@arkpar arkpar added A3-in_progress Pull request is in progress. No review needed at this stage. and removed A0-please_review Pull request needs code review. labels Aug 7, 2019
@arkpar arkpar added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Aug 7, 2019
@arkpar arkpar requested a review from rphmeier August 7, 2019 10:45
@gavofyork gavofyork added A7-looksgoodcantmerge and removed A0-please_review Pull request needs code review. labels Aug 7, 2019
@arkpar arkpar merged commit d6eb5dd into master Aug 7, 2019
@arkpar arkpar deleted the a-uncles branch August 7, 2019 22:56
kianenigma pushed a commit that referenced this pull request Aug 9, 2019
* Include uncles

* Filter missing uncles

* Moved inherent registration to a new crate

* Ignore invalid inherent encoding
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Actually construct the Authorship::set_uncles inherent

4 participants