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

Updates needed for substrate #4820 (composite accounts) #834

Closed
wants to merge 50 commits into from
Closed
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
2383ba9
Amalgamate pieces of balance module
gavofyork Jan 20, 2020
62023ac
Merge branch 'master' of github.com:paritytech/polkadot
gavofyork Jan 22, 2020
e4065cb
Fixes for vesting split
gavofyork Jan 22, 2020
f7d05c8
Refactoring for vesting/balances split
gavofyork Jan 22, 2020
372908d
Build fixes
gavofyork Jan 23, 2020
f9b2b2f
Remove on_free_balance_zero and some docs.
gavofyork Jan 23, 2020
c51f4d7
Indentation.
gavofyork Jan 29, 2020
84ed49c
Merge branch 'gav-split-balanecs-vesting' into gav-upsub
gavofyork Feb 1, 2020
94b9d10
Revert branch
gavofyork Feb 1, 2020
d7b44ec
Fix.
gavofyork Feb 2, 2020
4013a30
Update substrate: fixes after CLI refactoring
cecton Feb 4, 2020
830f819
Merge branch 'master' into gav-upsub
rphmeier Feb 5, 2020
b5f436a
Reverting removal of exit
cecton Feb 6, 2020
1df7547
Removed too much again
cecton Feb 6, 2020
7916135
Update Cargo.lock
cecton Feb 6, 2020
96a0c87
Cargo.lock
cecton Feb 7, 2020
a1f25b4
Update Substrate, ready for #4820
gavofyork Feb 7, 2020
bebc910
Merge branch 'gav-upsub' of github.com:paritytech/polkadot into gav-u…
gavofyork Feb 7, 2020
6b05cb4
Fixes
gavofyork Feb 7, 2020
bffee5e
Merge remote-tracking branch 'origin/cecton-cli-refactoring-more' int…
bkchr Feb 8, 2020
3441e24
Merge remote-tracking branch 'origin/cecton-cli-refactoring-more' int…
gavofyork Feb 8, 2020
142b9c9
Merge branch 'gav-upsub' of github.com:paritytech/polkadot into gav-u…
gavofyork Feb 8, 2020
09e6236
Update to latest substrate master
bkchr Feb 8, 2020
691c6c3
Fix network tests
bkchr Feb 8, 2020
e710b5b
Changes needed for substrate/#4820
gavofyork Feb 8, 2020
7f7ce20
Remove StaticLookup
gavofyork Feb 8, 2020
c563e9d
Bump version to 0.7.21
gavofyork Feb 8, 2020
ab23e94
rename uses of StorageMap::exists(key) to ::contains_key(key)
apopiak Feb 7, 2020
587a1fd
use substrate PR branch
apopiak Feb 7, 2020
e124686
adjust impl_version according to substrate change
apopiak Feb 7, 2020
8ab4509
update Cargo.lock
apopiak Feb 7, 2020
9239d7e
use master branch instead of PR branch
apopiak Feb 10, 2020
a616423
Revert "use master branch instead of PR branch"
apopiak Feb 10, 2020
cdacb01
Style
gavofyork Feb 10, 2020
a068b4a
Merge remote-tracking branch 'origin/master' into gav-composite-account
gavofyork Feb 10, 2020
b3f98cd
Merge remote-tracking branch 'origin/apopiak-rename-exists-to-contain…
gavofyork Feb 10, 2020
f9e41fb
Fix tests
gavofyork Feb 10, 2020
8586c90
Merge remote-tracking branch 'origin/master' into gav-composite-account
gavofyork Feb 10, 2020
770e0e6
Update lock
gavofyork Feb 10, 2020
3aaaab3
Update to use correct hash
gavofyork Feb 10, 2020
7ed3a51
Bump spec_version for polkadot runtime
jacogr Feb 11, 2020
2355515
Tidying it up.
gavofyork Feb 13, 2020
06f5595
Merge branch 'gav-composite-account' of github.com:paritytech/polkado…
gavofyork Feb 13, 2020
4be0cbc
Merge remote-tracking branch 'origin/master' into gav-composite-account
bkchr Feb 15, 2020
335d0de
*: Ensure GossipEngine is being polled
mxinden Feb 11, 2020
9e1f576
Update to latest Substrate master
bkchr Feb 15, 2020
a5c02b6
Merge remote-tracking branch 'origin/master' into gav-composite-account
bkchr Feb 15, 2020
ac69c83
Bump spec_version for polkadot runtime
jacogr Feb 15, 2020
15fe7cc
Fix claim w/ vesting logic
shawntabrizi Feb 19, 2020
6c4c166
Make claim tests a bit better
shawntabrizi Feb 19, 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
700 changes: 386 additions & 314 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ path = "src/main.rs"

[package]
name = "polkadot"
version = "0.7.20"
version = "0.7.21"
authors = ["Parity Technologies <[email protected]>"]
build = "build.rs"
edition = "2018"
Expand Down
2 changes: 1 addition & 1 deletion availability-store/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "polkadot-availability-store"
description = "Persistent database for parachain data"
version = "0.7.20"
version = "0.7.21"
authors = ["Parity Technologies <[email protected]>"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "polkadot-cli"
version = "0.7.20"
version = "0.7.21"
authors = ["Parity Technologies <[email protected]>"]
description = "Polkadot node implementation in Rust."
edition = "2018"
Expand Down
2 changes: 1 addition & 1 deletion collator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "polkadot-collator"
version = "0.7.20"
version = "0.7.21"
authors = ["Parity Technologies <[email protected]>"]
description = "Collator node implementation"
edition = "2018"
Expand Down
2 changes: 1 addition & 1 deletion erasure-coding/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "polkadot-erasure-coding"
version = "0.7.20"
version = "0.7.21"
authors = ["Parity Technologies <[email protected]>"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion network/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "polkadot-network"
version = "0.7.20"
version = "0.7.21"
authors = ["Parity Technologies <[email protected]>"]
description = "Polkadot-specific networking protocol"
edition = "2018"
Expand Down
10 changes: 9 additions & 1 deletion network/src/legacy/gossip/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,19 @@ pub fn register_validator<C: ChainContext + 'static, S: NetworkSpecialization<Bl
let gossip_side = validator.clone();
let gossip_engine = sc_network_gossip::GossipEngine::new(
service.clone(),
executor,
POLKADOT_ENGINE_ID,
gossip_side,
);

// Ideally this would not be spawned as an orphaned task, but polled by
// `RegisteredMessageValidator` which in turn would be polled by a `ValidationNetwork`.
let spawn_res = executor.spawn_obj(futures::task::FutureObj::from(Box::new(gossip_engine.clone())));

// Note: we consider the chances of an error to spawn a background task almost null.
if spawn_res.is_err() {
log::error!(target: "polkadot-gossip", "Failed to spawn background task");
}

RegisteredMessageValidator {
inner: validator as _,
service: Some(service),
Expand Down
2 changes: 1 addition & 1 deletion parachain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "polkadot-parachain"
version = "0.7.20"
version = "0.7.21"
authors = ["Parity Technologies <[email protected]>"]
description = "Types and utilities for creating and working with parachains"
edition = "2018"
Expand Down
2 changes: 1 addition & 1 deletion primitives/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "polkadot-primitives"
version = "0.7.20"
version = "0.7.21"
authors = ["Parity Technologies <[email protected]>"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion rpc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "polkadot-rpc"
version = "0.7.20"
version = "0.7.21"
authors = ["Parity Technologies <[email protected]>"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "polkadot-runtime-common"
version = "0.7.20"
version = "0.7.21"
authors = ["Parity Technologies <[email protected]>"]
edition = "2018"

Expand Down
6 changes: 3 additions & 3 deletions runtime/common/src/attestations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ decl_module! {
/// Provide candidate receipts for parachains, in ascending order by id.
fn more_attestations(origin, _more: MoreAttestations) -> DispatchResult {
ensure_none(origin)?;
ensure!(!<DidUpdate>::exists(), Error::<T>::TooManyAttestations);
<DidUpdate>::put(true);
ensure!(!DidUpdate::exists(), Error::<T>::TooManyAttestations);
DidUpdate::put(true);

Ok(())
}

fn on_finalize(_n: T::BlockNumber) {
<DidUpdate>::kill();
DidUpdate::kill();
}
}
}
Expand Down
46 changes: 19 additions & 27 deletions runtime/common/src/claims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use rstd::prelude::*;
use sp_io::{hashing::keccak_256, crypto::secp256k1_ecdsa_recover};
use frame_support::{decl_event, decl_storage, decl_module, decl_error, ensure};
use frame_support::{decl_event, decl_storage, decl_module, decl_error};
use frame_support::{dispatch::DispatchResult, weights::SimpleDispatchInfo};
use frame_support::traits::{Currency, Get, VestingSchedule};
use system::{ensure_root, ensure_none};
Expand Down Expand Up @@ -161,31 +161,23 @@ decl_module! {
let balance_due = <Claims<T>>::get(&signer)
.ok_or(Error::<T>::SignerHasNoClaim)?;

let maybe_vested = <Vesting<T>>::get(&signer);

// If this fails, destination account already has a vesting schedule
// applied to it, and this claim should not be processed.
ensure!(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you removed this ensure check, I also believe you now made it possible for someone with a vesting schedule to drop the pot to zero by calling this function over and over.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the logic and added a test which would have failed if this logic didn't exist.

15fe7cc

maybe_vested.is_none() || T::VestingSchedule::vesting_balance(&dest).is_zero(),
Error::<T>::DestinationVesting
);

<Total<T>>::mutate(|t| -> DispatchResult {
*t = t.checked_sub(&balance_due).ok_or(Error::<T>::PotUnderflow)?;
Ok(())
})?;

// Check if this claim should have a vesting schedule.
if let Some(vs) = <Vesting<T>>::get(&signer) {
// If this fails, destination account already has a vesting schedule
// applied to it, and this claim should not be processed.
T::VestingSchedule::add_vesting_schedule(&dest, vs.0, vs.1, vs.2)
.map_err(|_| Error::<T>::DestinationVesting)?;
}

// This must happen before the add_vesting_schedule otherwise the schedule will be
// nullified.
CurrencyOf::<T>::deposit_creating(&dest, balance_due);

// Check if this claim should have a vesting schedule.
if let Some(vs) = maybe_vested {
// Should never fail since we ensured that the destination is not already vesting.
// However, we already deposited, so can't error out here anyway.
let _ = T::VestingSchedule::add_vesting_schedule(&dest, vs.0, vs.1, vs.2);
}

<Claims<T>>::remove(&signer);
<Vesting<T>>::remove(&signer);

Expand Down Expand Up @@ -268,7 +260,7 @@ impl<T: Trait> sp_runtime::traits::ValidateUnsigned for Module<T> {
).into();
};

if !<Claims<T>>::exists(&signer) {
if !<Claims<T>>::contains_key(&signer) {
return Err(InvalidTransaction::Custom(
ValidityError::SignerHasNoClaim.into(),
).into());
Expand Down Expand Up @@ -335,6 +327,9 @@ mod tests {
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
type ModuleToIndex = ();
type AccountData = balances::AccountData<u64>;
type OnNewAccount = ();
type OnReapAccount = Balances;
}

parameter_types! {
Expand All @@ -344,13 +339,10 @@ mod tests {

impl balances::Trait for Test {
type Balance = u64;
type OnReapAccount = System;
type OnNewAccount = ();
type TransferPayment = ();
type DustRemoval = ();
type Event = ();
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type CreationFee = CreationFee;
type AccountStore = System;
}

impl vesting::Trait for Test {
Expand Down Expand Up @@ -431,7 +423,7 @@ mod tests {
#[test]
fn claiming_works() {
new_test_ext().execute_with(|| {
assert_eq!(Balances::free_balance(&42), 0);
assert_eq!(Balances::free_balance(42), 0);
assert_ok!(Claims::claim(Origin::NONE, 42, sig(&alice(), &42u64.encode())));
assert_eq!(Balances::free_balance(&42), 100);
assert_eq!(Vesting::vesting_balance(&42), 50);
Expand All @@ -445,14 +437,14 @@ mod tests {
Claims::mint_claim(Origin::signed(42), eth(&bob()), 200, None),
sp_runtime::traits::BadOrigin,
);
assert_eq!(Balances::free_balance(&42), 0);
assert_eq!(Balances::free_balance(42), 0);
assert_noop!(
Claims::claim(Origin::NONE, 69, sig(&bob(), &69u64.encode())),
Error::<Test>::SignerHasNoClaim
);
assert_ok!(Claims::mint_claim(Origin::ROOT, eth(&bob()), 200, None));
assert_ok!(Claims::claim(Origin::NONE, 69, sig(&bob(), &69u64.encode())));
assert_eq!(Balances::free_balance(69), 200);
assert_eq!(Balances::free_balance(&69), 200);
assert_eq!(Vesting::vesting_balance(&69), 0);
});
}
Expand All @@ -471,7 +463,7 @@ mod tests {
);
assert_ok!(Claims::mint_claim(Origin::ROOT, eth(&bob()), 200, Some((50, 10, 1))));
assert_ok!(Claims::claim(Origin::NONE, 69, sig(&bob(), &69u64.encode())));
assert_eq!(Balances::free_balance(69), 200);
assert_eq!(Balances::free_balance(&69), 200);
assert_eq!(Vesting::vesting_balance(&69), 50);
});
}
Expand Down
11 changes: 5 additions & 6 deletions runtime/common/src/crowdfund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,20 +614,19 @@ mod tests {
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
type ModuleToIndex = ();
type AccountData = balances::AccountData<u64>;
type OnNewAccount = ();
type OnReapAccount = Balances;
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
pub const CreationFee: u64 = 0;
}
impl balances::Trait for Test {
type Balance = u64;
type OnReapAccount = System;
type OnNewAccount = ();
type TransferPayment = ();
type DustRemoval = ();
type Event = ();
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type CreationFee = CreationFee;
type AccountStore = System;
}

parameter_types! {
Expand Down
15 changes: 7 additions & 8 deletions runtime/common/src/parachains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ decl_module! {
Self::update_routing(
&heads,
);

Self::dispatch_upward_messages(
MAX_QUEUE_COUNT,
WATERMARK_QUEUE_SIZE,
Expand Down Expand Up @@ -889,6 +889,9 @@ mod tests {
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
type ModuleToIndex = ();
type AccountData = balances::AccountData<u128>;
type OnNewAccount = ();
type OnReapAccount = ();
}

parameter_types! {
Expand Down Expand Up @@ -945,18 +948,14 @@ mod tests {

parameter_types! {
pub const ExistentialDeposit: Balance = 1;
pub const CreationFee: Balance = 0;
}

impl balances::Trait for Test {
type Balance = Balance;
type OnReapAccount = System;
type OnNewAccount = ();
type Event = ();
type Balance = u128;
type DustRemoval = ();
type Event = ();
type ExistentialDeposit = ExistentialDeposit;
type TransferPayment = ();
type CreationFee = CreationFee;
type AccountStore = System;
}

pallet_staking_reward_curve::build! {
Expand Down
16 changes: 7 additions & 9 deletions runtime/common/src/registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ impl<T: Trait> Registrar<T::AccountId> for Module<T> {
code: Vec<u8>,
initial_head_data: Vec<u8>,
) -> DispatchResult {
ensure!(!Paras::exists(id), Error::<T>::ParaAlreadyExists);

ensure!(!Paras::contains_key(id), Error::<T>::ParaAlreadyExists);
if let Scheduling::Always = info.scheduling {
Parachains::mutate(|parachains|
match parachains.binary_search(&id) {
Expand Down Expand Up @@ -703,22 +702,21 @@ mod tests {
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
type ModuleToIndex = ();
type AccountData = balances::AccountData<u128>;
type OnNewAccount = ();
type OnReapAccount = Balances;
}

parameter_types! {
pub const ExistentialDeposit: Balance = 1;
pub const CreationFee: Balance = 0;
}

impl balances::Trait for Test {
type OnNewAccount = ();
type OnReapAccount = System;
type Balance = Balance;
type Event = ();
type Balance = u128;
type DustRemoval = ();
type Event = ();
type ExistentialDeposit = ExistentialDeposit;
type TransferPayment = ();
type CreationFee = CreationFee;
type AccountStore = System;
}

parameter_types!{
Expand Down
13 changes: 6 additions & 7 deletions runtime/common/src/slots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ decl_storage! {

impl<T: Trait> SwapAux for Module<T> {
fn ensure_can_swap(one: ParaId, other: ParaId) -> Result<(), &'static str> {
if <Onboarding<T>>::exists(one) || <Onboarding<T>>::exists(other) {
if <Onboarding<T>>::contains_key(one) || <Onboarding<T>>::contains_key(other) {
Err("can't swap an undeployed parachain")?
}
Ok(())
Expand Down Expand Up @@ -292,7 +292,7 @@ decl_module! {
// winner information is duplicated from the previous block in case no bids happened
// in this block.
if let Some(offset) = Self::is_ending(now) {
if !<Winning<T>>::exists(&offset) {
if !<Winning<T>>::contains_key(&offset) {
<Winning<T>>::insert(offset,
offset.checked_sub(&One::one())
.and_then(<Winning<T>>::get)
Expand Down Expand Up @@ -915,22 +915,21 @@ mod tests {
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
type ModuleToIndex = ();
type AccountData = balances::AccountData<u64>;
type OnNewAccount = ();
type OnReapAccount = Balances;
}

parameter_types! {
pub const ExistentialDeposit: u64 = 1;
pub const CreationFee: u64 = 0;
}

impl balances::Trait for Test {
type Balance = u64;
type Event = ();
type OnNewAccount = ();
type OnReapAccount = System;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type CreationFee = CreationFee;
type TransferPayment = ();
type AccountStore = System;
}

thread_local! {
Expand Down
Loading