Skip to content

Commit

Permalink
small refac in rpc crate (#6264)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger authored Jan 28, 2024
1 parent f56ee79 commit 5b3ce67
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 34 deletions.
35 changes: 17 additions & 18 deletions crates/rpc/rpc/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ use reth_primitives::{
use reth_provider::{
BlockReaderIdExt, ChainSpecProvider, HeaderProvider, StateProviderBox, TransactionVariant,
};
use revm_inspectors::tracing::{
js::{JsInspector, TransactionContext},
FourByteInspector, TracingInspector, TracingInspectorConfig,
};

use reth_revm::database::{StateProviderDatabase, SubState};
use reth_rpc_api::DebugApiServer;
use reth_rpc_types::{
Expand All @@ -36,7 +31,10 @@ use reth_rpc_types::{
BlockError, Bundle, CallRequest, RichBlock, StateContext,
};
use revm::{db::CacheDB, primitives::Env};

use revm_inspectors::tracing::{
js::{JsInspector, TransactionContext},
FourByteInspector, TracingInspector, TracingInspectorConfig,
};
use std::sync::Arc;
use tokio::sync::{AcquireError, OwnedSemaphorePermit};

Expand Down Expand Up @@ -640,18 +638,19 @@ where

/// Handler for `debug_getRawReceipts`
async fn raw_receipts(&self, block_id: BlockId) -> RpcResult<Vec<Bytes>> {
let receipts =
self.inner.provider.receipts_by_block_id(block_id).to_rpc_result()?.unwrap_or_default();
let mut all_receipts = Vec::with_capacity(receipts.len());

for receipt in receipts {
let mut buf = Vec::new();
let receipt = receipt.with_bloom();
receipt.encode(&mut buf);
all_receipts.push(buf.into());
}

Ok(all_receipts)
Ok(self
.inner
.provider
.receipts_by_block_id(block_id)
.to_rpc_result()?
.unwrap_or_default()
.into_iter()
.map(|receipt| {
let mut buf = Vec::new();
receipt.with_bloom().encode(&mut buf);
Bytes::from(buf)
})
.collect())
}

/// Handler for `debug_getBadBlocks`
Expand Down
29 changes: 13 additions & 16 deletions crates/rpc/rpc/src/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ where
tx: &T,
content: &mut BTreeMap<Address, BTreeMap<String, Transaction>>,
) {
let entry = content.entry(tx.sender()).or_default();
let key = tx.nonce().to_string();
let tx = tx.to_recovered_transaction();
let tx = reth_rpc_types_compat::transaction::from_recovered(tx);
entry.insert(key, tx);
content.entry(tx.sender()).or_default().insert(
tx.nonce().to_string(),
reth_rpc_types_compat::transaction::from_recovered(tx.to_recovered_transaction()),
);
}

let AllPoolTransactions { pending, queued } = self.pool.all_transactions();
Expand Down Expand Up @@ -93,17 +92,15 @@ where
let entry = inspect.entry(tx.sender()).or_default();
let key = tx.nonce().to_string();
let tx = tx.to_recovered_transaction();
let to = tx.to();
let gas_price = tx.transaction.max_fee_per_gas();
let value = tx.value();
let gas = tx.gas_limit();
let summary = TxpoolInspectSummary {
to,
value: value.into(),
gas: U256::from(gas),
gas_price: U256::from(gas_price),
};
entry.insert(key, summary);
entry.insert(
key,
TxpoolInspectSummary {
to: tx.to(),
value: tx.value().into(),
gas: U256::from(tx.gas_limit()),
gas_price: U256::from(tx.transaction.max_fee_per_gas()),
},
);
}

let mut inspect = TxpoolInspect::default();
Expand Down

0 comments on commit 5b3ce67

Please sign in to comment.