Skip to content

Commit

Permalink
Update polkadot-sdk (#72)
Browse files Browse the repository at this point in the history
* Update polkadot-sdk

* Fix test

* .
  • Loading branch information
liuchengxu authored Nov 8, 2024
1 parent 7c6ea45 commit 39ea1fb
Show file tree
Hide file tree
Showing 10 changed files with 2,249 additions and 462 deletions.
2,551 changes: 2,163 additions & 388 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ serde = "1"
serde_json = "1"
tempfile = "3.10.1"
thiserror = "1.0"
tokio = "1.37.0"
tokio = "1.41.1"
tracing = "0.1"

# Disable the default `rocksdb` feature
Expand Down
3 changes: 1 addition & 2 deletions crates/subcoin-network/src/network_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,7 @@ where
if inv.len() == 1 {
if let Inventory::Block(block_hash) = inv[0] {
if self.client.block_number(block_hash).is_none() {
// TODO: peers may sent us duplicate block announcements.
tracing::debug!("Recv possible block announcement {inv:?} from {from:?}");
tracing::debug!("Recv block announcement {inv:?} from {from:?}");

let mut is_new_block_announce = false;

Expand Down
3 changes: 2 additions & 1 deletion crates/subcoin-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ bitcoin = { workspace = true }
bitcoin-explorer = { workspace = true, default-features = false }
clap = { workspace = true, features = ["derive"] }
codec = { workspace = true }
frame-benchmarking-cli = { workspace = true }
frame-benchmarking-cli = { workspace = true, optional = true }
futures = { workspace = true }
hex = { workspace = true }
jsonrpsee = { workspace = true }
Expand Down Expand Up @@ -69,3 +69,4 @@ runtime-benchmarks = [
"sc-service/runtime-benchmarks",
]
rocksdb = ["sc-cli/rocksdb"]
benchmark = ["frame-benchmarking-cli"]
3 changes: 3 additions & 0 deletions crates/subcoin-node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::commands::run::{Run, RunCmd};
use crate::commands::tools::Tools;
use crate::substrate_cli::SubstrateCli;
use clap::Parser;
#[cfg(feature = "benchmark")]
use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
use sc_cli::SubstrateCli as SubstrateCliT;
use sc_client_api::UsageProvider;
Expand Down Expand Up @@ -49,6 +50,7 @@ pub enum Command {
Revert(sc_cli::RevertCmd),

/// Sub-commands concerned with benchmarking.
#[cfg(feature = "benchmark")]
#[command(subcommand)]
Benchmark(Box<frame_benchmarking_cli::BenchmarkCmd>),

Expand Down Expand Up @@ -222,6 +224,7 @@ pub fn run() -> sc_cli::Result<()> {
Ok((cmd.run(client, backend, None), task_manager))
})
}
#[cfg(feature = "benchmark")]
Command::Benchmark(cmd) => {
let runner = SubstrateCli.create_runner(&*cmd)?;

Expand Down
24 changes: 19 additions & 5 deletions crates/subcoin-node/src/transaction_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use sc_transaction_pool_api::{
ImportNotificationStream, PoolFuture, PoolStatus, ReadyTransactions, TransactionFor,
TransactionSource, TransactionStatusStreamFor, TxHash,
};
use sp_runtime::traits::NumberFor;
use sp_runtime::OpaqueExtrinsic;
use std::collections::HashMap;
use std::pin::Pin;
Expand All @@ -12,21 +11,21 @@ use subcoin_runtime::interface::OpaqueBlock;

#[derive(Clone, Debug)]
pub struct PoolTransaction {
data: OpaqueExtrinsic,
data: Arc<OpaqueExtrinsic>,
hash: sp_core::H256,
}

impl From<OpaqueExtrinsic> for PoolTransaction {
fn from(e: OpaqueExtrinsic) -> Self {
Self {
data: e,
data: Arc::from(e),
hash: sp_core::H256::zero(),
}
}
}

impl sc_transaction_pool_api::InPoolTransaction for PoolTransaction {
type Transaction = OpaqueExtrinsic;
type Transaction = Arc<OpaqueExtrinsic>;
type Hash = sp_core::H256;

fn data(&self) -> &Self::Transaction {
Expand Down Expand Up @@ -115,7 +114,7 @@ impl sc_transaction_pool_api::TransactionPool for Transactions {

fn ready_at(
&self,
_at: NumberFor<Self::Block>,
_at: Self::Hash,
) -> Pin<
Box<
dyn Future<
Expand Down Expand Up @@ -159,4 +158,19 @@ impl sc_transaction_pool_api::TransactionPool for Transactions {
fn ready_transaction(&self, _hash: &TxHash<Self>) -> Option<Arc<Self::InPoolTransaction>> {
unimplemented!()
}

fn ready_at_with_timeout(
&self,
_at: Self::Hash,
_timeout: std::time::Duration,
) -> Pin<
Box<
dyn Future<
Output = Box<dyn ReadyTransactions<Item = Arc<Self::InPoolTransaction>> + Send>,
> + Send
+ '_,
>,
> {
unimplemented!()
}
}
8 changes: 5 additions & 3 deletions crates/subcoin-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

extern crate alloc;

use frame_support::dispatch::PerDispatchClass;
use frame_support::genesis_builder_helper::{build_state, get_preset};
use frame_support::pallet_prelude::*;
Expand All @@ -42,7 +44,7 @@ use sp_std::vec;
use sp_std::vec::Vec;
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_version::{create_runtime_str, runtime_version, RuntimeVersion};
use sp_version::{runtime_version, RuntimeVersion};

/// header weight (80 * 4) + tx_data_len(4)
const BITCOIN_BASE_BLOCK_WEIGHT: u64 = 80 * 4 + 4;
Expand All @@ -53,8 +55,8 @@ const BITCOIN_MAX_WEIGHT: u64 = 4_000_000;

#[runtime_version]
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("subcoin"),
impl_name: create_runtime_str!("subcoin"),
spec_name: alloc::borrow::Cow::Borrowed("subcoin"),
impl_name: alloc::borrow::Cow::Borrowed("subcoin"),
authoring_version: 0,
spec_version: 0,
impl_version: 0,
Expand Down
2 changes: 1 addition & 1 deletion crates/subcoin-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license.workspace = true
[dependencies]
async-trait = { workspace = true }
bitcoin = { workspace = true }
frame-benchmarking-cli = { workspace = true }
# frame-benchmarking-cli = { workspace = true }
frame-system = { workspace = true }
futures = { workspace = true }
jsonrpsee = { workspace = true }
Expand Down
109 changes: 52 additions & 57 deletions crates/subcoin-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ mod genesis_block_builder;
mod transaction_adapter;

use bitcoin::hashes::Hash;
use frame_benchmarking_cli::SUBSTRATE_REFERENCE_HARDWARE;
use futures::FutureExt;
use genesis_block_builder::GenesisBlockBuilder;
use sc_client_api::{AuxStore, HeaderBackend};
Expand Down Expand Up @@ -136,7 +135,7 @@ pub fn new_node(config: SubcoinConfiguration) -> Result<NodeComponents, ServiceE
let SubcoinConfiguration {
network: bitcoin_network,
config,
no_hardware_benchmarks,
no_hardware_benchmarks: _,
storage_monitor,
} = config;

Expand Down Expand Up @@ -179,41 +178,44 @@ pub fn new_node(config: SubcoinConfiguration) -> Result<NodeComponents, ServiceE

let client = Arc::new(client);

let mut telemetry = telemetry.map(|(worker, telemetry)| {
let telemetry = telemetry.map(|(worker, telemetry)| {
task_manager
.spawn_handle()
.spawn("telemetry", None, worker.run());
telemetry
});

let database_path = config.database.path().map(Path::to_path_buf);
let maybe_hwbench = (!no_hardware_benchmarks)
.then_some(database_path.as_ref().map(|db_path| {
let _ = std::fs::create_dir_all(db_path);
sc_sysinfo::gather_hwbench(Some(db_path), &SUBSTRATE_REFERENCE_HARDWARE)
}))
.flatten();

if let Some(hwbench) = maybe_hwbench {
sc_sysinfo::print_hwbench(&hwbench);
match SUBSTRATE_REFERENCE_HARDWARE.check_hardware(&hwbench, config.role.is_authority()) {
Err(err) if config.role.is_authority() => {
tracing::warn!(
"⚠️ The hardware does not meet the minimal requirements {err} for role 'Authority'.",
);
}
_ => {}
}

if let Some(ref mut telemetry) = telemetry {
let telemetry_handle = telemetry.handle();
task_manager.spawn_handle().spawn(
"telemetry_hwbench",
None,
sc_sysinfo::initialize_hwbench_telemetry(telemetry_handle, hwbench),
);
}
}
// TODO: frame_benchmarking_cli pulls in rocksdb due to its dep
// cumulus-client-parachain-inherent.
// let maybe_hwbench = (!no_hardware_benchmarks)
// .then_some(database_path.as_ref().map(|db_path| {
// let _ = std::fs::create_dir_all(db_path);
// sc_sysinfo::gather_hwbench(Some(db_path), &frame_benchmarking_cli::SUBSTRATE_REFERENCE_HARDWARE)
// }))
// .flatten();

// if let Some(hwbench) = maybe_hwbench {
// sc_sysinfo::print_hwbench(&hwbench);
// match frame_benchmarking_cli::SUBSTRATE_REFERENCE_HARDWARE.check_hardware(&hwbench, config.role.is_authority()) {
// Err(err) if config.role.is_authority() => {
// tracing::warn!(
// "⚠️ The hardware does not meet the minimal requirements {err} for role 'Authority'.",
// );
// }
// _ => {}
// }

// if let Some(ref mut telemetry) = telemetry {
// let telemetry_handle = telemetry.handle();
// task_manager.spawn_handle().spawn(
// "telemetry_hwbench",
// None,
// sc_sysinfo::initialize_hwbench_telemetry(telemetry_handle, hwbench),
// );
// }
// }

if let Some(database_path) = database_path {
sc_storage_monitor::StorageMonitorService::try_spawn(
Expand Down Expand Up @@ -251,19 +253,22 @@ pub fn start_substrate_network<N>(
where
N: sc_network::NetworkBackend<Block, <Block as BlockT>::Hash>,
{
let mut net_config = sc_network::config::FullNetworkConfiguration::<
let net_config = sc_network::config::FullNetworkConfiguration::<
Block,
<Block as BlockT>::Hash,
N,
>::new(&config.network, config.prometheus_registry().cloned());
let metrics = N::register_notification_metrics(config.prometheus_registry());

let transaction_pool = sc_transaction_pool::BasicPool::new_full(
config.transaction_pool.clone(),
config.role.is_authority().into(),
config.prometheus_registry(),
task_manager.spawn_essential_handle(),
client.clone(),
let transaction_pool = Arc::from(
sc_transaction_pool::Builder::new(
task_manager.spawn_essential_handle(),
client.clone(),
config.role.is_authority().into(),
)
.with_options(config.transaction_pool.clone())
.with_prometheus(config.prometheus_registry())
.build(),
);

let import_queue = BasicQueue::new(
Expand All @@ -274,19 +279,6 @@ where
None,
);

let syncing_strategy = sc_service::build_polkadot_syncing_strategy(
config.protocol_id(),
config.chain_spec.fork_id(),
&mut net_config,
None,
client.clone(),
&task_manager.spawn_handle(),
config
.prometheus_config
.as_ref()
.map(|config| &config.registry),
)?;

let (network, system_rpc_tx, _tx_handler_controller, network_starter, sync_service) =
sc_service::build_network(sc_service::BuildNetworkParams {
config,
Expand All @@ -296,7 +288,7 @@ where
spawn_handle: task_manager.spawn_handle(),
import_queue,
block_announce_validator_builder: None,
syncing_strategy,
warp_sync_config: None,
block_relay: None,
metrics,
})?;
Expand Down Expand Up @@ -374,7 +366,7 @@ type PartialComponents = sc_service::PartialComponents<
FullBackend,
FullSelectChain,
sc_consensus::DefaultImportQueue<Block>,
sc_transaction_pool::FullPool<Block, FullClient>,
sc_transaction_pool::TransactionPoolHandle<Block, FullClient>,
Option<Telemetry>,
>;

Expand Down Expand Up @@ -413,12 +405,15 @@ pub fn new_partial(

let select_chain = sc_consensus::LongestChain::new(backend.clone());

let transaction_pool = sc_transaction_pool::BasicPool::new_full(
config.transaction_pool.clone(),
config.role.is_authority().into(),
config.prometheus_registry(),
task_manager.spawn_essential_handle(),
client.clone(),
let transaction_pool = Arc::from(
sc_transaction_pool::Builder::new(
task_manager.spawn_essential_handle(),
client.clone(),
config.role.is_authority().into(),
)
.with_options(config.transaction_pool.clone())
.with_prometheus(config.prometheus_registry())
.build(),
);

let import_queue = BasicQueue::new(
Expand Down
6 changes: 2 additions & 4 deletions crates/subcoin-service/src/transaction_adapter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bitcoin::Transaction;
use sp_core::{Decode, Encode};
use sp_runtime::traits::{Block as BlockT, Extrinsic};
use sp_runtime::traits::Block as BlockT;
use subcoin_primitives::BitcoinTransactionAdapter;

/// Responsible for doing the conversion between Bitcoin transaction and Substrate extrinsic.
Expand Down Expand Up @@ -36,14 +36,12 @@ impl<Block: BlockT> BitcoinTransactionAdapter<Block> for TransactionAdapter {

fn bitcoin_transaction_into_extrinsic(btc_tx: bitcoin::Transaction) -> Block::Extrinsic {
Decode::decode(
&mut subcoin_runtime::UncheckedExtrinsic::new(
&mut subcoin_runtime::UncheckedExtrinsic::new_bare(
pallet_bitcoin::Call::<subcoin_runtime::Runtime>::transact {
btc_tx: btc_tx.into(),
}
.into(),
None,
)
.expect("Extrinsic constructed internally must not fail; qed")
.encode()
.as_slice(),
)
Expand Down

0 comments on commit 39ea1fb

Please sign in to comment.