-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Allow BabeConsensusDataProvider fork existing chain #7078
Conversation
There was a problem hiding this 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
.
primitives/io/src/lib.rs
Outdated
@@ -408,6 +408,105 @@ pub trait Misc { | |||
} | |||
} | |||
|
|||
/// for times you want your chain to be useless | |||
#[runtime_interface] | |||
pub trait UselessCrypto { |
There was a problem hiding this comment.
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.
primitives/io/src/lib.rs
Outdated
@@ -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) |
There was a problem hiding this comment.
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.
@@ -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)), |
There was a problem hiding this comment.
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.
There was a problem hiding this 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).
primitives/core/src/traits.rs
Outdated
|
||
sp_externalities::decl_extension! { | ||
/// The crypto extension to register/retrieve from the externalities. | ||
pub struct CryptoExtension(Box<dyn CryptoExt>); |
There was a problem hiding this comment.
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.
I never said that @seunlanlege should use |
@@ -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>()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if let None = extensions.get_mut(TypeId::of::<CryptoExtension>()) { | |
if extensions.get_mut(TypeId::of::<CryptoExtension>()).is_none() { |
primitives/core/src/traits.rs
Outdated
/// | ||
/// 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 { |
There was a problem hiding this comment.
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.
primitives/core/src/traits.rs
Outdated
@@ -195,6 +195,48 @@ pub trait BareCryptoStore: Send + Sync { | |||
) -> Result<VRFSignature, Error>; | |||
} | |||
|
|||
/// Something that generates, stores and provides access to keys. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs are not correct.
primitives/core/src/traits.rs
Outdated
@@ -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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
@NikVolf is your benchmark bot still working? Could you please run it here. |
@seunlanlege please explain me what the problem was with overwriting the host functions? |
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. |
That is no "explanation" I will accept here.
You already have done the changes here: https://github.com/paritytech/substrate/pull/7078/files#diff-b447ad296633d7d693790a1fb7ce8b5f ? And you modify Substrate here anyway? |
There was a problem hiding this 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
e227bb7
to
737f7bf
Compare
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
@seunlanlege this PR doesn't have a single approval, can you justify why it was merged? |
weird, could've sworn @bkchr approved it, which was why i was able to merge |
I did not approve anything here. |
Huh, merge button was green for some other reason then. |
Yeah, but that is no excuse for merging this. |
Aren't approvals are a requirement for merging? |
* 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>
This allows
BabeConsensusDataProvider
build blocks on top of an existing chain where the Alice key isn't part of the authorities.