Skip to content
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

feat: commit transaction data to L1 #85

Merged
merged 23 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
424 changes: 244 additions & 180 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ validator = { path = "./packages/validator", default-features = false }
actix-web = { version = "4", default-features = false }
anyhow = { version = "1.0", default-features = false }
async-trait = { version = "0.1", default-features = false }
c-kzg = { version = "1.0", default-features = false }
clap = { version = "4.5" }
config = { version = "0.14", default-features = false }
ethers = { version = "2.0", default-features = false }
Expand All @@ -43,9 +44,12 @@ fuel-crypto = { version = "0.49.0", default-features = false }
futures = { version = "0.3", default-features = false }
hex = { version = "0.4", default-features = false }
impl-tools = { version = "0.10.0", default-features = false }
itertools = "0.13.0"
mockall = { version = "0.12", default-features = false }
prometheus = { version = "0.13", default-features = false }
rand = { version = "0.8", default-features = false }
rlp = { version = "0.5.2" }
secp256k1 = { version = "0.27.0", features = ["recovery", "global-context"] }
serde = { version = "1.0", default-features = false }
serde_json = { version = "1.0", default-features = false }
sqlx = { version = "0.7.4", default-features = false }
Expand Down
16 changes: 16 additions & 0 deletions committer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ pub struct Config {
pub app: App,
}

impl Config {
pub fn validate(&self) -> crate::errors::Result<()> {
if let Some(blob_pool_wallet_key) = &self.eth.blob_pool_wallet_key {
if blob_pool_wallet_key == &self.eth.wallet_key {
return Err(crate::errors::Error::Other(
"Wallet key and blob pool wallet key must be different".to_string(),
));
}
}

Ok(())
}
}

#[derive(Debug, Clone, Deserialize)]
pub struct Fuel {
/// URL to a fuel-core graphql endpoint.
Expand All @@ -26,6 +40,8 @@ pub struct Fuel {
pub struct Eth {
/// The secret key authorized by the L1 bridging contracts to post block commitments.
pub wallet_key: String,
/// The secret key for posting L2 state to L1.
pub blob_pool_wallet_key: Option<String>,
/// URL to a Ethereum RPC endpoint.
#[serde(deserialize_with = "parse_url")]
pub rpc: Url,
Expand Down
42 changes: 32 additions & 10 deletions committer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ async fn main() -> Result<()> {
setup::logger();

let config = config::parse()?;
config.validate()?;

let storage = setup::storage(&config).await?;

Expand Down Expand Up @@ -49,20 +50,48 @@ async fn main() -> Result<()> {
commit_interval,
ethereum_rpc.clone(),
storage.clone(),
fuel_adapter,
fuel_adapter.clone(),
&config,
&metrics_registry,
cancel_token.clone(),
);

let listener_handle = setup::l1_event_listener(
&internal_config,
ethereum_rpc,
ethereum_rpc.clone(),
storage.clone(),
&metrics_registry,
cancel_token.clone(),
);

let mut handles = vec![
wallet_balance_tracker_handle,
committer_handle,
listener_handle,
];

// If the blob pool wallet key is set, we need to start the state committer and state importer
if config.eth.blob_pool_wallet_key.is_some() {
let state_committer_handle = setup::state_committer(
ethereum_rpc,
storage.clone(),
&metrics_registry,
cancel_token.clone(),
&config,
);

let state_importer_handle = setup::state_importer(
fuel_adapter,
storage.clone(),
&metrics_registry,
cancel_token.clone(),
&config,
);

handles.push(state_committer_handle);
handles.push(state_importer_handle);
}

launch_api_server(
&config,
metrics_registry,
Expand All @@ -72,14 +101,7 @@ async fn main() -> Result<()> {
)
.await?;

shut_down(
cancel_token,
wallet_balance_tracker_handle,
committer_handle,
listener_handle,
storage,
)
.await
shut_down(cancel_token, handles, storage).await
}

#[cfg(test)]
Expand Down
46 changes: 38 additions & 8 deletions committer/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,41 @@ pub fn block_committer(
)
}

pub fn state_committer(
l1: L1,
storage: impl Storage + 'static,
_registry: &Registry,
cancel_token: CancellationToken,
config: &config::Config,
) -> tokio::task::JoinHandle<()> {
let state_committer = services::StateCommitter::new(l1, storage);

schedule_polling(
config.app.block_check_interval,
state_committer,
"State Committer",
cancel_token,
)
}

pub fn state_importer(
fuel: FuelApi,
storage: impl Storage + 'static,
_registry: &Registry,
cancel_token: CancellationToken,
config: &config::Config,
) -> tokio::task::JoinHandle<()> {
let validator = BlockValidator::new(config.fuel.block_producer_public_key);
let state_importer = services::StateImporter::new(storage, fuel, validator);

schedule_polling(
config.app.block_check_interval,
state_importer,
"State Importer",
cancel_token,
)
}

pub async fn l1_adapter(
config: &config::Config,
internal_config: &config::Internal,
Expand All @@ -80,6 +115,7 @@ pub async fn l1_adapter(
config.eth.chain_id,
config.eth.state_contract_address,
&config.eth.wallet_key,
config.eth.blob_pool_wallet_key.clone(),
internal_config.eth_errors_before_unhealthy,
)
.await?;
Expand Down Expand Up @@ -148,18 +184,12 @@ pub async fn storage(config: &config::Config) -> Result<Database> {

pub async fn shut_down(
cancel_token: CancellationToken,
wallet_balance_tracker_handle: JoinHandle<()>,
committer_handle: JoinHandle<()>,
listener_handle: JoinHandle<()>,
handles: Vec<JoinHandle<()>>,
storage: Database,
) -> Result<()> {
cancel_token.cancel();

for handle in [
wallet_balance_tracker_handle,
committer_handle,
listener_handle,
] {
for handle in handles {
handle.await?;
}

Expand Down
9 changes: 5 additions & 4 deletions configurations/development/config.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[eth]
wallet_key = "0x9e56ccf010fa4073274b8177ccaad46fbaf286645310d03ac9bb6afa922a7c36"
chain_id = "hardhat"
state_contract_address = "0xdAad669b06d79Cb48C8cfef789972436dBe6F24d"
rpc = "ws://localhost:8089"
wallet_key = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
blob_pool_wallet_key = "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"
chain_id = "anvil"
state_contract_address = "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9"
rpc = "ws://localhost:8545"

[fuel]
graphql_endpoint = "http://localhost:4000"
Expand Down
1 change: 1 addition & 0 deletions e2e/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod tests {
Chain::AnvilHardhat,
"0xdAad669b06d79Cb48C8cfef789972436dBe6F24d".parse()?,
"0x9e56ccf010fa4073274b8177ccaad46fbaf286645310d03ac9bb6afa922a7c36",
None,
10,
)
.await?;
Expand Down
3 changes: 3 additions & 0 deletions packages/eth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ rust-version = { workspace = true }

[dependencies]
async-trait = { workspace = true }
c-kzg = { workspace = true }
ethers = { workspace = true, features = ["ws"] }
futures = { workspace = true }
itertools = { workspace = true }
metrics = { workspace = true }
ports = { workspace = true, features = ["l1"] }
rlp = { workspace = true }
serde_json = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
Expand Down
5 changes: 5 additions & 0 deletions packages/eth/src/eip_4844.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod types;
mod utils;

pub use types::*;
pub use utils::*;
Loading
Loading