Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielMartinezRodriguez committed Jan 23, 2024
1 parent 3bcd397 commit 109b02e
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 172 deletions.
40 changes: 25 additions & 15 deletions precompiles/upgrade-runtime-controller/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ use frame_support::dispatch::{Dispatchable, GetDispatchInfo, PostDispatchInfo};
use frame_support::parameter_types;
use frame_support::storage::types::{StorageValue, ValueQuery};

use frame_support::traits::StorageInstance;
use frame_support::traits::ChangeMembers;
use frame_support::inherent::Vec;
use frame_support::traits::ChangeMembers;
use frame_support::traits::StorageInstance;
use precompile_utils::prelude::*;

use sp_core::Get;
Expand Down Expand Up @@ -87,7 +87,10 @@ pub struct UpgradeRuntimeControllerPrecompile<Runtime, DefaultOwner: Get<H160> +
impl<Runtime, DefaultOwner> UpgradeRuntimeControllerPrecompile<Runtime, DefaultOwner>
where
DefaultOwner: Get<H160> + 'static,
Runtime: pallet_upgrade_runtime_proposal::Config + pallet_collective::Config<pallet_collective::Instance1> + pallet_timestamp::Config + pallet_evm::Config,
Runtime: pallet_upgrade_runtime_proposal::Config
+ pallet_collective::Config<pallet_collective::Instance1>
+ pallet_timestamp::Config
+ pallet_evm::Config,
Runtime::RuntimeCall: From<pallet_upgrade_runtime_proposal::Call<Runtime>>,
<Runtime::RuntimeCall as Dispatchable>::RuntimeOrigin: From<Option<Runtime::AccountId>>,
Runtime::RuntimeCall: Dispatchable<PostInfo = PostDispatchInfo> + GetDispatchInfo,
Expand Down Expand Up @@ -136,7 +139,7 @@ where
handle.context().address,
SELECTOR_LOG_TRANSFER_OWNER,
Into::<H256>::into(owner),
solidity::encode_event_data(Into::<H256>::into(target_new_owner))
solidity::encode_event_data(Into::<H256>::into(target_new_owner)),
)
.record(handle)?;

Expand Down Expand Up @@ -166,7 +169,7 @@ where
log1(
handle.context().address,
SELECTOR_LOG_NEW_OWNER,
solidity::encode_event_data(Into::<H256>::into(target_new_owner))
solidity::encode_event_data(Into::<H256>::into(target_new_owner)),
)
.record(handle)?;

Expand Down Expand Up @@ -246,7 +249,8 @@ where

let member_id: H160 = member.into();

let old_members = pallet_collective::Pallet::<Runtime, pallet_collective::Instance1>::members();
let old_members =
pallet_collective::Pallet::<Runtime, pallet_collective::Instance1>::members();

if old_members.contains(&member_id.into()) {
return Err(revert("already a member"));
Expand All @@ -257,12 +261,12 @@ where
.cloned()
.chain(Some(member_id.into()))
.collect::<Vec<_>>();

new_members.sort();

pallet_collective::Pallet::<Runtime, pallet_collective::Instance1>::set_members_sorted(
&new_members,
&old_members
&old_members,
);

handle.record_log_costs_manual(1, 32)?;
Expand All @@ -289,13 +293,14 @@ where
if msg_sender != owner {
return Err(revert("sender is not owner"));
}

handle.record_cost(RuntimeHelper::<Runtime>::db_read_gas_cost())?;

let member_id: H160 = member.into();
let member_account = <Runtime as frame_system::Config>::AccountId::from(member_id);

let old_members = pallet_collective::Pallet::<Runtime, pallet_collective::Instance1>::members();
let old_members =
pallet_collective::Pallet::<Runtime, pallet_collective::Instance1>::members();

if !old_members.contains(&member_account) {
return Err(revert("not a member"));
Expand All @@ -306,15 +311,14 @@ where
.cloned()
.filter(|m| *m != member_account)
.collect::<Vec<_>>();

new_members.sort();

pallet_collective::Pallet::<Runtime, pallet_collective::Instance1>::set_members_sorted(
&new_members,
&old_members
&old_members,
);


handle.record_log_costs_manual(1, 32)?;
log1(
handle.context().address,
Expand All @@ -328,12 +332,18 @@ where

#[precompile::public("getTechnicalCommitteeMembers()")]
#[precompile::view]
fn get_technical_committee_members(handle: &mut impl PrecompileHandle) -> EvmResult<Vec<Address>> {
fn get_technical_committee_members(
handle: &mut impl PrecompileHandle,
) -> EvmResult<Vec<Address>> {
handle.record_cost(RuntimeHelper::<Runtime>::db_read_gas_cost())?;

let members = pallet_collective::Pallet::<Runtime, pallet_collective::Instance1>::members();

Ok(members.iter().map(|m| Into::<H160>::into(m.clone())).map(|m| Into::<Address>::into(m)).collect())
Ok(members
.iter()
.map(|m| Into::<H160>::into(m.clone()))
.map(|m| Into::<Address>::into(m))
.collect())
}

#[precompile::public("getHashOfProposedCode()")]
Expand Down
25 changes: 13 additions & 12 deletions precompiles/upgrade-runtime-controller/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use super::*;

use frame_support::{parameter_types, weights::Weight};
use crate::mock::sp_api_hidden_includes_construct_runtime::hidden_include::traits::GenesisBuild;
use frame_support::traits::{ConstU32, ConstU64, Contains};
use frame_support::{parameter_types, weights::Weight};
use frame_system::EnsureRoot;
use pallet_evm::{AddressMapping, EnsureAddressNever, EnsureAddressRoot};
use precompile_utils::precompile_set::*;
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
};
use sp_version::RuntimeVersion;
use precompile_utils::precompile_set::*;
use pallet_evm::{EnsureAddressRoot, EnsureAddressNever, AddressMapping};
use crate::mock::sp_api_hidden_includes_construct_runtime::hidden_include::traits::GenesisBuild;

type Block = frame_system::mocking::MockBlock<Test>;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
Expand Down Expand Up @@ -95,18 +95,13 @@ impl pallet_timestamp::Config for Test {
type WeightInfo = ();
}



pub struct IdentityAddressMapping;
impl pallet_evm::AddressMapping<AccountId> for IdentityAddressMapping {
fn into_account_id(address: H160) -> AccountId {
address.into()
}
}




parameter_types! {
pub BlockGasLimit: U256 = U256::max_value();
pub PrecompilesValue: Precompiles<Test> = Precompiles::new();
Expand Down Expand Up @@ -161,7 +156,7 @@ impl pallet_balances::Config for Test {

type TechCommitteeInstance = pallet_collective::Instance1;

use frame_support::weights::{constants::WEIGHT_REF_TIME_PER_MILLIS};
use frame_support::weights::constants::WEIGHT_REF_TIME_PER_MILLIS;
use sp_runtime::{Perbill, Permill};
use stbl_core_primitives::BlockNumber;

Expand All @@ -176,8 +171,14 @@ const COMPUTATION_BLOCK_TIME_RATIO: (u64, u64) = (2, 3); // 2 third parts of the
const COMPUTATION_POWER_MULTIPLIER: u64 = 6; // 6 times more computation power than normal

// how much weight for normal extrinsics could be processed in a block
pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_MILLIS * MILLISECS_PER_BLOCK * COMPUTATION_POWER_MULTIPLIER * COMPUTATION_BLOCK_TIME_RATIO.0 / COMPUTATION_BLOCK_TIME_RATIO.1, u64::MAX);

pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
WEIGHT_REF_TIME_PER_MILLIS
* MILLISECS_PER_BLOCK
* COMPUTATION_POWER_MULTIPLIER
* COMPUTATION_BLOCK_TIME_RATIO.0
/ COMPUTATION_BLOCK_TIME_RATIO.1,
u64::MAX,
);

parameter_types! {
pub const CouncilMotionDuration: BlockNumber = 120;
Expand Down
Loading

0 comments on commit 109b02e

Please sign in to comment.