1
- use sp_core:: { Pair , Public , sr25519, U256 , H160 } ;
1
+ use sp_core:: { Pair , Public , sr25519, U256 , H160 , crypto :: UncheckedInto , } ;
2
2
use mathchain_runtime:: {
3
3
AccountId , AuraConfig , BalancesConfig , EVMConfig , EthereumConfig , GenesisConfig , GrandpaConfig ,
4
- SudoConfig , SystemConfig , WASM_BINARY , Signature
4
+ SudoConfig , SystemConfig , WASM_BINARY , Signature , ValidatorSetConfig , opaque :: SessionKeys , SessionConfig
5
5
} ;
6
6
use mathchain_runtime:: constants:: currency:: MATHS as MATH ;
7
7
@@ -11,6 +11,7 @@ use sp_runtime::traits::{Verify, IdentifyAccount};
11
11
use sc_service:: { ChainType , Properties } ;
12
12
use std:: collections:: BTreeMap ;
13
13
use std:: str:: FromStr ;
14
+ use sc_telemetry:: TelemetryEndpoints ;
14
15
15
16
const DEFAULT_PROTOCOL_ID : & str = "math" ;
16
17
@@ -79,6 +80,145 @@ pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {
79
80
)
80
81
}
81
82
83
+ fn session_keys (
84
+ aura : AuraId ,
85
+ grandpa : GrandpaId ,
86
+ ) -> SessionKeys {
87
+ SessionKeys { aura, grandpa }
88
+ }
89
+
90
+ pub fn get_authority_keys_from_seed ( seed : & str ) -> (
91
+ AccountId ,
92
+ AuraId ,
93
+ GrandpaId
94
+ ) {
95
+ (
96
+ get_account_id_from_seed :: < sr25519:: Public > ( seed) ,
97
+ get_from_seed :: < AuraId > ( seed) ,
98
+ get_from_seed :: < GrandpaId > ( seed)
99
+ )
100
+ }
101
+
102
+ pub fn galois_for_genesis ( ) -> Result < ChainSpec , String > {
103
+ let wasm_binary = WASM_BINARY . ok_or_else ( || "Galois wasm not available" . to_string ( ) ) ?;
104
+
105
+ const ROOT : & ' static str = "0x24a80b84d2d5130beafcb2b1a3b1a0e0e1cee122ef0e508d6b1eb862b802fe1d" ;
106
+ let root: AccountId = array_bytes:: hex_str_array_unchecked!( ROOT , 32 ) . into ( ) ;
107
+
108
+ const GENESIS_VALIDATOR_SR1 : & ' static str =
109
+ "0xf88768150c3a86509384e744132b5323390c6c24ddccbe39468865db7c07d842" ;
110
+ const GENESIS_VALIDATOR_ED1 : & ' static str =
111
+ "0x490c6732f48ae1ce0e0208d53776e7b0153713fce99e5a0c36731fd4da761450" ;
112
+
113
+ const GENESIS_VALIDATOR_SR2 : & ' static str =
114
+ "0xa2e1437ba4d59fc44ee774fab33a06d952527e909e35ef64dc91859bbb60fe65" ;
115
+ const GENESIS_VALIDATOR_ED2 : & ' static str =
116
+ "0xa2e1437ba4d59fc44ee774fab33a06d952527e909e35ef64dc91859bbb60fe65" ;
117
+
118
+ const GENESIS_VALIDATOR_SR3 : & ' static str =
119
+ "0xbca164498a1bc44c91e20a64c83431592a9caa7aa509e0ba5d1fc5710b524557" ;
120
+ const GENESIS_VALIDATOR_ED3 : & ' static str =
121
+ "0xf350c893e43dafe5d0e1c572673666b3d414057c0d117b476fcac5f777e627f2" ;
122
+
123
+ let genesis_validator1: (
124
+ AccountId ,
125
+ AuraId ,
126
+ GrandpaId ,
127
+ ) = {
128
+ let stash = array_bytes:: hex_str_array_unchecked!( GENESIS_VALIDATOR_SR1 , 32 ) ;
129
+ let session = array_bytes:: hex_str_array_unchecked!( GENESIS_VALIDATOR_SR1 , 32 ) ;
130
+ let grandpa = array_bytes:: hex_str_array_unchecked!( GENESIS_VALIDATOR_ED1 , 32 ) ;
131
+
132
+ (
133
+ stash. into ( ) ,
134
+ session. unchecked_into ( ) ,
135
+ grandpa. unchecked_into ( ) ,
136
+ )
137
+ } ;
138
+
139
+ let genesis_validator2: (
140
+ AccountId ,
141
+ AuraId ,
142
+ GrandpaId ,
143
+ ) = {
144
+ let stash = array_bytes:: hex_str_array_unchecked!( GENESIS_VALIDATOR_SR2 , 32 ) ;
145
+ let session = array_bytes:: hex_str_array_unchecked!( GENESIS_VALIDATOR_SR2 , 32 ) ;
146
+ let grandpa = array_bytes:: hex_str_array_unchecked!( GENESIS_VALIDATOR_ED2 , 32 ) ;
147
+
148
+ (
149
+ stash. into ( ) ,
150
+ session. unchecked_into ( ) ,
151
+ grandpa. unchecked_into ( ) ,
152
+ )
153
+ } ;
154
+
155
+ let genesis_validator3: (
156
+ AccountId ,
157
+ AuraId ,
158
+ GrandpaId ,
159
+ ) = {
160
+ let stash = array_bytes:: hex_str_array_unchecked!( GENESIS_VALIDATOR_SR3 , 32 ) ;
161
+ let session = array_bytes:: hex_str_array_unchecked!( GENESIS_VALIDATOR_SR3 , 32 ) ;
162
+ let grandpa = array_bytes:: hex_str_array_unchecked!( GENESIS_VALIDATOR_ED3 , 32 ) ;
163
+
164
+ (
165
+ stash. into ( ) ,
166
+ session. unchecked_into ( ) ,
167
+ grandpa. unchecked_into ( ) ,
168
+ )
169
+ } ;
170
+
171
+ let endowed_accounts = [
172
+ // Sudo
173
+ "0x24a80b84d2d5130beafcb2b1a3b1a0e0e1cee122ef0e508d6b1eb862b802fe1d" ,
174
+ // node1
175
+ "0xf88768150c3a86509384e744132b5323390c6c24ddccbe39468865db7c07d842" ,
176
+ // node2
177
+ "0xa2e1437ba4d59fc44ee774fab33a06d952527e909e35ef64dc91859bbb60fe65" ,
178
+ // node3
179
+ "0xbca164498a1bc44c91e20a64c83431592a9caa7aa509e0ba5d1fc5710b524557"
180
+ ]
181
+ . iter ( )
182
+ . map ( |s| array_bytes:: hex_str_array_unchecked!( s, 32 ) . into ( ) )
183
+ . collect :: < Vec < _ > > ( ) ;
184
+
185
+ Ok ( ChainSpec :: from_genesis (
186
+ // Name
187
+ "Galois" ,
188
+ "galois" ,
189
+ ChainType :: Live ,
190
+ move || testnet_genesis (
191
+ wasm_binary,
192
+ // Initial Poa authorities
193
+ vec ! [
194
+ genesis_validator1. clone( ) ,
195
+ genesis_validator2. clone( ) ,
196
+ genesis_validator3. clone( ) ,
197
+ ] ,
198
+ root. clone ( ) ,
199
+ endowed_accounts. clone ( ) ,
200
+ true
201
+ ) ,
202
+ vec ! [
203
+ "/ip4/47.111.168.132/tcp/3031/p2p/12D3KooWNMtGp5TQGApApAoPj37QHXSCv1Yi4mkZvVnse2A5wQZK" . parse( ) . unwrap( ) ,
204
+ "/ip4/8.209.214.249/tcp/3033/p2p/12D3KooWG2QSh8hKp1Bm4XuidjFijKZcHY9Q7my4fBJfJTqWj4Xd" . parse( ) . unwrap( )
205
+ ] ,
206
+ Some (
207
+ TelemetryEndpoints :: new ( vec ! [
208
+ ( "/dns4/telemetry.polkadot.io/tcp/443/x-parity-wss/%2Fsubmit%2F" . parse( ) . unwrap( ) , 0 ) ,
209
+ ( "/dns4/telemetry.maiziqianbao.net/tcp/443/x-parity-wss/%2Fsubmit%2F" . parse( ) . unwrap( ) , 0 ) ,
210
+ ( "/dns4/telemetry.maiziqianbao.vip/tcp/443/x-parity-wss/%2Fsubmit%2F" . parse( ) . unwrap( ) , 0 ) ,
211
+ ] ) . expect ( "Galois telemetry url is valid; qed" )
212
+ ) ,
213
+ // Protocol ID
214
+ Some ( DEFAULT_PROTOCOL_ID ) ,
215
+ // Properties
216
+ Some ( math_testnet_properties ( ) ) ,
217
+ // Extensions
218
+ None
219
+ ) )
220
+ }
221
+
82
222
pub fn development_config ( ) -> Result < ChainSpec , String > {
83
223
let wasm_binary = WASM_BINARY . ok_or_else ( || "Development wasm not available" . to_string ( ) ) ?;
84
224
@@ -92,7 +232,7 @@ pub fn development_config() -> Result<ChainSpec, String> {
92
232
wasm_binary,
93
233
// Initial PoA authorities
94
234
vec ! [
95
- authority_keys_from_seed ( "Alice" ) ,
235
+ get_authority_keys_from_seed ( "Alice" ) ,
96
236
] ,
97
237
// Sudo account
98
238
get_account_id_from_seed :: < sr25519:: Public > ( "Alice" ) ,
@@ -131,8 +271,8 @@ pub fn local_testnet_config() -> Result<ChainSpec, String> {
131
271
wasm_binary,
132
272
// Initial PoA authorities
133
273
vec ! [
134
- authority_keys_from_seed ( "Alice" ) ,
135
- authority_keys_from_seed ( "Bob" ) ,
274
+ get_authority_keys_from_seed ( "Alice" ) ,
275
+ get_authority_keys_from_seed ( "Bob" ) ,
136
276
] ,
137
277
// Sudo account
138
278
get_account_id_from_seed :: < sr25519:: Public > ( "Alice" ) ,
@@ -169,7 +309,7 @@ pub fn local_testnet_config() -> Result<ChainSpec, String> {
169
309
/// Configure initial storage state for FRAME modules.
170
310
fn testnet_genesis (
171
311
wasm_binary : & [ u8 ] ,
172
- initial_authorities : Vec < ( AuraId , GrandpaId ) > ,
312
+ initial_authorities : Vec < ( AccountId , AuraId , GrandpaId ) > ,
173
313
root_key : AccountId ,
174
314
endowed_accounts : Vec < AccountId > ,
175
315
_enable_println : bool ,
@@ -197,10 +337,10 @@ fn testnet_genesis(
197
337
balances : endowed_accounts. iter ( ) . cloned ( ) . map ( |k|( k, 10000 * MATH ) ) . collect ( ) ,
198
338
} ,
199
339
pallet_aura : AuraConfig {
200
- authorities : initial_authorities . iter ( ) . map ( |x| ( x . 0 . clone ( ) ) ) . collect ( ) ,
340
+ authorities : vec ! [ ] ,
201
341
} ,
202
342
pallet_grandpa : GrandpaConfig {
203
- authorities : initial_authorities . iter ( ) . map ( |x| ( x . 1 . clone ( ) , 1 ) ) . collect ( ) ,
343
+ authorities : vec ! [ ] ,
204
344
} ,
205
345
pallet_sudo : SudoConfig {
206
346
// Assign network admin rights.
@@ -210,5 +350,13 @@ fn testnet_genesis(
210
350
accounts : evm_accounts,
211
351
} ,
212
352
pallet_ethereum : EthereumConfig { } ,
353
+ pallet_validator_set : ValidatorSetConfig {
354
+ validators : initial_authorities. iter ( ) . map ( |x| x. 0 . clone ( ) ) . collect :: < Vec < _ > > ( ) ,
355
+ } ,
356
+ pallet_session : SessionConfig {
357
+ keys : initial_authorities. iter ( ) . map ( |x| {
358
+ ( x. 0 . clone ( ) , x. 0 . clone ( ) , session_keys ( x. 1 . clone ( ) , x. 2 . clone ( ) ) )
359
+ } ) . collect :: < Vec < _ > > ( ) ,
360
+ } ,
213
361
}
214
362
}
0 commit comments