-
Notifications
You must be signed in to change notification settings - Fork 31
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
refactor: move VersionedConstants macro, errors from Blockifier to StarknetAPI #3195
refactor: move VersionedConstants macro, errors from Blockifier to StarknetAPI #3195
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Benchmark movements: |
55013d2
to
1499408
Compare
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.
Reviewed 6 of 6 files at r1, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @ayeletstarkware)
crates/starknet_api/src/versioned_constants_logic.rs
line 17 at r1 (raw file):
#[error("Invalid Starknet version: {0}")] InvalidStarknetVersion(StarknetVersion), }
you are planning on refactoring the macro into a more generic "X_constants" generating macro, right?
why not add the error type as an argument to the macro?
I guess you could even generate the error enum automatically.
Also, you can use paste! { $struct_name Error }
to avoid an extra arg.
My issue is: you shouldn't be mentioning "versioned constants" in starknet-api; in any case I'd want the error enum definition to move back to blockifier crate
Code quote:
#[derive(Debug, Error)]
pub enum VersionedConstantsError {
#[error(transparent)]
IoError(#[from] io::Error),
#[error("JSON file cannot be serialized into VersionedConstants: {0}")]
ParseError(#[from] serde_json::Error),
#[error("Invalid version: {version:?}")]
InvalidVersion { version: String },
#[error("Invalid Starknet version: {0}")]
InvalidStarknetVersion(StarknetVersion),
}
crates/starknet_api/src/versioned_constants_logic.rs
line 33 at r1 (raw file):
use starknet_api::versioned_constants_logic::{ VersionedConstantsError, VersionedConstantsResult, };
please don't use use
s in macros: if you need the types, I would fully-qualify them
Code quote:
use starknet_infra_utils::compile_time_cargo_manifest_dir;
use paste::paste;
use std::fs;
use std::path::PathBuf;
use std::sync::LazyLock;
use starknet_api::block::StarknetVersion;
use starknet_api::versioned_constants_logic::{
VersionedConstantsError, VersionedConstantsResult,
};
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.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @ayeletstarkware)
a discussion (no related file):
please add yoni/noa as additional reviewer
1499408
to
0981189
Compare
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.
Reviewable status: 4 of 7 files reviewed, 3 unresolved discussions (waiting on @dorimedini-starkware)
a discussion (no related file):
Previously, dorimedini-starkware wrote…
please add yoni/noa as additional reviewer
Done.
crates/starknet_api/src/versioned_constants_logic.rs
line 17 at r1 (raw file):
Previously, dorimedini-starkware wrote…
you are planning on refactoring the macro into a more generic "X_constants" generating macro, right?
why not add the error type as an argument to the macro?
I guess you could even generate the error enum automatically.
Also, you can usepaste! { $struct_name Error }
to avoid an extra arg.My issue is: you shouldn't be mentioning "versioned constants" in starknet-api; in any case I'd want the error enum definition to move back to blockifier crate
It's not a generic X_constants
macro. It's for versioned constants in Blockifier and Consensus, each with different constants.
Why pass the error type as an argument? The errors are currently related to parsing and versioning. If different structs need unique errors in the future, we can refactor.
Can you explain how to generate the error enum automatically and how paste! { $struct_name Error }
would be used?
crates/starknet_api/src/versioned_constants_logic.rs
line 33 at r1 (raw file):
Previously, dorimedini-starkware wrote…
please don't use
use
s in macros: if you need the types, I would fully-qualify them
Done. can you explain why not use use
in macros? Fully qualifying types feels much longer.
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.
Reviewable status: 4 of 7 files reviewed, 1 unresolved discussion (waiting on @ayeletstarkware and @noaov1)
crates/starknet_api/src/versioned_constants_logic.rs
line 17 at r1 (raw file):
Previously, ayeletstarkware (Ayelet Zilber) wrote…
It's not a generic
X_constants
macro. It's for versioned constants in Blockifier and Consensus, each with different constants.Why pass the error type as an argument? The errors are currently related to parsing and versioning. If different structs need unique errors in the future, we can refactor.
Can you explain how to generate the error enum automatically and how
paste! { $struct_name Error }
would be used?
VersionedConstants is the name of the blockifier constants; I guess consensus constants will have a different name. Thus, I don't want the VersionedConstantsError enum defined in starknet-api - it should be defined in the blockifier crate.
Since the error enum will have the same variants in the consensus context, you could do this in the macro implementation:
#[derive(Debug, Error)]
pub enum paste! { $struct_name Error } {
#[error(transparent)]
IoError(#[from] io::Error),
#[error("JSON file cannot be serialized into {}: {0}", stringify!($struct_name))]
ParseError(#[from] serde_json::Error),
#[error("Invalid version: {version:?}")]
InvalidVersion { version: String },
#[error("Invalid Starknet version: {0}")]
InvalidStarknetVersion(StarknetVersion),
}
if that doesn't work, you can add the error enum name as input to the macro
crates/starknet_api/src/versioned_constants_logic.rs
line 33 at r1 (raw file):
Previously, ayeletstarkware (Ayelet Zilber) wrote…
Done. can you explain why not use
use
in macros? Fully qualifying types feels much longer.
because when you use the macro you implicitly use
objects; i.e. invoking the macro imports objects into the scope that you may not want
0981189
to
cd1a325
Compare
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.
Reviewable status: 1 of 7 files reviewed, 1 unresolved discussion (waiting on @dorimedini-starkware and @noaov1)
crates/starknet_api/src/versioned_constants_logic.rs
line 17 at r1 (raw file):
Previously, dorimedini-starkware wrote…
VersionedConstants is the name of the blockifier constants; I guess consensus constants will have a different name. Thus, I don't want the VersionedConstantsError enum defined in starknet-api - it should be defined in the blockifier crate.
Since the error enum will have the same variants in the consensus context, you could do this in the macro implementation:#[derive(Debug, Error)] pub enum paste! { $struct_name Error } { #[error(transparent)] IoError(#[from] io::Error), #[error("JSON file cannot be serialized into {}: {0}", stringify!($struct_name))] ParseError(#[from] serde_json::Error), #[error("Invalid version: {version:?}")] InvalidVersion { version: String }, #[error("Invalid Starknet version: {0}")] InvalidStarknetVersion(StarknetVersion), }
if that doesn't work, you can add the error enum name as input to the macro
didn't work. passed it as an argument to the macro.
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.
Reviewed 1 of 3 files at r2, 5 of 5 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ayeletstarkware and @noaov1)
crates/blockifier/src/versioned_constants.rs
line 1102 at r3 (raw file):
} pub type VersionedConstantsResult<T> = Result<T, VersionedConstantsError>;
why move this back, and not create this error enum in the macro?
Code quote:
#[derive(Debug, Error)]
pub enum VersionedConstantsError {
#[error(transparent)]
IoError(#[from] io::Error),
#[error("JSON file cannot be serialized into VersionedConstants: {0}")]
ParseError(#[from] serde_json::Error),
#[error("Invalid version: {version:?}")]
InvalidVersion { version: String },
#[error("Invalid Starknet version: {0}")]
InvalidStarknetVersion(StarknetVersion),
}
pub type VersionedConstantsResult<T> = Result<T, VersionedConstantsError>;
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.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @dorimedini-starkware and @noaov1)
crates/blockifier/src/versioned_constants.rs
line 1102 at r3 (raw file):
Previously, dorimedini-starkware wrote…
why move this back, and not create this error enum in the macro?
The only error from this enum used in the macro is InvalidStarknetVersion
, so passing it as an argument makes sense.
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.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @noaov1)
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.
Reviewed 1 of 6 files at r1, 1 of 3 files at r2, 5 of 5 files at r3, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @noaov1)
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.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @noaov1)
Refactoring the general versioned constants logic to make it reusable for Consensus in the next PR.