mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 09:21:04 +00:00
Adds an offchain call to submit double vote reports (#966)
* Adds an offchain call to submit double vote reports * Some tweaks * Remove unnecessary IdentifyAccount impls * Adds ValidateDoubleVoteReports to test runtime * sp-application-crypto is only a dev dependency
This commit is contained in:
@@ -40,7 +40,7 @@ use sp_runtime::{
|
||||
curve::PiecewiseLinear,
|
||||
traits::{
|
||||
BlakeTwo256, Block as BlockT, SignedExtension, OpaqueKeys, ConvertInto, IdentityLookup,
|
||||
DispatchInfoOf,
|
||||
DispatchInfoOf, StaticLookup, Extrinsic as ExtrinsicT, SaturatedConversion,
|
||||
},
|
||||
};
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
@@ -51,7 +51,10 @@ use grandpa::{AuthorityId as GrandpaId, fg_primitives};
|
||||
use version::NativeVersion;
|
||||
use sp_core::OpaqueMetadata;
|
||||
use sp_staking::SessionIndex;
|
||||
use frame_support::{parameter_types, construct_runtime, traits::{KeyOwnerProofSystem, Randomness}};
|
||||
use frame_support::{
|
||||
parameter_types, construct_runtime, debug,
|
||||
traits::{KeyOwnerProofSystem, Randomness},
|
||||
};
|
||||
use im_online::sr25519::AuthorityId as ImOnlineId;
|
||||
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
|
||||
use system::offchain::TransactionSubmitter;
|
||||
@@ -407,6 +410,46 @@ impl parachains::Trait for Runtime {
|
||||
type IdentificationTuple = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, Vec<u8>)>>::IdentificationTuple;
|
||||
type ReportOffence = Offences;
|
||||
type BlockHashConversion = sp_runtime::traits::Identity;
|
||||
type SubmitSignedTransaction = TransactionSubmitter<parachain::FishermanId, Runtime, UncheckedExtrinsic>;
|
||||
}
|
||||
|
||||
impl system::offchain::CreateTransaction<Runtime, UncheckedExtrinsic> for Runtime {
|
||||
type Public = <primitives::Signature as sp_runtime::traits::Verify>::Signer;
|
||||
type Signature = primitives::Signature;
|
||||
|
||||
fn create_transaction<TSigner: system::offchain::Signer<Self::Public, Self::Signature>>(
|
||||
call: <UncheckedExtrinsic as ExtrinsicT>::Call,
|
||||
public: Self::Public,
|
||||
account: <Runtime as system::Trait>::AccountId,
|
||||
nonce: <Runtime as system::Trait>::Index,
|
||||
) -> Option<(Call, <UncheckedExtrinsic as ExtrinsicT>::SignaturePayload)> {
|
||||
let period = BlockHashCount::get()
|
||||
.checked_next_power_of_two()
|
||||
.map(|c| c / 2)
|
||||
.unwrap_or(2) as u64;
|
||||
|
||||
let current_block = System::block_number()
|
||||
.saturated_into::<u64>()
|
||||
.saturating_sub(1);
|
||||
let tip = 0;
|
||||
let extra: SignedExtra = (
|
||||
RestrictFunctionality,
|
||||
system::CheckVersion::<Runtime>::new(),
|
||||
system::CheckGenesis::<Runtime>::new(),
|
||||
system::CheckEra::<Runtime>::from(generic::Era::mortal(period, current_block)),
|
||||
system::CheckNonce::<Runtime>::from(nonce),
|
||||
system::CheckWeight::<Runtime>::new(),
|
||||
transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
|
||||
registrar::LimitParathreadCommits::<Runtime>::new(),
|
||||
parachains::ValidateDoubleVoteReports::<Runtime>::new(),
|
||||
);
|
||||
let raw_payload = SignedPayload::new(call, extra).map_err(|e| {
|
||||
debug::warn!("Unable to create signed payload: {:?}", e)
|
||||
}).ok()?;
|
||||
let signature = TSigner::sign(public, &raw_payload)?;
|
||||
let (call, extra, _) = raw_payload.deconstruct();
|
||||
Some((call, (account, signature, extra)))
|
||||
}
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
@@ -580,6 +623,8 @@ pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signatu
|
||||
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Nonce, Call>;
|
||||
/// Executive: handles dispatch to the various modules.
|
||||
pub type Executive = executive::Executive<Runtime, Block, system::ChainContext<Runtime>, Runtime, AllModules>;
|
||||
/// The payload being signed in transactions.
|
||||
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;
|
||||
|
||||
sp_api::impl_runtime_apis! {
|
||||
impl sp_api::Core<Block> for Runtime {
|
||||
|
||||
Reference in New Issue
Block a user