Skip to content

Commit 96d3808

Browse files
acatangiutomusdrw
authored andcommitted
Integrate BEEFY with Rialto & Millau runtimes (#1227)
* Add Beefy pallet to Rialto runtime * Add Beefy gadget to Rialto node * Add MMR pallet to Rialto runtime * Add Beefy pallet to Millau runtime * Add Beefy gadget to Millau node * Add MMR pallet to Millau runtime * Add pallet_beefy_mmr to Millau runtime * Add pallet_beefy_mmr to Rialto runtime * Implement MMR and BEEFY APIs in Rialto * fix unit tests - should_encode_bridge_send_message_call() tests for new runtime encoding resulted from newly added pallets. - runtime size_of::<Call>() slightly increased from newly added pallets. * fix grumbles * tighten clippy allowances * fix more grumbles * Add MMR RPC to Rialto and Millau nodes Also implement MmrApi in Millau runtime. * rialto: use upstream polkadot_client::RuntimeApiCollection
1 parent f75a1bd commit 96d3808

12 files changed

Lines changed: 342 additions & 86 deletions

File tree

Cargo.lock

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/millau/node/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ pallet-bridge-messages = { path = "../../../modules/messages" }
2323

2424
# Substrate Dependencies
2525

26+
beefy-gadget = { git = "https://github.com/paritytech/substrate", branch = "master" }
27+
beefy-gadget-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" }
28+
beefy-primitives = { git = "https://github.com/paritytech/substrate", branch = "master" }
2629
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master" }
2730
frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "master" }
2831
node-inspect = { git = "https://github.com/paritytech/substrate", branch = "master" }
32+
pallet-mmr-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" }
2933
pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" }
3034
sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "master" }
3135
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "master", features = ["wasmtime"] }

bin/millau/node/src/chain_spec.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
1616

17+
use beefy_primitives::crypto::AuthorityId as BeefyId;
1718
use bp_millau::derive_account_from_rialto_id;
1819
use millau_runtime::{
19-
AccountId, AuraConfig, BalancesConfig, BridgeRialtoMessagesConfig, BridgeWestendGrandpaConfig,
20-
GenesisConfig, GrandpaConfig, SessionConfig, SessionKeys, Signature, SudoConfig, SystemConfig,
21-
WASM_BINARY,
20+
AccountId, AuraConfig, BalancesConfig, BeefyConfig, BridgeRialtoMessagesConfig,
21+
BridgeWestendGrandpaConfig, GenesisConfig, GrandpaConfig, SessionConfig, SessionKeys,
22+
Signature, SudoConfig, SystemConfig, WASM_BINARY,
2223
};
2324
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
2425
use sp_core::{sr25519, Pair, Public};
@@ -57,10 +58,11 @@ where
5758
}
5859

5960
/// Helper function to generate an authority key for Aura
60-
pub fn get_authority_keys_from_seed(s: &str) -> (AccountId, AuraId, GrandpaId) {
61+
pub fn get_authority_keys_from_seed(s: &str) -> (AccountId, AuraId, BeefyId, GrandpaId) {
6162
(
6263
get_account_id_from_seed::<sr25519::Public>(s),
6364
get_from_seed::<AuraId>(s),
65+
get_from_seed::<BeefyId>(s),
6466
get_from_seed::<GrandpaId>(s),
6567
)
6668
}
@@ -173,12 +175,12 @@ impl Alternative {
173175
}
174176
}
175177

176-
fn session_keys(aura: AuraId, grandpa: GrandpaId) -> SessionKeys {
177-
SessionKeys { aura, grandpa }
178+
fn session_keys(aura: AuraId, beefy: BeefyId, grandpa: GrandpaId) -> SessionKeys {
179+
SessionKeys { aura, beefy, grandpa }
178180
}
179181

180182
fn testnet_genesis(
181-
initial_authorities: Vec<(AccountId, AuraId, GrandpaId)>,
183+
initial_authorities: Vec<(AccountId, AuraId, BeefyId, GrandpaId)>,
182184
root_key: AccountId,
183185
endowed_accounts: Vec<AccountId>,
184186
_enable_println: bool,
@@ -191,12 +193,15 @@ fn testnet_genesis(
191193
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 50)).collect(),
192194
},
193195
aura: AuraConfig { authorities: Vec::new() },
196+
beefy: BeefyConfig { authorities: Vec::new() },
194197
grandpa: GrandpaConfig { authorities: Vec::new() },
195198
sudo: SudoConfig { key: root_key },
196199
session: SessionConfig {
197200
keys: initial_authorities
198201
.iter()
199-
.map(|x| (x.0.clone(), x.0.clone(), session_keys(x.1.clone(), x.2.clone())))
202+
.map(|x| {
203+
(x.0.clone(), x.0.clone(), session_keys(x.1.clone(), x.2.clone(), x.3.clone()))
204+
})
200205
.collect::<Vec<_>>(),
201206
},
202207
bridge_westend_grandpa: BridgeWestendGrandpaConfig {

bin/millau/node/src/service.rs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
// =====================================================================================
2222
// UPDATE GUIDE:
2323
// 1) replace everything with node-template/src/service.rs contents (found in main Substrate repo);
24-
// 2) the only thing to keep from old code, is `rpc_extensions_builder` - we use our own custom
25-
// RPCs; 3) fix compilation errors;
26-
// 4) test :)
24+
// 2) from old code keep `rpc_extensions_builder` - we use our own custom RPCs;
25+
// 3) from old code keep the Beefy gadget;
26+
// 4) fix compilation errors;
27+
// 5) test :)
2728
// =====================================================================================
2829
// =====================================================================================
2930
// =====================================================================================
@@ -209,6 +210,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
209210
}
210211

211212
config.network.extra_sets.push(sc_finality_grandpa::grandpa_peers_set_config());
213+
config.network.extra_sets.push(beefy_gadget::beefy_peers_set_config());
212214
let warp_sync = Arc::new(sc_finality_grandpa::warp_proof::NetworkProvider::new(
213215
backend.clone(),
214216
grandpa_link.shared_authority_set().clone(),
@@ -242,6 +244,8 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
242244
let enable_grandpa = !config.disable_grandpa;
243245
let prometheus_registry = config.prometheus_registry().cloned();
244246
let shared_voter_state = SharedVoterState::empty();
247+
let (signed_commitment_sender, signed_commitment_stream) =
248+
beefy_gadget::notification::BeefySignedCommitmentStream::channel();
245249

246250
let rpc_extensions_builder = {
247251
use sc_finality_grandpa::FinalityProofProvider as GrandpaFinalityProofProvider;
@@ -264,7 +268,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
264268
Some(shared_authority_set.clone()),
265269
);
266270

267-
Box::new(move |_, subscription_executor| {
271+
Box::new(move |_, subscription_executor: sc_rpc::SubscriptionTaskExecutor| {
268272
let mut io = jsonrpc_core::IoHandler::default();
269273
io.extend_with(SystemApi::to_delegate(FullSystem::new(
270274
client.clone(),
@@ -278,9 +282,18 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
278282
shared_authority_set.clone(),
279283
shared_voter_state.clone(),
280284
justification_stream.clone(),
281-
subscription_executor,
285+
subscription_executor.clone(),
282286
finality_proof_provider.clone(),
283287
)));
288+
io.extend_with(beefy_gadget_rpc::BeefyApi::to_delegate(
289+
beefy_gadget_rpc::BeefyRpcHandler::new(
290+
signed_commitment_stream.clone(),
291+
subscription_executor,
292+
),
293+
));
294+
io.extend_with(pallet_mmr_rpc::MmrApi::to_delegate(pallet_mmr_rpc::Mmr::new(
295+
client.clone(),
296+
)));
284297
Ok(io)
285298
})
286299
};
@@ -292,7 +305,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
292305
task_manager: &mut task_manager,
293306
transaction_pool: transaction_pool.clone(),
294307
rpc_extensions_builder,
295-
backend,
308+
backend: backend.clone(),
296309
system_rpc_tx,
297310
config,
298311
telemetry: telemetry.as_mut(),
@@ -355,6 +368,23 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
355368
let keystore =
356369
if role.is_authority() { Some(keystore_container.sync_keystore()) } else { None };
357370

371+
let beefy_params = beefy_gadget::BeefyParams {
372+
client,
373+
backend,
374+
key_store: keystore.clone(),
375+
network: network.clone(),
376+
signed_commitment_sender,
377+
min_block_delta: 4,
378+
prometheus_registry: prometheus_registry.clone(),
379+
};
380+
381+
// Start the BEEFY bridge gadget.
382+
task_manager.spawn_essential_handle().spawn_blocking(
383+
"beefy-gadget",
384+
None,
385+
beefy_gadget::start_beefy_gadget::<_, _, _, _>(beefy_params),
386+
);
387+
358388
let grandpa_config = sc_finality_grandpa::Config {
359389
// FIXME #1578 make this available through chainspec
360390
gossip_duration: Duration::from_millis(333),

bin/millau/runtime/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,19 @@ pallet-shift-session-manager = { path = "../../../modules/shift-session-manager"
3030

3131
# Substrate Dependencies
3232

33+
beefy-primitives = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
3334
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
3435
frame-executive = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
3536
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
3637
frame-system = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
3738
frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
3839
pallet-aura = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
3940
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
41+
pallet-beefy = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
42+
pallet-beefy-mmr = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
4043
pallet-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
44+
pallet-mmr = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
45+
pallet-mmr-primitives = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
4146
pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
4247
pallet-session = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
4348
pallet-sudo = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
@@ -64,6 +69,7 @@ substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", bran
6469
[features]
6570
default = ["std"]
6671
std = [
72+
"beefy-primitives/std",
6773
"bp-header-chain/std",
6874
"bp-messages/std",
6975
"bp-millau/std",
@@ -78,11 +84,14 @@ std = [
7884
"frame-system/std",
7985
"pallet-aura/std",
8086
"pallet-balances/std",
87+
"pallet-beefy/std",
88+
"pallet-beefy-mmr/std",
8189
"pallet-bridge-dispatch/std",
8290
"pallet-bridge-grandpa/std",
8391
"pallet-bridge-messages/std",
8492
"pallet-bridge-token-swap/std",
8593
"pallet-grandpa/std",
94+
"pallet-mmr/std",
8695
"pallet-randomness-collective-flip/std",
8796
"pallet-session/std",
8897
"pallet-shift-session-manager/std",

0 commit comments

Comments
 (0)