Skip to content

Commit 15afa21

Browse files
authored
Merge pull request #134 from movementlabsxyz/mikhail/mcr-settlement-setup
mcr-settlement-setup: new crate
2 parents 4a99d52 + 750ede2 commit 15afa21

File tree

7 files changed

+183
-54
lines changed

7 files changed

+183
-54
lines changed

Cargo.lock

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ members = [
1313
"protocol-units/settlement/mcr/client",
1414
"protocol-units/settlement/mcr/config",
1515
"protocol-units/settlement/mcr/manager",
16+
"protocol-units/settlement/mcr/setup",
1617
"protocol-units/movement-rest",
1718
"util/*",
1819
"util/buildtime/buildtime-helpers",
1920
"util/buildtime/buildtime-macros",
2021
"networks/monza/*",
2122
"networks/suzuka/*",
23+
"protocol-units/settlement/mcr/setup",
2224
]
2325

2426
[workspace.package]
@@ -61,6 +63,7 @@ sequencing-util = { path = "protocol-units/sequencing/util" }
6163
mcr-settlement-client = { path = "protocol-units/settlement/mcr/client" }
6264
mcr-settlement-config = { path = "protocol-units/settlement/mcr/config" }
6365
mcr-settlement-manager = { path = "protocol-units/settlement/mcr/manager" }
66+
mcr-settlement-setup = { path = "protocol-units/settlement/mcr/setup" }
6467
## types
6568
movement-types = { path = "util/movement-types" }
6669
## dot movement
@@ -183,6 +186,7 @@ hex = { version = "0.4.3", default-features = false, features = [
183186
"serde",
184187
] }
185188
ics23 = { version = "0.11.0" }
189+
k256 = { version = "0.13.3" }
186190
itertools = { version = "0.12.1", default-features = false }
187191
jmt = "0.9.0"
188192
jsonrpsee = { version = "0.20.1", features = ["jsonrpsee-types"] }

networks/suzuka/setup/Cargo.toml

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
22
name = "suzuka-full-node-setup"
33
version = { workspace = true }
4-
edition = { workspace = true }
5-
license = { workspace = true }
4+
edition = { workspace = true }
5+
license = { workspace = true }
66
authors = { workspace = true }
77
repository = { workspace = true }
88
homepage = { workspace = true }
@@ -12,23 +12,25 @@ rust-version = { workspace = true }
1212
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1313

1414
[dependencies]
15+
dot-movement = { workspace = true }
16+
m1-da-light-node-util = { workspace = true }
17+
m1-da-light-node-setup = { workspace = true }
18+
mcr-settlement-setup = { workspace = true }
19+
suzuka-config = { workspace = true }
20+
1521
anyhow = { workspace = true }
1622
tokio = { workspace = true }
1723
tokio-stream = { workspace = true }
1824
serde_json = { workspace = true }
1925
serde = { workspace = true }
2026
commander = { workspace = true }
2127
tracing = { workspace = true }
22-
m1-da-light-node-util = { workspace = true }
23-
dot-movement = { workspace = true }
2428
rand = { workspace = true }
2529
hex = { workspace = true }
2630
celestia-rpc = { workspace = true }
2731
celestia-types = { workspace = true }
2832
async-recursion = { workspace = true }
2933
tracing-subscriber = { workspace = true }
30-
m1-da-light-node-setup = { workspace = true }
31-
suzuka-config = { workspace = true }
3234

3335
[dev-dependencies]
3436
tempfile = { workspace = true }

networks/suzuka/setup/src/local.rs

+49-48
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,61 @@
1-
use dot_movement::DotMovement;
2-
use tracing::info;
31
use crate::SuzukaFullNodeSetupOperations;
2+
use dot_movement::DotMovement;
43
use m1_da_light_node_setup::M1DaLightNodeSetupOperations;
4+
use mcr_settlement_setup::Setup as _;
5+
6+
use tracing::debug;
57

68
#[derive(Debug, Clone)]
79
pub struct Local {
8-
m1_da_light_node_strategy : m1_da_light_node_setup::local::Local,
10+
m1_da_light_node_strategy: m1_da_light_node_setup::local::Local,
11+
mcr_settlement_strategy: mcr_settlement_setup::Local,
912
}
1013

1114
impl Local {
12-
13-
pub fn new() -> Self {
14-
Self {
15-
m1_da_light_node_strategy : m1_da_light_node_setup::local::Local::new(),
16-
}
17-
}
18-
19-
async fn run_m1_da_light_node_setup(
20-
&self,
21-
dot_movement : DotMovement,
22-
mut config : suzuka_config::Config
23-
) -> Result<suzuka_config::Config, anyhow::Error> {
24-
25-
// Get the m1_da_light_node_config from the suzuka config
26-
let m1_da_light_node_config = config.execution_config.light_node_config.clone();
27-
28-
// Run the m1_da_light_node_setup
29-
info!("Running m1_da_light_node_setup");
30-
let m1_da_light_node_config = self.m1_da_light_node_strategy.setup(
31-
dot_movement.clone(),
32-
m1_da_light_node_config
33-
).await?;
34-
35-
// Modify the suzuka config accordingly
36-
config.execution_config.light_node_config = m1_da_light_node_config;
37-
38-
Ok(config)
39-
40-
}
41-
15+
pub fn new() -> Self {
16+
Self {
17+
m1_da_light_node_strategy: m1_da_light_node_setup::local::Local::new(),
18+
mcr_settlement_strategy: Default::default(),
19+
}
20+
}
21+
22+
async fn run_m1_da_light_node_setup(
23+
&self,
24+
dot_movement: DotMovement,
25+
mut config: suzuka_config::Config,
26+
) -> Result<suzuka_config::Config, anyhow::Error> {
27+
// Get the m1_da_light_node_config from the suzuka config
28+
let m1_da_light_node_config = config.execution_config.light_node_config.clone();
29+
30+
// Run the m1_da_light_node_setup
31+
debug!("Running m1_da_light_node_setup");
32+
let m1_da_light_node_config = self
33+
.m1_da_light_node_strategy
34+
.setup(dot_movement.clone(), m1_da_light_node_config)
35+
.await?;
36+
37+
// Modify the suzuka config accordingly
38+
config.execution_config.light_node_config = m1_da_light_node_config;
39+
40+
debug!("Running mcr_settlement_setup");
41+
let mcr_settlement_config = config.mcr.clone();
42+
config.mcr =
43+
self.mcr_settlement_strategy.setup(&dot_movement, mcr_settlement_config).await?;
44+
45+
Ok(config)
46+
}
4247
}
4348

4449
impl SuzukaFullNodeSetupOperations for Local {
45-
async fn setup(
46-
&self,
47-
dot_movement : DotMovement,
48-
config : suzuka_config::Config
49-
) -> Result<suzuka_config::Config, anyhow::Error> {
50-
51-
// Run the m1_da_light_node_setup
52-
let config = self.run_m1_da_light_node_setup(
53-
dot_movement.clone(),
54-
config
55-
).await?;
56-
57-
// Placeholder for returning the actual configuration.
58-
Ok(config)
59-
}
50+
async fn setup(
51+
&self,
52+
dot_movement: DotMovement,
53+
config: suzuka_config::Config,
54+
) -> Result<suzuka_config::Config, anyhow::Error> {
55+
// Run the m1_da_light_node_setup
56+
let config = self.run_m1_da_light_node_setup(dot_movement.clone(), config).await?;
57+
58+
// Placeholder for returning the actual configuration.
59+
Ok(config)
60+
}
6061
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
name = "mcr-settlement-setup"
3+
description = "Setting up of MCR configuration"
4+
version.workspace = true
5+
edition.workspace = true
6+
license.workspace = true
7+
authors.workspace = true
8+
repository.workspace = true
9+
homepage.workspace = true
10+
publish.workspace = true
11+
rust-version.workspace = true
12+
13+
[dependencies]
14+
mcr-settlement-config = { workspace = true }
15+
dot-movement = { workspace = true }
16+
17+
alloy-primitives = { workspace = true }
18+
19+
anyhow = { workspace = true }
20+
k256 = { workspace = true }
21+
tracing = { workspace = true }
22+
23+
[lints]
24+
workspace = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use dot_movement::DotMovement;
2+
use mcr_settlement_config::Config;
3+
4+
use std::future::Future;
5+
6+
mod local;
7+
8+
pub use local::Local;
9+
10+
/// Abstraction trait for MCR settlement setup strategies.
11+
pub trait Setup {
12+
/// Sets up the MCR settlement client configuration.
13+
/// If required configuration values are unset, fills them with
14+
/// values decided by this setup strategy.
15+
fn setup(
16+
&self,
17+
dot_movement: &DotMovement,
18+
config: Config,
19+
) -> impl Future<Output = Result<Config, anyhow::Error>> + Send;
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
use super::Setup;
2+
3+
use dot_movement::DotMovement;
4+
use mcr_settlement_config::Config;
5+
6+
use alloy_primitives::hex;
7+
8+
use k256::ecdsa::SigningKey;
9+
use tracing::info;
10+
11+
use std::future::Future;
12+
13+
const DEFAULT_ETH_RPC_PORT: u16 = 8545;
14+
const DEFAULT_ETH_WS_PORT: u16 = 8545;
15+
16+
/// The local setup strategy for MCR settlement
17+
#[derive(Debug, Clone)]
18+
pub struct Local {
19+
eth_rpc_port: u16,
20+
eth_ws_port: u16,
21+
}
22+
23+
impl Local {
24+
/// Instantiates the local setup strategy with ports on localhost
25+
/// to configure for Ethernet RPC and WebSocket client access.
26+
pub fn new(eth_rpc_port: u16, eth_ws_port: u16) -> Self {
27+
Self { eth_rpc_port, eth_ws_port }
28+
}
29+
}
30+
31+
impl Default for Local {
32+
fn default() -> Self {
33+
Local::new(DEFAULT_ETH_RPC_PORT, DEFAULT_ETH_WS_PORT)
34+
}
35+
}
36+
37+
impl Setup for Local {
38+
fn setup(
39+
&self,
40+
_dot_movement: &DotMovement,
41+
mut config: Config,
42+
) -> impl Future<Output = Result<Config, anyhow::Error>> + Send {
43+
async move {
44+
// Can't use rand 0.7 while k256 is on rand 0.6
45+
let mut rng = k256::elliptic_curve::rand_core::OsRng;
46+
47+
info!("setting up MCR Ethereum client");
48+
49+
if config.rpc_url.is_none() {
50+
config.rpc_url = Some(format!("http://localhost:{}", self.eth_rpc_port));
51+
}
52+
if config.ws_url.is_none() {
53+
config.ws_url = Some(format!("http://localhost:{}", self.eth_ws_port));
54+
}
55+
if config.signer_private_key.is_none() {
56+
let key = SigningKey::random(&mut rng);
57+
let key_bytes = key.to_bytes();
58+
let private_key = hex::encode(key_bytes.as_slice());
59+
config.signer_private_key = Some(private_key);
60+
}
61+
62+
Ok(config)
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)