Skip to content

Commit

Permalink
Merge pull request #496 from gluwa/forks-refactoring
Browse files Browse the repository at this point in the history
feat: metrics for full node, refactoring
  • Loading branch information
rustlang-dev authored Sep 23, 2024
2 parents e89563b + c83dc66 commit 57910a0
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 335 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

20 changes: 3 additions & 17 deletions client/rpc/debug/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Moonbeam. If not, see <http://www.gnu.org/licenses/>.
pub use creditcoin3_rpc_core_debug::{DebugServer, TraceParams};
use fc_storage::StorageOverride;
use futures::StreamExt;
use jsonrpsee::core::{async_trait, RpcResult};
use fc_storage::StorageOverride;

use tokio::{
self,
Expand All @@ -27,18 +27,17 @@ use creditcoin3_client_evm_tracing::{formatters::ResponseFormatter, types::singl
use creditcoin3_rpc_core_types::{RequestBlockId, RequestBlockTag};
use creditcoin3_rpc_primitives_debug::{DebugRuntimeApi, TracerInput};
use ethereum_types::H256;
// use fc_rpc::{frontier_backend_client, internal_err, OverrideHandle};
use fc_rpc::{frontier_backend_client, internal_err};
use fp_rpc::EthereumRuntimeRPCApi;
use sc_client_api::backend::{Backend, StateBackend, StorageProvider};
use sc_utils::mpsc::TracingUnboundedSender;
use sp_runtime::generic::BlockId;
use sp_runtime::traits::Header as HeaderT;
use sp_api::{ApiExt, Core, ProvideRuntimeApi};
use sp_block_builder::BlockBuilder;
use sp_blockchain::{
Backend as BlockchainBackend, Error as BlockChainError, HeaderBackend, HeaderMetadata,
};
use sp_runtime::generic::BlockId;
use sp_runtime::traits::Header as HeaderT;
use sp_runtime::traits::{BlakeTwo256, Block as BlockT, UniqueSaturatedInto};
use std::{future::Future, marker::PhantomData, sync::Arc};

Expand Down Expand Up @@ -336,9 +335,6 @@ where
// Get parent blockid.
let parent_block_hash = *header.parent_hash();

// let schema = fc_storage::onchain_storage_schema::<B, C, BE>(client.as_ref(), hash);
// let schema = client.storage_schema::<B, C, BE>(hash);

// Using storage overrides we align with `:ethereum_schema` which will result in proper
// SCALE decoding in case of migration.
let statuses = overrides
Expand Down Expand Up @@ -478,16 +474,6 @@ where
));
};

// let x = client.storage(reference_hash, &sc_client_api::StorageKey(b":ethereum_schema".to_vec()));
// let schema = match x {
// Ok(Some(bytes)) => parity_scale_codec::Decode::decode(&mut &bytes.0[..])
// .ok()
// .unwrap_or(fp_storage::EthereumStorageSchema::Undefined),
// _ => fp_storage::EthereumStorageSchema::Undefined,
// };
// let schema = fc_storage::onchain_storage_schema::<B, C, BE>(client.as_ref(), reference_hash);


// Get the block that contains the requested transaction. Using storage overrides we align
// with `:ethereum_schema` which will result in proper SCALE decoding in case of migration.
let reference_block = overrides.current_block(reference_hash);
Expand Down
41 changes: 16 additions & 25 deletions client/rpc/trace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,31 @@
//! - For each traced block an async task responsible to wait for a permit, spawn a blocking
//! task and waiting for the result, then send it to the main `CacheTask`.
use fc_storage::StorageOverride;
use futures::{select, stream::FuturesUnordered, FutureExt, StreamExt};
use std::{collections::BTreeMap, future::Future, marker::PhantomData, sync::Arc, time::Duration};
use tokio::{
sync::{mpsc, oneshot, Semaphore},
time::sleep,
};
use fc_storage::StorageOverride;
use tracing::{instrument, Instrument};

use sc_client_api::{backend::{Backend, StateBackend, StorageProvider}, StorageKey};
use sc_client_api::{
backend::{Backend, StateBackend, StorageProvider},
};
use sc_utils::mpsc::TracingUnboundedSender;
use sp_runtime::traits::{Header as HeaderT};
use sp_api::{ApiExt, Core, ProvideRuntimeApi};
use sp_block_builder::BlockBuilder;
use sp_blockchain::{
Backend as BlockchainBackend, Error as BlockChainError, HeaderBackend, HeaderMetadata,
};
use sp_runtime::traits::Header as HeaderT;
use sp_runtime::traits::{BlakeTwo256, Block as BlockT};
use substrate_prometheus_endpoint::{
register, Counter, PrometheusError, Registry as PrometheusRegistry, U64,
};

use ethereum_types::H256;
// use fc_rpc::OverrideHandle;
use fp_rpc::EthereumRuntimeRPCApi;

use creditcoin3_client_evm_tracing::{
Expand Down Expand Up @@ -811,29 +812,19 @@ where
let height = *block_header.number();
let substrate_parent_hash = *block_header.parent_hash();

// let x = client.storage(substrate_hash, &StorageKey(b":ethereum_schema".to_vec()));
// let schema = match x {
// Ok(Some(bytes)) => parity_scale_codec::Decode::decode(&mut &bytes.0[..])
// .ok()
// .unwrap_or(fp_storage::EthereumStorageSchema::Undefined),
// _ => fp_storage::EthereumStorageSchema::Undefined,
// };
// let schema =
// fc_storage::onchain_storage_schema::<B, C, BE>(client.as_ref(), substrate_hash);

// Get Ethereum block data.
let (eth_block, eth_transactions) = match (
overrides.current_block(substrate_hash),
overrides.current_transaction_statuses(substrate_hash),
) {
(Some(a), Some(b)) => (a, b),
_ => {
return Err(format!(
"Failed to get Ethereum block data for Substrate block {}",
substrate_hash
))
}
};
overrides.current_block(substrate_hash),
overrides.current_transaction_statuses(substrate_hash),
) {
(Some(a), Some(b)) => (a, b),
_ => {
return Err(format!(
"Failed to get Ethereum block data for Substrate block {}",
substrate_hash
))
}
};

let eth_block_hash = eth_block.header.hash();
let eth_tx_hashes = eth_transactions
Expand Down
103 changes: 0 additions & 103 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,58 +160,6 @@ pub fn development_config(enable_manual_seal: Option<bool>) -> ChainSpec {
.with_genesis_config(config_json)
.with_properties(properties())
.build();

// DevChainSpec::from_genesis(
// // Name
// "Development",
// // ID
// "dev",
// ChainType::Development,
// move || {
// DevGenesisExt {
// genesis_config: testnet_genesis(
// wasm_binary,
// // Sudo account (Alice)
// get_account_id_from_seed::<sr25519::Public>("Alice"),
// // Pre-funded accounts
// vec![
// get_account_id_from_seed::<sr25519::Public>("Alice"),
// get_account_id_from_seed::<sr25519::Public>("Bob"),
// get_account_id_from_seed::<sr25519::Public>("Charlie"),
// get_account_id_from_seed::<sr25519::Public>("Dave"),
// get_account_id_from_seed::<sr25519::Public>("Eve"),
// get_account_id_from_seed::<sr25519::Public>("Ferdie"),
// eth_acct(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), // Alith
// ],
// vec![
// hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac"), // Alith
// hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0"), // Baltathar
// hex!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc"), // Charleth
// hex!("773539d4Ac0e786233D90A233654ccEE26a613D9"), // Dorothy
// hex!("Ff64d3F6efE2317EE2807d223a0Bdc4c0c49dfDB"), // Ethan
// hex!("C0F0f4ab324C46e55D02D0033343B4Be8A55532d"), // Faith
// ],
// // Initial PoA authorities
// vec![authority_keys_from_seed("Alice")],
// // Ethereum chain ID
// SS58Prefix::get() as u64,
// ),
// enable_manual_seal,
// }
// },
// // Bootnodes
// vec![],
// // Telemetry
// None,
// // Protocol ID
// None,
// // Fork ID
// None,
// // Properties
// Some(properties()),
// // Extensions
// None,
// )
}

pub fn local_testnet_config() -> ChainSpec {
Expand Down Expand Up @@ -255,56 +203,6 @@ pub fn local_testnet_config() -> ChainSpec {
.with_genesis_config(config_json)
.with_properties(properties())
.build();

// ChainSpec::from_genesis(
// // Name
// "Local Testnet",
// // ID
// "local_testnet",
// ChainType::Local,
// move || {
// testnet_genesis(
// wasm_binary,
// // Initial PoA authorities
// // Sudo account (Alice)
// get_account_id_from_seed::<sr25519::Public>("Alice"),
// // Pre-funded accounts
// vec![
// get_account_id_from_seed::<sr25519::Public>("Alice"),
// get_account_id_from_seed::<sr25519::Public>("Bob"),
// get_account_id_from_seed::<sr25519::Public>("Charlie"),
// get_account_id_from_seed::<sr25519::Public>("Dave"),
// get_account_id_from_seed::<sr25519::Public>("Eve"),
// get_account_id_from_seed::<sr25519::Public>("Ferdie"),
// ],
// vec![
// hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac"), // Alith
// hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0"), // Baltathar
// hex!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc"), // Charleth
// hex!("773539d4Ac0e786233D90A233654ccEE26a613D9"), // Dorothy
// hex!("Ff64d3F6efE2317EE2807d223a0Bdc4c0c49dfDB"), // Ethan
// hex!("C0F0f4ab324C46e55D02D0033343B4Be8A55532d"), // Faith
// ],
// vec![
// authority_keys_from_seed("Alice"),
// authority_keys_from_seed("Bob"),
// ],
// SS58Prefix::get() as u64,
// )
// },
// // Bootnodes
// vec![],
// // Telemetry
// None,
// // Protocol ID
// None,
// // Fork ID
// None,
// // Properties
// Some(properties()),
// // Extensions
// None,
// )
}

fn genesis_account(balance: U256) -> fp_evm::GenesisAccount {
Expand Down Expand Up @@ -342,7 +240,6 @@ fn testnet_genesis(
// System
system: SystemConfig {
// Add Wasm runtime to storage.
// code: wasm_binary.to_vec(), //todo! double check this. seems field does not exist indeed
..Default::default()
},
sudo: SudoConfig {
Expand Down
7 changes: 3 additions & 4 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ impl SubstrateCli for Cli {
let ret = match id {
"dev" => {
let enable_manual_seal = self.sealing.map(|_| true);
let x = Box::new(chain_spec::development_config(enable_manual_seal));
// panic!("eeeeeee");
x
let chain_spec = Box::new(chain_spec::development_config(enable_manual_seal));
chain_spec
}
"devnet" => Box::new(chain_spec::devnet_config()?),
"testnet" => Box::new(chain_spec::testnet_config()?),
Expand Down Expand Up @@ -191,7 +190,7 @@ pub fn run() -> sc_cli::Result<()> {

let runner = cli.create_runner(cmd)?;
match cmd {
BenchmarkCmd::Pallet(cmd) => runner.sync_run(|config| cmd.run::<Block, ()>(config)),
BenchmarkCmd::Pallet(cmd) => runner.sync_run(|config| cmd.run::<sp_runtime::traits::HashingFor<Block>, ()>(config)),
BenchmarkCmd::Block(cmd) => runner.sync_run(|mut config| {
let (client, _, _, _, _) = service::new_chain_ops(&mut config, &cli.eth)?;
cmd.run(client)
Expand Down
2 changes: 0 additions & 2 deletions node/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use sp_api::ConstructRuntimeApi;
// Frontier
pub use fc_consensus::FrontierBlockImport;
use fc_rpc::{EthTask, StorageOverride};
// use fc_rpc::{EthTask, OverrideHandle, StorageOverride};
pub use fc_rpc_core::types::{FeeHistoryCache, FeeHistoryCacheLimit, FilterPool};
// Local
use creditcoin3_runtime::opaque::Block;
Expand Down Expand Up @@ -155,7 +154,6 @@ pub async fn spawn_frontier_tasks<RuntimeApi, Executor>(
backend: Arc<FullBackend>,
frontier_backend: Arc<fc_db::Backend<Block, FullClient<RuntimeApi, Executor>>>,
filter_pool: Option<FilterPool>,
// overrides: Arc<OverrideHandle<Block>>,
overrides: Arc<dyn StorageOverride<Block>>,
fee_history_cache: FeeHistoryCache,
fee_history_cache_limit: FeeHistoryCacheLimit,
Expand Down
2 changes: 0 additions & 2 deletions node/src/rpc/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ use sp_core::H256;
use sp_inherents::CreateInherentDataProviders;
use sp_runtime::traits::Block as BlockT;
// Frontier
// pub use fc_rpc::{EthBlockDataCacheTask, EthConfig, OverrideHandle};
pub use fc_rpc::{EthBlockDataCacheTask, EthConfig};
pub use fc_rpc_core::types::{FeeHistoryCache, FeeHistoryCacheLimit, FilterPool};
// pub use fc_storage::overrides_handle;
use fp_rpc::{ConvertTransaction, ConvertTransactionRuntimeApi, EthereumRuntimeRPCApi};
use sc_network::service::traits::NetworkService as NetworkServiceTrait;

Expand Down
6 changes: 1 addition & 5 deletions node/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
// Runtime
use creditcoin3_cli_opt::EthApi as EthApiCmd;
use creditcoin3_runtime::{opaque::Block, AccountId, Balance, BlockNumber, Hash, Nonce};
// use fc_rpc::OverrideHandle;
use fc_rpc_core::types::{FeeHistoryCache, FilterPool};
use sc_client_api::BlockOf;
use sp_block_builder::BlockBuilder;
Expand All @@ -40,9 +39,7 @@ mod eth;

use crate::client::RuntimeApiCollection;

pub use self::eth::{
consensus_data_provider::BabeConsensusDataProvider, create_eth, EthDeps,
};
pub use self::eth::{consensus_data_provider::BabeConsensusDataProvider, create_eth, EthDeps};

type HasherFor<Block> = <<Block as BlockT>::Header as HeaderT>::Hashing;

Expand Down Expand Up @@ -94,7 +91,6 @@ pub struct SpawnTasksParams<'a, B: BlockT, C, BE> {
pub frontier_backend: Arc<fc_db::Backend<B, C>>,
pub filter_pool: Option<FilterPool>,
pub overrides: Arc<dyn StorageOverride<B>>,
// pub overrides: Arc<OverrideHandle<B>>,
pub fee_history_limit: u64,
pub fee_history_cache: FeeHistoryCache,
}
Expand Down
2 changes: 1 addition & 1 deletion node/src/rpc/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ where
Arc::clone(&params.substrate_backend),
match *params.frontier_backend.clone() {
fc_db::Backend::KeyValue(ref b) => b.clone(),
fc_db::Backend::Sql(ref b) => b.clone(),
fc_db::Backend::Sql(ref b) => b.clone(),
},
Arc::clone(&permit_pool),
Arc::clone(&params.overrides),
Expand Down
Loading

0 comments on commit 57910a0

Please sign in to comment.