2022-07-15 04:05:00 +00:00
|
|
|
#![cfg_attr(not(feature = "std"), no_std)]
|
|
|
|
#![recursion_limit = "256"]
|
|
|
|
|
|
|
|
#[cfg(feature = "std")]
|
|
|
|
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
|
|
|
|
|
|
|
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
|
|
|
|
use sp_runtime::{
|
|
|
|
create_runtime_str, generic, impl_opaque_keys,
|
2022-07-30 22:21:20 +00:00
|
|
|
traits::{IdentityLookup, BlakeTwo256, Block as BlockT},
|
2022-07-15 04:05:00 +00:00
|
|
|
transaction_validity::{TransactionSource, TransactionValidity},
|
2022-07-30 22:21:20 +00:00
|
|
|
ApplyExtrinsicResult, Perbill,
|
2022-07-15 04:05:00 +00:00
|
|
|
};
|
|
|
|
use sp_std::prelude::*;
|
|
|
|
#[cfg(feature = "std")]
|
|
|
|
use sp_version::NativeVersion;
|
|
|
|
use sp_version::RuntimeVersion;
|
|
|
|
|
|
|
|
use frame_support::{
|
2022-09-29 18:33:09 +00:00
|
|
|
traits::{ConstU8, ConstU32, ConstU64},
|
2022-07-15 05:26:07 +00:00
|
|
|
weights::{
|
2022-10-20 05:27:35 +00:00
|
|
|
constants::{RocksDbWeight, WEIGHT_PER_SECOND},
|
2022-09-29 18:33:09 +00:00
|
|
|
IdentityFee, Weight,
|
2022-07-15 05:26:07 +00:00
|
|
|
},
|
2022-09-29 18:33:09 +00:00
|
|
|
dispatch::DispatchClass,
|
2022-07-15 05:26:07 +00:00
|
|
|
parameter_types, construct_runtime,
|
2022-07-15 04:05:00 +00:00
|
|
|
};
|
|
|
|
pub use frame_system::Call as SystemCall;
|
2022-07-17 01:06:54 +00:00
|
|
|
|
2022-07-15 04:05:00 +00:00
|
|
|
pub use pallet_timestamp::Call as TimestampCall;
|
|
|
|
pub use pallet_balances::Call as BalancesCall;
|
|
|
|
use pallet_transaction_payment::CurrencyAdapter;
|
|
|
|
|
2022-09-29 09:25:29 +00:00
|
|
|
/// An index to a block.
|
2022-07-15 04:05:00 +00:00
|
|
|
pub type BlockNumber = u32;
|
|
|
|
|
2022-07-30 22:21:20 +00:00
|
|
|
/// Signature type
|
|
|
|
pub type Signature = sp_core::sr25519::Signature;
|
2022-07-15 04:05:00 +00:00
|
|
|
|
2022-07-30 22:21:20 +00:00
|
|
|
/// Account ID type, equivalent to a public key
|
|
|
|
pub type AccountId = sp_core::sr25519::Public;
|
2022-07-15 04:05:00 +00:00
|
|
|
|
2022-09-29 09:25:29 +00:00
|
|
|
/// Balance of an account.
|
2022-07-15 04:05:00 +00:00
|
|
|
pub type Balance = u64;
|
|
|
|
|
2022-09-29 09:25:29 +00:00
|
|
|
/// Index of a transaction in the chain, for a given account.
|
2022-07-15 04:05:00 +00:00
|
|
|
pub type Index = u32;
|
|
|
|
|
2022-09-29 09:25:29 +00:00
|
|
|
/// A hash of some data used by the chain.
|
2022-07-15 04:05:00 +00:00
|
|
|
pub type Hash = sp_core::H256;
|
|
|
|
|
|
|
|
pub mod opaque {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
|
|
|
|
|
|
|
|
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
|
|
|
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
|
|
|
|
pub type BlockId = generic::BlockId<Block>;
|
|
|
|
|
|
|
|
impl_opaque_keys! {
|
|
|
|
pub struct SessionKeys {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[sp_version::runtime_version]
|
|
|
|
pub const VERSION: RuntimeVersion = RuntimeVersion {
|
|
|
|
spec_name: create_runtime_str!("serai"),
|
|
|
|
impl_name: create_runtime_str!("turoctocrab"),
|
|
|
|
authoring_version: 1,
|
|
|
|
spec_version: 100,
|
|
|
|
impl_version: 1,
|
|
|
|
apis: RUNTIME_API_VERSIONS,
|
|
|
|
transaction_version: 1,
|
2022-07-15 05:26:07 +00:00
|
|
|
state_version: 1,
|
2022-07-15 04:05:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
pub const MILLISECS_PER_BLOCK: u64 = 6000;
|
|
|
|
pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;
|
|
|
|
|
2022-09-29 09:25:29 +00:00
|
|
|
/// Measured in blocks.
|
2022-07-15 04:05:00 +00:00
|
|
|
pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
|
|
|
|
pub const HOURS: BlockNumber = MINUTES * 60;
|
|
|
|
pub const DAYS: BlockNumber = HOURS * 24;
|
|
|
|
|
|
|
|
#[cfg(feature = "std")]
|
|
|
|
pub fn native_version() -> NativeVersion {
|
|
|
|
NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
|
|
|
|
}
|
|
|
|
|
|
|
|
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
|
|
|
|
|
2022-07-17 01:06:54 +00:00
|
|
|
// Unit = the base number of indivisible units for balances
|
|
|
|
const UNIT: Balance = 1_000_000_000_000;
|
|
|
|
const MILLIUNIT: Balance = 1_000_000_000;
|
|
|
|
|
|
|
|
const fn deposit(items: u32, bytes: u32) -> Balance {
|
|
|
|
(items as Balance * UNIT + (bytes as Balance) * (5 * MILLIUNIT / 100)) / 10
|
|
|
|
}
|
|
|
|
|
2022-07-15 04:05:00 +00:00
|
|
|
parameter_types! {
|
|
|
|
pub const BlockHashCount: BlockNumber = 2400;
|
|
|
|
pub const Version: RuntimeVersion = VERSION;
|
2022-07-17 01:06:54 +00:00
|
|
|
|
2022-07-30 22:21:20 +00:00
|
|
|
pub const SS58Prefix: u8 = 42; // TODO: Remove for Bech32m
|
2022-07-17 01:06:54 +00:00
|
|
|
|
|
|
|
// 1 MB block size limit
|
|
|
|
pub BlockLength: frame_system::limits::BlockLength =
|
|
|
|
frame_system::limits::BlockLength::max_with_normal_ratio(1024 * 1024, NORMAL_DISPATCH_RATIO);
|
|
|
|
pub BlockWeights: frame_system::limits::BlockWeights =
|
2022-10-20 05:27:35 +00:00
|
|
|
frame_system::limits::BlockWeights::with_sensible_defaults(
|
|
|
|
(2u64 * WEIGHT_PER_SECOND).set_proof_size(u64::MAX),
|
|
|
|
NORMAL_DISPATCH_RATIO,
|
|
|
|
);
|
2022-07-17 01:06:54 +00:00
|
|
|
|
|
|
|
pub const DepositPerItem: Balance = deposit(1, 0);
|
|
|
|
pub const DepositPerByte: Balance = deposit(0, 1);
|
|
|
|
pub const DeletionQueueDepth: u32 = 128;
|
|
|
|
// The lazy deletion runs inside on_initialize.
|
|
|
|
pub DeletionWeightLimit: Weight = BlockWeights::get()
|
|
|
|
.per_class
|
|
|
|
.get(DispatchClass::Normal)
|
|
|
|
.max_total
|
|
|
|
.unwrap_or(BlockWeights::get().max_block);
|
|
|
|
pub Schedule: pallet_contracts::Schedule<Runtime> = Default::default();
|
2022-07-15 04:05:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl frame_system::Config for Runtime {
|
|
|
|
type BaseCallFilter = frame_support::traits::Everything;
|
|
|
|
type BlockWeights = BlockWeights;
|
|
|
|
type BlockLength = BlockLength;
|
|
|
|
type AccountId = AccountId;
|
2022-09-29 18:33:09 +00:00
|
|
|
type RuntimeCall = RuntimeCall;
|
2022-07-30 22:21:20 +00:00
|
|
|
type Lookup = IdentityLookup<AccountId>;
|
2022-07-15 04:05:00 +00:00
|
|
|
type Index = Index;
|
|
|
|
type BlockNumber = BlockNumber;
|
|
|
|
type Hash = Hash;
|
|
|
|
type Hashing = BlakeTwo256;
|
|
|
|
type Header = Header;
|
2022-09-29 18:33:09 +00:00
|
|
|
type RuntimeOrigin = RuntimeOrigin;
|
|
|
|
type RuntimeEvent = RuntimeEvent;
|
2022-07-15 04:05:00 +00:00
|
|
|
type BlockHashCount = BlockHashCount;
|
|
|
|
type DbWeight = RocksDbWeight;
|
|
|
|
type Version = Version;
|
|
|
|
type PalletInfo = PalletInfo;
|
|
|
|
|
|
|
|
type OnNewAccount = ();
|
|
|
|
type OnKilledAccount = ();
|
|
|
|
type OnSetCode = ();
|
|
|
|
|
|
|
|
type AccountData = pallet_balances::AccountData<Balance>;
|
|
|
|
type SystemWeightInfo = ();
|
2022-07-30 22:21:20 +00:00
|
|
|
type SS58Prefix = SS58Prefix; // TODO: Remove for Bech32m
|
2022-07-15 04:05:00 +00:00
|
|
|
|
|
|
|
type MaxConsumers = frame_support::traits::ConstU32<16>;
|
|
|
|
}
|
|
|
|
|
2022-07-17 01:06:54 +00:00
|
|
|
impl pallet_randomness_collective_flip::Config for Runtime {}
|
|
|
|
|
2022-07-15 04:05:00 +00:00
|
|
|
impl pallet_timestamp::Config for Runtime {
|
|
|
|
type Moment = u64;
|
|
|
|
type OnTimestampSet = ();
|
|
|
|
type MinimumPeriod = ConstU64<{ SLOT_DURATION / 2 }>;
|
|
|
|
type WeightInfo = ();
|
|
|
|
}
|
|
|
|
|
|
|
|
impl pallet_balances::Config for Runtime {
|
|
|
|
type MaxLocks = ConstU32<50>;
|
|
|
|
type MaxReserves = ();
|
|
|
|
type ReserveIdentifier = [u8; 8];
|
|
|
|
type Balance = Balance;
|
2022-09-29 18:33:09 +00:00
|
|
|
type RuntimeEvent = RuntimeEvent;
|
2022-07-15 04:05:00 +00:00
|
|
|
type DustRemoval = ();
|
|
|
|
type ExistentialDeposit = ConstU64<500>;
|
|
|
|
type AccountStore = System;
|
|
|
|
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl pallet_transaction_payment::Config for Runtime {
|
2022-09-29 18:33:09 +00:00
|
|
|
type RuntimeEvent = RuntimeEvent;
|
2022-07-15 04:05:00 +00:00
|
|
|
type OnChargeTransaction = CurrencyAdapter<Balances, ()>;
|
|
|
|
type OperationalFeeMultiplier = ConstU8<5>;
|
|
|
|
type WeightToFee = IdentityFee<Balance>;
|
|
|
|
type LengthToFee = IdentityFee<Balance>;
|
|
|
|
type FeeMultiplierUpdate = ();
|
|
|
|
}
|
|
|
|
|
2022-07-17 01:06:54 +00:00
|
|
|
impl pallet_contracts::Config for Runtime {
|
|
|
|
type Time = Timestamp;
|
|
|
|
type Randomness = RandomnessCollectiveFlip;
|
|
|
|
type Currency = Balances;
|
2022-09-29 18:33:09 +00:00
|
|
|
type RuntimeEvent = RuntimeEvent;
|
|
|
|
type RuntimeCall = RuntimeCall;
|
2022-07-17 01:06:54 +00:00
|
|
|
|
|
|
|
type CallFilter = frame_support::traits::Nothing;
|
|
|
|
type DepositPerItem = DepositPerItem;
|
|
|
|
type DepositPerByte = DepositPerByte;
|
|
|
|
type CallStack = [pallet_contracts::Frame<Self>; 31];
|
|
|
|
type WeightPrice = pallet_transaction_payment::Pallet<Self>;
|
|
|
|
type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;
|
|
|
|
type ChainExtension = ();
|
|
|
|
type DeletionQueueDepth = DeletionQueueDepth;
|
|
|
|
type DeletionWeightLimit = DeletionWeightLimit;
|
|
|
|
type Schedule = Schedule;
|
|
|
|
type AddressGenerator = pallet_contracts::DefaultAddressGenerator;
|
|
|
|
|
|
|
|
type MaxCodeLen = ConstU32<{ 128 * 1024 }>;
|
|
|
|
type MaxStorageKeyLen = ConstU32<128>;
|
|
|
|
}
|
|
|
|
|
2022-07-30 22:21:20 +00:00
|
|
|
pub type Address = AccountId;
|
2022-07-15 04:05:00 +00:00
|
|
|
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
|
|
|
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
|
|
|
|
pub type SignedExtra = (
|
|
|
|
frame_system::CheckNonZeroSender<Runtime>,
|
|
|
|
frame_system::CheckSpecVersion<Runtime>,
|
|
|
|
frame_system::CheckTxVersion<Runtime>,
|
|
|
|
frame_system::CheckGenesis<Runtime>,
|
|
|
|
frame_system::CheckEra<Runtime>,
|
|
|
|
frame_system::CheckNonce<Runtime>,
|
|
|
|
frame_system::CheckWeight<Runtime>,
|
|
|
|
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
|
|
|
|
);
|
2022-09-29 18:33:09 +00:00
|
|
|
pub type UncheckedExtrinsic =
|
|
|
|
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
|
|
|
|
pub type SignedPayload = generic::SignedPayload<RuntimeCall, SignedExtra>;
|
2022-07-15 04:05:00 +00:00
|
|
|
pub type Executive = frame_executive::Executive<
|
|
|
|
Runtime,
|
|
|
|
Block,
|
|
|
|
frame_system::ChainContext<Runtime>,
|
|
|
|
Runtime,
|
|
|
|
AllPalletsWithSystem,
|
|
|
|
>;
|
|
|
|
|
|
|
|
construct_runtime!(
|
|
|
|
pub enum Runtime where
|
|
|
|
Block = Block,
|
|
|
|
NodeBlock = Block,
|
|
|
|
UncheckedExtrinsic = UncheckedExtrinsic
|
|
|
|
{
|
|
|
|
System: frame_system,
|
2022-07-22 16:31:29 +00:00
|
|
|
RandomnessCollectiveFlip: pallet_randomness_collective_flip,
|
2022-07-15 04:05:00 +00:00
|
|
|
Timestamp: pallet_timestamp,
|
|
|
|
Balances: pallet_balances,
|
2022-07-17 01:06:54 +00:00
|
|
|
TransactionPayment: pallet_transaction_payment,
|
2022-07-22 16:31:29 +00:00
|
|
|
Contracts: pallet_contracts,
|
2022-07-15 04:05:00 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
#[cfg(feature = "runtime-benchmarks")]
|
|
|
|
#[macro_use]
|
|
|
|
extern crate frame_benchmarking;
|
|
|
|
|
|
|
|
#[cfg(feature = "runtime-benchmarks")]
|
|
|
|
mod benches {
|
|
|
|
define_benchmarks!(
|
|
|
|
[frame_benchmarking, BaselineBench::<Runtime>]
|
|
|
|
[frame_system, SystemBench::<Runtime>]
|
|
|
|
[pallet_balances, Balances]
|
|
|
|
[pallet_timestamp, Timestamp]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-07-22 16:31:29 +00:00
|
|
|
sp_api::impl_runtime_apis! {
|
2022-07-15 04:05:00 +00:00
|
|
|
impl sp_api::Core<Block> for Runtime {
|
|
|
|
fn version() -> RuntimeVersion {
|
|
|
|
VERSION
|
|
|
|
}
|
|
|
|
|
|
|
|
fn execute_block(block: Block) {
|
|
|
|
Executive::execute_block(block);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn initialize_block(header: &<Block as BlockT>::Header) {
|
|
|
|
Executive::initialize_block(header)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl sp_api::Metadata<Block> for Runtime {
|
|
|
|
fn metadata() -> OpaqueMetadata {
|
|
|
|
OpaqueMetadata::new(Runtime::metadata().into())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl sp_block_builder::BlockBuilder<Block> for Runtime {
|
|
|
|
fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
|
|
|
|
Executive::apply_extrinsic(extrinsic)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn finalize_block() -> <Block as BlockT>::Header {
|
|
|
|
Executive::finalize_block()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
|
|
|
|
data.create_extrinsics()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_inherents(
|
|
|
|
block: Block,
|
|
|
|
data: sp_inherents::InherentData,
|
|
|
|
) -> sp_inherents::CheckInherentsResult {
|
|
|
|
data.check_extrinsics(&block)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
|
|
|
|
fn validate_transaction(
|
|
|
|
source: TransactionSource,
|
|
|
|
tx: <Block as BlockT>::Extrinsic,
|
|
|
|
block_hash: <Block as BlockT>::Hash,
|
|
|
|
) -> TransactionValidity {
|
|
|
|
Executive::validate_transaction(source, tx, block_hash)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
|
|
|
|
fn offchain_worker(header: &<Block as BlockT>::Header) {
|
|
|
|
Executive::offchain_worker(header)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<
|
|
|
|
Block,
|
|
|
|
Balance
|
|
|
|
> for Runtime {
|
|
|
|
fn query_info(
|
|
|
|
uxt: <Block as BlockT>::Extrinsic,
|
|
|
|
len: u32,
|
|
|
|
) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo<Balance> {
|
|
|
|
TransactionPayment::query_info(uxt, len)
|
|
|
|
}
|
|
|
|
fn query_fee_details(
|
|
|
|
uxt: <Block as BlockT>::Extrinsic,
|
|
|
|
len: u32,
|
|
|
|
) -> pallet_transaction_payment::FeeDetails<Balance> {
|
|
|
|
TransactionPayment::query_fee_details(uxt, len)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|