Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(gtest): Update gtest weights to match onchain weights #4088

Merged
merged 3 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions gtest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,13 +487,13 @@ pub mod constants {
/// Extra amount of blocks must be reserved for storing in storage.
pub const RESERVE_FOR: Block = 1;
/// Cost of read access into storage.
pub const READ_COST: Gas = 25;
pub const READ_COST: Gas = 25000000;
/// Per-byte extra cost of read access into storage.
pub const READ_PER_BYTE_COST: Gas = 10;
pub const READ_PER_BYTE_COST: Gas = 584;
/// Cost of write access into storage.
pub const WRITE_COST: Gas = 100;
pub const WRITE_COST: Gas = 100000000;
/// Per-byte extra cost of write access into storage.
pub const WRITE_PER_BYTE_COST: Gas = 10;
pub const WRITE_PER_BYTE_COST: Gas = 97656;

/* Rent-related constants */

Expand All @@ -519,7 +519,7 @@ pub mod constants {
pub const MODULE_DATA_SECTION_INSTANTIATION_BYTE_COST: Gas = 452;
/// Cost of wasm module global section instantiation before execution per
/// byte of code.
pub const MODULE_GLOBAL_SECTION_INSTANTIATION_BYTE_COST: Gas = 2360;
pub const MODULE_GLOBAL_SECTION_INSTANTIATION_BYTE_COST: Gas = 2359;
/// Cost of wasm module table section instantiation before execution per
/// byte of code.
pub const MODULE_TABLE_SECTION_INSTANTIATION_BYTE_COST: Gas = 350;
Expand All @@ -535,4 +535,27 @@ pub mod constants {
pub const MODULE_INSTRUMENTATION_BYTE_COST: Gas = 13;
/// Initial random seed for testing environment.
pub const INITIAL_RANDOM_SEED: u64 = 42;

/* Memory-related constants */
/// Memory grow cost.
pub const MEM_GROW_COST: usize = 810343;
/// Memory grow per page cost.
pub const MEM_GROW_PER_PAGE_COST: usize = 0;
/* Lazy pages related constants */

/// First read page access cost.
pub const SIGNAL_READ_COST: Gas = 28385632;
/// First write page access cost.
pub const SIGNAL_WRITE_COST: Gas = 137635397;
/// First read page access cost for page, which has been already read
/// accessed.
pub const SIGNAL_WRITE_AFTER_READ_COST: Gas = 112552575;
/// First read page access cost from host function call.
pub const HOST_FUNC_READ_COST: Gas = 31201248;
/// First write page access cost from host function call.
pub const HOST_FUNC_WRITE_COST: Gas = 141387608;
/// First write page access cost from host function call.
pub const HOST_FUNC_WRITE_AFTER_READ_COST: Gas = 115129057;
/// Loading page data from storage cost.
pub const LOAD_PAGE_STORAGE_DATA_COST: Gas = 10630903;
}
18 changes: 14 additions & 4 deletions gtest/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ use crate::{
mailbox::MailboxManager,
program::{Gas, WasmProgram},
Result, TestError, DISPATCH_HOLD_COST, EPOCH_DURATION_IN_BLOCKS, EXISTENTIAL_DEPOSIT,
GAS_ALLOWANCE, INITIAL_RANDOM_SEED, LOAD_ALLOCATIONS_PER_INTERVAL, MAILBOX_THRESHOLD,
MAX_RESERVATIONS, MODULE_CODE_SECTION_INSTANTIATION_BYTE_COST,
GAS_ALLOWANCE, HOST_FUNC_READ_COST, HOST_FUNC_WRITE_AFTER_READ_COST, HOST_FUNC_WRITE_COST,
INITIAL_RANDOM_SEED, LOAD_ALLOCATIONS_PER_INTERVAL, LOAD_PAGE_STORAGE_DATA_COST,
MAILBOX_THRESHOLD, MAX_RESERVATIONS, MODULE_CODE_SECTION_INSTANTIATION_BYTE_COST,
MODULE_DATA_SECTION_INSTANTIATION_BYTE_COST, MODULE_ELEMENT_SECTION_INSTANTIATION_BYTE_COST,
MODULE_GLOBAL_SECTION_INSTANTIATION_BYTE_COST, MODULE_INSTRUMENTATION_BYTE_COST,
MODULE_INSTRUMENTATION_COST, MODULE_TABLE_SECTION_INSTANTIATION_BYTE_COST,
MODULE_TYPE_SECTION_INSTANTIATION_BYTE_COST, READ_COST, READ_PER_BYTE_COST, RESERVATION_COST,
RESERVE_FOR, VALUE_PER_GAS, WAITLIST_COST, WRITE_COST,
RESERVE_FOR, SIGNAL_READ_COST, SIGNAL_WRITE_AFTER_READ_COST, SIGNAL_WRITE_COST, VALUE_PER_GAS,
WAITLIST_COST, WRITE_COST,
};
use core_processor::{
common::*,
Expand Down Expand Up @@ -870,7 +872,15 @@ impl ExtManager {
mem_grow: Default::default(),
mem_grow_per_page: Default::default(),
},
lazy_pages: LazyPagesCosts::default(),
lazy_pages: LazyPagesCosts {
host_func_read: HOST_FUNC_READ_COST.into(),
host_func_write: HOST_FUNC_WRITE_COST.into(),
host_func_write_after_read: HOST_FUNC_WRITE_AFTER_READ_COST.into(),
load_page_storage_data: LOAD_PAGE_STORAGE_DATA_COST.into(),
signal_read: SIGNAL_READ_COST.into(),
signal_write: SIGNAL_WRITE_COST.into(),
signal_write_after_read: SIGNAL_WRITE_AFTER_READ_COST.into(),
},
read: READ_COST.into(),
read_per_byte: READ_PER_BYTE_COST.into(),
write: WRITE_COST.into(),
Expand Down
Loading