-
Notifications
You must be signed in to change notification settings - Fork 279
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
Genesis API #3363
Comments
IMO we can use wrapper around function with const generic functions like: #[inline]
fn validate<const IS_GENESIS: bool>() {
// ...
}
fn validate_in_block() {
validate::<false>()
}
fn validate_in_genesis() {
validate::<true>()
} I checked similar pattern once using godbolt and emitted assembly looks as we want (link) |
The inline on a generic function is redundant. Also, the trait-based solution is arguably more descriptive, while allowing for idiomatic usage: fn do_stuff_in_genesis( ... ) {
use InGenesis as _;
// ...
thing.validate(args);
}
fn do_stuff_in_both( ... ) {
use InGenesis;
use InBlock;
// ...
<Thing as InGenesis>::validate(thing, args);
<Thing as InBlock>::validate(thing, args);
} and generating the same assembly as the const generic. If at some point we need to change the semantics of Moreover, I doubt that we'd need to validate with genesis semantics outside the |
Nice, i like this solution because we combine best of both worlds: DRY and descriptive behavior of the function. |
There was this interesting comment by @appetrosyan on how we can extract genesis into a bootstrap process |
Signed-off-by: Ilia Churin <churin.ilya@gmail.com>
Signed-off-by: Ilia Churin <churin.ilya@gmail.com>
Signed-off-by: Ilia Churin <churin.ilya@gmail.com>
Signed-off-by: Ilia Churin <churin.ilya@gmail.com>
Signed-off-by: Ilia Churin <churin.ilya@gmail.com>
Signed-off-by: Ilia Churin <churin.ilya@gmail.com>
Signed-off-by: Ilia Churin <churin.ilya@gmail.com>
Signed-off-by: Ilia Churin <churin.ilya@gmail.com>
Signed-off-by: Ilia Churin <churin.ilya@gmail.com>
Signed-off-by: Ilia Churin <churin.ilya@gmail.com>
Signed-off-by: Ilia Churin <churin.ilya@gmail.com>
Signed-off-by: Ilia Churin <churin.ilya@gmail.com>
Signed-off-by: Ilia Churin <churin.ilya@gmail.com>
Originally posted by @appetrosyan in #3356 (comment)
The text was updated successfully, but these errors were encountered: