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

chore: Implement tags, refactor exex notification pooler #110

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
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
7 changes: 5 additions & 2 deletions Cargo.lock

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

9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ members = [
"wvm-apps/wvm-exexed/crates/lambda/",
"wvm-apps/wvm-exexed/crates/precompiles/",
"wvm-apps/wvm-exexed/crates/wvm-borsh/",
"wvm-apps/wvm-exexed/crates/static/",
"crates/wvm-static/",
"wvm-apps/wvm-exexed/crates/brotli/",
"wvm-apps/wvm-exexed/crates/tx/",
]
Expand Down Expand Up @@ -396,7 +396,7 @@ reth-rpc-api = { path = "crates/rpc/rpc-api" }
reth-rpc-api-testing-util = { path = "crates/rpc/rpc-testing-util" }
reth-rpc-builder = { path = "crates/rpc/rpc-builder" }
reth-rpc-engine-api = { path = "crates/rpc/rpc-engine-api" }
reth-rpc-eth-api = { path = "crates/rpc/rpc-eth-api" }
reth-rpc-eth-api = { path = "crates/rpc/rpc-eth-api", features = ["client"] }
reth-rpc-eth-types = { path = "crates/rpc/rpc-eth-types", default-features = false }
reth-rpc-layer = { path = "crates/rpc/rpc-layer" }
reth-rpc-server-types = { path = "crates/rpc/rpc-server-types" }
Expand All @@ -418,6 +418,9 @@ reth-trie-common = { path = "crates/trie/common" }
reth-trie-db = { path = "crates/trie/db" }
reth-trie-parallel = { path = "crates/trie/parallel" }

# wvm
wvm-static = { path = "crates/wvm-static" }

# revm
revm = { git = "https://github.com/weaveVM/wvm-revm", branch = "main", features = [
"std",
Expand Down Expand Up @@ -608,7 +611,7 @@ brotlic = "0.8.2"

# exex-templates
exex-wvm-da = { git = "https://github.com/weaveVM/exex-templates?a", branch = "main" }
exex-wvm-bigquery = { git = "https://github.com/weaveVM/exex-templates?b", branch = "main" }
exex-wvm-bigquery = { git = "https://github.com/weaveVM/exex-templates?e", branch = "main" }

# fees
fees = { git = "https://github.com/weaveVM/miscalleneous?c", branch = "main" }
Expand Down
5 changes: 5 additions & 0 deletions crates/rpc/rpc-eth-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ auto_impl.workspace = true
dyn-clone.workspace = true
tracing.workspace = true

# wvm
wvm-static.workspace = true
serde.workspace = true
serde_json.workspace = true

[features]
js-tracer = ["revm-inspectors/js-tracer", "reth-rpc-eth-types/js-tracer"]
client = ["jsonrpsee/client", "jsonrpsee/async-client"]
13 changes: 12 additions & 1 deletion crates/rpc/rpc-eth-api/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use jsonrpsee::{core::RpcResult, proc_macros::rpc};
use reth_primitives::{BlockId, BlockNumberOrTag};
use reth_rpc_server_types::{result::internal_rpc_err, ToRpcResult};
use tracing::trace;

use reth_rpc_eth_types::wvm::WvmTransactionRequest;
use crate::{
helpers::{EthApiSpec, EthBlocks, EthCall, EthFees, EthState, EthTransactions, FullEthApi},
RpcBlock, RpcReceipt, RpcTransaction,
Expand Down Expand Up @@ -332,6 +332,11 @@ pub trait EthApi<T: RpcObject, B: RpcObject, R: RpcObject> {
#[method(name = "sendTransaction")]
async fn send_transaction(&self, request: TransactionRequest) -> RpcResult<B256>;

/// Sends WVM transaction; will block waiting for signer to return the
/// transaction hash.
#[method(name = "sendWvmTransaction")]
async fn send_wvm_transaction(&self, request: WvmTransactionRequest) -> RpcResult<B256>;

/// Sends signed transaction, returning its hash.
#[method(name = "sendRawTransaction")]
async fn send_raw_transaction(&self, bytes: Bytes) -> RpcResult<B256>;
Expand Down Expand Up @@ -767,6 +772,12 @@ where
Ok(EthTransactions::send_transaction(self, request).await?)
}

/// Handler for: `eth_sendWvmTransaction`
async fn send_wvm_transaction(&self, request: WvmTransactionRequest) -> RpcResult<B256> {
trace!(target: "rpc::eth", ?request, "Serving eth_sendWvmTransaction");
Ok(EthTransactions::send_wvm_transaction(self, request).await?)
}

/// Handler for: `eth_sendRawTransaction`
async fn send_raw_transaction(&self, tx: Bytes) -> RpcResult<B256> {
trace!(target: "rpc::eth", ?tx, "Serving eth_sendRawTransaction");
Expand Down
40 changes: 39 additions & 1 deletion crates/rpc/rpc-eth-api/src/helpers/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Database access for `eth_` transaction RPC methods. Loads transaction and receipt data w.r.t.
//! network.

use std::time::{SystemTime, UNIX_EPOCH};
use alloy_dyn_abi::TypedData;
use alloy_eips::eip2718::Encodable2718;
use alloy_network::TransactionBuilder;
Expand All @@ -16,9 +17,11 @@ use reth_rpc_eth_types::{
utils::{binary_search, recover_raw_transaction},
EthApiError, EthStateCache, SignError, TransactionSource,
};
use reth_rpc_eth_types::wvm::WvmTransactionRequest;
use reth_rpc_types_compat::transaction::{from_recovered, from_recovered_with_block_context};
use reth_transaction_pool::{PoolTransaction, TransactionOrigin, TransactionPool};

use serde::Serialize;
use wvm_static::PRECOMPILE_WVM_BIGQUERY_CLIENT;
use crate::{FromEthApiError, FullEthApiTypes, IntoEthApiError, RpcReceipt, RpcTransaction};

use super::{
Expand Down Expand Up @@ -336,6 +339,41 @@ pub trait EthTransactions: LoadTransaction {
}
}

fn send_wvm_transaction(&self, mut request: WvmTransactionRequest) -> impl Future<Output = Result<B256, Self::Error>> + Send
where
Self: EthApiSpec + LoadBlock + LoadPendingBlock + Call, {

// WVM
let bq_client = (&*PRECOMPILE_WVM_BIGQUERY_CLIENT).clone();

async move {
let tags = request.tags;
let hash = self.send_raw_transaction(request.tx).await?;
let created_at = {
let now = SystemTime::now();
let since_epoch = now.duration_since(UNIX_EPOCH).expect("Time went backwards");
since_epoch.as_millis()
};

#[derive(Serialize)]
struct TagsTbl {
hash: String,
tags: String,
created_at: u128
}

bq_client.insert_generic("tags", None, TagsTbl {
hash: hash.to_string(),
tags: serde_json::to_string(&tags).unwrap(),
created_at
}).await
.map_err(|_| EthApiError::InternalEthError)?;

Ok(hash)
}

}

/// Signs transaction with a matching signer, if any and submits the transaction to the pool.
/// Returns the hash of the signed transaction.
fn send_transaction(
Expand Down
1 change: 1 addition & 0 deletions crates/rpc/rpc-eth-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub mod revm_utils;
pub mod simulate;
pub mod transaction;
pub mod utils;
pub mod wvm;

pub use builder::{
config::{EthConfig, EthFilterConfig},
Expand Down
13 changes: 13 additions & 0 deletions crates/rpc/rpc-eth-types/src/wvm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use alloy_primitives::Bytes;
use alloy_rpc_types_eth::TransactionRequest;
use jsonrpsee_core::Serialize;
use serde::Deserialize;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WvmTransactionRequest {
pub tx: Bytes,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub tags: Option<Vec<(String, String)>>
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ exex-wvm-bigquery.workspace = true
tracing.workspace = true
serde_json.workspace = true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as I understood it's some kind of Ar provider? maybe name crate like this?
and in future we can just add new specific crates which should be in the node internals itself

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just very cautious with packages which have names Ala "common" :D

tokio.workspace = true
tokio-util = { version = "0.7.12", features = ["full"] }
once_cell = { version = "1.20.2" }
tokio-util = { workspace = true, features = ["full"] }
once_cell = { workspace = true }
2 changes: 1 addition & 1 deletion wvm-apps/wvm-exexed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ lambda = { path = "crates/lambda" }
arweave-upload = { path = "crates/arweave-upload" }
precompiles = { path = "crates/precompiles" }
wvm-borsh = { path = "crates/wvm-borsh" }
wvm-static = { path = "crates/static" }
wvm-static.workspace = true
exex-etl = { path = "crates/exex-etl" }
rbrotli = { path = "crates/brotli" }
wvm-tx = { path = "crates/tx" }
Expand Down
2 changes: 1 addition & 1 deletion wvm-apps/wvm-exexed/crates/precompiles/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ tokio.workspace = true
reqwest-graphql = "1.0.0"
rbrotli = { path = "../brotli" }
wvm-borsh = { path = "../wvm-borsh", name = "wvm-borsh" }
wvm-static = { path = "../static" }
wvm-static = { path = "../../../../crates/wvm-static" }
borsh.workspace = true
alloy-primitives.workspace = true
reth-evm-ethereum.workspace = true
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 @@ -22,7 +22,7 @@ lambda = { path = "../lambda" }
arweave-upload = { path = "../arweave-upload" }
precompiles = { path = "../precompiles" }
rbrotli = { path = "../brotli" }
wvm-static = { path = "../static" }
wvm-static = { path = "../../../../crates/wvm-static" }
tokio.workspace = true
exex-wvm-da.workspace = true
exex-wvm-bigquery.workspace = true
Expand Down
Loading
Loading