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

Allow BabeConsensusDataProvider fork existing chain #7078

Merged
merged 6 commits into from
Nov 4, 2020

Conversation

seunlanlege
Copy link
Contributor

This allows BabeConsensusDataProvider build blocks on top of an existing chain where the Alice key isn't part of the authorities.

@seunlanlege seunlanlege added the A0-please_review Pull request needs code review. label Sep 10, 2020
@seunlanlege seunlanlege changed the title Seun babe manual seal Allow BabeConsensusDataProvider fork existing chain Sep 10, 2020
@seunlanlege seunlanlege added the C1-low PR touches the given topic and has a low impact on builders. label Sep 10, 2020
Copy link
Contributor

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

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

Looks reasonable. Again the context here is to be able to create "fake" babe blocks in the test environment with ManualSeal.

client/consensus/babe/src/lib.rs Outdated Show resolved Hide resolved
client/consensus/babe/src/aux_schema.rs Outdated Show resolved Hide resolved
client/consensus/babe/src/aux_schema.rs Outdated Show resolved Hide resolved
client/consensus/manual-seal/src/consensus/babe.rs Outdated Show resolved Hide resolved
client/consensus/manual-seal/src/consensus/babe.rs Outdated Show resolved Hide resolved
client/consensus/manual-seal/src/consensus/babe.rs Outdated Show resolved Hide resolved
client/consensus/manual-seal/src/consensus/babe.rs Outdated Show resolved Hide resolved
client/consensus/manual-seal/src/consensus/babe.rs Outdated Show resolved Hide resolved
@@ -408,6 +408,105 @@ pub trait Misc {
}
}

/// for times you want your chain to be useless
#[runtime_interface]
pub trait UselessCrypto {
Copy link
Member

Choose a reason for hiding this comment

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

Ideally this should not live in Substrate.

If it needs to live in Substrate, it should go into a different crate. Where it is directly understandable that this is for testing.

@@ -460,7 +498,8 @@ pub trait Crypto {
msg: &[u8],
pub_key: &ed25519::Public,
) -> bool {
ed25519::Pair::verify(sig, msg, pub_key)
// ed25519::Pair::verify(sig, msg, pub_key)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please change the state of this PR to Draft since it seems it's being used to experiment with stuff and for sure is not ready to be merged to Substrate.

@seunlanlege seunlanlege marked this pull request as draft September 22, 2020 11:58
@@ -97,6 +99,7 @@ impl<Block: traits::Block> Default for ExecutionExtensions<Block> {
Self {
strategies: Default::default(),
keystore: None,
crypto_extension: RwLock::new(Arc::new(DefaultCryptoImpl)),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it shouldn't be required since it's going to be rarely customized. We should either add it not as an extension but rather to Externalities trait (with default sane implementations) or we should allow overriding via extensions_factory - i.e. we register the default extension only if it's not present in the Extensions returned by extensions_factory invocation.

Copy link
Contributor

@tomusdrw tomusdrw 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 to me, @bkchr could you take a look? I remember you didn't like the idea of putting crypto stuff into an extension, but we couldn't make it work with replace_implementation, since that one has to be called from within the runtime (and we want to keep the existing runtime and only alter the host environment).


sp_externalities::decl_extension! {
/// The crypto extension to register/retrieve from the externalities.
pub struct CryptoExtension(Box<dyn CryptoExt>);
Copy link
Contributor

Choose a reason for hiding this comment

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

To prevent a virtual call in the default case, we could perhaps do:

enum CryptoExt {
  Default(DefaultCryptoImpl),
  Custom(Box<dyn CryptoExt>),
}

Alternatively we could change the method implementation so that in case CryptoExt is not there we fall back to the default impl (i.e. CryptoExtension would not be required to be registered for this thing to work), but I feel current approach feels cleaner.

@bkchr
Copy link
Member

bkchr commented Oct 1, 2020

looks good to me, @bkchr could you take a look? I remember you didn't like the idea of putting crypto stuff into an extension, but we couldn't make it work with replace_implementation, since that one has to be called from within the runtime (and we want to keep the existing runtime and only alter the host environment).

I never said that @seunlanlege should use replace_implementation. I described it to him, that the host function that comes first is chosen and I also had shown him where he needs to change the order to make this work...

@@ -160,6 +167,11 @@ impl<Block: traits::Block> ExecutionExtensions<Block> {

let mut extensions = self.extensions_factory.read().extensions_for(capabilities);

// alas! there's no CryptoExtension in the extension factory.
if let None = extensions.get_mut(TypeId::of::<CryptoExtension>()) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if let None = extensions.get_mut(TypeId::of::<CryptoExtension>()) {
if extensions.get_mut(TypeId::of::<CryptoExtension>()).is_none() {

///
/// Returns `true` when the verification in successful regardless of
/// signature version.
fn sr25519_verify_deprecated(&self, sig: &sr25519::Signature, msg: &[u8], pubkey: &sr25519::Public) -> bool {
Copy link
Member

Choose a reason for hiding this comment

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

This function is only required for Kusama to sync. We don't require it here.

@@ -195,6 +195,48 @@ pub trait BareCryptoStore: Send + Sync {
) -> Result<VRFSignature, Error>;
}

/// Something that generates, stores and provides access to keys.
Copy link
Member

Choose a reason for hiding this comment

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

Docs are not correct.

@@ -195,6 +195,48 @@ pub trait BareCryptoStore: Send + Sync {
) -> Result<VRFSignature, Error>;
}

/// Something that generates, stores and provides access to keys.
pub trait CryptoExt: Send + Sync {
Copy link
Member

Choose a reason for hiding this comment

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

What is with the batching stuff, why isn't that here? Where do we draw the line?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch, we should defintely move all crypto stuff here to make it consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

batching eventually calls methods on CryptoExt

@bkchr
Copy link
Member

bkchr commented Oct 1, 2020

@NikVolf is your benchmark bot still working? Could you please run it here.

@bkchr
Copy link
Member

bkchr commented Oct 1, 2020

@seunlanlege please explain me what the problem was with overwriting the host functions?

@seunlanlege
Copy link
Contributor Author

Asides from the fact that it didn't work for me for some unknown reason, We needed a way to override signature verification without forking substrate and modifying the order in which host functions are initialized.

@bkchr
Copy link
Member

bkchr commented Oct 1, 2020

Asides from the fact that it didn't work for me for some unknown reason,

That is no "explanation" I will accept here.

We needed a way to override signature verification without forking substrate and modifying the order in which host functions are initialized.

You already have done the changes here: https://github.com/paritytech/substrate/pull/7078/files#diff-b447ad296633d7d693790a1fb7ce8b5f ?

And you modify Substrate here anyway?

Copy link
Contributor

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

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

Seems that crypto overrides can be better done with a host function overrides than execution extension, so let's implement that instead.

author Seun Lanlege <seunlanlege@gmail.com> 1599568164 +0100
committer Seun Lanlege <seunlanlege@gmail.com> 1604321289 +0100
gpgsig -----BEGIN PGP SIGNATURE-----

 iQGzBAABCgAdFiEECvQ02MnjnssnSbjr3HzzEhjN254FAl+gAAkACgkQ3HzzEhjN
 254soAv+KO5JA0HXSe0R0XS5TnwA3IxYsW+UvdF5dXFeC3jFdGTMvor818uoBePD
 dxzYEsUK6gjsNcM9+hpFhoy5JnUrUPInd2BZ7pmZiDuXmYJrHi0s7K5qL0EYDoe0
 m1egPNNyRR125ozJ24M+09c3OQsi3bvTx1TJaV9Aov8hK4So8UmlJTHWpkLw97ku
 HuTre2IPSFbV4GwJE40V+KNuDVHxaKL7zrInYScqbr6/hOTqBCvFn4ib3CjpF5HG
 zDAA5S2PrcbL9NQOothVcVB/TZr3IkhglCFqEjVyCX80IL0JkNZkw8jAh0B8uqXx
 Ug/c1/Mssa8F1jLZMmW45Cway60txqVbcWntPJAymGJbrRErOO/++oUrV0u1C65u
 LW7gXAaIJWQTX9KnX0SEyejNod7ubZktBz7n5WfkJAPIzdw5wtJalhLa673YTgQ9
 zyTPKiWjJj2myCq1AYrJvlK8hSsIBqbBFcUf1zX4SzZWKS+5mtp51o4gfVzcCRPd
 z/6/iPbB
 =g5tx
 -----END PGP SIGNATURE-----

BabeConsensusDataProvider works with existing chains

remove integer-sqrt from node-runtime

fix epoch changes
@seunlanlege seunlanlege marked this pull request as ready for review November 2, 2020 18:26
@athei athei removed their request for review November 3, 2020 06:22
frame/system/src/lib.rs Outdated Show resolved Hide resolved
client/api/src/execution_extensions.rs Outdated Show resolved Hide resolved
seunlanlege and others added 2 commits November 3, 2020 12:37
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
@seunlanlege seunlanlege merged commit f7a8b10 into master Nov 4, 2020
@seunlanlege seunlanlege deleted the seun-babe-manual-seal branch November 4, 2020 13:16
@tomusdrw
Copy link
Contributor

tomusdrw commented Nov 4, 2020

@seunlanlege this PR doesn't have a single approval, can you justify why it was merged?

@seunlanlege
Copy link
Contributor Author

this PR doesn't have a single approval

weird, could've sworn @bkchr approved it, which was why i was able to merge

@bkchr
Copy link
Member

bkchr commented Nov 4, 2020

this PR doesn't have a single approval

weird, could've sworn @bkchr approved it, which was why i was able to merge

I did not approve anything here.

@seunlanlege
Copy link
Contributor Author

Huh, merge button was green for some other reason then.

@bkchr
Copy link
Member

bkchr commented Nov 4, 2020

Yeah, but that is no excuse for merging this.

@seunlanlege
Copy link
Contributor Author

Aren't approvals are a requirement for merging?

darkfriend77 pushed a commit to mogwaicoin/substrate that referenced this pull request Jan 11, 2021
* parent ba8e812
author Seun Lanlege <seunlanlege@gmail.com> 1599568164 +0100
committer Seun Lanlege <seunlanlege@gmail.com> 1604321289 +0100
gpgsig -----BEGIN PGP SIGNATURE-----

 iQGzBAABCgAdFiEECvQ02MnjnssnSbjr3HzzEhjN254FAl+gAAkACgkQ3HzzEhjN
 254soAv+KO5JA0HXSe0R0XS5TnwA3IxYsW+UvdF5dXFeC3jFdGTMvor818uoBePD
 dxzYEsUK6gjsNcM9+hpFhoy5JnUrUPInd2BZ7pmZiDuXmYJrHi0s7K5qL0EYDoe0
 m1egPNNyRR125ozJ24M+09c3OQsi3bvTx1TJaV9Aov8hK4So8UmlJTHWpkLw97ku
 HuTre2IPSFbV4GwJE40V+KNuDVHxaKL7zrInYScqbr6/hOTqBCvFn4ib3CjpF5HG
 zDAA5S2PrcbL9NQOothVcVB/TZr3IkhglCFqEjVyCX80IL0JkNZkw8jAh0B8uqXx
 Ug/c1/Mssa8F1jLZMmW45Cway60txqVbcWntPJAymGJbrRErOO/++oUrV0u1C65u
 LW7gXAaIJWQTX9KnX0SEyejNod7ubZktBz7n5WfkJAPIzdw5wtJalhLa673YTgQ9
 zyTPKiWjJj2myCq1AYrJvlK8hSsIBqbBFcUf1zX4SzZWKS+5mtp51o4gfVzcCRPd
 z/6/iPbB
 =g5tx
 -----END PGP SIGNATURE-----

BabeConsensusDataProvider works with existing chains

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
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. 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.

4 participants