Skip to content

Commit

Permalink
Progress 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinonard committed Jul 14, 2023
1 parent 9a455d8 commit e58599f
Show file tree
Hide file tree
Showing 5 changed files with 509 additions and 83 deletions.
24 changes: 24 additions & 0 deletions pallets/pallet-xcm/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,18 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add(Weight::from_parts(0, 3102))
.saturating_add(T::DbWeight::get().reads(2_u64))
}
/// C/P from PolkadotXcm, should be measured independently.
/// Storage: XcmPallet XcmExecutionSuspended (r:0 w:1)
/// Proof Skipped: XcmPallet XcmExecutionSuspended (max_values: Some(1), max_size: None, mode: Measured)
fn force_suspension() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 2_849_000 picoseconds.
Weight::from_parts(3_018_000, 0)
.saturating_add(Weight::from_parts(0, 0))
.saturating_add(T::DbWeight::get().writes(1))
}
}

// For backwards compatibility and tests
Expand Down Expand Up @@ -438,4 +450,16 @@ impl WeightInfo for () {
.saturating_add(Weight::from_parts(0, 3102))
.saturating_add(RocksDbWeight::get().reads(2_u64))
}
/// C/P from PolkadotXcm, should be measured independently.
/// Storage: XcmPallet XcmExecutionSuspended (r:0 w:1)
/// Proof Skipped: XcmPallet XcmExecutionSuspended (max_values: Some(1), max_size: None, mode: Measured)
fn force_suspension() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 2_849_000 picoseconds.
Weight::from_parts(3_018_000, 0)
.saturating_add(Weight::from_parts(0, 0))
.saturating_add(RocksDbWeight::get().writes(1))
}
}
141 changes: 122 additions & 19 deletions runtime/astar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use frame_system::{
EnsureRoot, EnsureSigned,
};
use pallet_ethereum::PostLogContent;
use pallet_evm::{FeeCalculator, Runner};
use pallet_evm::{FeeCalculator, GasWeightMapping, Runner};
use pallet_transaction_payment::{
FeeDetails, Multiplier, RuntimeDispatchInfo, TargetedFeeAdjustment,
};
Expand Down Expand Up @@ -607,9 +607,8 @@ impl pallet_vesting::Config for Runtime {
parameter_types! {
pub const DepositPerItem: Balance = contracts_deposit(1, 0);
pub const DepositPerByte: Balance = contracts_deposit(0, 1);
// The lazy deletion runs inside on_initialize.
pub DeletionWeightLimit: Weight = AVERAGE_ON_INITIALIZE_RATIO *
RuntimeBlockWeights::get().max_block;
// Fallback value if storage deposit limit not set by the user
pub const DefaultDepositLimit: Balance = contracts_deposit(1024, 1024 * 1024);
pub Schedule: pallet_contracts::Schedule<Runtime> = Default::default();
}

Expand Down Expand Up @@ -639,12 +638,11 @@ impl pallet_contracts::Config for Runtime {
type CallFilter = Nothing;
type DepositPerItem = DepositPerItem;
type DepositPerByte = DepositPerByte;
type DefaultDepositLimit = DefaultDepositLimit;
type CallStack = [pallet_contracts::Frame<Self>; 5];
type WeightPrice = pallet_transaction_payment::Pallet<Self>;
type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;
type ChainExtension = ();
type DeletionQueueDepth = ConstU32<128>;
type DeletionWeightLimit = DeletionWeightLimit;
type Schedule = Schedule;
type AddressGenerator = pallet_contracts::DefaultAddressGenerator;
type MaxCodeLen = ConstU32<{ 123 * 1024 }>;
Expand Down Expand Up @@ -786,6 +784,13 @@ parameter_types! {
);
pub PrecompilesValue: Precompiles = AstarNetworkPrecompiles::<_, _>::new();
pub WeightPerGas: Weight = Weight::from_parts(WEIGHT_PER_GAS, 0);
/// The amount of gas per PoV size. Value is calculated as:
///
/// max_gas_limit = max_tx_ref_time / WEIGHT_PER_GAS = max_pov_size * gas_limit_pov_size_ratio
/// gas_limit_pov_size_ratio = ceil((max_tx_ref_time / WEIGHT_PER_GAS) / max_pov_size)
///
/// Equals 4 for values used by Astar runtime.
pub const GasLimitPovSizeRatio: u64 = 4;
}

impl pallet_evm::Config for Runtime {
Expand All @@ -807,6 +812,7 @@ impl pallet_evm::Config for Runtime {
type Timestamp = Timestamp;
type OnCreate = ();
type FindAuthor = FindAuthorTruncated<Aura>;
type GasLimitPovSizeRatio = GasLimitPovSizeRatio;
type WeightInfo = pallet_evm::weights::SubstrateWeight<Runtime>;
}

Expand All @@ -825,6 +831,7 @@ impl pallet_ethereum::Config for Runtime {
impl pallet_sudo::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type WeightInfo = pallet_sudo::weights::SubstrateWeight<Runtime>;
}

pub struct EvmRevertCodeHandler;
Expand Down Expand Up @@ -1082,6 +1089,11 @@ parameter_types! {
pub type Migrations =
(frame_support::migrations::RemovePallet<StateTrieMigrationStr, RocksDbWeight>,);

type EventRecord = frame_system::EventRecord<
<Runtime as frame_system::Config>::RuntimeEvent,
<Runtime as frame_system::Config>::Hash,
>;

use frame_support::pallet_prelude::*;
pub struct PalletContractsV9<T: pallet_contracts::Config>(PhantomData<T>);
impl<T: pallet_contracts::Config> frame_support::traits::OnRuntimeUpgrade for PalletContractsV9<T> {
Expand Down Expand Up @@ -1361,7 +1373,7 @@ impl_runtime_apis! {
max_priority_fee_per_gas: Option<U256>,
nonce: Option<U256>,
estimate: bool,
_access_list: Option<Vec<(H160, Vec<H256>)>>,
access_list: Option<Vec<(H160, Vec<H256>)>>,
) -> Result<pallet_evm::CallInfo, sp_runtime::DispatchError> {
let config = if estimate {
let mut config = <Runtime as pallet_evm::Config>::config().clone();
Expand All @@ -1373,6 +1385,42 @@ impl_runtime_apis! {

let is_transactional = false;
let validate = true;

// Reused approach from Moonbeam since Frontier implementation doesn't support this
let mut estimated_transaction_len = data.len() +
// to: 20
// from: 20
// value: 32
// gas_limit: 32
// nonce: 32
// 1 byte transaction action variant
// chain id 8 bytes
// 65 bytes signature
210;
if max_fee_per_gas.is_some() {
estimated_transaction_len += 32;
}
if max_priority_fee_per_gas.is_some() {
estimated_transaction_len += 32;
}
if access_list.is_some() {
estimated_transaction_len += access_list.encoded_size();
}

let gas_limit = gas_limit.min(u64::MAX.into()).low_u64();
let without_base_extrinsic_weight = true;

let (weight_limit, proof_size_base_cost) =
match <Runtime as pallet_evm::Config>::GasWeightMapping::gas_to_weight(
gas_limit,
without_base_extrinsic_weight
) {
weight_limit if weight_limit.proof_size() > 0 => {
(Some(weight_limit), Some(estimated_transaction_len as u64))
}
_ => (None, None),
};

<Runtime as pallet_evm::Config>::Runner::call(
from,
to,
Expand All @@ -1385,6 +1433,8 @@ impl_runtime_apis! {
Vec::new(),
is_transactional,
validate,
weight_limit,
proof_size_base_cost,
config
.as_ref()
.unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),
Expand All @@ -1401,7 +1451,7 @@ impl_runtime_apis! {
max_priority_fee_per_gas: Option<U256>,
nonce: Option<U256>,
estimate: bool,
_access_list: Option<Vec<(H160, Vec<H256>)>>,
access_list: Option<Vec<(H160, Vec<H256>)>>,
) -> Result<pallet_evm::CreateInfo, sp_runtime::DispatchError> {
let config = if estimate {
let mut config = <Runtime as pallet_evm::Config>::config().clone();
Expand All @@ -1413,6 +1463,42 @@ impl_runtime_apis! {

let is_transactional = false;
let validate = true;

// Reused approach from Moonbeam since Frontier implementation doesn't support this
let mut estimated_transaction_len = data.len() +
// to: 20
// from: 20
// value: 32
// gas_limit: 32
// nonce: 32
// 1 byte transaction action variant
// chain id 8 bytes
// 65 bytes signature
210;
if max_fee_per_gas.is_some() {
estimated_transaction_len += 32;
}
if max_priority_fee_per_gas.is_some() {
estimated_transaction_len += 32;
}
if access_list.is_some() {
estimated_transaction_len += access_list.encoded_size();
}

let gas_limit = gas_limit.min(u64::MAX.into()).low_u64();
let without_base_extrinsic_weight = true;

let (weight_limit, proof_size_base_cost) =
match <Runtime as pallet_evm::Config>::GasWeightMapping::gas_to_weight(
gas_limit,
without_base_extrinsic_weight
) {
weight_limit if weight_limit.proof_size() > 0 => {
(Some(weight_limit), Some(estimated_transaction_len as u64))
}
_ => (None, None),
};

#[allow(clippy::or_fun_call)] // suggestion not helpful here
<Runtime as pallet_evm::Config>::Runner::create(
from,
Expand All @@ -1425,6 +1511,8 @@ impl_runtime_apis! {
Vec::new(),
is_transactional,
validate,
weight_limit,
proof_size_base_cost,
config
.as_ref()
.unwrap_or(<Runtime as pallet_evm::Config>::config()),
Expand Down Expand Up @@ -1473,7 +1561,7 @@ impl_runtime_apis! {

fn pending_block(
xts: Vec<<Block as BlockT>::Extrinsic>,
) -> (Option<pallet_ethereum::Block>, Option<Vec<TransactionStatus>>) {
) -> (Option<pallet_ethereum::Block>, Option<Vec<fp_rpc::TransactionStatus>>) {
for ext in xts.into_iter() {
let _ = Executive::apply_extrinsic(ext);
}
Expand All @@ -1497,21 +1585,27 @@ impl_runtime_apis! {
}
}

impl pallet_contracts::ContractsApi<
Block, AccountId, Balance, BlockNumber, Hash,
>
for Runtime
{
impl pallet_contracts::ContractsApi<Block, AccountId, Balance, BlockNumber, Hash, EventRecord> for Runtime {
fn call(
origin: AccountId,
dest: AccountId,
value: Balance,
gas_limit: Option<Weight>,
storage_deposit_limit: Option<Balance>,
input_data: Vec<u8>,
) -> pallet_contracts_primitives::ContractExecResult<Balance> {
) -> pallet_contracts_primitives::ContractExecResult<Balance, EventRecord> {
let gas_limit = gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block);
Contracts::bare_call(origin, dest, value, gas_limit, storage_deposit_limit, input_data, true, pallet_contracts::Determinism::Enforced)
Contracts::bare_call(
origin,
dest,
value,
gas_limit,
storage_deposit_limit,
input_data,
pallet_contracts::DebugInfo::UnsafeDebug,
pallet_contracts::CollectEvents::UnsafeCollect,
pallet_contracts::Determinism::Enforced,
)
}

fn instantiate(
Expand All @@ -1522,10 +1616,19 @@ impl_runtime_apis! {
code: pallet_contracts_primitives::Code<Hash>,
data: Vec<u8>,
salt: Vec<u8>,
) -> pallet_contracts_primitives::ContractInstantiateResult<AccountId, Balance>
{
) -> pallet_contracts_primitives::ContractInstantiateResult<AccountId, Balance, EventRecord> {
let gas_limit = gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block);
Contracts::bare_instantiate(origin, value, gas_limit, storage_deposit_limit, code, data, salt, true)
Contracts::bare_instantiate(
origin,
value,
gas_limit,
storage_deposit_limit,
code,
data,
salt,
pallet_contracts::DebugInfo::UnsafeDebug,
pallet_contracts::CollectEvents::UnsafeCollect,
)
}

fn upload_code(
Expand Down
Loading

0 comments on commit e58599f

Please sign in to comment.