Companion PR to #5182 - Substrate offchain signing (#985)

* Implement offchain::SendTransactionTypes

* Fix test-runtime

* Fix Kusama

* Add SendTransactiontypes to Kusama

* impl SendTransactiontypes for parachains and registrar

* Fix typos

* Provided extrinsic type

* Implement AppCrypto for signing transactions

* Add signing capabilities to runtime

* Fix test runtimes

* Implement CreateSignedtransaction for Test

* Implement signing types for test runtimes

* Fix test runtime create transaction impl

* Fix build

* Bump kusama's spec version

* Update substrate

* Use all_accounts
This commit is contained in:
Rakan Alhneiti
2020-04-21 18:50:32 +02:00
committed by GitHub
parent 765c456a10
commit 2e521d30ea
7 changed files with 346 additions and 243 deletions
+126 -126
View File
File diff suppressed because it is too large Load Diff
+60 -33
View File
@@ -35,7 +35,7 @@ use sp_staking::{
}; };
use frame_support::{ use frame_support::{
traits::KeyOwnerProofSystem, traits::KeyOwnerProofSystem,
dispatch::{IsSubType}, dispatch::IsSubType,
weights::{SimpleDispatchInfo, Weight, MINIMUM_WEIGHT}, weights::{SimpleDispatchInfo, Weight, MINIMUM_WEIGHT},
}; };
use primitives::{ use primitives::{
@@ -59,11 +59,30 @@ use inherents::{ProvideInherent, InherentData, MakeFatalError, InherentIdentifie
use system::{ use system::{
ensure_none, ensure_signed, ensure_none, ensure_signed,
offchain::SubmitSignedTransaction, offchain::{CreateSignedTransaction, SendSignedTransaction, Signer},
}; };
use crate::attestations::{self, IncludedBlocks}; use crate::attestations::{self, IncludedBlocks};
use crate::registrar::Registrar; use crate::registrar::Registrar;
pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"para");
pub mod crypto {
use super::KEY_TYPE;
use sp_runtime::{
app_crypto::{app_crypto, sr25519},
traits::Verify,
};
use sp_core::sr25519::Signature as Sr25519Signature;
app_crypto!(sr25519, KEY_TYPE);
pub struct AuthorityId;
impl system::offchain::AppCrypto<<Sr25519Signature as Verify>::Signer, Sr25519Signature> for AuthorityId {
type RuntimeAppPublic = Public;
type GenericSignature = Sr25519Signature;
type GenericPublic = sp_core::sr25519::Public;
}
}
// ranges for iteration of general block number don't work, so this // ranges for iteration of general block number don't work, so this
// is a utility to get around that. // is a utility to get around that.
struct BlockNumberRange<N> { struct BlockNumberRange<N> {
@@ -220,7 +239,10 @@ impl GetSessionNumber for session::historical::Proof {
} }
} }
pub trait Trait: attestations::Trait + session::historical::Trait { pub trait Trait: CreateSignedTransaction<Call<Self>> + attestations::Trait + session::historical::Trait {
// The transaction signing authority
type AuthorityId: system::offchain::AppCrypto<Self::Public, Self::Signature>;
/// The outer origin type. /// The outer origin type.
type Origin: From<Origin> + From<system::RawOrigin<Self::AccountId>>; type Origin: From<Origin> + From<system::RawOrigin<Self::AccountId>>;
@@ -293,9 +315,6 @@ pub trait Trait: attestations::Trait + session::historical::Trait {
/// A type that converts the opaque hash type to exact one. /// A type that converts the opaque hash type to exact one.
type BlockHashConversion: Convert<Self::Hash, primitives::Hash>; type BlockHashConversion: Convert<Self::Hash, primitives::Hash>;
/// Submit a signed transaction.
type SubmitSignedTransaction: SubmitSignedTransaction<Self, <Self as Trait>::Call>;
} }
/// Origin for the parachains module. /// Origin for the parachains module.
@@ -794,15 +813,13 @@ impl<T: Trait> Module<T> {
pub fn submit_double_vote_report( pub fn submit_double_vote_report(
report: DoubleVoteReport<T::Proof>, report: DoubleVoteReport<T::Proof>,
) -> Option<()> { ) -> Option<()> {
let call = Call::report_double_vote(report); Signer::<T, T::AuthorityId>::all_accounts()
.send_signed_transaction(
let res = T::SubmitSignedTransaction::submit_signed(call); move |_account| {
Call::report_double_vote(report.clone())
if res.iter().any(|(_, r)| r.is_ok()) { }
Some(()) );
} else { return Some(())
None
}
} }
/// Dispatch some messages from a parachain. /// Dispatch some messages from a parachain.
@@ -1543,7 +1560,7 @@ mod tests {
use super::Call as ParachainsCall; use super::Call as ParachainsCall;
use bitvec::{bitvec, vec::BitVec}; use bitvec::{bitvec, vec::BitVec};
use sp_io::TestExternalities; use sp_io::TestExternalities;
use sp_core::{H256, Blake2Hasher}; use sp_core::{H256, Blake2Hasher, sr25519};
use sp_trie::NodeCodec; use sp_trie::NodeCodec;
use sp_runtime::{ use sp_runtime::{
impl_opaque_keys, impl_opaque_keys,
@@ -1631,6 +1648,13 @@ mod tests {
type OnKilledAccount = (); type OnKilledAccount = ();
} }
impl<C> system::offchain::SendTransactionTypes<C> for Test where
Call: From<C>,
{
type OverarchingCall = Call;
type Extrinsic = TestXt<Call, ()>;
}
parameter_types! { parameter_types! {
pub const Period: BlockNumber = 1; pub const Period: BlockNumber = 1;
pub const Offset: BlockNumber = 0; pub const Offset: BlockNumber = 0;
@@ -1760,7 +1784,6 @@ mod tests {
type NextNewSession = Session; type NextNewSession = Session;
type ElectionLookahead = ElectionLookahead; type ElectionLookahead = ElectionLookahead;
type Call = Call; type Call = Call;
type SubmitTransaction = system::offchain::TransactionSubmitter<(), Test, TestXt<Call, ()>>;
type UnsignedPriority = StakingUnsignedPriority; type UnsignedPriority = StakingUnsignedPriority;
} }
@@ -1817,8 +1840,7 @@ mod tests {
// This is needed for a custom `AccountId` type which is `u64` in testing here. // This is needed for a custom `AccountId` type which is `u64` in testing here.
pub mod test_keys { pub mod test_keys {
use sp_core::crypto::KeyTypeId; use sp_core::{crypto::KeyTypeId, sr25519};
pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"test"); pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"test");
mod app { mod app {
@@ -1837,10 +1859,16 @@ mod tests {
} }
pub type ReporterId = app::Public; pub type ReporterId = app::Public;
pub type ReporterSignature = app::Signature; pub struct ReporterAuthorityId;
impl system::offchain::AppCrypto<ReporterId, sr25519::Signature> for ReporterAuthorityId {
type RuntimeAppPublic = ReporterId;
type GenericSignature = sr25519::Signature;
type GenericPublic = sr25519::Public;
}
} }
impl Trait for Test { impl Trait for Test {
type AuthorityId = test_keys::ReporterAuthorityId;
type Origin = Origin; type Origin = Origin;
type Call = Call; type Call = Call;
type ParachainCurrency = Balances; type ParachainCurrency = Balances;
@@ -1860,29 +1888,28 @@ mod tests {
type ReportOffence = Offences; type ReportOffence = Offences;
type BlockHashConversion = sp_runtime::traits::Identity; type BlockHashConversion = sp_runtime::traits::Identity;
type KeyOwnerProofSystem = Historical; type KeyOwnerProofSystem = Historical;
type SubmitSignedTransaction = system::offchain::TransactionSubmitter<
test_keys::ReporterId,
Test,
Extrinsic,
>;
} }
type Extrinsic = TestXt<Call, ()>; type Extrinsic = TestXt<Call, ()>;
impl system::offchain::CreateTransaction<Test, Extrinsic> for Test { impl<LocalCall> system::offchain::CreateSignedTransaction<LocalCall> for Test where
type Public = test_keys::ReporterId; Call: From<LocalCall>,
type Signature = test_keys::ReporterSignature; {
fn create_transaction<C: system::offchain::AppCrypto<Self::Public, Self::Signature>>(
fn create_transaction<F: system::offchain::Signer<Self::Public, Self::Signature>>( call: Call,
call: <Extrinsic as ExtrinsicT>::Call, _public: test_keys::ReporterId,
_public: Self::Public,
_account: <Test as system::Trait>::AccountId, _account: <Test as system::Trait>::AccountId,
nonce: <Test as system::Trait>::Index, nonce: <Test as system::Trait>::Index,
) -> Option<(<Extrinsic as ExtrinsicT>::Call, <Extrinsic as ExtrinsicT>::SignaturePayload)> { ) -> Option<(Call, <Extrinsic as ExtrinsicT>::SignaturePayload)> {
Some((call, (nonce, ()))) Some((call, (nonce, ())))
} }
} }
impl system::offchain::SigningTypes for Test {
type Public = test_keys::ReporterId;
type Signature = sr25519::Signature;
}
type Parachains = Module<Test>; type Parachains = Module<Test>;
type Balances = balances::Module<Test>; type Balances = balances::Module<Test>;
type System = system::Module<Test>; type System = system::Module<Test>;
+29 -17
View File
@@ -676,7 +676,7 @@ mod tests {
CandidateReceipt, HeadData, ValidityAttestation, Statement, Chain, CandidateReceipt, HeadData, ValidityAttestation, Statement, Chain,
CollatorPair, CandidateCommitments, CollatorPair, CandidateCommitments,
}, },
Balance, BlockNumber, Header, Balance, BlockNumber, Header, Signature,
}; };
use frame_support::{ use frame_support::{
traits::{KeyOwnerProofSystem, OnInitialize, OnFinalize}, traits::{KeyOwnerProofSystem, OnInitialize, OnFinalize},
@@ -745,6 +745,13 @@ mod tests {
type OnKilledAccount = Balances; type OnKilledAccount = Balances;
} }
impl<C> system::offchain::SendTransactionTypes<C> for Test where
Call: From<C>,
{
type OverarchingCall = Call;
type Extrinsic = TestXt<Call, ()>;
}
parameter_types! { parameter_types! {
pub const ExistentialDeposit: Balance = 1; pub const ExistentialDeposit: Balance = 1;
} }
@@ -834,7 +841,6 @@ mod tests {
type NextNewSession = Session; type NextNewSession = Session;
type ElectionLookahead = ElectionLookahead; type ElectionLookahead = ElectionLookahead;
type Call = Call; type Call = Call;
type SubmitTransaction = system::offchain::TransactionSubmitter<(), Test, TestXt<Call, ()>>;
type UnsignedPriority = StakingUnsignedPriority; type UnsignedPriority = StakingUnsignedPriority;
} }
@@ -851,7 +857,8 @@ mod tests {
// This is needed for a custom `AccountId` type which is `u64` in testing here. // This is needed for a custom `AccountId` type which is `u64` in testing here.
pub mod test_keys { pub mod test_keys {
use sp_core::crypto::KeyTypeId; use sp_core::{crypto::KeyTypeId, sr25519};
use primitives::Signature;
pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"test"); pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"test");
@@ -872,10 +879,16 @@ mod tests {
} }
pub type ReporterId = app::Public; pub type ReporterId = app::Public;
pub type ReporterSignature = app::Signature; pub struct ReporterAuthorityId;
impl system::offchain::AppCrypto<ReporterId, Signature> for ReporterAuthorityId {
type RuntimeAppPublic = ReporterId;
type GenericSignature = sr25519::Signature;
type GenericPublic = sr25519::Public;
}
} }
impl parachains::Trait for Test { impl parachains::Trait for Test {
type AuthorityId = test_keys::ReporterAuthorityId;
type Origin = Origin; type Origin = Origin;
type Call = Call; type Call = Call;
type ParachainCurrency = balances::Module<Test>; type ParachainCurrency = balances::Module<Test>;
@@ -893,29 +906,28 @@ mod tests {
type IdentificationTuple = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, Vec<u8>)>>::IdentificationTuple; type IdentificationTuple = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, Vec<u8>)>>::IdentificationTuple;
type ReportOffence = (); type ReportOffence = ();
type BlockHashConversion = sp_runtime::traits::Identity; type BlockHashConversion = sp_runtime::traits::Identity;
type SubmitSignedTransaction = system::offchain::TransactionSubmitter<
test_keys::ReporterId,
Test,
Extrinsic,
>;
} }
type Extrinsic = TestXt<Call, ()>; type Extrinsic = TestXt<Call, ()>;
impl system::offchain::CreateTransaction<Test, Extrinsic> for Test { impl<LocalCall> system::offchain::CreateSignedTransaction<LocalCall> for Test where
type Public = test_keys::ReporterId; Call: From<LocalCall>,
type Signature = test_keys::ReporterSignature; {
fn create_transaction<C: system::offchain::AppCrypto<Self::Public, Self::Signature>>(
fn create_transaction<F: system::offchain::Signer<Self::Public, Self::Signature>>( call: Call,
call: <Extrinsic as ExtrinsicT>::Call, _public: test_keys::ReporterId,
_public: Self::Public,
_account: <Test as system::Trait>::AccountId, _account: <Test as system::Trait>::AccountId,
nonce: <Test as system::Trait>::Index, nonce: <Test as system::Trait>::Index,
) -> Option<(<Extrinsic as ExtrinsicT>::Call, <Extrinsic as ExtrinsicT>::SignaturePayload)> { ) -> Option<(Call, <Extrinsic as ExtrinsicT>::SignaturePayload)> {
Some((call, (nonce, ()))) Some((call, (nonce, ())))
} }
} }
impl system::offchain::SigningTypes for Test {
type Public = test_keys::ReporterId;
type Signature = Signature;
}
parameter_types! { parameter_types! {
pub const ParathreadDeposit: Balance = 10; pub const ParathreadDeposit: Balance = 10;
pub const QueueSize: usize = 2; pub const QueueSize: usize = 2;
+33 -18
View File
@@ -32,6 +32,7 @@ use runtime_common::{attestations, claims, parachains, registrar, slots,
NegativeImbalance, BlockHashCount, MaximumBlockWeight, AvailableBlockRatio, NegativeImbalance, BlockHashCount, MaximumBlockWeight, AvailableBlockRatio,
MaximumBlockLength, MaximumBlockLength,
}; };
use sp_core::sr25519;
use sp_runtime::{ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys, create_runtime_str, generic, impl_opaque_keys,
ApplyExtrinsicResult, KeyTypeId, Percent, Permill, Perbill, Perquintill, RuntimeDebug, ApplyExtrinsicResult, KeyTypeId, Percent, Permill, Perbill, Perquintill, RuntimeDebug,
@@ -41,7 +42,7 @@ use sp_runtime::{
curve::PiecewiseLinear, curve::PiecewiseLinear,
traits::{ traits::{
BlakeTwo256, Block as BlockT, SignedExtension, OpaqueKeys, ConvertInto, IdentityLookup, BlakeTwo256, Block as BlockT, SignedExtension, OpaqueKeys, ConvertInto, IdentityLookup,
DispatchInfoOf, Extrinsic as ExtrinsicT, SaturatedConversion, DispatchInfoOf, Extrinsic as ExtrinsicT, SaturatedConversion, Verify,
}, },
}; };
#[cfg(feature = "runtime-benchmarks")] #[cfg(feature = "runtime-benchmarks")]
@@ -58,7 +59,6 @@ use frame_support::{
}; };
use im_online::sr25519::AuthorityId as ImOnlineId; use im_online::sr25519::AuthorityId as ImOnlineId;
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
use system::offchain::TransactionSubmitter;
use transaction_payment_rpc_runtime_api::RuntimeDispatchInfo; use transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;
use session::{historical as session_historical}; use session::{historical as session_historical};
@@ -84,7 +84,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("kusama"), spec_name: create_runtime_str!("kusama"),
impl_name: create_runtime_str!("parity-kusama"), impl_name: create_runtime_str!("parity-kusama"),
authoring_version: 2, authoring_version: 2,
spec_version: 1059, spec_version: 1060,
impl_version: 0, impl_version: 0,
apis: RUNTIME_API_VERSIONS, apis: RUNTIME_API_VERSIONS,
transaction_version: 1, transaction_version: 1,
@@ -322,7 +322,6 @@ impl staking::Trait for Runtime {
type NextNewSession = Session; type NextNewSession = Session;
type ElectionLookahead = ElectionLookahead; type ElectionLookahead = ElectionLookahead;
type Call = Call; type Call = Call;
type SubmitTransaction = TransactionSubmitter<(), Runtime, UncheckedExtrinsic>;
type UnsignedPriority = StakingUnsignedPriority; type UnsignedPriority = StakingUnsignedPriority;
} }
@@ -467,8 +466,6 @@ impl offences::Trait for Runtime {
impl authority_discovery::Trait for Runtime {} impl authority_discovery::Trait for Runtime {}
type SubmitTransaction = TransactionSubmitter<ImOnlineId, Runtime, UncheckedExtrinsic>;
parameter_types! { parameter_types! {
pub const SessionDuration: BlockNumber = EPOCH_DURATION_IN_BLOCKS as _; pub const SessionDuration: BlockNumber = EPOCH_DURATION_IN_BLOCKS as _;
} }
@@ -481,8 +478,6 @@ parameter_types! {
impl im_online::Trait for Runtime { impl im_online::Trait for Runtime {
type AuthorityId = ImOnlineId; type AuthorityId = ImOnlineId;
type Event = Event; type Event = Event;
type Call = Call;
type SubmitTransaction = SubmitTransaction;
type ReportUnresponsiveness = Offences; type ReportUnresponsiveness = Offences;
type SessionDuration = SessionDuration; type SessionDuration = SessionDuration;
type UnsignedPriority = StakingUnsignedPriority; type UnsignedPriority = StakingUnsignedPriority;
@@ -522,6 +517,7 @@ parameter_types! {
} }
impl parachains::Trait for Runtime { impl parachains::Trait for Runtime {
type AuthorityId = FishermanAuthorityId;
type Origin = Origin; type Origin = Origin;
type Call = Call; type Call = Call;
type ParachainCurrency = Balances; type ParachainCurrency = Balances;
@@ -541,17 +537,22 @@ impl parachains::Trait for Runtime {
type IdentificationTuple = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, Vec<u8>)>>::IdentificationTuple; type IdentificationTuple = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, Vec<u8>)>>::IdentificationTuple;
type ReportOffence = Offences; type ReportOffence = Offences;
type BlockHashConversion = sp_runtime::traits::Identity; type BlockHashConversion = sp_runtime::traits::Identity;
type SubmitSignedTransaction = TransactionSubmitter<parachain::FishermanId, Runtime, UncheckedExtrinsic>;
} }
impl system::offchain::CreateTransaction<Runtime, UncheckedExtrinsic> for Runtime { pub struct FishermanAuthorityId;
type Public = <primitives::Signature as sp_runtime::traits::Verify>::Signer; impl system::offchain::AppCrypto<<Signature as Verify>::Signer, Signature> for FishermanAuthorityId {
type Signature = primitives::Signature; type RuntimeAppPublic = parachain::FishermanId;
type GenericSignature = sr25519::Signature;
type GenericPublic = sr25519::Public;
}
fn create_transaction<TSigner: system::offchain::Signer<Self::Public, Self::Signature>>( impl<LocalCall> system::offchain::CreateSignedTransaction<LocalCall> for Runtime where
call: <UncheckedExtrinsic as ExtrinsicT>::Call, Call: From<LocalCall>,
public: Self::Public, {
account: <Runtime as system::Trait>::AccountId, fn create_transaction<C: system::offchain::AppCrypto<Self::Public, Self::Signature>>(
call: Call,
public: <Signature as Verify>::Signer,
account: AccountId,
nonce: <Runtime as system::Trait>::Index, nonce: <Runtime as system::Trait>::Index,
) -> Option<(Call, <UncheckedExtrinsic as ExtrinsicT>::SignaturePayload)> { ) -> Option<(Call, <UncheckedExtrinsic as ExtrinsicT>::SignaturePayload)> {
let period = BlockHashCount::get() let period = BlockHashCount::get()
@@ -575,14 +576,28 @@ impl system::offchain::CreateTransaction<Runtime, UncheckedExtrinsic> for Runtim
parachains::ValidateDoubleVoteReports::<Runtime>::new(), parachains::ValidateDoubleVoteReports::<Runtime>::new(),
); );
let raw_payload = SignedPayload::new(call, extra).map_err(|e| { let raw_payload = SignedPayload::new(call, extra).map_err(|e| {
debug::warn!("Unable to create signed payload: {:?}", e) debug::warn!("Unable to create signed payload: {:?}", e);
}).ok()?; }).ok()?;
let signature = TSigner::sign(public, &raw_payload)?; let signature = raw_payload.using_encoded(|payload| {
C::sign(payload, public)
})?;
let (call, extra, _) = raw_payload.deconstruct(); let (call, extra, _) = raw_payload.deconstruct();
Some((call, (account, signature, extra))) Some((call, (account, signature, extra)))
} }
} }
impl system::offchain::SigningTypes for Runtime {
type Public = <Signature as Verify>::Signer;
type Signature = Signature;
}
impl<C> system::offchain::SendTransactionTypes<C> for Runtime where
Call: From<C>,
{
type OverarchingCall = Call;
type Extrinsic = UncheckedExtrinsic;
}
parameter_types! { parameter_types! {
pub const ParathreadDeposit: Balance = 5 * DOLLARS; pub const ParathreadDeposit: Balance = 5 * DOLLARS;
pub const QueueSize: usize = 2; pub const QueueSize: usize = 2;
+33 -17
View File
@@ -33,6 +33,7 @@ use primitives::{
AccountId, AccountIndex, Balance, BlockNumber, Hash, Nonce, Signature, Moment, AccountId, AccountIndex, Balance, BlockNumber, Hash, Nonce, Signature, Moment,
parachain::{self, ActiveParas, AbridgedCandidateReceipt, SigningContext}, ValidityError, parachain::{self, ActiveParas, AbridgedCandidateReceipt, SigningContext}, ValidityError,
}; };
use sp_core::sr25519;
use sp_runtime::{ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys, create_runtime_str, generic, impl_opaque_keys,
ApplyExtrinsicResult, KeyTypeId, Percent, Permill, Perbill, Perquintill, RuntimeDebug, ApplyExtrinsicResult, KeyTypeId, Percent, Permill, Perbill, Perquintill, RuntimeDebug,
@@ -43,6 +44,7 @@ use sp_runtime::{
traits::{ traits::{
BlakeTwo256, Block as BlockT, SignedExtension, OpaqueKeys, ConvertInto, BlakeTwo256, Block as BlockT, SignedExtension, OpaqueKeys, ConvertInto,
DispatchInfoOf, IdentityLookup, Extrinsic as ExtrinsicT, SaturatedConversion, DispatchInfoOf, IdentityLookup, Extrinsic as ExtrinsicT, SaturatedConversion,
Verify,
}, },
}; };
#[cfg(feature = "runtime-benchmarks")] #[cfg(feature = "runtime-benchmarks")]
@@ -59,9 +61,8 @@ use frame_support::{
}; };
use im_online::sr25519::AuthorityId as ImOnlineId; use im_online::sr25519::AuthorityId as ImOnlineId;
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
use system::offchain::TransactionSubmitter;
use transaction_payment_rpc_runtime_api::RuntimeDispatchInfo; use transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;
use session::{historical as session_historical}; use session::historical as session_historical;
#[cfg(feature = "std")] #[cfg(feature = "std")]
pub use staking::StakerStatus; pub use staking::StakerStatus;
@@ -326,7 +327,6 @@ impl staking::Trait for Runtime {
type NextNewSession = Session; type NextNewSession = Session;
type ElectionLookahead = ElectionLookahead; type ElectionLookahead = ElectionLookahead;
type Call = Call; type Call = Call;
type SubmitTransaction = TransactionSubmitter<(), Runtime, UncheckedExtrinsic>;
type UnsignedPriority = StakingUnsignedPriority; type UnsignedPriority = StakingUnsignedPriority;
} }
@@ -472,8 +472,6 @@ impl offences::Trait for Runtime {
impl authority_discovery::Trait for Runtime {} impl authority_discovery::Trait for Runtime {}
type SubmitTransaction = TransactionSubmitter<ImOnlineId, Runtime, UncheckedExtrinsic>;
parameter_types! { parameter_types! {
pub const SessionDuration: BlockNumber = EPOCH_DURATION_IN_BLOCKS as _; pub const SessionDuration: BlockNumber = EPOCH_DURATION_IN_BLOCKS as _;
} }
@@ -486,8 +484,6 @@ parameter_types! {
impl im_online::Trait for Runtime { impl im_online::Trait for Runtime {
type AuthorityId = ImOnlineId; type AuthorityId = ImOnlineId;
type Event = Event; type Event = Event;
type Call = Call;
type SubmitTransaction = SubmitTransaction;
type SessionDuration = SessionDuration; type SessionDuration = SessionDuration;
type ReportUnresponsiveness = Offences; type ReportUnresponsiveness = Offences;
type UnsignedPriority = ImOnlineUnsignedPriority; type UnsignedPriority = ImOnlineUnsignedPriority;
@@ -528,6 +524,7 @@ parameter_types! {
} }
impl parachains::Trait for Runtime { impl parachains::Trait for Runtime {
type AuthorityId = FishermanAuthorityId;
type Origin = Origin; type Origin = Origin;
type Call = Call; type Call = Call;
type ParachainCurrency = Balances; type ParachainCurrency = Balances;
@@ -547,17 +544,22 @@ impl parachains::Trait for Runtime {
type IdentificationTuple = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, Vec<u8>)>>::IdentificationTuple; type IdentificationTuple = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, Vec<u8>)>>::IdentificationTuple;
type ReportOffence = Offences; type ReportOffence = Offences;
type BlockHashConversion = sp_runtime::traits::Identity; type BlockHashConversion = sp_runtime::traits::Identity;
type SubmitSignedTransaction = TransactionSubmitter<parachain::FishermanId, Runtime, UncheckedExtrinsic>;
} }
impl system::offchain::CreateTransaction<Runtime, UncheckedExtrinsic> for Runtime { pub struct FishermanAuthorityId;
type Public = <primitives::Signature as sp_runtime::traits::Verify>::Signer; impl system::offchain::AppCrypto<<Signature as Verify>::Signer, Signature> for FishermanAuthorityId {
type Signature = primitives::Signature; type RuntimeAppPublic = parachain::FishermanId;
type GenericSignature = sr25519::Signature;
type GenericPublic = sr25519::Public;
}
fn create_transaction<TSigner: system::offchain::Signer<Self::Public, Self::Signature>>( impl<LocalCall> system::offchain::CreateSignedTransaction<LocalCall> for Runtime where
call: <UncheckedExtrinsic as ExtrinsicT>::Call, Call: From<LocalCall>,
public: Self::Public, {
account: <Runtime as system::Trait>::AccountId, fn create_transaction<C: system::offchain::AppCrypto<Self::Public, Self::Signature>>(
call: Call,
public: <Signature as Verify>::Signer,
account: AccountId,
nonce: <Runtime as system::Trait>::Index, nonce: <Runtime as system::Trait>::Index,
) -> Option<(Call, <UncheckedExtrinsic as ExtrinsicT>::SignaturePayload)> { ) -> Option<(Call, <UncheckedExtrinsic as ExtrinsicT>::SignaturePayload)> {
let period = BlockHashCount::get() let period = BlockHashCount::get()
@@ -581,14 +583,28 @@ impl system::offchain::CreateTransaction<Runtime, UncheckedExtrinsic> for Runtim
parachains::ValidateDoubleVoteReports::<Runtime>::new(), parachains::ValidateDoubleVoteReports::<Runtime>::new(),
); );
let raw_payload = SignedPayload::new(call, extra).map_err(|e| { let raw_payload = SignedPayload::new(call, extra).map_err(|e| {
debug::warn!("Unable to create signed payload: {:?}", e) debug::warn!("Unable to create signed payload: {:?}", e);
}).ok()?; }).ok()?;
let signature = TSigner::sign(public, &raw_payload)?; let signature = raw_payload.using_encoded(|payload| {
C::sign(payload, public)
})?;
let (call, extra, _) = raw_payload.deconstruct(); let (call, extra, _) = raw_payload.deconstruct();
Some((call, (account, signature, extra))) Some((call, (account, signature, extra)))
} }
} }
impl system::offchain::SigningTypes for Runtime {
type Public = <Signature as Verify>::Signer;
type Signature = Signature;
}
impl<C> system::offchain::SendTransactionTypes<C> for Runtime where
Call: From<C>,
{
type OverarchingCall = Call;
type Extrinsic = UncheckedExtrinsic;
}
parameter_types! { parameter_types! {
pub const ParathreadDeposit: Balance = 500 * DOLLARS; pub const ParathreadDeposit: Balance = 500 * DOLLARS;
pub const QueueSize: usize = 2; pub const QueueSize: usize = 2;
+32 -14
View File
@@ -31,7 +31,7 @@ use runtime_common::{attestations, claims, parachains, registrar, slots,
BlockHashCount, MaximumBlockWeight, AvailableBlockRatio, BlockHashCount, MaximumBlockWeight, AvailableBlockRatio,
MaximumBlockLength, MaximumBlockLength,
}; };
use sp_core::sr25519;
use sp_runtime::{ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys, create_runtime_str, generic, impl_opaque_keys,
ApplyExtrinsicResult, Perbill, Perquintill, RuntimeDebug, KeyTypeId, ApplyExtrinsicResult, Perbill, Perquintill, RuntimeDebug, KeyTypeId,
@@ -41,7 +41,7 @@ use sp_runtime::{
curve::PiecewiseLinear, curve::PiecewiseLinear,
traits::{ traits::{
BlakeTwo256, Block as BlockT, StaticLookup, SignedExtension, OpaqueKeys, ConvertInto, BlakeTwo256, Block as BlockT, StaticLookup, SignedExtension, OpaqueKeys, ConvertInto,
DispatchInfoOf, Extrinsic as ExtrinsicT, SaturatedConversion, DispatchInfoOf, Extrinsic as ExtrinsicT, SaturatedConversion, Verify,
}, },
}; };
use version::RuntimeVersion; use version::RuntimeVersion;
@@ -56,7 +56,6 @@ use frame_support::{
}; };
use pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo; use pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;
use session::historical as session_historical; use session::historical as session_historical;
use system::offchain::TransactionSubmitter;
#[cfg(feature = "std")] #[cfg(feature = "std")]
pub use staking::StakerStatus; pub use staking::StakerStatus;
@@ -153,6 +152,13 @@ impl system::Trait for Runtime {
type OnKilledAccount = (); type OnKilledAccount = ();
} }
impl<C> system::offchain::SendTransactionTypes<C> for Runtime where
Call: From<C>,
{
type OverarchingCall = Call;
type Extrinsic = UncheckedExtrinsic;
}
parameter_types! { parameter_types! {
pub const EpochDuration: u64 = EPOCH_DURATION_IN_BLOCKS as u64; pub const EpochDuration: u64 = EPOCH_DURATION_IN_BLOCKS as u64;
pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK; pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK;
@@ -303,7 +309,6 @@ impl staking::Trait for Runtime {
type NextNewSession = Session; type NextNewSession = Session;
type ElectionLookahead = ElectionLookahead; type ElectionLookahead = ElectionLookahead;
type Call = Call; type Call = Call;
type SubmitTransaction = system::offchain::TransactionSubmitter<(), Runtime, Extrinsic>;
type UnsignedPriority = StakingUnsignedPriority; type UnsignedPriority = StakingUnsignedPriority;
} }
@@ -331,6 +336,7 @@ parameter_types! {
} }
impl parachains::Trait for Runtime { impl parachains::Trait for Runtime {
type AuthorityId = FishermanAuthorityId;
type Origin = Origin; type Origin = Origin;
type Call = Call; type Call = Call;
type ParachainCurrency = Balances; type ParachainCurrency = Balances;
@@ -352,17 +358,22 @@ impl parachains::Trait for Runtime {
>::IdentificationTuple; >::IdentificationTuple;
type ReportOffence = Offences; type ReportOffence = Offences;
type BlockHashConversion = sp_runtime::traits::Identity; type BlockHashConversion = sp_runtime::traits::Identity;
type SubmitSignedTransaction = TransactionSubmitter<parachain::FishermanId, Runtime, UncheckedExtrinsic>;
} }
impl system::offchain::CreateTransaction<Runtime, UncheckedExtrinsic> for Runtime { pub struct FishermanAuthorityId;
type Public = <primitives::Signature as sp_runtime::traits::Verify>::Signer; impl system::offchain::AppCrypto<<Signature as Verify>::Signer, Signature> for FishermanAuthorityId {
type Signature = primitives::Signature; type RuntimeAppPublic = parachain::FishermanId;
type GenericSignature = sr25519::Signature;
type GenericPublic = sr25519::Public;
}
fn create_transaction<TSigner: system::offchain::Signer<Self::Public, Self::Signature>>( impl<LocalCall> system::offchain::CreateSignedTransaction<LocalCall> for Runtime where
call: <UncheckedExtrinsic as ExtrinsicT>::Call, Call: From<LocalCall>,
public: Self::Public, {
account: <Runtime as system::Trait>::AccountId, fn create_transaction<C: system::offchain::AppCrypto<Self::Public, Self::Signature>>(
call: Call,
public: <Signature as Verify>::Signer,
account: AccountId,
nonce: <Runtime as system::Trait>::Index, nonce: <Runtime as system::Trait>::Index,
) -> Option<(Call, <UncheckedExtrinsic as ExtrinsicT>::SignaturePayload)> { ) -> Option<(Call, <UncheckedExtrinsic as ExtrinsicT>::SignaturePayload)> {
let period = BlockHashCount::get() let period = BlockHashCount::get()
@@ -386,15 +397,22 @@ impl system::offchain::CreateTransaction<Runtime, UncheckedExtrinsic> for Runtim
parachains::ValidateDoubleVoteReports::<Runtime>::new(), parachains::ValidateDoubleVoteReports::<Runtime>::new(),
); );
let raw_payload = SignedPayload::new(call, extra).map_err(|e| { let raw_payload = SignedPayload::new(call, extra).map_err(|e| {
debug::warn!("Unable to create signed payload: {:?}", e) debug::warn!("Unable to create signed payload: {:?}", e);
}).ok()?; }).ok()?;
let signature = TSigner::sign(public, &raw_payload)?; let signature = raw_payload.using_encoded(|payload| {
C::sign(payload, public)
})?;
let (call, extra, _) = raw_payload.deconstruct(); let (call, extra, _) = raw_payload.deconstruct();
let address = Indices::unlookup(account); let address = Indices::unlookup(account);
Some((call, (address, signature, extra))) Some((call, (address, signature, extra)))
} }
} }
impl system::offchain::SigningTypes for Runtime {
type Public = <Signature as Verify>::Signer;
type Signature = Signature;
}
impl offences::Trait for Runtime { impl offences::Trait for Runtime {
type Event = Event; type Event = Event;
type IdentificationTuple = session::historical::IdentificationTuple<Self>; type IdentificationTuple = session::historical::IdentificationTuple<Self>;
+33 -18
View File
@@ -30,6 +30,7 @@ use runtime_common::{attestations, parachains, registrar,
impls::{CurrencyToVoteHandler, TargetedFeeAdjustment, ToAuthor}, impls::{CurrencyToVoteHandler, TargetedFeeAdjustment, ToAuthor},
BlockHashCount, MaximumBlockWeight, AvailableBlockRatio, MaximumBlockLength, BlockHashCount, MaximumBlockWeight, AvailableBlockRatio, MaximumBlockLength,
}; };
use sp_core::sr25519;
use sp_runtime::{ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys, create_runtime_str, generic, impl_opaque_keys,
ApplyExtrinsicResult, KeyTypeId, Perbill, Perquintill, RuntimeDebug, ApplyExtrinsicResult, KeyTypeId, Perbill, Perquintill, RuntimeDebug,
@@ -40,7 +41,7 @@ use sp_runtime::{
curve::PiecewiseLinear, curve::PiecewiseLinear,
traits::{ traits::{
BlakeTwo256, Block as BlockT, SignedExtension, OpaqueKeys, ConvertInto, IdentityLookup, BlakeTwo256, Block as BlockT, SignedExtension, OpaqueKeys, ConvertInto, IdentityLookup,
DispatchInfoOf, StaticLookup, Extrinsic as ExtrinsicT, SaturatedConversion, DispatchInfoOf, StaticLookup, Extrinsic as ExtrinsicT, SaturatedConversion, Verify,
}, },
}; };
#[cfg(feature = "runtime-benchmarks")] #[cfg(feature = "runtime-benchmarks")]
@@ -57,9 +58,8 @@ use frame_support::{
}; };
use im_online::sr25519::AuthorityId as ImOnlineId; use im_online::sr25519::AuthorityId as ImOnlineId;
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
use system::offchain::TransactionSubmitter;
use transaction_payment_rpc_runtime_api::RuntimeDispatchInfo; use transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;
use session::{historical as session_historical}; use session::historical as session_historical;
#[cfg(feature = "std")] #[cfg(feature = "std")]
pub use staking::StakerStatus; pub use staking::StakerStatus;
@@ -313,7 +313,6 @@ impl staking::Trait for Runtime {
type NextNewSession = Session; type NextNewSession = Session;
type ElectionLookahead = ElectionLookahead; type ElectionLookahead = ElectionLookahead;
type Call = Call; type Call = Call;
type SubmitTransaction = TransactionSubmitter<(), Runtime, UncheckedExtrinsic>;
type UnsignedPriority = StakingUnsignedPriority; type UnsignedPriority = StakingUnsignedPriority;
} }
@@ -337,8 +336,6 @@ impl offences::Trait for Runtime {
impl authority_discovery::Trait for Runtime {} impl authority_discovery::Trait for Runtime {}
type SubmitTransaction = TransactionSubmitter<ImOnlineId, Runtime, UncheckedExtrinsic>;
parameter_types! { parameter_types! {
pub const SessionDuration: BlockNumber = EPOCH_DURATION_IN_BLOCKS as _; pub const SessionDuration: BlockNumber = EPOCH_DURATION_IN_BLOCKS as _;
} }
@@ -351,8 +348,6 @@ parameter_types! {
impl im_online::Trait for Runtime { impl im_online::Trait for Runtime {
type AuthorityId = ImOnlineId; type AuthorityId = ImOnlineId;
type Event = Event; type Event = Event;
type Call = Call;
type SubmitTransaction = SubmitTransaction;
type ReportUnresponsiveness = Offences; type ReportUnresponsiveness = Offences;
type SessionDuration = SessionDuration; type SessionDuration = SessionDuration;
type UnsignedPriority = StakingUnsignedPriority; type UnsignedPriority = StakingUnsignedPriority;
@@ -392,6 +387,7 @@ parameter_types! {
} }
impl parachains::Trait for Runtime { impl parachains::Trait for Runtime {
type AuthorityId = FishermanAuthorityId;
type Origin = Origin; type Origin = Origin;
type Call = Call; type Call = Call;
type ParachainCurrency = Balances; type ParachainCurrency = Balances;
@@ -411,17 +407,22 @@ impl parachains::Trait for Runtime {
type IdentificationTuple = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, Vec<u8>)>>::IdentificationTuple; type IdentificationTuple = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, Vec<u8>)>>::IdentificationTuple;
type ReportOffence = Offences; type ReportOffence = Offences;
type BlockHashConversion = sp_runtime::traits::Identity; type BlockHashConversion = sp_runtime::traits::Identity;
type SubmitSignedTransaction = TransactionSubmitter<parachain::FishermanId, Runtime, UncheckedExtrinsic>;
} }
impl system::offchain::CreateTransaction<Runtime, UncheckedExtrinsic> for Runtime { pub struct FishermanAuthorityId;
type Public = <primitives::Signature as sp_runtime::traits::Verify>::Signer; impl system::offchain::AppCrypto<<Signature as Verify>::Signer, Signature> for FishermanAuthorityId {
type Signature = primitives::Signature; type RuntimeAppPublic = parachain::FishermanId;
type GenericSignature = sr25519::Signature;
type GenericPublic = sr25519::Public;
}
fn create_transaction<TSigner: system::offchain::Signer<Self::Public, Self::Signature>>( impl<LocalCall> system::offchain::CreateSignedTransaction<LocalCall> for Runtime where
call: <UncheckedExtrinsic as ExtrinsicT>::Call, Call: From<LocalCall>,
public: Self::Public, {
account: <Runtime as system::Trait>::AccountId, fn create_transaction<C: system::offchain::AppCrypto<Self::Public, Self::Signature>>(
call: Call,
public: <Signature as Verify>::Signer,
account: AccountId,
nonce: <Runtime as system::Trait>::Index, nonce: <Runtime as system::Trait>::Index,
) -> Option<(Call, <UncheckedExtrinsic as ExtrinsicT>::SignaturePayload)> { ) -> Option<(Call, <UncheckedExtrinsic as ExtrinsicT>::SignaturePayload)> {
let period = BlockHashCount::get() let period = BlockHashCount::get()
@@ -445,14 +446,28 @@ impl system::offchain::CreateTransaction<Runtime, UncheckedExtrinsic> for Runtim
parachains::ValidateDoubleVoteReports::<Runtime>::new(), parachains::ValidateDoubleVoteReports::<Runtime>::new(),
); );
let raw_payload = SignedPayload::new(call, extra).map_err(|e| { let raw_payload = SignedPayload::new(call, extra).map_err(|e| {
debug::warn!("Unable to create signed payload: {:?}", e) debug::warn!("Unable to create signed payload: {:?}", e);
}).ok()?; }).ok()?;
let signature = TSigner::sign(public, &raw_payload)?; let signature = raw_payload.using_encoded(|payload| {
C::sign(payload, public)
})?;
let (call, extra, _) = raw_payload.deconstruct(); let (call, extra, _) = raw_payload.deconstruct();
Some((call, (account, signature, extra))) Some((call, (account, signature, extra)))
} }
} }
impl system::offchain::SigningTypes for Runtime {
type Public = <Signature as Verify>::Signer;
type Signature = Signature;
}
impl<C> system::offchain::SendTransactionTypes<C> for Runtime where
Call: From<C>,
{
type OverarchingCall = Call;
type Extrinsic = UncheckedExtrinsic;
}
parameter_types! { parameter_types! {
pub const ParathreadDeposit: Balance = 5 * DOLLARS; pub const ParathreadDeposit: Balance = 5 * DOLLARS;
pub const QueueSize: usize = 2; pub const QueueSize: usize = 2;