-
Notifications
You must be signed in to change notification settings - Fork 63
support chain spec #138
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
Merged
Merged
support chain spec #138
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e231a43
support chain spec
ltitanb 5737c00
fixes
ltitanb 3533cf4
add cb init args
ltitanb 332fd0b
impl `Debug` for chain
ltitanb f75054a
small fixes
ltitanb 7ce9d11
fixes
ltitanb 72bd5d4
group chain constants
ltitanb e2b126a
comments
ltitanb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,18 @@ | ||
| use std::path::PathBuf; | ||
|
|
||
| use eyre::Result; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| use crate::types::Chain; | ||
| use crate::types::{load_chain_from_file, Chain}; | ||
|
|
||
| mod constants; | ||
| mod log; | ||
| mod metrics; | ||
| mod module; | ||
| mod pbs; | ||
| mod signer; | ||
| mod utils; | ||
|
|
||
| mod log; | ||
|
|
||
| pub use constants::*; | ||
| pub use log::*; | ||
| pub use metrics::*; | ||
|
|
@@ -22,7 +23,6 @@ pub use utils::*; | |
|
|
||
| #[derive(Debug, Deserialize, Serialize)] | ||
| pub struct CommitBoostConfig { | ||
| // TODO: generalize this with a spec file | ||
| pub chain: Chain, | ||
| pub relays: Vec<RelayConfig>, | ||
| pub pbs: StaticPbsConfig, | ||
|
|
@@ -45,9 +45,53 @@ impl CommitBoostConfig { | |
| Ok(config) | ||
| } | ||
|
|
||
| // When loading the config from the environment, it's important that every path | ||
| // is replaced with the correct value if the config is loaded inside a container | ||
| pub fn from_env_path() -> Result<Self> { | ||
| let config: Self = load_file_from_env(CONFIG_ENV)?; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wonder if we can do something like: impl TryFrom<&'static str> for CommitBoostConfigand then let config = CommitBoostConfig::try_from(CONFIG_ENV)?;
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah think we can improve in general how configs are loaded, will keep it in a separate PR |
||
| let config = if let Ok(path) = std::env::var(CHAIN_SPEC_ENV) { | ||
| // if the chain spec file is set, load it separately | ||
| let chain: Chain = load_chain_from_file(path.parse()?)?; | ||
| let rest_config: HelperConfig = load_file_from_env(CONFIG_ENV)?; | ||
|
|
||
| CommitBoostConfig { | ||
| chain, | ||
| relays: rest_config.relays, | ||
| pbs: rest_config.pbs, | ||
| modules: rest_config.modules, | ||
| signer: rest_config.signer, | ||
| metrics: rest_config.metrics, | ||
| logs: rest_config.logs, | ||
| } | ||
| } else { | ||
| load_file_from_env(CONFIG_ENV)? | ||
| }; | ||
|
|
||
| config.validate()?; | ||
| Ok(config) | ||
| } | ||
|
|
||
| /// Returns the path to the chain spec file if any | ||
| pub fn chain_spec_file(path: &str) -> Option<PathBuf> { | ||
| match load_from_file::<ChainConfig>(path) { | ||
| Ok(config) => Some(config.chain), | ||
| Err(_) => None, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Helper struct to load the chain spec file | ||
| #[derive(Deserialize)] | ||
| struct ChainConfig { | ||
| chain: PathBuf, | ||
| } | ||
|
|
||
| /// Helper struct to load the rest of the config | ||
| #[derive(Deserialize)] | ||
| struct HelperConfig { | ||
| relays: Vec<RelayConfig>, | ||
| pbs: StaticPbsConfig, | ||
| modules: Option<Vec<StaticModuleConfig>>, | ||
| signer: Option<SignerConfig>, | ||
| metrics: Option<MetricsConfig>, | ||
| logs: Option<LogsSettings>, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,3 @@ | ||
| // TODO: replace with full chain spec, allow loading from file | ||
|
|
||
| pub const APPLICATION_BUILDER_DOMAIN: [u8; 4] = [0, 0, 0, 1]; | ||
| pub const GENESIS_VALIDATORS_ROOT: [u8; 32] = [0; 32]; | ||
| pub const COMMIT_BOOST_DOMAIN: [u8; 4] = [109, 109, 111, 67]; | ||
|
|
||
| // MAINNET | ||
| pub const MAINNET_FORK_VERSION: [u8; 4] = [0u8; 4]; | ||
| pub const MAINNET_BUILDER_DOMAIN: [u8; 32] = [ | ||
| 0, 0, 0, 1, 245, 165, 253, 66, 209, 106, 32, 48, 39, 152, 239, 110, 211, 9, 151, 155, 67, 0, | ||
| 61, 35, 32, 217, 240, 232, 234, 152, 49, 169, | ||
| ]; | ||
| pub const MAINNET_GENESIS_TIME_SECONDS: u64 = 1606824023; | ||
|
|
||
| // HOLESKY | ||
| pub const HOLESKY_FORK_VERSION: [u8; 4] = [1, 1, 112, 0]; | ||
| pub const HOLESKY_BUILDER_DOMAIN: [u8; 32] = [ | ||
| 0, 0, 0, 1, 91, 131, 162, 55, 89, 197, 96, 178, 208, 198, 69, 118, 225, 220, 252, 52, 234, 148, | ||
| 196, 152, 143, 62, 13, 159, 119, 240, 83, 135, | ||
| ]; | ||
| pub const HOLESKY_GENESIS_TIME_SECONDS: u64 = 1695902400; | ||
|
|
||
| // HELDER | ||
| pub const HELDER_FORK_VERSION: [u8; 4] = [16, 0, 0, 0]; | ||
| pub const HELDER_BUILDER_DOMAIN: [u8; 32] = [ | ||
| 0, 0, 0, 1, 148, 196, 26, 244, 132, 255, 247, 150, 73, 105, 224, 189, 217, 34, 248, 45, 255, | ||
| 15, 75, 232, 122, 96, 208, 102, 76, 201, 209, 255, | ||
| ]; | ||
| pub const HELDER_GENESIS_TIME_SECONDS: u64 = 1718967660; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
maybe:
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.
mm not sure this is more legible