Skip to content

Commit

Permalink
chore: Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
andreespirela committed Sep 12, 2024
1 parent 81754f0 commit 1dff4b9
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 61 deletions.
17 changes: 9 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ members = [
"wvm-apps/wvm-exexed/crates/wevm-borsh/",
"wvm-apps/wvm-exexed/crates/types/",
"wvm-apps/wvm-exexed/crates/brotli/",
"wvm-apps/wvm-exexed/crates/exex-archiver/",
"wvm-apps/wvm-exexed/crates/exex-wvm-da/",
]
default-members = ["bin/reth"]

Expand Down
2 changes: 1 addition & 1 deletion wvm-apps/wvm-exexed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
brotlic.workspace = true

exex-archiver = { path = "crates/exex-archiver" }
exex-wvm-da = { path = "crates/exex-wvm-da" }
repository = { path = "crates/repository" }
bigquery = { path = "crates/bigquery" }
lambda = { path = "crates/lambda" }
Expand Down
47 changes: 0 additions & 47 deletions wvm-apps/wvm-exexed/crates/exex-archiver/src/lib.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "exex-archiver"
name = "exex-wvm-da"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
Expand Down Expand Up @@ -27,4 +27,7 @@ rbrotli = { path = "../brotli" }
wevm-borsh = { path = "../wevm-borsh", name = "wevm-borsh" }
borsh.workspace = true
async-trait = "0.1.82"
wvm-archiver = { git = "https://github.com/weaveVM/wvm-archiver?a=true", branch = "main" }
wvm-archiver = { git = "https://github.com/weaveVM/wvm-archiver?a=true", branch = "main" }

[dev-dependencies]
reth-exex-test-utils.workspace = true
96 changes: 96 additions & 0 deletions wvm-apps/wvm-exexed/crates/exex-wvm-da/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
use eyre::{Error, Report};
use rbrotli::to_brotli;
use reth::api::FullNodeComponents;
use reth::primitives::SealedBlockWithSenders;
use reth_exex::ExExContext;
use wevm_borsh::block::BorshSealedBlockWithSenders;
use async_trait::async_trait;
use wvm_archiver::utils::transaction::send_wvm_calldata;

pub struct DefaultWvmDataSettler;

pub enum WvmDataSettlerError {
InvalidSendRequest,
}

#[async_trait]
pub trait WvmDataSettler {

fn process_block(&self, data: &SealedBlockWithSenders) -> Result<Vec<u8>, Error> {
let clone_block = BorshSealedBlockWithSenders(data.clone());
let borsh_data = borsh::to_vec(&clone_block)?;
let brotli_borsh = to_brotli(borsh_data);
Ok(brotli_borsh)
}

async fn send_wvm_calldata(&mut self, block_data: Vec<u8>) -> Result<String, WvmDataSettlerError> {
send_wvm_calldata(block_data).await.map_err(|_| WvmDataSettlerError::InvalidSendRequest)
}

async fn exex<Node: FullNodeComponents>(
&mut self,
mut ctx: ExExContext<Node>
) -> eyre::Result<()> {
while let Some(notification) = ctx.notifications.recv().await {
if let Some(committed_chain) = notification.committed_chain() {
let sealed_block_with_senders = committed_chain.tip();
let block_data = self.process_block(sealed_block_with_senders)?;
self.send_wvm_calldata(block_data).await.map_err(|e| Report::msg("Invalid Settle Request"))?;
}
}

Ok(())
}

}

impl WvmDataSettler for DefaultWvmDataSettler {}

#[cfg(test)]
mod tests {
use std::sync::{Arc, RwLock};
use async_trait::async_trait;
use tokio::sync::mpsc;
use tokio::sync::mpsc::unbounded_channel;
use reth::providers::Chain;
use reth_exex::{ExExContext, ExExNotification};
use reth_exex_test_utils::test_exex_context;
use reth_node_ethereum::EthereumNode;
use crate::{WvmDataSettler, WvmDataSettlerError};

#[tokio::test]
pub async fn test_wvm_da() {


struct TestWvmDa {
called: bool
}

#[async_trait]
impl WvmDataSettler for TestWvmDa {
async fn send_wvm_calldata(&mut self, block_data: Vec<u8>) -> Result<String, WvmDataSettlerError> {
self.called = true;
Ok("hello world".to_string())
}
}

let context = test_exex_context().await.unwrap();

let chain_def = Chain::from_block(Default::default(), Default::default(), None);


context.1.notifications_tx.send(ExExNotification::ChainCommitted {
new: Arc::new(chain_def)
}).await.unwrap();

let mut wvm_da = TestWvmDa {
called: false
};

drop(context.1);

wvm_da.exex(context.0).await.unwrap();

assert!(wvm_da.called);
}
}
2 changes: 1 addition & 1 deletion wvm-apps/wvm-exexed/crates/reth-exexed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ reth-primitives.workspace = true
eyre.workspace = true
borsh.workspace = true
serde_json.workspace = true
exex-archiver = { path = "../exex-archiver" }
exex-wvm-da = { path = "../exex-wvm-da" }
wevm-borsh = { path = "../wevm-borsh", name = "wevm-borsh" }
repository = { path = "../repository" }
bigquery = { path = "../bigquery" }
Expand Down
2 changes: 1 addition & 1 deletion wvm-apps/wvm-exexed/crates/reth-exexed/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use reth_node_ethereum::{
};
use reth_tracing::tracing::info;
use serde_json::to_string;
use exex_archiver::{DefaultWvmDataSettler, WvmDataSettler};
use exex_wvm_da::{DefaultWvmDataSettler, WvmDataSettler};
use types::types::ExecutionTipState;
use wevm_borsh::block::BorshSealedBlockWithSenders;

Expand Down

0 comments on commit 1dff4b9

Please sign in to comment.