Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/higher funding proposal cap #5163

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion runtime-modules/argo-bridge/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::types::*;
use crate::vec::Vec;
use crate::Module as ArgoBridge;
use balances::Pallet as Balances;
use core::convert::TryFrom;
use core::convert::{TryFrom, TryInto};
use frame_benchmarking::v1::{account, benchmarks};
use frame_system::Pallet as System;
use frame_system::{EventRecord, RawOrigin};
Expand Down
33 changes: 13 additions & 20 deletions runtime-modules/argo-bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,14 @@
not(any(test, feature = "runtime-benchmarks")),
deny(clippy::panic),
deny(clippy::panic_in_result_fn),
deny(clippy::unwrap_used),
deny(clippy::expect_used),
deny(clippy::indexing_slicing),
deny(clippy::integer_arithmetic),
deny(clippy::match_on_vec_items),
deny(clippy::unreachable)
)]

#[cfg(not(any(test, feature = "runtime-benchmarks")))]
#[allow(unused_imports)]
#[macro_use]
extern crate common;

use core::{convert::TryInto, default::Default};
use core::default::Default;
use frame_support::{
decl_module, decl_storage,
dispatch::{marker::Copy, DispatchResult},
Expand All @@ -26,8 +20,8 @@ use frame_support::{
traits::{ConstU32, Currency, Get},
};
use frame_system::{ensure_root, ensure_signed};
use sp_runtime::traits::CheckedAdd;
use sp_runtime::DispatchError;
use sp_runtime::{traits::CheckedAdd, SaturatedConversion};

use sp_std::vec;

Expand Down Expand Up @@ -107,6 +101,8 @@ decl_module! {
let amount_with_fees = amount.checked_add(&fee).ok_or(Error::<T>::ArithmeticError)?;
let sender = ensure_signed(origin)?;
ensure!(has_sufficient_balance_for_payment::<T>(&sender, amount_with_fees), Error::<T>::InsufficientJoyBalance);
let transfer_id = NextTransferId::get();
let next_transfer_id = transfer_id.checked_add(1).ok_or(Error::<T>::ArithmeticError)?;

//
// == MUTATION SAFE ==
Expand All @@ -115,9 +111,8 @@ decl_module! {
burn_from_usable::<T>(&sender, amount_with_fees)?;
<MintAllowance<T>>::put(Self::mint_allowance() + amount);

let transfer_id = NextTransferId::get();
Self::deposit_event(RawEvent::OutboundTransferRequested(transfer_id, sender, dest_account, amount, fee));
NextTransferId::put(transfer_id + 1);
NextTransferId::put(next_transfer_id);

Ok(())
}
Expand Down Expand Up @@ -249,7 +244,8 @@ decl_module! {
}

if let Some(ref new_pauser_accounts) = parameters.pauser_accounts {
ensure!(new_pauser_accounts.len() <= T::MaxPauserAccounts::get().try_into().unwrap(), Error::<T>::InvalidNumberOfPauserAccounts);
// converts into range [0, u32::MAX], no risk as we might assume that the number of pausers is less than 100
ensure!(new_pauser_accounts.len().saturated_into::<u32>() <= T::MaxPauserAccounts::get(), Error::<T>::InvalidNumberOfPauserAccounts);
<PauserAccounts<T>>::put(BoundedVec::truncate_from(new_pauser_accounts.to_vec()));
}

Expand Down Expand Up @@ -285,15 +281,12 @@ impl<T: Config> Module<T> {

pub fn ensure_operator_origin(origin: T::RuntimeOrigin) -> Result<T::AccountId, DispatchError> {
let caller = ensure_signed(origin)?;
ensure!(
Self::operator_account().is_some(),
Error::<T>::OperatorAccountNotSet
);
ensure!(
caller == Self::operator_account().unwrap(),
Error::<T>::NotOperatorAccount
);
Ok(caller)
if let Some(operator_account) = Self::operator_account() {
ensure!(caller == operator_account, Error::<T>::NotOperatorAccount);
Ok(caller)
} else {
Err(Error::<T>::OperatorAccountNotSet.into())
}
}

pub fn ensure_pauser_origin(origin: T::RuntimeOrigin) -> Result<T::AccountId, DispatchError> {
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,7 @@ parameter_types! {
// Make sure to stay below MAX_BLOCK_SIZE of substrate consensus of ~4MB
// The new compressed wasm format is much smaller in size ~ 1MB
pub const RuntimeUpgradeWasmProposalMaxLength: u32 = DispatchableCallCodeMaxLen::get();
pub const FundingRequestProposalMaxTotalAmount: Balance = currency::BASE_UNIT_PER_JOY * 1_000_000;
pub const FundingRequestProposalMaxTotalAmount: Balance = joy!(1_000_000);
pub const FundingRequestProposalMaxAccounts: u32 = 20;
pub const SetMaxValidatorCountProposalMaxValidators: u32 = 100;
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/proposals_configuration/defaults.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! This module contains default "production" parameters configuration for the runtime codex proposals.

use crate::{
currency, days, dollars, hours, Balance, BlockNumber, CouncilSize, ExpectedBlockTime,
currency, days, dollars, hours, joy, Balance, BlockNumber, CouncilSize, ExpectedBlockTime,
ProposalParameters,
};
use static_assertions::const_assert;
Expand Down Expand Up @@ -65,7 +65,7 @@ pub(crate) fn funding_request_proposal() -> ProposalParameters<BlockNumber, Bala
approval_threshold_percentage: TWO_OUT_OF_THREE,
slashing_quorum_percentage: ALL,
slashing_threshold_percentage: ALL,
required_stake: Some(currency::BASE_UNIT_PER_JOY * 3_500),
required_stake: Some(joy!(3_500)),
constitutionality: 1,
}
}
Expand Down
7 changes: 7 additions & 0 deletions runtime/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,10 @@ macro_rules! monthly_dollars_to_per_block {
dollars!($a).saturating_div(Balance::from(days!(30)))
}};
}

#[macro_export]
macro_rules! joy {
($a: expr) => {
currency::BASE_UNIT_PER_JOY * $a
};
}
Loading