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

Move proof generation to the type system level #8185

Merged
5 commits merged into from Feb 24, 2021
Merged

Conversation

bkchr
Copy link
Member

@bkchr bkchr commented Feb 23, 2021

This pr changes the way proof generation can be requested when building a block with Proposer. Instead of passing RecordProof::Yes to every call of propose, this pr changes it to either always record the proof or never for a specific implementation of Proposer. Up to now there is was no middle way of "now we need a proof" and "now we don't need a proof". It was always either one of this.

The main advantage of moving this to the type system level is that we can write code Proposer<B, ProofRecording = EnableProofRecording>. Meaning we will only accept proposer implementations that will generate a proof. This is quite useful for Cumulus and for people who will be using Cumulus, to make it complain at compile time that the proposer is not correct.

The basic authorship ProposerFactory and Proposer are now written in a way to make them usable for proof recording or for no proof recording.

polkadot companion: paritytech/polkadot#2507

@bkchr bkchr 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. labels Feb 23, 2021
bkchr added a commit to paritytech/polkadot that referenced this pull request Feb 23, 2021
client/basic-authorship/src/basic_authorship.rs Outdated Show resolved Hide resolved
@@ -91,7 +117,7 @@ impl<A, B, C> ProposerFactory<A, B, C> {
}
}

impl<B, Block, C, A> ProposerFactory<A, B, C>
impl<B, Block, C, A, RP> ProposerFactory<A, B, C, RP>
Copy link
Member

Choose a reason for hiding this comment

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

nitpick I guess this is named RP from RecordProof but probably PR would be better (ProofRecording).

Copy link
Member Author

Choose a reason for hiding this comment

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

Ha! Before I renamed the trait over the lifetime of this pr :D

bkchr and others added 2 commits February 24, 2021 14:09
Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
Copy link
Contributor

@cheme cheme left a comment

Choose a reason for hiding this comment

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

LGTM, a few nit and questions.

primitives/consensus/common/src/lib.rs Show resolved Hide resolved
/// required. The only two implementations of this trait are [`DisableProofRecording`] and
/// [`EnableProofRecording`].
///
/// This trait is sealed and can not be implemented outside of this crate!
Copy link
Contributor

Choose a reason for hiding this comment

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

Would allowing external implementation be an issue?

Copy link
Member Author

Choose a reason for hiding this comment

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

For now I don't see any reason to allow this to change from the outside. Maybe in the future when there is a reason to change the proof type.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was a bit curious, but it is harmless anyway.

primitives/consensus/common/src/lib.rs Show resolved Hide resolved
@@ -170,7 +170,6 @@ impl core::Benchmark for ConstructionBenchmark {
inherent_data_providers.create_inherent_data().expect("Create inherent data failed"),
Default::default(),
std::time::Duration::from_secs(20),
RecordProof::Yes,
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it switch the bench to not recording (shouldn't we use proposerfactory::with_proof_recording)?

Copy link
Member Author

Choose a reason for hiding this comment

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

There is no reason this ever used proof recording.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know, maybe this was using proof recording on purpose to have worst case scenario bench, but I really don't know.

@@ -611,7 +610,6 @@ mod tests {
inherent_data,
digest,
std::time::Duration::from_secs(1),
RecordProof::Yes,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same, with_proof_recording for proposer factory?

Copy link
Member Author

Choose a reason for hiding this comment

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

Same

@bkchr
Copy link
Member Author

bkchr commented Feb 24, 2021

bot merge

@ghost
Copy link

ghost commented Feb 24, 2021

Trying merge.

@ghost ghost merged commit 7a6d60d into master Feb 24, 2021
@ghost ghost deleted the bkchr-proposer-stuff branch February 24, 2021 20:43
bkchr added a commit to paritytech/polkadot that referenced this pull request Feb 24, 2021
* Companion for Substrate #8185

paritytech/substrate#8185

* "Update Substrate"

Co-authored-by: parity-processbot <>
jam10o-new pushed a commit to jam10o-new/substrate that referenced this pull request Feb 28, 2021
* Start

* Finish!!!!

* Update client/basic-authorship/src/basic_authorship.rs

Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>

* Review comments

Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
bkchr added a commit to paritytech/polkadot that referenced this pull request Mar 4, 2021
* Companion for Substrate #8185

paritytech/substrate#8185

* "Update Substrate"

Co-authored-by: parity-processbot <>
KalitaAlexey pushed a commit to KalitaAlexey/substrate that referenced this pull request Jul 9, 2021
* Start

* Finish!!!!

* Update client/basic-authorship/src/basic_authorship.rs

Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>

* Review comments

Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants