Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
parity
Mirrored projects
polkadot
Commits
1abd7823
Commit
1abd7823
authored
Apr 06, 2020
by
Cecile Tonglet
Browse files
Merge commit
ed2c4cab
(no conflict)
Parent branch: origin/master Forked at:
77de8b91
parents
d41d65b1
ed2c4cab
Changes
51
Expand all
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
1abd7823
...
...
@@ -279,8 +279,6 @@ deploy-polkasync-kusama:
variables
:
POLKADOT_CI_COMMIT_NAME
:
"
${CI_COMMIT_REF_NAME}"
POLKADOT_CI_COMMIT_REF
:
"
${CI_COMMIT_REF}"
only
:
-
ci-testnet-deployment
allow_failure
:
true
trigger
:
"
parity/infrastructure/parity-testnet"
Cargo.lock
View file @
1abd7823
This diff is collapsed.
Click to expand it.
Cargo.toml
View file @
1abd7823
...
...
@@ -38,13 +38,15 @@ members = [
"service"
,
"validation"
,
"test-parachains/adder"
,
"test-parachains/adder/collator"
,
"parachain/test-parachains"
,
"parachain/test-parachains/adder"
,
"parachain/test-parachains/adder/collator"
,
"parachain/test-parachains/code-upgrader"
,
]
exclude
=
[
"runtime/polkadot/wasm"
,
"runtime/kusama/wasm"
,
"test-parachains/adder/wasm"
,
"
parachain/
test-parachains/adder/wasm"
,
]
[badges]
...
...
collator/src/lib.rs
View file @
1abd7823
...
...
@@ -59,7 +59,7 @@ use polkadot_primitives::{
BlockId
,
Hash
,
Block
,
parachain
::{
self
,
BlockData
,
DutyRoster
,
HeadData
,
Id
as
ParaId
,
PoVBlock
,
ValidatorId
,
CollatorPair
,
LocalValidationData
PoVBlock
,
ValidatorId
,
CollatorPair
,
LocalValidationData
,
GlobalValidationSchedule
,
}
};
use
polkadot_cli
::{
...
...
@@ -156,7 +156,8 @@ pub trait ParachainContext: Clone {
fn
produce_candidate
(
&
mut
self
,
relay_parent
:
Hash
,
status
:
LocalValidationData
,
global_validation
:
GlobalValidationSchedule
,
local_validation
:
LocalValidationData
,
)
->
Self
::
ProduceCandidate
;
}
...
...
@@ -164,6 +165,7 @@ pub trait ParachainContext: Clone {
pub
async
fn
collate
<
P
>
(
relay_parent
:
Hash
,
local_id
:
ParaId
,
global_validation
:
GlobalValidationSchedule
,
local_validation_data
:
LocalValidationData
,
mut
para_context
:
P
,
key
:
Arc
<
CollatorPair
>
,
...
...
@@ -175,6 +177,7 @@ pub async fn collate<P>(
{
let
(
block_data
,
head_data
)
=
para_context
.produce_candidate
(
relay_parent
,
global_validation
,
local_validation_data
,
)
.map_err
(
Error
::
Collator
)
.await
?
;
...
...
@@ -283,6 +286,7 @@ fn build_collator_service<S, P, Extrinsic>(
let
work
=
future
::
lazy
(
move
|
_
|
{
let
api
=
client
.runtime_api
();
let
global_validation
=
try_fr!
(
api
.global_validation_schedule
(
&
id
));
let
local_validation
=
match
try_fr!
(
api
.local_validation_data
(
&
id
,
para_id
))
{
Some
(
local_validation
)
=>
local_validation
,
None
=>
return
future
::
Either
::
Left
(
future
::
ok
(())),
...
...
@@ -299,6 +303,7 @@ fn build_collator_service<S, P, Extrinsic>(
let
collation_work
=
collate
(
relay_parent
,
para_id
,
global_validation
,
local_validation
,
parachain_context
,
key
,
...
...
@@ -390,6 +395,7 @@ mod tests {
fn
produce_candidate
(
&
mut
self
,
_relay_parent
:
Hash
,
_global
:
GlobalValidationSchedule
,
_local_validation
:
LocalValidationData
,
)
->
Self
::
ProduceCandidate
{
// send messages right back.
...
...
network/src/protocol/tests.rs
View file @
1abd7823
...
...
@@ -299,6 +299,7 @@ fn consensus_instances_cleaned_up() {
signing_context
,
AvailabilityStore
::
new_in_memory
(
service
.clone
()),
None
,
None
,
));
pool
.spawner
()
.spawn_local
(
worker_task
)
.unwrap
();
...
...
@@ -329,6 +330,7 @@ fn collation_is_received_with_dropped_router() {
signing_context
,
AvailabilityStore
::
new_in_memory
(
service
.clone
()),
None
,
None
,
));
pool
.spawner
()
.spawn_local
(
worker_task
)
.unwrap
();
...
...
@@ -550,6 +552,7 @@ fn fetches_pov_block_from_gossip() {
signing_context
,
AvailabilityStore
::
new_in_memory
(
service
.clone
()),
None
,
None
,
));
let
spawner
=
pool
.spawner
();
...
...
parachain/Cargo.toml
View file @
1abd7823
...
...
@@ -6,31 +6,30 @@ description = "Types and utilities for creating and working with parachains"
edition
=
"2018"
[dependencies]
codec
=
{
package
=
"parity-scale-codec"
,
version
=
"1.3.0"
,
default-features
=
false
,
features
=
[
"derive"
]
}
derive_more
=
{
version
=
"0.99.2"
,
optional
=
true
}
serde
=
{
version
=
"1.0.102"
,
default-features
=
false
,
features
=
[
"derive"
],
optional
=
true
}
# note: special care is taken to avoid inclusion of `sp-io` externals when compiling
# this crate for WASM. This is critical to avoid forcing all parachain WASM into implementing
# various unnecessary Substrate-specific endpoints.
codec
=
{
package
=
"parity-scale-codec"
,
version
=
"1.1.0"
,
default-features
=
false
,
features
=
[
"derive"
]
}
sp-std
=
{
package
=
"sp-std"
,
git
=
"https://github.com/paritytech/substrate"
,
branch
=
"master"
,
default-features
=
false
}
sp-core
=
{
git
=
"https://github.com/paritytech/substrate"
,
branch
=
"master"
,
default-features
=
false
}
sp-runtime-interface
=
{
git
=
"https://github.com/paritytech/substrate"
,
branch
=
"master"
,
default-features
=
false
}
sp-wasm-interface
=
{
git
=
"https://github.com/paritytech/substrate"
,
branch
=
"master"
,
default-features
=
false
}
# all optional crates.
derive_more
=
{
version
=
"0.99.2"
,
optional
=
true
}
serde
=
{
version
=
"1.0.102"
,
default-features
=
false
,
features
=
[
"derive"
],
optional
=
true
}
sp-runtime-interface
=
{
git
=
"https://github.com/paritytech/substrate"
,
branch
=
"master"
,
optional
=
true
,
default-features
=
false
}
sp-externalities
=
{
git
=
"https://github.com/paritytech/substrate"
,
branch
=
"master"
,
optional
=
true
}
sc-executor
=
{
git
=
"https://github.com/paritytech/substrate"
,
branch
=
"master"
,
optional
=
true
}
sp-io
=
{
git
=
"https://github.com/paritytech/substrate"
,
branch
=
"master"
,
optional
=
true
}
lazy_static
=
{
version
=
"1.4.0"
,
optional
=
true
}
parking_lot
=
{
version
=
"0.10.0"
,
optional
=
true
}
log
=
{
version
=
"0.4.8"
,
optional
=
true
}
[target.'cfg(not(target_os
=
"unknown"
))
'.dependencies]
shared_memory
=
{
version
=
"0.10.0"
,
optional
=
true
}
[dev-dependencies]
tiny-keccak
=
"1.5.0"
adder
=
{
path
=
"../test-parachains/adder"
}
halt
=
{
path
=
"../test-parachains/halt"
}
[features]
default
=
["std"]
wasm-api
=
[]
wasm-api
=
[
"sp-runtime-interface"
]
std
=
[
"codec/std"
,
"derive_more"
,
...
...
@@ -38,9 +37,9 @@ std = [
"sp-std/std"
,
"shared_memory"
,
"sp-core/std"
,
"lazy_static"
,
"parking_lot"
,
"log"
,
"sp-runtime-interface"
,
"sp-runtime-interface/std"
,
"sp-externalities"
,
"sc-executor"
,
...
...
parachain/src/lib.rs
View file @
1abd7823
...
...
@@ -45,182 +45,9 @@
#[cfg(feature
=
"std"
)]
pub
mod
wasm_executor
;
pub
mod
primitives
;
mod
wasm_api
;
use
sp_std
::
vec
::
Vec
;
use
codec
::{
Encode
,
Decode
,
CompactAs
};
use
sp_core
::{
RuntimeDebug
,
TypeId
};
#[cfg(all(not(feature
=
"std"
),
feature
=
"wasm-api"
))]
pub
use
wasm_api
::
*
;
/// Validation parameters for evaluating the parachain validity function.
// TODO: balance downloads (https://github.com/paritytech/polkadot/issues/220)
#[derive(PartialEq,
Eq,
Decode)]
#[cfg_attr(feature
=
"std"
,
derive(Debug,
Encode))]
pub
struct
ValidationParams
{
/// The collation body.
pub
block_data
:
Vec
<
u8
>
,
/// Previous head-data.
pub
parent_head
:
Vec
<
u8
>
,
}
/// The result of parachain validation.
// TODO: egress and balance uploads (https://github.com/paritytech/polkadot/issues/220)
#[derive(PartialEq,
Eq,
Encode)]
#[cfg_attr(feature
=
"std"
,
derive(Debug,
Decode))]
pub
struct
ValidationResult
{
/// New head data that should be included in the relay chain state.
pub
head_data
:
Vec
<
u8
>
,
}
/// Unique identifier of a parachain.
#[derive(
Clone,
CompactAs,
Copy,
Decode,
Default,
Encode,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
RuntimeDebug,
)]
#[cfg_attr(feature
=
"std"
,
derive(serde::Serialize,
serde::Deserialize,
derive_more::Display))]
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
From
<
Id
>
for
u32
{
fn
from
(
x
:
Id
)
->
Self
{
x
.0
}
}
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
{
/// Create an `Id`.
pub
const
fn
new
(
id
:
u32
)
->
Self
{
Self
(
id
)
}
/// Returns `true` if this parachain runs with system-level privileges.
pub
fn
is_system
(
&
self
)
->
bool
{
self
.0
<
USER_INDEX_START
}
}
impl
sp_std
::
ops
::
Add
<
u32
>
for
Id
{
type
Output
=
Self
;
fn
add
(
self
,
other
:
u32
)
->
Self
{
Self
(
self
.0
+
other
)
}
}
// TODO: Remove all of this, move sp-runtime::AccountIdConversion to own crate and and use that.
// #360
struct
TrailingZeroInput
<
'a
>
(
&
'a
[
u8
]);
impl
<
'a
>
codec
::
Input
for
TrailingZeroInput
<
'a
>
{
fn
remaining_len
(
&
mut
self
)
->
Result
<
Option
<
usize
>
,
codec
::
Error
>
{
Ok
(
None
)
}
fn
read
(
&
mut
self
,
into
:
&
mut
[
u8
])
->
Result
<
(),
codec
::
Error
>
{
let
len
=
into
.len
()
.min
(
self
.0
.len
());
into
[
..
len
]
.copy_from_slice
(
&
self
.0
[
..
len
]);
for
i
in
&
mut
into
[
len
..
]
{
*
i
=
0
;
}
self
.0
=
&
self
.0
[
len
..
];
Ok
(())
}
}
/// This type can be converted into and possibly from an AccountId (which itself is generic).
pub
trait
AccountIdConversion
<
AccountId
>
:
Sized
{
/// Convert into an account ID. This is infallible.
fn
into_account
(
&
self
)
->
AccountId
;
/// Try to convert an account ID into this type. Might not succeed.
fn
try_from_account
(
a
:
&
AccountId
)
->
Option
<
Self
>
;
}
/// Format is b"para" ++ encode(parachain ID) ++ 00.... where 00... is indefinite trailing
/// zeroes to fill AccountId.
impl
<
T
:
Encode
+
Decode
+
Default
>
AccountIdConversion
<
T
>
for
Id
{
fn
into_account
(
&
self
)
->
T
{
(
b"para"
,
self
)
.using_encoded
(|
b
|
T
::
decode
(
&
mut
TrailingZeroInput
(
b
))
)
.unwrap_or_default
()
}
fn
try_from_account
(
x
:
&
T
)
->
Option
<
Self
>
{
x
.using_encoded
(|
d
|
{
if
&
d
[
0
..
4
]
!=
b"para"
{
return
None
}
let
mut
cursor
=
&
d
[
4
..
];
let
result
=
Decode
::
decode
(
&
mut
cursor
)
.ok
()
?
;
if
cursor
.iter
()
.all
(|
x
|
*
x
==
0
)
{
Some
(
result
)
}
else
{
None
}
})
}
}
/// Which origin a parachain's message to the relay chain should be dispatched from.
#[derive(Clone,
PartialEq,
Eq,
Encode,
Decode)]
#[cfg_attr(feature
=
"std"
,
derive(Debug))]
#[repr(u8)]
pub
enum
ParachainDispatchOrigin
{
/// As a simple `Origin::Signed`, using `ParaId::account_id` as its value. This is good when
/// interacting with standard modules such as `balances`.
Signed
,
/// 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
sp_std
::
convert
::
TryFrom
<
u8
>
for
ParachainDispatchOrigin
{
type
Error
=
();
fn
try_from
(
x
:
u8
)
->
core
::
result
::
Result
<
ParachainDispatchOrigin
,
()
>
{
const
SIGNED
:
u8
=
ParachainDispatchOrigin
::
Signed
as
u8
;
const
PARACHAIN
:
u8
=
ParachainDispatchOrigin
::
Parachain
as
u8
;
Ok
(
match
x
{
SIGNED
=>
ParachainDispatchOrigin
::
Signed
,
PARACHAIN
=>
ParachainDispatchOrigin
::
Parachain
,
_
=>
return
Err
(()),
})
}
}
/// A message from a parachain to its Relay Chain.
#[derive(Clone,
PartialEq,
Eq,
Encode,
Decode,
sp_runtime_interface::pass_by::PassByCodec)]
#[cfg_attr(feature
=
"std"
,
derive(Debug))]
pub
struct
UpwardMessage
{
/// The origin for the message to be sent from.
pub
origin
:
ParachainDispatchOrigin
,
/// The message data.
pub
data
:
Vec
<
u8
>
,
}
/// An incoming message.
#[derive(PartialEq,
Eq,
Decode)]
#[cfg_attr(feature
=
"std"
,
derive(Debug,
Encode))]
pub
struct
IncomingMessage
{
/// The source parachain.
pub
source
:
Id
,
/// The data of the message.
pub
data
:
Vec
<
u8
>
,
}
parachain/src/primitives.rs
0 → 100644
View file @
1abd7823
// Copyright 2020 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//! Primitive types which are strictly necessary from a parachain-execution point
//! of view.
use
sp_std
::
vec
::
Vec
;
use
codec
::{
Encode
,
Decode
,
CompactAs
};
use
sp_core
::{
RuntimeDebug
,
TypeId
};
#[cfg(feature
=
"std"
)]
use
serde
::{
Serialize
,
Deserialize
};
#[cfg(feature
=
"std"
)]
use
sp_core
::
bytes
;
/// The block number of the relay chain.
/// 32-bits will allow for 136 years of blocks assuming 1 block per second.
pub
type
RelayChainBlockNumber
=
u32
;
/// Parachain head data included in the chain.
#[derive(PartialEq,
Eq,
Clone,
PartialOrd,
Ord,
Encode,
Decode)]
#[cfg_attr(feature
=
"std"
,
derive(Serialize,
Deserialize,
Debug,
Default))]
pub
struct
HeadData
(
#[cfg_attr(feature
=
"std"
,
serde(with=
"bytes"
))]
pub
Vec
<
u8
>
);
/// Parachain validation code.
#[derive(Default,
PartialEq,
Eq,
Clone,
Encode,
Decode)]
#[cfg_attr(feature
=
"std"
,
derive(Serialize,
Deserialize,
Debug))]
pub
struct
ValidationCode
(
#[cfg_attr(feature
=
"std"
,
serde(with=
"bytes"
))]
pub
Vec
<
u8
>
);
/// Parachain block data.
///
/// Contains everything required to validate para-block, may contain block and witness data.
#[derive(PartialEq,
Eq,
Clone,
Encode,
Decode)]
#[cfg_attr(feature
=
"std"
,
derive(Serialize,
Deserialize,
Debug))]
pub
struct
BlockData
(
#[cfg_attr(feature
=
"std"
,
serde(with=
"bytes"
))]
pub
Vec
<
u8
>
);
/// Unique identifier of a parachain.
#[derive(
Clone,
CompactAs,
Copy,
Decode,
Default,
Encode,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
RuntimeDebug,
)]
#[cfg_attr(feature
=
"std"
,
derive(serde::Serialize,
serde::Deserialize,
derive_more::Display))]
pub
struct
Id
(
u32
);
impl
TypeId
for
Id
{
const
TYPE_ID
:
[
u8
;
4
]
=
*
b"para"
;
}
impl
From
<
Id
>
for
u32
{
fn
from
(
x
:
Id
)
->
Self
{
x
.0
}
}
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
{
/// Create an `Id`.
pub
const
fn
new
(
id
:
u32
)
->
Self
{
Self
(
id
)
}
/// Returns `true` if this parachain runs with system-level privileges.
pub
fn
is_system
(
&
self
)
->
bool
{
self
.0
<
USER_INDEX_START
}
}
impl
sp_std
::
ops
::
Add
<
u32
>
for
Id
{
type
Output
=
Self
;
fn
add
(
self
,
other
:
u32
)
->
Self
{
Self
(
self
.0
+
other
)
}
}
/// This type can be converted into and possibly from an AccountId (which itself is generic).
pub
trait
AccountIdConversion
<
AccountId
>
:
Sized
{
/// Convert into an account ID. This is infallible.
fn
into_account
(
&
self
)
->
AccountId
;
/// Try to convert an account ID into this type. Might not succeed.
fn
try_from_account
(
a
:
&
AccountId
)
->
Option
<
Self
>
;
}
// TODO: Remove all of this, move sp-runtime::AccountIdConversion to own crate and and use that.
// #360
struct
TrailingZeroInput
<
'a
>
(
&
'a
[
u8
]);
impl
<
'a
>
codec
::
Input
for
TrailingZeroInput
<
'a
>
{
fn
remaining_len
(
&
mut
self
)
->
Result
<
Option
<
usize
>
,
codec
::
Error
>
{
Ok
(
None
)
}
fn
read
(
&
mut
self
,
into
:
&
mut
[
u8
])
->
Result
<
(),
codec
::
Error
>
{
let
len
=
into
.len
()
.min
(
self
.0
.len
());
into
[
..
len
]
.copy_from_slice
(
&
self
.0
[
..
len
]);
for
i
in
&
mut
into
[
len
..
]
{
*
i
=
0
;
}
self
.0
=
&
self
.0
[
len
..
];
Ok
(())
}
}
/// Format is b"para" ++ encode(parachain ID) ++ 00.... where 00... is indefinite trailing
/// zeroes to fill AccountId.
impl
<
T
:
Encode
+
Decode
+
Default
>
AccountIdConversion
<
T
>
for
Id
{
fn
into_account
(
&
self
)
->
T
{
(
b"para"
,
self
)
.using_encoded
(|
b
|
T
::
decode
(
&
mut
TrailingZeroInput
(
b
))
)
.unwrap_or_default
()
}
fn
try_from_account
(
x
:
&
T
)
->
Option
<
Self
>
{
x
.using_encoded
(|
d
|
{
if
&
d
[
0
..
4
]
!=
b"para"
{
return
None
}
let
mut
cursor
=
&
d
[
4
..
];
let
result
=
Decode
::
decode
(
&
mut
cursor
)
.ok
()
?
;
if
cursor
.iter
()
.all
(|
x
|
*
x
==
0
)
{
Some
(
result
)
}
else
{
None
}
})
}
}
/// Which origin a parachain's message to the relay chain should be dispatched from.
#[derive(Clone,
PartialEq,
Eq,
Encode,
Decode)]
#[cfg_attr(feature
=
"std"
,
derive(Debug))]
#[repr(u8)]
pub
enum
ParachainDispatchOrigin
{
/// As a simple `Origin::Signed`, using `ParaId::account_id` as its value. This is good when
/// interacting with standard modules such as `balances`.
Signed
,
/// 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
sp_std
::
convert
::
TryFrom
<
u8
>
for
ParachainDispatchOrigin
{
type
Error
=
();
fn
try_from
(
x
:
u8
)
->
core
::
result
::
Result
<
ParachainDispatchOrigin
,
()
>
{
const
SIGNED
:
u8
=
ParachainDispatchOrigin
::
Signed
as
u8
;
const
PARACHAIN
:
u8
=
ParachainDispatchOrigin
::
Parachain
as
u8
;
Ok
(
match
x
{
SIGNED
=>
ParachainDispatchOrigin
::
Signed
,
PARACHAIN
=>
ParachainDispatchOrigin
::
Parachain
,
_
=>
return
Err
(()),
})
}
}
/// A message from a parachain to its Relay Chain.
#[derive(Clone,
PartialEq,
Eq,
Encode,
Decode)]
#[cfg_attr(
any(feature
=
"std"
,
feature
=
"wasm-api"
),
derive(sp_runtime_interface::pass_by::PassByCodec,
))]
#[cfg_attr(feature
=
"std"
,
derive(Debug))]
pub
struct
UpwardMessage
{
/// The origin for the message to be sent from.
pub
origin
:
ParachainDispatchOrigin
,
/// The message data.
pub
data
:
Vec
<
u8
>
,
}
/// Validation parameters for evaluating the parachain validity function.
// TODO: balance downloads (https://github.com/paritytech/polkadot/issues/220)
#[derive(PartialEq,
Eq,
Decode)]
#[cfg_attr(feature
=
"std"
,
derive(Debug,
Encode))]
pub
struct
ValidationParams
{
/// The collation body.
pub
block_data
:
BlockData
,
/// Previous head-data.
pub
parent_head
:
HeadData
,
/// The maximum code size permitted, in bytes.
pub
max_code_size
:
u32
,
/// The maximum head-data size permitted, in bytes.
pub
max_head_data_size
:
u32
,
/// The current relay-chain block number.
pub
relay_chain_height
:
RelayChainBlockNumber
,
/// Whether a code upgrade is allowed or not, and at which height the upgrade
/// would be applied after, if so. The parachain logic should apply any upgrade
/// issued in this block after the first block
/// with `relay_chain_height` at least this value, if `Some`. if `None`, issue
/// no upgrade.
pub
code_upgrade_allowed
:
Option
<
RelayChainBlockNumber
>
,
}
/// The result of parachain validation.
// TODO: egress and balance uploads (https://github.com/paritytech/polkadot/issues/220)
#[derive(PartialEq,
Eq,
Encode)]
#[cfg_attr(feature
=
"std"
,
derive(Debug,
Decode))]
pub
struct
ValidationResult
{
/// New head data that should be included in the relay chain state.
pub
head_data
:
HeadData
,
/// An update to the validation code that should be scheduled in the relay chain.
pub
new_validation_code
:
Option
<
ValidationCode
>
,
}
parachain/src/wasm_api.rs
View file @
1abd7823
...
...
@@ -16,7 +16,9 @@
//! Utilities for writing parachain WASM.
use
crate
::
UpwardMessage
;
#[cfg(any(feature
=
"std"
,
all(not(feature
=
"std"
),
feature
=
"wasm-api"
)))]
use
crate
::
primitives
::
UpwardMessage
;
#[cfg(any(feature
=
"std"
,
all(not(feature
=
"std"
),
feature
=
"wasm-api"
)))]
use
sp_runtime_interface
::
runtime_interface
;
#[cfg(feature
=
"std"
)]
use
sp_externalities
::
ExternalitiesExt
;
...
...
@@ -42,7 +44,9 @@ pub trait Parachain {
/// Offset and length must have been provided by the validation
/// function's entry point.
#[cfg(not(feature
=
"std"
))]
pub
unsafe
fn
load_params
(
params
:
*
const
u8
,
len
:
usize
)
->
crate
::
ValidationParams
{
pub
unsafe
fn
load_params
(
params
:
*
const
u8
,
len
:
usize
)
->
crate
::
primitives
::
ValidationParams
{
let
mut
slice
=
sp_std
::
slice
::
from_raw_parts
(
params
,
len
);
codec
::
Decode
::
decode
(
&
mut
slice
)
.expect
(
"Invalid input data"
)
...
...
@@ -53,6 +57,6 @@ pub unsafe fn load_params(params: *const u8, len: usize) -> crate::ValidationPar
/// As described in the crate docs, this is a pointer to the appended length
/// of the vector.
#[cfg(not(feature
=
"std"
))]
pub
fn
write_result
(
result
:
&
crate
::
ValidationResult
)
->
u64
{
pub
fn
write_result
(
result
:
&
crate
::
primitives
::
ValidationResult
)
->
u64
{
sp_core
::
to_substrate_wasm_fn_return_value
(
&
result
)
}
parachain/src/wasm_executor/mod.rs
View file @
1abd7823
...
...
@@ -21,14 +21,14 @@
//! a WASM VM for re-execution of a parachain candidate.
use
std
::
any
::{
TypeId
,
Any
};
use
crate
::{
ValidationParams
,
ValidationResult
,
UpwardMessage
};
use
crate
::
primitives
::
{
ValidationParams
,
ValidationResult
,
UpwardMessage
};
use
codec
::{
Decode
,
Encode
};
use
sp_core
::
storage
::{
ChildStorageKey
,
ChildInfo
};
use
sp_core
::
traits
::
CallInWasm
;
use
sp_wasm_interface
::
HostFunctions
as
_
;
#[cfg(not(target_os
=
"unknown"
))]
pub
use
validation_host
::{
run_worker
,
EXECUTION_TIMEOUT_SEC
};
pub
use
validation_host
::{
run_worker
,
ValidationPool
,
EXECUTION_TIMEOUT_SEC
};