From 7836e4c1b2ccdd1275318801f6eed930d966d1ad Mon Sep 17 00:00:00 2001 From: tac0turtle Date: Wed, 16 Jul 2025 17:20:08 +0200 Subject: [PATCH 1/2] use bytes instead of strings --- README.md | 8 ++++---- crates/rollkit/src/rpc/txpool.rs | 13 ++++++------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index c926c514..4204acb5 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Modified Engine API validator that: Custom RPC namespace `txpoolExt` that provides: -- `txpoolExt_getTxs`: Retrieves pending transactions from the pool as RLP-encoded hex strings +- `txpoolExt_getTxs`: Retrieves pending transactions from the pool as RLP-encoded bytes - Configurable byte limit for transaction retrieval (default: 1.98 MB) - Efficient iteration that stops when reaching the byte limit @@ -129,8 +129,8 @@ curl -X POST http://localhost:8545 \ { "jsonrpc": "2.0", "result": [ - "0xf86d...", // RLP-encoded transaction 1 - "0xf86e...", // RLP-encoded transaction 2 + "0xf86d...", // RLP-encoded transaction bytes 1 + "0xf86e...", // RLP-encoded transaction bytes 2 // ... more transactions up to the byte limit ], "id": 1 @@ -177,7 +177,7 @@ This modular design allows for: 5. **Rollkit Txpool RPC** (`crates/rollkit/src/rpc/txpool.rs`) - Custom RPC implementation for transaction pool queries - Efficient transaction retrieval with size-based limits - - Returns RLP-encoded transactions for Rollkit consumption + - Returns RLP-encoded transaction bytes for Rollkit consumption ### Transaction Flow diff --git a/crates/rollkit/src/rpc/txpool.rs b/crates/rollkit/src/rpc/txpool.rs index 46cd6a7c..ee34a93a 100644 --- a/crates/rollkit/src/rpc/txpool.rs +++ b/crates/rollkit/src/rpc/txpool.rs @@ -1,4 +1,4 @@ -use alloy_primitives::hex::encode as hex_encode; +use alloy_primitives::{hex::encode as hex_encode, Bytes}; use alloy_rlp::Encodable; use async_trait::async_trait; use jsonrpsee_core::RpcResult; @@ -10,7 +10,7 @@ use reth_transaction_pool::{TransactionPool, ValidPoolTransaction}; pub trait RollkitTxpoolApi { /// Get transactions from the pool up to the configured `max_bytes` limit #[method(name = "getTxs")] - async fn get_txs(&self) -> RpcResult>; + async fn get_txs(&self) -> RpcResult>; } /// Implementation of the Rollkit txpool RPC API @@ -46,12 +46,12 @@ where Pool: TransactionPool + Send + Sync + 'static, { /// Returns a Geth-style `TxpoolContent` with raw RLP hex strings. - async fn get_txs(&self) -> RpcResult> { + async fn get_txs(&self) -> RpcResult> { //------------------------------------------------------------------// // 1. Iterate pending txs and stop once we hit the byte cap // //------------------------------------------------------------------// let mut total = 0u64; - let mut pending_map: Vec = Vec::new(); + let mut pending_map: Vec = Vec::new(); for arc_tx in self.pool.pending_transactions() { // deref Arc> @@ -65,10 +65,9 @@ where // inside the loop let tx = pooled.to_consensus(); let mut rlp_bytes = Vec::new(); - tx.encode(&mut rlp_bytes); // encode into Vec - let rlp_hex = format!("0x{}", hex_encode(&rlp_bytes)); + tx.encode(&mut rlp_bytes); - pending_map.push(rlp_hex); + pending_map.push(Bytes::from(rlp_bytes)); total += sz; } From 4cb90f44fab8df0ab6e191728ea68003045fc7ad Mon Sep 17 00:00:00 2001 From: tac0turtle Date: Wed, 16 Jul 2025 17:21:54 +0200 Subject: [PATCH 2/2] clippy --- crates/rollkit/src/rpc/txpool.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/rollkit/src/rpc/txpool.rs b/crates/rollkit/src/rpc/txpool.rs index ee34a93a..0a83aa30 100644 --- a/crates/rollkit/src/rpc/txpool.rs +++ b/crates/rollkit/src/rpc/txpool.rs @@ -1,4 +1,4 @@ -use alloy_primitives::{hex::encode as hex_encode, Bytes}; +use alloy_primitives::Bytes; use alloy_rlp::Encodable; use async_trait::async_trait; use jsonrpsee_core::RpcResult;