Skip to content

Commit f0d8e78

Browse files
authored
Sudo removal phase 1 (#980)
## Describe your changes 1. Prepare parachain and mainnet for sudo removal
2 parents f0640ac + 55cc355 commit f0d8e78

File tree

19 files changed

+472
-158
lines changed

19 files changed

+472
-158
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ orml-vesting = { git = "https://github.com/Polkadex-Substrate/orml-1.1.0.git", b
123123
sp-io = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
124124
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
125125
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
126-
sp-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false}
126+
sp-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
127127
sp-version = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
128128
sp-staking = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
129129
sp-keyring = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
@@ -172,7 +172,7 @@ sc-basic-authorship = { git = "https://github.com/paritytech/polkadot-sdk", bran
172172
sc-consensus-babe-rpc = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
173173
sc-authority-discovery = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
174174
sc-finality-grandpa-rpc = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
175-
substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0"}
175+
substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
176176
substrate-frame-rpc-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
177177
pallet-nomination-pools = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
178178
grandpa-primitives = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false, package = "sp-finality-grandpa" }
@@ -212,7 +212,7 @@ polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot-sdk",
212212
sp-consensus-aura = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.1.0" }
213213

214214
[patch.'https://github.com/w3f/ring-vrf']
215-
bandersnatch_vrfs = { git = "https://github.com/w3f//ring-vrf.git", rev = "3ebdd261873da05124f4499c85a8e62d40411620"}
215+
bandersnatch_vrfs = { git = "https://github.com/w3f//ring-vrf.git", rev = "3ebdd261873da05124f4499c85a8e62d40411620" }
216216

217217
[patch.'https://github.com/paritytech/polkadot-sdk']
218-
substrate-wasm-builder = { git = "https://github.com/Polkadex-Substrate/polkadot-sdk", branch = "release-polkadot-v1.1.0"}
218+
substrate-wasm-builder = { git = "https://github.com/Polkadex-Substrate/polkadot-sdk", branch = "release-polkadot-v1.1.0" }

nodes/mainnet/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ clap = { version = "4.0.9", features = ["derive"] }
2626
itertools = "0.10.1"
2727
jsonrpsee = { version = "0.16.2", features = ["server"] }
2828
# local dependencies
29-
node-polkadex-runtime = { path = "../../runtimes/mainnet"}
29+
node-polkadex-runtime = { path = "../../runtimes/mainnet" }
3030
rpc-assets = { path = "../../rpc/assets" }
3131
pallet-rewards-rpc = { path = "../../pallets/rewards/rpc" }
3232
pallet-ocex-rpc = { path = "../../pallets/ocex/rpc" }
@@ -100,7 +100,7 @@ sc-consensus-babe = { git = "https://github.com/paritytech/polkadot-sdk", branch
100100
sc-consensus-epochs = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
101101
sp-tracing = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
102102
sc-keystore = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
103-
sc-service-test = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0"}
103+
sc-service-test = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
104104

105105
[features]
106106
default = []

nodes/parachain/src/chain_spec.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,12 @@ fn create_genesis_config(
251251
..Default::default()
252252
},
253253
sudo: parachain_polkadex_runtime::SudoConfig { key: Some(root_key) },
254+
elections: Default::default(),
255+
council: Default::default(),
256+
technical_committee: Default::default(),
254257
assets: Default::default(),
255258
transaction_payment: Default::default(),
259+
democracy: Default::default(),
256260
}
257261
}
258262

pallets/ocex/src/validator.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,14 +658,17 @@ impl<T: Config> Pallet<T> {
658658
return Err("Invalid egress message for withdraw trading fees");
659659
}
660660
},
661-
IngressMessages::NewLMPEpoch(epoch) => Self::start_new_lmp_epoch(state, epoch)?,
661+
IngressMessages::NewLMPEpoch(_epoch) => {
662+
// Self::start_new_lmp_epoch(state, epoch)?
663+
},
662664
_ => {},
663665
}
664666
}
665667
state_info.last_block = blk.saturated_into();
666668
Ok(verified_egress_messages)
667669
}
668670

671+
#[allow(dead_code)]
669672
/// Reset the offchain state's LMP index and set the epoch
670673
fn start_new_lmp_epoch(state: &mut OffchainState, epoch: u16) -> Result<(), &'static str> {
671674
let mut config = if epoch > 1 {

pallets/thea-message-handler/src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ pub mod pallet {
205205
let current_set_id = <ValidatorSetId<T>>::get();
206206

207207
match payload.message.payload_type {
208-
PayloadType::ScheduledRotateValidators => {
208+
PayloadType::ScheduledRotateValidators => {}, // Deprecated
209+
PayloadType::ValidatorsRotated => {
209210
// Thea message related to key change
210211
match ValidatorSet::decode(&mut payload.message.data.as_ref()) {
211212
Err(_err) => return Err(Error::<T>::ErrorDecodingValidatorSet.into()),
@@ -218,13 +219,11 @@ pub mod pallet {
218219
validator_set.set_id,
219220
BoundedVec::truncate_from(validator_set.validators),
220221
);
222+
// We are checking if the validator set is changed, then we update it here too
223+
<ValidatorSetId<T>>::put(current_set_id.saturating_add(1));
221224
},
222225
}
223226
},
224-
PayloadType::ValidatorsRotated => {
225-
// We are checking if the validator set is changed, then we update it here too
226-
<ValidatorSetId<T>>::put(current_set_id.saturating_add(1));
227-
},
228227
PayloadType::L1Deposit => {
229228
// Normal Thea message
230229
T::Executor::execute_deposits(

pallets/thea-message-handler/src/test.rs

Lines changed: 6 additions & 15 deletions
Large diffs are not rendered by default.

pallets/thea/src/lib.rs

Lines changed: 96 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use sp_runtime::{
4040
use sp_std::collections::btree_set::BTreeSet;
4141
use sp_std::prelude::*;
4242
use thea_primitives::{
43-
types::{Message, NetworkType, PayloadType},
43+
types::{Message, PayloadType},
4444
Network, ValidatorSet, GENESIS_AUTHORITY_SET_ID,
4545
};
4646

@@ -382,6 +382,7 @@ pub mod pallet {
382382
stake: Balance,
383383
) -> DispatchResult {
384384
let signer = ensure_signed(origin)?;
385+
// Testing relayer must be removed after final audit
385386
let expected_signer = <AllowListTestingRelayers<T>>::get(payload.network)
386387
.ok_or(Error::<T>::NoRelayersFound)?;
387388
ensure!(signer == expected_signer, Error::<T>::NotAnAllowlistedRelayer);
@@ -758,103 +759,112 @@ impl<T: Config> Pallet<T> {
758759

759760
fn change_authorities(
760761
incoming: BoundedVec<T::TheaId, T::MaxAuthorities>, // n+1th set
761-
queued: BoundedVec<T::TheaId, T::MaxAuthorities>, // n+ 2th set
762+
_queued: BoundedVec<T::TheaId, T::MaxAuthorities>, // n+ 2th set
762763
) {
763764
// ( outgoing) -> (validators/incoming) -> (queued)
764765
// nth epoch -> n+1th epoch -> n+2nd epoch
765766
let id = Self::validator_set_id();
766767
let outgoing = <Authorities<T>>::get(id); // nth set ( active ,current )
767768
let new_id = id + 1u64;
768769
let active_networks = <ActiveNetworks<T>>::get();
769-
// We need to issue a new message if the validator set is changing,
770-
// that is, the incoming set is has different session keys from outgoing set.
771-
// This last message should be signed by the outgoing set
772-
// Similar to how Grandpa's session change works.
770+
// // We need to issue a new message if the validator set is changing,
771+
// // that is, the incoming set is has different session keys from outgoing set.
772+
// // This last message should be signed by the outgoing set
773+
// // Similar to how Grandpa's session change works.
773774
let incoming_set = BTreeSet::from_iter(incoming.to_vec());
774-
if incoming_set != BTreeSet::from_iter(queued.to_vec()) {
775-
let uncompressed_keys: Vec<[u8; 20]> = vec![];
776-
// TODO: Uncomment the following when parsing is fixed for ethereum keys.
777-
// for public_key in queued.clone().into_iter() {
778-
// let public_key: sp_core::ecdsa::Public = public_key.into();
779-
// if public_key.0 == [0u8; 33] {
780-
// uncompressed_keys.push([0u8; 20]);
781-
// continue;
782-
// }
783-
// if let Ok(compressed_key) = libsecp256k1::PublicKey::parse_compressed(&public_key.0)
784-
// {
785-
// let uncompressed_key = compressed_key.serialize();
786-
// let uncompressed_key: [u8; 64] =
787-
// if let Ok(uncompressed_key) = uncompressed_key[1..65].try_into() {
788-
// uncompressed_key
789-
// } else {
790-
// log::error!(target: "thea", "Unable to slice last 64 bytes of uncompressed_key for Evm");
791-
// Self::deposit_event(Event::<T>::UnableToSlicePublicKeyHash(
792-
// public_key.into(),
793-
// ));
794-
// return;
795-
// };
796-
// let hash: [u8; 32] = sp_io::hashing::keccak_256(&uncompressed_key);
797-
// if let Ok(address) = hash[12..32].try_into() {
798-
// uncompressed_keys.push(address);
799-
// } else {
800-
// log::error!(target: "thea", "Unable to slice last 20 bytes of hash for Evm");
801-
// Self::deposit_event(Event::<T>::UnableToSlicePublicKeyHash(
802-
// public_key.into(),
803-
// ));
804-
// return;
805-
// }
806-
// } else {
807-
// log::error!(target: "thea", "Unable to parse compressed key");
808-
// Self::deposit_event(Event::<T>::UnableToParsePublicKey(public_key.into()));
809-
// return;
810-
// }
811-
// }
812-
for network in &active_networks {
813-
let network_config = <NetworkConfig<T>>::get(*network);
814-
let message = match network_config.network_type {
815-
NetworkType::Evm => {
816-
if let Some(payload) = ValidatorSet::new(uncompressed_keys.clone(), new_id)
817-
{
818-
Self::generate_payload(
819-
PayloadType::ScheduledRotateValidators,
820-
*network,
821-
payload.encode(),
822-
)
823-
} else {
824-
log::error!(target: "thea", "Unable to generate rotate validators payload");
825-
Self::deposit_event(Event::<T>::UnableToGenerateValidatorSet(*network));
826-
continue;
827-
}
828-
},
829-
NetworkType::Parachain => {
830-
if let Some(payload) = ValidatorSet::new(queued.clone(), new_id) {
831-
Self::generate_payload(
832-
PayloadType::ScheduledRotateValidators,
833-
*network,
834-
payload.encode(),
835-
)
836-
} else {
837-
log::error!(target: "thea", "Unable to generate rotate validators payload");
838-
Self::deposit_event(Event::<T>::UnableToGenerateValidatorSet(*network));
839-
continue;
840-
}
841-
},
842-
};
843-
<OutgoingNonce<T>>::insert(message.network, message.nonce);
844-
<OutgoingMessages<T>>::insert(message.network, message.nonce, message);
845-
}
846-
<NextAuthorities<T>>::put(queued);
847-
}
775+
// if incoming_set != BTreeSet::from_iter(queued.to_vec()) {
776+
// let uncompressed_keys: Vec<[u8; 20]> = vec![];
777+
// // TODO: Uncomment the following when parsing is fixed for ethereum keys.
778+
// // for public_key in queued.clone().into_iter() {
779+
// // let public_key: sp_core::ecdsa::Public = public_key.into();
780+
// // if public_key.0 == [0u8; 33] {
781+
// // uncompressed_keys.push([0u8; 20]);
782+
// // continue;
783+
// // }
784+
// // if let Ok(compressed_key) = libsecp256k1::PublicKey::parse_compressed(&public_key.0)
785+
// // {
786+
// // let uncompressed_key = compressed_key.serialize();
787+
// // let uncompressed_key: [u8; 64] =
788+
// // if let Ok(uncompressed_key) = uncompressed_key[1..65].try_into() {
789+
// // uncompressed_key
790+
// // } else {
791+
// // log::error!(target: "thea", "Unable to slice last 64 bytes of uncompressed_key for Evm");
792+
// // Self::deposit_event(Event::<T>::UnableToSlicePublicKeyHash(
793+
// // public_key.into(),
794+
// // ));
795+
// // return;
796+
// // };
797+
// // let hash: [u8; 32] = sp_io::hashing::keccak_256(&uncompressed_key);
798+
// // if let Ok(address) = hash[12..32].try_into() {
799+
// // uncompressed_keys.push(address);
800+
// // } else {
801+
// // log::error!(target: "thea", "Unable to slice last 20 bytes of hash for Evm");
802+
// // Self::deposit_event(Event::<T>::UnableToSlicePublicKeyHash(
803+
// // public_key.into(),
804+
// // ));
805+
// // return;
806+
// // }
807+
// // } else {
808+
// // log::error!(target: "thea", "Unable to parse compressed key");
809+
// // Self::deposit_event(Event::<T>::UnableToParsePublicKey(public_key.into()));
810+
// // return;
811+
// // }
812+
// // }
813+
// for network in &active_networks {
814+
// let network_config = <NetworkConfig<T>>::get(*network);
815+
// let message = match network_config.network_type {
816+
// NetworkType::Evm => {
817+
// if let Some(payload) = ValidatorSet::new(uncompressed_keys.clone(), new_id)
818+
// {
819+
// Self::generate_payload(
820+
// PayloadType::ScheduledRotateValidators,
821+
// *network,
822+
// payload.encode(),
823+
// )
824+
// } else {
825+
// log::error!(target: "thea", "Unable to generate rotate validators payload");
826+
// Self::deposit_event(Event::<T>::UnableToGenerateValidatorSet(*network));
827+
// continue;
828+
// }
829+
// },
830+
// NetworkType::Parachain => {
831+
// if let Some(payload) = ValidatorSet::new(queued.clone(), new_id) {
832+
// Self::generate_payload(
833+
// PayloadType::ScheduledRotateValidators,
834+
// *network,
835+
// payload.encode(),
836+
// )
837+
// } else {
838+
// log::error!(target: "thea", "Unable to generate rotate validators payload");
839+
// Self::deposit_event(Event::<T>::UnableToGenerateValidatorSet(*network));
840+
// continue;
841+
// }
842+
// },
843+
// };
844+
// <OutgoingNonce<T>>::insert(message.network, message.nonce);
845+
// <OutgoingMessages<T>>::insert(message.network, message.nonce, message);
846+
// }
847+
// <NextAuthorities<T>>::put(queued);
848+
// }
848849
if incoming_set != BTreeSet::from_iter(outgoing.to_vec()) {
849850
// This will happen when new era starts, or end of the last epoch
850-
<Authorities<T>>::insert(new_id, incoming);
851-
<ValidatorSetId<T>>::put(new_id);
852851
for network in active_networks {
853-
let message =
854-
Self::generate_payload(PayloadType::ValidatorsRotated, network, Vec::new()); //Empty data means activate the next set_id
855-
<OutgoingNonce<T>>::insert(network, message.nonce);
856-
<OutgoingMessages<T>>::insert(network, message.nonce, message);
852+
if let Some(payload) = ValidatorSet::new(incoming.clone(), new_id) {
853+
let message = Self::generate_payload(
854+
PayloadType::ValidatorsRotated,
855+
network,
856+
payload.encode(),
857+
);
858+
<OutgoingNonce<T>>::insert(network, message.nonce);
859+
<OutgoingMessages<T>>::insert(network, message.nonce, message);
860+
} else {
861+
log::error!(target: "thea", "Unable to generate rotate validators payload");
862+
Self::deposit_event(Event::<T>::UnableToGenerateValidatorSet(network));
863+
continue;
864+
}
857865
}
866+
<Authorities<T>>::insert(new_id, incoming);
867+
<ValidatorSetId<T>>::put(new_id);
858868
}
859869
}
860870

pallets/thea/src/tests.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,12 @@ fn test_session_change() {
8383
// Simulating the on_new_session to last epoch of an era.
8484
Thea::on_new_session(false, authorities.into_iter(), queued.clone().into_iter());
8585
assert!(Thea::validator_set_id() == 0);
86-
assert!(Thea::outgoing_nonce(1) == 1); // Thea validator session change message is generated here
86+
assert!(Thea::outgoing_nonce(1) == 0); // Thea validator session change message is not generated here on new change only when session actually changes
8787

88+
// Simulating the on_new_session to the first epoch of the next era.
89+
Thea::on_new_session(false, queued.clone().into_iter(), queued.clone().into_iter());
90+
assert!(Thea::validator_set_id() == 1);
91+
assert!(Thea::outgoing_nonce(1) == 1);
8892
let message = Thea::get_outgoing_messages(1, 1).unwrap();
8993
assert_eq!(message.nonce, 1);
9094
let validator_set: ValidatorSet<<Test as Config>::TheaId> =
@@ -93,14 +97,6 @@ fn test_session_change() {
9397
queued.iter().map(|(_, public)| public.clone()).collect();
9498
assert_eq!(validator_set.set_id, 1);
9599
assert_eq!(validator_set.validators, queued_validators);
96-
97-
// Simulating the on_new_session to the first epoch of the next era.
98-
Thea::on_new_session(false, queued.clone().into_iter(), queued.clone().into_iter());
99-
assert!(Thea::validator_set_id() == 1);
100-
assert!(Thea::outgoing_nonce(1) == 2);
101-
let message = Thea::get_outgoing_messages(1, 2).unwrap();
102-
assert_eq!(message.nonce, 2);
103-
assert!(message.data.is_empty());
104100
})
105101
}
106102

@@ -320,11 +316,11 @@ fn test_report_misbehaviour_happy_path() {
320316
assert_ok!(Thea::report_misbehaviour(RuntimeOrigin::signed(fisherman), network, 1));
321317
})
322318
}
323-
324319
use frame_support::{
325320
assert_noop,
326321
traits::{fungible::MutateHold, tokens::Precision},
327322
};
323+
use thea_primitives::types::NetworkType;
328324
use thea_primitives::types::{AssetMetadata, IncomingMessage, SignedMessage, THEA_HOLD_REASON};
329325

330326
#[test]

0 commit comments

Comments
 (0)