15
15
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
16
16
17
17
use structopt:: StructOpt ;
18
- use sc_service:: {
19
- Configuration , RuntimeGenesis ,
20
- config:: DatabaseConfig , PruningMode ,
21
- } ;
18
+ use sc_service:: { Configuration , RuntimeGenesis , config:: DatabaseConfig } ;
22
19
23
20
use crate :: error;
24
21
use crate :: arg_enums:: {
25
22
WasmExecutionMethod , TracingReceiver , ExecutionStrategy , DEFAULT_EXECUTION_BLOCK_CONSTRUCTION ,
26
23
DEFAULT_EXECUTION_IMPORT_BLOCK , DEFAULT_EXECUTION_OFFCHAIN_WORKER , DEFAULT_EXECUTION_OTHER ,
27
24
DEFAULT_EXECUTION_SYNCING
28
25
} ;
26
+ use crate :: params:: PruningParams ;
29
27
30
28
/// Parameters for block import.
31
29
#[ derive( Debug , StructOpt , Clone ) ]
32
30
pub struct ImportParams {
33
- /// Specify the state pruning mode, a number of blocks to keep or 'archive'.
34
- ///
35
- /// Default is to keep all block states if the node is running as a
36
- /// validator (i.e. 'archive'), otherwise state is only kept for the last
37
- /// 256 blocks.
38
- #[ structopt( long = "pruning" , value_name = "PRUNING_MODE" ) ]
39
- pub pruning : Option < String > ,
31
+ #[ allow( missing_docs) ]
32
+ #[ structopt( flatten) ]
33
+ pub pruning_params : PruningParams ,
40
34
41
35
/// Force start with unsafe pruning settings.
42
36
///
@@ -87,7 +81,7 @@ impl ImportParams {
87
81
/// Put block import CLI params into `config` object.
88
82
pub fn update_config < G , E > (
89
83
& self ,
90
- config : & mut Configuration < G , E > ,
84
+ mut config : & mut Configuration < G , E > ,
91
85
role : sc_service:: Roles ,
92
86
is_dev : bool ,
93
87
) -> error:: Result < ( ) >
@@ -102,27 +96,7 @@ impl ImportParams {
102
96
103
97
config. state_cache_size = self . state_cache_size ;
104
98
105
- // by default we disable pruning if the node is an authority (i.e.
106
- // `ArchiveAll`), otherwise we keep state for the last 256 blocks. if the
107
- // node is an authority and pruning is enabled explicitly, then we error
108
- // unless `unsafe_pruning` is set.
109
- config. pruning = match & self . pruning {
110
- Some ( ref s) if s == "archive" => PruningMode :: ArchiveAll ,
111
- None if role == sc_service:: Roles :: AUTHORITY => PruningMode :: ArchiveAll ,
112
- None => PruningMode :: default ( ) ,
113
- Some ( s) => {
114
- if role == sc_service:: Roles :: AUTHORITY && !self . unsafe_pruning {
115
- return Err ( error:: Error :: Input (
116
- "Validators should run with state pruning disabled (i.e. archive). \
117
- You can ignore this check with `--unsafe-pruning`.". to_string ( )
118
- ) ) ;
119
- }
120
-
121
- PruningMode :: keep_blocks ( s. parse ( )
122
- . map_err ( |_| error:: Error :: Input ( "Invalid pruning mode specified" . to_string ( ) ) ) ?
123
- )
124
- } ,
125
- } ;
99
+ self . pruning_params . update_config ( & mut config, role, self . unsafe_pruning ) ?;
126
100
127
101
config. wasm_method = self . wasm_method . into ( ) ;
128
102
@@ -144,6 +118,7 @@ impl ImportParams {
144
118
exec_all_or ( exec. execution_offchain_worker , DEFAULT_EXECUTION_OFFCHAIN_WORKER ) ,
145
119
other : exec_all_or ( exec. execution_other , DEFAULT_EXECUTION_OTHER ) ,
146
120
} ;
121
+
147
122
Ok ( ( ) )
148
123
}
149
124
}
0 commit comments