@@ -3,7 +3,7 @@ use evm_domain_runtime::{AccountId as AccountId20, EVMChainIdConfig, EVMConfig,
3
3
use hex_literal:: hex;
4
4
use parity_scale_codec:: Encode ;
5
5
use sc_chain_spec:: GenericChainSpec ;
6
- use sc_service:: { ChainSpec , ChainType , NoExtension } ;
6
+ use sc_service:: { ChainSpec , ChainType } ;
7
7
use sp_core:: crypto:: AccountId32 ;
8
8
use sp_core:: { sr25519, Pair , Public } ;
9
9
use sp_domains:: storage:: RawGenesis ;
@@ -34,64 +34,58 @@ fn endowed_accounts() -> Vec<(MultiAccountId, Balance)> {
34
34
. collect ( )
35
35
}
36
36
37
- pub fn domain_dev_config ( ) -> GenericChainSpec < evm_domain_runtime:: RuntimeGenesisConfig > {
37
+ pub fn domain_dev_config (
38
+ ) -> Result < GenericChainSpec < evm_domain_runtime:: RuntimeGenesisConfig > , String > {
38
39
// Alith is sudo account
39
40
let sudo_account = AccountId20 :: from ( hex ! ( "f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac" ) ) ;
40
41
41
- // TODO: Migrate once https://github.com/paritytech/polkadot-sdk/issues/2963 is un-broken
42
- #[ allow( deprecated) ]
43
- GenericChainSpec :: from_genesis (
44
- // Name
45
- "Development" ,
46
- // ID
47
- "evm_domain_dev" ,
48
- ChainType :: Development ,
49
- move || {
50
- // This is the simplest bytecode to revert without returning any data.
51
- // We will pre-deploy it under all of our precompiles to ensure they can be called from
52
- // within contracts.
53
- // (PUSH1 0x00 PUSH1 0x00 REVERT)
54
- let revert_bytecode = vec ! [ 0x60 , 0x00 , 0x60 , 0x00 , 0xFD ] ;
55
-
56
- evm_domain_runtime:: RuntimeGenesisConfig {
57
- system : evm_domain_runtime:: SystemConfig :: default ( ) ,
58
- sudo : evm_domain_runtime:: SudoConfig {
59
- key : Some ( sudo_account) ,
60
- } ,
61
- balances : evm_domain_runtime:: BalancesConfig :: default ( ) ,
62
- // this is set to default and chain_id will be set into genesis during the domain
63
- // instantiation on Consensus runtime.
64
- evm_chain_id : EVMChainIdConfig :: default ( ) ,
65
- evm : EVMConfig {
66
- // We need _some_ code inserted at the precompile address so that
67
- // the evm will actually call the address.
68
- accounts : Precompiles :: used_addresses ( )
69
- . into_iter ( )
70
- . map ( |addr| {
71
- (
72
- addr,
73
- fp_evm:: GenesisAccount {
74
- nonce : Default :: default ( ) ,
75
- balance : Default :: default ( ) ,
76
- storage : Default :: default ( ) ,
77
- code : revert_bytecode. clone ( ) ,
78
- } ,
79
- )
80
- } )
81
- . collect ( ) ,
82
- ..Default :: default ( )
83
- } ,
84
- ..Default :: default ( )
85
- }
86
- } ,
87
- vec ! [ ] ,
88
- None ,
89
- None ,
90
- None ,
91
- None ,
92
- None ,
42
+ Ok ( GenericChainSpec :: builder (
93
43
evm_domain_runtime:: WASM_BINARY . expect ( "WASM binary was not build, please build it!" ) ,
44
+ None ,
94
45
)
46
+ . with_name ( "Development" )
47
+ . with_id ( "evm_domain_dev" )
48
+ . with_chain_type ( ChainType :: Development )
49
+ . with_genesis_config ( {
50
+ // This is the simplest bytecode to revert without returning any data.
51
+ // We will pre-deploy it under all of our precompiles to ensure they can be called from
52
+ // within contracts.
53
+ // (PUSH1 0x00 PUSH1 0x00 REVERT)
54
+ let revert_bytecode = vec ! [ 0x60 , 0x00 , 0x60 , 0x00 , 0xFD ] ;
55
+
56
+ serde_json:: to_value ( evm_domain_runtime:: RuntimeGenesisConfig {
57
+ system : evm_domain_runtime:: SystemConfig :: default ( ) ,
58
+ sudo : evm_domain_runtime:: SudoConfig {
59
+ key : Some ( sudo_account) ,
60
+ } ,
61
+ balances : evm_domain_runtime:: BalancesConfig :: default ( ) ,
62
+ // this is set to default and chain_id will be set into genesis during the domain
63
+ // instantiation on Consensus runtime.
64
+ evm_chain_id : EVMChainIdConfig :: default ( ) ,
65
+ evm : EVMConfig {
66
+ // We need _some_ code inserted at the precompile address so that
67
+ // the evm will actually call the address.
68
+ accounts : Precompiles :: used_addresses ( )
69
+ . into_iter ( )
70
+ . map ( |addr| {
71
+ (
72
+ addr,
73
+ fp_evm:: GenesisAccount {
74
+ nonce : Default :: default ( ) ,
75
+ balance : Default :: default ( ) ,
76
+ storage : Default :: default ( ) ,
77
+ code : revert_bytecode. clone ( ) ,
78
+ } ,
79
+ )
80
+ } )
81
+ . collect ( ) ,
82
+ ..Default :: default ( )
83
+ } ,
84
+ ..Default :: default ( )
85
+ } )
86
+ . map_err ( |error| format ! ( "Failed to serialize genesis config: {error}" ) ) ?
87
+ } )
88
+ . build ( ) )
95
89
}
96
90
97
91
pub ( crate ) fn consensus_dev_sudo_account ( ) -> AccountId32 {
@@ -103,7 +97,7 @@ pub fn create_domain_spec(
103
97
raw_genesis : RawGenesis ,
104
98
) -> Result < Box < dyn sc_cli:: ChainSpec > , String > {
105
99
let mut chain_spec = match chain_id {
106
- "dev" => domain_dev_config ( ) ,
100
+ "dev" => domain_dev_config ( ) ? ,
107
101
path => GenericChainSpec :: < evm_domain_runtime:: RuntimeGenesisConfig > :: from_json_file (
108
102
std:: path:: PathBuf :: from ( path) ,
109
103
) ?,
@@ -114,7 +108,7 @@ pub fn create_domain_spec(
114
108
115
109
pub fn load_domain_chain_spec ( spec_id : & str ) -> Result < Box < dyn sc_cli:: ChainSpec > , String > {
116
110
let chain_spec = match spec_id {
117
- "dev" => domain_dev_config ( ) ,
111
+ "dev" => domain_dev_config ( ) ? ,
118
112
path => GenericChainSpec :: < evm_domain_runtime:: RuntimeGenesisConfig > :: from_json_file (
119
113
std:: path:: PathBuf :: from ( path) ,
120
114
) ?,
@@ -163,24 +157,20 @@ pub fn dev_config() -> Result<GenericChainSpec<subspace_runtime::RuntimeGenesisC
163
157
. ok_or_else ( || "Development wasm not available" . to_string ( ) ) ?;
164
158
165
159
let raw_genesis_storage = {
166
- let domain_genesis_config = domain_dev_config ( ) ;
160
+ let domain_genesis_config = domain_dev_config ( ) ? ;
167
161
let storage = domain_genesis_config
168
162
. build_storage ( )
169
163
. expect ( "Failed to build genesis storage from genesis runtime config" ) ;
170
164
let raw_genesis = RawGenesis :: from_storage ( storage) ;
171
165
raw_genesis. encode ( )
172
166
} ;
173
167
174
- // TODO: Migrate once https://github.com/paritytech/polkadot-sdk/issues/2963 is un-broken
175
- #[ allow( deprecated) ]
176
- Ok ( GenericChainSpec :: from_genesis (
177
- // Name
178
- "Subspace development" ,
179
- // ID
180
- "subspace_dev" ,
181
- ChainType :: Development ,
182
- move || {
183
- subspace_genesis_config (
168
+ Ok ( GenericChainSpec :: builder ( wasm_binary, None )
169
+ . with_name ( "Subspace development" )
170
+ . with_id ( "subspace_dev" )
171
+ . with_chain_type ( ChainType :: Development )
172
+ . with_genesis_config ( patch_domain_runtime_version (
173
+ serde_json:: to_value ( subspace_genesis_config (
184
174
// Sudo account
185
175
get_account_id_from_seed ( "Alice" ) ,
186
176
// Pre-funded accounts
@@ -214,22 +204,10 @@ pub fn dev_config() -> Result<GenericChainSpec<subspace_runtime::RuntimeGenesisC
214
204
initial_balances : endowed_accounts ( ) ,
215
205
permissioned_action_allowed_by : PermissionedActionAllowedBy :: Anyone ,
216
206
} ,
217
- )
218
- } ,
219
- // Bootnodes
220
- vec ! [ ] ,
221
- // Telemetry
222
- None ,
223
- // Protocol ID
224
- None ,
225
- None ,
226
- // Properties
227
- None ,
228
- // Extensions
229
- NoExtension :: None ,
230
- // Code
231
- wasm_binary,
232
- ) )
207
+ ) )
208
+ . map_err ( |error| format ! ( "Failed to serialize genesis config: {error}" ) ) ?,
209
+ ) )
210
+ . build ( ) )
233
211
}
234
212
235
213
/// Configure initial storage state for FRAME modules.
@@ -302,3 +280,36 @@ fn subspace_genesis_config(
302
280
} ,
303
281
}
304
282
}
283
+
284
+ // TODO: Workaround for https://github.com/paritytech/polkadot-sdk/issues/4001
285
+ fn patch_domain_runtime_version ( mut genesis_config : serde_json:: Value ) -> serde_json:: Value {
286
+ let Some ( runtime_version) = genesis_config
287
+ . get_mut ( "domains" )
288
+ . and_then ( |domains| domains. get_mut ( "genesisDomain" ) )
289
+ . and_then ( |genesis_domain| genesis_domain. get_mut ( "runtime_version" ) )
290
+ else {
291
+ return genesis_config;
292
+ } ;
293
+
294
+ if let Some ( spec_name) = runtime_version. get_mut ( "specName" ) {
295
+ if let Some ( spec_name_bytes) = spec_name
296
+ . as_str ( )
297
+ . map ( |spec_name| spec_name. as_bytes ( ) . to_vec ( ) )
298
+ {
299
+ * spec_name = serde_json:: to_value ( spec_name_bytes)
300
+ . expect ( "Bytes serialization doesn't fail; qed" ) ;
301
+ }
302
+ }
303
+
304
+ if let Some ( impl_name) = runtime_version. get_mut ( "implName" ) {
305
+ if let Some ( impl_name_bytes) = impl_name
306
+ . as_str ( )
307
+ . map ( |impl_name| impl_name. as_bytes ( ) . to_vec ( ) )
308
+ {
309
+ * impl_name = serde_json:: to_value ( impl_name_bytes)
310
+ . expect ( "Bytes serialization doesn't fail; qed" ) ;
311
+ }
312
+ }
313
+
314
+ genesis_config
315
+ }
0 commit comments