Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Offchain signing followup #1017

Merged
merged 3 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 16 additions & 22 deletions runtime/common/src/parachains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use sp_std::prelude::*;
use sp_std::result;
use codec::{Decode, Encode};

use sp_core::sr25519;
use sp_runtime::{
KeyTypeId, Perbill, RuntimeDebug,
traits::{
Expand All @@ -41,19 +41,23 @@ use frame_support::{
use primitives::{
Balance,
BlockNumber,
Signature,
parachain::{
Id as ParaId, Chain, DutyRoster, AttestedCandidate, Statement, ParachainDispatchOrigin,
UpwardMessage, ValidatorId, ActiveParas, CollatorId, Retriable, OmittedValidationData,
CandidateReceipt, GlobalValidationSchedule, AbridgedCandidateReceipt,
LocalValidationData, Scheduling, ValidityAttestation, NEW_HEADS_IDENTIFIER, PARACHAIN_KEY_TYPE_ID,
ValidatorSignature, SigningContext, HeadData, ValidationCode,
ValidatorSignature, SigningContext, HeadData, ValidationCode, FishermanId,
},
};
use frame_support::{
Parameter, dispatch::DispatchResult, decl_storage, decl_module, decl_error, ensure,
traits::{Currency, Get, WithdrawReason, ExistenceRequirement, Randomness},
};
use sp_runtime::transaction_validity::InvalidTransaction;
use sp_runtime::{
transaction_validity::InvalidTransaction,
traits::Verify,
};

use inherents::{ProvideInherent, InherentData, MakeFatalError, InherentIdentifier};

Expand All @@ -64,23 +68,12 @@ use system::{
use crate::attestations::{self, IncludedBlocks};
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;
}
// An `AppCrypto` type to facilitate submitting signed transactions.
pub struct FishermanAuthorityId;
impl system::offchain::AppCrypto<<Signature as Verify>::Signer, Signature> for FishermanAuthorityId {
type RuntimeAppPublic = FishermanId;
type GenericSignature = sr25519::Signature;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really over-complicated code...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted here: paritytech/substrate#5662 Unfortunately using existing traits (IsWrappedBy) is non trivial and it is still to be addressed in substrate. But yeah, this code is definitely redundant.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type GenericPublic = sp_core::sr25519::Public;
}

// ranges for iteration of general block number don't work, so this
Expand Down Expand Up @@ -818,8 +811,9 @@ impl<T: Trait> Module<T> {
move |_account| {
Call::report_double_vote(report.clone())
}
);
return Some(())
)
.iter()
.find_map(|(_, res)| res.ok().map(|_| ()))
}

/// Dispatch some messages from a parachain.
Expand Down
10 changes: 1 addition & 9 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use runtime_common::{attestations, claims, parachains, registrar, slots,
NegativeImbalance, BlockHashCount, MaximumBlockWeight, AvailableBlockRatio,
MaximumBlockLength,
};
use sp_core::sr25519;
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
ApplyExtrinsicResult, KeyTypeId, Percent, Permill, Perbill, Perquintill, RuntimeDebug,
Expand Down Expand Up @@ -517,7 +516,7 @@ parameter_types! {
}

impl parachains::Trait for Runtime {
type AuthorityId = FishermanAuthorityId;
type AuthorityId = parachains::FishermanAuthorityId;
type Origin = Origin;
type Call = Call;
type ParachainCurrency = Balances;
Expand All @@ -539,13 +538,6 @@ impl parachains::Trait for Runtime {
type BlockHashConversion = sp_runtime::traits::Identity;
}

pub struct FishermanAuthorityId;
impl system::offchain::AppCrypto<<Signature as Verify>::Signer, Signature> for FishermanAuthorityId {
type RuntimeAppPublic = parachain::FishermanId;
type GenericSignature = sr25519::Signature;
type GenericPublic = sr25519::Public;
}

impl<LocalCall> system::offchain::CreateSignedTransaction<LocalCall> for Runtime where
Call: From<LocalCall>,
{
Expand Down
10 changes: 1 addition & 9 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use primitives::{
AccountId, AccountIndex, Balance, BlockNumber, Hash, Nonce, Signature, Moment,
parachain::{self, ActiveParas, AbridgedCandidateReceipt, SigningContext}, ValidityError,
};
use sp_core::sr25519;
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
ApplyExtrinsicResult, KeyTypeId, Percent, Permill, Perbill, Perquintill, RuntimeDebug,
Expand Down Expand Up @@ -524,7 +523,7 @@ parameter_types! {
}

impl parachains::Trait for Runtime {
type AuthorityId = FishermanAuthorityId;
type AuthorityId = parachains::FishermanAuthorityId;
type Origin = Origin;
type Call = Call;
type ParachainCurrency = Balances;
Expand All @@ -546,13 +545,6 @@ impl parachains::Trait for Runtime {
type BlockHashConversion = sp_runtime::traits::Identity;
}

pub struct FishermanAuthorityId;
impl system::offchain::AppCrypto<<Signature as Verify>::Signer, Signature> for FishermanAuthorityId {
type RuntimeAppPublic = parachain::FishermanId;
type GenericSignature = sr25519::Signature;
type GenericPublic = sr25519::Public;
}

impl<LocalCall> system::offchain::CreateSignedTransaction<LocalCall> for Runtime where
Call: From<LocalCall>,
{
Expand Down
10 changes: 1 addition & 9 deletions runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use runtime_common::{attestations, parachains, registrar,
impls::{CurrencyToVoteHandler, TargetedFeeAdjustment, ToAuthor},
BlockHashCount, MaximumBlockWeight, AvailableBlockRatio, MaximumBlockLength,
};
use sp_core::sr25519;
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
ApplyExtrinsicResult, KeyTypeId, Perbill, Perquintill, RuntimeDebug,
Expand Down Expand Up @@ -387,7 +386,7 @@ parameter_types! {
}

impl parachains::Trait for Runtime {
type AuthorityId = FishermanAuthorityId;
type AuthorityId = parachains::FishermanAuthorityId;
type Origin = Origin;
type Call = Call;
type ParachainCurrency = Balances;
Expand All @@ -409,13 +408,6 @@ impl parachains::Trait for Runtime {
type BlockHashConversion = sp_runtime::traits::Identity;
}

pub struct FishermanAuthorityId;
impl system::offchain::AppCrypto<<Signature as Verify>::Signer, Signature> for FishermanAuthorityId {
type RuntimeAppPublic = parachain::FishermanId;
type GenericSignature = sr25519::Signature;
type GenericPublic = sr25519::Public;
}

impl<LocalCall> system::offchain::CreateSignedTransaction<LocalCall> for Runtime where
Call: From<LocalCall>,
{
Expand Down