use alloc::{collections::BTreeSet, vec::Vec};
use gear_backend_common::lazy_pages::LazyPagesWeights;
use gear_core::{
costs::{CostPerPage, HostFnWeights},
pages::{GearPage, WasmPage},
};
use gear_wasm_instrument::syscalls::SysCallName;
use scale_info::scale::{self, Decode, Encode};
pub const TESTS_MAX_PAGES_NUMBER: u16 = 512;
#[derive(Clone, Copy, Debug, Encode, Decode, Default)]
#[codec(crate = scale)]
pub struct BlockInfo {
pub height: u32,
pub timestamp: u64,
}
#[derive(Clone, Debug, Decode, Encode, Default)]
#[codec(crate = scale)]
pub struct PageCosts {
pub lazy_pages_signal_read: CostPerPage<GearPage>,
pub lazy_pages_signal_write: CostPerPage<GearPage>,
pub lazy_pages_signal_write_after_read: CostPerPage<GearPage>,
pub lazy_pages_host_func_read: CostPerPage<GearPage>,
pub lazy_pages_host_func_write: CostPerPage<GearPage>,
pub lazy_pages_host_func_write_after_read: CostPerPage<GearPage>,
pub load_page_data: CostPerPage<GearPage>,
pub upload_page_data: CostPerPage<GearPage>,
pub static_page: CostPerPage<WasmPage>,
pub mem_grow: CostPerPage<WasmPage>,
pub parachain_load_heuristic: CostPerPage<GearPage>,
}
impl PageCosts {
pub fn lazy_pages_weights(&self) -> LazyPagesWeights {
LazyPagesWeights {
signal_read: self.lazy_pages_signal_read,
signal_write: self
.lazy_pages_signal_write
.saturating_add(self.upload_page_data),
signal_write_after_read: self
.lazy_pages_signal_write_after_read
.saturating_add(self.upload_page_data),
host_func_read: self.lazy_pages_host_func_read,
host_func_write: self
.lazy_pages_host_func_write
.saturating_add(self.upload_page_data),
host_func_write_after_read: self
.lazy_pages_host_func_write_after_read
.saturating_add(self.upload_page_data),
load_page_storage_data: self
.load_page_data
.saturating_add(self.parachain_load_heuristic),
}
}
pub fn new_for_tests() -> Self {
let a = 1000.into();
let b = 4000.into();
Self {
lazy_pages_signal_read: a,
lazy_pages_signal_write: a,
lazy_pages_signal_write_after_read: a,
lazy_pages_host_func_read: a,
lazy_pages_host_func_write: a,
lazy_pages_host_func_write_after_read: a,
load_page_data: a,
upload_page_data: a,
static_page: b,
mem_grow: b,
parachain_load_heuristic: a,
}
}
}
pub struct ExecutionSettings {
pub block_info: BlockInfo,
pub max_pages: WasmPage,
pub page_costs: PageCosts,
pub existential_deposit: u128,
pub host_fn_weights: HostFnWeights,
pub forbidden_funcs: BTreeSet<SysCallName>,
pub mailbox_threshold: u64,
pub waitlist_cost: u64,
pub dispatch_hold_cost: u64,
pub reserve_for: u32,
pub reservation: u64,
pub random_data: (Vec<u8>, u32),
pub rent_cost: u128,
}
#[derive(Clone)]
pub struct BlockConfig {
pub block_info: BlockInfo,
pub max_pages: WasmPage,
pub page_costs: PageCosts,
pub existential_deposit: u128,
pub outgoing_limit: u32,
pub host_fn_weights: HostFnWeights,
pub forbidden_funcs: BTreeSet<SysCallName>,
pub mailbox_threshold: u64,
pub waitlist_cost: u64,
pub dispatch_hold_cost: u64,
pub reserve_for: u32,
pub reservation: u64,
pub read_cost: u64,
pub write_cost: u64,
pub write_per_byte_cost: u64,
pub read_per_byte_cost: u64,
pub module_instantiation_byte_cost: u64,
pub max_reservations: u64,
pub code_instrumentation_cost: u64,
pub code_instrumentation_byte_cost: u64,
pub rent_cost: u128,
}