Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into fix-7074
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaka committed Oct 30, 2020
2 parents 50564dc + 5d30787 commit 256722e
Show file tree
Hide file tree
Showing 62 changed files with 939 additions and 800 deletions.
48 changes: 24 additions & 24 deletions .maintain/frame-weight-template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -33,68 +33,68 @@ use sp_std::marker::PhantomData;

/// Weight functions needed for {{pallet}}.
pub trait WeightInfo {
{{#each benchmarks as |benchmark| ~}}
{{~#each benchmarks as |benchmark|}}
fn {{benchmark.name~}}
(
{{~#each benchmark.components as |c| ~}}
{{c.name}}: u32, {{/each~}}
) -> Weight;
{{/each}}
{{~/each}}
}

/// Weights for {{pallet}} using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Trait> WeightInfo for SubstrateWeight<T> {
{{#each benchmarks as |benchmark| ~}}
{{~#each benchmarks as |benchmark|}}
fn {{benchmark.name~}}
(
{{~#each benchmark.components as |c| ~}}
{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
) -> Weight {
({{underscore benchmark.base_weight}} as Weight)
{{#each benchmark.component_weight as |cw| ~}}
{{~#each benchmark.component_weight as |cw|}}
.saturating_add(({{underscore cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight))
{{/each}}
{{~#if (ne benchmark.base_reads "0") ~}}
{{~/each}}
{{~#if (ne benchmark.base_reads "0")}}
.saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}} as Weight))
{{/if}}
{{~#each benchmark.component_reads as |cr| ~}}
{{~/if}}
{{~#each benchmark.component_reads as |cr|}}
.saturating_add(T::DbWeight::get().reads(({{cr.slope}} as Weight).saturating_mul({{cr.name}} as Weight)))
{{/each}}
{{~#if (ne benchmark.base_writes "0") ~}}
{{~/each}}
{{~#if (ne benchmark.base_writes "0")}}
.saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}} as Weight))
{{/if}}
{{~#each benchmark.component_writes as |cw| ~}}
{{~/if}}
{{~#each benchmark.component_writes as |cw|}}
.saturating_add(T::DbWeight::get().writes(({{cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight)))
{{~/each}}
}
{{/each}}
{{~/each}}
}

// For backwards compatibility and tests
impl WeightInfo for () {
{{#each benchmarks as |benchmark| ~}}
{{~#each benchmarks as |benchmark|}}
fn {{benchmark.name~}}
(
{{~#each benchmark.components as |c| ~}}
{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
) -> Weight {
({{underscore benchmark.base_weight}} as Weight)
{{#each benchmark.component_weight as |cw| ~}}
{{~#each benchmark.component_weight as |cw|}}
.saturating_add(({{underscore cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight))
{{/each}}
{{~#if (ne benchmark.base_reads "0") ~}}
{{~/each}}
{{~#if (ne benchmark.base_reads "0")}}
.saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}} as Weight))
{{/if}}
{{~#each benchmark.component_reads as |cr| ~}}
{{~/if}}
{{~#each benchmark.component_reads as |cr|}}
.saturating_add(RocksDbWeight::get().reads(({{cr.slope}} as Weight).saturating_mul({{cr.name}} as Weight)))
{{/each}}
{{~#if (ne benchmark.base_writes "0") ~}}
{{~/each}}
{{~#if (ne benchmark.base_writes "0")}}
.saturating_add(RocksDbWeight::get().writes({{benchmark.base_writes}} as Weight))
{{/if}}
{{~#each benchmark.component_writes as |cw| ~}}
{{~/if}}
{{~#each benchmark.component_writes as |cw|}}
.saturating_add(RocksDbWeight::get().writes(({{cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight)))
{{~/each}}
}
{{/each}}
{{~/each}}
}
18 changes: 7 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub use frame_support::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
},
};
use pallet_transaction_payment::CurrencyAdapter;

/// Import the template pallet.
pub use template;
Expand Down Expand Up @@ -249,8 +250,7 @@ parameter_types! {
}

impl pallet_transaction_payment::Trait for Runtime {
type Currency = Balances;
type OnTransactionPayment = ();
type OnChargeTransaction = CurrencyAdapter<Balances, ()>;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = IdentityFee<Balance>;
type FeeMultiplierUpdate = ();
Expand Down
19 changes: 4 additions & 15 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ use pallet_grandpa::fg_primitives;
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
use pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;
pub use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment};
use pallet_contracts_rpc_runtime_api::ContractExecResult;
pub use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment, CurrencyAdapter};
use pallet_session::{historical as pallet_session_historical};
use sp_inherents::{InherentData, CheckInherentsResult};
use static_assertions::const_assert;
Expand Down Expand Up @@ -361,8 +360,7 @@ parameter_types! {
}

impl pallet_transaction_payment::Trait for Runtime {
type Currency = Balances;
type OnTransactionPayment = DealWithFees;
type OnChargeTransaction = CurrencyAdapter<Balances, DealWithFees>;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = IdentityFee<Balance>;
type FeeMultiplierUpdate =
Expand Down Expand Up @@ -1124,17 +1122,8 @@ impl_runtime_apis! {
value: Balance,
gas_limit: u64,
input_data: Vec<u8>,
) -> ContractExecResult {
let (exec_result, gas_consumed) =
Contracts::bare_call(origin, dest.into(), value, gas_limit, input_data);
match exec_result {
Ok(v) => ContractExecResult::Success {
flags: v.flags.bits(),
data: v.data,
gas_consumed: gas_consumed,
},
Err(_) => ContractExecResult::Error,
}
) -> pallet_contracts_primitives::ContractExecResult {
Contracts::bare_call(origin, dest, value, gas_limit, input_data)
}

fn get_storage(
Expand Down
3 changes: 1 addition & 2 deletions client/api/src/call_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ pub trait CallExecutor<B: BlockT> {
) -> Result<(Vec<u8>, StorageProof), sp_blockchain::Error> {
let trie_state = state.as_trie_backend()
.ok_or_else(||
Box::new(sp_state_machine::ExecutionError::UnableToGenerateProof)
as Box<dyn sp_state_machine::Error>
sp_blockchain::Error::from_state(Box::new(sp_state_machine::ExecutionError::UnableToGenerateProof) as Box<_>)
)?;
self.prove_at_trie_state(trie_state, overlay, method, call_data)
}
Expand Down
6 changes: 3 additions & 3 deletions client/api/src/cht.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub fn build_proof<Header, Hasher, BlocksI, HashesI>(
prove_read_on_trie_backend(
trie_storage,
blocks.into_iter().map(|number| encode_cht_key(number)),
).map_err(ClientError::Execution)
).map_err(ClientError::from_state)
}

/// Check CHT-based header proof.
Expand Down Expand Up @@ -150,7 +150,7 @@ pub fn check_proof<Header, Hasher>(
.map(|mut map| map
.remove(local_cht_key)
.expect("checked proof of local_cht_key; qed"))
.map_err(|e| ClientError::from(e)),
.map_err(ClientError::from_state),
)
}

Expand All @@ -174,7 +174,7 @@ pub fn check_proof_on_proving_backend<Header, Hasher>(
read_proof_check_on_proving_backend::<Hasher>(
proving_backend,
local_cht_key,
).map_err(|e| ClientError::from(e)),
).map_err(ClientError::from_state),
)
}

Expand Down
2 changes: 1 addition & 1 deletion client/cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub enum Error {
InvalidListenMultiaddress,
/// Application specific error chain sequence forwarder.
#[error(transparent)]
Application(#[from] Box<dyn std::error::Error>),
Application(#[from] Box<dyn std::error::Error + Send + Sync + 'static>),
/// URI error.
#[error("Invalid URI; expecting either a secret URI or a public URI.")]
InvalidUri(crypto::PublicError),
Expand Down
5 changes: 5 additions & 0 deletions client/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,11 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkService<B, H> {
if let Some(protocol_name) = protocol_name {
sink.send_sync_notification(protocol_name, message);
} else {
log::error!(
target: "sub-libp2p",
"Attempted to send notification on unknown protocol: {:?}",
engine_id,
);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion docs/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
/primitives/consensus/pow/ @sorpaas

# Contracts
/frame/contracts/ @pepyakin
/frame/contracts/ @athei

# EVM
/frame/evm/ @sorpaas
Expand Down
16 changes: 8 additions & 8 deletions frame/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ use frame_support::{
StorageValue, Parameter, decl_event, decl_storage, decl_module, decl_error, ensure,
traits::{
Currency, OnKilledAccount, OnUnbalanced, TryDrop, StoredMap,
WithdrawReason, WithdrawReasons, LockIdentifier, LockableCurrency, ExistenceRequirement,
WithdrawReasons, LockIdentifier, LockableCurrency, ExistenceRequirement,
Imbalance, SignedImbalance, ReservableCurrency, Get, ExistenceRequirement::KeepAlive,
ExistenceRequirement::AllowDeath, IsDeadAccount, BalanceStatus as Status,
}
Expand Down Expand Up @@ -292,9 +292,9 @@ pub enum Reasons {

impl From<WithdrawReasons> for Reasons {
fn from(r: WithdrawReasons) -> Reasons {
if r == WithdrawReasons::from(WithdrawReason::TransactionPayment) {
if r == WithdrawReasons::from(WithdrawReasons::TRANSACTION_PAYMENT) {
Reasons::Fee
} else if r.contains(WithdrawReason::TransactionPayment) {
} else if r.contains(WithdrawReasons::TRANSACTION_PAYMENT) {
Reasons::All
} else {
Reasons::Misc
Expand Down Expand Up @@ -1011,7 +1011,7 @@ impl<T: Trait<I>, I: Instance> Currency<T::AccountId> for Module<T, I> where
Self::ensure_can_withdraw(
transactor,
value,
WithdrawReason::Transfer.into(),
WithdrawReasons::TRANSFER,
from_account.free,
)?;

Expand Down Expand Up @@ -1170,7 +1170,7 @@ impl<T: Trait<I>, I: Instance> ReservableCurrency<T::AccountId> for Module<T, I>
Self::account(who).free
.checked_sub(&value)
.map_or(false, |new_balance|
Self::ensure_can_withdraw(who, value, WithdrawReason::Reserve.into(), new_balance).is_ok()
Self::ensure_can_withdraw(who, value, WithdrawReasons::RESERVE, new_balance).is_ok()
)
}

Expand All @@ -1187,7 +1187,7 @@ impl<T: Trait<I>, I: Instance> ReservableCurrency<T::AccountId> for Module<T, I>
Self::try_mutate_account(who, |account, _| -> DispatchResult {
account.free = account.free.checked_sub(&value).ok_or(Error::<T, I>::InsufficientBalance)?;
account.reserved = account.reserved.checked_add(&value).ok_or(Error::<T, I>::Overflow)?;
Self::ensure_can_withdraw(&who, value.clone(), WithdrawReason::Reserve.into(), account.free)
Self::ensure_can_withdraw(&who, value.clone(), WithdrawReasons::RESERVE, account.free)
})?;

Self::deposit_event(RawEvent::Reserved(who.clone(), value));
Expand Down Expand Up @@ -1303,7 +1303,7 @@ where
amount: T::Balance,
reasons: WithdrawReasons,
) {
if amount.is_zero() || reasons.is_none() { return }
if amount.is_zero() || reasons.is_empty() { return }
let mut new_lock = Some(BalanceLock { id, amount, reasons: reasons.into() });
let mut locks = Self::locks(who).into_iter()
.filter_map(|l| if l.id == id { new_lock.take() } else { Some(l) })
Expand All @@ -1322,7 +1322,7 @@ where
amount: T::Balance,
reasons: WithdrawReasons,
) {
if amount.is_zero() || reasons.is_none() { return }
if amount.is_zero() || reasons.is_empty() { return }
let mut new_lock = Some(BalanceLock { id, amount, reasons: reasons.into() });
let mut locks = Self::locks(who).into_iter().filter_map(|l|
if l.id == id {
Expand Down
Loading

0 comments on commit 256722e

Please sign in to comment.