Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
7fda870
Rest of parathread draft implementation, parachain permissioning.
gavofyork Jul 26, 2019
c399cfa
Update Substrate
bkchr Jul 25, 2019
e81963f
Update Substrate again
bkchr Jul 25, 2019
37e667e
Integrate weight/fee stuff.
kianenigma Jul 25, 2019
0e3fa8d
Council
gavofyork Jul 26, 2019
32d7d7a
Build fixes
gavofyork Jul 26, 2019
b0922e7
More fixes
gavofyork Jul 26, 2019
efc6c27
Minor additions
gavofyork Jul 27, 2019
5e2478b
Merge remote-tracking branch 'origin/master' into gav-parathreads
gavofyork Jul 27, 2019
4fb52c8
fix some small errors
4meta5 Aug 2, 2019
baa3951
Merge remote-tracking branch 'origin/gav-parathreads' into gav-parath…
gavofyork Aug 5, 2019
cc53ff8
Revert "fix some small errors"
shawntabrizi Aug 6, 2019
7171106
Merge branch 'gav-parathreads' of github.com:paritytech/polkadot into…
gavofyork Aug 6, 2019
f93597b
Merge fix.
gavofyork Aug 6, 2019
da82e97
do_swap -> on_swap
shawntabrizi Aug 7, 2019
decd15a
Update depdendency to polkadot-master
shawntabrizi Aug 14, 2019
1a354e7
Merge remote-tracking branch 'upstream/master' into gav-parathreads
shawntabrizi Aug 14, 2019
03e2131
Fix more merge problems
shawntabrizi Aug 14, 2019
3d1c74c
Some patching of errors
shawntabrizi Aug 14, 2019
e4ea710
Fix storage closure
shawntabrizi Aug 14, 2019
496d7bd
Actually fix storage. It builds!
shawntabrizi Aug 14, 2019
58b003f
Tests run... but not successfully.
shawntabrizi Aug 14, 2019
1339268
Add `run_to_block` to get parachains active to start
shawntabrizi Aug 14, 2019
08db18d
More `run_to_block`
shawntabrizi Aug 14, 2019
0ee5826
Merge remote-tracking branch 'origin/master' into gav-parathreads
gavofyork Sep 19, 2019
22a9549
Fix build
shawntabrizi Sep 19, 2019
446567a
Queue up changes to threads
gavofyork Sep 19, 2019
061fffe
Merge branch 'gav-parathreads' of github.com:paritytech/polkadot into…
gavofyork Sep 19, 2019
5a2b2bb
Move registration test
shawntabrizi Sep 22, 2019
1f7578e
Fix regsiter/deregister test
shawntabrizi Sep 22, 2019
04d3d12
Retry queue.
gavofyork Sep 23, 2019
8330c6d
Minor refactor
gavofyork Sep 23, 2019
28a9c49
Refactor to avoid heavy storage items
gavofyork Sep 23, 2019
511603b
Make tests pass
gavofyork Sep 23, 2019
22bf8db
Merge branch 'gav-parathreads' of github.com:paritytech/polkadot into…
gavofyork Sep 23, 2019
1b40ff0
remove para on deregister, add events
shawntabrizi Sep 23, 2019
ef37e6f
Merge branch 'gav-parathreads' of https://github.com/paritytech/polka…
shawntabrizi Sep 23, 2019
1b60c7b
Remove println
shawntabrizi Sep 23, 2019
d6a1b3e
Fix register/deregister parathread test
shawntabrizi Sep 23, 2019
981e605
Merge remote-tracking branch 'upstream/master' into gav-parathreads
shawntabrizi Sep 23, 2019
6abbb87
fix merge
shawntabrizi Sep 23, 2019
c1bee54
Parathread can be activated test
shawntabrizi Sep 24, 2019
3271c18
Test auction
shawntabrizi Sep 25, 2019
e4a24fa
Add `Debtors` storage item
shawntabrizi Sep 25, 2019
de62f9b
remove comment code
shawntabrizi Sep 25, 2019
e14f075
Some new tests
gavofyork Sep 26, 2019
2ac5e7e
Merge branch 'gav-parathreads' of github.com:paritytech/polkadot into…
gavofyork Sep 27, 2019
f447939
Fixes for removing threads when scheduled. Tests.
gavofyork Sep 28, 2019
9359583
Test progression of threads.
gavofyork Sep 28, 2019
26ed62f
Test that reschedule queuing works properly.
gavofyork Sep 28, 2019
32aa11d
Make test slightly more interesting
gavofyork Sep 28, 2019
ae15e48
whitespace
gavofyork Sep 28, 2019
970ea10
Swap works properly.
gavofyork Sep 29, 2019
2cbe8b8
Update locks
gavofyork Oct 3, 2019
113c1da
Merge remote-tracking branch 'origin/master' into gav-parathreads
gavofyork Oct 3, 2019
f743564
Build
gavofyork Oct 3, 2019
09bdb4d
Rename can_swap
gavofyork Oct 3, 2019
53a837b
Add test for funds to be correctly returned after a swap
shawntabrizi Oct 6, 2019
9039fd9
Make tests consistant
shawntabrizi Oct 6, 2019
c135f47
Add check that `PendingSwap` is cleaned up
shawntabrizi Oct 6, 2019
4a7313f
Update runtime/src/parachains.rs
gavofyork Oct 9, 2019
e6f068a
Update runtime/src/registrar.rs
gavofyork Oct 9, 2019
dc18ed8
Some fixes/suggestions from review
gavofyork Oct 9, 2019
a9006ea
Docs
gavofyork Oct 9, 2019
2697d25
Apply suggestions from code review
gavofyork Oct 9, 2019
564200c
Merge branch 'gav-parathreads' of github.com:paritytech/polkadot into…
gavofyork Oct 9, 2019
c075d8a
Update network/src/gossip.rs
gavofyork Oct 9, 2019
8babd8b
Rename OnSwap
gavofyork Oct 9, 2019
df87f54
Merge remote-tracking branch 'origin/master' into gav-parathreads
gavofyork Oct 9, 2019
3a1fae6
Add missing `]`
shawntabrizi Oct 9, 2019
78d6b53
Rejig ordering semantics, making everything a bit slower but correct.
gavofyork Oct 10, 2019
a02828e
Merge remote-tracking branch 'origin/gav-parathreads' into gav-parath…
gavofyork Oct 10, 2019
dcf569a
Some Fixes to Parathread Compile (#470)
shawntabrizi Oct 10, 2019
2d864a8
Build fixes
gavofyork Oct 10, 2019
f7bb4e5
Merge remote-tracking branch 'origin/master' into gav-parathreads
gavofyork Oct 10, 2019
1b6855e
Fix tests
gavofyork Oct 11, 2019
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: 2 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion network/src/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ impl<F, P> ChainContext for (F, P) where
let leaf_id = BlockId::Hash(leaf);
let active_parachains = api.active_parachains(&leaf_id)?;

for para_id in active_parachains {
// TODO: https://github.com/paritytech/polkadot/issues/467
for (para_id, _) in active_parachains {
if let Some(ingress) = api.ingress(&leaf_id, para_id, None)? {
for (_height, _from, queue_root) in ingress.iter() {
with_queue_root(queue_root);
Expand Down
6 changes: 3 additions & 3 deletions network/src/tests/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use polkadot_primitives::{Block, BlockNumber, Hash, Header, BlockId};
use polkadot_primitives::parachain::{
Id as ParaId, Chain, DutyRoster, ParachainHost, TargetedMessage,
ValidatorId, StructuredUnroutedIngress, BlockIngressRoots, Status,
FeeSchedule, HeadData,
FeeSchedule, HeadData, Retriable, CollatorId
};
use parking_lot::Mutex;
use substrate_client::error::Result as ClientResult;
Expand Down Expand Up @@ -177,7 +177,7 @@ impl NetworkService for TestNetwork {
struct ApiData {
validators: Vec<ValidatorId>,
duties: Vec<Chain>,
active_parachains: Vec<ParaId>,
active_parachains: Vec<(ParaId, Option<(CollatorId, Retriable)>)>,
ingress: HashMap<ParaId, StructuredUnroutedIngress>,
}

Expand Down Expand Up @@ -279,7 +279,7 @@ impl ParachainHost<Block> for RuntimeApi {
_: ExecutionContext,
_: Option<()>,
_: Vec<u8>,
) -> ClientResult<NativeOrEncoded<Vec<ParaId>>> {
) -> ClientResult<NativeOrEncoded<Vec<(ParaId, Option<(CollatorId, Retriable)>)>>> {
Ok(NativeOrEncoded::Native(self.data.lock().active_parachains.clone()))
}

Expand Down
2 changes: 2 additions & 0 deletions parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ wasmi = { version = "0.4.3", optional = true }
derive_more = { version = "0.14", optional = true }
serde = { version = "1.0", default-features = false, features = [ "derive" ] }
rstd = { package = "sr-std", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
lazy_static = { version = "1.3.0", optional = true }
parking_lot = { version = "0.7.1", optional = true }
log = { version = "0.4.6", optional = true }
Expand All @@ -33,6 +34,7 @@ std = [
"serde/std",
"rstd/std",
"shared_memory",
"substrate-primitives/std",
"lazy_static",
"parking_lot",
"log"
Expand Down
22 changes: 22 additions & 0 deletions parachain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub mod wasm_api;
use rstd::vec::Vec;

use codec::{Encode, Decode};
use substrate_primitives::TypeId;

/// Validation parameters for evaluating the parachain validity function.
// TODO: balance downloads (https://github.com/paritytech/polkadot/issues/220)
Expand Down Expand Up @@ -82,6 +83,16 @@ pub struct ValidationResult {
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize, Debug))]
pub struct Id(u32);

impl TypeId for Id {
const TYPE_ID: [u8; 4] = *b"para";
}

/// Type for determining the active set of parachains.
pub trait ActiveThreads {
/// Return the current ordered set of `Id`s of active parathreads.
fn active_threads() -> Vec<Id>;
}

impl codec::CompactAs for Id {
type As = u32;
fn encode_as(&self) -> &u32 {
Expand All @@ -105,11 +116,19 @@ impl From<u32> for Id {
fn from(x: u32) -> Self { Id(x) }
}

const USER_INDEX_START: u32 = 1000;

/// The ID of the first user (non-system) parachain.
pub const LOWEST_USER_ID: Id = Id(USER_INDEX_START);

impl Id {
/// Convert this Id into its inner representation.
pub fn into_inner(self) -> u32 {
self.0
}

/// Returns `true` if this parachain runs with system-level privileges.
pub fn is_system(&self) -> bool { self.0 < USER_INDEX_START }
}

// TODO: Remove all of this, move sr-primitives::AccountIdConversion to own crate and and use that.
Expand Down Expand Up @@ -191,6 +210,9 @@ pub enum ParachainDispatchOrigin {
/// As the special `Origin::Parachain(ParaId)`. This is good when interacting with parachain-
/// aware modules which need to succinctly verify that the origin is a parachain.
Parachain,
/// As the simple, superuser `Origin::Root`. This can only be done on specially permissioned
/// parachains.
Root,
}

impl rstd::convert::TryFrom<u8> for ParachainDispatchOrigin {
Expand Down
65 changes: 63 additions & 2 deletions primitives/src/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use primitives::bytes;
use application_crypto::KeyTypeId;

pub use polkadot_parachain::{
Id, AccountIdConversion, ParachainDispatchOrigin, UpwardMessage,
Id, ParachainDispatchOrigin, LOWEST_USER_ID, UpwardMessage,
};

/// The key type ID for a collator key.
Expand Down Expand Up @@ -78,6 +78,67 @@ pub type ValidatorPair = validator_app::Pair;
/// so we define it to be the same type as `SessionKey`. In the future it may have different crypto.
pub type ValidatorSignature = validator_app::Signature;

/// Retriability for a given active para.
#[derive(Clone, Eq, PartialEq, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Debug))]
pub enum Retriable {
/// Ineligible for retry. This means it's either a parachain which is always scheduled anyway or
/// has been removed/swapped.
Never,
/// Eligible for retry; the associated value is the number of retries that the para already had.
WithRetries(u32),
}

/// Type determining the active set of parachains in current block.
pub trait ActiveParas {
/// Return the active set of parachains in current block. This attempts to keep any IDs in the
/// same place between sequential blocks. It is therefore unordered. The second item in the
/// tuple is the required collator ID, if any. If `Some`, then it is invalid to include any
/// other collator's block.
///
/// NOTE: The initial implementation simply concatenates the (ordered) set of (permanent)
/// parachain IDs with the (unordered) set of parathread IDs selected for this block.
fn active_paras() -> Vec<(Id, Option<(CollatorId, Retriable)>)>;
}

/// Description of how often/when this parachain is scheduled for progression.
#[derive(Encode, Decode, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug))]
pub enum Scheduling {
/// Scheduled every block.
Always,
/// Scheduled dynamically (i.e. a parathread).
Dynamic,
}

/// Information regarding a deployed parachain/thread.
#[derive(Encode, Decode, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct Info {
/// Scheduling info.
pub scheduling: Scheduling,
}

/// An `Info` value for a standard leased parachain.
pub const PARACHAIN_INFO: Info = Info {
scheduling: Scheduling::Always,
};

/// Auxilliary for when there's an attempt to swapped two parachains/parathreads.
pub trait SwapAux {
/// Result describing whether it is possible to swap two parachains. Doesn't mutate state.
fn ensure_can_swap(one: Id, other: Id) -> Result<(), &'static str>;

/// Updates any needed state/references to enact a logical swap of two parachains. Identity,
/// code and head_data remain equivalent for all parachains/threads, however other properties
/// such as leases, deposits held and thread/chain nature are swapped.
///
/// May only be called on a state that `ensure_can_swap` has previously returned `Ok` for: if this is
/// not the case, the result is undefined. May only return an error if `ensure_can_swap` also returns
/// an error.
fn on_swap(one: Id, other: Id) -> Result<(), &'static str>;
}

/// Identifier for a chain, either one of a number of parachains or the relay chain.
#[derive(Copy, Clone, PartialEq, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Debug))]
Expand Down Expand Up @@ -432,7 +493,7 @@ substrate_client::decl_runtime_apis! {
/// Get the current duty roster.
fn duty_roster() -> DutyRoster;
/// Get the currently active parachains.
fn active_parachains() -> Vec<Id>;
fn active_parachains() -> Vec<(Id, Option<(CollatorId, Retriable)>)>;
/// Get the given parachain's status.
fn parachain_status(id: Id) -> Option<Status>;
/// Get the given parachain's head code blob.
Expand Down
2 changes: 2 additions & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ timestamp = { package = "srml-timestamp", git = "https://github.com/paritytech/s
treasury = { package = "srml-treasury", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }

primitives = { package = "polkadot-primitives", path = "../primitives", default-features = false }
polkadot-parachain = { path = "../parachain", default-features = false }

[dev-dependencies]
hex-literal = "0.2.0"
Expand All @@ -79,6 +80,7 @@ std = [
"codec/std",
"inherents/std",
"substrate-primitives/std",
"polkadot-parachain/std",
"client/std",
"offchain-primitives/std",
"rstd/std",
Expand Down
32 changes: 17 additions & 15 deletions runtime/src/crowdfund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,16 @@ use sr_primitives::{ModuleId, weights::SimpleDispatchInfo,
use crate::slots;
use codec::{Encode, Decode};
use rstd::vec::Vec;
use crate::parachains::ParachainRegistrar;
use substrate_primitives::storage::well_known_keys::CHILD_STORAGE_KEY_PREFIX;
use primitives::parachain::Id as ParaId;

const MODULE_ID: ModuleId = ModuleId(*b"py/cfund");

pub type BalanceOf<T> = <<T as slots::Trait>::Currency as Currency<<T as system::Trait>::AccountId>>::Balance;
pub type NegativeImbalanceOf<T> = <<T as slots::Trait>::Currency as Currency<<T as system::Trait>::AccountId>>::NegativeImbalance;
pub type ParaIdOf<T> = <<T as slots::Trait>::Parachains as ParachainRegistrar<<T as system::Trait>::AccountId>>::ParaId;
pub type BalanceOf<T> =
<<T as slots::Trait>::Currency as Currency<<T as system::Trait>::AccountId>>::Balance;
#[allow(dead_code)]
pub type NegativeImbalanceOf<T> =
<<T as slots::Trait>::Currency as Currency<<T as system::Trait>::AccountId>>::NegativeImbalance;

pub trait Trait: slots::Trait {
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
Expand Down Expand Up @@ -117,7 +119,7 @@ pub enum LastContribution<BlockNumber> {

#[derive(Encode, Decode, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct FundInfo<AccountId, Balance, Hash, BlockNumber, ParaId> {
pub struct FundInfo<AccountId, Balance, Hash, BlockNumber> {
/// The parachain that this fund has funded, if there is one. As long as this is `Some`, then
/// the funds may not be withdrawn and the fund cannot be dissolved.
parachain: Option<ParaId>,
Expand Down Expand Up @@ -154,7 +156,7 @@ decl_storage! {
trait Store for Module<T: Trait> as Example {
/// Info on all of the funds.
Funds get(funds):
map FundIndex => Option<FundInfo<T::AccountId, BalanceOf<T>, T::Hash, T::BlockNumber, ParaIdOf<T>>>;
map FundIndex => Option<FundInfo<T::AccountId, BalanceOf<T>, T::Hash, T::BlockNumber>>;

/// The total number of funds that have so far been allocated.
FundCount get(fund_count): FundIndex;
Expand All @@ -172,7 +174,6 @@ decl_event! {
pub enum Event<T> where
<T as system::Trait>::AccountId,
Balance = BalanceOf<T>,
ParaId = ParaIdOf<T>,
{
Created(FundIndex),
Contributed(AccountId, FundIndex, Balance),
Expand Down Expand Up @@ -321,7 +322,7 @@ decl_module! {
/// - `para_id` is the parachain index that this fund won.
fn onboard(origin,
#[compact] index: FundIndex,
#[compact] para_id: ParaIdOf<T>
#[compact] para_id: ParaId
) {
let _ = ensure_signed(origin)?;

Expand Down Expand Up @@ -503,13 +504,14 @@ mod tests {
use srml_support::{impl_outer_origin, assert_ok, assert_noop, parameter_types};
use sr_io::with_externalities;
use substrate_primitives::{H256, Blake2Hasher};
use primitives::parachain::Id as ParaId;
use primitives::parachain::Info as ParaInfo;
// The testing primitives are very useful for avoiding having to work with signatures
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are requried.
use sr_primitives::{
Perbill, Permill, testing::Header,
traits::{BlakeTwo256, OnInitialize, OnFinalize, IdentityLookup, ConvertInto},
};
use crate::registrar::Registrar;

impl_outer_origin! {
pub enum Origin for Test {}
Expand Down Expand Up @@ -595,16 +597,16 @@ mod tests {
}

pub struct TestParachains;
impl ParachainRegistrar<u64> for TestParachains {
type ParaId = ParaId;
fn new_id() -> Self::ParaId {
impl Registrar<u64> for TestParachains {
fn new_id() -> ParaId {
PARACHAIN_COUNT.with(|p| {
*p.borrow_mut() += 1;
(*p.borrow() - 1).into()
})
}
fn register_parachain(
id: Self::ParaId,
fn register_para(
id: ParaId,
_info: ParaInfo,
code: Vec<u8>,
initial_head_data: Vec<u8>
) -> Result<(), &'static str> {
Expand All @@ -616,7 +618,7 @@ mod tests {
Ok(())
})
}
fn deregister_parachain(id: Self::ParaId) -> Result<(), &'static str> {
fn deregister_para(id: ParaId) -> Result<(), &'static str> {
PARACHAINS.with(|p| {
if !p.borrow().contains_key(&id.into_inner()) {
panic!("ID doesn't exist")
Expand Down
Loading