forked from paradigmxyz/reth
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from weaveVM/exex-archiver
Exex archiver
- Loading branch information
Showing
8 changed files
with
1,492 additions
and
36 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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 |
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,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); | ||
} | ||
} |
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