Skip to content

Commit

Permalink
Merge pull request #59 from weaveVM/exex-archiver
Browse files Browse the repository at this point in the history
Exex archiver
  • Loading branch information
andreespirela authored Sep 12, 2024
2 parents dbd439c + 1dff4b9 commit 13bfc22
Show file tree
Hide file tree
Showing 8 changed files with 1,492 additions and 36 deletions.
1,386 changes: 1,355 additions & 31 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +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-wvm-da/",
]
default-members = ["bin/reth"]

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

exex-wvm-da = { path = "crates/exex-wvm-da" }
repository = { path = "crates/repository" }
bigquery = { path = "crates/bigquery" }
lambda = { path = "crates/lambda" }
Expand Down
33 changes: 33 additions & 0 deletions wvm-apps/wvm-exexed/crates/exex-wvm-da/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[package]
name = "exex-wvm-da"
version.workspace = true
edition.workspace = true
rust-version.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
parking_lot.workspace = true
schnellru.workspace = true
reth-revm.workspace = true
reth-chainspec.workspace = true
reth-ethereum-engine-primitives.workspace = true
reth.workspace = true
reth-exex.workspace = true
revm-primitives.workspace = true
reth-node-ethereum.workspace = true
reth-tracing.workspace = true
serde_json.workspace = true
serde.workspace = true
reqwest.workspace = true
eyre.workspace = true
tokio.workspace = true
reqwest-graphql = "1.0.0"
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" }

[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);
}
}
1 change: 1 addition & 0 deletions wvm-apps/wvm-exexed/crates/reth-exexed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ reth-primitives.workspace = true
eyre.workspace = true
borsh.workspace = true
serde_json.workspace = true
exex-wvm-da = { path = "../exex-wvm-da" }
wevm-borsh = { path = "../wevm-borsh", name = "wevm-borsh" }
repository = { path = "../repository" }
bigquery = { path = "../bigquery" }
Expand Down
6 changes: 3 additions & 3 deletions wvm-apps/wvm-exexed/crates/reth-exexed/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use reth_node_ethereum::{
};
use reth_tracing::tracing::info;
use serde_json::to_string;
use exex_wvm_da::{DefaultWvmDataSettler, WvmDataSettler};
use types::types::ExecutionTipState;
use wevm_borsh::block::BorshSealedBlockWithSenders;

Expand Down Expand Up @@ -53,10 +54,9 @@ async fn exex_etl_processor<Node: FullNodeComponents>(
}

if let Some(committed_chain) = notification.committed_chain() {
let data_settler = DefaultWvmDataSettler;
let sealed_block_with_senders = committed_chain.tip();
let clone_block = BorshSealedBlockWithSenders(sealed_block_with_senders.clone());
let borsh_data = borsh::to_vec(&clone_block)?;
let brotli_borsh = to_brotli(borsh_data);
let brotli_borsh = data_settler.process_block(sealed_block_with_senders)?;
let json_str = to_string(&sealed_block_with_senders)?;

let blk_str_hash = sealed_block_with_senders.block.hash().to_string();
Expand Down
4 changes: 2 additions & 2 deletions wvm-apps/wvm-exexed/crates/reth-exexed/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ mod tests {
#[tokio::test]
async fn test_check_block_existence() {
let block_1 = check_block_existence(
"0xd579c6931a9d1744b2540eeb540540a5582f6befebc59871b1ba4a4d967bd794",
"0x2685fbb2e5b93cea32e7e51334d3cc746e1a6790b901eddb3df8214be18899a1",
)
.await;
let block_2 = check_block_existence(
"0xd579c6931a9d1744b2540eeb540540a5582f6befebc59871b1ba4a4d967bd793",
"0x2685fbb2e5b93cea32e7e51334d3cc746e1a6790b901eddb3df8214be18899a2",
)
.await;
assert!(block_1);
Expand Down

0 comments on commit 13bfc22

Please sign in to comment.