diff --git a/execution_engine/src/engine_state/engine_config.rs b/execution_engine/src/engine_state/engine_config.rs index 942dbc4cd0..98da996116 100644 --- a/execution_engine/src/engine_state/engine_config.rs +++ b/execution_engine/src/engine_state/engine_config.rs @@ -7,8 +7,8 @@ use num_rational::Ratio; use num_traits::One; use casper_types::{ - account::AccountHash, FeeHandling, ProtocolVersion, PublicKey, RefundHandling, SystemConfig, - TimeDiff, WasmConfig, DEFAULT_FEE_HANDLING, DEFAULT_MINIMUM_BID_AMOUNT, + account::AccountHash, FeeHandling, ProtocolVersion, PublicKey, RefundHandling, StorageCosts, + SystemConfig, TimeDiff, WasmConfig, DEFAULT_FEE_HANDLING, DEFAULT_MINIMUM_BID_AMOUNT, DEFAULT_REFUND_HANDLING, }; @@ -86,6 +86,7 @@ pub struct EngineConfig { pub(crate) fee_handling: FeeHandling, /// Compute auction rewards. pub(crate) compute_rewards: bool, + storage_costs: StorageCosts, } impl Default for EngineConfig { @@ -108,6 +109,7 @@ impl Default for EngineConfig { fee_handling: DEFAULT_FEE_HANDLING, compute_rewards: DEFAULT_COMPUTE_REWARDS, protocol_version: DEFAULT_PROTOCOL_VERSION, + storage_costs: Default::default(), } } } @@ -198,6 +200,11 @@ impl EngineConfig { self.fee_handling } + /// Returns the engine config's storage_costs. + pub fn storage_costs(&self) -> &StorageCosts { + &self.storage_costs + } + /// Returns the engine config's compute rewards flag. pub fn compute_rewards(&self) -> bool { self.compute_rewards @@ -215,7 +222,7 @@ impl EngineConfig { /// Sets the `wasm_config.max_memory` to `new_value`. #[cfg(feature = "test-support")] pub fn set_max_memory(&mut self, new_value: u32) { - self.wasm_config.max_memory = new_value; + *self.wasm_config.v1_mut().max_memory_mut() = new_value; } } @@ -244,6 +251,7 @@ pub struct EngineConfigBuilder { fee_handling: Option, compute_rewards: Option, balance_hold_interval: Option, + storage_costs: Option, } impl EngineConfigBuilder { @@ -312,7 +320,7 @@ impl EngineConfigBuilder { /// Sets the maximum wasm stack height config option. pub fn with_wasm_max_stack_height(mut self, wasm_stack_height: u32) -> Self { let wasm_config = self.wasm_config.get_or_insert_with(WasmConfig::default); - wasm_config.max_stack_height = wasm_stack_height; + *wasm_config.v1_mut().max_stack_height_mut() = wasm_stack_height; self } @@ -391,6 +399,12 @@ impl EngineConfigBuilder { self } + /// Sets the storage_costs config option. + pub fn with_storage_costs(mut self, storage_costs: StorageCosts) -> Self { + self.storage_costs = Some(storage_costs); + self + } + /// Builds a new [`EngineConfig`] object. pub fn build(self) -> EngineConfig { let max_associated_keys = self @@ -437,6 +451,7 @@ impl EngineConfigBuilder { .max_delegators_per_validator .unwrap_or(DEFAULT_MAX_DELEGATORS_PER_VALIDATOR); let compute_rewards = self.compute_rewards.unwrap_or(DEFAULT_COMPUTE_REWARDS); + let storage_costs = self.storage_costs.unwrap_or_default(); EngineConfig { max_associated_keys, @@ -456,6 +471,7 @@ impl EngineConfigBuilder { vesting_schedule_period_millis, max_delegators_per_validator, compute_rewards, + storage_costs, } } } diff --git a/execution_engine/src/resolvers/mod.rs b/execution_engine/src/resolvers/mod.rs index 9dc81c0c29..9a14b51638 100644 --- a/execution_engine/src/resolvers/mod.rs +++ b/execution_engine/src/resolvers/mod.rs @@ -22,7 +22,7 @@ pub(crate) fn create_module_resolver( // TODO: revisit how protocol_version check here is meant to combine with upgrade if protocol_version >= ProtocolVersion::V1_0_0 { return Ok(v1_resolver::RuntimeModuleImportResolver::new( - engine_config.wasm_config().max_memory, + engine_config.wasm_config().v1().max_memory(), )); } Err(ResolverError::UnknownProtocolVersion(protocol_version)) diff --git a/execution_engine/src/runtime/externals.rs b/execution_engine/src/runtime/externals.rs index 8cf5cf04e4..e5b80f6793 100644 --- a/execution_engine/src/runtime/externals.rs +++ b/execution_engine/src/runtime/externals.rs @@ -32,11 +32,8 @@ where ) -> Result, Trap> { let func = FunctionIndex::try_from(index).expect("unknown function index"); - let host_function_costs = self - .context - .engine_config() - .wasm_config() - .take_host_function_costs(); + let host_function_costs = + (*self.context.engine_config().wasm_config().v1()).take_host_function_costs(); match func { FunctionIndex::ReadFuncIndex => { diff --git a/execution_engine/src/runtime/mod.rs b/execution_engine/src/runtime/mod.rs index e266532983..4287183daa 100644 --- a/execution_engine/src/runtime/mod.rs +++ b/execution_engine/src/runtime/mod.rs @@ -1211,7 +1211,7 @@ where let engine_config = self.context.engine_config(); let wasm_config = engine_config.wasm_config(); #[cfg(feature = "test-support")] - let max_stack_height = wasm_config.max_stack_height; + let max_stack_height = wasm_config.v1().max_stack_height(); let module = wasm_prep::preprocess(*wasm_config, module_bytes)?; let (instance, memory) = utils::instance_and_memory(module.clone(), protocol_version, engine_config)?; @@ -1683,7 +1683,11 @@ where #[cfg(feature = "test-support")] dump_runtime_stack_info( instance, - self.context.engine_config().wasm_config().max_stack_height, + self.context + .engine_config() + .wasm_config() + .v1() + .max_stack_height(), ); if let Some(host_error) = error.as_host_error() { // If the "error" was in fact a trap caused by calling `ret` then this is normal diff --git a/execution_engine/src/runtime/wasm_prep.rs b/execution_engine/src/runtime/wasm_prep.rs index a4b11e230e..220d5643e8 100644 --- a/execution_engine/src/runtime/wasm_prep.rs +++ b/execution_engine/src/runtime/wasm_prep.rs @@ -402,11 +402,11 @@ pub(crate) fn preprocess( ensure_parameter_limit(&module, DEFAULT_MAX_PARAMETER_COUNT)?; ensure_valid_imports(&module)?; - let costs = RuledOpcodeCosts(wasm_config.opcode_costs()); - let module = casper_wasm_utils::externalize_mem(module, None, wasm_config.max_memory); + let costs = RuledOpcodeCosts(wasm_config.v1().opcode_costs()); + let module = casper_wasm_utils::externalize_mem(module, None, wasm_config.v1().max_memory()); let module = casper_wasm_utils::inject_gas_counter(module, &costs, DEFAULT_GAS_MODULE_NAME) .map_err(|_| PreprocessingError::OperationForbiddenByGasRules)?; - let module = stack_height::inject_limiter(module, wasm_config.max_stack_height) + let module = stack_height::inject_limiter(module, wasm_config.v1().max_stack_height()) .map_err(|_| PreprocessingError::StackLimiter)?; Ok(module) } diff --git a/execution_engine/src/runtime_context/mod.rs b/execution_engine/src/runtime_context/mod.rs index c10d4aa616..990940d056 100644 --- a/execution_engine/src/runtime_context/mod.rs +++ b/execution_engine/src/runtime_context/mod.rs @@ -119,8 +119,7 @@ where entry_point_type: EntryPointType, calling_add_contract_version: CallingAddContractVersion, ) -> Self { - let emit_message_cost = engine_config - .wasm_config() + let emit_message_cost = (*engine_config.wasm_config().v1()) .take_host_function_costs() .emit_message .cost() @@ -842,7 +841,7 @@ where } } - let storage_costs = self.engine_config.wasm_config().storage_costs(); + let storage_costs = self.engine_config.storage_costs(); let gas_cost = storage_costs.calculate_gas_cost(bytes_count); diff --git a/execution_engine/src/runtime_context/tests.rs b/execution_engine/src/runtime_context/tests.rs index 2693fbc89b..1fa385d4e2 100644 --- a/execution_engine/src/runtime_context/tests.rs +++ b/execution_engine/src/runtime_context/tests.rs @@ -987,7 +987,6 @@ fn should_meter_for_gas_storage_write() { let value = StoredValue::CLValue(CLValue::from_t(43_i32).unwrap()); let expected_write_cost = test_engine_config() - .wasm_config() .storage_costs() .calculate_gas_cost(value.serialized_length()); @@ -1025,7 +1024,6 @@ fn should_meter_for_gas_storage_add() { let value = StoredValue::CLValue(CLValue::from_t(43_i32).unwrap()); let expected_add_cost = test_engine_config() - .wasm_config() .storage_costs() .calculate_gas_cost(value.serialized_length()); diff --git a/execution_engine_testing/test_support/src/chainspec_config.rs b/execution_engine_testing/test_support/src/chainspec_config.rs index 66f65b80c3..0417c41dc2 100644 --- a/execution_engine_testing/test_support/src/chainspec_config.rs +++ b/execution_engine_testing/test_support/src/chainspec_config.rs @@ -13,7 +13,7 @@ use casper_storage::data_access_layer::GenesisRequest; use casper_types::{ system::auction::VESTING_SCHEDULE_LENGTH_MILLIS, CoreConfig, FeeHandling, GenesisAccount, GenesisConfig, GenesisConfigBuilder, MintCosts, PricingHandling, ProtocolVersion, - RefundHandling, SystemConfig, TimeDiff, WasmConfig, + RefundHandling, StorageCosts, SystemConfig, TimeDiff, WasmConfig, }; use crate::{ @@ -58,6 +58,8 @@ pub struct ChainspecConfig { /// SystemConfig #[serde(rename = "system_costs")] pub system_costs_config: SystemConfig, + /// Storage costs. + pub storage_costs: StorageCosts, } impl ChainspecConfig { @@ -121,6 +123,7 @@ impl ChainspecConfig { core_config, wasm_config, system_costs_config, + storage_costs, } = self; let CoreConfig { validator_slots, @@ -141,6 +144,7 @@ impl ChainspecConfig { .with_round_seigniorage_rate(*round_seigniorage_rate) .with_unbonding_delay(*unbonding_delay) .with_genesis_timestamp_millis(DEFAULT_GENESIS_TIMESTAMP_MILLIS) + .with_storage_costs(*storage_costs) .build(); Ok(GenesisRequest::new( @@ -207,7 +211,7 @@ impl ChainspecConfig { /// Sets wasm max stack height. pub fn with_wasm_max_stack_height(mut self, max_stack_height: u32) -> Self { - self.wasm_config.max_stack_height = max_stack_height; + *self.wasm_config.v1_mut().max_stack_height_mut() = max_stack_height; self } @@ -251,6 +255,7 @@ impl ChainspecConfig { .with_allow_unrestricted_transfers(self.core_config.allow_unrestricted_transfers) .with_refund_handling(self.core_config.refund_handling) .with_fee_handling(self.core_config.fee_handling) + .with_storage_costs(self.storage_costs) .build() } } @@ -296,6 +301,7 @@ impl TryFrom for GenesisConfig { .with_round_seigniorage_rate(chainspec_config.core_config.round_seigniorage_rate) .with_unbonding_delay(chainspec_config.core_config.unbonding_delay) .with_genesis_timestamp_millis(DEFAULT_GENESIS_TIMESTAMP_MILLIS) + .with_storage_costs(chainspec_config.storage_costs) .build()) } } diff --git a/execution_engine_testing/test_support/src/lib.rs b/execution_engine_testing/test_support/src/lib.rs index 901d37216b..e63e2cd9ea 100644 --- a/execution_engine_testing/test_support/src/lib.rs +++ b/execution_engine_testing/test_support/src/lib.rs @@ -25,7 +25,7 @@ use casper_storage::data_access_layer::GenesisRequest; use casper_types::{ account::AccountHash, testing::TestRng, ChainspecRegistry, Digest, GenesisAccount, GenesisConfig, GenesisConfigBuilder, Motes, ProtocolVersion, PublicKey, SecretKey, - SystemConfig, WasmConfig, U512, + StorageCosts, SystemConfig, WasmConfig, WasmV1Config, U512, }; pub use chainspec_config::{ChainspecConfig, CHAINSPEC_SYMLINK}; @@ -142,8 +142,12 @@ pub const DEFAULT_PROTOCOL_VERSION: ProtocolVersion = ProtocolVersion::V2_0_0; pub static DEFAULT_PAYMENT: Lazy = Lazy::new(|| U512::from(10_000_000_000_000u64)); /// Default [`WasmConfig`]. pub static DEFAULT_WASM_CONFIG: Lazy = Lazy::new(WasmConfig::default); +/// Default [`WasmV1Config`]. +pub static DEFAULT_WASM_V1_CONFIG: Lazy = Lazy::new(WasmV1Config::default); /// Default [`SystemConfig`]. pub static DEFAULT_SYSTEM_CONFIG: Lazy = Lazy::new(SystemConfig::default); +/// Default [`StorageConfig`]. +pub static DEFAULT_STORAGE_COSTS: Lazy = Lazy::new(StorageCosts::default); /// Default [`GenesisConfig`]. pub static DEFAULT_EXEC_CONFIG: Lazy = Lazy::new(|| { @@ -157,6 +161,7 @@ pub static DEFAULT_EXEC_CONFIG: Lazy = Lazy::new(|| { .with_round_seigniorage_rate(DEFAULT_ROUND_SEIGNIORAGE_RATE) .with_unbonding_delay(DEFAULT_UNBONDING_DELAY) .with_genesis_timestamp_millis(DEFAULT_GENESIS_TIMESTAMP_MILLIS) + .with_storage_costs(*DEFAULT_STORAGE_COSTS) .build() }); diff --git a/execution_engine_testing/test_support/src/utils.rs b/execution_engine_testing/test_support/src/utils.rs index 87b6031e43..e369cc8d0f 100644 --- a/execution_engine_testing/test_support/src/utils.rs +++ b/execution_engine_testing/test_support/src/utils.rs @@ -15,7 +15,7 @@ use super::{DEFAULT_ROUND_SEIGNIORAGE_RATE, DEFAULT_SYSTEM_CONFIG, DEFAULT_UNBON use crate::{ DEFAULT_AUCTION_DELAY, DEFAULT_CHAINSPEC_REGISTRY, DEFAULT_GENESIS_CONFIG_HASH, DEFAULT_GENESIS_TIMESTAMP_MILLIS, DEFAULT_LOCKED_FUNDS_PERIOD_MILLIS, DEFAULT_PROTOCOL_VERSION, - DEFAULT_VALIDATOR_SLOTS, DEFAULT_WASM_CONFIG, + DEFAULT_STORAGE_COSTS, DEFAULT_VALIDATOR_SLOTS, DEFAULT_WASM_CONFIG, }; static RUST_WORKSPACE_PATH: Lazy = Lazy::new(|| { @@ -133,6 +133,7 @@ pub fn create_genesis_config(accounts: Vec) -> GenesisConfig { let round_seigniorage_rate = DEFAULT_ROUND_SEIGNIORAGE_RATE; let unbonding_delay = DEFAULT_UNBONDING_DELAY; let genesis_timestamp_millis = DEFAULT_GENESIS_TIMESTAMP_MILLIS; + let storage_costs = *DEFAULT_STORAGE_COSTS; GenesisConfigBuilder::default() .with_accounts(accounts) @@ -144,6 +145,7 @@ pub fn create_genesis_config(accounts: Vec) -> GenesisConfig { .with_round_seigniorage_rate(round_seigniorage_rate) .with_unbonding_delay(unbonding_delay) .with_genesis_timestamp_millis(genesis_timestamp_millis) + .with_storage_costs(storage_costs) .build() } diff --git a/execution_engine_testing/tests/src/test/contract_messages.rs b/execution_engine_testing/tests/src/test/contract_messages.rs index a9b36f02a0..47d8d90132 100644 --- a/execution_engine_testing/tests/src/test/contract_messages.rs +++ b/execution_engine_testing/tests/src/test/contract_messages.rs @@ -10,8 +10,8 @@ use casper_types::{ contract_messages::{MessageChecksum, MessagePayload, MessageTopicSummary, TopicNameHash}, crypto, runtime_args, AddressableEntity, AddressableEntityHash, BlockGlobalAddr, BlockTime, CLValue, CoreConfig, Digest, EntityAddr, HostFunction, HostFunctionCosts, Key, MessageLimits, - OpcodeCosts, RuntimeArgs, StorageCosts, StoredValue, SystemConfig, WasmConfig, - DEFAULT_MAX_STACK_HEIGHT, DEFAULT_WASM_MAX_MEMORY, U512, + OpcodeCosts, RuntimeArgs, StorageCosts, StoredValue, SystemConfig, WasmConfig, WasmV1Config, + DEFAULT_V1_MAX_STACK_HEIGHT, DEFAULT_V1_WASM_MAX_MEMORY, U512, }; const MESSAGE_EMITTER_INSTALLER_WASM: &str = "contract_messages_emitter.wasm"; @@ -491,23 +491,26 @@ fn should_not_add_duplicate_topics() { #[ignore] #[test] fn should_not_exceed_configured_limits() { - let default_wasm_config = WasmConfig::default(); - let wasm_config = WasmConfig::new( - default_wasm_config.max_memory, - default_wasm_config.max_stack_height, + let default_wasm_config = WasmV1Config::default(); + let wasm_v1_config = WasmV1Config::new( + default_wasm_config.max_memory(), + default_wasm_config.max_stack_height(), default_wasm_config.opcode_costs(), - default_wasm_config.storage_costs(), default_wasm_config.take_host_function_costs(), + ); + let wasm_config = WasmConfig::new( MessageLimits { max_topic_name_size: 32, max_message_size: 100, max_topics_per_contract: 2, }, + wasm_v1_config, ); let chainspec = ChainspecConfig { system_costs_config: SystemConfig::default(), core_config: CoreConfig::default(), wasm_config, + storage_costs: StorageCosts::default(), }; let builder = RefCell::new(LmdbWasmTestBuilder::new_temporary_with_config(chainspec)); @@ -659,18 +662,18 @@ fn should_not_emit_messages_from_account() { fn should_charge_expected_gas_for_storage() { const GAS_PER_BYTE_COST: u32 = 100; - let wasm_config = WasmConfig::new( - DEFAULT_WASM_MAX_MEMORY, - DEFAULT_MAX_STACK_HEIGHT, + let wasm_v1_config = WasmV1Config::new( + DEFAULT_V1_WASM_MAX_MEMORY, + DEFAULT_V1_MAX_STACK_HEIGHT, OpcodeCosts::zero(), - StorageCosts::new(GAS_PER_BYTE_COST), HostFunctionCosts::zero(), - MessageLimits::default(), ); + let wasm_config = WasmConfig::new(MessageLimits::default(), wasm_v1_config); let chainspec = ChainspecConfig { wasm_config, core_config: CoreConfig::default(), system_costs_config: SystemConfig::default(), + storage_costs: StorageCosts::new(GAS_PER_BYTE_COST), }; let builder = RefCell::new(LmdbWasmTestBuilder::new_temporary_with_config(chainspec)); builder @@ -759,22 +762,22 @@ fn should_charge_increasing_gas_cost_for_multiple_messages_emitted() { const EMIT_MESSAGES_FROM_MULTIPLE_CONTRACTS: u32 = emit_cost_per_execution(EMIT_MESSAGE_FROM_EACH_VERSION_NUM_MESSAGES); - let wasm_config = WasmConfig::new( - DEFAULT_WASM_MAX_MEMORY, - DEFAULT_MAX_STACK_HEIGHT, + let wasm_v1_config = WasmV1Config::new( + DEFAULT_V1_WASM_MAX_MEMORY, + DEFAULT_V1_MAX_STACK_HEIGHT, OpcodeCosts::zero(), - StorageCosts::zero(), HostFunctionCosts { emit_message: HostFunction::fixed(FIRST_MESSAGE_EMIT_COST), cost_increase_per_message: COST_INCREASE_PER_MESSAGE, ..Zero::zero() }, - MessageLimits::default(), ); + let wasm_config = WasmConfig::new(MessageLimits::default(), wasm_v1_config); let chainspec = ChainspecConfig { wasm_config, core_config: CoreConfig::default(), system_costs_config: SystemConfig::default(), + storage_costs: StorageCosts::zero(), }; let builder = RefCell::new(LmdbWasmTestBuilder::new_temporary_with_config(chainspec)); @@ -875,23 +878,26 @@ fn should_register_topic_on_contract_creation() { #[ignore] #[test] fn should_not_exceed_configured_topic_name_limits_on_contract_upgrade_no_init() { - let default_wasm_config = WasmConfig::default(); + let default_wasm_v1_config = WasmV1Config::default(); + let wasm_v1_config = WasmV1Config::new( + default_wasm_v1_config.max_memory(), + default_wasm_v1_config.max_stack_height(), + default_wasm_v1_config.opcode_costs(), + default_wasm_v1_config.take_host_function_costs(), + ); let wasm_config = WasmConfig::new( - default_wasm_config.max_memory, - default_wasm_config.max_stack_height, - default_wasm_config.opcode_costs(), - default_wasm_config.storage_costs(), - default_wasm_config.take_host_function_costs(), MessageLimits { max_topic_name_size: 16, //length of MESSAGE_EMITTER_GENERIC_TOPIC max_message_size: 100, max_topics_per_contract: 3, }, + wasm_v1_config, ); let chainspec = ChainspecConfig { wasm_config, core_config: CoreConfig::default(), system_costs_config: SystemConfig::default(), + storage_costs: StorageCosts::default(), }; let builder = RefCell::new(LmdbWasmTestBuilder::new_temporary_with_config(chainspec)); @@ -906,24 +912,27 @@ fn should_not_exceed_configured_topic_name_limits_on_contract_upgrade_no_init() #[ignore] #[test] fn should_not_exceed_configured_max_topics_per_contract_upgrade_no_init() { - let default_wasm_config = WasmConfig::default(); - let wasm_config = WasmConfig::new( - default_wasm_config.max_memory, - default_wasm_config.max_stack_height, + let default_wasm_config = WasmV1Config::default(); + let wasm_v1_config = WasmV1Config::new( + default_wasm_config.max_memory(), + default_wasm_config.max_stack_height(), default_wasm_config.opcode_costs(), - default_wasm_config.storage_costs(), default_wasm_config.take_host_function_costs(), + ); + let wasm_config = WasmConfig::new( MessageLimits { max_topic_name_size: 32, max_message_size: 100, max_topics_per_contract: 1, /* only allow 1 topic. Since on upgrade previous * topics carry over, the upgrade should fail. */ }, + wasm_v1_config, ); let chainspec = ChainspecConfig { wasm_config, system_costs_config: SystemConfig::default(), core_config: CoreConfig::default(), + storage_costs: StorageCosts::default(), }; let builder = RefCell::new(LmdbWasmTestBuilder::new_temporary_with_config(chainspec)); @@ -1117,12 +1126,10 @@ fn emit_message_should_charge_variable_gas_cost_based_on_topic_and_message_size( const COST_PER_MESSAGE_TOPIC_NAME_SIZE: u32 = 2; const COST_PER_MESSAGE_LENGTH: u32 = 1_000; const MESSAGE_SUFFIX: &str = "test"; - - let wasm_config = WasmConfig::new( - DEFAULT_WASM_MAX_MEMORY, - DEFAULT_MAX_STACK_HEIGHT, + let wasm_v1_config = WasmV1Config::new( + DEFAULT_V1_WASM_MAX_MEMORY, + DEFAULT_V1_MAX_STACK_HEIGHT, OpcodeCosts::zero(), - StorageCosts::zero(), HostFunctionCosts { emit_message: HostFunction::new( MESSAGE_EMIT_COST, @@ -1135,12 +1142,13 @@ fn emit_message_should_charge_variable_gas_cost_based_on_topic_and_message_size( ), ..Zero::zero() }, - MessageLimits::default(), ); + let wasm_config = WasmConfig::new(MessageLimits::default(), wasm_v1_config); let chainspec = ChainspecConfig { wasm_config, core_config: CoreConfig::default(), system_costs_config: SystemConfig::default(), + storage_costs: StorageCosts::zero(), }; let builder = RefCell::new(LmdbWasmTestBuilder::new_temporary_with_config(chainspec)); diff --git a/execution_engine_testing/tests/src/test/gas_counter.rs b/execution_engine_testing/tests/src/test/gas_counter.rs index 4588cf8888..d10326ff60 100644 --- a/execution_engine_testing/tests/src/test/gas_counter.rs +++ b/execution_engine_testing/tests/src/test/gas_counter.rs @@ -6,10 +6,12 @@ use casper_wasm::{ use casper_engine_test_support::{ DeployItemBuilder, ExecuteRequestBuilder, LmdbWasmTestBuilder, ARG_AMOUNT, - DEFAULT_ACCOUNT_ADDR, DEFAULT_PAYMENT, DEFAULT_WASM_CONFIG, LOCAL_GENESIS_REQUEST, + DEFAULT_ACCOUNT_ADDR, DEFAULT_PAYMENT, LOCAL_GENESIS_REQUEST, }; use casper_execution_engine::{engine_state::Error, runtime::PreprocessingError}; -use casper_types::{addressable_entity::DEFAULT_ENTRY_POINT_NAME, runtime_args, Gas, RuntimeArgs}; +use casper_types::{ + addressable_entity::DEFAULT_ENTRY_POINT_NAME, runtime_args, Gas, OpcodeCosts, RuntimeArgs, +}; use crate::test::regression::test_utils::make_gas_counter_overflow; @@ -71,7 +73,7 @@ fn should_fail_to_overflow_gas_counter() { #[ignore] #[test] fn should_correctly_measure_gas_for_opcodes() { - let opcode_costs = DEFAULT_WASM_CONFIG.opcode_costs(); + let opcode_costs = OpcodeCosts::default(); const GROW_PAGES: u32 = 1; diff --git a/execution_engine_testing/tests/src/test/private_chain.rs b/execution_engine_testing/tests/src/test/private_chain.rs index 8a202fd069..9eab9268a0 100644 --- a/execution_engine_testing/tests/src/test/private_chain.rs +++ b/execution_engine_testing/tests/src/test/private_chain.rs @@ -9,8 +9,8 @@ use casper_engine_test_support::{ ChainspecConfig, LmdbWasmTestBuilder, DEFAULT_ACCOUNT_INITIAL_BALANCE, DEFAULT_AUCTION_DELAY, DEFAULT_CHAINSPEC_REGISTRY, DEFAULT_GENESIS_CONFIG_HASH, DEFAULT_GENESIS_TIMESTAMP_MILLIS, DEFAULT_LOCKED_FUNDS_PERIOD_MILLIS, DEFAULT_PROPOSER_PUBLIC_KEY, DEFAULT_PROTOCOL_VERSION, - DEFAULT_ROUND_SEIGNIORAGE_RATE, DEFAULT_SYSTEM_CONFIG, DEFAULT_UNBONDING_DELAY, - DEFAULT_VALIDATOR_SLOTS, DEFAULT_WASM_CONFIG, + DEFAULT_ROUND_SEIGNIORAGE_RATE, DEFAULT_STORAGE_COSTS, DEFAULT_SYSTEM_CONFIG, + DEFAULT_UNBONDING_DELAY, DEFAULT_VALIDATOR_SLOTS, DEFAULT_WASM_CONFIG, }; use num_rational::Ratio; use once_cell::sync::Lazy; @@ -20,7 +20,8 @@ use casper_types::{ account::AccountHash, system::auction::DELEGATION_RATE_DENOMINATOR, AdministratorAccount, CoreConfig, FeeHandling, GenesisAccount, GenesisConfig, GenesisConfigBuilder, GenesisValidator, HostFunction, HostFunctionCosts, MessageLimits, Motes, OpcodeCosts, PublicKey, RefundHandling, - SecretKey, StorageCosts, WasmConfig, DEFAULT_MAX_STACK_HEIGHT, DEFAULT_WASM_MAX_MEMORY, U512, + SecretKey, StorageCosts, WasmConfig, WasmV1Config, DEFAULT_V1_MAX_STACK_HEIGHT, + DEFAULT_V1_WASM_MAX_MEMORY, U512, }; use tempfile::TempDir; @@ -144,6 +145,7 @@ static DEFUALT_PRIVATE_CHAIN_EXEC_CONFIG: Lazy = Lazy::new(|| { .with_round_seigniorage_rate(DEFAULT_ROUND_SEIGNIORAGE_RATE) .with_unbonding_delay(DEFAULT_UNBONDING_DELAY) .with_genesis_timestamp_millis(DEFAULT_GENESIS_TIMESTAMP_MILLIS) + .with_storage_costs(*DEFAULT_STORAGE_COSTS) .build() }); @@ -194,14 +196,13 @@ fn make_wasm_config() -> WasmConfig { transfer_from_purse_to_account: HostFunction::fixed(0), ..HostFunctionCosts::default() }; - WasmConfig::new( - DEFAULT_WASM_MAX_MEMORY, - DEFAULT_MAX_STACK_HEIGHT, + let wasm_v1_config = WasmV1Config::new( + DEFAULT_V1_WASM_MAX_MEMORY, + DEFAULT_V1_MAX_STACK_HEIGHT, OpcodeCosts::default(), - StorageCosts::default(), host_functions, - MessageLimits::default(), - ) + ); + WasmConfig::new(MessageLimits::default(), wasm_v1_config) } fn make_private_chain_config( @@ -222,10 +223,12 @@ fn make_private_chain_config( ..Default::default() }; let wasm_config = make_wasm_config(); + let storage_costs = StorageCosts::default(); ChainspecConfig { core_config, wasm_config, system_costs_config: Default::default(), + storage_costs, } } diff --git a/execution_engine_testing/tests/src/test/private_chain/management.rs b/execution_engine_testing/tests/src/test/private_chain/management.rs index 899510dd66..f6a2dd648c 100644 --- a/execution_engine_testing/tests/src/test/private_chain/management.rs +++ b/execution_engine_testing/tests/src/test/private_chain/management.rs @@ -3,8 +3,8 @@ use casper_engine_test_support::{ TransferRequestBuilder, DEFAULT_AUCTION_DELAY, DEFAULT_CHAINSPEC_REGISTRY, DEFAULT_GENESIS_CONFIG_HASH, DEFAULT_GENESIS_TIMESTAMP_MILLIS, DEFAULT_LOCKED_FUNDS_PERIOD_MILLIS, DEFAULT_PAYMENT, DEFAULT_PROTOCOL_VERSION, - DEFAULT_ROUND_SEIGNIORAGE_RATE, DEFAULT_SYSTEM_CONFIG, DEFAULT_UNBONDING_DELAY, - DEFAULT_VALIDATOR_SLOTS, DEFAULT_WASM_CONFIG, + DEFAULT_ROUND_SEIGNIORAGE_RATE, DEFAULT_STORAGE_COSTS, DEFAULT_SYSTEM_CONFIG, + DEFAULT_UNBONDING_DELAY, DEFAULT_VALIDATOR_SLOTS, DEFAULT_WASM_CONFIG, }; use casper_execution_engine::{engine_state::Error, execution::ExecError}; use casper_storage::{data_access_layer::GenesisRequest, tracking_copy::TrackingCopyError}; @@ -74,6 +74,7 @@ fn should_not_run_genesis_with_duplicated_administrator_accounts() { core_config, wasm_config: Default::default(), system_costs_config: Default::default(), + storage_costs: Default::default(), }; let data_dir = TempDir::new().expect("should create temp dir"); @@ -100,6 +101,7 @@ fn should_not_run_genesis_with_duplicated_administrator_accounts() { .with_round_seigniorage_rate(DEFAULT_ROUND_SEIGNIORAGE_RATE) .with_unbonding_delay(DEFAULT_UNBONDING_DELAY) .with_genesis_timestamp_millis(DEFAULT_GENESIS_TIMESTAMP_MILLIS) + .with_storage_costs(*DEFAULT_STORAGE_COSTS) .build(); let modified_genesis_request = GenesisRequest::new( diff --git a/execution_engine_testing/tests/src/test/regression/ee_966.rs b/execution_engine_testing/tests/src/test/regression/ee_966.rs index ee472bf628..4f025485a0 100644 --- a/execution_engine_testing/tests/src/test/regression/ee_966.rs +++ b/execution_engine_testing/tests/src/test/regression/ee_966.rs @@ -10,8 +10,8 @@ use casper_engine_test_support::{ use casper_execution_engine::{engine_state::Error, execution::ExecError}; use casper_types::{ addressable_entity::DEFAULT_ENTRY_POINT_NAME, runtime_args, ApiError, EraId, HostFunctionCosts, - MessageLimits, OpcodeCosts, ProtocolVersion, RuntimeArgs, StorageCosts, WasmConfig, - DEFAULT_MAX_STACK_HEIGHT, DEFAULT_WASM_MAX_MEMORY, + MessageLimits, OpcodeCosts, ProtocolVersion, RuntimeArgs, WasmConfig, WasmV1Config, + DEFAULT_V1_MAX_STACK_HEIGHT, DEFAULT_V1_WASM_MAX_MEMORY, }; const CONTRACT_EE_966_REGRESSION: &str = "ee_966_regression.wasm"; @@ -19,14 +19,13 @@ const MINIMUM_INITIAL_MEMORY: u32 = 16; const DEFAULT_ACTIVATION_POINT: EraId = EraId::new(0); static DOUBLED_WASM_MEMORY_LIMIT: Lazy = Lazy::new(|| { - WasmConfig::new( - DEFAULT_WASM_MAX_MEMORY * 2, - DEFAULT_MAX_STACK_HEIGHT, + let wasm_v1_config = WasmV1Config::new( + DEFAULT_V1_WASM_MAX_MEMORY * 2, + DEFAULT_V1_MAX_STACK_HEIGHT, OpcodeCosts::default(), - StorageCosts::default(), HostFunctionCosts::default(), - MessageLimits::default(), - ) + ); + WasmConfig::new(MessageLimits::default(), wasm_v1_config) }); const NEW_PROTOCOL_VERSION: ProtocolVersion = ProtocolVersion::from_parts( DEFAULT_PROTOCOL_VERSION.value().major, @@ -89,7 +88,7 @@ fn should_run_ee_966_with_zero_min_and_zero_max_memory() { #[ignore] #[test] fn should_run_ee_966_cant_have_too_much_initial_memory() { - let session_code = make_session_code_with_memory_pages(DEFAULT_WASM_MAX_MEMORY + 1, None); + let session_code = make_session_code_with_memory_pages(DEFAULT_V1_WASM_MAX_MEMORY + 1, None); let exec_request = make_request_with_session_bytes(session_code); @@ -109,8 +108,10 @@ fn should_run_ee_966_cant_have_too_much_initial_memory() { #[ignore] #[test] fn should_run_ee_966_should_request_exactly_maximum() { - let session_code = - make_session_code_with_memory_pages(DEFAULT_WASM_MAX_MEMORY, Some(DEFAULT_WASM_MAX_MEMORY)); + let session_code = make_session_code_with_memory_pages( + DEFAULT_V1_WASM_MAX_MEMORY, + Some(DEFAULT_V1_WASM_MAX_MEMORY), + ); let exec_request = make_request_with_session_bytes(session_code); @@ -124,7 +125,7 @@ fn should_run_ee_966_should_request_exactly_maximum() { #[ignore] #[test] fn should_run_ee_966_should_request_exactly_maximum_as_initial() { - let session_code = make_session_code_with_memory_pages(DEFAULT_WASM_MAX_MEMORY, None); + let session_code = make_session_code_with_memory_pages(DEFAULT_V1_WASM_MAX_MEMORY, None); let exec_request = make_request_with_session_bytes(session_code); @@ -140,7 +141,7 @@ fn should_run_ee_966_should_request_exactly_maximum_as_initial() { fn should_run_ee_966_cant_have_too_much_max_memory() { let session_code = make_session_code_with_memory_pages( MINIMUM_INITIAL_MEMORY, - Some(DEFAULT_WASM_MAX_MEMORY + 1), + Some(DEFAULT_V1_WASM_MAX_MEMORY + 1), ); let exec_request = make_request_with_session_bytes(session_code); @@ -163,7 +164,7 @@ fn should_run_ee_966_cant_have_too_much_max_memory() { fn should_run_ee_966_cant_have_way_too_much_max_memory() { let session_code = make_session_code_with_memory_pages( MINIMUM_INITIAL_MEMORY, - Some(DEFAULT_WASM_MAX_MEMORY + 42), + Some(DEFAULT_V1_WASM_MAX_MEMORY + 42), ); let exec_request = make_request_with_session_bytes(session_code); @@ -184,8 +185,10 @@ fn should_run_ee_966_cant_have_way_too_much_max_memory() { #[ignore] #[test] fn should_run_ee_966_cant_have_larger_initial_than_max_memory() { - let session_code = - make_session_code_with_memory_pages(DEFAULT_WASM_MAX_MEMORY, Some(MINIMUM_INITIAL_MEMORY)); + let session_code = make_session_code_with_memory_pages( + DEFAULT_V1_WASM_MAX_MEMORY, + Some(MINIMUM_INITIAL_MEMORY), + ); let exec_request = make_request_with_session_bytes(session_code); diff --git a/execution_engine_testing/tests/src/test/regression/gh_2280.rs b/execution_engine_testing/tests/src/test/regression/gh_2280.rs index 77003f52b1..d0e6f80b8f 100644 --- a/execution_engine_testing/tests/src/test/regression/gh_2280.rs +++ b/execution_engine_testing/tests/src/test/regression/gh_2280.rs @@ -8,8 +8,8 @@ use casper_engine_test_support::{ use casper_types::{ account::AccountHash, runtime_args, system::mint, AddressableEntityHash, EraId, Gas, HostFunction, HostFunctionCost, HostFunctionCosts, Key, MintCosts, Motes, - ProtocolUpgradeConfig, ProtocolVersion, PublicKey, SecretKey, WasmConfig, - DEFAULT_MAX_STACK_HEIGHT, DEFAULT_WASM_MAX_MEMORY, U512, + ProtocolUpgradeConfig, ProtocolVersion, PublicKey, SecretKey, WasmConfig, WasmV1Config, + DEFAULT_V1_MAX_STACK_HEIGHT, DEFAULT_V1_WASM_MAX_MEMORY, U512, }; const TRANSFER_TO_ACCOUNT_CONTRACT: &str = "transfer_to_account.wasm"; @@ -217,7 +217,11 @@ fn gh_2280_create_purse_should_always_cost_the_same_gas() { // Increase "transfer_to_account" host function call exactly by X, so we can assert that // transfer cost increased by exactly X without hidden fees. - let host_function_costs = builder.chainspec().wasm_config.take_host_function_costs(); + let host_function_costs = builder + .chainspec() + .wasm_config + .v1() + .take_host_function_costs(); let default_create_purse_cost = host_function_costs.create_purse.cost(); let new_create_purse_cost = default_create_purse_cost @@ -662,14 +666,13 @@ fn make_wasm_config( new_host_function_costs: HostFunctionCosts, old_wasm_config: WasmConfig, ) -> WasmConfig { - WasmConfig::new( - DEFAULT_WASM_MAX_MEMORY, - DEFAULT_MAX_STACK_HEIGHT, - old_wasm_config.opcode_costs(), - old_wasm_config.storage_costs(), + let wasm_v1_config = WasmV1Config::new( + DEFAULT_V1_WASM_MAX_MEMORY, + DEFAULT_V1_MAX_STACK_HEIGHT, + old_wasm_config.v1().opcode_costs(), new_host_function_costs, - old_wasm_config.messages_limits(), - ) + ); + WasmConfig::new(old_wasm_config.messages_limits(), wasm_v1_config) } fn make_upgrade_request() -> ProtocolUpgradeConfig { diff --git a/execution_engine_testing/tests/src/test/regression/gov_427.rs b/execution_engine_testing/tests/src/test/regression/gov_427.rs index c343d84468..80f86f0fc0 100644 --- a/execution_engine_testing/tests/src/test/regression/gov_427.rs +++ b/execution_engine_testing/tests/src/test/regression/gov_427.rs @@ -1,5 +1,5 @@ use casper_engine_test_support::{ - ExecuteRequestBuilder, LmdbWasmTestBuilder, DEFAULT_ACCOUNT_ADDR, DEFAULT_WASM_CONFIG, + ExecuteRequestBuilder, LmdbWasmTestBuilder, DEFAULT_ACCOUNT_ADDR, DEFAULT_WASM_V1_CONFIG, LOCAL_GENESIS_REQUEST, }; use casper_execution_engine::{engine_state::Error, execution::ExecError}; @@ -63,7 +63,7 @@ fn too_many_locals_should_exceed_stack_height() { const CALL_COST: usize = 1; let extra_types = [ValType::I32]; let repeat_pattern = [ValType::I64]; - let max_stack_height = DEFAULT_WASM_CONFIG.max_stack_height as usize; + let max_stack_height = DEFAULT_WASM_V1_CONFIG.max_stack_height() as usize; let success_wasm_bytes: Vec = make_arbitrary_local_count( max_stack_height - extra_types.len() - CALL_COST - 1, diff --git a/execution_engine_testing/tests/src/test/regression/gov_74.rs b/execution_engine_testing/tests/src/test/regression/gov_74.rs index d45d2a8bdc..6efd99f023 100644 --- a/execution_engine_testing/tests/src/test/regression/gov_74.rs +++ b/execution_engine_testing/tests/src/test/regression/gov_74.rs @@ -7,7 +7,7 @@ use casper_execution_engine::{ execution::ExecError, runtime::{PreprocessingError, WasmValidationError, DEFAULT_MAX_PARAMETER_COUNT}, }; -use casper_types::{EraId, ProtocolVersion, RuntimeArgs, WasmConfig}; +use casper_types::{EraId, ProtocolVersion, RuntimeArgs, WasmV1Config}; use crate::wasm_utils; @@ -79,7 +79,7 @@ fn should_pass_max_parameter_count() { fn should_observe_stack_height_limit() { let mut builder = initialize_builder(); - assert!(WasmConfig::default().max_stack_height > NEW_WASM_STACK_HEIGHT); + assert!(WasmV1Config::default().max_stack_height() > NEW_WASM_STACK_HEIGHT); // This runs out of the interpreter stack limit let exec_request_1 = { diff --git a/execution_engine_testing/tests/src/test/regression/regression_20240105.rs b/execution_engine_testing/tests/src/test/regression/regression_20240105.rs index cada5fbbfb..d2ee4f0931 100644 --- a/execution_engine_testing/tests/src/test/regression/regression_20240105.rs +++ b/execution_engine_testing/tests/src/test/regression/regression_20240105.rs @@ -94,7 +94,7 @@ mod repeated_ffi_call_should_gas_out_quickly { ChainspecConfig::from_chainspec_path(&*CHAINSPEC_SYMLINK).unwrap(); // Increase the `max_memory` available in order to avoid hitting unreachable // instruction during execution. - chainspec_config.wasm_config.max_memory = 10_000; + *chainspec_config.wasm_config.v1_mut().max_memory_mut() = 10_000; let mut builder = LmdbWasmTestBuilder::open( data_dir.path(), chainspec_config, diff --git a/execution_engine_testing/tests/src/test/regression/test_utils.rs b/execution_engine_testing/tests/src/test/regression/test_utils.rs index 44f6043b06..4d7d994a88 100644 --- a/execution_engine_testing/tests/src/test/regression/test_utils.rs +++ b/execution_engine_testing/tests/src/test/regression/test_utils.rs @@ -1,4 +1,4 @@ -use casper_engine_test_support::DEFAULT_WASM_CONFIG; +use casper_engine_test_support::DEFAULT_WASM_V1_CONFIG; use casper_types::addressable_entity::DEFAULT_ENTRY_POINT_NAME; use casper_wasm::{ builder, @@ -8,7 +8,7 @@ use casper_wasm::{ /// Prepare malicious payload with amount of opcodes that could potentially overflow injected gas /// counter. pub(crate) fn make_gas_counter_overflow() -> Vec { - let opcode_costs = DEFAULT_WASM_CONFIG.opcode_costs(); + let opcode_costs = DEFAULT_WASM_V1_CONFIG.opcode_costs(); // Create a lot of `nop` opcodes to potentially overflow gas injector's batching counter. let upper_bound = (u32::max_value() as usize / opcode_costs.nop as usize) + 1; diff --git a/execution_engine_testing/tests/src/test/storage_costs.rs b/execution_engine_testing/tests/src/test/storage_costs.rs index 776cffc53f..ab34a7bf69 100644 --- a/execution_engine_testing/tests/src/test/storage_costs.rs +++ b/execution_engine_testing/tests/src/test/storage_costs.rs @@ -17,8 +17,8 @@ use casper_types::{ bytesrepr::{Bytes, ToBytes}, AddressableEntityHash, BrTableCost, CLValue, ControlFlowCosts, EntityVersionKey, EraId, Group, Groups, HostFunctionCosts, Key, MessageLimits, OpcodeCosts, Package, ProtocolVersion, - RuntimeArgs, StorageCosts, StoredValue, URef, WasmConfig, DEFAULT_MAX_STACK_HEIGHT, - DEFAULT_WASM_MAX_MEMORY, U512, + RuntimeArgs, StorageCosts, StoredValue, URef, WasmConfig, WasmV1Config, + DEFAULT_V1_MAX_STACK_HEIGHT, DEFAULT_V1_WASM_MAX_MEMORY, U512, }; #[cfg(not(feature = "use-as-wasm"))] use casper_types::{ @@ -94,15 +94,14 @@ const NEW_OPCODE_COSTS: OpcodeCosts = OpcodeCosts { }; static NEW_HOST_FUNCTION_COSTS: Lazy = Lazy::new(HostFunctionCosts::zero); -static STORAGE_COSTS_ONLY: Lazy = Lazy::new(|| { - WasmConfig::new( - DEFAULT_WASM_MAX_MEMORY, - DEFAULT_MAX_STACK_HEIGHT, +static NO_COSTS_WASM_CONFIG: Lazy = Lazy::new(|| { + let wasm_v1_config = WasmV1Config::new( + DEFAULT_V1_WASM_MAX_MEMORY, + DEFAULT_V1_MAX_STACK_HEIGHT, NEW_OPCODE_COSTS, - StorageCosts::default(), *NEW_HOST_FUNCTION_COSTS, - MessageLimits::default(), - ) + ); + WasmConfig::new(MessageLimits::default(), wasm_v1_config) }); static NEW_PROTOCOL_VERSION: Lazy = Lazy::new(|| { @@ -131,7 +130,7 @@ fn initialize_isolated_storage_costs() -> LmdbWasmTestBuilder { let updated_chainspec = builder .chainspec() .clone() - .with_wasm_config(*STORAGE_COSTS_ONLY); + .with_wasm_config(*NO_COSTS_WASM_CONFIG); builder .with_chainspec(updated_chainspec) @@ -719,7 +718,7 @@ fn should_verify_new_uref_storage_cost() { assert_eq!( // should charge for storage of a u64 behind a URef builder.last_exec_gas_cost(), - STORAGE_COSTS_ONLY.storage_costs().calculate_gas_cost( + StorageCosts::default().calculate_gas_cost( StoredValue::CLValue(CLValue::from_t(0u64).expect("should create CLValue")) .serialized_length() ) @@ -764,7 +763,7 @@ fn should_verify_put_key_is_charging_for_storage() { assert_eq!( // should charge for storage of a named key builder.last_exec_gas_cost(), - STORAGE_COSTS_ONLY.storage_costs().calculate_gas_cost( + StorageCosts::default().calculate_gas_cost( StoredValue::NamedKey( NamedKeyValue::from_concrete_values(Key::Hash([0u8; 32]), "new_key".to_owned()) .expect("should create NamedKey") @@ -812,7 +811,7 @@ fn should_verify_remove_key_is_not_charging_for_storage() { assert_eq!( // should charge zero, because we do not charge for storage when removing a key builder.last_exec_gas_cost(), - STORAGE_COSTS_ONLY.storage_costs().calculate_gas_cost(0), + StorageCosts::default().calculate_gas_cost(0), ) } @@ -854,7 +853,7 @@ fn should_verify_create_contract_at_hash_is_charging_for_storage() { assert_eq!( // should charge at least enough for storage of a package and unit CLValue (for a URef) builder.last_exec_gas_cost(), - STORAGE_COSTS_ONLY.storage_costs().calculate_gas_cost( + StorageCosts::default().calculate_gas_cost( StoredValue::Package(Package::default()).serialized_length() + StoredValue::CLValue(CLValue::unit()).serialized_length() ) @@ -916,8 +915,7 @@ fn should_verify_create_contract_user_group_is_charging_for_storage() { assert_eq!( // should charge for storage of the new package builder.last_exec_gas_cost(), - STORAGE_COSTS_ONLY - .storage_costs() + StorageCosts::default() .calculate_gas_cost(StoredValue::Package(package.clone()).serialized_length()), ); @@ -940,7 +938,7 @@ fn should_verify_create_contract_user_group_is_charging_for_storage() { assert_eq!( // should charge for storage of the new package and a unit CLValue (for a URef) builder.last_exec_gas_cost(), - STORAGE_COSTS_ONLY.storage_costs().calculate_gas_cost( + StorageCosts::default().calculate_gas_cost( StoredValue::Package(package.clone()).serialized_length() + StoredValue::CLValue(CLValue::unit()).serialized_length() ) @@ -961,8 +959,7 @@ fn should_verify_create_contract_user_group_is_charging_for_storage() { assert_eq!( // should charge for storage of the new package builder.last_exec_gas_cost(), - STORAGE_COSTS_ONLY - .storage_costs() + StorageCosts::default() .calculate_gas_cost(StoredValue::Package(package).serialized_length()) ) } @@ -1025,7 +1022,7 @@ fn should_verify_subcall_new_uref_is_charging_for_storage() { assert_eq!( // should charge for storage of a u64 behind a URef builder.last_exec_gas_cost(), - STORAGE_COSTS_ONLY.storage_costs().calculate_gas_cost( + StorageCosts::default().calculate_gas_cost( StoredValue::CLValue(CLValue::from_t(0u64).expect("should create CLValue")) .serialized_length() ) diff --git a/execution_engine_testing/tests/src/test/system_contracts/genesis.rs b/execution_engine_testing/tests/src/test/system_contracts/genesis.rs index 3811d02a19..600eb91b7f 100644 --- a/execution_engine_testing/tests/src/test/system_contracts/genesis.rs +++ b/execution_engine_testing/tests/src/test/system_contracts/genesis.rs @@ -4,8 +4,8 @@ use once_cell::sync::Lazy; use casper_engine_test_support::{ ChainspecConfig, LmdbWasmTestBuilder, DEFAULT_AUCTION_DELAY, DEFAULT_CHAINSPEC_REGISTRY, DEFAULT_GENESIS_TIMESTAMP_MILLIS, DEFAULT_LOCKED_FUNDS_PERIOD_MILLIS, DEFAULT_PROTOCOL_VERSION, - DEFAULT_ROUND_SEIGNIORAGE_RATE, DEFAULT_SYSTEM_CONFIG, DEFAULT_UNBONDING_DELAY, - DEFAULT_VALIDATOR_SLOTS, DEFAULT_WASM_CONFIG, + DEFAULT_ROUND_SEIGNIORAGE_RATE, DEFAULT_STORAGE_COSTS, DEFAULT_SYSTEM_CONFIG, + DEFAULT_UNBONDING_DELAY, DEFAULT_VALIDATOR_SLOTS, DEFAULT_WASM_CONFIG, }; use casper_storage::data_access_layer::GenesisRequest; use casper_types::{ @@ -144,6 +144,7 @@ fn should_track_total_token_supply_in_mint() { .with_round_seigniorage_rate(round_seigniorage_rate) .with_unbonding_delay(unbonding_delay) .with_genesis_timestamp_millis(genesis_timestamp) + .with_storage_costs(*DEFAULT_STORAGE_COSTS) .build(); let genesis_request = GenesisRequest::new( diff --git a/execution_engine_testing/tests/src/test/system_contracts/upgrade.rs b/execution_engine_testing/tests/src/test/system_contracts/upgrade.rs index 8a0980834b..3e8c90231e 100644 --- a/execution_engine_testing/tests/src/test/system_contracts/upgrade.rs +++ b/execution_engine_testing/tests/src/test/system_contracts/upgrade.rs @@ -20,8 +20,8 @@ use casper_types::{ }, mint::ROUND_SEIGNIORAGE_RATE_KEY, }, - Account, CLValue, CoreConfig, EntityAddr, EraId, Key, ProtocolVersion, StoredValue, - SystemEntityRegistry, U256, U512, + Account, CLValue, CoreConfig, EntityAddr, EraId, Key, ProtocolVersion, StorageCosts, + StoredValue, SystemEntityRegistry, U256, U512, }; use rand::Rng; @@ -618,6 +618,7 @@ fn should_increase_max_associated_keys_after_upgrade() { core_config, wasm_config: Default::default(), system_costs_config: Default::default(), + storage_costs: StorageCosts::default(), }; builder.with_chainspec(chainspec); diff --git a/execution_engine_testing/tests/src/test/system_costs.rs b/execution_engine_testing/tests/src/test/system_costs.rs index 96b640c4a7..3be4f4b3ad 100644 --- a/execution_engine_testing/tests/src/test/system_costs.rs +++ b/execution_engine_testing/tests/src/test/system_costs.rs @@ -17,8 +17,9 @@ use casper_types::{ AuctionCosts, BrTableCost, ControlFlowCosts, CoreConfig, EraId, Gas, GenesisAccount, GenesisValidator, HandlePaymentCosts, HostFunction, HostFunctionCost, HostFunctionCosts, MessageLimits, MintCosts, Motes, OpcodeCosts, ProtocolVersion, PublicKey, RuntimeArgs, - SecretKey, StandardPaymentCosts, StorageCosts, SystemConfig, WasmConfig, DEFAULT_ADD_BID_COST, - DEFAULT_MAX_STACK_HEIGHT, DEFAULT_MINIMUM_BID_AMOUNT, DEFAULT_WASM_MAX_MEMORY, U512, + SecretKey, StandardPaymentCosts, StorageCosts, SystemConfig, WasmConfig, WasmV1Config, + DEFAULT_ADD_BID_COST, DEFAULT_MINIMUM_BID_AMOUNT, DEFAULT_V1_MAX_STACK_HEIGHT, + DEFAULT_V1_WASM_MAX_MEMORY, U512, }; use crate::wasm_utils; @@ -837,15 +838,13 @@ fn should_verify_wasm_add_bid_wasm_cost_is_not_recursive() { call_contract: HostFunction::fixed(UPDATED_CALL_CONTRACT_COST), ..Zero::zero() }; - - let wasm_config = WasmConfig::new( - DEFAULT_WASM_MAX_MEMORY, - DEFAULT_MAX_STACK_HEIGHT, + let wasm_v1_config = WasmV1Config::new( + DEFAULT_V1_WASM_MAX_MEMORY, + DEFAULT_V1_MAX_STACK_HEIGHT, new_opcode_costs, - new_storage_costs, new_host_function_costs, - MessageLimits::default(), ); + let wasm_config = WasmConfig::new(MessageLimits::default(), wasm_v1_config); let new_max_associated_keys = DEFAULT_MAX_ASSOCIATED_KEYS; let new_auction_costs = AuctionCosts::default(); @@ -872,6 +871,7 @@ fn should_verify_wasm_add_bid_wasm_cost_is_not_recursive() { system_costs_config, wasm_config, core_config, + storage_costs: new_storage_costs, }; builder.with_chainspec(chainspec); diff --git a/node/src/components/contract_runtime.rs b/node/src/components/contract_runtime.rs index a4a0859690..4c14d96a5a 100644 --- a/node/src/components/contract_runtime.rs +++ b/node/src/components/contract_runtime.rs @@ -148,6 +148,7 @@ impl ContractRuntime { .with_refund_handling(chainspec.core_config.refund_handling) .with_fee_handling(chainspec.core_config.fee_handling) .with_protocol_version(chainspec.protocol_version()) + .with_storage_costs(chainspec.storage_costs) .build(); let data_access_layer = Arc::new( diff --git a/node/src/utils/chain_specification.rs b/node/src/utils/chain_specification.rs index b87f079672..9f32ea8d18 100644 --- a/node/src/utils/chain_specification.rs +++ b/node/src/utils/chain_specification.rs @@ -153,9 +153,9 @@ mod tests { use casper_types::{ bytesrepr::FromBytes, ActivationPoint, BrTableCost, ChainspecRawBytes, ControlFlowCosts, CoreConfig, EraId, GlobalStateUpdate, HighwayConfig, HostFunction, HostFunctionCosts, - MessageLimits, Motes, OpcodeCosts, ProtocolConfig, ProtocolVersion, StorageCosts, - StoredValue, TestBlockBuilder, TimeDiff, Timestamp, TransactionConfig, TransactionV1Config, - WasmConfig, MINT_LANE_ID, + MessageLimits, Motes, OpcodeCosts, ProtocolConfig, ProtocolVersion, StoredValue, + TestBlockBuilder, TimeDiff, Timestamp, TransactionConfig, TransactionV1Config, WasmConfig, + WasmV1Config, MINT_LANE_ID, }; use super::*; @@ -164,7 +164,6 @@ mod tests { utils::{Loadable, RESOURCES_PATH}, }; - const EXPECTED_GENESIS_STORAGE_COSTS: StorageCosts = StorageCosts::new(101); const EXPECTED_GENESIS_COSTS: OpcodeCosts = OpcodeCosts { bit: 13, add: 14, @@ -254,14 +253,13 @@ mod tests { get_block_info: HostFunction::new(330, [0, 0]), }); static EXPECTED_GENESIS_WASM_COSTS: Lazy = Lazy::new(|| { - WasmConfig::new( + let wasm_v1_config = WasmV1Config::new( 17, // initial_memory 19, // max_stack_height EXPECTED_GENESIS_COSTS, - EXPECTED_GENESIS_STORAGE_COSTS, *EXPECTED_GENESIS_HOST_FUNCTION_COSTS, - MessageLimits::default(), - ) + ); + WasmConfig::new(MessageLimits::default(), wasm_v1_config) }); #[test] diff --git a/node/src/utils/chain_specification/parse_toml.rs b/node/src/utils/chain_specification/parse_toml.rs index f0026844ea..1a3ce947a3 100644 --- a/node/src/utils/chain_specification/parse_toml.rs +++ b/node/src/utils/chain_specification/parse_toml.rs @@ -34,7 +34,8 @@ use serde::{Deserialize, Serialize}; use casper_types::{ bytesrepr::Bytes, file_utils, AccountsConfig, ActivationPoint, Chainspec, ChainspecRawBytes, CoreConfig, GlobalStateUpdate, GlobalStateUpdateConfig, HighwayConfig, NetworkConfig, - ProtocolConfig, ProtocolVersion, SystemConfig, TransactionConfig, VacancyConfig, WasmConfig, + ProtocolConfig, ProtocolVersion, StorageCosts, SystemConfig, TransactionConfig, VacancyConfig, + WasmConfig, }; use crate::utils::{ @@ -80,6 +81,7 @@ pub(super) struct TomlChainspec { wasm: WasmConfig, system_costs: SystemConfig, vacancy: VacancyConfig, + storage_costs: StorageCosts, } impl From<&Chainspec> for TomlChainspec { @@ -99,6 +101,7 @@ impl From<&Chainspec> for TomlChainspec { let wasm = chainspec.wasm_config; let system_costs = chainspec.system_costs_config; let vacancy = chainspec.vacancy_config; + let storage_costs = chainspec.storage_costs; TomlChainspec { protocol, @@ -109,6 +112,7 @@ impl From<&Chainspec> for TomlChainspec { wasm, system_costs, vacancy, + storage_costs, } } } @@ -163,6 +167,7 @@ pub(super) fn parse_toml>( wasm_config: toml_chainspec.wasm, system_costs_config: toml_chainspec.system_costs, vacancy_config: toml_chainspec.vacancy, + storage_costs: toml_chainspec.storage_costs, }; let chainspec_raw_bytes = ChainspecRawBytes::new( Bytes::from(chainspec_bytes), diff --git a/resources/local/chainspec.toml.in b/resources/local/chainspec.toml.in index dba1042329..f083a25156 100644 --- a/resources/local/chainspec.toml.in +++ b/resources/local/chainspec.toml.in @@ -212,17 +212,17 @@ payment_args_max_length = 1024 # The limit of length of serialized session code arguments. session_args_max_length = 1024 -[wasm] +[wasm.v1] # Amount of free memory (in 64kB pages) each contract can use for stack. max_memory = 64 # Max stack height (native WebAssembly stack limiter). max_stack_height = 500 -[wasm.storage_costs] +[storage_costs] # Gas charged per byte stored in the global state. gas_per_byte = 1_117_587 -[wasm.opcode_costs] +[wasm.v1.opcode_costs] # Bit operations multiplier. bit = 300 # Arithmetic add operations multiplier. @@ -257,7 +257,7 @@ grow_memory = 240_000 sign = 300 # Control flow operations multiplier. -[wasm.opcode_costs.control_flow] +[wasm.v1.opcode_costs.control_flow] block = 440 loop = 440 if = 440 @@ -271,14 +271,14 @@ call = 68_000 call_indirect = 68_000 drop = 440 -[wasm.opcode_costs.control_flow.br_table] +[wasm.v1.opcode_costs.control_flow.br_table] # Fixed cost per `br_table` opcode cost = 35_000 # Size of target labels in the `br_table` opcode will be multiplied by `size_multiplier` size_multiplier = 100 # Host function declarations are located in smart_contracts/contract/src/ext_ffi.rs -[wasm.host_function_costs] +[wasm.v1.host_function_costs] add = { cost = 5_800, arguments = [0, 0, 0, 0] } add_associated_key = { cost = 9_000, arguments = [0, 0, 0] } add_contract_version = { cost = 200, arguments = [0, 0, 0, 0, 120_000, 0, 0, 0, 0, 0] } diff --git a/resources/production/chainspec.toml b/resources/production/chainspec.toml index b06df0aa05..be2814c7f0 100644 --- a/resources/production/chainspec.toml +++ b/resources/production/chainspec.toml @@ -220,17 +220,17 @@ payment_args_max_length = 1024 # The limit of length of serialized session code arguments. session_args_max_length = 1024 -[wasm] +[wasm.v1] # Amount of free memory (in 64kB pages) each contract can use for stack. max_memory = 64 # Max stack height (native WebAssembly stack limiter). max_stack_height = 500 -[wasm.storage_costs] +[storage_costs] # Gas charged per byte stored in the global state. gas_per_byte = 1_117_587 -[wasm.opcode_costs] +[wasm.v1.opcode_costs] # Bit operations multiplier. bit = 300 # Arithmetic add operations multiplier. @@ -265,7 +265,7 @@ grow_memory = 240_000 sign = 300 # Control flow operations multiplier. -[wasm.opcode_costs.control_flow] +[wasm.v1.opcode_costs.control_flow] block = 440 loop = 440 if = 440 @@ -279,14 +279,14 @@ call = 68_000 call_indirect = 68_000 drop = 440 -[wasm.opcode_costs.control_flow.br_table] +[wasm.v1.opcode_costs.control_flow.br_table] # Fixed cost per `br_table` opcode cost = 35_000 # Size of target labels in the `br_table` opcode will be multiplied by `size_multiplier` size_multiplier = 100 # Host function declarations are located in smart_contracts/contract/src/ext_ffi.rs -[wasm.host_function_costs] +[wasm.v1.host_function_costs] add = { cost = 5_800, arguments = [0, 0, 0, 0] } add_associated_key = { cost = 1_200_000, arguments = [0, 0, 0] } add_contract_version = { cost = 200, arguments = [0, 0, 0, 0, 120_000, 0, 0, 0, 0, 0] } diff --git a/storage/src/data_access_layer.rs b/storage/src/data_access_layer.rs index 21ae587b03..719b4393b5 100644 --- a/storage/src/data_access_layer.rs +++ b/storage/src/data_access_layer.rs @@ -2,7 +2,7 @@ use crate::global_state::{ error::Error as GlobalStateError, state::{CommitProvider, StateProvider}, }; -use casper_types::{execution::Effects, Digest, EraId}; +use casper_types::{execution::Effects, Digest}; use crate::tracking_copy::TrackingCopy; @@ -88,23 +88,6 @@ pub use system_entity_registry::{ pub use total_supply::{TotalSupplyRequest, TotalSupplyResult}; pub use trie::{PutTrieRequest, PutTrieResult, TrieElement, TrieRequest, TrieResult}; -/// Block placeholder. -pub struct Block { - _era_id: EraId, -} - -/// Block provider definition. -pub trait BlockProvider { - /// Block provider error type. - type Error; - - /// Read block by height. - fn read_block_by_height(&self, _height: usize) -> Result, Self::Error> { - // TODO: We need to implement this - todo!() - } -} - /// Anchor struct for block store functionality. #[derive(Default, Copy, Clone)] pub struct BlockStore(()); diff --git a/types/CHANGELOG.md b/types/CHANGELOG.md index f84ac67171..b04b30a7fc 100644 --- a/types/CHANGELOG.md +++ b/types/CHANGELOG.md @@ -1,15 +1,13 @@ # Changelog -All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog]. +All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog]. -[comment]: <> (Added: new features) -[comment]: <> (Changed: changes in existing functionality) +[comment]: <> (Added: new features) +[comment]: <> (Changed: changes in existing functionality) [comment]: <> (Deprecated: soon-to-be removed features) -[comment]: <> (Removed: now removed features) -[comment]: <> (Fixed: any bug fixes) -[comment]: <> (Security: in case of vulnerabilities) - - +[comment]: <> (Removed: now removed features) +[comment]: <> (Fixed: any bug fixes) +[comment]: <> (Security: in case of vulnerabilities) ## [Unreleased] (node 2.0) @@ -112,6 +110,7 @@ All notable changes to this project will be documented in this file. The format - struct StorageCosts - struct SystemConfig - struct WasmConfig +- struct WasmV1Config - struct ChecksumRegistry - struct SystemEntityRegistry - struct contract_messages::MessageAddr @@ -167,6 +166,7 @@ All notable changes to this project will be documented in this file. The format - enum TransactionScheduling - enum TransactionTarget - struct TransactionV1, +- struct TransactionV1Payload, - struct TransactionV1Hash - struct TransactionV1Builder - enum TransactionV1BuilderError @@ -250,189 +250,175 @@ All notable changes to this project will be documented in this file. The format - methods `groups_mut`, `add_group`, `lookup_contract_hash`, `is_version_enabled`, `is_contract_enabled`, `insert_contract_version`, `disable_contract_version`, `enable_contract_version`, `enabled_versions`, `remove_group`, `next_contract_version_for`, `current_contract_version`, `current_contract_hash` in struct ContractPackage - in enum StoredValue removed variant Transfer (replaced with LegacyTransfer) - - -## [Unreleased] (node 1.6) +## [Unreleased] (node 1.5.4) ### Changed -* Remove filesystem I/O functionality from the `std` feature, and gated this behind a new feature `std-fs-io` which depends upon `std`. - +- Remove filesystem I/O functionality from the `std` feature, and gated this behind a new feature `std-fs-io` which depends upon `std`. ## 4.0.1 ### Added -* Add a new `SyncHandling` enum, which allows a node to opt out of historical sync. + +- Add a new `SyncHandling` enum, which allows a node to opt out of historical sync. ### Changed -* Update `k256` to version 0.13.1. + +- Update `k256` to version 0.13.1. ### Removed -* Remove `ExecutionResult::successful_transfers`. -### Security -* Update `ed25519-dalek` to version 2.0.0 as mitigation for [RUSTSEC-2022-0093](https://rustsec.org/advisories/RUSTSEC-2022-0093) +- Remove `ExecutionResult::successful_transfers`. +### Security +- Update `ed25519-dalek` to version 2.0.0 as mitigation for [RUSTSEC-2022-0093](https://rustsec.org/advisories/RUSTSEC-2022-0093) ## 3.0.0 ### Added -* Add new `bytesrepr::Error::NotRepresentable` error variant that represents values that are not representable by the serialization format. -* Add new `Key::Unbond` key variant under which the new unbonding information (to support redelegation) is written. -* Add new `Key::ChainspecRegistry` key variant under which the `ChainspecRegistry` is written. -* Add new `Key::ChecksumRegistry` key variant under which a registry of checksums for a given block is written. There are two checksums in the registry, one for the execution results and the other for the approvals of all deploys in the block. -* Add new `StoredValue::Unbonding` variant to support redelegating. -* Add a new type `WithdrawPurses` which is meant to represent `UnbondingPurses` as they exist in current live networks. + +- Add new `bytesrepr::Error::NotRepresentable` error variant that represents values that are not representable by the serialization format. +- Add new `Key::Unbond` key variant under which the new unbonding information (to support redelegation) is written. +- Add new `Key::ChainspecRegistry` key variant under which the `ChainspecRegistry` is written. +- Add new `Key::ChecksumRegistry` key variant under which a registry of checksums for a given block is written. There are two checksums in the registry, one for the execution results and the other for the approvals of all deploys in the block. +- Add new `StoredValue::Unbonding` variant to support redelegating. +- Add a new type `WithdrawPurses` which is meant to represent `UnbondingPurses` as they exist in current live networks. ### Changed -* Extend `UnbondingPurse` to take a new field `new_validator` which represents the validator to whom tokens will be re-delegated. -* Increase `DICTIONARY_ITEM_KEY_MAX_LENGTH` to 128. -* Change prefix of formatted string representation of `ContractPackageHash` from "contract-package-wasm" to "contract-package-". Parsing from the old format is still supported. -* Apply `#[non_exhaustive]` to error enums. -* Change Debug output of `DeployHash` to hex-encoded string rather than a list of integers. -### Fixed -* Fix some integer casts, where failure is now detected and reported via new error variant `NotRepresentable`. +- Extend `UnbondingPurse` to take a new field `new_validator` which represents the validator to whom tokens will be re-delegated. +- Increase `DICTIONARY_ITEM_KEY_MAX_LENGTH` to 128. +- Change prefix of formatted string representation of `ContractPackageHash` from "contract-package-wasm" to "contract-package-". Parsing from the old format is still supported. +- Apply `#[non_exhaustive]` to error enums. +- Change Debug output of `DeployHash` to hex-encoded string rather than a list of integers. +### Fixed +- Fix some integer casts, where failure is now detected and reported via new error variant `NotRepresentable`. ## 2.0.0 ### Fixed -* Republish v1.6.0 as v2.0.0 due to missed breaking change in API (addition of new variant to `Key`). - +- Republish v1.6.0 as v2.0.0 due to missed breaking change in API (addition of new variant to `Key`). ## 1.6.0 [YANKED] ### Added -* Extend asymmetric key functionality, available via feature `std` (moved from `casper-nodes` crate). -* Provide `Timestamp` and `TimeDiff` types for time operations, with extended functionality available via feature `std` (moved from `casper-nodes` crate). -* Provide test-only functionality, in particular a seedable RNG `TestRng` which outputs its seed on test failure. Available via a new feature `testing`. -* Add new `Key::EraSummary` key variant under which the era summary info is written on each switch block execution. -### Deprecated -* Deprecate `gens` feature: its functionality is included in the new `testing` feature. +- Extend asymmetric key functionality, available via feature `std` (moved from `casper-nodes` crate). +- Provide `Timestamp` and `TimeDiff` types for time operations, with extended functionality available via feature `std` (moved from `casper-nodes` crate). +- Provide test-only functionality, in particular a seedable RNG `TestRng` which outputs its seed on test failure. Available via a new feature `testing`. +- Add new `Key::EraSummary` key variant under which the era summary info is written on each switch block execution. +### Deprecated +- Deprecate `gens` feature: its functionality is included in the new `testing` feature. ## 1.5.0 ### Added -* Provide types and functionality to support improved access control inside execution engine. -* Provide `CLTyped` impl for `ContractPackage` to allow it to be passed into contracts. -### Fixed -* Limit parsing of CLTyped objects to a maximum of 50 types deep. +- Provide types and functionality to support improved access control inside execution engine. +- Provide `CLTyped` impl for `ContractPackage` to allow it to be passed into contracts. +### Fixed +- Limit parsing of CLTyped objects to a maximum of 50 types deep. ## 1.4.6 - 2021-12-29 ### Changed -* Disable checksummed-hex encoding, but leave checksummed-hex decoding in place. - +- Disable checksummed-hex encoding, but leave checksummed-hex decoding in place. ## 1.4.5 - 2021-12-06 ### Added -* Add function to `auction::MintProvider` trait to support minting into an existing purse. -### Changed -* Change checksummed hex implementation to use 32 byte rather than 64 byte blake2b digests. +- Add function to `auction::MintProvider` trait to support minting into an existing purse. +### Changed +- Change checksummed hex implementation to use 32 byte rather than 64 byte blake2b digests. ## [1.4.4] - 2021-11-18 ### Fixed -* Revert the accidental change to the `std` feature causing a broken build when this feature is enabled. - +- Revert the accidental change to the `std` feature causing a broken build when this feature is enabled. ## [1.4.3] - 2021-11-17 [YANKED] - - ## [1.4.2] - 2021-11-13 [YANKED] ### Added -* Add checksummed hex encoding following a scheme similar to [EIP-55](https://eips.ethereum.org/EIPS/eip-55). - +- Add checksummed hex encoding following a scheme similar to [EIP-55](https://eips.ethereum.org/EIPS/eip-55). ## [1.4.1] - 2021-10-23 No changes. - - ## [1.4.0] - 2021-10-21 [YANKED] ### Added -* Add `json-schema` feature, disabled by default, to enable many types to be used to produce JSON-schema data. -* Add implicit `datasize` feature, disabled by default, to enable many types to derive the `DataSize` trait. -* Add `StoredValue` types to this crate. + +- Add `json-schema` feature, disabled by default, to enable many types to be used to produce JSON-schema data. +- Add implicit `datasize` feature, disabled by default, to enable many types to derive the `DataSize` trait. +- Add `StoredValue` types to this crate. ### Changed -* Support building and testing using stable Rust. -* Allow longer hex string to be presented in `json` files. Current maximum is increased from 100 to 150 characters. -* Improve documentation and `Debug` impls for `ApiError`. -### Deprecated -* Feature `std` is deprecated as it is now a no-op, since there is no benefit to linking the std lib via this crate. +- Support building and testing using stable Rust. +- Allow longer hex string to be presented in `json` files. Current maximum is increased from 100 to 150 characters. +- Improve documentation and `Debug` impls for `ApiError`. +### Deprecated +- Feature `std` is deprecated as it is now a no-op, since there is no benefit to linking the std lib via this crate. ## [1.3.0] - 2021-07-19 ### Changed -* Restrict summarization when JSON pretty-printing to contiguous long hex strings. -* Update pinned version of Rust to `nightly-2021-06-17`. -### Removed -* Remove ability to clone `SecretKey`s. +- Restrict summarization when JSON pretty-printing to contiguous long hex strings. +- Update pinned version of Rust to `nightly-2021-06-17`. +### Removed +- Remove ability to clone `SecretKey`s. ## [1.2.0] - 2021-05-27 ### Changed -* Change to Apache 2.0 license. -* Return a `Result` from the constructor of `SecretKey` rather than potentially panicking. -* Improve `Key` error reporting and tests. -### Fixed -* Fix `Key` deserialization. +- Change to Apache 2.0 license. +- Return a `Result` from the constructor of `SecretKey` rather than potentially panicking. +- Improve `Key` error reporting and tests. +### Fixed +- Fix `Key` deserialization. ## [1.1.1] - 2021-04-19 No changes. - - ## [1.1.0] - 2021-04-13 [YANKED] No changes. - - ## [1.0.1] - 2021-04-08 No changes. - - ## [1.0.0] - 2021-03-30 ### Added -* Initial release of types for use by software compatible with Casper mainnet. - +- Initial release of types for use by software compatible with Casper mainnet. [Keep a Changelog]: https://keepachangelog.com/en/1.0.0 [unreleased]: https://github.com/casper-network/casper-node/compare/24fc4027a...dev diff --git a/types/src/chainspec.rs b/types/src/chainspec.rs index a723271e95..315a1ebd97 100644 --- a/types/src/chainspec.rs +++ b/types/src/chainspec.rs @@ -75,7 +75,7 @@ pub use vacancy_config::VacancyConfig; pub use vm_config::{ AuctionCosts, BrTableCost, ChainspecRegistry, ControlFlowCosts, HandlePaymentCosts, HostFunction, HostFunctionCost, HostFunctionCosts, MessageLimits, MintCosts, OpcodeCosts, - StandardPaymentCosts, StorageCosts, SystemConfig, WasmConfig, + StandardPaymentCosts, StorageCosts, SystemConfig, WasmConfig, WasmV1Config, DEFAULT_HOST_FUNCTION_NEW_DICTIONARY, }; #[cfg(any(feature = "testing", test))] @@ -90,9 +90,9 @@ pub use vm_config::{ DEFAULT_CONTROL_FLOW_RETURN_OPCODE, DEFAULT_CONTROL_FLOW_SELECT_OPCODE, DEFAULT_CONVERSION_COST, DEFAULT_CURRENT_MEMORY_COST, DEFAULT_DELEGATE_COST, DEFAULT_DIV_COST, DEFAULT_GLOBAL_COST, DEFAULT_GROW_MEMORY_COST, DEFAULT_INTEGER_COMPARISON_COST, - DEFAULT_LOAD_COST, DEFAULT_LOCAL_COST, DEFAULT_MAX_STACK_HEIGHT, DEFAULT_MUL_COST, - DEFAULT_NEW_DICTIONARY_COST, DEFAULT_NOP_COST, DEFAULT_STORE_COST, DEFAULT_TRANSFER_COST, - DEFAULT_UNREACHABLE_COST, DEFAULT_WASM_MAX_MEMORY, + DEFAULT_LOAD_COST, DEFAULT_LOCAL_COST, DEFAULT_MUL_COST, DEFAULT_NEW_DICTIONARY_COST, + DEFAULT_NOP_COST, DEFAULT_STORE_COST, DEFAULT_TRANSFER_COST, DEFAULT_UNREACHABLE_COST, + DEFAULT_V1_MAX_STACK_HEIGHT, DEFAULT_V1_WASM_MAX_MEMORY, }; /// A collection of configuration settings describing the state of the system at genesis and after @@ -132,6 +132,9 @@ pub struct Chainspec { /// Vacancy behavior config #[serde(rename = "vacancy")] pub vacancy_config: VacancyConfig, + + /// Storage costs. + pub storage_costs: StorageCosts, } impl Chainspec { @@ -282,6 +285,7 @@ impl Chainspec { wasm_config, system_costs_config, vacancy_config, + storage_costs: rng.gen(), } } @@ -319,7 +323,8 @@ impl ToBytes for Chainspec { self.transaction_config.write_bytes(writer)?; self.wasm_config.write_bytes(writer)?; self.system_costs_config.write_bytes(writer)?; - self.vacancy_config.write_bytes(writer) + self.vacancy_config.write_bytes(writer)?; + self.storage_costs.write_bytes(writer) } fn to_bytes(&self) -> Result, bytesrepr::Error> { @@ -337,6 +342,7 @@ impl ToBytes for Chainspec { + self.wasm_config.serialized_length() + self.system_costs_config.serialized_length() + self.vacancy_config.serialized_length() + + self.storage_costs.serialized_length() } } @@ -350,6 +356,7 @@ impl FromBytes for Chainspec { let (wasm_config, remainder) = WasmConfig::from_bytes(remainder)?; let (system_costs_config, remainder) = SystemConfig::from_bytes(remainder)?; let (vacancy_config, remainder) = VacancyConfig::from_bytes(remainder)?; + let (storage_costs, remainder) = FromBytes::from_bytes(remainder)?; let chainspec = Chainspec { protocol_config, network_config, @@ -359,6 +366,7 @@ impl FromBytes for Chainspec { wasm_config, system_costs_config, vacancy_config, + storage_costs, }; Ok((chainspec, remainder)) } diff --git a/types/src/chainspec/genesis_config.rs b/types/src/chainspec/genesis_config.rs index c694939d80..efe48eac5c 100644 --- a/types/src/chainspec/genesis_config.rs +++ b/types/src/chainspec/genesis_config.rs @@ -16,6 +16,8 @@ use crate::{ SystemConfig, WasmConfig, }; +use super::StorageCosts; + /// Default number of validator slots. pub const DEFAULT_VALIDATOR_SLOTS: u32 = 5; /// Default auction delay. @@ -54,6 +56,7 @@ pub struct GenesisConfig { genesis_timestamp_millis: u64, gas_hold_balance_handling: HoldBalanceHandling, gas_hold_interval_millis: u64, + storage_costs: StorageCosts, } impl GenesisConfig { @@ -78,6 +81,7 @@ impl GenesisConfig { genesis_timestamp_millis: u64, gas_hold_balance_handling: HoldBalanceHandling, gas_hold_interval_millis: u64, + storage_costs: StorageCosts, ) -> GenesisConfig { GenesisConfig { accounts, @@ -91,6 +95,7 @@ impl GenesisConfig { genesis_timestamp_millis, gas_hold_balance_handling, gas_hold_interval_millis, + storage_costs, } } @@ -209,6 +214,7 @@ impl Distribution for Standard { let genesis_timestamp_millis = rng.gen(); let gas_hold_balance_handling = rng.gen(); let gas_hold_interval_millis = rng.gen(); + let storage_costs = rng.gen(); GenesisConfig { accounts, @@ -222,6 +228,7 @@ impl Distribution for Standard { genesis_timestamp_millis, gas_hold_balance_handling, gas_hold_interval_millis, + storage_costs, } } } @@ -243,6 +250,7 @@ pub struct GenesisConfigBuilder { genesis_timestamp_millis: Option, gas_hold_balance_handling: Option, gas_hold_interval_millis: Option, + storage_costs: Option, } impl GenesisConfigBuilder { @@ -320,6 +328,12 @@ impl GenesisConfigBuilder { self } + /// Sets the storage_costs handling. + pub fn with_storage_costs(mut self, storage_costs: StorageCosts) -> Self { + self.storage_costs = Some(storage_costs); + self + } + /// Builds a new [`GenesisConfig`] object. pub fn build(self) -> GenesisConfig { GenesisConfig { @@ -344,6 +358,7 @@ impl GenesisConfigBuilder { gas_hold_interval_millis: self .gas_hold_interval_millis .unwrap_or(DEFAULT_GAS_HOLD_INTERVAL_MILLIS), + storage_costs: self.storage_costs.unwrap_or_default(), } } } @@ -357,6 +372,7 @@ impl From<&Chainspec> for GenesisConfig { .map_or(0, |timestamp| timestamp.millis()); let gas_hold_interval_millis = chainspec.core_config.gas_hold_interval.millis(); let gas_hold_balance_handling = chainspec.core_config.gas_hold_balance_handling; + let storage_costs = chainspec.storage_costs; // TODO: maybe construct this instead of accreting the values //GenesisConfigBuilder::new(account,..) @@ -372,6 +388,7 @@ impl From<&Chainspec> for GenesisConfig { .with_genesis_timestamp_millis(genesis_timestamp_millis) .with_gas_hold_balance_handling(gas_hold_balance_handling) .with_gas_hold_interval_millis(gas_hold_interval_millis) + .with_storage_costs(storage_costs) .build() } } diff --git a/types/src/chainspec/vm_config.rs b/types/src/chainspec/vm_config.rs index 0d1bde8821..52c76dc6a1 100644 --- a/types/src/chainspec/vm_config.rs +++ b/types/src/chainspec/vm_config.rs @@ -9,6 +9,7 @@ mod standard_payment_costs; mod storage_costs; mod system_config; mod wasm_config; +mod wasm_v1_config; pub use auction_costs::AuctionCosts; #[cfg(any(feature = "testing", test))] @@ -43,5 +44,6 @@ pub use standard_payment_costs::StandardPaymentCosts; pub use storage_costs::StorageCosts; pub use system_config::SystemConfig; pub use wasm_config::WasmConfig; +pub use wasm_v1_config::WasmV1Config; #[cfg(any(feature = "testing", test))] -pub use wasm_config::{DEFAULT_MAX_STACK_HEIGHT, DEFAULT_WASM_MAX_MEMORY}; +pub use wasm_v1_config::{DEFAULT_V1_MAX_STACK_HEIGHT, DEFAULT_V1_WASM_MAX_MEMORY}; diff --git a/types/src/chainspec/vm_config/storage_costs.rs b/types/src/chainspec/vm_config/storage_costs.rs index e12098f894..ea12e4999c 100644 --- a/types/src/chainspec/vm_config/storage_costs.rs +++ b/types/src/chainspec/vm_config/storage_costs.rs @@ -99,6 +99,7 @@ pub mod tests { use crate::U512; use super::*; + use proptest::prelude::*; const SMALL_WEIGHT: usize = 123456789; const LARGE_WEIGHT: usize = usize::max_value(); @@ -122,22 +123,24 @@ pub mod tests { let expected_cost = U512::from(DEFAULT_GAS_PER_BYTE_COST) * U512::from(LARGE_WEIGHT); assert_eq!(cost, Gas::new(expected_cost)); } + + proptest! { + #[test] + fn bytesrepr_roundtrip(storage_costs in super::gens::storage_costs_arb()) { + bytesrepr::test_serialization_roundtrip(&storage_costs); + } + } } #[doc(hidden)] -#[cfg(any(feature = "gens", test))] +#[cfg(test)] pub mod gens { - use proptest::{num, prop_compose}; + use crate::gens::example_u32_arb; use super::StorageCosts; + use proptest::prelude::*; - prop_compose! { - pub fn storage_costs_arb()( - gas_per_byte in num::u32::ANY, - ) -> StorageCosts { - StorageCosts { - gas_per_byte, - } - } + pub(super) fn storage_costs_arb() -> impl Strategy { + example_u32_arb().prop_map(StorageCosts::new) } } diff --git a/types/src/chainspec/vm_config/wasm_config.rs b/types/src/chainspec/vm_config/wasm_config.rs index fe432b1da6..e273a6c7b7 100644 --- a/types/src/chainspec/vm_config/wasm_config.rs +++ b/types/src/chainspec/vm_config/wasm_config.rs @@ -10,131 +10,73 @@ use serde::{Deserialize, Serialize}; use crate::{ bytesrepr::{self, FromBytes, ToBytes}, - chainspec::vm_config::{HostFunctionCosts, MessageLimits, OpcodeCosts, StorageCosts}, + chainspec::vm_config::MessageLimits, }; -/// Default maximum number of pages of the Wasm memory. -pub const DEFAULT_WASM_MAX_MEMORY: u32 = 64; -/// Default maximum stack height. -pub const DEFAULT_MAX_STACK_HEIGHT: u32 = 500; +use super::wasm_v1_config::WasmV1Config; /// Configuration of the Wasm execution environment. /// /// This structure contains various Wasm execution configuration options, such as memory limits, /// stack limits and costs. -#[derive(Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Debug)] +#[derive(Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize, Debug)] #[cfg_attr(feature = "datasize", derive(DataSize))] #[serde(deny_unknown_fields)] pub struct WasmConfig { - /// Maximum amount of heap memory (represented in 64kB pages) each contract can use. - pub max_memory: u32, - /// Max stack height (native WebAssembly stack limiter). - pub max_stack_height: u32, - /// Wasm opcode costs table. - opcode_costs: OpcodeCosts, - /// Storage costs. - storage_costs: StorageCosts, - /// Host function costs table. - host_function_costs: HostFunctionCosts, /// Messages limits. messages_limits: MessageLimits, + /// Configuration for wasms in v1 execution engine. + v1: WasmV1Config, } impl WasmConfig { /// Creates new Wasm config. - pub const fn new( - max_memory: u32, - max_stack_height: u32, - opcode_costs: OpcodeCosts, - storage_costs: StorageCosts, - host_function_costs: HostFunctionCosts, - messages_limits: MessageLimits, - ) -> Self { + pub const fn new(messages_limits: MessageLimits, v1: WasmV1Config) -> Self { Self { - max_memory, - max_stack_height, - opcode_costs, - storage_costs, - host_function_costs, messages_limits, + v1, } } - /// Returns opcode costs. - pub fn opcode_costs(&self) -> OpcodeCosts { - self.opcode_costs - } - - /// Returns storage costs. - pub fn storage_costs(&self) -> StorageCosts { - self.storage_costs - } - - /// Returns host function costs and consumes this object. - pub fn take_host_function_costs(self) -> HostFunctionCosts { - self.host_function_costs - } - /// Returns the limits config for messages. pub fn messages_limits(&self) -> MessageLimits { self.messages_limits } -} -impl Default for WasmConfig { - fn default() -> Self { - Self { - max_memory: DEFAULT_WASM_MAX_MEMORY, - max_stack_height: DEFAULT_MAX_STACK_HEIGHT, - opcode_costs: OpcodeCosts::default(), - storage_costs: StorageCosts::default(), - host_function_costs: HostFunctionCosts::default(), - messages_limits: MessageLimits::default(), - } + /// Returns the config for v1 wasms. + pub fn v1(&self) -> &WasmV1Config { + &self.v1 + } + + /// Returns mutable v1 reference + #[cfg(any(feature = "testing", test))] + pub fn v1_mut(&mut self) -> &mut WasmV1Config { + &mut self.v1 } } impl ToBytes for WasmConfig { fn to_bytes(&self) -> Result, bytesrepr::Error> { let mut ret = bytesrepr::unchecked_allocate_buffer(self); - - ret.append(&mut self.max_memory.to_bytes()?); - ret.append(&mut self.max_stack_height.to_bytes()?); - ret.append(&mut self.opcode_costs.to_bytes()?); - ret.append(&mut self.storage_costs.to_bytes()?); - ret.append(&mut self.host_function_costs.to_bytes()?); ret.append(&mut self.messages_limits.to_bytes()?); - + ret.append(&mut self.v1.to_bytes()?); Ok(ret) } fn serialized_length(&self) -> usize { - self.max_memory.serialized_length() - + self.max_stack_height.serialized_length() - + self.opcode_costs.serialized_length() - + self.storage_costs.serialized_length() - + self.host_function_costs.serialized_length() - + self.messages_limits.serialized_length() + self.messages_limits.serialized_length() + self.v1.serialized_length() } } impl FromBytes for WasmConfig { fn from_bytes(bytes: &[u8]) -> Result<(Self, &[u8]), bytesrepr::Error> { - let (max_memory, rem) = FromBytes::from_bytes(bytes)?; - let (max_stack_height, rem) = FromBytes::from_bytes(rem)?; - let (opcode_costs, rem) = FromBytes::from_bytes(rem)?; - let (storage_costs, rem) = FromBytes::from_bytes(rem)?; - let (host_function_costs, rem) = FromBytes::from_bytes(rem)?; - let (messages_limits, rem) = FromBytes::from_bytes(rem)?; + let (messages_limits, rem) = FromBytes::from_bytes(bytes)?; + let (v1, rem) = FromBytes::from_bytes(rem)?; Ok(( WasmConfig { - max_memory, - max_stack_height, - opcode_costs, - storage_costs, - host_function_costs, messages_limits, + v1, }, rem, )) @@ -145,12 +87,20 @@ impl FromBytes for WasmConfig { impl Distribution for Standard { fn sample(&self, rng: &mut R) -> WasmConfig { WasmConfig { - max_memory: rng.gen(), - max_stack_height: rng.gen(), - opcode_costs: rng.gen(), - storage_costs: rng.gen(), - host_function_costs: rng.gen(), messages_limits: rng.gen(), + v1: rng.gen(), + } + } +} + +#[cfg(test)] +pub mod tests { + use super::*; + use proptest::prelude::*; + proptest! { + #[test] + fn bytesrepr_roundtrip(wasm_config in super::gens::wasm_config_arb()) { + bytesrepr::test_serialization_roundtrip(&wasm_config); } } } @@ -158,33 +108,23 @@ impl Distribution for Standard { #[doc(hidden)] #[cfg(any(feature = "gens", test))] pub mod gens { - use proptest::{num, prop_compose}; + use proptest::prop_compose; use crate::{ chainspec::vm_config::{ - host_function_costs::gens::host_function_costs_arb, - message_limits::gens::message_limits_arb, opcode_costs::gens::opcode_costs_arb, - storage_costs::gens::storage_costs_arb, + message_limits::gens::message_limits_arb, wasm_v1_config::gens::wasm_v1_config_arb, }, WasmConfig, }; prop_compose! { pub fn wasm_config_arb() ( - max_memory in num::u32::ANY, - max_stack_height in num::u32::ANY, - opcode_costs in opcode_costs_arb(), - storage_costs in storage_costs_arb(), - host_function_costs in host_function_costs_arb(), + v1 in wasm_v1_config_arb(), messages_limits in message_limits_arb(), ) -> WasmConfig { WasmConfig { - max_memory, - max_stack_height, - opcode_costs, - storage_costs, - host_function_costs, messages_limits, + v1, } } } diff --git a/types/src/chainspec/vm_config/wasm_v1_config.rs b/types/src/chainspec/vm_config/wasm_v1_config.rs new file mode 100644 index 0000000000..019a9e4631 --- /dev/null +++ b/types/src/chainspec/vm_config/wasm_v1_config.rs @@ -0,0 +1,174 @@ +use crate::{ + bytesrepr::{self, FromBytes, ToBytes}, + chainspec::vm_config::{HostFunctionCosts, OpcodeCosts}, +}; +#[cfg(feature = "datasize")] +use datasize::DataSize; +#[cfg(any(feature = "testing", test))] +use rand::{ + distributions::{Distribution, Standard}, + Rng, +}; +use serde::{Deserialize, Serialize}; + +/// Default maximum number of pages of the Wasm memory. +pub const DEFAULT_V1_WASM_MAX_MEMORY: u32 = 64; +/// Default maximum stack height. +pub const DEFAULT_V1_MAX_STACK_HEIGHT: u32 = 500; + +/// Configuration of the Wasm execution environment for V1 execution machine. +/// +/// This structure contains various Wasm execution configuration options, such as memory limits, +/// stack limits and costs. +#[derive(Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Debug)] +#[cfg_attr(feature = "datasize", derive(DataSize))] +#[serde(deny_unknown_fields)] +pub struct WasmV1Config { + /// Maximum amount of heap memory (represented in 64kB pages) each contract can use. + max_memory: u32, + /// Max stack height (native WebAssembly stack limiter). + max_stack_height: u32, + /// Wasm opcode costs table. + opcode_costs: OpcodeCosts, + /// Host function costs table. + host_function_costs: HostFunctionCosts, +} + +impl WasmV1Config { + /// ctor + pub fn new( + max_memory: u32, + max_stack_height: u32, + opcode_costs: OpcodeCosts, + host_function_costs: HostFunctionCosts, + ) -> Self { + WasmV1Config { + max_memory, + max_stack_height, + opcode_costs, + host_function_costs, + } + } + + /// Returns opcode costs. + pub fn opcode_costs(&self) -> OpcodeCosts { + self.opcode_costs + } + + /// Returns host function costs and consumes this object. + pub fn take_host_function_costs(self) -> HostFunctionCosts { + self.host_function_costs + } + + /// Returns max_memory. + pub fn max_memory(&self) -> u32 { + self.max_memory + } + + /// Returns mutable max_memory reference + #[cfg(any(feature = "testing", test))] + pub fn max_memory_mut(&mut self) -> &mut u32 { + &mut self.max_memory + } + + /// Returns mutable max_stack_height reference + #[cfg(any(feature = "testing", test))] + pub fn max_stack_height_mut(&mut self) -> &mut u32 { + &mut self.max_stack_height + } + + /// Returns max_stack_height. + pub fn max_stack_height(&self) -> u32 { + self.max_stack_height + } +} + +impl Default for WasmV1Config { + fn default() -> Self { + Self { + max_memory: DEFAULT_V1_WASM_MAX_MEMORY, + max_stack_height: DEFAULT_V1_MAX_STACK_HEIGHT, + opcode_costs: OpcodeCosts::default(), + host_function_costs: HostFunctionCosts::default(), + } + } +} + +impl ToBytes for WasmV1Config { + fn to_bytes(&self) -> Result, bytesrepr::Error> { + let mut ret = bytesrepr::unchecked_allocate_buffer(self); + ret.append(&mut self.max_memory.to_bytes()?); + ret.append(&mut self.max_stack_height.to_bytes()?); + ret.append(&mut self.opcode_costs.to_bytes()?); + ret.append(&mut self.host_function_costs.to_bytes()?); + Ok(ret) + } + + fn serialized_length(&self) -> usize { + self.max_memory.serialized_length() + + self.max_stack_height.serialized_length() + + self.opcode_costs.serialized_length() + + self.host_function_costs.serialized_length() + } +} + +impl FromBytes for WasmV1Config { + fn from_bytes(bytes: &[u8]) -> Result<(Self, &[u8]), bytesrepr::Error> { + let (max_memory, rem) = FromBytes::from_bytes(bytes)?; + let (max_stack_height, rem) = FromBytes::from_bytes(rem)?; + let (opcode_costs, rem) = FromBytes::from_bytes(rem)?; + let (host_function_costs, rem) = FromBytes::from_bytes(rem)?; + Ok(( + WasmV1Config { + max_memory, + max_stack_height, + opcode_costs, + host_function_costs, + }, + rem, + )) + } +} + +#[cfg(any(feature = "testing", test))] +impl Distribution for Standard { + fn sample(&self, rng: &mut R) -> WasmV1Config { + WasmV1Config { + max_memory: rng.gen(), + max_stack_height: rng.gen(), + opcode_costs: rng.gen(), + host_function_costs: rng.gen(), + } + } +} + +#[doc(hidden)] +#[cfg(any(feature = "gens", test))] +pub mod gens { + use crate::{ + chainspec::vm_config::{ + host_function_costs::gens::host_function_costs_arb, + opcode_costs::gens::opcode_costs_arb, + }, + gens::example_u32_arb, + }; + use proptest::prop_compose; + + use super::WasmV1Config; + + prop_compose! { + pub fn wasm_v1_config_arb() ( + max_memory in example_u32_arb(), + max_stack_height in example_u32_arb(), + opcode_costs in opcode_costs_arb(), + host_function_costs in host_function_costs_arb(), + ) -> WasmV1Config { + WasmV1Config { + max_memory, + max_stack_height, + opcode_costs, + host_function_costs, + } + } + } +} diff --git a/types/src/gens.rs b/types/src/gens.rs index 1d109f7017..420a0b3e7d 100644 --- a/types/src/gens.rs +++ b/types/src/gens.rs @@ -1191,3 +1191,6 @@ pub fn transaction_arb() -> impl Strategy { pub fn legal_transaction_arb() -> impl Strategy { (legal_v1_transaction_arb()).prop_map(Transaction::V1) } +pub fn example_u32_arb() -> impl Strategy { + prop_oneof![Just(0), Just(1), Just(u32::MAX / 2), Just(u32::MAX)] +} diff --git a/types/src/lib.rs b/types/src/lib.rs index 13cf3da49b..e7ebb75feb 100644 --- a/types/src/lib.rs +++ b/types/src/lib.rs @@ -131,7 +131,7 @@ pub use chainspec::{ MessageLimits, MintCosts, NetworkConfig, NextUpgrade, OpcodeCosts, PricingHandling, ProtocolConfig, ProtocolUpgradeConfig, RefundHandling, StandardPaymentCosts, StorageCosts, SystemConfig, TransactionConfig, TransactionLimitsDefinition, TransactionV1Config, - VacancyConfig, ValidatorConfig, WasmConfig, DEFAULT_GAS_HOLD_INTERVAL, + VacancyConfig, ValidatorConfig, WasmConfig, WasmV1Config, DEFAULT_GAS_HOLD_INTERVAL, DEFAULT_HOST_FUNCTION_NEW_DICTIONARY, DEFAULT_MINIMUM_BID_AMOUNT, DEFAULT_REFUND_HANDLING, }; #[cfg(any(all(feature = "std", feature = "testing"), test))] @@ -147,9 +147,10 @@ pub use chainspec::{ DEFAULT_CONVERSION_COST, DEFAULT_CURRENT_MEMORY_COST, DEFAULT_DELEGATE_COST, DEFAULT_DIV_COST, DEFAULT_FEE_HANDLING, DEFAULT_GAS_HOLD_BALANCE_HANDLING, DEFAULT_GLOBAL_COST, DEFAULT_GROW_MEMORY_COST, DEFAULT_INTEGER_COMPARISON_COST, DEFAULT_LARGE_TRANSACTION_GAS_LIMIT, - DEFAULT_LOAD_COST, DEFAULT_LOCAL_COST, DEFAULT_MAX_PAYMENT_MOTES, DEFAULT_MAX_STACK_HEIGHT, - DEFAULT_MIN_TRANSFER_MOTES, DEFAULT_MUL_COST, DEFAULT_NEW_DICTIONARY_COST, DEFAULT_NOP_COST, - DEFAULT_STORE_COST, DEFAULT_TRANSFER_COST, DEFAULT_UNREACHABLE_COST, DEFAULT_WASM_MAX_MEMORY, + DEFAULT_LOAD_COST, DEFAULT_LOCAL_COST, DEFAULT_MAX_PAYMENT_MOTES, DEFAULT_MIN_TRANSFER_MOTES, + DEFAULT_MUL_COST, DEFAULT_NEW_DICTIONARY_COST, DEFAULT_NOP_COST, DEFAULT_STORE_COST, + DEFAULT_TRANSFER_COST, DEFAULT_UNREACHABLE_COST, DEFAULT_V1_MAX_STACK_HEIGHT, + DEFAULT_V1_WASM_MAX_MEMORY, }; pub use contract_wasm::{ContractWasm, ContractWasmHash}; #[doc(inline)] diff --git a/types/src/transaction/transaction_v1/transaction_v1_body.rs b/types/src/transaction/transaction_v1/transaction_v1_body.rs deleted file mode 100644 index e69de29bb2..0000000000