From 8fbf38794fc79cc98fe71a6b8bf054bc335a87b0 Mon Sep 17 00:00:00 2001 From: Jakub Zajkowski Date: Mon, 16 Dec 2024 12:38:56 +0100 Subject: [PATCH] Code fixes --- .../components/transaction_buffer/tests.rs | 17 ++- .../main_reactor/tests/transactions.rs | 3 +- node/src/testing.rs | 2 + node/src/types/appendable_block.rs | 3 +- .../src/types/transaction/meta_transaction.rs | 10 +- .../{transaction_lane.rs => lane_id.rs} | 0 .../meta_transaction/meta_deploy.rs | 24 ++-- .../meta_transaction/meta_transaction_v1.rs | 14 +- node/src/utils/chain_specification.rs | 16 +-- node/src/utils/specimen.rs | 3 +- types/src/chainspec.rs | 2 +- types/src/chainspec/transaction_config.rs | 2 +- .../transaction_v1_config.rs | 134 +++++++++--------- types/src/lib.rs | 2 +- 14 files changed, 117 insertions(+), 115 deletions(-) rename node/src/types/transaction/meta_transaction/{transaction_lane.rs => lane_id.rs} (100%) diff --git a/node/src/components/transaction_buffer/tests.rs b/node/src/components/transaction_buffer/tests.rs index 42260cad9b..17926637a3 100644 --- a/node/src/components/transaction_buffer/tests.rs +++ b/node/src/components/transaction_buffer/tests.rs @@ -3,21 +3,20 @@ use std::iter; use prometheus::Registry; use rand::{seq::SliceRandom, Rng}; -use casper_types::{ - testing::TestRng, Deploy, EraId, SecretKey, TestBlockBuilder, TimeDiff, Transaction, - TransactionConfig, TransactionLanesDefinition, TransactionV1Config, - DEFAULT_LARGE_TRANSACTION_GAS_LIMIT, -}; - use super::*; use crate::{ effect::announcements::TransactionBufferAnnouncement::{self, TransactionsExpired}, reactor::{EventQueueHandle, QueueKind, Scheduler}, + testing::LARGE_WASM_LANE_ID, types::{transaction::transaction_v1_builder::TransactionV1Builder, FinalizedBlock}, utils, }; +use casper_types::{ + testing::TestRng, Deploy, EraId, SecretKey, TestBlockBuilder, TimeDiff, Transaction, + TransactionConfig, TransactionLaneDefinition, TransactionV1Config, + DEFAULT_LARGE_TRANSACTION_GAS_LIMIT, +}; -const LARGE_WASM_LANE_ID: u8 = 3; const ERA_ONE: EraId = EraId::new(1u64); const GAS_PRICE_TOLERANCE: u8 = 1; const DEFAULT_MINIMUM_GAS_PRICE: u8 = 1; @@ -1122,10 +1121,10 @@ fn make_test_chainspec(max_standard_count: u64, max_mint_count: u64) -> Arc> = Lazy::new(|| { Arc::new(SecretKey::ed25519_from_bytes([0xAA; SecretKey::ED25519_LENGTH]).unwrap()) }); diff --git a/node/src/testing.rs b/node/src/testing.rs index 42a9ea5f59..d3ada553d3 100644 --- a/node/src/testing.rs +++ b/node/src/testing.rs @@ -73,6 +73,8 @@ const TEST_PORT_RANGE: Range = 60001..60998; /// Random offset + stride for port generation. const TEST_PORT_STRIDE: u16 = 29; +pub(crate) const LARGE_WASM_LANE_ID: u8 = 3; + macro_rules! map { () => { std::collections::BTreeMap::new() }; ( $first_key:expr => $first_value:expr $( , $key:expr => $value:expr )* $(,)? ) => {{ diff --git a/node/src/types/appendable_block.rs b/node/src/types/appendable_block.rs index 0f83a2463e..88acc59e3e 100644 --- a/node/src/types/appendable_block.rs +++ b/node/src/types/appendable_block.rs @@ -249,10 +249,11 @@ impl Display for AppendableBlock { mod tests { use casper_types::{testing::TestRng, SingleBlockRewardedSignatures, TimeDiff}; + use crate::testing::LARGE_WASM_LANE_ID; + use super::*; use std::collections::HashSet; - const LARGE_WASM_LANE_ID: u8 = 3; impl AppendableBlock { pub(crate) fn transaction_hashes(&self) -> HashSet { self.transactions.keys().copied().collect() diff --git a/node/src/types/transaction/meta_transaction.rs b/node/src/types/transaction/meta_transaction.rs index b4490379e1..702c0fef19 100644 --- a/node/src/types/transaction/meta_transaction.rs +++ b/node/src/types/transaction/meta_transaction.rs @@ -1,7 +1,7 @@ +mod lane_id; mod meta_deploy; mod meta_transaction_v1; mod transaction_header; -mod transaction_lane; use meta_deploy::MetaDeploy; pub(crate) use transaction_header::*; @@ -217,7 +217,7 @@ impl MetaTransaction { ) -> Result { match transaction { Transaction::Deploy(deploy) => { - MetaDeploy::from(deploy.clone(), &transaction_config.transaction_v1_config) + MetaDeploy::from_deploy(deploy.clone(), &transaction_config.transaction_v1_config) .map(MetaTransaction::Deploy) } Transaction::V1(v1) => MetaTransactionV1::from_transaction_v1( @@ -342,7 +342,7 @@ impl Display for MetaTransaction { #[cfg(test)] mod proptests { use super::*; - use casper_types::{gens::legal_transaction_arb, TransactionLanesDefinition}; + use casper_types::{gens::legal_transaction_arb, TransactionLaneDefinition}; use proptest::prelude::*; proptest! { @@ -350,14 +350,14 @@ mod proptests { fn construction_roundtrip(transaction in legal_transaction_arb()) { let mut transaction_config = TransactionConfig::default(); transaction_config.transaction_v1_config.set_wasm_lanes(vec![ - TransactionLanesDefinition { + TransactionLaneDefinition { id: 3, max_transaction_length: u64::MAX/2, max_transaction_args_length: 100, max_transaction_gas_limit: u64::MAX/2, max_transaction_count: 10, }, - TransactionLanesDefinition { + TransactionLaneDefinition { id: 4, max_transaction_length: u64::MAX, max_transaction_args_length: 100, diff --git a/node/src/types/transaction/meta_transaction/transaction_lane.rs b/node/src/types/transaction/meta_transaction/lane_id.rs similarity index 100% rename from node/src/types/transaction/meta_transaction/transaction_lane.rs rename to node/src/types/transaction/meta_transaction/lane_id.rs diff --git a/node/src/types/transaction/meta_transaction/meta_deploy.rs b/node/src/types/transaction/meta_transaction/meta_deploy.rs index 74df7c26c6..c9ebc65085 100644 --- a/node/src/types/transaction/meta_transaction/meta_deploy.rs +++ b/node/src/types/transaction/meta_transaction/meta_deploy.rs @@ -1,5 +1,5 @@ use casper_types::{ - Deploy, ExecutableDeployItem, InvalidDeploy, InvalidTransaction, TransactionLanesDefinition, + Deploy, ExecutableDeployItem, InvalidDeploy, InvalidTransaction, TransactionLaneDefinition, TransactionV1Config, MINT_LANE_ID, }; use datasize::DataSize; @@ -14,7 +14,7 @@ pub(crate) struct MetaDeploy { } impl MetaDeploy { - pub(crate) fn from( + pub(crate) fn from_deploy( deploy: Deploy, config: &TransactionV1Config, ) -> Result { @@ -40,7 +40,7 @@ impl MetaDeploy { } } - fn calculate_lane_id_of_biggest_wasm(wasm_lanes: &[TransactionLanesDefinition]) -> Option { + fn calculate_lane_id_of_biggest_wasm(wasm_lanes: &[TransactionLaneDefinition]) -> Option { wasm_lanes .iter() .max_by(|left, right| { @@ -62,7 +62,7 @@ impl MetaDeploy { #[cfg(test)] mod tests { use super::MetaDeploy; - use casper_types::TransactionLanesDefinition; + use casper_types::TransactionLaneDefinition; #[test] fn calculate_lane_id_of_biggest_wasm_should_return_none_on_empty() { let wasms = vec![]; @@ -72,14 +72,14 @@ mod tests { #[test] fn calculate_lane_id_of_biggest_wasm_should_return_biggest() { let wasms = vec![ - TransactionLanesDefinition { + TransactionLaneDefinition { id: 0, max_transaction_length: 1, max_transaction_args_length: 2, max_transaction_gas_limit: 3, max_transaction_count: 4, }, - TransactionLanesDefinition { + TransactionLaneDefinition { id: 1, max_transaction_length: 10, max_transaction_args_length: 2, @@ -92,21 +92,21 @@ mod tests { Some(1) ); let wasms = vec![ - TransactionLanesDefinition { + TransactionLaneDefinition { id: 0, max_transaction_length: 1, max_transaction_args_length: 2, max_transaction_gas_limit: 3, max_transaction_count: 4, }, - TransactionLanesDefinition { + TransactionLaneDefinition { id: 1, max_transaction_length: 10, max_transaction_args_length: 2, max_transaction_gas_limit: 3, max_transaction_count: 4, }, - TransactionLanesDefinition { + TransactionLaneDefinition { id: 2, max_transaction_length: 7, max_transaction_args_length: 2, @@ -120,21 +120,21 @@ mod tests { ); let wasms = vec![ - TransactionLanesDefinition { + TransactionLaneDefinition { id: 0, max_transaction_length: 1, max_transaction_args_length: 2, max_transaction_gas_limit: 3, max_transaction_count: 4, }, - TransactionLanesDefinition { + TransactionLaneDefinition { id: 1, max_transaction_length: 10, max_transaction_args_length: 2, max_transaction_gas_limit: 3, max_transaction_count: 4, }, - TransactionLanesDefinition { + TransactionLaneDefinition { id: 2, max_transaction_length: 70, max_transaction_args_length: 2, diff --git a/node/src/types/transaction/meta_transaction/meta_transaction_v1.rs b/node/src/types/transaction/meta_transaction/meta_transaction_v1.rs index e1d016fc7b..a820f32f43 100644 --- a/node/src/types/transaction/meta_transaction/meta_transaction_v1.rs +++ b/node/src/types/transaction/meta_transaction/meta_transaction_v1.rs @@ -1,4 +1,4 @@ -use super::transaction_lane::calculate_transaction_lane; +use super::lane_id::calculate_transaction_lane; use crate::types::transaction::arg_handling; use casper_types::{ bytesrepr::ToBytes, crypto, Approval, Chainspec, ContractRuntimeTag, Digest, DisplayIter, Gas, @@ -735,7 +735,7 @@ mod tests { use crate::types::transaction::transaction_v1_builder::TransactionV1Builder; use casper_types::{ testing::TestRng, InvalidTransaction, InvalidTransactionV1, PricingMode, SecretKey, - TransactionInvocationTarget, TransactionLanesDefinition, TransactionRuntimeParams, + TransactionInvocationTarget, TransactionLaneDefinition, TransactionRuntimeParams, TransactionV1Config, }; @@ -819,14 +819,14 @@ mod tests { .unwrap(); let mut config = TransactionV1Config::default(); config.set_wasm_lanes(vec![ - TransactionLanesDefinition { + TransactionLaneDefinition { id: 3, max_transaction_length: 200, max_transaction_args_length: 100, max_transaction_gas_limit: 100, max_transaction_count: 10, }, - TransactionLanesDefinition { + TransactionLaneDefinition { id: 4, max_transaction_length: 500, max_transaction_args_length: 100, @@ -874,21 +874,21 @@ mod tests { fn build_v1_config() -> TransactionV1Config { let mut config = TransactionV1Config::default(); config.set_wasm_lanes(vec![ - TransactionLanesDefinition { + TransactionLaneDefinition { id: 3, max_transaction_length: 10000, max_transaction_args_length: 100, max_transaction_gas_limit: 100, max_transaction_count: 10, }, - TransactionLanesDefinition { + TransactionLaneDefinition { id: 4, max_transaction_length: 10001, max_transaction_args_length: 100, max_transaction_gas_limit: 10000, max_transaction_count: 10, }, - TransactionLanesDefinition { + TransactionLaneDefinition { id: 5, max_transaction_length: 10002, max_transaction_args_length: 100, diff --git a/node/src/utils/chain_specification.rs b/node/src/utils/chain_specification.rs index 5b8c1c9ae8..9366b03d31 100644 --- a/node/src/utils/chain_specification.rs +++ b/node/src/utils/chain_specification.rs @@ -196,7 +196,7 @@ mod tests { bytesrepr::FromBytes, ActivationPoint, BrTableCost, ChainspecRawBytes, ControlFlowCosts, CoreConfig, EraId, GlobalStateUpdate, HighwayConfig, HostFunction, HostFunctionCosts, MessageLimits, Motes, OpcodeCosts, ProtocolConfig, ProtocolVersion, StoredValue, - TestBlockBuilder, TimeDiff, Timestamp, TransactionConfig, TransactionLanesDefinition, + TestBlockBuilder, TimeDiff, Timestamp, TransactionConfig, TransactionLaneDefinition, TransactionV1Config, WasmConfig, WasmV1Config, MINT_LANE_ID, }; @@ -700,21 +700,21 @@ mod tests { #[test] fn should_fail_when_wasm_lanes_have_duplicate_max_transaction_length() { let mut v1_config = TransactionV1Config::default(); - let definition_1 = TransactionLanesDefinition { + let definition_1 = TransactionLaneDefinition { id: 3, max_transaction_length: 100, max_transaction_args_length: 100, max_transaction_gas_limit: 100, max_transaction_count: 10, }; - let definition_2 = TransactionLanesDefinition { + let definition_2 = TransactionLaneDefinition { id: 4, max_transaction_length: 10000, max_transaction_args_length: 100, max_transaction_gas_limit: 101, max_transaction_count: 10, }; - let definition_3 = TransactionLanesDefinition { + let definition_3 = TransactionLaneDefinition { id: 5, max_transaction_length: 1000, max_transaction_args_length: 100, @@ -748,21 +748,21 @@ mod tests { #[test] fn should_fail_when_wasm_lanes_have_duplicate_max_gas_price() { let mut v1_config = TransactionV1Config::default(); - let definition_1 = TransactionLanesDefinition { + let definition_1 = TransactionLaneDefinition { id: 3, max_transaction_length: 100, max_transaction_args_length: 100, max_transaction_gas_limit: 100, max_transaction_count: 10, }; - let definition_2 = TransactionLanesDefinition { + let definition_2 = TransactionLaneDefinition { id: 4, max_transaction_length: 10000, max_transaction_args_length: 100, max_transaction_gas_limit: 101, max_transaction_count: 10, }; - let definition_3 = TransactionLanesDefinition { + let definition_3 = TransactionLaneDefinition { id: 5, max_transaction_length: 1000, max_transaction_args_length: 100, @@ -802,7 +802,7 @@ mod tests { fn fail_validation_with_lane_id(lane_id: u8) { let mut v1_config = TransactionV1Config::default(); - let definition_1 = TransactionLanesDefinition { + let definition_1 = TransactionLaneDefinition { id: lane_id, max_transaction_length: 100, max_transaction_args_length: 100, diff --git a/node/src/utils/specimen.rs b/node/src/utils/specimen.rs index 7a0fcf1224..c6a5ac8bb8 100644 --- a/node/src/utils/specimen.rs +++ b/node/src/utils/specimen.rs @@ -46,6 +46,7 @@ use casper_storage::block_store::types::ApprovalsHashes; /// The largest valid unicode codepoint that can be encoded to UTF-8. pub(crate) const HIGHEST_UNICODE_CODEPOINT: char = '\u{10FFFF}'; +const LARGE_WASM_LANE_ID: u8 = 3; /// A cache used for memoization, typically on a single estimator. #[derive(Debug, Default)] @@ -858,7 +859,7 @@ impl LargestSpecimen for BlockPayload { ], ); transactions.insert( - 3, + LARGE_WASM_LANE_ID, vec![ large_txn_hash_with_approvals.clone(); estimator.parameter::("max_standard_transactions_per_block") diff --git a/types/src/chainspec.rs b/types/src/chainspec.rs index a4108ffa41..003c822e65 100644 --- a/types/src/chainspec.rs +++ b/types/src/chainspec.rs @@ -62,7 +62,7 @@ pub use pricing_handling::PricingHandling; pub use protocol_config::ProtocolConfig; pub use refund_handling::RefundHandling; pub use transaction_config::{ - DeployConfig, TransactionConfig, TransactionLanesDefinition, TransactionV1Config, + DeployConfig, TransactionConfig, TransactionLaneDefinition, TransactionV1Config, }; #[cfg(any(feature = "testing", test))] pub use transaction_config::{ diff --git a/types/src/chainspec/transaction_config.rs b/types/src/chainspec/transaction_config.rs index 7443ea3cd7..aada895dcf 100644 --- a/types/src/chainspec/transaction_config.rs +++ b/types/src/chainspec/transaction_config.rs @@ -21,7 +21,7 @@ pub use deploy_config::DeployConfig; pub use deploy_config::DEFAULT_MAX_PAYMENT_MOTES; #[cfg(any(feature = "testing", test))] pub use transaction_v1_config::DEFAULT_LARGE_TRANSACTION_GAS_LIMIT; -pub use transaction_v1_config::{TransactionLanesDefinition, TransactionV1Config}; +pub use transaction_v1_config::{TransactionLaneDefinition, TransactionV1Config}; /// The default minimum number of motes that can be transferred. pub const DEFAULT_MIN_TRANSFER_MOTES: u64 = 2_500_000_000; diff --git a/types/src/chainspec/transaction_config/transaction_v1_config.rs b/types/src/chainspec/transaction_config/transaction_v1_config.rs index 09d31ecf7d..fe0287980a 100644 --- a/types/src/chainspec/transaction_config/transaction_v1_config.rs +++ b/types/src/chainspec/transaction_config/transaction_v1_config.rs @@ -35,7 +35,7 @@ const TRANSACTION_COUNT_INDEX: usize = 4; /// Structured limits imposed on a transaction lane #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] #[cfg_attr(feature = "datasize", derive(DataSize))] -pub struct TransactionLanesDefinition { +pub struct TransactionLaneDefinition { /// The lane identifier pub id: u8, /// The maximum length of a transaction in bytes @@ -48,14 +48,14 @@ pub struct TransactionLanesDefinition { pub max_transaction_count: u64, } -impl TryFrom> for TransactionLanesDefinition { +impl TryFrom> for TransactionLaneDefinition { type Error = TransactionConfigError; fn try_from(v: Vec) -> Result { if v.len() != 5 { return Err(TransactionConfigError::InvalidArgsProvided); } - Ok(TransactionLanesDefinition { + Ok(TransactionLaneDefinition { id: v[TRANSACTION_ID_INDEX] as u8, max_transaction_length: v[TRANSACTION_LENGTH_INDEX], max_transaction_args_length: v[TRANSACTION_ARGS_LENGTH_INDEX], @@ -65,7 +65,7 @@ impl TryFrom> for TransactionLanesDefinition { } } -impl TransactionLanesDefinition { +impl TransactionLaneDefinition { /// Creates a new instance of TransactionLimitsDefinition pub fn new( id: u8, @@ -135,39 +135,39 @@ pub struct TransactionV1Config { deserialize_with = "vec_to_limit_definition" )] /// Lane configuration of the native mint interaction. - pub native_mint_lane: TransactionLanesDefinition, + pub native_mint_lane: TransactionLaneDefinition, #[serde( serialize_with = "limit_definition_to_vec", deserialize_with = "vec_to_limit_definition" )] /// Lane configuration for the native auction interaction. - pub native_auction_lane: TransactionLanesDefinition, + pub native_auction_lane: TransactionLaneDefinition, #[serde( serialize_with = "limit_definition_to_vec", deserialize_with = "vec_to_limit_definition" )] /// Lane configuration for the install/upgrade interaction. - pub install_upgrade_lane: TransactionLanesDefinition, + pub install_upgrade_lane: TransactionLaneDefinition, #[serde( serialize_with = "wasm_definitions_to_vec", deserialize_with = "definition_to_wasms" )] /// Lane configurations for Wasm based lanes that are not declared as install/upgrade. - wasm_lanes: Vec, + wasm_lanes: Vec, #[cfg_attr(any(all(feature = "std", feature = "once_cell"), test), serde(skip))] #[cfg_attr( all(any(feature = "once_cell", test), feature = "datasize"), data_size(skip) )] #[cfg(any(feature = "once_cell", test))] - wasm_lanes_ordered_by_transaction_size: OnceCell>, + wasm_lanes_ordered_by_transaction_size: OnceCell>, #[cfg_attr(any(all(feature = "std", feature = "once_cell"), test), serde(skip))] #[cfg_attr( all(any(feature = "once_cell", test), feature = "datasize"), data_size(skip) )] #[cfg(any(feature = "once_cell", test))] - wasm_lanes_ordered_by_transaction_gas_limit: OnceCell>, + wasm_lanes_ordered_by_transaction_gas_limit: OnceCell>, } impl PartialEq for TransactionV1Config { @@ -193,10 +193,10 @@ impl PartialEq for TransactionV1Config { impl TransactionV1Config { /// Cretaes a new instance of TransactionV1Config pub fn new( - native_mint_lane: TransactionLanesDefinition, - native_auction_lane: TransactionLanesDefinition, - install_upgrade_lane: TransactionLanesDefinition, - wasm_lanes: Vec, + native_mint_lane: TransactionLaneDefinition, + native_auction_lane: TransactionLaneDefinition, + install_upgrade_lane: TransactionLaneDefinition, + wasm_lanes: Vec, ) -> Self { #[cfg(any(feature = "once_cell", test))] let wasm_lanes_ordered_by_transaction_size = OnceCell::with_value( @@ -414,7 +414,7 @@ impl TransactionV1Config { #[allow(unreachable_code)] //We're allowing unreachable code here because there's a possibility that someone might // want to use the types crate without once_cell - fn get_wasm_lanes_ordered_by_transaction_size(&self) -> &Vec { + fn get_wasm_lanes_ordered_by_transaction_size(&self) -> &Vec { #[cfg(any(feature = "once_cell", test))] return self.wasm_lanes_ordered_by_transaction_size.get_or_init(|| { Self::build_wasm_lanes_ordered_by_transaction_size(self.wasm_lanes.clone()) @@ -425,7 +425,7 @@ impl TransactionV1Config { #[allow(unreachable_code)] //We're allowing unreachable code here because there's a possibility that someone might // want to use the types crate without once_cell - fn get_wasm_lanes_ordered_by_gas_limit(&self) -> &Vec { + fn get_wasm_lanes_ordered_by_gas_limit(&self) -> &Vec { #[cfg(any(feature = "once_cell", test))] return self .wasm_lanes_ordered_by_transaction_gas_limit @@ -436,8 +436,8 @@ impl TransactionV1Config { } fn build_wasm_lanes_ordered_by_transaction_gas_limit( - wasm_lanes: Vec, - ) -> Vec { + wasm_lanes: Vec, + ) -> Vec { let mut ordered = wasm_lanes; ordered.sort_by(|a, b| { a.max_transaction_gas_limit @@ -447,19 +447,19 @@ impl TransactionV1Config { } fn build_wasm_lanes_ordered_by_transaction_size( - wasm_lanes: Vec, - ) -> Vec { + wasm_lanes: Vec, + ) -> Vec { let mut ordered = wasm_lanes; ordered.sort_by(|a, b| a.max_transaction_length.cmp(&b.max_transaction_length)); ordered } - pub fn wasm_lanes(&self) -> &Vec { + pub fn wasm_lanes(&self) -> &Vec { &self.wasm_lanes } #[cfg(any(feature = "testing", test))] - pub fn set_wasm_lanes(&mut self, wasm_lanes: Vec) { + pub fn set_wasm_lanes(&mut self, wasm_lanes: Vec) { self.wasm_lanes = wasm_lanes; #[cfg(any(feature = "once_cell", test))] { @@ -491,7 +491,7 @@ impl Default for TransactionV1Config { let native_auction_lane = DEFAULT_NATIVE_AUCTION_LANE.to_vec(); let install_upgrade_lane = DEFAULT_INSTALL_UPGRADE_LANE.to_vec(); let raw_wasm_lanes = vec![wasm_lane]; - let wasm_lanes: Result, _> = + let wasm_lanes: Result, _> = raw_wasm_lanes.into_iter().map(|v| v.try_into()).collect(); TransactionV1Config::new( @@ -511,7 +511,7 @@ impl ToBytes for TransactionV1Config { let wasm_lanes_as_vecs: Vec> = self .wasm_lanes .iter() - .map(TransactionLanesDefinition::as_vec) + .map(TransactionLaneDefinition::as_vec) .collect(); wasm_lanes_as_vecs.write_bytes(writer) } @@ -526,7 +526,7 @@ impl ToBytes for TransactionV1Config { let wasm_lanes_as_vecs: Vec> = self .wasm_lanes .iter() - .map(TransactionLanesDefinition::as_vec) + .map(TransactionLaneDefinition::as_vec) .collect(); self.native_mint_lane.as_vec().serialized_length() + self.native_auction_lane.as_vec().serialized_length() @@ -552,7 +552,7 @@ impl FromBytes for TransactionV1Config { let install_upgrade_lane = raw_install_upgrade_lane .try_into() .map_err(|_| bytesrepr::Error::Formatting)?; - let wasm_lanes: Result, _> = + let wasm_lanes: Result, _> = raw_wasm_lanes.into_iter().map(|v| v.try_into()).collect(); let config = TransactionV1Config::new( native_mint_lane, @@ -564,12 +564,12 @@ impl FromBytes for TransactionV1Config { } } -fn vec_to_limit_definition<'de, D>(deserializer: D) -> Result +fn vec_to_limit_definition<'de, D>(deserializer: D) -> Result where D: Deserializer<'de>, { let vec = Vec::::deserialize(deserializer)?; - let limits = TransactionLanesDefinition::try_from(vec).map_err(|_| { + let limits = TransactionLaneDefinition::try_from(vec).map_err(|_| { D::Error::invalid_value( Unexpected::Seq, &"expected 5 u64 compliant numbers to create a TransactionLimitsDefinition", @@ -579,7 +579,7 @@ where } fn limit_definition_to_vec( - limits: &TransactionLanesDefinition, + limits: &TransactionLaneDefinition, serializer: S, ) -> Result where @@ -593,12 +593,12 @@ where seq.end() } -fn definition_to_wasms<'de, D>(deserializer: D) -> Result, D::Error> +fn definition_to_wasms<'de, D>(deserializer: D) -> Result, D::Error> where D: Deserializer<'de>, { let vec = Vec::>::deserialize(deserializer)?; - let result: Result, TransactionConfigError> = + let result: Result, TransactionConfigError> = vec.into_iter().map(|v| v.try_into()).collect(); result.map_err(|_| { D::Error::invalid_value( @@ -609,7 +609,7 @@ where } fn wasm_definitions_to_vec( - limits: &[TransactionLanesDefinition], + limits: &[TransactionLaneDefinition], serializer: S, ) -> Result where @@ -743,21 +743,21 @@ mod tests { example_auction(), example_install_upgrade(), vec![ - TransactionLanesDefinition { + TransactionLaneDefinition { id: 3, max_transaction_length: 10, max_transaction_args_length: 1, max_transaction_gas_limit: 5, max_transaction_count: 1, }, - TransactionLanesDefinition { + TransactionLaneDefinition { id: 4, max_transaction_length: 11, max_transaction_args_length: 1, max_transaction_gas_limit: 55, max_transaction_count: 1, }, - TransactionLanesDefinition { + TransactionLaneDefinition { id: 5, max_transaction_length: 12, max_transaction_args_length: 1, @@ -777,21 +777,21 @@ mod tests { example_auction(), example_install_upgrade(), vec![ - TransactionLanesDefinition { + TransactionLaneDefinition { id: 3, max_transaction_length: 10, max_transaction_args_length: 1, max_transaction_gas_limit: 5, max_transaction_count: 1, }, - TransactionLanesDefinition { + TransactionLaneDefinition { id: 4, max_transaction_length: 11, max_transaction_args_length: 1, max_transaction_gas_limit: 55, max_transaction_count: 1, }, - TransactionLanesDefinition { + TransactionLaneDefinition { id: 5, max_transaction_length: 12, max_transaction_args_length: 1, @@ -811,21 +811,21 @@ mod tests { example_auction(), example_install_upgrade(), vec![ - TransactionLanesDefinition { + TransactionLaneDefinition { id: 3, max_transaction_length: 10, max_transaction_args_length: 1, max_transaction_gas_limit: 5, max_transaction_count: 1, }, - TransactionLanesDefinition { + TransactionLaneDefinition { id: 4, max_transaction_length: 11, max_transaction_args_length: 1, max_transaction_gas_limit: 55, max_transaction_count: 1, }, - TransactionLanesDefinition { + TransactionLaneDefinition { id: 5, max_transaction_length: 12, max_transaction_args_length: 1, @@ -842,13 +842,13 @@ mod tests { fn should_deserialize() { let got: TransactionV1Config = serde_json::from_str(EXAMPLE_JSON).unwrap(); let expected = TransactionV1Config::new( - TransactionLanesDefinition::new(0, 1, 2, 3, 4), - TransactionLanesDefinition::new(1, 5, 6, 7, 8), - TransactionLanesDefinition::new(2, 9, 10, 11, 12), + TransactionLaneDefinition::new(0, 1, 2, 3, 4), + TransactionLaneDefinition::new(1, 5, 6, 7, 8), + TransactionLaneDefinition::new(2, 9, 10, 11, 12), vec![ - TransactionLanesDefinition::new(3, 13, 14, 15, 16), - TransactionLanesDefinition::new(4, 17, 18, 19, 20), - TransactionLanesDefinition::new(5, 21, 22, 23, 24), + TransactionLaneDefinition::new(3, 13, 14, 15, 16), + TransactionLaneDefinition::new(4, 17, 18, 19, 20), + TransactionLaneDefinition::new(5, 21, 22, 23, 24), ], ); assert_eq!(got, expected); @@ -857,13 +857,13 @@ mod tests { #[test] fn should_serialize() { let input = TransactionV1Config::new( - TransactionLanesDefinition::new(0, 1, 2, 3, 4), - TransactionLanesDefinition::new(1, 5, 6, 7, 8), - TransactionLanesDefinition::new(2, 9, 10, 11, 12), + TransactionLaneDefinition::new(0, 1, 2, 3, 4), + TransactionLaneDefinition::new(1, 5, 6, 7, 8), + TransactionLaneDefinition::new(2, 9, 10, 11, 12), vec![ - TransactionLanesDefinition::new(3, 13, 14, 15, 16), - TransactionLanesDefinition::new(4, 17, 18, 19, 20), - TransactionLanesDefinition::new(5, 21, 22, 23, 24), + TransactionLaneDefinition::new(3, 13, 14, 15, 16), + TransactionLaneDefinition::new(4, 17, 18, 19, 20), + TransactionLaneDefinition::new(5, 21, 22, 23, 24), ], ); let raw = serde_json::to_string(&input).unwrap(); @@ -872,35 +872,35 @@ mod tests { assert_eq!(got, expected); } - fn example_native() -> TransactionLanesDefinition { - TransactionLanesDefinition::new(0, 1500, 1024, 1_500_000_000, 150) + fn example_native() -> TransactionLaneDefinition { + TransactionLaneDefinition::new(0, 1500, 1024, 1_500_000_000, 150) } - fn example_auction() -> TransactionLanesDefinition { - TransactionLanesDefinition::new(1, 500, 3024, 3_500_000_000, 350) + fn example_auction() -> TransactionLaneDefinition { + TransactionLaneDefinition::new(1, 500, 3024, 3_500_000_000, 350) } - fn example_install_upgrade() -> TransactionLanesDefinition { - TransactionLanesDefinition::new(2, 10000, 2024, 2_500_000_000, 250) + fn example_install_upgrade() -> TransactionLaneDefinition { + TransactionLaneDefinition::new(2, 10000, 2024, 2_500_000_000, 250) } - fn wasm_small(id: u8) -> TransactionLanesDefinition { - TransactionLanesDefinition::new(id, 600, 4024, 4_500_000_000, 450) + fn wasm_small(id: u8) -> TransactionLaneDefinition { + TransactionLaneDefinition::new(id, 600, 4024, 4_500_000_000, 450) } - fn wasm_medium(id: u8) -> TransactionLanesDefinition { - TransactionLanesDefinition::new(id, 700, 5024, 5_500_000_000, 550) + fn wasm_medium(id: u8) -> TransactionLaneDefinition { + TransactionLaneDefinition::new(id, 700, 5024, 5_500_000_000, 550) } - fn wasm_large(id: u8) -> TransactionLanesDefinition { - TransactionLanesDefinition::new(id, 800, 6024, 6_500_000_000, 650) + fn wasm_large(id: u8) -> TransactionLaneDefinition { + TransactionLaneDefinition::new(id, 800, 6024, 6_500_000_000, 650) } - fn example_wasm() -> Vec { + fn example_wasm() -> Vec { vec![wasm_small(3), wasm_medium(4), wasm_large(5)] } - fn example_wasm_reversed_ids() -> Vec { + fn example_wasm_reversed_ids() -> Vec { vec![wasm_small(5), wasm_medium(4), wasm_large(3)] } diff --git a/types/src/lib.rs b/types/src/lib.rs index ab07d01d2e..bdd261a808 100644 --- a/types/src/lib.rs +++ b/types/src/lib.rs @@ -130,7 +130,7 @@ pub use chainspec::{ HostFunctionCost, HostFunctionCosts, LegacyRequiredFinality, MessageLimits, MintCosts, NetworkConfig, NextUpgrade, OpcodeCosts, PricingHandling, ProtocolConfig, ProtocolUpgradeConfig, RefundHandling, StandardPaymentCosts, StorageCosts, SystemConfig, - TransactionConfig, TransactionLanesDefinition, TransactionV1Config, VacancyConfig, + TransactionConfig, TransactionLaneDefinition, TransactionV1Config, VacancyConfig, ValidatorConfig, WasmConfig, WasmV1Config, DEFAULT_GAS_HOLD_INTERVAL, DEFAULT_HOST_FUNCTION_NEW_DICTIONARY, DEFAULT_MINIMUM_BID_AMOUNT, DEFAULT_REFUND_HANDLING, };