Skip to content

Commit

Permalink
Debug interfaces (#149)
Browse files Browse the repository at this point in the history
Co-authored-by: GabrielMartinezRodriguez <[email protected]>
Co-authored-by: Daniel Blanco Parla <[email protected]>
Co-authored-by: Gabriel Martínez Rodríguez <[email protected]>
  • Loading branch information
4 people authored Nov 15, 2023
1 parent 1a5a488 commit 485d219
Show file tree
Hide file tree
Showing 101 changed files with 6,998 additions and 153 deletions.
355 changes: 282 additions & 73 deletions Cargo.lock

Large diffs are not rendered by default.

23 changes: 21 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ bn = { package = "substrate-bn", version = "0.6", default-features = false }
environmental = { version = "1.1.4", default-features = false }
ethereum = { version = "0.14.0", default-features = false }
ethereum-types = { version = "0.14.1", default-features = false }
evm = { git = "https://github.com/rust-blockchain/evm", rev = "b7b82c7e1fc57b7449d6dfa6826600de37cc1e65", default-features = false }
jsonrpsee = "0.16.2"
kvdb-rocksdb = "0.19.0"
libsecp256k1 = { version = "0.7.1", default-features = false }
Expand Down Expand Up @@ -122,6 +121,7 @@ sc-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/parityt
sc-transaction-pool-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
sc-proposer-metrics = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"}
sc-offchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
sc-utils = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
# Substrate Primitive
sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false }
sp-block-builder = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false }
Expand Down Expand Up @@ -258,4 +258,23 @@ ark-bls12-377 = { version = "0.4.0", default-features = false, features = ["curv
ark-bw6-761 = { version = "0.4.0", default-features = false }
ark-ec = { version = "0.4.0", default-features = false }
ark-ff = { version = "0.4.0", default-features = false }
ark-std = { version = "0.4.0", default-features = false }
ark-std = { version = "0.4.0", default-features = false }

moonbeam-primitives-ext = { path = "vendor/primitives/ext", default-features = false }
moonbeam-evm-tracer = { path = "vendor/runtime/evm_tracer", default-features = false }
moonbeam-rpc-primitives-debug = { path = "vendor/primitives/rpc/debug", default-features = false }
evm-tracing-events = { path = "vendor/primitives/rpc/evm-tracing-events", default-features = false }
moonbeam-rpc-primitives-txpool = { path = "vendor/primitives/rpc/txpool", default-features = false }
evm = { git = "https://github.com/rust-blockchain/evm", rev = "b7b82c7e1fc57b7449d6dfa6826600de37cc1e65", default-features = false }
evm-gasometer = { git = "https://github.com/rust-blockchain/evm", rev = "b7b82c7e1fc57b7449d6dfa6826600de37cc1e65", default-features = false }
evm-runtime = { git = "https://github.com/rust-blockchain/evm", rev = "b7b82c7e1fc57b7449d6dfa6826600de37cc1e65", default-features = false }
moonbeam-rpc-debug = { path = "vendor/client/rpc/debug" }
moonbeam-rpc-trace = { path = "vendor/client/rpc/trace" }
moonbeam-rpc-txpool = { path = "vendor/client/rpc/txpool" }
moonbeam-client-evm-tracing = { path = "vendor/client/evm-tracing" }
moonbeam-rpc-core-debug = { path = "vendor/rpc-core/debug" }
moonbeam-rpc-core-trace = { path = "vendor/rpc-core/trace" }
moonbeam-rpc-core-types = { path = "vendor/rpc-core/types" }
moonbeam-rpc-core-txpool = { path = "vendor/rpc-core/txpool" }

substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
2 changes: 1 addition & 1 deletion client/authorship/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repository = "https://github.com/stabilityprotocol/stability/"
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { workspace = true, package = "parity-scale-codec" }
parity-scale-codec = { workspace = true }
futures = { workspace = true }
futures-timer = { workspace = true }
log = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion client/authorship/src/authorship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// FIXME #1021 move this into sp-consensus

use account::EthereumSigner;
use codec::Encode;
use parity_scale_codec::Encode;
use futures::{
channel::oneshot,
future,
Expand Down
1 change: 1 addition & 0 deletions docker/client/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ COPY primitives ./primitives
COPY client ./client
COPY stability-rpc ./stability-rpc
COPY test-utils ./test-utils
COPY vendor ./vendor
COPY chain-specs ./chain-specs
COPY Cargo.lock Cargo.toml rust-toolchain.toml ./

Expand Down
6 changes: 6 additions & 0 deletions docker/client/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ if [ -n "$ZERO_GAS_TX_POOL" ]; then
START_COMMAND="$START_COMMAND --zero-gas-tx-pool $ZERO_GAS_TX_POOL"
fi

if [ -n "$CUSTOM_ETH_APIS" ]; then
START_COMMAND="$START_COMMAND --ethapi=$CUSTOM_ETH_APIS"
else
START_COMMAND="$START_COMMAND --ethapi=txpool,debug,trace"
fi

echo "Starting $CHAIN_TARGET chain"
eval $START_COMMAND

1 change: 1 addition & 0 deletions docker/test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ COPY primitives ./primitives
COPY test-utils ./test-utils
COPY client ./client
COPY stability-rpc ./stability-rpc
COPY vendor ./vendor
COPY Cargo.lock Cargo.toml rust-toolchain.toml ./

RUN cargo build --release --tests
Expand Down
10 changes: 8 additions & 2 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ futures = { workspace = true }
hex-literal = { workspace = true }
jsonrpsee = { workspace = true, features = ["server", "macros"] }
log = { workspace = true }
scale-codec = { workspace = true, package = "parity-scale-codec" }
scale-codec = { workspace = true }
serde = { workspace = true }

# Substrate
prometheus-endpoint = { package = "substrate-prometheus-endpoint", workspace = true }
prometheus-endpoint = { workspace = true }
sc-chain-spec = { workspace = true }
sc-cli = { workspace = true }
sc-client-api = { workspace = true }
Expand Down Expand Up @@ -90,6 +90,12 @@ account = { workspace = true, features = ["default"] }
stbl-core-primitives = { workspace = true, features = ["default"] }
stability-rpc = { workspace = true }
stbl-tools = { workspace = true }
moonbeam-primitives-ext = { workspace = true }
moonbeam-rpc-primitives-debug = { workspace = true }
moonbeam-rpc-primitives-txpool = { workspace = true }
moonbeam-rpc-debug = { workspace = true }
moonbeam-rpc-trace = { workspace = true }
tokio = { workspace = true }

[build-dependencies]
substrate-build-script-utils = { workspace = true }
Expand Down
19 changes: 15 additions & 4 deletions node/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ pub type Client = FullClient<stability_runtime::RuntimeApi, TemplateRuntimeExecu

/// Only enable the benchmarking host functions when we actually want to benchmark.
#[cfg(feature = "runtime-benchmarks")]
pub type HostFunctions = frame_benchmarking::benchmarking::HostFunctions;
pub type HostFunctions = (
frame_benchmarking::benchmarking::HostFunctions,
moonbeam_primitives_ext::moonbeam_ext::HostFunctions,
);
/// Otherwise we use empty host functions for ext host functions.
#[cfg(not(feature = "runtime-benchmarks"))]
pub type HostFunctions = ();
pub type HostFunctions = moonbeam_primitives_ext::moonbeam_ext::HostFunctions;

pub struct TemplateRuntimeExecutor;
impl NativeExecutionDispatch for TemplateRuntimeExecutor {
Expand All @@ -42,6 +45,8 @@ pub trait BaseRuntimeApiCollection:
+ sp_offchain::OffchainWorkerApi<Block>
+ sp_session::SessionKeys<Block>
+ sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
+ moonbeam_rpc_primitives_debug::DebugRuntimeApi<Block>
+ moonbeam_rpc_primitives_txpool::TxPoolRuntimeApi<Block>
where
<Self as sp_api::ApiExt<Block>>::StateBackend: sp_api::StateBackend<BlakeTwo256>,
{
Expand All @@ -54,7 +59,9 @@ where
+ sp_block_builder::BlockBuilder<Block>
+ sp_offchain::OffchainWorkerApi<Block>
+ sp_session::SessionKeys<Block>
+ sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>,
+ sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
+ moonbeam_rpc_primitives_debug::DebugRuntimeApi<Block>
+ moonbeam_rpc_primitives_txpool::TxPoolRuntimeApi<Block>,
<Self as sp_api::ApiExt<Block>>::StateBackend: sp_api::StateBackend<BlakeTwo256>,
{
}
Expand All @@ -69,6 +76,8 @@ pub trait RuntimeApiCollection:
+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>
+ stbl_primitives_fee_compatible_api::CompatibleFeeApi<Block, AccountId>
+ stbl_primitives_zero_gas_transactions_api::ZeroGasTransactionApi<Block>
+ moonbeam_rpc_primitives_debug::DebugRuntimeApi<Block>
+ moonbeam_rpc_primitives_txpool::TxPoolRuntimeApi<Block>
where
<Self as sp_api::ApiExt<Block>>::StateBackend: sp_api::StateBackend<BlakeTwo256>,
{
Expand All @@ -83,7 +92,9 @@ where
+ frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index>
+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>
+ stbl_primitives_fee_compatible_api::CompatibleFeeApi<Block, AccountId>
+ stbl_primitives_zero_gas_transactions_api::ZeroGasTransactionApi<Block>,
+ stbl_primitives_zero_gas_transactions_api::ZeroGasTransactionApi<Block>
+ moonbeam_rpc_primitives_txpool::TxPoolRuntimeApi<Block>
+ moonbeam_rpc_primitives_debug::DebugRuntimeApi<Block>,
<Self as sp_api::ApiExt<Block>>::StateBackend: sp_api::StateBackend<BlakeTwo256>,
{
}
51 changes: 51 additions & 0 deletions node/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use sc_network_sync::SyncingService;
use sc_service::{error::Error as ServiceError, Configuration, TaskManager};
use sp_api::ConstructRuntimeApi;
use sp_runtime::traits::BlakeTwo256;
use core::str::FromStr;
// Frontier
pub use fc_consensus::FrontierBlockImport;

Expand Down Expand Up @@ -40,6 +41,34 @@ pub enum BackendType {
Sql,
}


#[derive(Debug, PartialEq, Clone)]
pub enum EthApi {
Txpool,
Debug,
Trace,
None,
}

impl FromStr for EthApi {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"txpool" => Self::Txpool,
"debug" => Self::Debug,
"trace" => Self::Trace,
"none" => Self::None,
_ => {
return Err(format!(
"`{}` is not recognized as a supported Ethereum Api",
s
))
}
})
}
}

/// The ethereum-compatibility configuration used to run a node.
#[derive(Clone, Debug, clap::Parser)]
pub struct EthConfiguration {
Expand Down Expand Up @@ -88,6 +117,28 @@ pub struct EthConfiguration {
/// Default value is 200MB.
#[arg(long, default_value = "209715200")]
pub frontier_sql_backend_cache_size: u64,

/// Sets the maximum permits
#[arg(long, default_value = "10")]
pub ethapi_max_permits: u64,

/// Sets the maximum permits
#[arg(long, default_value = "500")]
pub trace_filter_max_count: u32,

/// Size in bytes of data a raw tracing request is allowed to use.
/// Bound the size of memory, stack and storage data.
#[arg(long, default_value = "20000000")]
pub tracing_raw_max_memory_usage: usize,

/// Duration (in seconds) after which the cache of `trace_filter` for a given block will be
/// discarded.
#[arg(long, default_value = "300")]
pub ethapi_trace_cache_duration: u64,

#[arg(long, value_delimiter = ',', default_value = "none")]
pub ethapi: Vec<EthApi>,

}

pub struct FrontierPartialComponents {
Expand Down
27 changes: 25 additions & 2 deletions node/src/rpc/eth.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::{collections::BTreeMap, sync::Arc};

use jsonrpsee::RpcModule;
use moonbeam_rpc_debug::{Debug, DebugServer};
use moonbeam_rpc_trace::{Trace, TraceServer};
// Substrate
use sc_client_api::{
backend::{Backend, StorageProvider},
Expand All @@ -16,11 +18,15 @@ use sp_block_builder::BlockBuilder as BlockBuilderApi;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
use sp_core::H256;
use sp_runtime::traits::Block as BlockT;
use sp_runtime::traits::Header as HeaderT;
// Frontier
pub use fc_rpc::{EthBlockDataCacheTask, EthConfig, OverrideHandle, StorageOverride, TxPool};
pub use fc_rpc_core::types::{FeeHistoryCache, FeeHistoryCacheLimit, FilterPool};
pub use fc_storage::overrides_handle;
use fp_rpc::{ConvertTransaction, ConvertTransactionRuntimeApi, EthereumRuntimeRPCApi};
use crate::eth::{EthApi, EthConfiguration};

use super::TracingConfig;

/// Extra dependencies for Ethereum compatibility.
pub struct EthDeps<C, P, A: ChainApi, CT, B: BlockT> {
Expand Down Expand Up @@ -95,14 +101,18 @@ pub fn create_eth<C, BE, P, A, CT, B, EC: EthConfig<B, C>>(
fc_mapping_sync::EthereumBlockNotification<B>,
>,
>,
eth_config: &EthConfiguration,
optional_tracing_config: Option<TracingConfig>,
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
where
B: BlockT<Hash = sp_core::H256>,
B::Header: HeaderT<Number = u32>,
C: CallApiAt<B> + ProvideRuntimeApi<B>,
C::Api: BlockBuilderApi<B> + ConvertTransactionRuntimeApi<B> + EthereumRuntimeRPCApi<B>,
C: BlockchainEvents<B> + 'static,
C: HeaderBackend<B> + HeaderMetadata<B, Error = BlockChainError> + StorageProvider<B, BE>,
BE: Backend<B> + 'static,
B::Header: HeaderT<Number = u32>,
P: TransactionPool<Block = B> + 'static,
A: ChainApi<Block = B> + 'static,
CT: ConvertTransaction<<B as BlockT>::Extrinsic> + Send + Sync + 'static,
Expand Down Expand Up @@ -196,8 +206,21 @@ where
.into_rpc(),
)?;

io.merge(Web3::new(client).into_rpc())?;
io.merge(tx_pool.into_rpc())?;
io.merge(Web3::new(client.clone()).into_rpc())?;

if let Some(tracing_config) = optional_tracing_config {
if let Some(debug_requester) = tracing_config.tracing_requesters.debug {
io.merge(Debug::new(debug_requester).into_rpc())?;
}

if let Some(trace_requester) = tracing_config.tracing_requesters.trace {
io.merge(Trace::new(client.clone(), trace_requester, 20).into_rpc())?;
}
}

if eth_config.ethapi.contains(&EthApi::Txpool) {
io.merge(tx_pool.into_rpc())?;
}

Ok(io)
}
15 changes: 14 additions & 1 deletion node/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ use stbl_primitives_zero_gas_transactions_api::ZeroGasTransactionApi;
// Runtime
use stability_runtime::{opaque::Block, AccountId, Balance, Hash, Index};

mod tracing;
pub use self::tracing::*;

mod eth;
pub use self::eth::{create_eth, overrides_handle, EthDeps};
pub use self::eth::{create_eth, overrides_handle, EthDeps, };
use crate::service::EthConfiguration;

/// Full client dependencies.
pub struct FullDeps<C, P, A: ChainApi, CT> {
Expand All @@ -49,16 +53,22 @@ where
type RuntimeStorageOverride =
fc_rpc::frontier_backend_client::SystemAccountId20StorageOverride<Block, C, BE>;
}
pub struct TracingConfig {
pub tracing_requesters: RpcRequesters,
pub trace_filter_max_count: u32,
}

/// Instantiate all Full RPC extensions.
pub fn create_full<C, P, BE, A, CT>(
eth_config: &EthConfiguration,
deps: FullDeps<C, P, A, CT>,
subscription_task_executor: SubscriptionTaskExecutor,
pubsub_notification_sinks: Arc<
fc_mapping_sync::EthereumBlockNotificationSinks<
fc_mapping_sync::EthereumBlockNotification<Block>,
>,
>,
optional_tracing_config: Option<TracingConfig>,
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
where
C: CallApiAt<Block> + ProvideRuntimeApi<Block>,
Expand All @@ -74,6 +84,7 @@ where
+ HeaderMetadata<Block, Error = BlockChainError>
+ StorageProvider<Block, BE>,
BE: Backend<Block> + 'static,
C::Api: moonbeam_rpc_primitives_debug::DebugRuntimeApi<Block>,
P: TransactionPool<Block = Block> + 'static,
A: ChainApi<Block = Block> + 'static,
CT: fp_rpc::ConvertTransaction<<Block as BlockT>::Extrinsic> + Send + Sync + 'static,
Expand Down Expand Up @@ -110,6 +121,8 @@ where
eth,
subscription_task_executor,
pubsub_notification_sinks,
eth_config,
optional_tracing_config,
)?;

Ok(io)
Expand Down
Loading

0 comments on commit 485d219

Please sign in to comment.