Skip to content
Closed
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
3 changes: 2 additions & 1 deletion crates/e2e-test-utils/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ where
where
AddOns::EthApi: EthApiSpec<Provider: BlockReader<Block = BlockTy<Node::Types>>>
+ EthTransactions
+ TraceExt,
+ TraceExt
+ reth_rpc_eth_api::RpcNodeCore<Provider = Node::Provider>,
{
let mut chain = Vec::with_capacity(length as usize);
for i in 0..length {
Expand Down
3 changes: 2 additions & 1 deletion crates/e2e-test-utils/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ where
Node: FullNodeComponents<Types: NodeTypes<ChainSpec: EthereumHardforks>>,
EthApi: EthApiSpec<Provider: BlockReader<Block = BlockTy<Node::Types>>>
+ EthTransactions
+ TraceExt,
+ TraceExt
+ reth_rpc_eth_api::RpcNodeCore<Provider = Node::Provider>,
{
/// Injects a raw transaction into the node tx pool via RPC server
pub async fn inject_tx(&self, raw_tx: Bytes) -> Result<B256, EthApi::Error> {
Expand Down
19 changes: 19 additions & 0 deletions crates/node/builder/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{
};
use alloy_rpc_types::engine::ClientVersionV1;
use alloy_rpc_types_engine::ExecutionData;
use futures::StreamExt;
use jsonrpsee::{core::middleware::layer::Either, RpcModule};
use reth_chain_state::CanonStateSubscriptions;
use reth_chainspec::{ChainSpecProvider, EthChainSpec, EthereumHardforks, Hardforks};
Expand All @@ -23,6 +24,7 @@ use reth_node_core::{
version::{version_metadata, CLIENT_CODE},
};
use reth_payload_builder::{PayloadBuilderHandle, PayloadStore};
use reth_primitives_traits::RecoveredBlock;
use reth_rpc::{
eth::{core::EthRpcConverterFor, DevSigner, EthApiTypes, FullEthApiServer},
AdminApi,
Expand Down Expand Up @@ -1018,6 +1020,23 @@ where
registry.eth_api().signers().write().extend(signers);
}

// keep track of invalid blocks for `debug_getBadBlocks`
let bad_block_store = registry.bad_block_store().clone();
let mut engine_events_stream = engine_events.new_listener();
node.task_executor().spawn_critical(
Comment on lines +1023 to +1026
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is kinda redundant if we dont have the debug_ endpoint installed because then the blockstore wont be useable, but this doesnt really hurt anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have set a flag to enable blockstore only when debug_ endpoint installed

Comment on lines +1023 to +1026
Copy link
Collaborator

Choose a reason for hiding this comment

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

we can spawn this as regular task imo

"collect bad blocks",
Box::pin(async move {
while let Some(event) = engine_events_stream.next().await {
if let ConsensusEngineEvent::InvalidBlock(block) = event &&
let Ok(recovered) =
RecoveredBlock::try_recover_sealed(block.as_ref().clone())
{
bad_block_store.insert(recovered);
}
}
}),
);

let mut registry = RpcRegistry { registry };
let ctx = RpcContext {
node: node.clone(),
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc/rpc-api/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use alloy_genesis::ChainConfig;
use alloy_json_rpc::RpcObject;
use alloy_primitives::{Address, Bytes, B256};
use alloy_rpc_types_debug::ExecutionWitness;
use alloy_rpc_types_eth::{Block, Bundle, StateContext};
use alloy_rpc_types_eth::{BadBlock, Bundle, StateContext};
use alloy_rpc_types_trace::geth::{
BlockTraceResult, GethDebugTracingCallOptions, GethDebugTracingOptions, GethTrace, TraceResult,
};
Expand Down Expand Up @@ -38,7 +38,7 @@ pub trait DebugApi<TxReq: RpcObject> {

/// Returns an array of recent bad blocks that the client has seen on the network.
#[method(name = "getBadBlocks")]
async fn bad_blocks(&self) -> RpcResult<Vec<Block>>;
async fn bad_blocks(&self) -> RpcResult<Vec<BadBlock>>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can actually make this just serde_json::Value, seems easier or we use the actual rpc type see also

#[method(name = "getBlockByHash")]
async fn block_by_hash(&self, hash: B256, full: bool) -> RpcResult<Option<B>>;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah think we need to unify the block def in rpc here


/// Returns the structured logs created during the execution of EVM between two blocks
/// (excluding start) as a JSON object.
Expand Down
53 changes: 35 additions & 18 deletions crates/rpc/rpc-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ use reth_evm::ConfigureEvm;
use reth_network_api::{noop::NoopNetwork, NetworkInfo, Peers};
use reth_primitives_traits::{NodePrimitives, TxTy};
use reth_rpc::{
AdminApi, DebugApi, EngineEthApi, EthApi, EthApiBuilder, EthBundle, MinerApi, NetApi,
OtterscanApi, RPCApi, RethApi, TraceApi, TxPoolApi, ValidationApiConfig, Web3Api,
AdminApi, BadBlockStore, DebugApi, EngineEthApi, EthApi, EthApiBuilder, EthBundle, MinerApi,
NetApi, OtterscanApi, RPCApi, RethApi, TraceApi, TxPoolApi, ValidationApiConfig, Web3Api,
};
use reth_rpc_api::servers::*;
use reth_rpc_eth_api::{
Expand All @@ -52,8 +52,7 @@ use reth_rpc_eth_api::{
use reth_rpc_eth_types::{receipt::EthReceiptConverter, EthConfig, EthSubscriptionIdProvider};
use reth_rpc_layer::{AuthLayer, Claims, CompressionLayer, JwtAuthValidator, JwtSecret};
use reth_storage_api::{
AccountReader, BlockReader, ChangeSetReader, FullRpcProvider, ProviderBlock,
StateProviderFactory,
AccountReader, BlockReader, ChangeSetReader, FullRpcProvider, StateProviderFactory,
};
use reth_tasks::{pool::BlockingTaskGuard, TaskSpawner, TokioTaskExecutor};
use reth_transaction_pool::{noop::NoopTransactionPool, TransactionPool};
Expand Down Expand Up @@ -332,7 +331,8 @@ where
RpcRegistryInner<Provider, Pool, Network, EthApi, EvmConfig, Consensus>,
)
where
EthApi: FullEthApiServer<Provider = Provider, Pool = Pool>,
EthApi:
FullEthApiServer<Provider = Provider, Pool = Pool> + RpcNodeCore<Provider = Provider>,
{
let Self { provider, pool, network, executor, consensus, evm_config, .. } = self;

Expand All @@ -359,7 +359,7 @@ where
eth: EthApi,
) -> RpcRegistryInner<Provider, Pool, Network, EthApi, EvmConfig, Consensus>
where
EthApi: EthApiTypes + 'static,
EthApi: EthApiTypes + RpcNodeCore<Provider = Provider> + 'static,
{
let Self { provider, pool, network, executor, consensus, evm_config, .. } = self;
RpcRegistryInner::new(provider, pool, network, executor, consensus, config, evm_config, eth)
Expand All @@ -373,7 +373,8 @@ where
eth: EthApi,
) -> TransportRpcModules<()>
where
EthApi: FullEthApiServer<Provider = Provider, Pool = Pool>,
EthApi:
FullEthApiServer<Provider = Provider, Pool = Pool> + RpcNodeCore<Provider = Provider>,
{
let mut modules = TransportRpcModules::default();

Expand Down Expand Up @@ -511,6 +512,8 @@ pub struct RpcRegistryInner<
modules: HashMap<RethRpcModule, Methods>,
/// eth config settings
eth_config: EthConfig,
/// Recent bad blocks observed by the node.
bad_block_store: BadBlockStore<Provider::Block>,
}

// === impl RpcRegistryInner ===
Expand All @@ -527,7 +530,7 @@ where
+ 'static,
Pool: Send + Sync + Clone + 'static,
Network: Clone + 'static,
EthApi: EthApiTypes + 'static,
EthApi: EthApiTypes + RpcNodeCore<Provider = Provider> + 'static,
EvmConfig: ConfigureEvm<Primitives = N>,
{
/// Creates a new, empty instance.
Expand Down Expand Up @@ -560,6 +563,7 @@ where
blocking_pool_guard,
eth_config: config.eth,
evm_config,
bad_block_store: BadBlockStore::default(),
}
}
}
Expand Down Expand Up @@ -595,6 +599,11 @@ where
&self.provider
}

/// Returns the bad block store.
pub const fn bad_block_store(&self) -> &BadBlockStore<Provider::Block> {
&self.bad_block_store
}

/// Returns all installed methods
pub fn methods(&self) -> Vec<Methods> {
self.modules.values().cloned().collect()
Expand Down Expand Up @@ -706,8 +715,7 @@ where
/// If called outside of the tokio runtime. See also [`Self::eth_api`]
pub fn register_debug(&mut self) -> &mut Self
where
EthApi: EthApiSpec + EthTransactions + TraceExt,
EvmConfig::Primitives: NodePrimitives<Block = ProviderBlock<EthApi::Provider>>,
EthApi: EthApiSpec + EthTransactions + TraceExt + RpcNodeCore<Provider = Provider>,
{
let debug_api = self.debug_api();
self.modules.insert(RethRpcModule::Debug, debug_api.into_rpc().into());
Expand Down Expand Up @@ -814,8 +822,15 @@ where
/// # Panics
///
/// If called outside of the tokio runtime. See also [`Self::eth_api`]
pub fn debug_api(&self) -> DebugApi<EthApi> {
DebugApi::new(self.eth_api().clone(), self.blocking_pool_guard.clone())
pub fn debug_api(&self) -> DebugApi<EthApi>
where
EthApi: EthApiTypes + RpcNodeCore<Provider = Provider>,
{
DebugApi::new(
self.eth_api().clone(),
self.blocking_pool_guard.clone(),
self.bad_block_store.clone(),
)
}

/// Instantiates `NetApi`
Expand Down Expand Up @@ -847,7 +862,7 @@ where
+ ChangeSetReader,
Pool: TransactionPool + Clone + 'static,
Network: NetworkInfo + Peers + Clone + 'static,
EthApi: FullEthApiServer,
EthApi: FullEthApiServer + RpcNodeCore<Provider = Provider>,
EvmConfig: ConfigureEvm<Primitives = N> + 'static,
Consensus: FullConsensus<N, Error = ConsensusError> + Clone + 'static,
{
Expand Down Expand Up @@ -933,11 +948,13 @@ where
)
.into_rpc()
.into(),
RethRpcModule::Debug => {
DebugApi::new(eth_api.clone(), self.blocking_pool_guard.clone())
.into_rpc()
.into()
}
RethRpcModule::Debug => DebugApi::new(
eth_api.clone(),
self.blocking_pool_guard.clone(),
self.bad_block_store.clone(),
)
.into_rpc()
.into(),
RethRpcModule::Eth => {
// merge all eth handlers
let mut module = eth_api.clone().into_rpc();
Expand Down
Loading
Loading