Skip to content

Commit f4b4a21

Browse files
authored
Merge pull request #2489 from opentensor/feature/build-test-clone
Extend node with build-patched-spec subcommand
2 parents 1af5008 + 946dc03 commit f4b4a21

File tree

15 files changed

+863
-40
lines changed

15 files changed

+863
-40
lines changed

Cargo.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ clap = { workspace = true, features = ["derive"] }
2626
futures = { workspace = true, features = ["thread-pool"] }
2727
serde = { workspace = true, features = ["derive"] }
2828
hex.workspace = true
29-
tokio = { workspace = true, features = ["time"] }
29+
tokio = { workspace = true, features = ["time", "rt", "net"] }
3030

3131
# Storage import
3232
memmap2.workspace = true
@@ -68,6 +68,7 @@ sp-offchain.workspace = true
6868
sp-session.workspace = true
6969
frame-metadata-hash-extension.workspace = true
7070
frame-system.workspace = true
71+
frame-support.workspace = true
7172
pallet-transaction-payment.workspace = true
7273
pallet-commitments.workspace = true
7374
pallet-drand.workspace = true
@@ -80,7 +81,7 @@ polkadot-sdk = { workspace = true, features = [
8081
] }
8182

8283
# These dependencies are used for the subtensor's RPCs
83-
jsonrpsee = { workspace = true, features = ["server"] }
84+
jsonrpsee = { workspace = true, features = ["server", "http-client"] }
8485
sc-rpc.workspace = true
8586
sp-api.workspace = true
8687
sc-rpc-api.workspace = true
@@ -156,6 +157,7 @@ runtime-benchmarks = [
156157
"node-subtensor-runtime/runtime-benchmarks",
157158
"frame-benchmarking/runtime-benchmarks",
158159
"frame-benchmarking-cli/runtime-benchmarks",
160+
"frame-support/runtime-benchmarks",
159161
"frame-system/runtime-benchmarks",
160162
"sc-service/runtime-benchmarks",
161163
"sp-runtime/runtime-benchmarks",
@@ -174,6 +176,7 @@ pow-faucet = []
174176
# in the near future.
175177
try-runtime = [
176178
"node-subtensor-runtime/try-runtime",
179+
"frame-support/try-runtime",
177180
"frame-system/try-runtime",
178181
"pallet-transaction-payment/try-runtime",
179182
"sp-runtime/try-runtime",

node/src/cli.rs

Lines changed: 104 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use node_subtensor_runtime::opaque::Block;
88
use sc_cli::RunCmd;
99
use sc_consensus::BasicQueue;
1010
use sc_service::{Configuration, TaskManager};
11+
use std::fmt;
12+
use std::path::PathBuf;
1113
use std::sync::Arc;
1214

1315
#[derive(Debug, clap::Parser)]
@@ -33,6 +35,14 @@ pub struct Cli {
3335

3436
#[command(flatten)]
3537
pub eth: EthConfiguration,
38+
39+
/// Control historical gap-backfill during initial/catch-up sync.
40+
///
41+
/// `keep` preserves complete history (default for normal node runs).
42+
/// `skip` is faster/lighter but historical block data may be incomplete.
43+
/// For `build-patched-spec`, the implicit default is `skip` unless this flag is explicitly set.
44+
#[arg(long, value_enum, default_value_t = HistoryBackfill::Keep)]
45+
pub history_backfill: HistoryBackfill,
3646
}
3747

3848
#[allow(clippy::large_enum_variant)]
@@ -70,6 +80,93 @@ pub enum Subcommand {
7080

7181
// Db meta columns information.
7282
ChainInfo(sc_cli::ChainInfoCmd),
83+
84+
// Build a patched test chainspec from synced network state.
85+
#[command(name = "build-patched-spec")]
86+
CloneState(CloneStateCmd),
87+
}
88+
89+
/// Build a patched clone chainspec by syncing state, exporting raw state, and applying test patch.
90+
#[derive(Debug, Clone, clap::Args)]
91+
pub struct CloneStateCmd {
92+
/// Chain spec identifier or path (same semantics as `--chain`).
93+
#[arg(long, value_name = "CHAIN")]
94+
pub chain: String,
95+
96+
/// Base path used for syncing and state export.
97+
#[arg(long, value_name = "PATH")]
98+
pub base_path: PathBuf,
99+
100+
/// Output file path for the final patched chainspec JSON.
101+
#[arg(long, value_name = "FILE")]
102+
pub output: PathBuf,
103+
104+
/// Sync mode for the temporary sync node.
105+
#[arg(long, value_enum, default_value_t = sc_cli::SyncMode::Warp)]
106+
pub sync: sc_cli::SyncMode,
107+
108+
/// Database backend for the temporary sync/export node.
109+
#[arg(long, value_enum, default_value_t = sc_cli::Database::ParityDb)]
110+
pub database: sc_cli::Database,
111+
112+
/// RPC port used by the temporary sync node.
113+
#[arg(long, default_value_t = 9966)]
114+
pub rpc_port: u16,
115+
116+
/// P2P port used by the temporary sync node.
117+
#[arg(long, default_value_t = 30466)]
118+
pub port: u16,
119+
120+
/// Maximum time to wait for sync completion.
121+
#[arg(long, default_value_t = 7200)]
122+
pub sync_timeout_sec: u64,
123+
124+
/// Accept sync completion when current is within this many blocks of highest.
125+
#[arg(long, default_value_t = 8)]
126+
pub sync_lag_blocks: u64,
127+
128+
/// Optional bootnodes for the sync step. Repeatable.
129+
#[arg(long, value_name = "BOOTNODE")]
130+
pub bootnodes: Vec<String>,
131+
132+
/// Include Alice in patched validator authorities (default if no validator flags are passed;
133+
/// Sudo is assigned to the first selected validator in Alice->Bob->Charlie order).
134+
#[arg(long, default_value_t = false)]
135+
pub alice: bool,
136+
137+
/// Include Bob in patched validator authorities (if any validator flag is set, only selected
138+
/// validators are used; Sudo is assigned to the first selected validator in Alice->Bob->Charlie
139+
/// order).
140+
#[arg(long, default_value_t = false)]
141+
pub bob: bool,
142+
143+
/// Include Charlie in patched validator authorities (if any validator flag is set, only
144+
/// selected validators are used; Sudo is assigned to the first selected validator in
145+
/// Alice->Bob->Charlie order).
146+
#[arg(long, default_value_t = false)]
147+
pub charlie: bool,
148+
}
149+
150+
#[derive(Debug, Clone, Copy, clap::ValueEnum, Default)]
151+
pub enum HistoryBackfill {
152+
#[default]
153+
Keep,
154+
Skip,
155+
}
156+
157+
impl AsRef<str> for HistoryBackfill {
158+
fn as_ref(&self) -> &str {
159+
match self {
160+
HistoryBackfill::Keep => "keep",
161+
HistoryBackfill::Skip => "skip",
162+
}
163+
}
164+
}
165+
166+
impl fmt::Display for HistoryBackfill {
167+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
168+
f.write_str(self.as_ref())
169+
}
73170
}
74171

75172
/// Available Sealing methods.
@@ -99,6 +196,7 @@ impl SupportedConsensusMechanism {
99196
&self,
100197
config: &mut Configuration,
101198
eth_config: &EthConfiguration,
199+
skip_history_backfill: bool,
102200
) -> Result<
103201
(
104202
Arc<FullClient>,
@@ -110,8 +208,12 @@ impl SupportedConsensusMechanism {
110208
sc_service::Error,
111209
> {
112210
match self {
113-
SupportedConsensusMechanism::Aura => new_chain_ops::<AuraConsensus>(config, eth_config),
114-
SupportedConsensusMechanism::Babe => new_chain_ops::<BabeConsensus>(config, eth_config),
211+
SupportedConsensusMechanism::Aura => {
212+
new_chain_ops::<AuraConsensus>(config, eth_config, skip_history_backfill)
213+
}
214+
SupportedConsensusMechanism::Babe => {
215+
new_chain_ops::<BabeConsensus>(config, eth_config, skip_history_backfill)
216+
}
115217
}
116218
}
117219
}

0 commit comments

Comments
 (0)