Merge branch 'develop' into tendermint

This commit is contained in:
Luke Parker
2022-10-20 01:34:59 -04:00
80 changed files with 2727 additions and 1241 deletions

View File

@@ -3,10 +3,15 @@ name = "serai-consensus"
version = "0.1.0"
description = "Serai consensus module"
license = "AGPL-3.0-only"
repository = "https://github.com/serai-dex/serai/tree/develop/substrate/consensus"
authors = ["Luke Parker <lukeparker5132@gmail.com>"]
edition = "2021"
publish = false
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[dependencies]
sp-core = { git = "https://github.com/serai-dex/substrate" }
sp-trie = { git = "https://github.com/serai-dex/substrate" }

View File

@@ -3,6 +3,7 @@ name = "serai-node"
version = "0.1.0"
description = "Serai network node, built over Substrate"
license = "AGPL-3.0-only"
repository = "https://github.com/serai-dex/serai/tree/develop/substrate/node"
authors = ["Luke Parker <lukeparker5132@gmail.com>"]
edition = "2021"
publish = false
@@ -11,7 +12,7 @@ publish = false
name = "serai-node"
[dependencies]
clap = { version = "3.1.18", features = ["derive"] }
clap = { version = "4", features = ["derive"] }
sc-cli = { git = "https://github.com/serai-dex/substrate", features = ["wasmtime"] }
sp-core = { git = "https://github.com/serai-dex/substrate" }
@@ -31,7 +32,7 @@ frame-system = { git = "https://github.com/serai-dex/substrate" }
pallet-transaction-payment = { git = "https://github.com/serai-dex/substrate", default-features = false }
# These dependencies are used for the node template's RPCs
jsonrpsee = { version = "0.15.1", features = ["server"] }
jsonrpsee = { version = "0.15", features = ["server"] }
sc-rpc = { git = "https://github.com/serai-dex/substrate" }
sp-api = { git = "https://github.com/serai-dex/substrate" }
sc-rpc-api = { git = "https://github.com/serai-dex/substrate" }
@@ -39,7 +40,6 @@ sp-blockchain = { git = "https://github.com/serai-dex/substrate" }
sp-block-builder = { git = "https://github.com/serai-dex/substrate" }
substrate-frame-rpc-system = { git = "https://github.com/serai-dex/substrate" }
pallet-transaction-payment-rpc = { git = "https://github.com/serai-dex/substrate" }
pallet-contracts-rpc = { git = "https://github.com/serai-dex/substrate", package = "pallet-contracts-rpc" }
# These dependencies are used for runtime benchmarking
frame-benchmarking = { git = "https://github.com/serai-dex/substrate" }

View File

@@ -9,7 +9,7 @@ use sp_api::ProvideRuntimeApi;
pub use sc_rpc_api::DenyUnsafe;
use serai_runtime::{BlockNumber, Hash, opaque::Block, AccountId, Balance, Index};
use serai_runtime::{opaque::Block, AccountId, Balance, Index};
pub struct FullDeps<C, P> {
pub client: Arc<C>,
@@ -31,19 +31,16 @@ pub fn create_full<
where
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>
+ pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>
+ pallet_contracts_rpc::ContractsRuntimeApi<Block, AccountId, Balance, BlockNumber, Hash>
+ BlockBuilder<Block>,
{
use substrate_frame_rpc_system::{System, SystemApiServer};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use pallet_contracts_rpc::{Contracts, ContractsApiServer};
let mut module = RpcModule::new(());
let FullDeps { client, pool, deny_unsafe } = deps;
module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
module.merge(TransactionPayment::new(client.clone()).into_rpc())?;
module.merge(Contracts::new(client).into_rpc())?;
Ok(module)
}

View File

@@ -3,15 +3,19 @@ name = "serai-runtime"
version = "0.1.0"
description = "Serai network node runtime, built over Substrate"
license = "AGPL-3.0-only"
repository = "https://github.com/serai-dex/serai/tree/develop/substrate/runtime"
authors = ["Luke Parker <lukeparker5132@gmail.com>"]
edition = "2021"
publish = false
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[dependencies]
hex-literal = { version = "0.3.4", optional = true }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"] }
sp-core = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-std = { git = "https://github.com/serai-dex/substrate", default-features = false }
@@ -35,7 +39,6 @@ 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-contracts-rpc-runtime-api = { git = "https://github.com/serai-dex/substrate", default-features = false }
# Used for the node template's RPCs
frame-system-rpc-runtime-api = { git = "https://github.com/serai-dex/substrate", default-features = false }
@@ -77,7 +80,6 @@ std = [
"pallet-contracts/std",
"pallet-contracts-primitives/std",
"pallet-contracts-rpc-runtime-api/std",
]
runtime-benchmarks = [

View File

@@ -19,7 +19,7 @@ use sp_version::RuntimeVersion;
use frame_support::{
traits::{ConstU8, ConstU32, ConstU64},
weights::{
constants::{RocksDbWeight, ExtrinsicBaseWeight, BlockExecutionWeight, WEIGHT_PER_SECOND},
constants::{RocksDbWeight, WEIGHT_PER_SECOND},
IdentityFee, Weight,
},
dispatch::DispatchClass,
@@ -30,7 +30,6 @@ pub use frame_system::Call as SystemCall;
pub use pallet_timestamp::Call as TimestampCall;
pub use pallet_balances::Call as BalancesCall;
use pallet_transaction_payment::CurrencyAdapter;
use pallet_contracts::DefaultContractAccessWeight;
/// An index to a block.
pub type BlockNumber = u32;
@@ -92,17 +91,6 @@ pub fn native_version() -> NativeVersion {
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
/// We assume that ~10% of the block weight is consumed by `on_initialize` handlers.
/// This is used to limit the maximal weight of a single extrinsic.
const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
/// We allow for 2 seconds of compute with a 6 second average block time.
const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_ref_time(2 * WEIGHT_PER_SECOND.ref_time());
// Prints debug output of the `contracts` pallet to stdout if the node is
// started with `-lruntime::contracts=debug`.
const CONTRACTS_DEBUG_OUTPUT: bool = true;
// Unit = the base number of indivisible units for balances
const UNIT: Balance = 1_000_000_000_000;
const MILLIUNIT: Balance = 1_000_000_000;
@@ -121,24 +109,10 @@ parameter_types! {
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 =
frame_system::limits::BlockWeights::builder()
.base_block(BlockExecutionWeight::get())
.for_class(DispatchClass::all(), |weights| {
weights.base_extrinsic = ExtrinsicBaseWeight::get();
})
.for_class(DispatchClass::Normal, |weights| {
weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
})
.for_class(DispatchClass::Operational, |weights| {
weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
// Operational transactions have some extra reserved space, so that they
// are included even if block reached `MAXIMUM_BLOCK_WEIGHT`.
weights.reserved = Some(
MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT
);
})
.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
.build_or_panic();
frame_system::limits::BlockWeights::with_sensible_defaults(
(2u64 * WEIGHT_PER_SECOND).set_proof_size(u64::MAX),
NORMAL_DISPATCH_RATIO,
);
pub const DepositPerItem: Balance = deposit(1, 0);
pub const DepositPerByte: Balance = deposit(0, 1);
@@ -236,7 +210,6 @@ impl pallet_contracts::Config for Runtime {
type DeletionWeightLimit = DeletionWeightLimit;
type Schedule = Schedule;
type AddressGenerator = pallet_contracts::DefaultAddressGenerator;
type ContractAccessWeight = DefaultContractAccessWeight<BlockWeights>;
type MaxCodeLen = ConstU32<{ 128 * 1024 }>;
type MaxStorageKeyLen = ConstU32<128>;
@@ -388,63 +361,4 @@ sp_api::impl_runtime_apis! {
TransactionPayment::query_fee_details(uxt, len)
}
}
impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber, Hash>
for Runtime
{
fn call(
origin: AccountId,
dest: AccountId,
value: Balance,
gas_limit: u64,
storage_deposit_limit: Option<Balance>,
input_data: Vec<u8>,
) -> pallet_contracts_primitives::ContractExecResult<Balance> {
Contracts::bare_call(
origin,
dest,
value,
Weight::from_ref_time(gas_limit),
storage_deposit_limit,
input_data,
CONTRACTS_DEBUG_OUTPUT
)
}
fn instantiate(
origin: AccountId,
value: Balance,
gas_limit: u64,
storage_deposit_limit: Option<Balance>,
code: pallet_contracts_primitives::Code<Hash>,
data: Vec<u8>,
salt: Vec<u8>,
) -> pallet_contracts_primitives::ContractInstantiateResult<AccountId, Balance> {
Contracts::bare_instantiate(
origin,
value,
Weight::from_ref_time(gas_limit),
storage_deposit_limit,
code,
data,
salt,
CONTRACTS_DEBUG_OUTPUT
)
}
fn upload_code(
origin: AccountId,
code: Vec<u8>,
storage_deposit_limit: Option<Balance>,
) -> pallet_contracts_primitives::CodeUploadResult<Hash, Balance> {
Contracts::bare_upload_code(origin, code, storage_deposit_limit)
}
fn get_storage(
address: AccountId,
key: Vec<u8>,
) -> pallet_contracts_primitives::GetStorageResult {
Contracts::get_storage(address, key)
}
}
}