Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: disable slashing #184

Merged
merged 9 commits into from
Mar 29, 2021
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion pallets/claims/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![cfg_attr(not(feature = "std"), no_std)]

#![allow(clippy::unused_unit)]

use codec::{Decode, Encode};
Expand Down Expand Up @@ -213,3 +212,10 @@ where
}
}
}

impl<T: Config + Send + Sync> ValidateClaim<T> {
#[cfg_attr(feature = "cargo-clippy", allow(clippy::new_without_default))]
pub fn new() -> Self {
Self(sp_std::marker::PhantomData)
}
}
8 changes: 4 additions & 4 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ homepage = 'https://github.com/galacticcouncil/hydradx-node'
license = 'Unlicense'
name = 'hydra-dx-runtime'
repository = 'https://github.com/galacticcouncil/hydradx-node'
version = '5.0.0'
version = '6.0.0'

[package.metadata.docs.rs]
targets = ['x86_64-unknown-linux-gnu']
Expand All @@ -27,7 +27,7 @@ tracing-core = {optional = true, version = '0.1.17'}

# local dependencies
module-amm-rpc-runtime-api = {path = '../pallets/amm/rpc/runtime-api', default-features = false}
pallet-amm = {path = '../pallets/amm', default-features = false }
pallet-amm = {path = '../pallets/amm', default-features = false}
pallet-asset-registry = {path = '../pallets/asset-registry', default-features = false}
pallet-claims = {path = '../pallets/claims', default-features = false}
pallet-exchange = {path = '../pallets/exchange', default-features = false}
Expand All @@ -47,16 +47,16 @@ pallet-authority-discovery = {default-features = false, version = '3.0.0'}
pallet-authorship = {default-features = false, version = '3.0.0'}
pallet-babe = {default-features = false, version = '3.0.0'}
pallet-collective = {default-features = false, version = '3.0.0'}
pallet-elections-phragmen = {default-features = false, version = '3.0.0'}
pallet-election-provider-multi-phase = {default-features = false, version = '3.0.0'}
pallet-elections-phragmen = {default-features = false, version = '3.0.0'}
pallet-im-online = {default-features = false, version = '3.0.0'}
pallet-offences = {default-features = false, version = '3.0.0'}
pallet-scheduler = {default-features = false, version = '3.0.0'}
pallet-session = {default-features = false, version = '3.0.0'}
pallet-staking = {default-features = false, version = '3.0.0'}
pallet-staking-reward-curve = {default-features = false, version = '3.0.0'}
pallet-tips = {default-features = false, version = '=3.0.0'}
pallet-treasury = {default-features = false, version = '3.0.0'}
pallet-scheduler = {default-features = false, version = '3.0.0'}
sp-authority-discovery = {default-features = false, version = '3.0.0'}
sp-consensus-babe = {default-features = false, version = '0.9.0'}

Expand Down
132 changes: 101 additions & 31 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

use codec::Encode;
use pallet_grandpa::fg_primitives;
use pallet_grandpa::{AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList};
use sp_api::impl_runtime_apis;
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
use sp_core::{
crypto::KeyTypeId,
u32_trait::{_1, _2, _3, _4},
u32_trait::{_1, _2, _4},
OpaqueMetadata,
};
use sp_runtime::traits::{
BlakeTwo256, Block as BlockT, IdentifyAccount, IdentityLookup, NumberFor, OpaqueKeys, Verify,
BlakeTwo256, Block as BlockT, Extrinsic as ExtrinsicT, IdentifyAccount, IdentityLookup, NumberFor, OpaqueKeys,
SaturatedConversion, Verify,
};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
Expand Down Expand Up @@ -131,7 +133,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("hydra-dx"),
impl_name: create_runtime_str!("hydra-dx"),
authoring_version: 1,
spec_version: 5,
spec_version: 6,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down Expand Up @@ -277,14 +279,15 @@ impl pallet_grandpa::Config for Runtime {
type Event = Event;
type Call = Call;

type KeyOwnerProofSystem = ();

type KeyOwnerProof = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;

type KeyOwnerIdentification =
<Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::IdentificationTuple;

type HandleEquivocation = ();
type KeyOwnerProofSystem = Historical;

type HandleEquivocation =
pallet_grandpa::EquivocationHandler<Self::KeyOwnerIdentification, Offences, ReportLongevity>;

type WeightInfo = ();
}
Expand Down Expand Up @@ -383,6 +386,7 @@ impl pallet_identity::Config for Runtime {
}

/// ORML Configurations

impl orml_tokens::Config for Runtime {
type Event = Event;
type Balance = Balance;
Expand Down Expand Up @@ -478,7 +482,7 @@ pallet_staking_reward_curve::build! {
parameter_types! {
pub const SessionsPerEra: sp_staking::SessionIndex = 6;
pub const BondingDuration: pallet_staking::EraIndex = 24 * 28;
pub const SlashDeferDuration: pallet_staking::EraIndex = 24 * 7; // 1/4 the bonding duration.
pub const SlashDeferDuration: pallet_staking::EraIndex = 24 * 28 - 1; //SlashDeferDuration should be less than BondingDuration https://github.com/paritytech/substrate/blob/49a4103f4bfef55be20a5c6d26e18ff3003c3353/frame/staking/src/lib.rs#L1402
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const MaxNominatorRewardedPerValidator: u32 = 64;
pub const ElectionLookahead: BlockNumber = EPOCH_DURATION_IN_BLOCKS / 4;
Expand All @@ -487,6 +491,9 @@ parameter_types! {
pub MinSolutionScoreBump: Perbill = Perbill::from_rational_approximation(5u32, 10_000);
}

type SlashCancelOrigin =
EnsureOneOf<AccountId, EnsureRoot<AccountId>, pallet_collective::EnsureMember<AccountId, CouncilCollective>>;

impl pallet_staking::Config for Runtime {
type Currency = Balances;
type UnixTime = Timestamp;
Expand All @@ -500,7 +507,7 @@ impl pallet_staking::Config for Runtime {
type BondingDuration = BondingDuration;
type SlashDeferDuration = SlashDeferDuration;
// A super-majority of the council can cancel the slash.
type SlashCancelOrigin = pallet_collective::EnsureProportionAtLeast<_3, _4, AccountId, CouncilCollective>;
type SlashCancelOrigin = SlashCancelOrigin;
type SessionInterface = Self;
type RewardCurve = RewardCurve;
type NextNewSession = Session;
Expand Down Expand Up @@ -676,7 +683,7 @@ impl pallet_babe::Config for Runtime {
type KeyOwnerIdentification =
<Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, pallet_babe::AuthorityId)>>::IdentificationTuple;

type HandleEquivocation = pallet_babe::EquivocationHandler<Self::KeyOwnerIdentification, (), ReportLongevity>;
type HandleEquivocation = pallet_babe::EquivocationHandler<Self::KeyOwnerIdentification, Offences, ReportLongevity>;
type WeightInfo = ();
}

Expand Down Expand Up @@ -708,6 +715,60 @@ parameter_types! {
pub const StakingUnsignedPriority: TransactionPriority = TransactionPriority::max_value() / 2;
}

pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;

impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for Runtime
where
Call: From<LocalCall>,
{
fn create_transaction<C: frame_system::offchain::AppCrypto<Self::Public, Self::Signature>>(
call: Call,
public: <Signature as Verify>::Signer,
account: AccountId,
nonce: Index,
) -> Option<(Call, <UncheckedExtrinsic as ExtrinsicT>::SignaturePayload)> {
use sp_runtime::traits::StaticLookup;

let tip = 0;
// take the biggest period possible.
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>()
// The `System::block_number` is initialized with `n+1`,
// so the actual block number is `n`.
.saturating_sub(1);

let era = generic::Era::mortal(period, current_block);
let extra: SignedExtra = (
frame_system::CheckSpecVersion::<Runtime>::new(),
frame_system::CheckTxVersion::<Runtime>::new(),
frame_system::CheckGenesis::<Runtime>::new(),
frame_system::CheckEra::<Runtime>::from(era),
frame_system::CheckNonce::<Runtime>::from(nonce),
frame_system::CheckWeight::<Runtime>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
pallet_claims::ValidateClaim::<Runtime>::new(),
);
let raw_payload = SignedPayload::new(call, extra)
.map_err(|e| {
frame_support::debug::warn!("Unable to create signed payload: {:?}", e);
})
.ok()?;
let signature = raw_payload.using_encoded(|payload| C::sign(payload, public))?;
let address = <Runtime as frame_system::Config>::Lookup::unlookup(account);
let (call, extra, _) = raw_payload.deconstruct();
Some((call, (address, signature, extra)))
}
}

impl frame_system::offchain::SigningTypes for Runtime {
type Public = <Signature as Verify>::Signer;
type Signature = Signature;
}

impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime
where
Call: From<C>,
Expand Down Expand Up @@ -738,19 +799,19 @@ impl pallet_offences::Config for Runtime {
}

parameter_types! {
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(10) * BlockWeights::get().max_block;
pub const MaxScheduledPerBlock: u32 = 50;
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(10) * BlockWeights::get().max_block;
pub const MaxScheduledPerBlock: u32 = 50;
}

impl pallet_scheduler::Config for Runtime {
type Event = Event;
type Origin = Origin;
type PalletsOrigin = OriginCaller;
type Call = Call;
type MaximumWeight = MaximumSchedulerWeight;
type ScheduleOrigin = EnsureRoot<AccountId>;
type MaxScheduledPerBlock = MaxScheduledPerBlock;
type WeightInfo = ();
type Event = Event;
type Origin = Origin;
type PalletsOrigin = OriginCaller;
type Call = Call;
type MaximumWeight = MaximumSchedulerWeight;
type ScheduleOrigin = EnsureRoot<AccountId>;
type MaxScheduledPerBlock = MaxScheduledPerBlock;
type WeightInfo = ();
}

// Create the runtime by composing the FRAME pallets that were previously configured.
Expand All @@ -762,20 +823,25 @@ construct_runtime!(
{
System: frame_system::{Module, Call, Config, Storage, Event<T>},
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},


Babe: pallet_babe::{Module, Call, Storage, Config, ValidateUnsigned},

Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},
Grandpa: pallet_grandpa::{Module, Call, Storage, Config, Event},
Grandpa: pallet_grandpa::{Module, Call, Storage, Config, Event, ValidateUnsigned},
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
TransactionPayment: pallet_transaction_payment::{Module, Storage},
Sudo: pallet_sudo::{Module, Call, Config<T>, Storage, Event<T>},
Scheduler: pallet_scheduler::{Module, Call, Storage, Event<T>},
Identity: pallet_identity::{Module, Call, Storage, Event<T>},



//Staking related modules
Authorship: pallet_authorship::{Module, Call, Storage, Inherent},
Staking: pallet_staking::{Module, Call, Config<T>, Storage, Event<T>, ValidateUnsigned},
ElectionProviderMultiPhase: pallet_election_provider_multi_phase::{Module, Call, Storage, Event<T>, ValidateUnsigned},
Treasury: pallet_treasury::{Module, Call, Storage, Config, Event<T>},
Babe: pallet_babe::{Module, Call, Storage, Config, ValidateUnsigned},
Session: pallet_session::{Module, Call, Storage, Event, Config<T>},
Elections: pallet_elections_phragmen::{Module, Call, Storage, Event<T>, Config<T>},
Council: pallet_collective::<Instance1>::{Module, Call, Storage, Origin<T>, Event<T>, Config<T>},
Expand Down Expand Up @@ -862,8 +928,6 @@ impl_runtime_apis! {
_slot_number: sp_consensus_babe::Slot,
authority_id: sp_consensus_babe::AuthorityId,
) -> Option<sp_consensus_babe::OpaqueKeyOwnershipProof> {
use codec::Encode;

Historical::prove((sp_consensus_babe::KEY_TYPE, authority_id))
.map(|p| p.encode())
.map(sp_consensus_babe::OpaqueKeyOwnershipProof::new)
Expand Down Expand Up @@ -967,23 +1031,29 @@ impl_runtime_apis! {
}

fn submit_report_equivocation_unsigned_extrinsic(
_equivocation_proof: fg_primitives::EquivocationProof<
equivocation_proof: fg_primitives::EquivocationProof<
<Block as BlockT>::Hash,
NumberFor<Block>,
>,
_key_owner_proof: fg_primitives::OpaqueKeyOwnershipProof,
key_owner_proof: fg_primitives::OpaqueKeyOwnershipProof,
) -> Option<()> {
None
let key_owner_proof = key_owner_proof.decode()?;

Grandpa::submit_unsigned_equivocation_report(
equivocation_proof,
key_owner_proof,
)
}

fn generate_key_ownership_proof(
_set_id: fg_primitives::SetId,
_authority_id: GrandpaId,
authority_id: GrandpaId,
) -> Option<fg_primitives::OpaqueKeyOwnershipProof> {
// NOTE: this is the only implementation possible since we've
// defined our key owner proof type as a bottom type (i.e. a type
// with no values).
None
use codec::Encode;

Historical::prove((fg_primitives::KEY_TYPE, authority_id))
.map(|p| p.encode())
.map(fg_primitives::OpaqueKeyOwnershipProof::new)
}
}

Expand Down