mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 08:11:03 +00:00
Implement basic upward & downward messages (#118)
* Start by replacing branch names and set `DownwardMessage` * Add the upward-message crate * Add Kusama & Polkadot * More work on getting the upward messages working * Fix build * Begin to integrate it into the test Parachain * Update * Make everything compile again * Switch to westend and print parachain account on startup * Use MultiSignature etc * Fix validate block * Some downward messages work * Update git reference * More downward messages integration * Update test runtime for downward messages * Enable downward message handler and withdraw send tokens * Add some docs * Begin to implement simple XCMP * More work * Fixes and make parachain id configurable * Make parachain ID be part of the genesis * Finishing the XCMP message demo * Update and fixes tests * Update branch
This commit is contained in:
Generated
+53
-20
@@ -864,10 +864,14 @@ name = "cumulus-message-broker"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cumulus-primitives",
|
"cumulus-primitives",
|
||||||
|
"cumulus-upward-message",
|
||||||
"frame-support",
|
"frame-support",
|
||||||
"frame-system",
|
"frame-system",
|
||||||
"parity-scale-codec",
|
"parity-scale-codec",
|
||||||
"sp-inherents",
|
"sp-inherents",
|
||||||
|
"sp-io",
|
||||||
|
"sp-runtime",
|
||||||
|
"sp-std",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -923,6 +927,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"impl-trait-for-tuples",
|
"impl-trait-for-tuples",
|
||||||
"parity-scale-codec",
|
"parity-scale-codec",
|
||||||
|
"polkadot-core-primitives",
|
||||||
"polkadot-parachain",
|
"polkadot-parachain",
|
||||||
"polkadot-primitives",
|
"polkadot-primitives",
|
||||||
"sp-inherents",
|
"sp-inherents",
|
||||||
@@ -947,7 +952,6 @@ dependencies = [
|
|||||||
"sp-blockchain",
|
"sp-blockchain",
|
||||||
"sp-consensus",
|
"sp-consensus",
|
||||||
"sp-core",
|
"sp-core",
|
||||||
"sp-inherents",
|
|
||||||
"sp-io",
|
"sp-io",
|
||||||
"sp-keyring",
|
"sp-keyring",
|
||||||
"sp-runtime",
|
"sp-runtime",
|
||||||
@@ -981,6 +985,7 @@ dependencies = [
|
|||||||
"cumulus-collator",
|
"cumulus-collator",
|
||||||
"cumulus-consensus",
|
"cumulus-consensus",
|
||||||
"cumulus-network",
|
"cumulus-network",
|
||||||
|
"cumulus-primitives",
|
||||||
"cumulus-test-parachain-runtime",
|
"cumulus-test-parachain-runtime",
|
||||||
"derive_more 0.15.0",
|
"derive_more 0.15.0",
|
||||||
"exit-future 0.1.4",
|
"exit-future 0.1.4",
|
||||||
@@ -997,6 +1002,7 @@ dependencies = [
|
|||||||
"parking_lot 0.9.0",
|
"parking_lot 0.9.0",
|
||||||
"polkadot-cli",
|
"polkadot-cli",
|
||||||
"polkadot-collator",
|
"polkadot-collator",
|
||||||
|
"polkadot-parachain",
|
||||||
"polkadot-primitives",
|
"polkadot-primitives",
|
||||||
"polkadot-runtime",
|
"polkadot-runtime",
|
||||||
"polkadot-runtime-common",
|
"polkadot-runtime-common",
|
||||||
@@ -1030,18 +1036,21 @@ dependencies = [
|
|||||||
name = "cumulus-test-parachain-runtime"
|
name = "cumulus-test-parachain-runtime"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"cumulus-message-broker",
|
||||||
"cumulus-parachain-upgrade",
|
"cumulus-parachain-upgrade",
|
||||||
|
"cumulus-primitives",
|
||||||
"cumulus-runtime",
|
"cumulus-runtime",
|
||||||
|
"cumulus-upward-message",
|
||||||
"frame-executive",
|
"frame-executive",
|
||||||
"frame-support",
|
"frame-support",
|
||||||
"frame-system",
|
"frame-system",
|
||||||
"pallet-balances",
|
"pallet-balances",
|
||||||
"pallet-indices",
|
|
||||||
"pallet-randomness-collective-flip",
|
"pallet-randomness-collective-flip",
|
||||||
"pallet-sudo",
|
"pallet-sudo",
|
||||||
"pallet-timestamp",
|
"pallet-timestamp",
|
||||||
"pallet-transaction-payment",
|
"pallet-transaction-payment",
|
||||||
"parity-scale-codec",
|
"parity-scale-codec",
|
||||||
|
"polkadot-parachain",
|
||||||
"serde",
|
"serde",
|
||||||
"sp-api",
|
"sp-api",
|
||||||
"sp-block-builder",
|
"sp-block-builder",
|
||||||
@@ -1066,6 +1075,18 @@ dependencies = [
|
|||||||
"substrate-wasm-builder-runner 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"substrate-wasm-builder-runner 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cumulus-upward-message"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"kusama-runtime",
|
||||||
|
"polkadot-core-primitives",
|
||||||
|
"polkadot-parachain",
|
||||||
|
"polkadot-runtime",
|
||||||
|
"sp-std",
|
||||||
|
"westend-runtime",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "curve25519-dalek"
|
name = "curve25519-dalek"
|
||||||
version = "2.1.0"
|
version = "2.1.0"
|
||||||
@@ -2483,7 +2504,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "kusama-runtime"
|
name = "kusama-runtime"
|
||||||
version = "0.8.8"
|
version = "0.8.8"
|
||||||
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#abc1db331ac1fc4f73138bb059c107ee4011a069"
|
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#91f3e68f5750dff7bddedeb846ff55447e8cf8f8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitvec",
|
"bitvec",
|
||||||
"frame-executive",
|
"frame-executive",
|
||||||
@@ -4320,7 +4341,7 @@ checksum = "feb3b2b1033b8a60b4da6ee470325f887758c95d5320f52f9ce0df055a55940e"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "polkadot-availability-store"
|
name = "polkadot-availability-store"
|
||||||
version = "0.8.8"
|
version = "0.8.8"
|
||||||
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#abc1db331ac1fc4f73138bb059c107ee4011a069"
|
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#91f3e68f5750dff7bddedeb846ff55447e8cf8f8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"derive_more 0.99.7",
|
"derive_more 0.99.7",
|
||||||
"exit-future 0.2.0",
|
"exit-future 0.2.0",
|
||||||
@@ -4347,7 +4368,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "polkadot-cli"
|
name = "polkadot-cli"
|
||||||
version = "0.8.8"
|
version = "0.8.8"
|
||||||
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#abc1db331ac1fc4f73138bb059c107ee4011a069"
|
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#91f3e68f5750dff7bddedeb846ff55447e8cf8f8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"frame-benchmarking-cli",
|
"frame-benchmarking-cli",
|
||||||
"futures 0.3.5",
|
"futures 0.3.5",
|
||||||
@@ -4369,7 +4390,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "polkadot-collator"
|
name = "polkadot-collator"
|
||||||
version = "0.8.8"
|
version = "0.8.8"
|
||||||
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#abc1db331ac1fc4f73138bb059c107ee4011a069"
|
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#91f3e68f5750dff7bddedeb846ff55447e8cf8f8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures 0.3.5",
|
"futures 0.3.5",
|
||||||
"futures-timer 2.0.2",
|
"futures-timer 2.0.2",
|
||||||
@@ -4393,10 +4414,21 @@ dependencies = [
|
|||||||
"tokio 0.2.21",
|
"tokio 0.2.21",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "polkadot-core-primitives"
|
||||||
|
version = "0.7.30"
|
||||||
|
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#91f3e68f5750dff7bddedeb846ff55447e8cf8f8"
|
||||||
|
dependencies = [
|
||||||
|
"parity-scale-codec",
|
||||||
|
"sp-core",
|
||||||
|
"sp-runtime",
|
||||||
|
"sp-std",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "polkadot-erasure-coding"
|
name = "polkadot-erasure-coding"
|
||||||
version = "0.8.8"
|
version = "0.8.8"
|
||||||
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#abc1db331ac1fc4f73138bb059c107ee4011a069"
|
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#91f3e68f5750dff7bddedeb846ff55447e8cf8f8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"derive_more 0.15.0",
|
"derive_more 0.15.0",
|
||||||
"parity-scale-codec",
|
"parity-scale-codec",
|
||||||
@@ -4409,7 +4441,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "polkadot-network"
|
name = "polkadot-network"
|
||||||
version = "0.8.8"
|
version = "0.8.8"
|
||||||
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#abc1db331ac1fc4f73138bb059c107ee4011a069"
|
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#91f3e68f5750dff7bddedeb846ff55447e8cf8f8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec 0.4.12",
|
"arrayvec 0.4.12",
|
||||||
"bytes 0.5.4",
|
"bytes 0.5.4",
|
||||||
@@ -4436,19 +4468,19 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "polkadot-parachain"
|
name = "polkadot-parachain"
|
||||||
version = "0.8.8"
|
version = "0.8.8"
|
||||||
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#abc1db331ac1fc4f73138bb059c107ee4011a069"
|
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#91f3e68f5750dff7bddedeb846ff55447e8cf8f8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"derive_more 0.99.7",
|
"derive_more 0.99.7",
|
||||||
"log 0.4.8",
|
"log 0.4.8",
|
||||||
"parity-scale-codec",
|
"parity-scale-codec",
|
||||||
"parking_lot 0.10.2",
|
"parking_lot 0.10.2",
|
||||||
|
"polkadot-core-primitives",
|
||||||
"sc-executor",
|
"sc-executor",
|
||||||
"serde",
|
"serde",
|
||||||
"shared_memory",
|
"shared_memory",
|
||||||
"sp-core",
|
"sp-core",
|
||||||
"sp-externalities",
|
"sp-externalities",
|
||||||
"sp-io",
|
"sp-io",
|
||||||
"sp-runtime-interface",
|
|
||||||
"sp-std",
|
"sp-std",
|
||||||
"sp-wasm-interface",
|
"sp-wasm-interface",
|
||||||
]
|
]
|
||||||
@@ -4456,11 +4488,12 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "polkadot-primitives"
|
name = "polkadot-primitives"
|
||||||
version = "0.8.8"
|
version = "0.8.8"
|
||||||
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#abc1db331ac1fc4f73138bb059c107ee4011a069"
|
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#91f3e68f5750dff7bddedeb846ff55447e8cf8f8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitvec",
|
"bitvec",
|
||||||
"frame-system",
|
"frame-system",
|
||||||
"parity-scale-codec",
|
"parity-scale-codec",
|
||||||
|
"polkadot-core-primitives",
|
||||||
"polkadot-parachain",
|
"polkadot-parachain",
|
||||||
"serde",
|
"serde",
|
||||||
"sp-api",
|
"sp-api",
|
||||||
@@ -4477,7 +4510,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "polkadot-rpc"
|
name = "polkadot-rpc"
|
||||||
version = "0.8.8"
|
version = "0.8.8"
|
||||||
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#abc1db331ac1fc4f73138bb059c107ee4011a069"
|
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#91f3e68f5750dff7bddedeb846ff55447e8cf8f8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"jsonrpc-core",
|
"jsonrpc-core",
|
||||||
"pallet-transaction-payment-rpc",
|
"pallet-transaction-payment-rpc",
|
||||||
@@ -4503,7 +4536,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "polkadot-runtime"
|
name = "polkadot-runtime"
|
||||||
version = "0.8.8"
|
version = "0.8.8"
|
||||||
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#abc1db331ac1fc4f73138bb059c107ee4011a069"
|
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#91f3e68f5750dff7bddedeb846ff55447e8cf8f8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitvec",
|
"bitvec",
|
||||||
"frame-executive",
|
"frame-executive",
|
||||||
@@ -4567,7 +4600,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "polkadot-runtime-common"
|
name = "polkadot-runtime-common"
|
||||||
version = "0.8.8"
|
version = "0.8.8"
|
||||||
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#abc1db331ac1fc4f73138bb059c107ee4011a069"
|
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#91f3e68f5750dff7bddedeb846ff55447e8cf8f8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitvec",
|
"bitvec",
|
||||||
"frame-support",
|
"frame-support",
|
||||||
@@ -4599,7 +4632,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "polkadot-service"
|
name = "polkadot-service"
|
||||||
version = "0.8.8"
|
version = "0.8.8"
|
||||||
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#abc1db331ac1fc4f73138bb059c107ee4011a069"
|
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#91f3e68f5750dff7bddedeb846ff55447e8cf8f8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"frame-benchmarking",
|
"frame-benchmarking",
|
||||||
"frame-system-rpc-runtime-api",
|
"frame-system-rpc-runtime-api",
|
||||||
@@ -4657,7 +4690,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "polkadot-statement-table"
|
name = "polkadot-statement-table"
|
||||||
version = "0.8.8"
|
version = "0.8.8"
|
||||||
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#abc1db331ac1fc4f73138bb059c107ee4011a069"
|
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#91f3e68f5750dff7bddedeb846ff55447e8cf8f8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"parity-scale-codec",
|
"parity-scale-codec",
|
||||||
"polkadot-primitives",
|
"polkadot-primitives",
|
||||||
@@ -4667,7 +4700,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "polkadot-test-runtime"
|
name = "polkadot-test-runtime"
|
||||||
version = "0.8.8"
|
version = "0.8.8"
|
||||||
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#abc1db331ac1fc4f73138bb059c107ee4011a069"
|
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#91f3e68f5750dff7bddedeb846ff55447e8cf8f8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitvec",
|
"bitvec",
|
||||||
"frame-executive",
|
"frame-executive",
|
||||||
@@ -4717,7 +4750,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "polkadot-test-runtime-client"
|
name = "polkadot-test-runtime-client"
|
||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#abc1db331ac1fc4f73138bb059c107ee4011a069"
|
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#91f3e68f5750dff7bddedeb846ff55447e8cf8f8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures 0.3.5",
|
"futures 0.3.5",
|
||||||
"pallet-timestamp",
|
"pallet-timestamp",
|
||||||
@@ -4740,7 +4773,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "polkadot-validation"
|
name = "polkadot-validation"
|
||||||
version = "0.8.8"
|
version = "0.8.8"
|
||||||
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#abc1db331ac1fc4f73138bb059c107ee4011a069"
|
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#91f3e68f5750dff7bddedeb846ff55447e8cf8f8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitvec",
|
"bitvec",
|
||||||
"derive_more 0.14.1",
|
"derive_more 0.14.1",
|
||||||
@@ -8638,7 +8671,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "westend-runtime"
|
name = "westend-runtime"
|
||||||
version = "0.8.8"
|
version = "0.8.8"
|
||||||
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#abc1db331ac1fc4f73138bb059c107ee4011a069"
|
source = "git+https://github.com/paritytech/polkadot?branch=cumulus-branch#91f3e68f5750dff7bddedeb846ff55447e8cf8f8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitvec",
|
"bitvec",
|
||||||
"frame-executive",
|
"frame-executive",
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ members = [
|
|||||||
"test/client",
|
"test/client",
|
||||||
"test/parachain/runtime",
|
"test/parachain/runtime",
|
||||||
"test/parachain/",
|
"test/parachain/",
|
||||||
|
"upward-message",
|
||||||
]
|
]
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
|
|||||||
+77
-69
@@ -20,39 +20,39 @@ use cumulus_network::{
|
|||||||
DelayedBlockAnnounceValidator, JustifiedBlockAnnounceValidator, WaitToAnnounce,
|
DelayedBlockAnnounceValidator, JustifiedBlockAnnounceValidator, WaitToAnnounce,
|
||||||
};
|
};
|
||||||
use cumulus_primitives::{
|
use cumulus_primitives::{
|
||||||
HeadData, inherents::VALIDATION_FUNCTION_PARAMS_IDENTIFIER as VFP_IDENT,
|
inherents::{VALIDATION_FUNCTION_PARAMS_IDENTIFIER as VFP_IDENT, DOWNWARD_MESSAGES_IDENTIFIER, DownwardMessagesType},
|
||||||
validation_function_params::ValidationFunctionParams,
|
validation_function_params::ValidationFunctionParams, HeadData,
|
||||||
};
|
};
|
||||||
use cumulus_runtime::ParachainBlockData;
|
use cumulus_runtime::ParachainBlockData;
|
||||||
|
|
||||||
|
use sc_client_api::{BlockchainEvents, Finalizer, StateBackend, UsageProvider};
|
||||||
|
use sc_service::Configuration;
|
||||||
|
use sp_api::{ApiExt, ProvideRuntimeApi};
|
||||||
use sp_blockchain::HeaderBackend;
|
use sp_blockchain::HeaderBackend;
|
||||||
use sp_consensus::{
|
use sp_consensus::{
|
||||||
BlockImport, BlockImportParams, BlockOrigin, Environment, Error as ConsensusError,
|
BlockImport, BlockImportParams, BlockOrigin, Environment, Error as ConsensusError,
|
||||||
ForkChoiceStrategy, Proposal, Proposer, RecordProof,
|
ForkChoiceStrategy, Proposal, Proposer, RecordProof,
|
||||||
};
|
};
|
||||||
use sp_inherents::{InherentData, InherentDataProviders};
|
use sp_inherents::{InherentData, InherentDataProviders};
|
||||||
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, HashFor};
|
use sp_runtime::traits::{Block as BlockT, HashFor, Header as HeaderT};
|
||||||
use sp_api::{ApiExt, ProvideRuntimeApi};
|
|
||||||
use sc_client_api::{StateBackend, UsageProvider, Finalizer, BlockchainEvents};
|
|
||||||
use sc_service::Configuration;
|
|
||||||
|
|
||||||
use polkadot_collator::{
|
use polkadot_collator::{
|
||||||
BuildParachainContext, InvalidHead, Network as CollatorNetwork, ParachainContext,
|
BuildParachainContext, InvalidHead, Network as CollatorNetwork, ParachainContext,
|
||||||
RuntimeApiCollection,
|
RuntimeApiCollection,
|
||||||
};
|
};
|
||||||
use polkadot_primitives::{
|
use polkadot_primitives::{
|
||||||
parachain::{self, BlockData, GlobalValidationSchedule, LocalValidationData, Id as ParaId},
|
parachain::{self, BlockData, GlobalValidationSchedule, Id as ParaId, LocalValidationData},
|
||||||
Block as PBlock, Hash as PHash,
|
Block as PBlock, DownwardMessage, Hash as PHash,
|
||||||
};
|
};
|
||||||
|
|
||||||
use codec::{Decode, Encode};
|
use codec::{Decode, Encode};
|
||||||
|
|
||||||
use log::{error, trace};
|
use log::{error, trace};
|
||||||
|
|
||||||
use futures::task::Spawn;
|
|
||||||
use futures::prelude::*;
|
use futures::prelude::*;
|
||||||
|
use futures::task::Spawn;
|
||||||
|
|
||||||
use std::{marker::PhantomData, sync::Arc, time::Duration, pin::Pin};
|
use std::{marker::PhantomData, pin::Pin, sync::Arc, time::Duration};
|
||||||
|
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
|
||||||
@@ -98,10 +98,9 @@ impl<Block: BlockT, PF, BI> Collator<Block, PF, BI> {
|
|||||||
inherent_providers: InherentDataProviders,
|
inherent_providers: InherentDataProviders,
|
||||||
global_validation: GlobalValidationSchedule,
|
global_validation: GlobalValidationSchedule,
|
||||||
local_validation: LocalValidationData,
|
local_validation: LocalValidationData,
|
||||||
|
downward_messages: DownwardMessagesType,
|
||||||
) -> Result<InherentData, InvalidHead> {
|
) -> Result<InherentData, InvalidHead> {
|
||||||
let mut inherent_data = inherent_providers
|
let mut inherent_data = inherent_providers.create_inherent_data().map_err(|e| {
|
||||||
.create_inherent_data()
|
|
||||||
.map_err(|e| {
|
|
||||||
error!(
|
error!(
|
||||||
target: "cumulus-collator",
|
target: "cumulus-collator",
|
||||||
"Failed to create inherent data: {:?}",
|
"Failed to create inherent data: {:?}",
|
||||||
@@ -110,13 +109,29 @@ impl<Block: BlockT, PF, BI> Collator<Block, PF, BI> {
|
|||||||
InvalidHead
|
InvalidHead
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
inherent_data.put_data(
|
inherent_data
|
||||||
|
.put_data(
|
||||||
VFP_IDENT,
|
VFP_IDENT,
|
||||||
&ValidationFunctionParams::from((global_validation, local_validation))
|
&ValidationFunctionParams::from((global_validation, local_validation)),
|
||||||
).map_err(|e| {
|
)
|
||||||
|
.map_err(|e| {
|
||||||
error!(
|
error!(
|
||||||
target: "cumulus-collator",
|
target: "cumulus-collator",
|
||||||
"Failed to inject validation function params into inherents: {:?}",
|
"Failed to put validation function params into inherent data: {:?}",
|
||||||
|
e,
|
||||||
|
);
|
||||||
|
InvalidHead
|
||||||
|
})?;
|
||||||
|
|
||||||
|
inherent_data
|
||||||
|
.put_data(
|
||||||
|
DOWNWARD_MESSAGES_IDENTIFIER,
|
||||||
|
&downward_messages,
|
||||||
|
)
|
||||||
|
.map_err(|e| {
|
||||||
|
error!(
|
||||||
|
target: "cumulus-collator",
|
||||||
|
"Failed to put downward messages into inherent data: {:?}",
|
||||||
e,
|
e,
|
||||||
);
|
);
|
||||||
InvalidHead
|
InvalidHead
|
||||||
@@ -152,16 +167,15 @@ where
|
|||||||
+ Sync
|
+ Sync
|
||||||
+ 'static,
|
+ 'static,
|
||||||
{
|
{
|
||||||
type ProduceCandidate = Pin<Box<
|
type ProduceCandidate =
|
||||||
dyn Future<Output=Result<(BlockData, parachain::HeadData), InvalidHead>>
|
Pin<Box<dyn Future<Output = Result<(BlockData, parachain::HeadData), InvalidHead>> + Send>>;
|
||||||
+ Send,
|
|
||||||
>>;
|
|
||||||
|
|
||||||
fn produce_candidate(
|
fn produce_candidate(
|
||||||
&mut self,
|
&mut self,
|
||||||
relay_chain_parent: PHash,
|
relay_chain_parent: PHash,
|
||||||
global_validation: GlobalValidationSchedule,
|
global_validation: GlobalValidationSchedule,
|
||||||
local_validation: LocalValidationData,
|
local_validation: LocalValidationData,
|
||||||
|
downward_messages: Vec<DownwardMessage>,
|
||||||
) -> Self::ProduceCandidate {
|
) -> Self::ProduceCandidate {
|
||||||
let factory = self.proposer_factory.clone();
|
let factory = self.proposer_factory.clone();
|
||||||
let inherent_providers = self.inherent_data_providers.clone();
|
let inherent_providers = self.inherent_data_providers.clone();
|
||||||
@@ -177,18 +191,14 @@ where
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let proposer_future = factory
|
let proposer_future = factory.lock().init(&last_head.header);
|
||||||
.lock()
|
|
||||||
.init(&last_head.header);
|
|
||||||
|
|
||||||
let wait_to_announce = self.wait_to_announce.clone();
|
let wait_to_announce = self.wait_to_announce.clone();
|
||||||
|
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
let parent_state_root = *last_head.header.state_root();
|
let parent_state_root = *last_head.header.state_root();
|
||||||
|
|
||||||
let proposer = proposer_future
|
let proposer = proposer_future.await.map_err(|e| {
|
||||||
.await
|
|
||||||
.map_err(|e| {
|
|
||||||
error!(
|
error!(
|
||||||
target: "cumulus-collator",
|
target: "cumulus-collator",
|
||||||
"Could not create proposer: {:?}",
|
"Could not create proposer: {:?}",
|
||||||
@@ -197,7 +207,12 @@ where
|
|||||||
InvalidHead
|
InvalidHead
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let inherent_data = Self::inherent_data(inherent_providers, global_validation, local_validation)?;
|
let inherent_data = Self::inherent_data(
|
||||||
|
inherent_providers,
|
||||||
|
global_validation,
|
||||||
|
local_validation,
|
||||||
|
downward_messages,
|
||||||
|
)?;
|
||||||
|
|
||||||
let Proposal {
|
let Proposal {
|
||||||
block,
|
block,
|
||||||
@@ -221,8 +236,7 @@ where
|
|||||||
InvalidHead
|
InvalidHead
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let proof = proof
|
let proof = proof.ok_or_else(|| {
|
||||||
.ok_or_else(|| {
|
|
||||||
error!(
|
error!(
|
||||||
target: "cumulus-collator",
|
target: "cumulus-collator",
|
||||||
"Proposer did not return the requested proof.",
|
"Proposer did not return the requested proof.",
|
||||||
@@ -262,20 +276,13 @@ where
|
|||||||
let header = b.into_header();
|
let header = b.into_header();
|
||||||
let encoded_header = header.encode();
|
let encoded_header = header.encode();
|
||||||
let hash = header.hash();
|
let hash = header.hash();
|
||||||
let head_data = HeadData::<Block> {
|
let head_data = HeadData::<Block> { header };
|
||||||
header,
|
|
||||||
};
|
|
||||||
|
|
||||||
let candidate = (
|
let candidate = (block_data, parachain::HeadData(head_data.encode()));
|
||||||
block_data,
|
|
||||||
parachain::HeadData(head_data.encode()),
|
|
||||||
);
|
|
||||||
|
|
||||||
wait_to_announce.lock().wait_to_announce(
|
wait_to_announce
|
||||||
hash,
|
.lock()
|
||||||
relay_chain_parent,
|
.wait_to_announce(hash, relay_chain_parent, encoded_header);
|
||||||
encoded_header,
|
|
||||||
);
|
|
||||||
|
|
||||||
trace!(target: "cumulus-collator", "Produced candidate: {:?}", candidate);
|
trace!(target: "cumulus-collator", "Produced candidate: {:?}", candidate);
|
||||||
|
|
||||||
@@ -296,9 +303,7 @@ pub struct CollatorBuilder<Block: BlockT, PF, BI, Backend, Client> {
|
|||||||
_marker: PhantomData<(Block, Backend)>,
|
_marker: PhantomData<(Block, Backend)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Block: BlockT, PF, BI, Backend, Client>
|
impl<Block: BlockT, PF, BI, Backend, Client> CollatorBuilder<Block, PF, BI, Backend, Client> {
|
||||||
CollatorBuilder<Block, PF, BI, Backend, Client>
|
|
||||||
{
|
|
||||||
/// Create a new instance of self.
|
/// Create a new instance of self.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
proposer_factory: PF,
|
proposer_factory: PF,
|
||||||
@@ -334,7 +339,9 @@ where
|
|||||||
+ Sync
|
+ Sync
|
||||||
+ 'static,
|
+ 'static,
|
||||||
Backend: sc_client_api::Backend<Block> + 'static,
|
Backend: sc_client_api::Backend<Block> + 'static,
|
||||||
Client: Finalizer<Block, Backend> + UsageProvider<Block> + HeaderBackend<Block>
|
Client: Finalizer<Block, Backend>
|
||||||
|
+ UsageProvider<Block>
|
||||||
|
+ HeaderBackend<Block>
|
||||||
+ Send
|
+ Send
|
||||||
+ Sync
|
+ Sync
|
||||||
+ 'static,
|
+ 'static,
|
||||||
@@ -348,16 +355,22 @@ where
|
|||||||
polkadot_network: impl CollatorNetwork + Clone + 'static,
|
polkadot_network: impl CollatorNetwork + Clone + 'static,
|
||||||
) -> Result<Self::ParachainContext, ()>
|
) -> Result<Self::ParachainContext, ()>
|
||||||
where
|
where
|
||||||
PClient: ProvideRuntimeApi<PBlock> + BlockchainEvents<PBlock> + HeaderBackend<PBlock>
|
PClient: ProvideRuntimeApi<PBlock>
|
||||||
+ Send + Sync + 'static,
|
+ BlockchainEvents<PBlock>
|
||||||
|
+ HeaderBackend<PBlock>
|
||||||
|
+ Send
|
||||||
|
+ Sync
|
||||||
|
+ 'static,
|
||||||
PClient::Api: RuntimeApiCollection<Extrinsic>,
|
PClient::Api: RuntimeApiCollection<Extrinsic>,
|
||||||
<PClient::Api as ApiExt<PBlock>>::StateBackend: StateBackend<HashFor<PBlock>>,
|
<PClient::Api as ApiExt<PBlock>>::StateBackend: StateBackend<HashFor<PBlock>>,
|
||||||
Spawner: Spawn + Clone + Send + Sync + 'static,
|
Spawner: Spawn + Clone + Send + Sync + 'static,
|
||||||
Extrinsic: codec::Codec + Send + Sync + 'static,
|
Extrinsic: codec::Codec + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
self.delayed_block_announce_validator.set(
|
self.delayed_block_announce_validator
|
||||||
Box::new(JustifiedBlockAnnounceValidator::new(polkadot_client.clone(), self.para_id)),
|
.set(Box::new(JustifiedBlockAnnounceValidator::new(
|
||||||
);
|
polkadot_client.clone(),
|
||||||
|
self.para_id,
|
||||||
|
)));
|
||||||
|
|
||||||
let follow =
|
let follow =
|
||||||
match cumulus_consensus::follow_polkadot(self.para_id, self.client, polkadot_client) {
|
match cumulus_consensus::follow_polkadot(self.para_id, self.client, polkadot_client) {
|
||||||
@@ -368,12 +381,7 @@ where
|
|||||||
};
|
};
|
||||||
|
|
||||||
spawner
|
spawner
|
||||||
.spawn_obj(
|
.spawn_obj(Box::new(follow.map(|_| ())).into())
|
||||||
Box::new(
|
|
||||||
follow.map(|_| ()),
|
|
||||||
)
|
|
||||||
.into(),
|
|
||||||
)
|
|
||||||
.map_err(|_| error!("Could not spawn parachain server!"))?;
|
.map_err(|_| error!("Could not spawn parachain server!"))?;
|
||||||
|
|
||||||
Ok(Collator::new(
|
Ok(Collator::new(
|
||||||
@@ -415,12 +423,10 @@ mod tests {
|
|||||||
use sp_state_machine::StorageProof;
|
use sp_state_machine::StorageProof;
|
||||||
use substrate_test_client::{NativeExecutor, WasmExecutionMethod::Interpreted};
|
use substrate_test_client::{NativeExecutor, WasmExecutionMethod::Interpreted};
|
||||||
|
|
||||||
use test_client::{
|
use test_client::{DefaultTestClientBuilderExt, TestClientBuilder, TestClientBuilderExt};
|
||||||
DefaultTestClientBuilderExt, TestClientBuilder, TestClientBuilderExt,
|
|
||||||
};
|
|
||||||
use test_runtime::{Block, Header};
|
use test_runtime::{Block, Header};
|
||||||
|
|
||||||
use futures::{Stream, future};
|
use futures::{future, Stream};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Error;
|
struct Error;
|
||||||
@@ -436,9 +442,9 @@ mod tests {
|
|||||||
impl Environment<Block> for DummyFactory {
|
impl Environment<Block> for DummyFactory {
|
||||||
type Proposer = DummyProposer;
|
type Proposer = DummyProposer;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type CreateProposer = Pin<Box<
|
type CreateProposer = Pin<
|
||||||
dyn Future<Output = Result<Self::Proposer, Self::Error>> + Send + Unpin + 'static
|
Box<dyn Future<Output = Result<Self::Proposer, Self::Error>> + Send + Unpin + 'static>,
|
||||||
>>;
|
>;
|
||||||
|
|
||||||
fn init(&mut self, _: &Header) -> Self::CreateProposer {
|
fn init(&mut self, _: &Header) -> Self::CreateProposer {
|
||||||
Box::pin(future::ready(Ok(DummyProposer)))
|
Box::pin(future::ready(Ok(DummyProposer)))
|
||||||
@@ -479,7 +485,10 @@ mod tests {
|
|||||||
struct DummyCollatorNetwork;
|
struct DummyCollatorNetwork;
|
||||||
|
|
||||||
impl CollatorNetwork for DummyCollatorNetwork {
|
impl CollatorNetwork for DummyCollatorNetwork {
|
||||||
fn checked_statements(&self, _: PHash) -> Pin<Box<dyn Stream<Item = SignedStatement> + Send>> {
|
fn checked_statements(
|
||||||
|
&self,
|
||||||
|
_: PHash,
|
||||||
|
) -> Pin<Box<dyn Stream<Item = SignedStatement> + Send>> {
|
||||||
unimplemented!("Not required in tests")
|
unimplemented!("Not required in tests")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -526,13 +535,11 @@ mod tests {
|
|||||||
Arc::new(
|
Arc::new(
|
||||||
substrate_test_client::TestClientBuilder::<_, _, _, ()>::default()
|
substrate_test_client::TestClientBuilder::<_, _, _, ()>::default()
|
||||||
.build_with_native_executor::<polkadot_service::polkadot_runtime::RuntimeApi, _>(
|
.build_with_native_executor::<polkadot_service::polkadot_runtime::RuntimeApi, _>(
|
||||||
Some(
|
Some(NativeExecutor::<polkadot_service::PolkadotExecutor>::new(
|
||||||
NativeExecutor::<polkadot_service::PolkadotExecutor>::new(
|
|
||||||
Interpreted,
|
Interpreted,
|
||||||
None,
|
None,
|
||||||
1,
|
1,
|
||||||
)
|
)),
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.0,
|
.0,
|
||||||
),
|
),
|
||||||
@@ -562,6 +569,7 @@ mod tests {
|
|||||||
balance: 10,
|
balance: 10,
|
||||||
code_upgrade_allowed: None,
|
code_upgrade_allowed: None,
|
||||||
},
|
},
|
||||||
|
Vec::new(),
|
||||||
context,
|
context,
|
||||||
Arc::new(Sr25519Keyring::Alice.pair().into()),
|
Arc::new(Sr25519Keyring::Alice.pair().into()),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -9,12 +9,16 @@ edition = "2018"
|
|||||||
frame-support = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
|
frame-support = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
|
||||||
frame-system = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
|
frame-system = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
|
||||||
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
|
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
|
||||||
|
sp-io = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
|
||||||
|
sp-std = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
|
||||||
|
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
|
||||||
|
|
||||||
# Other dependencies
|
# Other dependencies
|
||||||
codec = { package = "parity-scale-codec", version = "1.3.0", features = [ "derive" ], default-features = false }
|
codec = { package = "parity-scale-codec", version = "1.3.0", features = [ "derive" ], default-features = false }
|
||||||
|
|
||||||
# Cumulus dependencies
|
# Cumulus dependencies
|
||||||
cumulus-primitives = { path = "../primitives", default-features = false }
|
cumulus-primitives = { path = "../primitives", default-features = false }
|
||||||
|
cumulus-upward-message = { path = "../upward-message", default-features = false }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = [ "std" ]
|
default = [ "std" ]
|
||||||
@@ -22,6 +26,10 @@ std = [
|
|||||||
"frame-support/std",
|
"frame-support/std",
|
||||||
"frame-system/std",
|
"frame-system/std",
|
||||||
"sp-inherents/std",
|
"sp-inherents/std",
|
||||||
|
"sp-io/std",
|
||||||
|
"sp-std/std",
|
||||||
|
"sp-runtime/std",
|
||||||
"codec/std",
|
"codec/std",
|
||||||
"cumulus-primitives/std",
|
"cumulus-primitives/std",
|
||||||
|
"cumulus-upward-message/std",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -16,52 +16,128 @@
|
|||||||
|
|
||||||
//! Cumulus message broker pallet.
|
//! Cumulus message broker pallet.
|
||||||
//!
|
//!
|
||||||
//! This pallet provides support for handling downward and upward messages.
|
//! This pallet provides support for handling downward, upward messages and
|
||||||
|
//! XMCP messages.
|
||||||
|
|
||||||
#![cfg_attr(not(feature = "std"), no_std)]
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
|
|
||||||
|
use codec::{Encode, Decode};
|
||||||
use cumulus_primitives::{
|
use cumulus_primitives::{
|
||||||
inherents::{DownwardMessagesType, DOWNWARD_MESSAGES_IDENTIFIER},
|
inherents::{DownwardMessagesType, DOWNWARD_MESSAGES_IDENTIFIER},
|
||||||
well_known_keys, DownwardMessageHandler, UpwardMessageSender,
|
well_known_keys,
|
||||||
|
xcmp::{RawXCMPMessage, XCMPMessageHandler, XCMPMessageSender},
|
||||||
|
DownwardMessage, DownwardMessageHandler, GenericUpwardMessage, ParaId, UpwardMessageOrigin,
|
||||||
|
UpwardMessageSender,
|
||||||
};
|
};
|
||||||
|
use cumulus_upward_message::XCMPMessage;
|
||||||
use frame_support::{
|
use frame_support::{
|
||||||
decl_module, storage,
|
decl_event, decl_module, storage,
|
||||||
|
traits::Get,
|
||||||
weights::{DispatchClass, Weight},
|
weights::{DispatchClass, Weight},
|
||||||
};
|
};
|
||||||
use frame_system::ensure_none;
|
use frame_system::ensure_none;
|
||||||
use sp_inherents::{InherentData, InherentIdentifier, MakeFatalError, ProvideInherent};
|
use sp_inherents::{InherentData, InherentIdentifier, MakeFatalError, ProvideInherent};
|
||||||
|
use sp_runtime::traits::Hash;
|
||||||
|
use sp_std::vec::Vec;
|
||||||
|
|
||||||
/// Configuration trait of this pallet.
|
/// Configuration trait of this pallet.
|
||||||
pub trait Trait: frame_system::Trait {
|
pub trait Trait: frame_system::Trait {
|
||||||
|
/// Event type used by the runtime.
|
||||||
|
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
|
||||||
|
|
||||||
/// The downward message handlers that will be informed when a message is received.
|
/// The downward message handlers that will be informed when a message is received.
|
||||||
type DownwardMessageHandlers: DownwardMessageHandler;
|
type DownwardMessageHandlers: DownwardMessageHandler;
|
||||||
|
|
||||||
|
/// The upward message type used by the Parachain runtime.
|
||||||
|
type UpwardMessage: codec::Codec + XCMPMessage;
|
||||||
|
|
||||||
|
/// The XCMP message handlers that will be informed when a XCMP message is received.
|
||||||
|
type XCMPMessageHandlers: XCMPMessageHandler<Self::XCMPMessage>;
|
||||||
|
|
||||||
|
/// The XCMP message type used by the Parachain runtime.
|
||||||
|
type XCMPMessage: codec::Codec;
|
||||||
|
|
||||||
|
/// The Id of the parachain.
|
||||||
|
type ParachainId: Get<ParaId>;
|
||||||
|
}
|
||||||
|
|
||||||
|
decl_event! {
|
||||||
|
pub enum Event<T> where Hash = <T as frame_system::Trait>::Hash {
|
||||||
|
/// An upward message was sent to the relay chain.
|
||||||
|
///
|
||||||
|
/// The hash corresponds to the hash of the encoded upward message.
|
||||||
|
UpwardMessageSent(Hash),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
decl_module! {
|
decl_module! {
|
||||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system = frame_system {
|
||||||
/// Executes the given downward messages by calling the message handlers.
|
/// Executes the given downward messages by calling the message handlers.
|
||||||
///
|
///
|
||||||
/// The origin of this call needs to be `None` as this is an inherent.
|
/// The origin of this call needs to be `None` as this is an inherent.
|
||||||
#[weight = (10, DispatchClass::Mandatory)]
|
#[weight = (10, DispatchClass::Mandatory)]
|
||||||
fn execute_downward_messages(origin, messages: Vec<()>) {
|
fn execute_downward_messages(origin, messages: Vec<DownwardMessage>) {
|
||||||
ensure_none(origin)?;
|
ensure_none(origin)?;
|
||||||
messages.iter().for_each(T::DownwardMessageHandlers::handle_downward_message);
|
|
||||||
|
//TODO: max messages should not be hardcoded. It should be determined based on the
|
||||||
|
// weight used by the handlers.
|
||||||
|
let max_messages = 10;
|
||||||
|
messages.iter().take(max_messages).for_each(|msg| {
|
||||||
|
match msg {
|
||||||
|
DownwardMessage::XCMPMessage(msg) => {
|
||||||
|
if let Ok(msg) = RawXCMPMessage::decode(&mut &msg[..]) {
|
||||||
|
if let Ok(xcmp_msg) = T::XCMPMessage::decode(&mut &msg.data[..]) {
|
||||||
|
T::XCMPMessageHandlers::handle_xcmp_message(msg.from, &xcmp_msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
msg => T::DownwardMessageHandlers::handle_downward_message(msg),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let processed = sp_std::cmp::min(messages.len(), max_messages) as u32;
|
||||||
|
storage::unhashed::put(well_known_keys::PROCESSED_DOWNWARD_MESSAGES, &processed);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_initialize() -> Weight {
|
fn on_initialize() -> Weight {
|
||||||
storage::unhashed::kill(well_known_keys::UPWARD_MESSAGES);
|
storage::unhashed::kill(well_known_keys::UPWARD_MESSAGES);
|
||||||
|
|
||||||
0
|
T::DbWeight::get().writes(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn deposit_event() = default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Trait> UpwardMessageSender for Module<T> {
|
impl<T: Trait> UpwardMessageSender<T::UpwardMessage> for Module<T> {
|
||||||
fn send_upward_message(_: &()) -> Result<(), ()> {
|
fn send_upward_message(msg: &T::UpwardMessage, origin: UpwardMessageOrigin) -> Result<(), ()> {
|
||||||
|
//TODO: check fee schedule
|
||||||
|
let data = msg.encode();
|
||||||
|
let data_hash = T::Hashing::hash(&data);
|
||||||
|
|
||||||
|
let msg = GenericUpwardMessage { origin, data };
|
||||||
|
sp_io::storage::append(well_known_keys::UPWARD_MESSAGES, msg.encode());
|
||||||
|
|
||||||
|
Self::deposit_event(RawEvent::UpwardMessageSent(data_hash));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: Trait> XCMPMessageSender<T::XCMPMessage> for Module<T> {
|
||||||
|
fn send_xcmp_message(dest: ParaId, msg: &T::XCMPMessage) -> Result<(), ()> {
|
||||||
|
let message = RawXCMPMessage {
|
||||||
|
from: T::ParachainId::get(),
|
||||||
|
data: msg.encode(),
|
||||||
|
};
|
||||||
|
|
||||||
|
Self::send_upward_message(
|
||||||
|
&T::UpwardMessage::send_message(dest, message.encode()),
|
||||||
|
UpwardMessageOrigin::Parachain,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: Trait> ProvideInherent for Module<T> {
|
impl<T: Trait> ProvideInherent for Module<T> {
|
||||||
type Call = Call<T>;
|
type Call = Call<T>;
|
||||||
type Error = MakeFatalError<()>;
|
type Error = MakeFatalError<()>;
|
||||||
|
|||||||
@@ -439,6 +439,10 @@ sp_api::mock_impl_runtime_apis! {
|
|||||||
parent_hash: Default::default(),
|
parent_hash: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn downward_messages(_: ParaId) -> Vec<polkadot_primitives::DownwardMessage> {
|
||||||
|
Vec::new()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,23 +14,24 @@ cumulus-runtime = { path = "../runtime", default-features = false }
|
|||||||
parachain = { package = "polkadot-parachain", git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch", default-features = false }
|
parachain = { package = "polkadot-parachain", git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch", default-features = false }
|
||||||
|
|
||||||
# Substrate dependencies
|
# Substrate dependencies
|
||||||
frame-support = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
|
frame-support = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
|
||||||
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
|
pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
|
||||||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", version = "2.0.0-dev", default-features = false }
|
sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", version = "2.0.0-dev", default-features = false }
|
||||||
sp-std = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", version = "2.0.0-dev", default-features = false }
|
sp-inherents = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
|
||||||
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
|
sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
|
||||||
sp-io = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
|
sp-std = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
|
||||||
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
|
sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
|
||||||
system = { package = "frame-system", git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
|
sp-version = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
|
||||||
|
system = { package = "frame-system", git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
|
||||||
|
|
||||||
# Other Dependencies
|
# Other Dependencies
|
||||||
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"]}
|
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"]}
|
||||||
serde = { version = "1.0.101", optional = true, features = ["derive"] }
|
serde = { version = "1.0.101", optional = true, features = ["derive"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
sp-externalities = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
|
sp-externalities = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
|
||||||
substrate-test-runtime-client = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
|
substrate-test-runtime-client = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
|
||||||
sp-version = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
|
sp-version = { git = "https://github.com/paritytech/substrate.git", branch = "cumulus-branch", default-features = false }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ['std']
|
default = ['std']
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch =
|
|||||||
codec = { package = "parity-scale-codec", version = "1.0.5", default-features = false, features = [ "derive" ] }
|
codec = { package = "parity-scale-codec", version = "1.0.5", default-features = false, features = [ "derive" ] }
|
||||||
impl-trait-for-tuples = "0.1.3"
|
impl-trait-for-tuples = "0.1.3"
|
||||||
|
|
||||||
|
# Polkadot dependencies
|
||||||
|
polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch", default-features = false }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = [ "std" ]
|
default = [ "std" ]
|
||||||
std = [
|
std = [
|
||||||
@@ -26,5 +29,6 @@ std = [
|
|||||||
"polkadot-primitives/std",
|
"polkadot-primitives/std",
|
||||||
"polkadot-parachain/std",
|
"polkadot-parachain/std",
|
||||||
"sp-inherents/std",
|
"sp-inherents/std",
|
||||||
|
"polkadot-core-primitives/std",
|
||||||
"sp-runtime/std",
|
"sp-runtime/std",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -18,7 +18,18 @@
|
|||||||
|
|
||||||
#![cfg_attr(not(feature = "std"), no_std)]
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
|
|
||||||
|
pub use polkadot_core_primitives as relay_chain;
|
||||||
|
pub use polkadot_core_primitives::DownwardMessage;
|
||||||
|
/// A generic upward message from a Parachain to the Relay Chain.
|
||||||
|
///
|
||||||
|
/// It is "generic" in such a way, that the actual message is encoded in the `data` field.
|
||||||
|
/// Besides the `data` it also holds the `origin` of the message.
|
||||||
|
pub use polkadot_parachain::primitives::UpwardMessage as GenericUpwardMessage;
|
||||||
|
pub use polkadot_parachain::primitives::ParachainDispatchOrigin as UpwardMessageOrigin;
|
||||||
|
pub use polkadot_parachain::primitives::Id as ParaId;
|
||||||
|
|
||||||
pub mod validation_function_params;
|
pub mod validation_function_params;
|
||||||
|
pub mod xcmp;
|
||||||
|
|
||||||
use codec::{Decode, Encode};
|
use codec::{Decode, Encode};
|
||||||
use sp_runtime::traits::Block as BlockT;
|
use sp_runtime::traits::Block as BlockT;
|
||||||
@@ -31,7 +42,7 @@ pub mod inherents {
|
|||||||
pub const DOWNWARD_MESSAGES_IDENTIFIER: InherentIdentifier = *b"cumdownm";
|
pub const DOWNWARD_MESSAGES_IDENTIFIER: InherentIdentifier = *b"cumdownm";
|
||||||
|
|
||||||
/// The type of the inherent downward messages.
|
/// The type of the inherent downward messages.
|
||||||
pub type DownwardMessagesType = sp_std::vec::Vec<()>;
|
pub type DownwardMessagesType = sp_std::vec::Vec<crate::DownwardMessage>;
|
||||||
|
|
||||||
/// The identifier for the `validation_function_params` inherent.
|
/// The identifier for the `validation_function_params` inherent.
|
||||||
pub const VALIDATION_FUNCTION_PARAMS_IDENTIFIER: InherentIdentifier = *b"valfunp0";
|
pub const VALIDATION_FUNCTION_PARAMS_IDENTIFIER: InherentIdentifier = *b"valfunp0";
|
||||||
@@ -43,29 +54,34 @@ pub mod inherents {
|
|||||||
pub mod well_known_keys {
|
pub mod well_known_keys {
|
||||||
/// The storage key for the upward messages.
|
/// The storage key for the upward messages.
|
||||||
///
|
///
|
||||||
/// The upward messages are stored as SCALE encoded `Vec<()>`.
|
/// The upward messages are stored as SCALE encoded `Vec<GenericUpwardMessage>`.
|
||||||
pub const UPWARD_MESSAGES: &'static [u8] = b":cumulus_upward_messages:";
|
pub const UPWARD_MESSAGES: &'static [u8] = b":cumulus_upward_messages:";
|
||||||
|
|
||||||
/// Current validation function parameters.
|
/// Current validation function parameters.
|
||||||
pub const VALIDATION_FUNCTION_PARAMS: &'static [u8] = b":validation_function_params";
|
pub const VALIDATION_FUNCTION_PARAMS: &'static [u8] = b":cumulus_validation_function_params";
|
||||||
|
|
||||||
/// Code upgarde (set as appropriate by a pallet).
|
/// Code upgarde (set as appropriate by a pallet).
|
||||||
pub const NEW_VALIDATION_CODE: &'static [u8] = b":new_validation_code";
|
pub const NEW_VALIDATION_CODE: &'static [u8] = b":cumulus_new_validation_code";
|
||||||
|
|
||||||
|
/// The storage key for the processed downward messages.
|
||||||
|
///
|
||||||
|
/// The value is stored as SCALE encoded `u32`.
|
||||||
|
pub const PROCESSED_DOWNWARD_MESSAGES: &'static [u8] = b":cumulus_processed_downward_messages:";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Something that should be called when a downward message is received.
|
/// Something that should be called when a downward message is received.
|
||||||
#[impl_trait_for_tuples::impl_for_tuples(30)]
|
#[impl_trait_for_tuples::impl_for_tuples(30)]
|
||||||
pub trait DownwardMessageHandler {
|
pub trait DownwardMessageHandler {
|
||||||
/// Handle the given downward message.
|
/// Handle the given downward message.
|
||||||
fn handle_downward_message(msg: &());
|
fn handle_downward_message(msg: &DownwardMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Something that can send upward messages.
|
/// Something that can send upward messages.
|
||||||
pub trait UpwardMessageSender {
|
pub trait UpwardMessageSender<UpwardMessage> {
|
||||||
/// Send an upward message to the relay chain.
|
/// Send an upward message to the relay chain.
|
||||||
///
|
///
|
||||||
/// Returns an error if sending failed.
|
/// Returns an error if sending failed.
|
||||||
fn send_upward_message(msg: &()) -> Result<(), ()>;
|
fn send_upward_message(msg: &UpwardMessage, origin: UpwardMessageOrigin) -> Result<(), ()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The head data of the parachain, stored in the relay chain.
|
/// The head data of the parachain, stored in the relay chain.
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||||
|
// This file is part of Cumulus.
|
||||||
|
|
||||||
|
// Substrate 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.
|
||||||
|
|
||||||
|
// Substrate 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//! XMCP related primitives
|
||||||
|
|
||||||
|
use polkadot_primitives::parachain::Id as ParaId;
|
||||||
|
use sp_std::vec::Vec;
|
||||||
|
|
||||||
|
/// A raw XCMP message that is being send between two Parachain's.
|
||||||
|
#[derive(codec::Encode, codec::Decode)]
|
||||||
|
pub struct RawXCMPMessage {
|
||||||
|
/// Parachain sending the message.
|
||||||
|
pub from: ParaId,
|
||||||
|
/// SCALE encoded message.
|
||||||
|
pub data: Vec<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Something that can handle XCMP messages.
|
||||||
|
#[impl_trait_for_tuples::impl_for_tuples(30)]
|
||||||
|
pub trait XCMPMessageHandler<Message: codec::Decode> {
|
||||||
|
/// Handle a XCMP message.
|
||||||
|
fn handle_xcmp_message(src: ParaId, msg: &Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Something that can send XCMP messages.
|
||||||
|
pub trait XCMPMessageSender<Message: codec::Encode> {
|
||||||
|
/// Send a XCMP message to the given parachain.
|
||||||
|
fn send_xcmp_message(dest: ParaId, msg: &Message) -> Result<(), ()>;
|
||||||
|
}
|
||||||
@@ -22,7 +22,6 @@ sp-core = { git = "https://github.com/paritytech/substrate", default-features =
|
|||||||
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||||
frame-executive = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
frame-executive = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||||
sp-trie = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
sp-trie = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||||
sp-inherents = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
|
||||||
|
|
||||||
# Polkadot dependencies
|
# Polkadot dependencies
|
||||||
parachain = { package = "polkadot-parachain", git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch", default-features = false, features = [ "wasm-api" ] }
|
parachain = { package = "polkadot-parachain", git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch", default-features = false, features = [ "wasm-api" ] }
|
||||||
|
|||||||
@@ -33,7 +33,11 @@ use codec::{Decode, Encode, EncodeAppend};
|
|||||||
|
|
||||||
use cumulus_primitives::{
|
use cumulus_primitives::{
|
||||||
validation_function_params::ValidationFunctionParams,
|
validation_function_params::ValidationFunctionParams,
|
||||||
well_known_keys::{NEW_VALIDATION_CODE, VALIDATION_FUNCTION_PARAMS},
|
well_known_keys::{
|
||||||
|
NEW_VALIDATION_CODE, PROCESSED_DOWNWARD_MESSAGES, UPWARD_MESSAGES,
|
||||||
|
VALIDATION_FUNCTION_PARAMS,
|
||||||
|
},
|
||||||
|
GenericUpwardMessage,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Stores the global [`Storage`] instance.
|
/// Stores the global [`Storage`] instance.
|
||||||
@@ -92,11 +96,11 @@ pub fn validate_block<B: BlockT, E: ExecuteBlock<B>>(params: ValidationParams) -
|
|||||||
let block_data = crate::ParachainBlockData::<B>::decode(&mut ¶ms.block_data.0[..])
|
let block_data = crate::ParachainBlockData::<B>::decode(&mut ¶ms.block_data.0[..])
|
||||||
.expect("Invalid parachain block data");
|
.expect("Invalid parachain block data");
|
||||||
|
|
||||||
let parent_head = B::Header::decode(&mut ¶ms.parent_head.0[..]).expect("Invalid parent head");
|
let parent_head =
|
||||||
// TODO: Use correct head data
|
B::Header::decode(&mut ¶ms.parent_head.0[..]).expect("Invalid parent head");
|
||||||
|
|
||||||
let head_data = HeadData(block_data.header.encode());
|
let head_data = HeadData(block_data.header.encode());
|
||||||
|
|
||||||
// TODO: Add `PolkadotInherent`.
|
|
||||||
let block = B::new(block_data.header, block_data.extrinsics);
|
let block = B::new(block_data.header, block_data.extrinsics);
|
||||||
assert!(
|
assert!(
|
||||||
parent_head.hash() == *block.header().parent_hash(),
|
parent_head.hash() == *block.header().parent_hash(),
|
||||||
@@ -131,16 +135,30 @@ pub fn validate_block<B: BlockT, E: ExecuteBlock<B>>(params: ValidationParams) -
|
|||||||
|
|
||||||
E::execute_block(block);
|
E::execute_block(block);
|
||||||
|
|
||||||
// if in the course of block execution new validation code was set, insert
|
// If in the course of block execution new validation code was set, insert
|
||||||
// its scheduled upgrade so we can validate that block number later
|
// its scheduled upgrade so we can validate that block number later.
|
||||||
let new_validation_code = storage().get(NEW_VALIDATION_CODE).map(ValidationCode);
|
let new_validation_code = storage().get(NEW_VALIDATION_CODE).map(ValidationCode);
|
||||||
if new_validation_code.is_some() && validation_function_params.code_upgrade_allowed.is_none() {
|
if new_validation_code.is_some() && validation_function_params.code_upgrade_allowed.is_none() {
|
||||||
panic!("attempt to upgrade validation function when not permitted");
|
panic!("Attempt to upgrade validation function when not permitted!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Extract potential upward messages from the storage.
|
||||||
|
let upward_messages = match storage().get(UPWARD_MESSAGES) {
|
||||||
|
Some(encoded) => Vec::<GenericUpwardMessage>::decode(&mut &encoded[..])
|
||||||
|
.expect("Upward messages vec is not correctly encoded in the storage!"),
|
||||||
|
None => Vec::new(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let processed_downward_messages = storage()
|
||||||
|
.get(PROCESSED_DOWNWARD_MESSAGES)
|
||||||
|
.and_then(|v| Decode::decode(&mut &v[..]).ok())
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
ValidationResult {
|
ValidationResult {
|
||||||
head_data,
|
head_data,
|
||||||
new_validation_code,
|
new_validation_code,
|
||||||
|
upward_messages,
|
||||||
|
processed_downward_messages,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,7 +175,11 @@ impl<B: BlockT> WitnessStorage<B> {
|
|||||||
/// Initialize from the given witness data and storage root.
|
/// Initialize from the given witness data and storage root.
|
||||||
///
|
///
|
||||||
/// Returns an error if given storage root was not found in the witness data.
|
/// Returns an error if given storage root was not found in the witness data.
|
||||||
fn new(data: WitnessData, storage_root: B::Hash, params: ValidationFunctionParams) -> Result<Self, &'static str> {
|
fn new(
|
||||||
|
data: WitnessData,
|
||||||
|
storage_root: B::Hash,
|
||||||
|
params: ValidationFunctionParams,
|
||||||
|
) -> Result<Self, &'static str> {
|
||||||
let mut db = MemoryDB::default();
|
let mut db = MemoryDB::default();
|
||||||
data.into_iter().for_each(|i| {
|
data.into_iter().for_each(|i| {
|
||||||
db.insert(EMPTY_PREFIX, &i);
|
db.insert(EMPTY_PREFIX, &i);
|
||||||
@@ -180,8 +202,8 @@ impl<B: BlockT> Storage for WitnessStorage<B> {
|
|||||||
fn get(&self, key: &[u8]) -> Option<Vec<u8>> {
|
fn get(&self, key: &[u8]) -> Option<Vec<u8>> {
|
||||||
match key {
|
match key {
|
||||||
VALIDATION_FUNCTION_PARAMS => Some(self.params.encode()),
|
VALIDATION_FUNCTION_PARAMS => Some(self.params.encode()),
|
||||||
key => {
|
key => self
|
||||||
self.overlay
|
.overlay
|
||||||
.get(key)
|
.get(key)
|
||||||
.cloned()
|
.cloned()
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
@@ -192,8 +214,7 @@ impl<B: BlockT> Storage for WitnessStorage<B> {
|
|||||||
)
|
)
|
||||||
.ok()
|
.ok()
|
||||||
})
|
})
|
||||||
.unwrap_or(None)
|
.unwrap_or(None),
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,8 +230,11 @@ impl<B: BlockT> Storage for WitnessStorage<B> {
|
|||||||
let root = delta_trie_root::<Layout<HashFor<B>>, _, _, _, _, _>(
|
let root = delta_trie_root::<Layout<HashFor<B>>, _, _, _, _, _>(
|
||||||
&mut self.witness_data,
|
&mut self.witness_data,
|
||||||
self.storage_root.clone(),
|
self.storage_root.clone(),
|
||||||
self.overlay.iter().map(|(k, v)| (k.as_ref(), v.as_ref().map(|v| v.as_ref()))),
|
self.overlay
|
||||||
).expect("Calculates storage root");
|
.iter()
|
||||||
|
.map(|(k, v)| (k.as_ref(), v.as_ref().map(|v| v.as_ref()))),
|
||||||
|
)
|
||||||
|
.expect("Calculates storage root");
|
||||||
|
|
||||||
root.encode()
|
root.encode()
|
||||||
}
|
}
|
||||||
@@ -222,8 +246,7 @@ impl<B: BlockT> Storage for WitnessStorage<B> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let trie = match TrieDB::<Layout<HashFor<B>>>::new(&self.witness_data, &self.storage_root)
|
let trie = match TrieDB::<Layout<HashFor<B>>>::new(&self.witness_data, &self.storage_root) {
|
||||||
{
|
|
||||||
Ok(r) => r,
|
Ok(r) => r,
|
||||||
Err(_) => panic!(),
|
Err(_) => panic!(),
|
||||||
};
|
};
|
||||||
@@ -239,10 +262,12 @@ impl<B: BlockT> Storage for WitnessStorage<B> {
|
|||||||
let current_value = self.overlay.entry(key.to_vec()).or_default();
|
let current_value = self.overlay.entry(key.to_vec()).or_default();
|
||||||
|
|
||||||
let item = current_value.take().unwrap_or_default();
|
let item = current_value.take().unwrap_or_default();
|
||||||
*current_value = Some(match Vec::<EncodeOpaqueValue>::append_or_new(item, &value_vec) {
|
*current_value = Some(
|
||||||
|
match Vec::<EncodeOpaqueValue>::append_or_new(item, &value_vec) {
|
||||||
Ok(item) => item,
|
Ok(item) => item,
|
||||||
Err(_) => value_vec.encode(),
|
Err(_) => value_vec.encode(),
|
||||||
});
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ mod tests;
|
|||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub use parachain;
|
pub use parachain;
|
||||||
|
|
||||||
/// Register the `validate_block` function that is used by parachains to validate blocks on a validator.
|
/// Register the `validate_block` function that is used by parachains to validate blocks on a
|
||||||
|
/// validator.
|
||||||
///
|
///
|
||||||
/// Does *nothing* when `std` feature is enabled.
|
/// Does *nothing* when `std` feature is enabled.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -44,9 +44,11 @@ sc-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch
|
|||||||
cumulus-consensus = { path = "../../consensus" }
|
cumulus-consensus = { path = "../../consensus" }
|
||||||
cumulus-collator = { path = "../../collator" }
|
cumulus-collator = { path = "../../collator" }
|
||||||
cumulus-network = { path = "../../network" }
|
cumulus-network = { path = "../../network" }
|
||||||
|
cumulus-primitives = { path = "../../primitives" }
|
||||||
|
|
||||||
# Polkadot dependencies
|
# Polkadot dependencies
|
||||||
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
||||||
|
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
||||||
polkadot-collator = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
polkadot-collator = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
||||||
polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
||||||
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
||||||
@@ -70,8 +72,8 @@ polkadot-runtime = { git = "https://github.com/paritytech/polkadot", branch = "c
|
|||||||
# Substrate dependencies
|
# Substrate dependencies
|
||||||
substrate-test-runtime-client = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
substrate-test-runtime-client = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||||
frame-system = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
frame-system = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||||
|
pallet-grandpa = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||||
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||||
sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||||
sp-version = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
sp-version = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||||
pallet-sudo = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
pallet-sudo = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||||
pallet-grandpa = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -25,7 +25,6 @@ frame-support = { git = "https://github.com/paritytech/substrate", default-featu
|
|||||||
frame-executive = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
frame-executive = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||||
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||||
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||||
pallet-indices = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
|
||||||
pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||||
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||||
pallet-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
pallet-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||||
@@ -34,35 +33,48 @@ pallet-transaction-payment = { git = "https://github.com/paritytech/substrate",
|
|||||||
# Cumulus dependencies
|
# Cumulus dependencies
|
||||||
cumulus-runtime = { path = "../../../runtime", default-features = false }
|
cumulus-runtime = { path = "../../../runtime", default-features = false }
|
||||||
cumulus-parachain-upgrade = { path = "../../../parachain-upgrade", default-features = false }
|
cumulus-parachain-upgrade = { path = "../../../parachain-upgrade", default-features = false }
|
||||||
|
cumulus-message-broker = { path = "../../../message-broker", default-features = false }
|
||||||
|
cumulus-upward-message = { path = "../../../upward-message", default-features = false }
|
||||||
|
cumulus-primitives = { path = "../../../primitives", default-features = false }
|
||||||
|
|
||||||
|
# Polkadot dependencies
|
||||||
|
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch", default-features = false }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.6" }
|
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.6" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ['std']
|
default = [ "std" ]
|
||||||
std = [
|
std = [
|
||||||
'codec/std',
|
"codec/std",
|
||||||
'serde',
|
"serde",
|
||||||
'sp-api/std',
|
"sp-api/std",
|
||||||
'sp-std/std',
|
"sp-std/std",
|
||||||
'sp-io/std',
|
"sp-io/std",
|
||||||
'sp-core/std',
|
"sp-core/std",
|
||||||
'sp-runtime/std',
|
"sp-runtime/std",
|
||||||
'sp-version/std',
|
"sp-version/std",
|
||||||
'sp-offchain/std',
|
"sp-offchain/std",
|
||||||
'sp-session/std',
|
"sp-session/std",
|
||||||
'sp-block-builder/std',
|
"sp-block-builder/std",
|
||||||
'sp-transaction-pool/std',
|
"sp-transaction-pool/std",
|
||||||
'sp-inherents/std',
|
"sp-inherents/std",
|
||||||
'frame-support/std',
|
"frame-support/std",
|
||||||
'frame-executive/std',
|
"frame-executive/std",
|
||||||
'frame-system/std',
|
"frame-system/std",
|
||||||
'pallet-balances/std',
|
"pallet-balances/std",
|
||||||
'pallet-indices/std',
|
"pallet-randomness-collective-flip/std",
|
||||||
'pallet-randomness-collective-flip/std',
|
"pallet-timestamp/std",
|
||||||
'pallet-timestamp/std',
|
"pallet-sudo/std",
|
||||||
'pallet-sudo/std',
|
"pallet-transaction-payment/std",
|
||||||
'pallet-transaction-payment/std',
|
"cumulus-runtime/std",
|
||||||
'cumulus-runtime/std',
|
"cumulus-parachain-upgrade/std",
|
||||||
'cumulus-parachain-upgrade/std',
|
"cumulus-message-broker/std",
|
||||||
|
"cumulus-upward-message/std",
|
||||||
|
"cumulus-primitives/std",
|
||||||
|
"polkadot-parachain/std",
|
||||||
|
]
|
||||||
|
# Will be enabled by the `wasm-builder` when building the runtime for WASM.
|
||||||
|
runtime-wasm = [
|
||||||
|
"cumulus-upward-message/runtime-wasm",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -26,20 +26,22 @@ use sp_api::impl_runtime_apis;
|
|||||||
use sp_core::OpaqueMetadata;
|
use sp_core::OpaqueMetadata;
|
||||||
use sp_runtime::{
|
use sp_runtime::{
|
||||||
create_runtime_str, generic, impl_opaque_keys,
|
create_runtime_str, generic, impl_opaque_keys,
|
||||||
traits::{BlakeTwo256, Block as BlockT, Saturating, StaticLookup, Verify},
|
traits::{BlakeTwo256, Block as BlockT, IdentifyAccount, IdentityLookup, Saturating, Verify},
|
||||||
transaction_validity::{TransactionSource, TransactionValidity},
|
transaction_validity::{TransactionSource, TransactionValidity},
|
||||||
AnySignature, ApplyExtrinsicResult,
|
ApplyExtrinsicResult, MultiSignature,
|
||||||
};
|
};
|
||||||
use sp_std::prelude::*;
|
use sp_std::prelude::*;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use sp_version::NativeVersion;
|
use sp_version::NativeVersion;
|
||||||
use sp_version::RuntimeVersion;
|
use sp_version::RuntimeVersion;
|
||||||
|
|
||||||
|
mod message_example;
|
||||||
|
|
||||||
// A few exports that help ease life for downstream crates.
|
// A few exports that help ease life for downstream crates.
|
||||||
pub use frame_support::{
|
pub use frame_support::{
|
||||||
construct_runtime, parameter_types,
|
construct_runtime, parameter_types,
|
||||||
traits::Randomness,
|
traits::Randomness,
|
||||||
weights::{IdentityFee, Weight},
|
weights::{constants::WEIGHT_PER_SECOND, IdentityFee, Weight},
|
||||||
StorageValue,
|
StorageValue,
|
||||||
};
|
};
|
||||||
pub use pallet_balances::Call as BalancesCall;
|
pub use pallet_balances::Call as BalancesCall;
|
||||||
@@ -52,11 +54,11 @@ pub use sp_runtime::{Perbill, Permill};
|
|||||||
pub type BlockNumber = u32;
|
pub type BlockNumber = u32;
|
||||||
|
|
||||||
/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
|
/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
|
||||||
pub type Signature = AnySignature;
|
pub type Signature = MultiSignature;
|
||||||
|
|
||||||
/// Some way of identifying an account on the chain. We intentionally make it equivalent
|
/// Some way of identifying an account on the chain. We intentionally make it equivalent
|
||||||
/// to the public key of our transaction signing scheme.
|
/// to the public key of our transaction signing scheme.
|
||||||
pub type AccountId = <Signature as Verify>::Signer;
|
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
|
||||||
|
|
||||||
/// The type for looking up accounts. We don't expect more than 4 billion of them, but you
|
/// The type for looking up accounts. We don't expect more than 4 billion of them, but you
|
||||||
/// never know...
|
/// never know...
|
||||||
@@ -122,6 +124,12 @@ pub const DAYS: BlockNumber = HOURS * 24;
|
|||||||
// 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks.
|
// 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks.
|
||||||
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
|
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
|
||||||
|
|
||||||
|
#[derive(codec::Encode, codec::Decode)]
|
||||||
|
pub enum XCMPMessage<XAccountId, XBalance> {
|
||||||
|
/// Transfer tokens to the given account from the Parachain account.
|
||||||
|
TransferToken(XAccountId, XBalance),
|
||||||
|
}
|
||||||
|
|
||||||
/// The version infromation used to identify this runtime when compiled natively.
|
/// The version infromation used to identify this runtime when compiled natively.
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub fn native_version() -> NativeVersion {
|
pub fn native_version() -> NativeVersion {
|
||||||
@@ -133,7 +141,7 @@ pub fn native_version() -> NativeVersion {
|
|||||||
|
|
||||||
parameter_types! {
|
parameter_types! {
|
||||||
pub const BlockHashCount: BlockNumber = 250;
|
pub const BlockHashCount: BlockNumber = 250;
|
||||||
pub const MaximumBlockWeight: Weight = 1_000_000;
|
pub const MaximumBlockWeight: Weight = 2 * WEIGHT_PER_SECOND;
|
||||||
/// Assume 10% of weight for average on_initialize calls.
|
/// Assume 10% of weight for average on_initialize calls.
|
||||||
pub MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get()
|
pub MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get()
|
||||||
.saturating_sub(Perbill::from_percent(10)) * MaximumBlockWeight::get();
|
.saturating_sub(Perbill::from_percent(10)) * MaximumBlockWeight::get();
|
||||||
@@ -149,7 +157,7 @@ impl frame_system::Trait for Runtime {
|
|||||||
/// The aggregated dispatch type that is available for extrinsics.
|
/// The aggregated dispatch type that is available for extrinsics.
|
||||||
type Call = Call;
|
type Call = Call;
|
||||||
/// The lookup mechanism to get account ID from whatever is passed in dispatchers.
|
/// The lookup mechanism to get account ID from whatever is passed in dispatchers.
|
||||||
type Lookup = Indices;
|
type Lookup = IdentityLookup<AccountId>;
|
||||||
/// The index type for storing how many extrinsics an account has signed.
|
/// The index type for storing how many extrinsics an account has signed.
|
||||||
type Index = Index;
|
type Index = Index;
|
||||||
/// The index type for blocks.
|
/// The index type for blocks.
|
||||||
@@ -178,24 +186,13 @@ impl frame_system::Trait for Runtime {
|
|||||||
type ModuleToIndex = ModuleToIndex;
|
type ModuleToIndex = ModuleToIndex;
|
||||||
type AccountData = pallet_balances::AccountData<Balance>;
|
type AccountData = pallet_balances::AccountData<Balance>;
|
||||||
type OnNewAccount = ();
|
type OnNewAccount = ();
|
||||||
type OnKilledAccount = Balances;
|
type OnKilledAccount = ();
|
||||||
type DbWeight = ();
|
type DbWeight = ();
|
||||||
type ExtrinsicBaseWeight = ExtrinsicBaseWeight;
|
type ExtrinsicBaseWeight = ExtrinsicBaseWeight;
|
||||||
type BlockExecutionWeight = ();
|
type BlockExecutionWeight = ();
|
||||||
type MaximumExtrinsicWeight = MaximumExtrinsicWeight;
|
type MaximumExtrinsicWeight = MaximumExtrinsicWeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
parameter_types! {
|
|
||||||
pub const IndexDeposit: Balance = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl pallet_indices::Trait for Runtime {
|
|
||||||
type AccountIndex = u32;
|
|
||||||
type Event = Event;
|
|
||||||
type Currency = Balances;
|
|
||||||
type Deposit = IndexDeposit;
|
|
||||||
}
|
|
||||||
|
|
||||||
parameter_types! {
|
parameter_types! {
|
||||||
pub const MinimumPeriod: u64 = SLOT_DURATION / 2;
|
pub const MinimumPeriod: u64 = SLOT_DURATION / 2;
|
||||||
}
|
}
|
||||||
@@ -242,6 +239,27 @@ impl cumulus_parachain_upgrade::Trait for Runtime {
|
|||||||
type OnValidationFunctionParams = ();
|
type OnValidationFunctionParams = ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parameter_types! {
|
||||||
|
pub storage ParachainId: cumulus_primitives::ParaId = 100.into();
|
||||||
|
}
|
||||||
|
|
||||||
|
impl cumulus_message_broker::Trait for Runtime {
|
||||||
|
type Event = Event;
|
||||||
|
type DownwardMessageHandlers = TokenDealer;
|
||||||
|
type UpwardMessage = cumulus_upward_message::WestendUpwardMessage;
|
||||||
|
type ParachainId = ParachainId;
|
||||||
|
type XCMPMessage = XCMPMessage<AccountId, Balance>;
|
||||||
|
type XCMPMessageHandlers = TokenDealer;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl message_example::Trait for Runtime {
|
||||||
|
type Event = Event;
|
||||||
|
type UpwardMessageSender = MessageBroker;
|
||||||
|
type UpwardMessage = cumulus_upward_message::WestendUpwardMessage;
|
||||||
|
type Currency = Balances;
|
||||||
|
type XCMPMessageSender = MessageBroker;
|
||||||
|
}
|
||||||
|
|
||||||
construct_runtime! {
|
construct_runtime! {
|
||||||
pub enum Runtime where
|
pub enum Runtime where
|
||||||
Block = Block,
|
Block = Block,
|
||||||
@@ -250,16 +268,18 @@ construct_runtime! {
|
|||||||
{
|
{
|
||||||
System: frame_system::{Module, Call, Storage, Config, Event<T>},
|
System: frame_system::{Module, Call, Storage, Config, Event<T>},
|
||||||
Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},
|
Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},
|
||||||
Indices: pallet_indices::{Module, Call, Storage, Config<T>, Event<T>},
|
|
||||||
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
|
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
|
||||||
Sudo: pallet_sudo::{Module, Call, Storage, Config<T>, Event<T>},
|
Sudo: pallet_sudo::{Module, Call, Storage, Config<T>, Event<T>},
|
||||||
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},
|
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},
|
||||||
ParachainUpgrade: cumulus_parachain_upgrade::{Module, Call, Storage, Inherent, Event},
|
ParachainUpgrade: cumulus_parachain_upgrade::{Module, Call, Storage, Inherent, Event},
|
||||||
|
MessageBroker: cumulus_message_broker::{Module, Call, Inherent, Event<T>},
|
||||||
|
TokenDealer: message_example::{Module, Call, Event<T>, Config},
|
||||||
|
TransactionPayment: pallet_transaction_payment::{Module, Storage},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The address format for describing accounts.
|
/// The address format for describing accounts.
|
||||||
pub type Address = <Indices as StaticLookup>::Source;
|
pub type Address = AccountId;
|
||||||
/// Block header type as expected by this runtime.
|
/// Block header type as expected by this runtime.
|
||||||
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
||||||
/// Block type as expected by this runtime.
|
/// Block type as expected by this runtime.
|
||||||
|
|||||||
@@ -0,0 +1,179 @@
|
|||||||
|
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||||
|
// This file is part of Cumulus.
|
||||||
|
|
||||||
|
// Cumulus 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.
|
||||||
|
|
||||||
|
// Cumulus 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//! Example Pallet that shows how to send upward messages and how to receive
|
||||||
|
//! downward messages.
|
||||||
|
|
||||||
|
use frame_support::{
|
||||||
|
decl_event, decl_module, decl_storage,
|
||||||
|
traits::{Currency, ExistenceRequirement, WithdrawReason},
|
||||||
|
};
|
||||||
|
use frame_system::ensure_signed;
|
||||||
|
|
||||||
|
use crate::XCMPMessage;
|
||||||
|
use codec::{Decode, Encode};
|
||||||
|
use cumulus_primitives::{
|
||||||
|
relay_chain::DownwardMessage,
|
||||||
|
xcmp::{XCMPMessageHandler, XCMPMessageSender},
|
||||||
|
DownwardMessageHandler, ParaId, UpwardMessageOrigin, UpwardMessageSender,
|
||||||
|
};
|
||||||
|
use cumulus_upward_message::BalancesMessage;
|
||||||
|
use polkadot_parachain::primitives::AccountIdConversion;
|
||||||
|
use sp_runtime::DispatchResult;
|
||||||
|
|
||||||
|
type BalanceOf<T> =
|
||||||
|
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
|
||||||
|
|
||||||
|
/// Configuration trait of this pallet.
|
||||||
|
pub trait Trait: frame_system::Trait {
|
||||||
|
/// Event type used by the runtime.
|
||||||
|
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
|
||||||
|
|
||||||
|
/// The sender of upward messages.
|
||||||
|
type UpwardMessageSender: UpwardMessageSender<Self::UpwardMessage>;
|
||||||
|
|
||||||
|
/// The upward message type used by the Parachain runtime.
|
||||||
|
type UpwardMessage: codec::Codec + BalancesMessage<Self::AccountId, BalanceOf<Self>>;
|
||||||
|
|
||||||
|
/// Currency of the runtime.
|
||||||
|
type Currency: Currency<Self::AccountId>;
|
||||||
|
|
||||||
|
/// The sender of XCMP messages.
|
||||||
|
type XCMPMessageSender: XCMPMessageSender<XCMPMessage<Self::AccountId, BalanceOf<Self>>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This pallet's storage items.
|
||||||
|
decl_storage! {
|
||||||
|
trait Store for Module<T: Trait> as ParachainUpgrade {}
|
||||||
|
add_extra_genesis {
|
||||||
|
config(parachain_id): ParaId;
|
||||||
|
build(|config: &Self| {
|
||||||
|
// This is basically a hack to make the parachain id easily configurable.
|
||||||
|
// Could also be done differently, but yeah..
|
||||||
|
crate::ParachainId::set(&config.parachain_id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
decl_event! {
|
||||||
|
pub enum Event<T> where
|
||||||
|
AccountId = <T as frame_system::Trait>::AccountId,
|
||||||
|
Balance = BalanceOf<T>
|
||||||
|
{
|
||||||
|
/// Transferred tokens to the account on the relay chain.
|
||||||
|
TransferredTokensToRelayChain(AccountId, Balance),
|
||||||
|
/// Transferred tokens to the account on request from the relay chain.
|
||||||
|
TransferredTokensFromRelayChain(AccountId, Balance),
|
||||||
|
/// Transferred tokens to the account from the given parachain account.
|
||||||
|
TransferredTokensViaXCMP(ParaId, AccountId, Balance, DispatchResult),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
decl_module! {
|
||||||
|
pub struct Module<T: Trait> for enum Call where origin: T::Origin, system = frame_system {
|
||||||
|
/// Transfer `amount` of tokens on the relay chain from the Parachain account to
|
||||||
|
/// the given `dest` account.
|
||||||
|
#[weight = 10]
|
||||||
|
fn transfer_tokens_to_relay_chain(origin, dest: T::AccountId, amount: BalanceOf<T>) {
|
||||||
|
let who = ensure_signed(origin)?;
|
||||||
|
|
||||||
|
let _ = T::Currency::withdraw(
|
||||||
|
&who,
|
||||||
|
amount,
|
||||||
|
WithdrawReason::Transfer.into(),
|
||||||
|
ExistenceRequirement::AllowDeath,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let msg = <T as Trait>::UpwardMessage::transfer(dest.clone(), amount.clone());
|
||||||
|
<T as Trait>::UpwardMessageSender::send_upward_message(&msg, UpwardMessageOrigin::Signed)
|
||||||
|
.expect("Should not fail; qed");
|
||||||
|
|
||||||
|
Self::deposit_event(Event::<T>::TransferredTokensToRelayChain(dest, amount));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Transfer `amount` of tokens to another parachain.
|
||||||
|
#[weight = 10]
|
||||||
|
fn transfer_tokens_to_parachain_chain(
|
||||||
|
origin,
|
||||||
|
para_id: u32,
|
||||||
|
dest: T::AccountId,
|
||||||
|
amount: BalanceOf<T>,
|
||||||
|
) {
|
||||||
|
//TODO we don't make sure that the parachain has some tokens on the other parachain.
|
||||||
|
let who = ensure_signed(origin)?;
|
||||||
|
|
||||||
|
let _ = T::Currency::withdraw(
|
||||||
|
&who,
|
||||||
|
amount,
|
||||||
|
WithdrawReason::Transfer.into(),
|
||||||
|
ExistenceRequirement::AllowDeath,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
T::XCMPMessageSender::send_xcmp_message(
|
||||||
|
para_id.into(),
|
||||||
|
&XCMPMessage::TransferToken(dest, amount),
|
||||||
|
).expect("Should not fail; qed");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deposit_event() = default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// This is a hack to convert from one generic type to another where we are sure that both are the
|
||||||
|
/// same type/use the same encoding.
|
||||||
|
fn convert_hack<O: Decode>(input: &impl Encode) -> O {
|
||||||
|
input.using_encoded(|e| Decode::decode(&mut &e[..]).expect("Must be compatible; qed"))
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Trait> DownwardMessageHandler for Module<T> {
|
||||||
|
fn handle_downward_message(msg: &DownwardMessage) {
|
||||||
|
match msg {
|
||||||
|
DownwardMessage::TransferInto(dest, amount, _) => {
|
||||||
|
let dest = convert_hack(&dest);
|
||||||
|
let amount: BalanceOf<T> = convert_hack(amount);
|
||||||
|
|
||||||
|
let _ = T::Currency::deposit_creating(&dest, amount.clone());
|
||||||
|
|
||||||
|
Self::deposit_event(Event::<T>::TransferredTokensFromRelayChain(dest, amount));
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Trait> XCMPMessageHandler<XCMPMessage<T::AccountId, BalanceOf<T>>> for Module<T> {
|
||||||
|
fn handle_xcmp_message(src: ParaId, msg: &XCMPMessage<T::AccountId, BalanceOf<T>>) {
|
||||||
|
match msg {
|
||||||
|
XCMPMessage::TransferToken(dest, amount) => {
|
||||||
|
let para_account = src.clone().into_account();
|
||||||
|
|
||||||
|
let res = T::Currency::transfer(
|
||||||
|
¶_account,
|
||||||
|
dest,
|
||||||
|
amount.clone(),
|
||||||
|
ExistenceRequirement::AllowDeath,
|
||||||
|
);
|
||||||
|
|
||||||
|
Self::deposit_event(Event::<T>::TransferredTokensViaXCMP(
|
||||||
|
src,
|
||||||
|
dest.clone(),
|
||||||
|
amount.clone(),
|
||||||
|
res,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,11 +14,14 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
use cumulus_primitives::ParaId;
|
||||||
use parachain_runtime::{
|
use parachain_runtime::{
|
||||||
AccountId, BalancesConfig, GenesisConfig, IndicesConfig, SudoConfig, SystemConfig, WASM_BINARY,
|
AccountId, BalancesConfig, GenesisConfig, Signature, SudoConfig, SystemConfig,
|
||||||
|
TokenDealerConfig, WASM_BINARY,
|
||||||
};
|
};
|
||||||
use sc_service;
|
use sc_service::ChainType;
|
||||||
use sp_core::{Pair, Public};
|
use sp_core::{sr25519, Pair, Public};
|
||||||
|
use sp_runtime::traits::{IdentifyAccount, Verify};
|
||||||
|
|
||||||
/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
|
/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
|
||||||
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>;
|
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>;
|
||||||
@@ -30,42 +33,39 @@ pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Pu
|
|||||||
.public()
|
.public()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper function to generate stash, controller and session key from seed
|
type AccountPublic = <Signature as Verify>::Signer;
|
||||||
pub fn get_authority_keys_from_seed(seed: &str) -> (AccountId, AccountId) {
|
|
||||||
(
|
/// Helper function to generate an account ID from seed
|
||||||
get_from_seed::<AccountId>(&format!("{}//stash", seed)),
|
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
|
||||||
get_from_seed::<AccountId>(seed),
|
where
|
||||||
)
|
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
|
||||||
|
{
|
||||||
|
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the chain spec.
|
pub fn get_chain_spec(id: ParaId) -> ChainSpec {
|
||||||
pub fn get_chain_spec() -> ChainSpec {
|
|
||||||
ChainSpec::from_genesis(
|
ChainSpec::from_genesis(
|
||||||
"Local Testnet",
|
"Local Testnet",
|
||||||
"parachain_local_testnet",
|
"local_testnet",
|
||||||
sc_service::ChainType::Local,
|
ChainType::Local,
|
||||||
|| {
|
move || {
|
||||||
testnet_genesis(
|
testnet_genesis(
|
||||||
|
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||||
vec![
|
vec![
|
||||||
get_authority_keys_from_seed("Alice"),
|
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||||
get_authority_keys_from_seed("Bob"),
|
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||||
|
get_account_id_from_seed::<sr25519::Public>("Charlie"),
|
||||||
|
get_account_id_from_seed::<sr25519::Public>("Dave"),
|
||||||
|
get_account_id_from_seed::<sr25519::Public>("Eve"),
|
||||||
|
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
|
||||||
|
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
|
||||||
|
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
|
||||||
|
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
|
||||||
|
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
|
||||||
|
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
|
||||||
|
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
|
||||||
],
|
],
|
||||||
get_from_seed::<AccountId>("Alice"),
|
id,
|
||||||
vec![
|
|
||||||
get_from_seed::<AccountId>("Alice"),
|
|
||||||
get_from_seed::<AccountId>("Bob"),
|
|
||||||
get_from_seed::<AccountId>("Charlie"),
|
|
||||||
get_from_seed::<AccountId>("Dave"),
|
|
||||||
get_from_seed::<AccountId>("Eve"),
|
|
||||||
get_from_seed::<AccountId>("Ferdie"),
|
|
||||||
get_from_seed::<AccountId>("Alice//stash"),
|
|
||||||
get_from_seed::<AccountId>("Bob//stash"),
|
|
||||||
get_from_seed::<AccountId>("Charlie//stash"),
|
|
||||||
get_from_seed::<AccountId>("Dave//stash"),
|
|
||||||
get_from_seed::<AccountId>("Eve//stash"),
|
|
||||||
get_from_seed::<AccountId>("Ferdie//stash"),
|
|
||||||
],
|
|
||||||
true,
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
vec![],
|
vec![],
|
||||||
@@ -77,19 +77,15 @@ pub fn get_chain_spec() -> ChainSpec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn testnet_genesis(
|
fn testnet_genesis(
|
||||||
_initial_authorities: Vec<(AccountId, AccountId)>,
|
|
||||||
root_key: AccountId,
|
root_key: AccountId,
|
||||||
endowed_accounts: Vec<AccountId>,
|
endowed_accounts: Vec<AccountId>,
|
||||||
_enable_println: bool,
|
id: ParaId,
|
||||||
) -> GenesisConfig {
|
) -> GenesisConfig {
|
||||||
GenesisConfig {
|
GenesisConfig {
|
||||||
frame_system: Some(SystemConfig {
|
frame_system: Some(SystemConfig {
|
||||||
code: WASM_BINARY.to_vec(),
|
code: WASM_BINARY.to_vec(),
|
||||||
changes_trie_config: Default::default(),
|
changes_trie_config: Default::default(),
|
||||||
}),
|
}),
|
||||||
pallet_indices: Some(IndicesConfig {
|
|
||||||
indices: vec![],
|
|
||||||
}),
|
|
||||||
pallet_balances: Some(BalancesConfig {
|
pallet_balances: Some(BalancesConfig {
|
||||||
balances: endowed_accounts
|
balances: endowed_accounts
|
||||||
.iter()
|
.iter()
|
||||||
@@ -98,5 +94,6 @@ fn testnet_genesis(
|
|||||||
.collect(),
|
.collect(),
|
||||||
}),
|
}),
|
||||||
pallet_sudo: Some(SudoConfig { key: root_key }),
|
pallet_sudo: Some(SudoConfig { key: root_key }),
|
||||||
|
message_example: Some(TokenDealerConfig { parachain_id: id }),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,28 @@ pub struct ExportGenesisStateCommand {
|
|||||||
/// Output file name or stdout if unspecified.
|
/// Output file name or stdout if unspecified.
|
||||||
#[structopt(parse(from_os_str))]
|
#[structopt(parse(from_os_str))]
|
||||||
pub output: Option<PathBuf>,
|
pub output: Option<PathBuf>,
|
||||||
|
|
||||||
|
/// Id of the parachain this state is for.
|
||||||
|
#[structopt(long, default_value = "100")]
|
||||||
|
pub parachain_id: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, StructOpt)]
|
||||||
|
pub struct RunCmd {
|
||||||
|
#[structopt(flatten)]
|
||||||
|
pub base: sc_cli::RunCmd,
|
||||||
|
|
||||||
|
/// Id of the parachain this collator collates for.
|
||||||
|
#[structopt(long, default_value = "100")]
|
||||||
|
pub parachain_id: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::ops::Deref for RunCmd {
|
||||||
|
type Target = sc_cli::RunCmd;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.base
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, StructOpt)]
|
#[derive(Debug, StructOpt)]
|
||||||
@@ -55,7 +77,7 @@ pub struct Cli {
|
|||||||
pub subcommand: Option<Subcommand>,
|
pub subcommand: Option<Subcommand>,
|
||||||
|
|
||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
pub run: sc_cli::RunCmd,
|
pub run: RunCmd,
|
||||||
|
|
||||||
/// Relaychain arguments
|
/// Relaychain arguments
|
||||||
#[structopt(raw = true)]
|
#[structopt(raw = true)]
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ use crate::cli::{Cli, PolkadotCli, Subcommand};
|
|||||||
use codec::Encode;
|
use codec::Encode;
|
||||||
use log::info;
|
use log::info;
|
||||||
use parachain_runtime::Block;
|
use parachain_runtime::Block;
|
||||||
|
use polkadot_parachain::primitives::AccountIdConversion;
|
||||||
use sc_cli::{
|
use sc_cli::{
|
||||||
CliConfiguration, Error, ImportParams, KeystoreParams, NetworkParams, Result, SharedParams,
|
CliConfiguration, Error, ImportParams, KeystoreParams, NetworkParams, Result, SharedParams,
|
||||||
SubstrateCli,
|
SubstrateCli,
|
||||||
@@ -30,8 +31,8 @@ use sp_runtime::{
|
|||||||
traits::{Block as BlockT, Hash as HashT, Header as HeaderT, Zero},
|
traits::{Block as BlockT, Hash as HashT, Header as HeaderT, Zero},
|
||||||
BuildStorage,
|
BuildStorage,
|
||||||
};
|
};
|
||||||
use std::net::SocketAddr;
|
use std::{net::SocketAddr, sync::Arc};
|
||||||
use std::sync::Arc;
|
use cumulus_primitives::ParaId;
|
||||||
|
|
||||||
impl SubstrateCli for Cli {
|
impl SubstrateCli for Cli {
|
||||||
fn impl_name() -> &'static str {
|
fn impl_name() -> &'static str {
|
||||||
@@ -66,7 +67,8 @@ impl SubstrateCli for Cli {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn load_spec(&self, _id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
|
fn load_spec(&self, _id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
|
||||||
Ok(Box::new(chain_spec::get_chain_spec()))
|
// Such a hack :(
|
||||||
|
Ok(Box::new(chain_spec::get_chain_spec(self.run.parachain_id.into())))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,12 +116,11 @@ impl SubstrateCli for PolkadotCli {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_genesis_state() -> Result<Block> {
|
fn generate_genesis_state(para_id: ParaId) -> Result<Block> {
|
||||||
let storage = (&chain_spec::get_chain_spec()).build_storage()?;
|
let storage = (&chain_spec::get_chain_spec(para_id)).build_storage()?;
|
||||||
|
|
||||||
let child_roots = storage.children_default.iter().map(|(sk, child_content)| {
|
let child_roots = storage.children_default.iter().map(|(sk, child_content)| {
|
||||||
let state_root =
|
let state_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
||||||
<<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
|
||||||
child_content.data.clone().into_iter().collect(),
|
child_content.data.clone().into_iter().collect(),
|
||||||
);
|
);
|
||||||
(sk.clone(), state_root.encode())
|
(sk.clone(), state_root.encode())
|
||||||
@@ -128,9 +129,8 @@ fn generate_genesis_state() -> Result<Block> {
|
|||||||
storage.top.clone().into_iter().chain(child_roots).collect(),
|
storage.top.clone().into_iter().chain(child_roots).collect(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let extrinsics_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
let extrinsics_root =
|
||||||
Vec::new(),
|
<<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(Vec::new());
|
||||||
);
|
|
||||||
|
|
||||||
Ok(Block::new(
|
Ok(Block::new(
|
||||||
<<Block as BlockT>::Header as HeaderT>::new(
|
<<Block as BlockT>::Header as HeaderT>::new(
|
||||||
@@ -157,7 +157,7 @@ pub fn run() -> Result<()> {
|
|||||||
Some(Subcommand::ExportGenesisState(params)) => {
|
Some(Subcommand::ExportGenesisState(params)) => {
|
||||||
sc_cli::init_logger("");
|
sc_cli::init_logger("");
|
||||||
|
|
||||||
let block = generate_genesis_state()?;
|
let block = generate_genesis_state(params.parachain_id.into())?;
|
||||||
let header_hex = format!("0x{:?}", HexDisplay::from(&block.header().encode()));
|
let header_hex = format!("0x{:?}", HexDisplay::from(&block.header().encode()));
|
||||||
|
|
||||||
if let Some(output) = ¶ms.output {
|
if let Some(output) = ¶ms.output {
|
||||||
@@ -174,13 +174,14 @@ pub fn run() -> Result<()> {
|
|||||||
let grandpa_pause = if polkadot_cli.run.grandpa_pause.is_empty() {
|
let grandpa_pause = if polkadot_cli.run.grandpa_pause.is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some((polkadot_cli.run.grandpa_pause[0], polkadot_cli.run.grandpa_pause[1]))
|
Some((
|
||||||
|
polkadot_cli.run.grandpa_pause[0],
|
||||||
|
polkadot_cli.run.grandpa_pause[1],
|
||||||
|
))
|
||||||
};
|
};
|
||||||
|
|
||||||
runner.run_node(
|
runner.run_node(
|
||||||
|config| {
|
|config| polkadot_service::polkadot_new_light(config),
|
||||||
polkadot_service::polkadot_new_light(config)
|
|
||||||
},
|
|
||||||
|config| {
|
|config| {
|
||||||
polkadot_service::polkadot_new_full(
|
polkadot_service::polkadot_new_full(
|
||||||
config,
|
config,
|
||||||
@@ -190,22 +191,23 @@ pub fn run() -> Result<()> {
|
|||||||
6000,
|
6000,
|
||||||
grandpa_pause,
|
grandpa_pause,
|
||||||
None,
|
None,
|
||||||
).map(|(s, _, _)| s)
|
|
||||||
},
|
|
||||||
polkadot_service::PolkadotExecutor::native_version().runtime_version
|
|
||||||
)
|
)
|
||||||
|
.map(|(s, _, _)| s)
|
||||||
},
|
},
|
||||||
|
polkadot_service::PolkadotExecutor::native_version().runtime_version,
|
||||||
|
)
|
||||||
|
}
|
||||||
Some(Subcommand::PolkadotValidationWorker(cmd)) => {
|
Some(Subcommand::PolkadotValidationWorker(cmd)) => {
|
||||||
sc_cli::init_logger("");
|
sc_cli::init_logger("");
|
||||||
polkadot_service::run_validation_worker(&cmd.mem_id)?;
|
polkadot_service::run_validation_worker(&cmd.mem_id)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
}
|
||||||
None => {
|
None => {
|
||||||
let runner = cli.create_runner(&cli.run)?;
|
let runner = cli.create_runner(&*cli.run)?;
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
let key = Arc::new(sp_core::Pair::from_seed(&[10; 32]));
|
let key = Arc::new(sp_core::Pair::generate().0);
|
||||||
|
|
||||||
let mut polkadot_cli = PolkadotCli::from_iter(
|
let mut polkadot_cli = PolkadotCli::from_iter(
|
||||||
[PolkadotCli::executable_name().to_string()]
|
[PolkadotCli::executable_name().to_string()]
|
||||||
@@ -213,6 +215,14 @@ pub fn run() -> Result<()> {
|
|||||||
.chain(cli.relaychain_args.iter()),
|
.chain(cli.relaychain_args.iter()),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let id = ParaId::from(cli.run.parachain_id);
|
||||||
|
|
||||||
|
let parachain_account =
|
||||||
|
AccountIdConversion::<polkadot_primitives::AccountId>::into_account(&id);
|
||||||
|
|
||||||
|
let block = generate_genesis_state(id)?;
|
||||||
|
let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));
|
||||||
|
|
||||||
runner.run_full_node(
|
runner.run_full_node(
|
||||||
|config| {
|
|config| {
|
||||||
polkadot_cli.base_path =
|
polkadot_cli.base_path =
|
||||||
@@ -226,9 +236,11 @@ pub fn run() -> Result<()> {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
info!("Parachain id: {:?}", crate::PARA_ID);
|
info!("Parachain id: {:?}", id);
|
||||||
|
info!("Parachain Account: {}", parachain_account);
|
||||||
|
info!("Parachain genesis state: {}", genesis_state);
|
||||||
|
|
||||||
crate::service::run_collator(config, key, polkadot_config)
|
crate::service::run_collator(config, key, polkadot_config, id)
|
||||||
},
|
},
|
||||||
parachain_runtime::VERSION,
|
parachain_runtime::VERSION,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -19,17 +19,12 @@
|
|||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
#![warn(unused_extern_crates)]
|
#![warn(unused_extern_crates)]
|
||||||
|
|
||||||
use polkadot_primitives::parachain::Id as ParaId;
|
|
||||||
|
|
||||||
mod chain_spec;
|
mod chain_spec;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod service;
|
mod service;
|
||||||
mod cli;
|
mod cli;
|
||||||
mod command;
|
mod command;
|
||||||
|
|
||||||
/// The parachain id of this parachain.
|
|
||||||
pub const PARA_ID: ParaId = ParaId::new(100);
|
|
||||||
|
|
||||||
fn main() -> sc_cli::Result<()> {
|
fn main() -> sc_cli::Result<()> {
|
||||||
command::run()
|
command::run()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,15 +15,17 @@
|
|||||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use ansi_term::Color;
|
use ansi_term::Color;
|
||||||
use std::sync::Arc;
|
use cumulus_collator::{prepare_collator_config, CollatorBuilder};
|
||||||
use sc_executor::native_executor_instance;
|
|
||||||
use sc_service::{AbstractService, Configuration};
|
|
||||||
use sc_finality_grandpa::{FinalityProofProvider as GrandpaFinalityProofProvider, StorageAndProofProvider};
|
|
||||||
use polkadot_primitives::parachain::CollatorPair;
|
|
||||||
use cumulus_collator::{CollatorBuilder, prepare_collator_config};
|
|
||||||
use futures::FutureExt;
|
|
||||||
pub use sc_executor::NativeExecutor;
|
|
||||||
use cumulus_network::DelayedBlockAnnounceValidator;
|
use cumulus_network::DelayedBlockAnnounceValidator;
|
||||||
|
use futures::FutureExt;
|
||||||
|
use polkadot_primitives::parachain::CollatorPair;
|
||||||
|
use sc_executor::native_executor_instance;
|
||||||
|
pub use sc_executor::NativeExecutor;
|
||||||
|
use sc_finality_grandpa::{
|
||||||
|
FinalityProofProvider as GrandpaFinalityProofProvider, StorageAndProofProvider,
|
||||||
|
};
|
||||||
|
use sc_service::{AbstractService, Configuration};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
// Our native executor instance.
|
// Our native executor instance.
|
||||||
native_executor_instance!(
|
native_executor_instance!(
|
||||||
@@ -47,9 +49,8 @@ macro_rules! new_full_start {
|
|||||||
>($config)?
|
>($config)?
|
||||||
.with_select_chain(|_config, backend| Ok(sc_consensus::LongestChain::new(backend.clone())))?
|
.with_select_chain(|_config, backend| Ok(sc_consensus::LongestChain::new(backend.clone())))?
|
||||||
.with_transaction_pool(|builder| {
|
.with_transaction_pool(|builder| {
|
||||||
let pool_api = Arc::new(sc_transaction_pool::FullChainApi::new(
|
let client = builder.client();
|
||||||
builder.client().clone(),
|
let pool_api = Arc::new(sc_transaction_pool::FullChainApi::new(client.clone()));
|
||||||
));
|
|
||||||
let pool = sc_transaction_pool::BasicPool::new(
|
let pool = sc_transaction_pool::BasicPool::new(
|
||||||
builder.config().transaction_pool.clone(),
|
builder.config().transaction_pool.clone(),
|
||||||
pool_api,
|
pool_api,
|
||||||
@@ -57,19 +58,12 @@ macro_rules! new_full_start {
|
|||||||
);
|
);
|
||||||
Ok(pool)
|
Ok(pool)
|
||||||
})?
|
})?
|
||||||
.with_import_queue(|
|
.with_import_queue(|_config, client, _, _, spawner, registry| {
|
||||||
_config,
|
|
||||||
client,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
spawn_task_handle,
|
|
||||||
registry,
|
|
||||||
| {
|
|
||||||
let import_queue = cumulus_consensus::import_queue::import_queue(
|
let import_queue = cumulus_consensus::import_queue::import_queue(
|
||||||
client.clone(),
|
client.clone(),
|
||||||
client,
|
client,
|
||||||
inherent_data_providers.clone(),
|
inherent_data_providers.clone(),
|
||||||
spawn_task_handle,
|
spawner,
|
||||||
registry,
|
registry,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
@@ -87,6 +81,7 @@ pub fn run_collator(
|
|||||||
parachain_config: Configuration,
|
parachain_config: Configuration,
|
||||||
key: Arc<CollatorPair>,
|
key: Arc<CollatorPair>,
|
||||||
polkadot_config: polkadot_collator::Configuration,
|
polkadot_config: polkadot_collator::Configuration,
|
||||||
|
id: polkadot_primitives::parachain::Id,
|
||||||
) -> sc_service::error::Result<impl AbstractService> {
|
) -> sc_service::error::Result<impl AbstractService> {
|
||||||
let parachain_config = prepare_collator_config(parachain_config);
|
let parachain_config = prepare_collator_config(parachain_config);
|
||||||
|
|
||||||
@@ -104,9 +99,7 @@ pub fn run_collator(
|
|||||||
let provider = client as Arc<dyn StorageAndProofProvider<_, _>>;
|
let provider = client as Arc<dyn StorageAndProofProvider<_, _>>;
|
||||||
Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, provider)) as _)
|
Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, provider)) as _)
|
||||||
})?
|
})?
|
||||||
.with_block_announce_validator(|_client| {
|
.with_block_announce_validator(|_client| Box::new(block_announce_validator_copy))?
|
||||||
Box::new(block_announce_validator_copy)
|
|
||||||
})?
|
|
||||||
.build_full()?;
|
.build_full()?;
|
||||||
|
|
||||||
let registry = service.prometheus_registry();
|
let registry = service.prometheus_registry();
|
||||||
@@ -120,14 +113,12 @@ pub fn run_collator(
|
|||||||
let block_import = service.client();
|
let block_import = service.client();
|
||||||
let client = service.client();
|
let client = service.client();
|
||||||
let network = service.network();
|
let network = service.network();
|
||||||
let announce_block = Arc::new(move |hash, data| {
|
let announce_block = Arc::new(move |hash, data| network.announce_block(hash, data));
|
||||||
network.announce_block(hash, data)
|
|
||||||
});
|
|
||||||
let builder = CollatorBuilder::new(
|
let builder = CollatorBuilder::new(
|
||||||
proposer_factory,
|
proposer_factory,
|
||||||
inherent_data_providers,
|
inherent_data_providers,
|
||||||
block_import,
|
block_import,
|
||||||
crate::PARA_ID,
|
id,
|
||||||
client,
|
client,
|
||||||
announce_block,
|
announce_block,
|
||||||
block_announce_validator,
|
block_announce_validator,
|
||||||
@@ -135,11 +126,12 @@ pub fn run_collator(
|
|||||||
|
|
||||||
let polkadot_future = polkadot_collator::start_collator(
|
let polkadot_future = polkadot_collator::start_collator(
|
||||||
builder,
|
builder,
|
||||||
crate::PARA_ID,
|
id,
|
||||||
key,
|
key,
|
||||||
polkadot_config,
|
polkadot_config,
|
||||||
Some(format!("[{}] ", Color::Blue.bold().paint("Relaychain"))),
|
Some(format!("[{}] ", Color::Blue.bold().paint("Relaychain"))),
|
||||||
).map(|_| ());
|
)
|
||||||
|
.map(|_| ());
|
||||||
service.spawn_essential_task("polkadot", polkadot_future);
|
service.spawn_essential_task("polkadot", polkadot_future);
|
||||||
|
|
||||||
Ok(service)
|
Ok(service)
|
||||||
|
|||||||
@@ -48,6 +48,6 @@ fn purge_chain_works() {
|
|||||||
assert!(status.success());
|
assert!(status.success());
|
||||||
|
|
||||||
// Make sure that the `parachain_local_testnet` chain folder exists, but the `db` is deleted.
|
// Make sure that the `parachain_local_testnet` chain folder exists, but the `db` is deleted.
|
||||||
assert!(PathBuf::from(base_path).join("chains/parachain_local_testnet/").exists());
|
assert!(PathBuf::from(base_path).join("chains/local_testnet/").exists());
|
||||||
assert!(!PathBuf::from(base_path).join("chains/parachain_local_testnet/db").exists());
|
assert!(!PathBuf::from(base_path).join("chains/local_testnet/db").exists());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ build = "build.rs"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
runtime = { package = "cumulus-runtime", path = "../../runtime", default-features = false }
|
runtime = { package = "cumulus-runtime", path = "../../runtime", default-features = false }
|
||||||
substrate-test-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch", version = "2.0.0-rc2" }
|
substrate-test-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = " 1.0.6" }
|
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = " 1.0.6" }
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
[package]
|
||||||
|
name = "cumulus-upward-message"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Parity Technologies <admin@parity.io>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
# Substrate dependencies
|
||||||
|
sp-std = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
|
||||||
|
|
||||||
|
# Polkadot deps
|
||||||
|
polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch", default-features = false }
|
||||||
|
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch", default-features = false }
|
||||||
|
|
||||||
|
# All these should be optional dependenices, but given the perfect Cargo, it is not possible.
|
||||||
|
polkadot-runtime = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch", default-features = false }
|
||||||
|
kusama-runtime = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch", default-features = false }
|
||||||
|
westend-runtime = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch", default-features = false }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = [ "std" ]
|
||||||
|
std = [
|
||||||
|
"sp-std/std",
|
||||||
|
"polkadot-runtime/std",
|
||||||
|
"kusama-runtime/std",
|
||||||
|
"westend-runtime/std",
|
||||||
|
"polkadot-core-primitives/std",
|
||||||
|
"polkadot-parachain/std",
|
||||||
|
]
|
||||||
|
# Should be enabled by when compiling the runtime for WASM.
|
||||||
|
#
|
||||||
|
# This disables the runtime api of the Polkadot/Kusama/Westend
|
||||||
|
# runtimes to not clash with the runtime api of the Parachain when building
|
||||||
|
# for WASM.
|
||||||
|
runtime-wasm = [
|
||||||
|
"polkadot-runtime/disable-runtime-api",
|
||||||
|
"westend-runtime/disable-runtime-api",
|
||||||
|
"kusama-runtime/disable-runtime-api",
|
||||||
|
]
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||||
|
// This file is part of Cumulus.
|
||||||
|
|
||||||
|
// Substrate 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.
|
||||||
|
|
||||||
|
// Substrate 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//! Kusama upward message
|
||||||
|
|
||||||
|
use crate::*;
|
||||||
|
use polkadot_core_primitives::{Balance, AccountId};
|
||||||
|
use kusama_runtime::{BalancesCall, ParachainsCall};
|
||||||
|
use sp_std::vec::Vec;
|
||||||
|
|
||||||
|
/// The Kusama upward message.
|
||||||
|
pub type UpwardMessage = kusama_runtime::Call;
|
||||||
|
|
||||||
|
impl BalancesMessage<AccountId, Balance> for UpwardMessage {
|
||||||
|
fn transfer(dest: AccountId, amount: Balance) -> Self {
|
||||||
|
BalancesCall::transfer(dest, amount).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl XCMPMessage for UpwardMessage {
|
||||||
|
fn send_message(dest: ParaId, msg: Vec<u8>) -> Self {
|
||||||
|
ParachainsCall::send_xcmp_message(dest, msg).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||||
|
// This file is part of Cumulus.
|
||||||
|
|
||||||
|
// Substrate 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.
|
||||||
|
|
||||||
|
// Substrate 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//! Upward messages types and traits for Polkadot, Kusama and Westend.
|
||||||
|
//!
|
||||||
|
//! As Cumulus needs to suits multiple Polkadot-like runtimes the upward message
|
||||||
|
//! type is different for each of them. To support all of them, Cumulus provides
|
||||||
|
//! traits to write upward message generic code.
|
||||||
|
|
||||||
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
|
|
||||||
|
use polkadot_parachain::primitives::Id as ParaId;
|
||||||
|
use sp_std::vec::Vec;
|
||||||
|
|
||||||
|
mod polkadot;
|
||||||
|
mod kusama;
|
||||||
|
mod westend;
|
||||||
|
|
||||||
|
pub use polkadot::UpwardMessage as PolkadotUpwardMessage;
|
||||||
|
pub use kusama::UpwardMessage as KusamaUpwardMessage;
|
||||||
|
pub use westend::UpwardMessage as WestendUpwardMessage;
|
||||||
|
|
||||||
|
/// A `Balances` related upward message.
|
||||||
|
pub trait BalancesMessage<AccountId, Balance>: Sized {
|
||||||
|
/// Transfer the given `amount` from the parachain account to the given
|
||||||
|
/// `dest` account.
|
||||||
|
fn transfer(dest: AccountId, amount: Balance) -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A `XCMP` related upward message.
|
||||||
|
pub trait XCMPMessage: Sized {
|
||||||
|
/// Send the given XCMP message to given parachain.
|
||||||
|
fn send_message(dest: ParaId, msg: Vec<u8>) -> Self;
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||||
|
// This file is part of Cumulus.
|
||||||
|
|
||||||
|
// Substrate 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.
|
||||||
|
|
||||||
|
// Substrate 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//! Polkadot upward message
|
||||||
|
|
||||||
|
use crate::*;
|
||||||
|
use polkadot_core_primitives::{Balance, AccountId};
|
||||||
|
use polkadot_runtime::{BalancesCall, ParachainsCall};
|
||||||
|
use sp_std::vec::Vec;
|
||||||
|
|
||||||
|
/// The Polkadot upward message.
|
||||||
|
pub type UpwardMessage = polkadot_runtime::Call;
|
||||||
|
|
||||||
|
impl BalancesMessage<AccountId, Balance> for UpwardMessage {
|
||||||
|
fn transfer(dest: AccountId, amount: Balance) -> Self {
|
||||||
|
BalancesCall::transfer(dest, amount).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl XCMPMessage for UpwardMessage {
|
||||||
|
fn send_message(dest: ParaId, msg: Vec<u8>) -> Self {
|
||||||
|
ParachainsCall::send_xcmp_message(dest, msg).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||||
|
// This file is part of Cumulus.
|
||||||
|
|
||||||
|
// Substrate 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.
|
||||||
|
|
||||||
|
// Substrate 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//! Westend upward message
|
||||||
|
|
||||||
|
use crate::*;
|
||||||
|
use polkadot_core_primitives::{Balance, AccountId};
|
||||||
|
use westend_runtime::{BalancesCall, ParachainsCall};
|
||||||
|
use sp_std::vec::Vec;
|
||||||
|
|
||||||
|
/// The Westend upward message.
|
||||||
|
pub type UpwardMessage = westend_runtime::Call;
|
||||||
|
|
||||||
|
impl BalancesMessage<AccountId, Balance> for UpwardMessage {
|
||||||
|
fn transfer(dest: AccountId, amount: Balance) -> Self {
|
||||||
|
BalancesCall::transfer(dest, amount).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl XCMPMessage for UpwardMessage {
|
||||||
|
fn send_message(dest: ParaId, msg: Vec<u8>) -> Self {
|
||||||
|
ParachainsCall::send_xcmp_message(dest, msg).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user