Unverified Commit 265474a8 authored by Pierre Krieger's avatar Pierre Krieger Committed by GitHub
Browse files

Companion PR to #5560 - Also includes polkadot#979 and polkadot#986 (#982)



* Companion PR to #5560

* Set priorities.

* Update substrate.

* Fix tests.

* Update Substrate

* Companion of SignedExtension refactor (#5540)
Co-authored-by: default avatarTomasz Drwięga <tomasz@parity.io>
Co-authored-by: default avatarAlexander Theißen <alexander.theissen@parity.io>
parent 5f406649
Pipeline #87157 passed with stages
in 25 minutes and 11 seconds
This diff is collapsed.
......@@ -43,7 +43,7 @@ use sp_consensus::block_import::{BlockImport, ImportResult};
use sp_consensus::Error as ConsensusError;
use sp_consensus::{BlockOrigin, BlockImportParams, BlockCheckParams, JustificationImport};
use futures::prelude::*;
use sc_network::{NetworkWorker, NetworkStateInfo, NetworkService, ReportHandle, config::ProtocolId};
use sc_network::{NetworkWorker, NetworkService, ReportHandle, config::ProtocolId};
use sc_network::config::{NetworkConfiguration, TransportConfig, BoxFinalityProofRequestBuilder};
use parking_lot::Mutex;
use sp_core::H256;
......@@ -157,7 +157,7 @@ pub struct Peer<D> {
impl<D> Peer<D> {
/// Get this peer ID.
pub fn id(&self) -> PeerId {
pub fn id(&self) -> &PeerId {
self.network.service().local_peer_id()
}
......@@ -597,7 +597,7 @@ pub trait TestNetFactory: Sized {
self.mut_peers(|peers| {
for peer in peers.iter_mut() {
peer.network.add_known_address(network.service().local_peer_id(), listen_addr.clone());
peer.network.add_known_address(network.service().local_peer_id().clone(), listen_addr.clone());
}
let imported_blocks_stream = Box::pin(client.import_notification_stream().fuse());
......@@ -672,7 +672,7 @@ pub trait TestNetFactory: Sized {
self.mut_peers(|peers| {
for peer in peers.iter_mut() {
peer.network.add_known_address(network.service().local_peer_id(), listen_addr.clone());
peer.network.add_known_address(network.service().local_peer_id().clone(), listen_addr.clone());
}
let imported_blocks_stream = Box::pin(client.import_notification_stream().fuse());
......
......@@ -25,6 +25,7 @@ use sp_runtime::{
traits::{
Hash as HashT, BlakeTwo256, Saturating, One, Zero, Dispatchable,
AccountIdConversion, BadOrigin, Convert, SignedExtension, AppVerify,
DispatchInfoOf,
},
transaction_validity::{TransactionValidityError, ValidTransaction, TransactionValidity},
};
......@@ -35,7 +36,7 @@ use sp_staking::{
use frame_support::{
traits::KeyOwnerProofSystem,
dispatch::{IsSubType},
weights::{DispatchInfo, SimpleDispatchInfo, Weight, WeighData},
weights::{SimpleDispatchInfo, Weight, WeighData},
};
use primitives::{
Balance,
......@@ -1456,7 +1457,6 @@ impl<T: Trait + Send + Sync> SignedExtension for ValidateDoubleVoteReports<T> wh
type Call = <T as system::Trait>::Call;
type AdditionalSigned = ();
type Pre = ();
type DispatchInfo = DispatchInfo;
fn additional_signed(&self)
-> sp_std::result::Result<Self::AdditionalSigned, TransactionValidityError>
......@@ -1468,7 +1468,7 @@ impl<T: Trait + Send + Sync> SignedExtension for ValidateDoubleVoteReports<T> wh
&self,
_who: &Self::AccountId,
call: &Self::Call,
_info: DispatchInfo,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> TransactionValidity {
let r = ValidTransaction::default();
......@@ -1538,6 +1538,7 @@ mod tests {
use frame_support::{
impl_outer_origin, impl_outer_dispatch, assert_ok, assert_err, parameter_types,
traits::{OnInitialize, OnFinalize},
weights::DispatchInfo,
};
use crate::parachains;
use crate::registrar;
......@@ -1699,6 +1700,7 @@ mod tests {
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const MaxNominatorRewardedPerValidator: u32 = 64;
pub const ElectionLookahead: BlockNumber = 0;
pub const StakingUnsignedPriority: u64 = u64::max_value() / 2;
}
pub struct CurrencyToVoteHandler;
......@@ -1730,6 +1732,7 @@ mod tests {
type ElectionLookahead = ElectionLookahead;
type Call = Call;
type SubmitTransaction = system::offchain::TransactionSubmitter<(), Test, TestXt<Call, ()>>;
type UnsignedPriority = StakingUnsignedPriority;
}
impl attestations::Trait for Test {
......@@ -1900,7 +1903,7 @@ mod tests {
let call = Call::Parachains(inner.clone());
ValidateDoubleVoteReports::<Test>(sp_std::marker::PhantomData)
.validate(&0, &call, DispatchInfo::default(), 0)?;
.validate(&0, &call, &DispatchInfo::default(), 0)?;
Ok(inner)
}
......
......@@ -25,13 +25,13 @@ use codec::{Encode, Decode};
use sp_runtime::{
transaction_validity::{TransactionValidityError, ValidTransaction, TransactionValidity},
traits::{Hash as HashT, SignedExtension}
traits::{Hash as HashT, SignedExtension, DispatchInfoOf},
};
use frame_support::{
decl_storage, decl_module, decl_event, decl_error, ensure,
dispatch::{DispatchResult, IsSubType}, traits::{Get, Currency, ReservableCurrency},
weights::{SimpleDispatchInfo, DispatchInfo, Weight, WeighData},
weights::{SimpleDispatchInfo, Weight, WeighData},
};
use system::{self, ensure_root, ensure_signed};
use primitives::parachain::{
......@@ -588,7 +588,6 @@ impl<T: Trait + Send + Sync> SignedExtension for LimitParathreadCommits<T> where
type Call = <T as system::Trait>::Call;
type AdditionalSigned = ();
type Pre = ();
type DispatchInfo = DispatchInfo;
fn additional_signed(&self)
-> sp_std::result::Result<Self::AdditionalSigned, TransactionValidityError>
......@@ -600,7 +599,7 @@ impl<T: Trait + Send + Sync> SignedExtension for LimitParathreadCommits<T> where
&self,
_who: &Self::AccountId,
call: &Self::Call,
_info: DispatchInfo,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> TransactionValidity {
let mut r = ValidTransaction::default();
......@@ -673,6 +672,7 @@ mod tests {
use frame_support::{
traits::{KeyOwnerProofSystem, OnInitialize, OnFinalize},
impl_outer_origin, impl_outer_dispatch, assert_ok, parameter_types, assert_noop,
weights::DispatchInfo,
};
use keyring::Sr25519Keyring;
......@@ -803,6 +803,7 @@ mod tests {
pub const ValidationUpgradeDelay: BlockNumber = 2;
pub const SlashPeriod: BlockNumber = 50;
pub const ElectionLookahead: BlockNumber = 0;
pub const StakingUnsignedPriority: u64 = u64::max_value() / 2;
}
impl staking::Trait for Test {
......@@ -824,6 +825,7 @@ mod tests {
type ElectionLookahead = ElectionLookahead;
type Call = Call;
type SubmitTransaction = system::offchain::TransactionSubmitter<(), Test, TestXt<Call, ()>>;
type UnsignedPriority = StakingUnsignedPriority;
}
impl timestamp::Trait for Test {
......@@ -969,7 +971,7 @@ mod tests {
let inner_call = super::Call::select_parathread(id, col.clone(), hdh);
let call = Call::Registrar(inner_call);
let origin = 4u64;
assert!(tx.validate(&origin, &call, Default::default(), 0).is_ok());
assert!(tx.validate(&origin, &call, &Default::default(), 0).is_ok());
assert_ok!(call.dispatch(Origin::signed(origin)));
}
......@@ -1416,7 +1418,7 @@ mod tests {
let bad_para_id = user_id(1);
let bad_head_hash = <Test as system::Trait>::Hashing::hash(&vec![1, 2, 1]);
let good_head_hash = <Test as system::Trait>::Hashing::hash(&vec![1, 1, 1]);
let info = DispatchInfo::default();
let info = &DispatchInfo::default();
// Allow for threads
assert_ok!(Registrar::set_thread_count(Origin::ROOT, 10));
......@@ -1481,7 +1483,7 @@ mod tests {
let head_hash = <Test as system::Trait>::Hashing::hash(&vec![x; 3]);
let inner = super::Call::select_parathread(para_id, collator_id, head_hash);
let call = Call::Registrar(inner);
let info = DispatchInfo::default();
let info = &DispatchInfo::default();
// First 3 transactions win a slot
if x < 3 {
......
......@@ -36,10 +36,13 @@ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
ApplyExtrinsicResult, KeyTypeId, Percent, Permill, Perbill, RuntimeDebug,
transaction_validity::{
TransactionValidity, InvalidTransaction, TransactionValidityError, TransactionSource,
TransactionValidity, InvalidTransaction, TransactionValidityError, TransactionSource, TransactionPriority,
},
curve::PiecewiseLinear,
traits::{BlakeTwo256, Block as BlockT, SignedExtension, OpaqueKeys, ConvertInto, IdentityLookup},
traits::{
BlakeTwo256, Block as BlockT, SignedExtension, OpaqueKeys, ConvertInto, IdentityLookup,
DispatchInfoOf,
},
};
#[cfg(feature = "runtime-benchmarks")]
use sp_runtime::RuntimeString;
......@@ -51,7 +54,6 @@ use sp_core::OpaqueMetadata;
use sp_staking::SessionIndex;
use frame_support::{
parameter_types, construct_runtime, traits::{KeyOwnerProofSystem, SplitTwoWays, Randomness},
weights::DispatchInfo,
};
use im_online::sr25519::AuthorityId as ImOnlineId;
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
......@@ -104,11 +106,16 @@ impl SignedExtension for RestrictFunctionality {
type Call = Call;
type AdditionalSigned = ();
type Pre = ();
type DispatchInfo = DispatchInfo;
fn additional_signed(&self) -> sp_std::result::Result<(), TransactionValidityError> { Ok(()) }
fn validate(&self, _: &Self::AccountId, call: &Self::Call, _: DispatchInfo, _: usize)
fn validate(
&self,
_: &Self::AccountId,
call: &Self::Call,
_: &DispatchInfoOf<Self::Call>,
_: usize
)
-> TransactionValidity
{
match call {
......@@ -313,6 +320,7 @@ impl staking::Trait for Runtime {
type ElectionLookahead = ElectionLookahead;
type Call = Call;
type SubmitTransaction = TransactionSubmitter<(), Runtime, UncheckedExtrinsic>;
type UnsignedPriority = StakingUnsignedPriority;
}
parameter_types! {
......@@ -462,6 +470,11 @@ parameter_types! {
pub const SessionDuration: BlockNumber = EPOCH_DURATION_IN_BLOCKS as _;
}
parameter_types! {
pub const StakingUnsignedPriority: TransactionPriority = TransactionPriority::max_value() / 2;
pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value();
}
impl im_online::Trait for Runtime {
type AuthorityId = ImOnlineId;
type Event = Event;
......@@ -469,6 +482,7 @@ impl im_online::Trait for Runtime {
type SubmitTransaction = SubmitTransaction;
type ReportUnresponsiveness = Offences;
type SessionDuration = SessionDuration;
type UnsignedPriority = StakingUnsignedPriority;
}
impl grandpa::Trait for Runtime {
......
......@@ -37,12 +37,12 @@ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
ApplyExtrinsicResult, KeyTypeId, Percent, Permill, Perbill, RuntimeDebug,
transaction_validity::{
TransactionValidity, InvalidTransaction, TransactionValidityError, TransactionSource,
TransactionValidity, InvalidTransaction, TransactionValidityError, TransactionSource, TransactionPriority,
},
curve::PiecewiseLinear,
traits::{
BlakeTwo256, Block as BlockT, SignedExtension, OpaqueKeys, ConvertInto,
IdentityLookup
IdentityLookup, DispatchInfoOf,
},
};
#[cfg(feature = "runtime-benchmarks")]
......@@ -55,7 +55,6 @@ use sp_core::OpaqueMetadata;
use sp_staking::SessionIndex;
use frame_support::{
parameter_types, construct_runtime, traits::{KeyOwnerProofSystem, SplitTwoWays, Randomness},
weights::DispatchInfo,
};
use im_online::sr25519::AuthorityId as ImOnlineId;
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
......@@ -112,11 +111,16 @@ impl SignedExtension for OnlyStakingAndClaims {
type Call = Call;
type AdditionalSigned = ();
type Pre = ();
type DispatchInfo = DispatchInfo;
fn additional_signed(&self) -> sp_std::result::Result<(), TransactionValidityError> { Ok(()) }
fn validate(&self, _: &Self::AccountId, call: &Self::Call, _: DispatchInfo, _: usize)
fn validate(
&self, _:
&Self::AccountId,
call: &Self::Call,
_: &DispatchInfoOf<Self::Call>,
_: usize
)
-> TransactionValidity
{
match call {
......@@ -320,6 +324,7 @@ impl staking::Trait for Runtime {
type ElectionLookahead = ElectionLookahead;
type Call = Call;
type SubmitTransaction = TransactionSubmitter<(), Runtime, UncheckedExtrinsic>;
type UnsignedPriority = StakingUnsignedPriority;
}
parameter_types! {
......@@ -470,6 +475,11 @@ parameter_types! {
pub const SessionDuration: BlockNumber = EPOCH_DURATION_IN_BLOCKS as _;
}
parameter_types! {
pub const StakingUnsignedPriority: TransactionPriority = TransactionPriority::max_value() / 2;
pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value();
}
impl im_online::Trait for Runtime {
type AuthorityId = ImOnlineId;
type Event = Event;
......@@ -477,6 +487,7 @@ impl im_online::Trait for Runtime {
type SubmitTransaction = SubmitTransaction;
type SessionDuration = SessionDuration;
type ReportUnresponsiveness = Offences;
type UnsignedPriority = ImOnlineUnsignedPriority;
}
impl grandpa::Trait for Runtime {
......
......@@ -36,10 +36,13 @@ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
ApplyExtrinsicResult, Perbill, RuntimeDebug, KeyTypeId,
transaction_validity::{
TransactionValidity, InvalidTransaction, TransactionValidityError, TransactionSource,
TransactionValidity, InvalidTransaction, TransactionValidityError, TransactionSource, TransactionPriority,
},
curve::PiecewiseLinear,
traits::{BlakeTwo256, Block as BlockT, StaticLookup, SignedExtension, OpaqueKeys, ConvertInto},
traits::{
BlakeTwo256, Block as BlockT, StaticLookup, SignedExtension, OpaqueKeys, ConvertInto,
DispatchInfoOf,
},
};
use version::RuntimeVersion;
use grandpa::{AuthorityId as GrandpaId, fg_primitives};
......@@ -50,7 +53,6 @@ use sp_staking::SessionIndex;
use frame_support::{
parameter_types, construct_runtime,
traits::{KeyOwnerProofSystem, Randomness},
weights::DispatchInfo,
};
use pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;
use session::historical as session_historical;
......@@ -100,11 +102,16 @@ impl SignedExtension for RestrictFunctionality {
type Call = Call;
type AdditionalSigned = ();
type Pre = ();
type DispatchInfo = DispatchInfo;
fn additional_signed(&self) -> rstd::result::Result<(), TransactionValidityError> { Ok(()) }
fn validate(&self, _: &Self::AccountId, call: &Self::Call, _: DispatchInfo, _: usize)
fn validate(
&self,
_: &Self::AccountId,
call: &Self::Call,
_: &DispatchInfoOf<Self::Call>,
_: usize
)
-> TransactionValidity
{
match call {
......@@ -269,6 +276,7 @@ parameter_types! {
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const MaxNominatorRewardedPerValidator: u32 = 64;
pub const ElectionLookahead: BlockNumber = 0;
pub const StakingUnsignedPriority: TransactionPriority = TransactionPriority::max_value() / 2;
}
impl staking::Trait for Runtime {
......@@ -291,6 +299,7 @@ impl staking::Trait for Runtime {
type ElectionLookahead = ElectionLookahead;
type Call = Call;
type SubmitTransaction = system::offchain::TransactionSubmitter<(), Runtime, Extrinsic>;
type UnsignedPriority = StakingUnsignedPriority;
}
impl grandpa::Trait for Runtime {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment