Skip to content

Commit

Permalink
Support for multi- and custom-signatures (#376)
Browse files Browse the repository at this point in the history
* Added MultiSig and CustomSig pallets

* Enabled pallet_multisig in runtime
* Ported pallet_custom_signatures to FRAME 2.0
* Enabled pallet_custom_signatures with Ethereum signatures on runtime
* Switch to polkadot-v0.9.9 release
* Added payment-info RPC service
* Bump runtime version

* Bump version

* Updated Cargo.lock
  • Loading branch information
akru authored Aug 22, 2021
1 parent c07145e commit e9f3bea
Show file tree
Hide file tree
Showing 16 changed files with 1,589 additions and 835 deletions.
1,595 changes: 898 additions & 697 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
"bin/collator",
"runtime/shiden",
"frame/block-reward",
"frame/custom-signatures",
]

[profile.release]
Expand Down
100 changes: 52 additions & 48 deletions bin/collator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "astar-collator"
version = "2.3.0"
version = "2.4.0"
authors = ["Stake Technologies <devops@stake.co.jp>"]
description = "Astar collator implementation in Rust."
build = "build.rs"
Expand All @@ -26,35 +26,37 @@ log = "0.4.8"
hex = "0.4"

# primitives
sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sp-trie= { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sp-session = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sp-keystore= { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sp-offchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sp-trie= { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sp-session = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sp-keystore= { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sp-offchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }

# client dependencies
sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sc-client-db = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sc-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sc-offchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sc-service = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sc-telemetry = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sc-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sc-client-db = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false }
sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sc-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sc-offchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sc-service = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sc-telemetry = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
sc-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }

# RPC related dependencies
jsonrpc-core = "15.1.0"
Expand All @@ -63,34 +65,36 @@ jsonrpc-core = "15.1.0"
shiden-runtime = { path = "../../runtime/shiden" }

# frame dependencies
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
frame-rpc-system = { package = "substrate-frame-rpc-system", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }

# CLI-specific dependencies
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", optional = true }
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", optional = true }

# cumulus dependencies
cumulus-client-cli = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.8" }
cumulus-client-network = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.8" }
cumulus-client-service = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.8" }
cumulus-client-consensus-aura = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.8" }
cumulus-client-consensus-common = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.8" }
cumulus-client-consensus-relay-chain = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.8" }
cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.8" }
cumulus-primitives-parachain-inherent = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.8" }
substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
cumulus-client-cli = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.9" }
cumulus-client-network = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.9" }
cumulus-client-service = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.9" }
cumulus-client-consensus-aura = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.9" }
cumulus-client-consensus-common = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.9" }
cumulus-client-consensus-relay-chain = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.9" }
cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.9" }
cumulus-primitives-parachain-inherent = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.9" }
substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }

# polkadot dependencies
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.8" }
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.8" }
polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.8" }
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.8", optional = true }
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.9" }
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.9" }
polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.9" }
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.9", optional = true }

[build-dependencies]
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", optional = true }
sc-service = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", optional = true }
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.8", optional = true }
build-script-utils = { package = "substrate-build-script-utils", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", optional = true }
sc-service = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", optional = true }
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.9", optional = true }
build-script-utils = { package = "substrate-build-script-utils", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
structopt = { version = "0.3.8", optional = true }
vergen = { version = "3.0.4", optional = true }

Expand Down
27 changes: 7 additions & 20 deletions bin/collator/src/aura_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@
use cumulus_client_consensus_common::{ParachainCandidate, ParachainConsensus};
use cumulus_primitives_core::relay_chain::v1::{Hash as PHash, PersistedValidationData};
use futures::lock::Mutex;
use sc_consensus::{import_queue::Verifier as VerifierT, BlockImportParams};
use sp_api::ApiExt;
use sp_consensus::{
import_queue::{CacheKeyId, Verifier as VerifierT},
BlockImportParams, BlockOrigin,
};
use sp_consensus::CacheKeyId;
use sp_consensus_aura::{sr25519::AuthorityId as AuraId, AuraApi};
use sp_runtime::{generic::BlockId, traits::Header as HeaderT};
use std::sync::Arc;

type BlockNumber = u32;
type Header = sp_runtime::generic::Header<BlockNumber, sp_runtime::traits::BlakeTwo256>;
pub type Block = sp_runtime::generic::Block<Header, sp_runtime::OpaqueExtrinsic>;
pub type Hash = sp_core::H256;
use crate::primitives::*;

pub enum BuildOnAccess<R> {
Uninitialized(Option<Box<dyn FnOnce() -> R + Send + Sync>>),
Expand Down Expand Up @@ -100,33 +95,25 @@ where
{
async fn verify(
&mut self,
origin: BlockOrigin,
header: Header,
justifications: Option<sp_runtime::Justifications>,
body: Option<Vec<<Block as sp_runtime::traits::Block>::Extrinsic>>,
block_import: BlockImportParams<Block, ()>,
) -> Result<
(
BlockImportParams<Block, ()>,
Option<Vec<(CacheKeyId, Vec<u8>)>>,
),
String,
> {
let block_id = BlockId::hash(*header.parent_hash());
let block_id = BlockId::hash(*block_import.header.parent_hash());

if self
.client
.runtime_api()
.has_api::<dyn AuraApi<Block, AuraId>>(&block_id)
.unwrap_or(false)
{
self.aura_verifier
.get_mut()
.verify(origin, header, justifications, body)
.await
self.aura_verifier.get_mut().verify(block_import).await
} else {
self.relay_chain_verifier
.verify(origin, header, justifications, body)
.await
self.relay_chain_verifier.verify(block_import).await
}
}
}
3 changes: 2 additions & 1 deletion bin/collator/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::{
chain_spec,
cli::{Cli, RelayChainCli, Subcommand},
service::{self, shiden, Block},
primitives::Block,
service::{self, shiden},
};
use codec::Encode;
use cumulus_client_service::genesis::generate_genesis_block;
Expand Down
2 changes: 2 additions & 0 deletions bin/collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ mod cli;
mod command;

mod aura_upgrade;
mod primitives;
mod rpc;

pub use cli::*;
pub use command::*;
9 changes: 9 additions & 0 deletions bin/collator/src/primitives.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//! Opaque primitives for different parachain runtimes.

pub type BlockNumber = u32;
pub type Header = sp_runtime::generic::Header<BlockNumber, sp_runtime::traits::BlakeTwo256>;
pub type Block = sp_runtime::generic::Block<Header, sp_runtime::OpaqueExtrinsic>;
pub type Hash = sp_core::H256;
pub type Balance = u128;
pub type Nonce = u32;
pub type AccountId = sp_runtime::AccountId32;
61 changes: 61 additions & 0 deletions bin/collator/src/rpc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//! Parachain-specific RPCs implementation.

use sc_client_api::AuxStore;
pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor};
use sc_transaction_pool_api::TransactionPool;
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
use std::sync::Arc;

use crate::primitives::*;

/// A type representing all RPC extensions.
pub type RpcExtension = jsonrpc_core::IoHandler<sc_rpc::Metadata>;

/// Full client dependencies
pub struct FullDeps<C, P> {
/// The client instance to use.
pub client: Arc<C>,
/// Transaction pool instance.
pub pool: Arc<P>,
/// Whether to deny unsafe calls
pub deny_unsafe: DenyUnsafe,
}

/// Instantiate all RPC extensions.
pub fn create_full<C, P>(deps: FullDeps<C, P>) -> RpcExtension
where
C: ProvideRuntimeApi<Block>
+ HeaderBackend<Block>
+ AuxStore
+ HeaderMetadata<Block, Error = BlockChainError>
+ Send
+ Sync
+ 'static,
C::Api: frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: BlockBuilder<Block>,
P: TransactionPool + Sync + Send + 'static,
{
use frame_rpc_system::{FullSystem, SystemApi};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};

let mut io = jsonrpc_core::IoHandler::default();
let FullDeps {
client,
pool,
deny_unsafe,
} = deps;

io.extend_with(SystemApi::to_delegate(FullSystem::new(
client.clone(),
pool,
deny_unsafe,
)));
io.extend_with(TransactionPaymentApi::to_delegate(TransactionPayment::new(
client.clone(),
)));

io
}
Loading

0 comments on commit e9f3bea

Please sign in to comment.