Skip to content

Commit

Permalink
Revert "Merge branch 'main' into I110-im-online-fix"
Browse files Browse the repository at this point in the history
This reverts commit 1accee1, reversing
changes made to a45502a.
  • Loading branch information
OnyxSkyscape committed Mar 20, 2023
1 parent 3127ad1 commit 408bf06
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 219 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ substrate-frame-rpc-system = { version = "15.0.0", default-features = false }
pallet-aura = { version = "14.0.0", default-features = false }
pallet-balances = { version = "15.0.0", default-features = false }
pallet-grandpa = { version = "15.0.0", default-features = false }
pallet-im-online = { version = "14.0.0", default-features = false }
pallet-randomness-collective-flip = { version = "15.0.0", default-features = false }
pallet-session = { version = "15.0.0", default-features = false }
pallet-sudo = { version = "15.0.0", default-features = false }
Expand Down
25 changes: 5 additions & 20 deletions gn-client/examples/guild/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod common;
mod fund;
mod join;
mod key;
mod sudo;
mod register;
mod token;

use gn_client::tx;
Expand All @@ -20,13 +20,9 @@ enum Example {
Join,
Key(Key),
Token,
Sudo {
Register {
#[structopt(long, short)]
pallet: String,
#[structopt(long, short)]
method: String,
#[structopt(long, short)]
account: Option<String>,
operator: Option<String>,
},
}

Expand Down Expand Up @@ -83,19 +79,8 @@ async fn main() {
key::generate(&curve, password.as_deref())
}
Example::Key(Key::Rotate) => key::rotate(api).await,
Example::Sudo {
pallet,
method,
account,
} => {
sudo::sudo(
api,
signer,
&pallet.to_lowercase(),
&method.to_lowercase(),
account.as_deref(),
)
.await
Example::Register { operator } => {
register::register(api, signer, operator.as_deref()).await
}
Example::Token => token::token(api, signer).await,
}
Expand Down
21 changes: 21 additions & 0 deletions gn-client/examples/guild/register.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use gn_client::{
tx::{self, Signer},
AccountId, Api,
};

use std::str::FromStr;
use std::sync::Arc;

pub async fn register(api: Api, root: Arc<Signer>, maybe_operator: Option<&str>) {
let account_id = if let Some(operator) = maybe_operator {
AccountId::from_str(operator).expect("invalid operator id string")
} else {
root.account_id().clone()
};

let payload = tx::register_operator(&account_id);
tx::send_tx_in_block(api, &tx::sudo(payload), root)
.await
.unwrap();
println!("{account_id} registered as operator");
}
34 changes: 0 additions & 34 deletions gn-client/examples/guild/sudo.rs

This file was deleted.

36 changes: 6 additions & 30 deletions gn-client/src/tx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,44 +39,20 @@ pub fn sudo<'a>(call: DynamicTxPayload<'_>) -> DynamicTxPayload<'a> {
subxt::dynamic::tx("Sudo", "sudo", vec![("call", call.into_value())])
}

pub fn register_operator<'a>(operator: &AccountId) -> DynamicTxPayload<'a> {
subxt::dynamic::tx(
"Oracle",
"register_operator",
vec![("operator", Value::from_bytes(operator))],
)
pub fn fund_account(account: &AccountId, amount: u128) -> impl TxPayload {
runtime::tx()
.balances()
.transfer(MultiAddress::Id(account.clone()), amount)
}

pub fn deregister_operator<'a>(operator: &AccountId) -> DynamicTxPayload<'a> {
pub fn register_operator<'a>(operator: &AccountId) -> DynamicTxPayload<'a> {
subxt::dynamic::tx(
"Oracle",
"deregister_operator",
"register_operator",
vec![("operator", Value::from_bytes(operator))],
)
}

pub fn add_validator<'a>(validator: &AccountId) -> DynamicTxPayload<'a> {
subxt::dynamic::tx(
"ValidatorManager",
"add_validator",
vec![("validator_id", Value::from_bytes(validator))],
)
}

pub fn remove_validator<'a>(validator: &AccountId) -> DynamicTxPayload<'a> {
subxt::dynamic::tx(
"ValidatorManager",
"remove_validator",
vec![("validator_id", Value::from_bytes(validator))],
)
}

pub fn fund_account(account: &AccountId, amount: u128) -> impl TxPayload {
runtime::tx()
.balances()
.transfer(MultiAddress::Id(account.clone()), amount)
}

pub fn activate_operator() -> impl TxPayload {
runtime::tx().oracle().activate_operator()
}
Expand Down
1 change: 1 addition & 0 deletions gn-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ frame-system = { workspace = true, optional = true }
substrate-frame-rpc-system = { workspace = true }

# substrate pallets
pallet-im-online = { workspace = true }
pallet-transaction-payment = { workspace = true, optional = true }
pallet-transaction-payment-rpc = { workspace = true }

Expand Down
9 changes: 7 additions & 2 deletions gn-node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use gn_runtime::{
AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig, SessionConfig, Signature,
SudoConfig, SystemConfig, ValidatorManagerConfig, WASM_BINARY,
AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig, ImOnlineConfig,
SessionConfig, Signature, SudoConfig, SystemConfig, ValidatorManagerConfig, WASM_BINARY,
};
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use sc_service::ChainType;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::{sr25519, Pair, Public};
Expand Down Expand Up @@ -35,6 +36,7 @@ struct AuthorityKeys {
account_id: AccountId,
aura_id: AuraId,
grandpa_id: GrandpaId,
im_online_id: ImOnlineId,
}

impl AuthorityKeys {
Expand All @@ -43,13 +45,15 @@ impl AuthorityKeys {
account_id: get_account_id_from_seed::<sr25519::Public>(seed),
aura_id: get_from_seed::<AuraId>(seed),
grandpa_id: get_from_seed::<GrandpaId>(seed),
im_online_id: get_from_seed::<ImOnlineId>(seed),
}
}

pub fn to_session_keys(&self) -> gn_runtime::opaque::SessionKeys {
gn_runtime::opaque::SessionKeys {
aura: self.aura_id.clone(),
grandpa: self.grandpa_id.clone(),
im_online: self.im_online_id.clone(),
}
}
}
Expand Down Expand Up @@ -188,6 +192,7 @@ fn testnet_genesis(
grandpa: GrandpaConfig {
authorities: vec![],
},
im_online: ImOnlineConfig { keys: vec![] },
sudo: SudoConfig {
// Assign network admin rights.
key: Some(root_key),
Expand Down
2 changes: 0 additions & 2 deletions gn-pallets/pallet-validator-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#![deny(clippy::dbg_macro)]
#![deny(unused_crate_dependencies)]

pub mod migration;
#[cfg(test)]
mod mock;
#[cfg(test)]
Expand Down Expand Up @@ -239,7 +238,6 @@ impl<T: Config> Pallet<T> {
fn unapprove_validator(validator_id: T::AccountId) -> DispatchResult {
let mut approved_set = <ApprovedValidators<T>>::get();
approved_set.retain(|v| *v != validator_id);
<ApprovedValidators<T>>::set(approved_set);
Ok(())
}

Expand Down
15 changes: 0 additions & 15 deletions gn-pallets/pallet-validator-manager/src/migration.rs

This file was deleted.

16 changes: 5 additions & 11 deletions gn-pallets/pallet-validator-manager/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,24 @@ fn simple_setup_should_work() {
authorities(),
vec![UintAuthorityId(1), UintAuthorityId(2), UintAuthorityId(3)]
);
assert_eq!(ValidatorSet::validators(), &[1, 2, 3]);
assert_eq!(Session::validators(), &[1, 2, 3]);
assert_eq!(ValidatorSet::validators(), vec![1u64, 2u64, 3u64]);
assert_eq!(Session::validators(), vec![1, 2, 3]);
});
}

#[test]
fn add_validator_updates_validators_list() {
new_test_ext().execute_with(|| {
assert_ok!(ValidatorSet::add_validator(RuntimeOrigin::root(), 4));
assert_eq!(ValidatorSet::validators(), &[1, 2, 3, 4]);
assert_eq!(ValidatorSet::approved_validators(), &[1, 2, 3, 4]);
assert_eq!(ValidatorSet::validators(), vec![1u64, 2u64, 3u64, 4u64])
});
}

#[test]
fn remove_validator_updates_validators_list() {
new_test_ext().execute_with(|| {
assert_ok!(ValidatorSet::remove_validator(RuntimeOrigin::root(), 2));
assert_eq!(ValidatorSet::validators(), &[1, 3]);
assert_eq!(ValidatorSet::approved_validators(), &[1, 3]);
// add again
assert_ok!(ValidatorSet::add_validator(RuntimeOrigin::root(), 2));
assert_eq!(ValidatorSet::validators(), &[1, 3, 2]);
assert_eq!(ValidatorSet::approved_validators(), &[1, 3, 2]);
assert_eq!(ValidatorSet::validators(), vec![1u64, 3u64]);
});
}

Expand Down Expand Up @@ -63,7 +57,7 @@ fn remove_validator_fails_with_invalid_origin() {
fn duplicate_check() {
new_test_ext().execute_with(|| {
assert_ok!(ValidatorSet::add_validator(RuntimeOrigin::root(), 4));
assert_eq!(ValidatorSet::validators(), &[1, 2, 3, 4]);
assert_eq!(ValidatorSet::validators(), vec![1u64, 2u64, 3u64, 4u64]);
assert_noop!(
ValidatorSet::add_validator(RuntimeOrigin::root(), 4),
Error::<Test>::Duplicate
Expand Down
4 changes: 4 additions & 0 deletions gn-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ std = [
"pallet-balances/std",
"pallet-grandpa/std",
"pallet-guild/std",
"pallet-im-online/std",
"pallet-oracle/std",
"pallet-randomness-collective-flip/std",
"pallet-session/std",
Expand Down Expand Up @@ -64,6 +65,7 @@ try-runtime = [
"pallet-balances/try-runtime",
"pallet-grandpa/try-runtime",
"pallet-guild/try-runtime",
"pallet-im-online/try-runtime",
"pallet-oracle/try-runtime",
"pallet-randomness-collective-flip/try-runtime",
"pallet-sudo/try-runtime",
Expand All @@ -80,6 +82,7 @@ pallet-validator-manager = { version = "0.0.0-alpha", path = "../gn-pallets/pall

# general
hex-literal = { version = "0.3.4", optional = true }
log = { version = "0.4.17", default-features = false }
parity-scale-codec = { workspace = true, features = ["derive"] }
scale-info = { workspace = true, features = ["derive"] }

Expand All @@ -96,6 +99,7 @@ frame-try-runtime = { workspace = true, features = ["try-runtime"], optional = t
pallet-aura = { workspace = true }
pallet-balances = { workspace = true }
pallet-grandpa = { workspace = true }
pallet-im-online = { workspace = true }
pallet-randomness-collective-flip = { workspace = true }
pallet-session = { workspace = true }
pallet-sudo = { workspace = true }
Expand Down
11 changes: 10 additions & 1 deletion gn-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub use pallet_balances::Call as BalancesCall;
use pallet_grandpa::{
fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList,
};
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use parity_scale_codec::Encode;
use sp_api::impl_runtime_apis;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
Expand All @@ -24,7 +26,7 @@ use sp_runtime::{
Verify,
},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, MultiSignature,
ApplyExtrinsicResult, MultiSignature, SaturatedConversion,
};
use sp_std::prelude::*;
#[cfg(feature = "std")]
Expand Down Expand Up @@ -90,6 +92,7 @@ pub mod opaque {
pub struct SessionKeys {
pub aura: Aura,
pub grandpa: Grandpa,
pub im_online: ImOnline,
}
}
}
Expand Down Expand Up @@ -156,6 +159,11 @@ parameter_types! {
pub const MinAuthorities: u32 = 2;
pub const Period: u32 = 2 * MINUTES;
pub const Offset: u32 = 0;

pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value();
pub const MaxKeys: u32 = 10_000;
pub const MaxPeerInHeartbeats: u32 = 10_000;
pub const MaxPeerDataEncodingSize: u32 = 1_000;
}

// Configure FRAME pallets to include in runtime.
Expand Down Expand Up @@ -420,6 +428,7 @@ construct_runtime!(
Timestamp: pallet_timestamp,
ValidatorManager: pallet_validator_manager,
Session: pallet_session,
ImOnline: pallet_im_online,
Aura: pallet_aura,
Grandpa: pallet_grandpa,

Expand Down
1 change: 0 additions & 1 deletion gn-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ queries = []
# local
gn-client = { version = "0.0.0-alpha", path = "../gn-client", default-features = false, features = ["wasm"] }
gn-common = { version = "0.0.0-alpha", path = "../gn-common", default-features = false }
gn-engine = { version = "0.0.0-alpha", path = "../gn-engine", default-features = false }

# general
serde-wasm-bindgen = "0.4.5"
Expand Down
Loading

0 comments on commit 408bf06

Please sign in to comment.