Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
40762b6
Refactor rebase master prometheus_v0.3
nodebreaker0-0 Nov 28, 2019
472aca1
Milestone1: Final Version of v0.3
nodebreaker0-0 Dec 10, 2019
1974f94
no-std or warm compatibility issues, grapana-data -source code refere…
nodebreaker0-0 Jan 2, 2020
62a873d
Cargo.lock paritytech/master rebase
nodebreaker0-0 Jan 2, 2020
97e37e4
prometheus networking.rs del, grafana-data-source networking.rs pub e…
nodebreaker0-0 Jan 3, 2020
f3e444e
chore: reflect various feedback
nodebreaker0-0 Jan 10, 2020
8145df7
Spaces to tabs.
gavofyork Jan 6, 2020
fca71be
Replace grafana and tidy
expenses Jan 10, 2020
855ceed
Add generics
expenses Jan 10, 2020
70c6bcc
Add photo back
expenses Jan 10, 2020
5941041
Re-fix spaces in primitives/consensus/babe/src/inherents.rs
expenses Jan 10, 2020
c93a0a3
custom weight function wrapper (#4158)
kianenigma Jan 14, 2020
b443dda
Take `genesis_storage` by ref (#4617)
bkchr Jan 14, 2020
012c5ef
Add trivial EnsureFounder verifier to society (#4615)
gavofyork Jan 14, 2020
410ce11
Update the service to std futures (#4447)
expenses Jan 14, 2020
45995b4
fixed panic on empty remote read request (#4619)
svyatonik Jan 14, 2020
8cb71bd
Add `pallet-society` and `pallet-recovery` to substrate node (#4622)
bkchr Jan 14, 2020
37be263
Make offchain worker calls more future proof. (#4618)
tomusdrw Jan 14, 2020
05ce617
network: add logging for extra requests (#4625)
andresilva Jan 15, 2020
5649259
Add more logging to the network (#4621)
tomaka Jan 15, 2020
33b3c23
Return early when fees/balances/values are zero (#4628)
shawntabrizi Jan 15, 2020
c2b0c0f
reset a couple of versions down from v2.0 (#4572)
rphmeier Jan 15, 2020
af1bc8c
fix some discrepancies in generic-asset (#4221)
kigawas Jan 15, 2020
1dafa60
Make Proposer instantiation potentially async. (#4630)
rphmeier Jan 15, 2020
f21eb1a
remove old test (#4637)
gui1117 Jan 16, 2020
4c4ee3d
use default in-memory for commands that don't use keystore (#4634)
NikVolf Jan 16, 2020
3fa5f09
Getting configuration from commands (#4643)
cecton Jan 16, 2020
47c36e6
Rename basic-authority to basic-authorship (#4640)
tomusdrw Jan 16, 2020
879e28a
Implement runtime version checks in `set_code` (#4548)
bkchr Jan 16, 2020
99430a5
grandpa: generic voting rule for backing off from best block (#4635)
andresilva Jan 16, 2020
1e0c679
Make the sync_cycle_from_offline_to_syncing_to_offline test non flaky…
tomaka Jan 16, 2020
f931588
Merge remote-tracking branch 'nodebreaker/prometheus_v0.3' into ashle…
expenses Jan 16, 2020
5796c85
Merge remote-tracking branch 'parity/master' into ashley-prometheus
expenses Jan 16, 2020
8e98643
Allow updating configuration of changes tries (#3201)
svyatonik Jan 16, 2020
2a45de8
Merge remote-tracking branch 'parity/master' into ashley-prometheus
expenses Jan 16, 2020
6a7137f
remove unused safe-mix dependency (#4656)
xlc Jan 17, 2020
394bcf4
Add typedefs for storage types (#4654)
stanislav-tkach Jan 17, 2020
7248ac2
add debug logs (#4657)
NikVolf Jan 17, 2020
188d59e
CODEOWNERS: Add myself to pow and EVM module (#4653)
sorpaas Jan 17, 2020
8bae73b
Merge remote-tracking branch 'parity/master' into ashley-prometheus
expenses Jan 17, 2020
d4fbb89
client/finality-grandpa: Reintegrate periodic neighbor packet worker …
mxinden Jan 17, 2020
2d15616
grandpa: bump finality-grandpa crate to v0.10.3 (#4659)
andresilva Jan 17, 2020
10bebed
add missing bits (#4660)
NikVolf Jan 17, 2020
083ada5
Patch practical usability issues with Society (#4651)
shawntabrizi Jan 17, 2020
36a6de0
Expose proof generation and verifying api. (#4646)
montekki Jan 17, 2020
1caa0f1
Merge remote-tracking branch 'parity/master' into ashley-prometheus
expenses Jan 17, 2020
ffb4746
Tidy
expenses Jan 17, 2020
e581e3c
Drive by fix of doc of `Value`. (#4658)
pepyakin Jan 17, 2020
f0c1852
client/finality-grandpa: Reintegrate gossip validator report stream (…
mxinden Jan 17, 2020
8a6e3c5
Use local registry
expenses Jan 17, 2020
8de5340
Society: Ensure all votes are removed after tally (#4666)
shawntabrizi Jan 17, 2020
0097939
make compute_fee public (#4669)
xlc Jan 18, 2020
a31ad6e
`sp-runtime-interface` add table about FFI types (#4668)
bkchr Jan 18, 2020
8131288
Add rules and unfounding to society. (#4671)
gavofyork Jan 18, 2020
6cf45f2
Make use of `cfg(doc)` in `sp-runtime-interface` (#4673)
bkchr Jan 19, 2020
3d1634b
Merge remote-tracking branch 'nodebreaker/prometheus_v0.3' into ashle…
expenses Jan 20, 2020
55ac4f8
Merge remote-tracking branch 'parity/master' into ashley-prometheus
expenses Jan 20, 2020
3cfe43c
endpoint -> exporter
expenses Jan 20, 2020
0af2369
fix readme
expenses Jan 20, 2020
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
Prev Previous commit
Next Next commit
Return early when fees/balances/values are zero (paritytech#4628)
* Return early when fees/balances/values are zero

* Add docs about no-op
  • Loading branch information
shawntabrizi authored and gavofyork committed Jan 15, 2020
commit 33b3c2386010a124e90cd3490b6d4a63fd89576e
58 changes: 57 additions & 1 deletion frame/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,10 @@ where
Self::free_balance(who) + Self::reserved_balance(who)
}

// Check if `value` amount of free balance can be slashed from `who`.
// Is a no-op if value to be slashed is zero.
fn can_slash(who: &T::AccountId, value: Self::Balance) -> bool {
if value.is_zero() { return true }
Self::free_balance(who) >= value
}

Expand All @@ -901,7 +904,10 @@ where
<FreeBalance<T, I>>::get(who)
}

// Burn funds from the total issuance, returning a positive imbalance for the amount burned.
// Is a no-op if amount to be burned is zero.
fn burn(mut amount: Self::Balance) -> Self::PositiveImbalance {
if amount.is_zero() { return PositiveImbalance::zero() }
<TotalIssuance<T, I>>::mutate(|issued| {
*issued = issued.checked_sub(&amount).unwrap_or_else(|| {
amount = *issued;
Expand All @@ -911,7 +917,11 @@ where
PositiveImbalance::new(amount)
}

// Create new funds into the total issuance, returning a negative imbalance
// for the amount issued.
// Is a no-op if amount to be issued it zero.
fn issue(mut amount: Self::Balance) -> Self::NegativeImbalance {
if amount.is_zero() { return NegativeImbalance::zero() }
<TotalIssuance<T, I>>::mutate(|issued|
*issued = issued.checked_add(&amount).unwrap_or_else(|| {
amount = Self::Balance::max_value() - *issued;
Expand All @@ -921,16 +931,21 @@ where
NegativeImbalance::new(amount)
}

// Ensure that an account can withdraw from their free balance given any existing withdrawal
// restrictions like locks and vesting balance.
// Is a no-op if amount to be withdrawn is zero.
//
// # <weight>
// Despite iterating over a list of locks, they are limited by the number of
// lock IDs, which means the number of runtime modules that intend to use and create locks.
// # </weight>
fn ensure_can_withdraw(
who: &T::AccountId,
_amount: T::Balance,
amount: T::Balance,
reasons: WithdrawReasons,
new_balance: T::Balance,
) -> DispatchResult {
if amount.is_zero() { return Ok(()) }
if reasons.intersects(WithdrawReason::Reserve | WithdrawReason::Transfer)
&& Self::vesting_balance(who) > new_balance
{
Expand All @@ -955,12 +970,15 @@ where
}
}

// Transfer some free balance from `transactor` to `dest`, respecting existence requirements.
// Is a no-op if value to be transferred is zero.
fn transfer(
transactor: &T::AccountId,
dest: &T::AccountId,
value: Self::Balance,
existence_requirement: ExistenceRequirement,
) -> DispatchResult {
if value.is_zero() { return Ok(()) }
let from_balance = Self::free_balance(transactor);
let to_balance = Self::free_balance(dest);
let would_create = to_balance.is_zero();
Expand Down Expand Up @@ -1001,12 +1019,16 @@ where
Ok(())
}

// Withdraw some free balance from an account, respecting existence requirements.
// Is a no-op if value to be withdrawn is zero.
fn withdraw(
who: &T::AccountId,
value: Self::Balance,
reasons: WithdrawReasons,
liveness: ExistenceRequirement,
) -> result::Result<Self::NegativeImbalance, DispatchError> {
if value.is_zero() { return Ok(NegativeImbalance::zero()); }

let old_balance = Self::free_balance(who);
if let Some(new_balance) = old_balance.checked_sub(&value) {
// if we need to keep the account alive...
Expand All @@ -1026,10 +1048,15 @@ where
}
}

// Slash an account, returning the negative imbalance created and any left over
// amount that could not be slashed.
// Is a no-op if value to be slashed is zero.
fn slash(
who: &T::AccountId,
value: Self::Balance
) -> (Self::NegativeImbalance, Self::Balance) {
if value.is_zero() { return (NegativeImbalance::zero(), Zero::zero()) }

let free_balance = Self::free_balance(who);
let free_slash = cmp::min(free_balance, value);

Expand All @@ -1049,21 +1076,29 @@ where
}
}

// Deposit some `value` into the free balance of an existing account.
// Is a no-op if the value to be deposited is zero.
fn deposit_into_existing(
who: &T::AccountId,
value: Self::Balance
) -> result::Result<Self::PositiveImbalance, DispatchError> {
if value.is_zero() { return Ok(PositiveImbalance::zero()) }

if Self::total_balance(who).is_zero() {
Err(Error::<T, I>::DeadAccount)?
}
Self::set_free_balance(who, Self::free_balance(who) + value);
Ok(PositiveImbalance::new(value))
}

// Deposit some `value` into the free balance of `who`, possibly creating a new account.
// Is a no-op if the value to be deposited is zero.
fn deposit_creating(
who: &T::AccountId,
value: Self::Balance,
) -> Self::PositiveImbalance {
if value.is_zero() { return Self::PositiveImbalance::zero() }

let (imbalance, _) = Self::make_free_balance_be(who, Self::free_balance(who) + value);
if let SignedImbalance::Positive(p) = imbalance {
p
Expand Down Expand Up @@ -1122,7 +1157,10 @@ impl<T: Trait<I>, I: Instance> ReservableCurrency<T::AccountId> for Module<T, I>
where
T::Balance: MaybeSerializeDeserialize + Debug
{
// Check if `who` can reserve `value` from their free balance.
// Is a no-op if value to be reserved is zero.
fn can_reserve(who: &T::AccountId, value: Self::Balance) -> bool {
if value.is_zero() { return true }
Self::free_balance(who)
.checked_sub(&value)
.map_or(false, |new_balance|
Expand All @@ -1134,7 +1172,10 @@ where
<ReservedBalance<T, I>>::get(who)
}

// Move `value` from the free balance from `who` to their reserved balance.
// Is a no-op if value to be reserved is zero.
fn reserve(who: &T::AccountId, value: Self::Balance) -> result::Result<(), DispatchError> {
if value.is_zero() { return Ok(()) }
let b = Self::free_balance(who);
if b < value {
Err(Error::<T, I>::InsufficientBalance)?
Expand All @@ -1146,30 +1187,40 @@ where
Ok(())
}

// Unreserve some funds, returning any amount that was unable to be unreserved.
// Is a no-op if the value to be unreserved is zero.
fn unreserve(who: &T::AccountId, value: Self::Balance) -> Self::Balance {
if value.is_zero() { return Zero::zero() }
let b = Self::reserved_balance(who);
let actual = cmp::min(b, value);
Self::set_free_balance(who, Self::free_balance(who) + actual);
Self::set_reserved_balance(who, b - actual);
value - actual
}

// Slash from reserved balance, returning the negative imbalance created,
// and any amount that was unable to be slashed.
// Is a no-op if the value to be slashed is zero.
fn slash_reserved(
who: &T::AccountId,
value: Self::Balance
) -> (Self::NegativeImbalance, Self::Balance) {
if value.is_zero() { return (NegativeImbalance::zero(), Zero::zero()) }
let b = Self::reserved_balance(who);
let slash = cmp::min(b, value);
// underflow should never happen, but it if does, there's nothing to be done here.
Self::set_reserved_balance(who, b - slash);
(NegativeImbalance::new(slash), value - slash)
}

// Move the reserved balance of one account into the free balance of another.
// Is a no-op if the value to be moved is zero.
fn repatriate_reserved(
slashed: &T::AccountId,
beneficiary: &T::AccountId,
value: Self::Balance,
) -> result::Result<Self::Balance, DispatchError> {
if value.is_zero() { return Ok (Zero::zero()) }
if Self::total_balance(beneficiary).is_zero() {
Err(Error::<T, I>::DeadAccount)?
}
Expand All @@ -1187,13 +1238,16 @@ where
{
type Moment = T::BlockNumber;

// Set a lock on the balance of `who`.
// Is a no-op if lock amount is zero.
fn set_lock(
id: LockIdentifier,
who: &T::AccountId,
amount: T::Balance,
until: T::BlockNumber,
reasons: WithdrawReasons,
) {
if amount.is_zero() { return }
let now = <frame_system::Module<T>>::block_number();
let mut new_lock = Some(BalanceLock { id, amount, until, reasons });
let mut locks = Self::locks(who).into_iter().filter_map(|l|
Expand Down Expand Up @@ -1275,12 +1329,14 @@ where
///
/// If there already exists a vesting schedule for the given account, an `Err` is returned
/// and nothing is updated.
/// Is a no-op if the amount to be vested is zero.
fn add_vesting_schedule(
who: &T::AccountId,
locked: T::Balance,
per_block: T::Balance,
starting_block: T::BlockNumber
) -> DispatchResult {
if locked.is_zero() { return Ok(()) }
if <Vesting<T, I>>::exists(who) {
Err(Error::<T, I>::ExistingVestingSchedule)?
}
Expand Down
31 changes: 17 additions & 14 deletions frame/transaction-payment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,20 +218,23 @@ impl<T: Trait + Send + Sync> SignedExtension for ChargeTransactionPayment<T>
// pay any fees.
let tip = self.0;
let fee = Self::compute_fee(len as u32, info, tip);
let imbalance = match T::Currency::withdraw(
who,
fee,
if tip.is_zero() {
WithdrawReason::TransactionPayment.into()
} else {
WithdrawReason::TransactionPayment | WithdrawReason::Tip
},
ExistenceRequirement::KeepAlive,
) {
Ok(imbalance) => imbalance,
Err(_) => return InvalidTransaction::Payment.into(),
};
T::OnTransactionPayment::on_unbalanced(imbalance);
// Only mess with balances if fee is not zero.
if !fee.is_zero() {
let imbalance = match T::Currency::withdraw(
who,
fee,
if tip.is_zero() {
WithdrawReason::TransactionPayment.into()
} else {
WithdrawReason::TransactionPayment | WithdrawReason::Tip
},
ExistenceRequirement::KeepAlive,
) {
Ok(imbalance) => imbalance,
Err(_) => return InvalidTransaction::Payment.into(),
};
T::OnTransactionPayment::on_unbalanced(imbalance);
}

let mut r = ValidTransaction::default();
// NOTE: we probably want to maximize the _fee (of any type) per weight unit_ here, which
Expand Down