Skip to content

Commit 0bc5743

Browse files
committed
start work on finality builtin
remove async_extra stuff continue continue local testnet (Alice + Bob) for node
1 parent 8118db6 commit 0bc5743

18 files changed

+1329
-984
lines changed

Cargo.lock

+338-760
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/node/node/src/chain_spec.rs

+59-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
use bridge_node_runtime::{
1818
AccountId, AuraConfig, BalancesConfig, BridgeEthPoAConfig, GenesisConfig, GrandpaConfig, Signature, SudoConfig,
19-
SystemConfig, WASM_BINARY,
19+
SystemConfig, SessionConfig, SessionKeys, WASM_BINARY,
2020
};
2121
use grandpa_primitives::AuthorityId as GrandpaId;
2222
use sc_service;
@@ -34,6 +34,8 @@ pub type ChainSpec = sc_service::ChainSpec<GenesisConfig>;
3434
pub enum Alternative {
3535
/// Whatever the current runtime is, with just Alice as an auth.
3636
Development,
37+
/// Whatever the current runtime is, with simple Alice/Bob auths.
38+
LocalTestnet,
3739
}
3840

3941
/// Helper function to generate a crypto pair from seed
@@ -54,8 +56,12 @@ where
5456
}
5557

5658
/// Helper function to generate an authority key for Aura
57-
pub fn get_authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {
58-
(get_from_seed::<AuraId>(s), get_from_seed::<GrandpaId>(s))
59+
pub fn get_authority_keys_from_seed(s: &str) -> (AccountId, AuraId, GrandpaId) {
60+
(
61+
get_account_id_from_seed::<sr25519::Public>(s),
62+
get_from_seed::<AuraId>(s),
63+
get_from_seed::<GrandpaId>(s),
64+
)
5965
}
6066

6167
impl Alternative {
@@ -84,19 +90,58 @@ impl Alternative {
8490
None,
8591
None,
8692
),
93+
Alternative::LocalTestnet => ChainSpec::from_genesis(
94+
"Local Testnet",
95+
"local_testnet",
96+
|| testnet_genesis(
97+
vec![
98+
get_authority_keys_from_seed("Alice"),
99+
get_authority_keys_from_seed("Bob"),
100+
],
101+
get_account_id_from_seed::<sr25519::Public>("Alice"),
102+
vec![
103+
get_account_id_from_seed::<sr25519::Public>("Alice"),
104+
get_account_id_from_seed::<sr25519::Public>("Bob"),
105+
get_account_id_from_seed::<sr25519::Public>("Charlie"),
106+
get_account_id_from_seed::<sr25519::Public>("Dave"),
107+
get_account_id_from_seed::<sr25519::Public>("Eve"),
108+
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
109+
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
110+
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
111+
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
112+
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
113+
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
114+
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
115+
],
116+
true,
117+
),
118+
vec![],
119+
None,
120+
None,
121+
None,
122+
None
123+
),
87124
})
88125
}
89126

90127
pub(crate) fn from(s: &str) -> Option<Self> {
91128
match s {
92129
"" | "dev" => Some(Alternative::Development),
130+
"local" => Some(Alternative::LocalTestnet),
93131
_ => None,
94132
}
95133
}
96134
}
97135

136+
fn session_keys(
137+
aura: AuraId,
138+
grandpa: GrandpaId,
139+
) -> SessionKeys {
140+
SessionKeys { aura, grandpa }
141+
}
142+
98143
fn testnet_genesis(
99-
initial_authorities: Vec<(AuraId, GrandpaId)>,
144+
initial_authorities: Vec<(AccountId, AuraId, GrandpaId)>,
100145
root_key: AccountId,
101146
endowed_accounts: Vec<AccountId>,
102147
_enable_println: bool,
@@ -110,13 +155,21 @@ fn testnet_genesis(
110155
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
111156
}),
112157
pallet_aura: Some(AuraConfig {
113-
authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),
158+
authorities: Vec::new(),
114159
}),
115160
pallet_bridge_eth_poa: load_kovan_config(),
116161
pallet_grandpa: Some(GrandpaConfig {
117-
authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect(),
162+
authorities: Vec::new(),
118163
}),
119164
pallet_sudo: Some(SudoConfig { key: root_key }),
165+
pallet_session: Some(SessionConfig {
166+
keys: initial_authorities.iter().map(|x| {
167+
(x.0.clone(), x.0.clone(), session_keys(
168+
x.1.clone(),
169+
x.2.clone(),
170+
))
171+
}).collect::<Vec<_>>(),
172+
}),
120173
}
121174
}
122175

bin/node/runtime/Cargo.toml

+12
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ default-features = false
5959
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
6060
git = "https://github.com/paritytech/substrate/"
6161

62+
[dependencies.pallet-session]
63+
version = "2.0.0-alpha.2"
64+
default-features = false
65+
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
66+
git = "https://github.com/paritytech/substrate/"
67+
6268
[dependencies.frame-system]
6369
version = "2.0.0-alpha.2"
6470
default-features = false
@@ -149,6 +155,12 @@ default-features = false
149155
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
150156
git = "https://github.com/paritytech/substrate/"
151157

158+
[dependencies.sp-staking]
159+
version = "2.0.0-alpha.2"
160+
default-features = false
161+
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
162+
git = "https://github.com/paritytech/substrate/"
163+
152164
[dependencies.sp-std]
153165
version = "2.0.0-alpha.2"
154166
default-features = false

bin/node/runtime/src/lib.rs

+42-8
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use pallet_grandpa::AuthorityList as GrandpaAuthorityList;
2929
use sp_api::impl_runtime_apis;
3030
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
3131
use sp_core::OpaqueMetadata;
32-
use sp_runtime::traits::{BlakeTwo256, Block as BlockT, ConvertInto, IdentifyAccount, IdentityLookup, Verify};
32+
use sp_runtime::traits::{BlakeTwo256, Block as BlockT, ConvertInto, IdentifyAccount, IdentityLookup, Verify, OpaqueKeys};
3333
use sp_runtime::{
3434
create_runtime_str, generic, impl_opaque_keys, transaction_validity::TransactionValidity, ApplyExtrinsicResult,
3535
MultiSignature,
@@ -89,12 +89,12 @@ pub mod opaque {
8989
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
9090
/// Opaque block identifier type.
9191
pub type BlockId = generic::BlockId<Block>;
92+
}
9293

93-
impl_opaque_keys! {
94-
pub struct SessionKeys {
95-
pub aura: Aura,
96-
pub grandpa: Grandpa,
97-
}
94+
impl_opaque_keys! {
95+
pub struct SessionKeys {
96+
pub aura: Aura,
97+
pub grandpa: Grandpa,
9898
}
9999
}
100100

@@ -233,6 +233,39 @@ impl pallet_sudo::Trait for Runtime {
233233
type Call = Call;
234234
}
235235

236+
parameter_types! {
237+
pub const Period: BlockNumber = 8;
238+
pub const Offset: BlockNumber = 0;
239+
}
240+
241+
impl pallet_session::Trait for Runtime {
242+
type Event = Event;
243+
type ValidatorId = <Self as frame_system::Trait>::AccountId;
244+
type ValidatorIdOf = ();
245+
type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;
246+
type SessionManager = ShiftSessionManager;
247+
type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
248+
type Keys = SessionKeys;
249+
type DisabledValidatorsThreshold = ();
250+
}
251+
252+
pub struct ShiftSessionManager;
253+
impl pallet_session::SessionManager<AccountId> for ShiftSessionManager {
254+
fn end_session(_: sp_staking::SessionIndex) {}
255+
// fn start_session(_: sp_staking::SessionIndex) {}
256+
fn new_session(session_index: sp_staking::SessionIndex) -> Option<Vec<AccountId>> {
257+
if session_index == 0 || session_index == 1 {
258+
return None;
259+
}
260+
261+
let mut current_validators = <pallet_session::Module<Runtime>>::validators();
262+
if session_index % 2 != 0 {
263+
current_validators.reverse();
264+
}
265+
Some(current_validators)
266+
}
267+
}
268+
236269
construct_runtime!(
237270
pub enum Runtime where
238271
Block = Block,
@@ -247,6 +280,7 @@ construct_runtime!(
247280
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
248281
TransactionPayment: pallet_transaction_payment::{Module, Storage},
249282
Sudo: pallet_sudo::{Module, Call, Config<T>, Storage, Event<T>},
283+
Session: pallet_session::{Module, Call, Storage, Event, Config<T>},
250284
BridgeEthPoA: pallet_bridge_eth_poa::{Module, Call, Config, Storage, ValidateUnsigned},
251285
}
252286
);
@@ -374,13 +408,13 @@ impl_runtime_apis! {
374408

375409
impl sp_session::SessionKeys<Block> for Runtime {
376410
fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
377-
opaque::SessionKeys::generate(seed)
411+
SessionKeys::generate(seed)
378412
}
379413

380414
fn decode_session_keys(
381415
encoded: Vec<u8>,
382416
) -> Option<Vec<(Vec<u8>, sp_core::crypto::KeyTypeId)>> {
383-
opaque::SessionKeys::decode_into_raw_public_keys(&encoded)
417+
SessionKeys::decode_into_raw_public_keys(&encoded)
384418
}
385419
}
386420

modules/ethereum-contract/builtin/Cargo.toml

+19-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,27 @@ edition = "2018"
1010
# General dependencies
1111

1212
codec = { package = "parity-scale-codec", version = "1.0.0" }
13+
ethereum-types = "0.8.0"
1314
finality-grandpa = { version = "0.11.2", features = ["derive-codec"] }
14-
sp-blockchain = "2.0.0-alpha.5"
15-
sp-finality-grandpa = "2.0.0-alpha.5"
16-
sp-runtime = "2.0.0-alpha.5"
15+
#sp-blockchain = "2.0.0-alpha.2"
16+
#sp-finality-grandpa = "2.0.0-alpha.2"
17+
#sp-runtime = "2.0.0-alpha.2"
1718

1819
# Runtime/chain specific dependencies
1920

2021
bridge-node-runtime = { path = "../../../bin/node/runtime" }
22+
23+
[dependencies.sp-blockchain]
24+
version = "2.0.0-alpha.2"
25+
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
26+
git = "https://github.com/paritytech/substrate/"
27+
28+
[dependencies.sp-finality-grandpa]
29+
version = "2.0.0-alpha.2"
30+
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
31+
git = "https://github.com/paritytech/substrate/"
32+
33+
[dependencies.sp-runtime]
34+
version = "2.0.0-alpha.2"
35+
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
36+
git = "https://github.com/paritytech/substrate/"

0 commit comments

Comments
 (0)