mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Staking pallet (#373)
* initial staking pallet * add staking pallet to runtime * support session rotation for serai * optimizations & cleaning * fix deny * add serai network to initial networks * a few tweaks & comments * fix some pr comments * Rewrite validator-sets with logarithmic algorithms Uses the fact the underlying DB is sorted to achieve sorting of potential validators by stake. Removes release of deallocated stake for now. --------- Co-authored-by: Luke Parker <lukeparker5132@gmail.com>
This commit is contained in:
@@ -50,7 +50,9 @@ pallet-transaction-payment = { git = "https://github.com/serai-dex/substrate", d
|
||||
tokens-pallet = { package = "serai-tokens-pallet", path = "../tokens/pallet", default-features = false }
|
||||
in-instructions-pallet = { package = "serai-in-instructions-pallet", path = "../in-instructions/pallet", default-features = false }
|
||||
|
||||
staking-pallet = { package = "serai-staking-pallet", path = "../staking/pallet", default-features = false }
|
||||
validator-sets-pallet = { package = "serai-validator-sets-pallet", path = "../validator-sets/pallet", default-features = false }
|
||||
|
||||
pallet-session = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
pallet-babe = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
pallet-grandpa = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
@@ -102,7 +104,9 @@ std = [
|
||||
"tokens-pallet/std",
|
||||
"in-instructions-pallet/std",
|
||||
|
||||
"staking-pallet/std",
|
||||
"validator-sets-pallet/std",
|
||||
|
||||
"pallet-session/std",
|
||||
"pallet-babe/std",
|
||||
"pallet-grandpa/std",
|
||||
|
||||
@@ -21,6 +21,7 @@ pub use pallet_assets as assets;
|
||||
pub use tokens_pallet as tokens;
|
||||
pub use in_instructions_pallet as in_instructions;
|
||||
|
||||
pub use staking_pallet as staking;
|
||||
pub use validator_sets_pallet as validator_sets;
|
||||
|
||||
pub use pallet_session as session;
|
||||
@@ -142,7 +143,7 @@ parameter_types! {
|
||||
NORMAL_DISPATCH_RATIO,
|
||||
);
|
||||
|
||||
pub const MaxAuthorities: u32 = 100;
|
||||
pub const MaxAuthorities: u32 = validator_sets::primitives::MAX_VALIDATORS_PER_SET;
|
||||
}
|
||||
|
||||
pub struct CallFilter;
|
||||
@@ -172,10 +173,24 @@ impl Contains<RuntimeCall> for CallFilter {
|
||||
return matches!(call, in_instructions::Call::execute_batch { .. });
|
||||
}
|
||||
|
||||
if let RuntimeCall::Staking(call) = call {
|
||||
return matches!(
|
||||
call,
|
||||
staking::Call::stake { .. } |
|
||||
staking::Call::unstake { .. } |
|
||||
staking::Call::allocate { .. } |
|
||||
staking::Call::deallocate { .. }
|
||||
);
|
||||
}
|
||||
|
||||
if let RuntimeCall::ValidatorSets(call) = call {
|
||||
return matches!(call, validator_sets::Call::set_keys { .. });
|
||||
}
|
||||
|
||||
if let RuntimeCall::Session(call) = call {
|
||||
return matches!(call, session::Call::set_keys { .. });
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
}
|
||||
@@ -300,6 +315,10 @@ impl in_instructions::Config for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
}
|
||||
|
||||
impl staking::Config for Runtime {
|
||||
type Currency = Balances;
|
||||
}
|
||||
|
||||
impl validator_sets::Config for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
}
|
||||
@@ -317,7 +336,7 @@ impl session::Config for Runtime {
|
||||
type ValidatorIdOf = IdentityValidatorIdOf;
|
||||
type ShouldEndSession = Babe;
|
||||
type NextSessionRotation = Babe;
|
||||
type SessionManager = (); // TODO?
|
||||
type SessionManager = Staking;
|
||||
type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
|
||||
type Keys = SessionKeys;
|
||||
type WeightInfo = session::weights::SubstrateWeight<Runtime>;
|
||||
@@ -393,6 +412,8 @@ construct_runtime!(
|
||||
|
||||
ValidatorSets: validator_sets,
|
||||
|
||||
Staking: staking,
|
||||
|
||||
Session: session,
|
||||
Babe: babe,
|
||||
Grandpa: grandpa,
|
||||
|
||||
Reference in New Issue
Block a user