mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-10 05:09:22 +00:00
Add pallet sessions to runtime, create pallet-tendermint
This commit is contained in:
@@ -18,11 +18,11 @@ codec = { package = "parity-scale-codec", version = "3", default-features = fals
|
||||
scale-info = { version = "2", default-features = false, features = ["derive"] }
|
||||
|
||||
sp-core = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
sp-application-crypto = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
sp-std = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
sp-version = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
sp-inherents = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
sp-offchain = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
sp-session = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
sp-transaction-pool = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
sp-block-builder = { git = "https://github.com/serai-dex/substrate", default-features = false}
|
||||
sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
@@ -41,6 +41,9 @@ pallet-transaction-payment = { git = "https://github.com/serai-dex/substrate", d
|
||||
pallet-contracts-primitives = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
pallet-contracts = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
|
||||
pallet-session = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
pallet-tendermint = { path = "../pallet-tendermint", default-features = false }
|
||||
|
||||
frame-system-rpc-runtime-api = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
|
||||
@@ -53,11 +56,11 @@ std = [
|
||||
"scale-info/std",
|
||||
|
||||
"sp-core/std",
|
||||
"sp-application-crypto/std",
|
||||
"sp-std/std",
|
||||
"sp-version/std",
|
||||
"sp-inherents/std",
|
||||
"sp-offchain/std",
|
||||
"sp-session/std",
|
||||
"sp-transaction-pool/std",
|
||||
"sp-block-builder/std",
|
||||
"sp-runtime/std",
|
||||
@@ -75,6 +78,9 @@ std = [
|
||||
"pallet-contracts/std",
|
||||
"pallet-contracts-primitives/std",
|
||||
|
||||
"pallet-session/std",
|
||||
"pallet-tendermint/std",
|
||||
|
||||
"frame-system-rpc-runtime-api/std",
|
||||
"pallet-transaction-payment-rpc-runtime-api/std",
|
||||
]
|
||||
@@ -90,6 +96,8 @@ runtime-benchmarks = [
|
||||
|
||||
"pallet-timestamp/runtime-benchmarks",
|
||||
"pallet-balances/runtime-benchmarks",
|
||||
|
||||
"pallet-tendermint/runtime-benchmarks",
|
||||
]
|
||||
|
||||
default = ["std"]
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
#[cfg(feature = "std")]
|
||||
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
||||
|
||||
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
|
||||
pub use sp_core::sr25519::Signature;
|
||||
use sp_core::OpaqueMetadata;
|
||||
pub use sp_core::sr25519::{Public, Signature};
|
||||
use sp_runtime::{
|
||||
create_runtime_str, generic, impl_opaque_keys,
|
||||
traits::{IdentityLookup, BlakeTwo256, Block as BlockT},
|
||||
traits::{Convert, OpaqueKeys, IdentityLookup, BlakeTwo256, Block as BlockT},
|
||||
transaction_validity::{TransactionSource, TransactionValidity},
|
||||
ApplyExtrinsicResult, Perbill,
|
||||
};
|
||||
@@ -32,11 +32,13 @@ pub use pallet_timestamp::Call as TimestampCall;
|
||||
pub use pallet_balances::Call as BalancesCall;
|
||||
use pallet_transaction_payment::CurrencyAdapter;
|
||||
|
||||
use pallet_session::PeriodicSessions;
|
||||
|
||||
/// An index to a block.
|
||||
pub type BlockNumber = u32;
|
||||
|
||||
/// Account ID type, equivalent to a public key
|
||||
pub type AccountId = sp_core::sr25519::Public;
|
||||
pub type AccountId = Public;
|
||||
|
||||
/// Balance of an account.
|
||||
pub type Balance = u64;
|
||||
@@ -57,10 +59,14 @@ pub mod opaque {
|
||||
pub type BlockId = generic::BlockId<Block>;
|
||||
|
||||
impl_opaque_keys! {
|
||||
pub struct SessionKeys {}
|
||||
pub struct SessionKeys {
|
||||
pub tendermint: Tendermint,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
use opaque::SessionKeys;
|
||||
|
||||
#[sp_version::runtime_version]
|
||||
pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
spec_name: create_runtime_str!("serai"),
|
||||
@@ -206,6 +212,30 @@ impl pallet_contracts::Config for Runtime {
|
||||
type MaxStorageKeyLen = ConstU32<128>;
|
||||
}
|
||||
|
||||
impl pallet_tendermint::Config for Runtime {}
|
||||
|
||||
const SESSION_LENGTH: BlockNumber = 5 * DAYS;
|
||||
type Sessions = PeriodicSessions<ConstU32<{ SESSION_LENGTH }>, ConstU32<{ SESSION_LENGTH }>>;
|
||||
|
||||
pub struct IdentityValidatorIdOf;
|
||||
impl Convert<Public, Option<Public>> for IdentityValidatorIdOf {
|
||||
fn convert(key: Public) -> Option<Public> {
|
||||
Some(key)
|
||||
}
|
||||
}
|
||||
|
||||
impl pallet_session::Config for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type ValidatorId = AccountId;
|
||||
type ValidatorIdOf = IdentityValidatorIdOf;
|
||||
type ShouldEndSession = Sessions;
|
||||
type NextSessionRotation = Sessions;
|
||||
type SessionManager = ();
|
||||
type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
|
||||
type Keys = SessionKeys;
|
||||
type WeightInfo = pallet_session::weights::SubstrateWeight<Runtime>;
|
||||
}
|
||||
|
||||
pub type Address = AccountId;
|
||||
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
||||
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
|
||||
@@ -242,6 +272,8 @@ construct_runtime!(
|
||||
Balances: pallet_balances,
|
||||
TransactionPayment: pallet_transaction_payment,
|
||||
Contracts: pallet_contracts,
|
||||
Session: pallet_session,
|
||||
Tendermint: pallet_tendermint,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -317,18 +349,6 @@ sp_api::impl_runtime_apis! {
|
||||
}
|
||||
}
|
||||
|
||||
impl sp_session::SessionKeys<Block> for Runtime {
|
||||
fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
|
||||
opaque::SessionKeys::generate(seed)
|
||||
}
|
||||
|
||||
fn decode_session_keys(
|
||||
encoded: Vec<u8>,
|
||||
) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {
|
||||
opaque::SessionKeys::decode_into_raw_public_keys(&encoded)
|
||||
}
|
||||
}
|
||||
|
||||
impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {
|
||||
fn account_nonce(account: AccountId) -> Index {
|
||||
System::account_nonce(account)
|
||||
|
||||
Reference in New Issue
Block a user