-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
ssv_network_config
for configurable networks (#121)
- Loading branch information
Showing
18 changed files
with
187 additions
and
59 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "ssv_network_config" | ||
version = "0.1.0" | ||
authors = ["Sigma Prime <contact@sigmaprime.io"] | ||
edition = { workspace = true } | ||
|
||
[dependencies] | ||
alloy = { workspace = true } | ||
enr = { workspace = true } | ||
eth2_network_config = { workspace = true } | ||
serde_yaml = { workspace = true } |
3 changes: 3 additions & 0 deletions
3
anchor/common/ssv_network_config/built_in_network_configs/holesky/ssv_boot_enr.yaml
This file contains 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# SSV Labs | ||
- enr:-Ja4QKFD3u5tZob7xukp-JKX9QJMFqqI68cItsE4tBbhsOyDR0M_1UUjb35hbrqvTP3bnXO_LnKh-jNLTeaUqN4xiduGAZKaP_sagmlkgnY0gmlwhDb0fh6Jc2VjcDI1NmsxoQMw_H2anuiqP9NmEaZwbUfdvPFog7PvcKmoVByDa576SINzc3YBg3RjcIITioN1ZHCCD6I | ||
- enr:-Li4QFIQzamdvTxGJhvcXG_DFmCeyggSffDnllY5DiU47pd_K_1MRnSaJimWtfKJ-MD46jUX9TwgW5Jqe0t4pH41RYWGAYuFnlyth2F0dG5ldHOIAAAAAAAAAACEZXRoMpD1pf1CAAAAAP__________gmlkgnY0gmlwhCLdu_SJc2VjcDI1NmsxoQN4v-N9zFYwEqzGPBBX37q24QPFvAVUtokIo1fblIsmTIN0Y3CCE4uDdWRwgg-j |
1 change: 1 addition & 0 deletions
1
anchor/common/ssv_network_config/built_in_network_configs/holesky/ssv_contract_address.txt
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
0x38A4794cCEd47d3baf7370CcC43B560D3a1beEFA |
1 change: 1 addition & 0 deletions
1
anchor/common/ssv_network_config/built_in_network_configs/holesky/ssv_contract_block.txt
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
181612 |
9 changes: 9 additions & 0 deletions
9
anchor/common/ssv_network_config/built_in_network_configs/mainnet/ssv_boot_enr.yaml
This file contains 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# SSV Labs | ||
- enr:-Ja4QAbDe5XANqJUDyJU1GmtS01qqMwDYx9JNZgymjBb55fMaha80E2HznRYoUGy6NFVSvs1u1cFqSM0MgJI-h1QK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mlkgnY0gmlwhBLb3g2Jc2VjcDI1NmsxoQKeSDcZWSaY9FC723E9yYX1Li18bswhLNlxBZdLfgOKp4N0Y3CCE4mDdWRwgg-h |
1 change: 1 addition & 0 deletions
1
anchor/common/ssv_network_config/built_in_network_configs/mainnet/ssv_contract_address.txt
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
0xDD9BC35aE942eF0cFa76930954a156B3fF30a4E1 |
1 change: 1 addition & 0 deletions
1
anchor/common/ssv_network_config/built_in_network_configs/mainnet/ssv_contract_block.txt
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
17507487 |
This file contains 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 |
---|---|---|
@@ -0,0 +1,104 @@ | ||
use alloy::primitives::Address; | ||
use enr::{CombinedKey, Enr}; | ||
use eth2_network_config::Eth2NetworkConfig; | ||
use std::fs::File; | ||
use std::path::{Path, PathBuf}; | ||
use std::str::FromStr; | ||
|
||
macro_rules! include_str_for_net { | ||
($network:ident, $file:literal) => { | ||
include_str!(concat!( | ||
"../built_in_network_configs/", | ||
stringify!($network), | ||
"/", | ||
$file | ||
)) | ||
}; | ||
} | ||
|
||
macro_rules! get_hardcoded { | ||
($network:ident) => { | ||
( | ||
include_str_for_net!($network, "ssv_boot_enr.yaml"), | ||
include_str_for_net!($network, "ssv_contract_address.txt"), | ||
include_str_for_net!($network, "ssv_contract_block.txt"), | ||
) | ||
}; | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct SsvNetworkConfig { | ||
pub eth2_network: Eth2NetworkConfig, | ||
pub ssv_boot_nodes: Option<Vec<Enr<CombinedKey>>>, | ||
pub ssv_contract: Address, | ||
pub ssv_contract_block: u64, | ||
} | ||
|
||
impl SsvNetworkConfig { | ||
pub fn constant(name: &str) -> Result<Option<Self>, String> { | ||
let (enr_yaml, address, block) = match name { | ||
"mainnet" => get_hardcoded!(mainnet), | ||
"holesky" => get_hardcoded!(holesky), | ||
_ => return Ok(None), | ||
}; | ||
let Some(eth2_network) = Eth2NetworkConfig::constant(name)? else { | ||
return Ok(None); | ||
}; | ||
Ok(Some(Self { | ||
eth2_network, | ||
ssv_boot_nodes: Some( | ||
serde_yaml::from_str(enr_yaml).map_err(|_| "Unable to parse built-in yaml!")?, | ||
), | ||
ssv_contract: address | ||
.parse() | ||
.map_err(|_| "Unable to parse built-in address!")?, | ||
ssv_contract_block: block | ||
.parse() | ||
.map_err(|_| "Unable to parse built-in block!")?, | ||
})) | ||
} | ||
|
||
pub fn load(base_dir: PathBuf) -> Result<Self, String> { | ||
let ssv_boot_nodes_path = base_dir.join("ssv_boot_enr.yaml"); | ||
let ssv_boot_nodes = ssv_boot_nodes_path | ||
.exists() | ||
.then(|| { | ||
File::open(&ssv_boot_nodes_path) | ||
.map_err(|e| format!("Unable to read {ssv_boot_nodes_path:?}: {e}")) | ||
.and_then(|f| { | ||
serde_yaml::from_reader(f) | ||
.map_err(|e| format!("Unable to parse {ssv_boot_nodes_path:?}: {e}")) | ||
}) | ||
}) | ||
.transpose()?; | ||
|
||
Ok(Self { | ||
ssv_boot_nodes, | ||
ssv_contract: read(&base_dir.join("ssv_contract_address.txt"))?, | ||
ssv_contract_block: read(&base_dir.join("ssv_contract_block.txt"))?, | ||
eth2_network: Eth2NetworkConfig::load(base_dir)?, | ||
}) | ||
} | ||
} | ||
|
||
fn read<T: FromStr>(file: &Path) -> Result<T, String> { | ||
std::fs::read_to_string(file) | ||
.map_err(|e| format!("Unable to read {file:?}: {e}"))? | ||
.parse() | ||
.map_err(|_| format!("Unable to parse {file:?}")) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_holesky() { | ||
SsvNetworkConfig::constant("holesky").unwrap().unwrap(); | ||
} | ||
|
||
#[test] | ||
fn test_mainnet() { | ||
SsvNetworkConfig::constant("mainnet").unwrap().unwrap(); | ||
} | ||
} |
This file contains 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 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 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.