-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make snowbridge-ethereum-beacon-client
generic over the network it is built for
#788
Make snowbridge-ethereum-beacon-client
generic over the network it is built for
#788
Conversation
e074015
to
80c2ad4
Compare
8542208
to
494ab1c
Compare
BTW, let me know if you want to see |
@@ -1,5 +1,7 @@ | |||
//! # Ethereum Beacon Client | |||
#![cfg_attr(not(feature = "std"), no_std)] | |||
#![allow(incomplete_features)] | |||
#![feature(generic_const_exprs)] |
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.
We can't really use unstable features (and especially this one, which is still in development) in the common-good BridgeHub parachain. That's where this pallet is eventually going to be installed.
But simple const generics, which were stabilized in Rust 1.51, are totally fine. So then would it not be possible to support both the minimal
and mainnet
using a more dynamic approach, like the following:
const A: u32 = 2;
const B: u32 = 3;
function foo<const FOO: u32>() { ... }
function main() {
if ... {
foo<A>();
} else {
foo<B>();
}
}
Another option is doing away with the minimal
feature. That will increase the duration of our integration tests though. But perhaps it is better to test always against mainnet
configs. Let me think over it for a bit.
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.
Those features were only added so we can use constants defined on Config
in function calls (that also have const generics) otherwise they are considered expressions in current Rust version for some reason ({}
part). There are apparently more advanced versions of this that are not complete, but we literally use the most basic version of the feature possible, so I'd say the risk of using it is low.
And as I said before, runtime already requires nightly Rust (and you run tests on nightly Rust too), so I don't see an issue there either.
Dynamic approach means bigger runtime and less flexibility. With this PR you can provide whatever values you want (you might want to use Ethereum or any of the numerous forks), with "dynamic" approach we're limited to a few hardcoded options only.
Why are you saying that you can't use unstable features, is there a requirement for this somewhere?
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.
Well the issue is that our snowbridge runtimes/parachain in this repo are just for testing. Our pallets are eventually going to be included in the BridgeHub runtime in the cumulus repo: https://github.com/paritytech/cumulus/tree/master/parachains/runtimes/bridge-hubs
So we'd have to ask the Cumulus team if they are willing to support the generic_const_exprs
feature. I can't find a clear policy anywhere, but I suspect that Parity-developed core parachains can't use unstable features, even if the runtimes are built using nightly.
I believe Substrate relies on rust nightly mainly because it supports wasm compilation, rather than because of needing other unstable features.
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 pallet is made instantiable (I didn't implement it in this PR as it might be more controversial) then it would be possible to have this pallet included multiple times in the same runtime with different configurations, which wasn't possible before.
I don't have a strong objection against making the pallet instantiable. Just bear in mind that operating even a single instance of the pallet consumes a lot of block weight due to BLS signature verification. I wouldn't add more 2-3 instances in a runtime (and that is still dependent on BLS host functions being merged into Substrate).
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.
Here is why they use nightly: paritytech/substrate#1252
TL;DR: It will soon become stable compatible: paritytech/substrate#13580
Still it seems to be useful to have ability to customize it and this is the only way. I don't see usage of nightly compiler as a big obstacle for Substrate ecosystem so far.
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.
Thanks for those links, some that is news to me! I asked some Parity devs, and it was pointed out to me that paritytech/substrate#13580 pretty much answers this question. Using rust nightly is on the way out. And unstable features won't be accepted on the BridgeHub parachain, because it will add instability during compilation and possibly in production settings.
So I think we need to find another solution here for you.
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.
Got it, will close for now then, but if you have specific steps you'd like to make I might be able to help. Thanks for review!
We wanted to use this at Subspace, but turned out there was a mix of constants and generic configuration parameters that were:
I resolved this by making a few data structures generic and adding constants to
Config
trait. If pallet is made instantiable (I didn't implement it in this PR as it might be more controversial) then it would be possible to have this pallet included multiple times in the same runtime with different configurations, which wasn't possible before.It required using unstable feature, but since Substrate uses them too and nightly is already required, this seemed like a decent compromise.
Note:
minimal
feature is still there, but it is now only used for benchmaking and testing and has no effect otherwise.