Skip to content

Commit

Permalink
Upgrade polkadot-sdk (paritytech#42)
Browse files Browse the repository at this point in the history
* Upgrade polkadot-sdk

* Sync subcoin-informant with upstream

* Fix upgrade

* Upgrade to rust 1.80

* Fix clippy

* clippy
  • Loading branch information
liuchengxu authored Aug 16, 2024
1 parent 1e5a386 commit 88308a1
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 241 deletions.
274 changes: 134 additions & 140 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 @@ -27,14 +27,14 @@ members = [
default-members = ["crates/subcoin-node"]

[workspace.dependencies]
ansi_term = "0.12.1"
async-trait = "0.1"
bitcoin = { git = "https://github.com/liuchengxu/rust-bitcoin", branch = "0.32.x-subcoin", default-features = false }
bitcoinconsensus = "0.105.0+25.1"
bitcoin-explorer = { git = "https://github.com/liuchengxu/Rusty-Bitcoin-Explorer", branch = "rust-bitcoin-upgrade", default-features = false }
chrono = "0.4.37"
clap = { version = "4", features = ["derive"] }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false }
console = "0.15.8"
fastrand = "2.0.2"
futures = "0.3"
futures-timer = "3.0.1"
Expand Down
10 changes: 5 additions & 5 deletions crates/sc-consensus-nakamoto/src/block_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ pub trait BlockExecutor<Block: BlockT>: Send + Sync {
/// There are two kinds of clients for executing the block:
///
/// 1) Client using the disk backend. This is the default behaviour in Substrate. The state
/// is maintained in the disk backend and pruned according to the parameters provided on startup.
/// is maintained in the disk backend and pruned according to the parameters provided on startup.
///
/// 2) Client using the in memory backend. This is specifically designated for fast block execution
/// in the initial full sync stage, the in memory backend keeps the entire latest chain state in
/// the memory for executing blocks, the previous states are not stored. The block executor using
/// the in memory backend needs to import the block within the executor to update the in memory
/// chain state.
/// in the initial full sync stage, the in memory backend keeps the entire latest chain state in
/// the memory for executing blocks, the previous states are not stored. The block executor using
/// the in memory backend needs to import the block within the executor to update the in memory
/// chain state.
pub enum ClientContext<BI> {
Disk,
InMemory(BI),
Expand Down
6 changes: 6 additions & 0 deletions crates/sc-fast-sync-backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ impl<Block: BlockT> Blockchain<Block> {
None => storage.aux.remove(&k),
};
}
println!("[write_aux] after {:?}", storage.aux);
}
}

Expand Down Expand Up @@ -770,11 +771,16 @@ impl<Block: BlockT> backend::Backend<Block> for Backend<Block> {
.apply_transaction(*header.state_root(), state);
}

println!("=============== [commit_operation] hash: {hash:?}, header: {header:?}, justification: {justification:?}, body: {body:?}");
self.blockchain
.insert(hash, header, justification, body, pending_block.state)?;
}

if !operation.aux.is_empty() {
println!(
"=============== [commit_operation] aux: {:?}",
operation.aux
);
self.blockchain.write_aux(operation.aux);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/subcoin-informant/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ repository.workspace = true
license.workspace = true

[dependencies]
ansi_term = { workspace = true }
bitcoin = { workspace = true }
console = { workspace = true }
futures = { workspace = true }
futures-timer = { workspace = true }
sc-client-api = { workspace = true }
Expand Down
23 changes: 10 additions & 13 deletions crates/subcoin-informant/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{ClientInfoExt, OutputFormat};
use ansi_term::Colour;
use crate::ClientInfoExt;
use bitcoin::hashes::Hash;
use bitcoin::BlockHash;
use console::style;
use sp_runtime::traits::{Block as BlockT, CheckedDiv, NumberFor, Saturating, Zero};
use std::fmt::{self, Display};
use std::time::Instant;
Expand Down Expand Up @@ -64,19 +64,16 @@ pub struct InformantDisplay<B: BlockT> {
last_total_bytes_inbound: u64,
/// The last seen total of bytes sent.
last_total_bytes_outbound: u64,
/// The format to print output in.
format: OutputFormat,
}

impl<B: BlockT> InformantDisplay<B> {
/// Builds a new informant display system.
pub fn new(format: OutputFormat) -> InformantDisplay<B> {
pub fn new() -> InformantDisplay<B> {
InformantDisplay {
last_number: None,
last_update: Instant::now(),
last_total_bytes_inbound: 0,
last_total_bytes_outbound: 0,
format,
}
}

Expand Down Expand Up @@ -125,13 +122,13 @@ impl<B: BlockT> InformantDisplay<B> {

tracing::info!(
target: "subcoin",
"{level} {}{target} ({} peers), best: #{} ({best_bitcoin_hash},{best_hash}), finalized #{} ({finalized_bitcoin_hash},{finalized_hash}), {} {}",
self.format.print_with_color(Colour::White.bold(), status),
self.format.print_with_color(Colour::White.bold(), num_connected_peers),
self.format.print_with_color(Colour::White.bold(), best_number),
self.format.print_with_color(Colour::White.bold(), finalized_number),
self.format.print_with_color(Colour::Green, format!("⬇ {}", TransferRateFormat(avg_bytes_per_sec_inbound))),
self.format.print_with_color(Colour::Red, format!("⬆ {}", TransferRateFormat(avg_bytes_per_sec_outbound))),
"{level} {}{target} ({} peers), best: #{} ({best_bitcoin_hash},{best_hash}), finalized #{} ({finalized_bitcoin_hash},{finalized_hash}), ⬇ {} ⬆ {}",
style(status).white().bold(),
style(num_connected_peers).white().bold(),
style(best_number).white().bold(),
style(finalized_number).white().bold(),
style(TransferRateFormat(avg_bytes_per_sec_inbound)).green(),
style(TransferRateFormat(avg_bytes_per_sec_outbound)).red(),
)
}
}
Expand Down
73 changes: 8 additions & 65 deletions crates/subcoin-informant/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

mod display;

use ansi_term::{Colour, Style};
use bitcoin::BlockHash;
use console::style;
use futures::prelude::*;
use futures_timer::Delay;
use sc_client_api::{AuxStore, BlockchainEvents, ClientInfo, UsageProvider};
Expand Down Expand Up @@ -41,69 +41,13 @@ fn interval(duration: Duration) -> impl Stream<Item = ()> + Unpin {
futures::stream::unfold((), move |_| Delay::new(duration).map(|_| Some(((), ())))).map(drop)
}

/// The format to print telemetry output in.
#[derive(Clone, Debug)]
pub struct OutputFormat {
/// Enable color output in logs.
///
/// Is enabled by default.
pub enable_color: bool,
}

impl Default for OutputFormat {
fn default() -> Self {
Self { enable_color: true }
}
}

enum ColorOrStyle {
Color(Colour),
Style(Style),
}

impl From<Colour> for ColorOrStyle {
fn from(value: Colour) -> Self {
Self::Color(value)
}
}

impl From<Style> for ColorOrStyle {
fn from(value: Style) -> Self {
Self::Style(value)
}
}

impl ColorOrStyle {
fn paint(&self, data: String) -> impl Display {
match self {
Self::Color(c) => c.paint(data),
Self::Style(s) => s.paint(data),
}
}
}

impl OutputFormat {
/// Print with color if `self.enable_color == true`.
fn print_with_color(
&self,
color: impl Into<ColorOrStyle>,
data: impl ToString,
) -> impl Display {
if self.enable_color {
color.into().paint(data.to_string()).to_string()
} else {
data.to_string()
}
}
}

/// Builds the informant and returns a `Future` that drives the informant.
pub async fn build<B: BlockT, C>(client: Arc<C>, network: NetworkHandle, format: OutputFormat)
pub async fn build<B: BlockT, C>(client: Arc<C>, network: NetworkHandle)
where
C: UsageProvider<B> + HeaderMetadata<B> + BlockchainEvents<B> + HeaderBackend<B> + AuxStore,
<C as HeaderMetadata<B>>::Error: Display,
{
let mut display = display::InformantDisplay::new(format.clone());
let mut display = display::InformantDisplay::new();

let net_client = client.clone();

Expand Down Expand Up @@ -145,13 +89,12 @@ where

futures::select! {
() = display_notifications.fuse() => (),
() = display_block_import(client, format, is_major_syncing).fuse() => (),
() = display_block_import(client, is_major_syncing).fuse() => (),
};
}

fn display_block_import<B: BlockT, C>(
client: Arc<C>,
format: OutputFormat,
is_major_syncing: Arc<AtomicBool>,
) -> impl Future<Output = ()>
where
Expand All @@ -177,11 +120,11 @@ where
match maybe_ancestor {
Ok(ref ancestor) if ancestor.hash != *last_hash => info!(
"♻️ Reorg on #{},{} to #{},{}, common ancestor #{},{}",
format.print_with_color(Colour::Red.bold(), last_num),
style(last_num).red().bold(),
last_hash,
format.print_with_color(Colour::Green.bold(), n.header.number()),
style(n.header.number()).green().bold(),
n.hash,
format.print_with_color(Colour::White.bold(), ancestor.number),
style(ancestor.number).white().bold(),
ancestor.hash,
),
Ok(_) => {}
Expand Down Expand Up @@ -211,7 +154,7 @@ where
info!(
target: "subcoin",
"{best_indicator} Imported #{} ({} → {})",
format.print_with_color(Colour::White.bold(), n.header.number()),
style(n.header.number()).white().bold(),
n.header.parent_hash(),
n.hash,
);
Expand Down
6 changes: 3 additions & 3 deletions crates/subcoin-network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
//! This crate offers two strategies for the initial block download:
//!
//! - **Blocks-First**: Downloads the full block data sequentially starting from the last known
//! block until it's fully synced with the network, in batches. This is primarily for the testing
//! purpose.
//! block until it's fully synced with the network, in batches. This is primarily for the testing
//! purpose.
//!
//! - **Headers-First**: First downloads the block headers and then proceeds to the full block data
//! based on the checkpoints.
//! based on the checkpoints.
//!
//! However, due to the nature of Subcoin, building a Bitcoin SPV node solely by syncing Bitcoin headers
//! from the network is not possible, in that Subcoin requires full block data to derive the corresponding
Expand Down
2 changes: 1 addition & 1 deletion crates/subcoin-node/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl RunCmd {
spawn_handle.spawn(
"subcoin-informant",
None,
subcoin_informant::build(client.clone(), subcoin_network_handle, Default::default()),
subcoin_informant::build(client.clone(), subcoin_network_handle),
);

Ok(task_manager)
Expand Down
1 change: 1 addition & 0 deletions crates/subcoin-service/src/block_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ fn new_in_memory_backend(

let now = std::time::Instant::now();

// This might take long when the chain state is huge.
let top = client
.storage_pairs(info.best_hash, None, None)?
.map(|(key, data)| (key.0, data.0))
Expand Down
16 changes: 6 additions & 10 deletions crates/subcoin-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,11 @@ pub fn start_substrate_network<N>(
where
N: sc_network::NetworkBackend<Block, <Block as BlockT>::Hash>,
{
let net_config =
sc_network::config::FullNetworkConfiguration::<Block, <Block as BlockT>::Hash, N>::new(
&config.network,
);
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(
Expand Down Expand Up @@ -357,12 +358,7 @@ where
spawn_handle.spawn(
"substrate-informant",
None,
sc_informant::build(
client.clone(),
Arc::new(network),
sync_service.clone(),
config.informant_output_format.clone(),
),
sc_informant::build(client.clone(), Arc::new(network), sync_service.clone()),
);

network_starter.start_network();
Expand Down
1 change: 0 additions & 1 deletion crates/subcoin-test-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ pub fn test_configuration(tokio_handle: tokio::runtime::Handle) -> Configuration
announce_block: true,
data_path: base_path.path().into(),
base_path,
informant_output_format: Default::default(),
wasm_runtime_overrides: None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "1.79"
channel = "1.80"
components = ["rust-src"]
targets = ["wasm32-unknown-unknown"]

0 comments on commit 88308a1

Please sign in to comment.