Skip to content

Commit ee7dec4

Browse files
authored
More cleanups - removed sudo (#39)
* We need production profile also * Remove sudo from bulletin-polkadot * Allow Grandpa init for owner or root (so we don't need sudo)
1 parent 547cb31 commit ee7dec4

File tree

5 files changed

+23
-44
lines changed

5 files changed

+23
-44
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,8 @@ members = [
132132
# Polkadot runtime requires unwinding.
133133
opt-level = 3
134134
panic = "unwind"
135+
136+
[profile.production]
137+
inherits = "release"
138+
lto = true
139+
codegen-units = 1

runtimes/bulletin-polkadot/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ pallet-babe = { workspace = true }
2525
pallet-grandpa = { workspace = true }
2626
pallet-offences = { workspace = true }
2727
pallet-session = { workspace = true }
28-
pallet-sudo = { workspace = true }
2928
pallet-timestamp = { workspace = true }
3029
sp-api = { workspace = true }
3130
sp-block-builder = { workspace = true }
@@ -117,7 +116,6 @@ std = [
117116
"pallet-grandpa/std",
118117
"pallet-offences/std",
119118
"pallet-session/std",
120-
"pallet-sudo/std",
121119
"pallet-timestamp/std",
122120
"sp-api/std",
123121
"sp-block-builder/std",
@@ -179,7 +177,6 @@ runtime-benchmarks = [
179177
"pallet-babe/runtime-benchmarks",
180178
"pallet-grandpa/runtime-benchmarks",
181179
"pallet-offences/runtime-benchmarks",
182-
"pallet-sudo/runtime-benchmarks",
183180
"pallet-timestamp/runtime-benchmarks",
184181
"sp-runtime/runtime-benchmarks",
185182
"sp-storage",
@@ -219,7 +216,6 @@ try-runtime = [
219216
"pallet-grandpa/try-runtime",
220217
"pallet-offences/try-runtime",
221218
"pallet-session/try-runtime",
222-
"pallet-sudo/try-runtime",
223219
"pallet-timestamp/try-runtime",
224220

225221
"pallet-bridge-grandpa/try-runtime",

runtimes/bulletin-polkadot/src/genesis_config_presets.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
opaque::SessionKeys, AccountId, BabeConfig, RelayerSetConfig, RuntimeGenesisConfig,
3-
SessionConfig, Signature, SudoConfig, ValidatorSetConfig, BABE_GENESIS_EPOCH_CONFIG,
3+
SessionConfig, Signature, ValidatorSetConfig, BABE_GENESIS_EPOCH_CONFIG,
44
};
55

66
use crate::{
@@ -50,7 +50,6 @@ fn session_keys(babe: BabeId, grandpa: GrandpaId) -> SessionKeys {
5050
fn testnet_genesis(
5151
initial_authorities: Vec<(AccountId, BabeId, GrandpaId)>,
5252
bridges_pallet_owner: Option<AccountId>,
53-
root_key: AccountId,
5453
) -> serde_json::Value {
5554
let config = RuntimeGenesisConfig {
5655
validator_set: ValidatorSetConfig {
@@ -69,10 +68,6 @@ fn testnet_genesis(
6968
non_authority_keys: Default::default(),
7069
},
7170
babe: BabeConfig { epoch_config: BABE_GENESIS_EPOCH_CONFIG, ..Default::default() },
72-
sudo: SudoConfig {
73-
// Assign network admin rights.
74-
key: Some(root_key.clone()),
75-
},
7671
relayer_set: RelayerSetConfig {
7772
// For simplicity just make the initial relayer set match the initial validator set. In
7873
// practice even if the same entities control the validators and the relayers they
@@ -106,8 +101,6 @@ pub fn get_preset(id: &PresetId) -> Option<Vec<u8>> {
106101
vec![authority_keys_from_seed("Alice")],
107102
// Bridges pallet owner
108103
Some(get_account_id_from_seed::<sr25519::Public>("Alice")),
109-
// Sudo account
110-
get_account_id_from_seed::<sr25519::Public>("Alice"),
111104
),
112105
sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET => testnet_genesis(
113106
// Initial PoA authorities
@@ -119,8 +112,6 @@ pub fn get_preset(id: &PresetId) -> Option<Vec<u8>> {
119112
],
120113
// Bridges pallet owner
121114
Some(get_account_id_from_seed::<sr25519::Public>("Alice")),
122-
// Sudo account
123-
get_account_id_from_seed::<sr25519::Public>("Alice"),
124115
),
125116
_ => return None,
126117
};

runtimes/bulletin-polkadot/src/lib.rs

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ extern crate alloc;
88
#[cfg(feature = "std")]
99
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
1010

11+
use bp_runtime::OwnedBridgeModule;
1112
use bridge_runtime_common::generate_bridge_reject_obsolete_headers_and_messages;
1213
use frame_support::{derive_impl, traits::ValidatorRegistration};
1314
use frame_system::EnsureRoot;
@@ -339,13 +340,6 @@ impl pallet_timestamp::Config for Runtime {
339340
type WeightInfo = ();
340341
}
341342

342-
// TODO: remove sudo before go live
343-
impl pallet_sudo::Config for Runtime {
344-
type RuntimeEvent = RuntimeEvent;
345-
type RuntimeCall = RuntimeCall;
346-
type WeightInfo = pallet_sudo::weights::SubstrateWeight<Runtime>;
347-
}
348-
349343
impl pallet_transaction_storage::Config for Runtime {
350344
type RuntimeEvent = RuntimeEvent;
351345
type WeightInfo = pallet_transaction_storage::weights::SubstrateWeight<Runtime>;
@@ -406,9 +400,6 @@ construct_runtime!(
406400
BridgePolkadotGrandpa: pallet_bridge_grandpa = 51,
407401
BridgePolkadotParachains: pallet_bridge_parachains = 52,
408402
BridgePolkadotMessages: pallet_bridge_messages = 53,
409-
410-
// sudo
411-
Sudo: pallet_sudo = 255,
412403
}
413404
);
414405

@@ -419,18 +410,6 @@ pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
419410
/// Block type as expected by this runtime.
420411
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
421412

422-
fn validate_sudo(_who: &AccountId) -> TransactionValidity {
423-
// TODO: make Sudo::key() accessible and uncomment this.
424-
// // Only allow sudo transactions signed by the sudo account. The sudo pallet obviously checks
425-
// // this, but not until transaction execution.
426-
// if Sudo::key().map_or(false, |k| who == &k) {
427-
// Ok(ValidTransaction { priority: SudoPriority::get(), ..Default::default() })
428-
// } else {
429-
// Err(InvalidTransaction::BadSigner.into())
430-
// }
431-
Ok(ValidTransaction { priority: SudoPriority::get(), ..Default::default() })
432-
}
433-
434413
fn validate_purge_keys(who: &AccountId) -> TransactionValidity {
435414
// Only allow if account has keys to purge
436415
if Session::is_registered(who) {
@@ -493,9 +472,6 @@ impl TransactionExtension<RuntimeCall> for ValidateSigned {
493472
RuntimeCall::TransactionStorage(inner_call) =>
494473
TransactionStorage::validate_signed(who, inner_call),
495474

496-
// Sudo call
497-
RuntimeCall::Sudo(_) => validate_sudo(who),
498-
499475
// Session key management
500476
RuntimeCall::Session(SessionCall::set_keys { .. }) =>
501477
ValidatorSet::validate_set_keys(who).map(|()| ValidTransaction {
@@ -530,6 +506,16 @@ impl TransactionExtension<RuntimeCall> for ValidateSigned {
530506
..Default::default()
531507
}),
532508

509+
// Bridge-privileged calls
510+
RuntimeCall::BridgePolkadotGrandpa(BridgeGrandpaCall::initialize { .. }) =>
511+
BridgePolkadotGrandpa::ensure_owner_or_root(origin.clone())
512+
.map_err(|_| InvalidTransaction::BadSigner.into())
513+
.map(|()| ValidTransaction {
514+
priority: BridgeTxPriority::get(),
515+
longevity: BridgeTxLongevity::get(),
516+
..Default::default()
517+
}),
518+
533519
// All other calls are invalid
534520
_ => Err(InvalidTransaction::Call.into()),
535521
}?;
@@ -551,9 +537,6 @@ impl TransactionExtension<RuntimeCall> for ValidateSigned {
551537
RuntimeCall::TransactionStorage(inner_call) =>
552538
TransactionStorage::pre_dispatch_signed(who, inner_call).map(|()| None),
553539

554-
// Sudo validation
555-
RuntimeCall::Sudo(_) => validate_sudo(who).map(|_| None),
556-
557540
// Session key management
558541
RuntimeCall::Session(SessionCall::set_keys { .. }) =>
559542
ValidatorSet::pre_dispatch_set_keys(who).map(|()| None),
@@ -580,6 +563,12 @@ impl TransactionExtension<RuntimeCall> for ValidateSigned {
580563
BridgeMessagesCall::receive_messages_delivery_proof { .. },
581564
) => RelayerSet::validate_bridge_tx(who).map(|()| Some(who.clone())),
582565

566+
// Bridge-privileged calls
567+
RuntimeCall::BridgePolkadotGrandpa(BridgeGrandpaCall::initialize { .. }) =>
568+
BridgePolkadotGrandpa::ensure_owner_or_root(origin.clone())
569+
.map_err(|_| InvalidTransaction::BadSigner.into())
570+
.map(|()| Some(who.clone())),
571+
583572
// All other calls are invalid
584573
_ => Err(InvalidTransaction::Call.into()),
585574
}
@@ -646,7 +635,6 @@ mod benches {
646635
[frame_benchmarking, BaselineBench::<Runtime>]
647636
[frame_system, SystemBench::<Runtime>]
648637
[pallet_timestamp, Timestamp]
649-
[pallet_sudo, Sudo]
650638
[pallet_transaction_storage, TransactionStorage]
651639
[pallet_validator_set, ValidatorSet]
652640
[pallet_relayer_set, RelayerSet]

0 commit comments

Comments
 (0)