@@ -8,6 +8,8 @@ use node_subtensor_runtime::opaque::Block;
88use sc_cli:: RunCmd ;
99use sc_consensus:: BasicQueue ;
1010use sc_service:: { Configuration , TaskManager } ;
11+ use std:: fmt;
12+ use std:: path:: PathBuf ;
1113use 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