From 01968e737ebfb0eaba0489fe42392ab6ddd4c337 Mon Sep 17 00:00:00 2001 From: Jakub Zajkowski Date: Sat, 14 Dec 2024 00:58:31 +0100 Subject: [PATCH 1/3] Changed the way transaction lanes are calculated if the transaction has PricingMode::PaymentLimited. For wasm based transaction with that pricing mode the payment_amount field will be used as size estimate to determine the wasm lane. Also added some validation for the chainspec to prevent: * wasm lanes using reserved ids (mint, auction, install/upgrade) * wasm lanes that have duplicate max_transaction_length * wasm lanes that have duplicate max_transaction_gas_limit * configs that have no wasm lanes defined --- node/src/components/block_validator/tests.rs | 4 +- node/src/components/transaction_acceptor.rs | 30 +- .../components/transaction_acceptor/tests.rs | 1 - .../components/transaction_buffer/tests.rs | 12 +- .../main_reactor/tests/transactions.rs | 2 +- node/src/types/appendable_block.rs | 7 +- .../src/types/transaction/meta_transaction.rs | 119 +++--- .../meta_transaction/meta_deploy.rs | 150 ++++++++ .../meta_transaction/meta_transaction_v1.rs | 215 +++++++++-- .../meta_transaction/transaction_lane.rs | 111 ++---- .../transaction/transaction_v1_builder.rs | 47 +-- node/src/utils/chain_specification.rs | 181 +++++++++- node/src/utils/specimen.rs | 5 +- .../test_block_v2_builder.rs | 2 +- types/src/chainspec.rs | 2 +- types/src/chainspec/transaction_config.rs | 2 +- .../transaction_v1_config.rs | 340 +++++++++++++----- types/src/gens.rs | 5 - types/src/lib.rs | 8 +- types/src/transaction/deploy/error.rs | 7 +- .../transaction/transaction_v1/errors_v1.rs | 10 +- 21 files changed, 959 insertions(+), 301 deletions(-) create mode 100644 node/src/types/transaction/meta_transaction/meta_deploy.rs diff --git a/node/src/components/block_validator/tests.rs b/node/src/components/block_validator/tests.rs index b73c36f136..aab43fdf14 100644 --- a/node/src/components/block_validator/tests.rs +++ b/node/src/components/block_validator/tests.rs @@ -9,7 +9,7 @@ use casper_types::{ BlockSignatures, BlockSignaturesV2, Chainspec, ChainspecRawBytes, Deploy, ExecutableDeployItem, FinalitySignatureV2, RuntimeArgs, SecretKey, TestBlockBuilder, TimeDiff, Transaction, TransactionHash, TransactionId, TransactionV1, TransactionV1Config, AUCTION_LANE_ID, - INSTALL_UPGRADE_LANE_ID, LARGE_WASM_LANE_ID, MINT_LANE_ID, U512, + INSTALL_UPGRADE_LANE_ID, MINT_LANE_ID, U512, }; use crate::{ @@ -152,7 +152,7 @@ pub(super) fn new_proposed_block_with_cited_signatures( INSTALL_UPGRADE_LANE_ID, install_upgrade.into_iter().collect(), ); - ret.insert(LARGE_WASM_LANE_ID, standard.into_iter().collect()); + ret.insert(3, standard.into_iter().collect()); ret }; let block_payload = BlockPayload::new(transactions, vec![], cited_signatures, true, 1u8); diff --git a/node/src/components/transaction_acceptor.rs b/node/src/components/transaction_acceptor.rs index 6975e2f29e..b0a84b0a56 100644 --- a/node/src/components/transaction_acceptor.rs +++ b/node/src/components/transaction_acceptor.rs @@ -404,7 +404,7 @@ impl TransactionAcceptor { block_header: Box, ) -> Effects { let session = match &event_metadata.meta_transaction { - MetaTransaction::Deploy(deploy) => deploy.session(), + MetaTransaction::Deploy(meta_deploy) => meta_deploy.session(), MetaTransaction::V1(txn) => { error!(%txn, "should only handle deploys in verify_deploy_session"); return self.reject_transaction( @@ -510,9 +510,10 @@ impl TransactionAcceptor { } let next_step = match &event_metadata.meta_transaction { - MetaTransaction::Deploy(deploy) => { + MetaTransaction::Deploy(meta_deploy) => { + let deploy_hash = meta_deploy.deploy().hash(); error!( - %deploy, + %deploy_hash, "should only handle version 1 transactions in verify_transaction_v1_body" ); return self.reject_transaction( @@ -594,12 +595,20 @@ impl TransactionAcceptor { }; let maybe_entry_point_name = match &event_metadata.meta_transaction { - MetaTransaction::Deploy(deploy) if is_payment => { - Some(deploy.payment().entry_point_name().to_string()) - } - MetaTransaction::Deploy(deploy) => { - Some(deploy.session().entry_point_name().to_string()) - } + MetaTransaction::Deploy(meta_deploy) if is_payment => Some( + meta_deploy + .deploy() + .payment() + .entry_point_name() + .to_string(), + ), + MetaTransaction::Deploy(meta_deploy) => Some( + meta_deploy + .deploy() + .session() + .entry_point_name() + .to_string(), + ), MetaTransaction::V1(_) if is_payment => { error!("should not fetch a contract to validate payment logic for transaction v1s"); None @@ -764,7 +773,8 @@ impl TransactionAcceptor { event_metadata: Box, ) -> Effects { let is_valid = match &event_metadata.meta_transaction { - MetaTransaction::Deploy(deploy) => deploy + MetaTransaction::Deploy(meta_deploy) => meta_deploy + .deploy() .is_valid() .map_err(|err| Error::InvalidTransaction(err.into())), MetaTransaction::V1(txn) => txn diff --git a/node/src/components/transaction_acceptor/tests.rs b/node/src/components/transaction_acceptor/tests.rs index 08d0adb18d..b559f5f58b 100644 --- a/node/src/components/transaction_acceptor/tests.rs +++ b/node/src/components/transaction_acceptor/tests.rs @@ -1163,7 +1163,6 @@ async fn run_transaction_acceptor_without_timeout( } else { chainspec }; - chainspec.core_config.administrators = iter::once(PublicKey::from(&admin)).collect(); let chainspec = Arc::new(chainspec); diff --git a/node/src/components/transaction_buffer/tests.rs b/node/src/components/transaction_buffer/tests.rs index 797dd43eda..42260cad9b 100644 --- a/node/src/components/transaction_buffer/tests.rs +++ b/node/src/components/transaction_buffer/tests.rs @@ -5,8 +5,8 @@ use rand::{seq::SliceRandom, Rng}; use casper_types::{ testing::TestRng, Deploy, EraId, SecretKey, TestBlockBuilder, TimeDiff, Transaction, - TransactionConfig, TransactionLimitsDefinition, TransactionV1Config, - DEFAULT_LARGE_TRANSACTION_GAS_LIMIT, LARGE_WASM_LANE_ID, + TransactionConfig, TransactionLanesDefinition, TransactionV1Config, + DEFAULT_LARGE_TRANSACTION_GAS_LIMIT, }; use super::*; @@ -17,6 +17,7 @@ use crate::{ utils, }; +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; @@ -1121,10 +1122,11 @@ 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/types/appendable_block.rs b/node/src/types/appendable_block.rs index 6a65fa37c8..0f83a2463e 100644 --- a/node/src/types/appendable_block.rs +++ b/node/src/types/appendable_block.rs @@ -176,7 +176,7 @@ impl AppendableBlock { for lane_id in self .transaction_config .transaction_v1_config - .wasm_lanes + .wasm_lanes() .iter() .map(|lane| lane.id()) { @@ -247,13 +247,12 @@ impl Display for AppendableBlock { #[cfg(test)] mod tests { - use casper_types::{ - testing::TestRng, SingleBlockRewardedSignatures, TimeDiff, LARGE_WASM_LANE_ID, - }; + use casper_types::{testing::TestRng, SingleBlockRewardedSignatures, TimeDiff}; 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 6ee16e49e6..b4490379e1 100644 --- a/node/src/types/transaction/meta_transaction.rs +++ b/node/src/types/transaction/meta_transaction.rs @@ -1,15 +1,16 @@ +mod meta_deploy; mod meta_transaction_v1; mod transaction_header; mod transaction_lane; +use meta_deploy::MetaDeploy; pub(crate) use transaction_header::*; use casper_execution_engine::engine_state::{SessionDataDeploy, SessionDataV1, SessionInputData}; use casper_types::{ - account::AccountHash, bytesrepr::ToBytes, Approval, Chainspec, Deploy, Digest, - ExecutableDeployItem, Gas, GasLimited, HashAddr, InitiatorAddr, InvalidTransaction, Phase, - PricingMode, TimeDiff, Timestamp, Transaction, TransactionArgs, TransactionConfig, - TransactionEntryPoint, TransactionHash, TransactionTarget, INSTALL_UPGRADE_LANE_ID, - LARGE_WASM_LANE_ID, MINT_LANE_ID, + account::AccountHash, bytesrepr::ToBytes, Approval, Chainspec, Digest, ExecutableDeployItem, + Gas, GasLimited, HashAddr, InitiatorAddr, InvalidTransaction, Phase, PricingMode, TimeDiff, + Timestamp, Transaction, TransactionArgs, TransactionConfig, TransactionEntryPoint, + TransactionHash, TransactionTarget, INSTALL_UPGRADE_LANE_ID, }; use core::fmt::{self, Debug, Display, Formatter}; pub(crate) use meta_transaction_v1::MetaTransactionV1; @@ -18,7 +19,7 @@ use std::{borrow::Cow, collections::BTreeSet}; #[derive(Clone, Debug, Serialize)] pub(crate) enum MetaTransaction { - Deploy(Deploy), + Deploy(MetaDeploy), V1(MetaTransactionV1), } @@ -26,7 +27,9 @@ impl MetaTransaction { /// Returns the `TransactionHash` identifying this transaction. pub fn hash(&self) -> TransactionHash { match self { - MetaTransaction::Deploy(deploy) => TransactionHash::from(*deploy.hash()), + MetaTransaction::Deploy(meta_deploy) => { + TransactionHash::from(*meta_deploy.deploy().hash()) + } MetaTransaction::V1(txn) => TransactionHash::from(*txn.hash()), } } @@ -34,7 +37,7 @@ impl MetaTransaction { /// Timestamp. pub fn timestamp(&self) -> Timestamp { match self { - MetaTransaction::Deploy(deploy) => deploy.header().timestamp(), + MetaTransaction::Deploy(meta_deploy) => meta_deploy.deploy().header().timestamp(), MetaTransaction::V1(v1) => v1.timestamp(), } } @@ -42,7 +45,7 @@ impl MetaTransaction { /// Time to live. pub fn ttl(&self) -> TimeDiff { match self { - MetaTransaction::Deploy(deploy) => deploy.header().ttl(), + MetaTransaction::Deploy(meta_deploy) => meta_deploy.deploy().header().ttl(), MetaTransaction::V1(v1) => v1.ttl(), } } @@ -50,7 +53,7 @@ impl MetaTransaction { /// Returns the `Approval`s for this transaction. pub fn approvals(&self) -> BTreeSet { match self { - MetaTransaction::Deploy(deploy) => deploy.approvals().clone(), + MetaTransaction::Deploy(meta_deploy) => meta_deploy.deploy().approvals().clone(), MetaTransaction::V1(v1) => v1.approvals().clone(), } } @@ -58,7 +61,9 @@ impl MetaTransaction { /// Returns the address of the initiator of the transaction. pub fn initiator_addr(&self) -> InitiatorAddr { match self { - MetaTransaction::Deploy(deploy) => InitiatorAddr::PublicKey(deploy.account().clone()), + MetaTransaction::Deploy(meta_deploy) => { + InitiatorAddr::PublicKey(meta_deploy.deploy().account().clone()) + } MetaTransaction::V1(txn) => txn.initiator_addr().clone(), } } @@ -66,7 +71,8 @@ impl MetaTransaction { /// Returns the set of account hashes corresponding to the public keys of the approvals. pub fn signers(&self) -> BTreeSet { match self { - MetaTransaction::Deploy(deploy) => deploy + MetaTransaction::Deploy(meta_deploy) => meta_deploy + .deploy() .approvals() .iter() .map(|approval| approval.signer().to_account_hash()) @@ -82,7 +88,7 @@ impl MetaTransaction { /// Returns `true` if `self` represents a native transfer deploy or a native V1 transaction. pub fn is_native(&self) -> bool { match self { - MetaTransaction::Deploy(deploy) => deploy.is_transfer(), + MetaTransaction::Deploy(meta_deploy) => meta_deploy.deploy().is_transfer(), MetaTransaction::V1(v1_txn) => *v1_txn.target() == TransactionTarget::Native, } } @@ -90,7 +96,10 @@ impl MetaTransaction { /// Should this transaction use standard payment processing? pub fn is_standard_payment(&self) -> bool { match self { - MetaTransaction::Deploy(deploy) => deploy.payment().is_standard_payment(Phase::Payment), + MetaTransaction::Deploy(meta_deploy) => meta_deploy + .deploy() + .payment() + .is_standard_payment(Phase::Payment), MetaTransaction::V1(v1) => { if let PricingMode::PaymentLimited { standard_payment, .. @@ -107,7 +116,8 @@ impl MetaTransaction { /// Authorization keys. pub fn authorization_keys(&self) -> BTreeSet { match self { - MetaTransaction::Deploy(deploy) => deploy + MetaTransaction::Deploy(meta_deploy) => meta_deploy + .deploy() .approvals() .iter() .map(|approval| approval.signer().to_account_hash()) @@ -123,9 +133,9 @@ impl MetaTransaction { /// The session args. pub fn session_args(&self) -> Cow { match self { - MetaTransaction::Deploy(deploy) => { - Cow::Owned(TransactionArgs::Named(deploy.session().args().clone())) - } + MetaTransaction::Deploy(meta_deploy) => Cow::Owned(TransactionArgs::Named( + meta_deploy.deploy().session().args().clone(), + )), MetaTransaction::V1(transaction_v1) => Cow::Borrowed(transaction_v1.args()), } } @@ -133,7 +143,9 @@ impl MetaTransaction { /// The entry point. pub fn entry_point(&self) -> TransactionEntryPoint { match self { - MetaTransaction::Deploy(deploy) => deploy.session().entry_point_name().into(), + MetaTransaction::Deploy(meta_deploy) => { + meta_deploy.deploy().session().entry_point_name().into() + } MetaTransaction::V1(transaction_v1) => transaction_v1.entry_point().clone(), } } @@ -141,21 +153,16 @@ impl MetaTransaction { /// The transaction lane. pub fn transaction_lane(&self) -> u8 { match self { - MetaTransaction::Deploy(deploy) => { - if deploy.is_transfer() { - MINT_LANE_ID - } else { - LARGE_WASM_LANE_ID - } - } - MetaTransaction::V1(v1) => v1.transaction_lane(), + MetaTransaction::Deploy(meta_deploy) => meta_deploy.lane_id(), + MetaTransaction::V1(v1) => v1.lane_id(), } } /// Returns the gas price tolerance. pub fn gas_price_tolerance(&self) -> Result { match self { - MetaTransaction::Deploy(deploy) => deploy + MetaTransaction::Deploy(meta_deploy) => meta_deploy + .deploy() .gas_price_tolerance() .map_err(InvalidTransaction::from), MetaTransaction::V1(v1) => Ok(v1.gas_price_tolerance()), @@ -164,7 +171,8 @@ impl MetaTransaction { pub fn gas_limit(&self, chainspec: &Chainspec) -> Result { match self { - MetaTransaction::Deploy(deploy) => deploy + MetaTransaction::Deploy(meta_deploy) => meta_deploy + .deploy() .gas_limit(chainspec) .map_err(InvalidTransaction::from), MetaTransaction::V1(v1) => v1.gas_limit(chainspec), @@ -187,10 +195,10 @@ impl MetaTransaction { /// Returns a `hash_addr` for a targeted contract, if known. pub fn contract_direct_address(&self) -> Option<(HashAddr, String)> { match self { - MetaTransaction::Deploy(deploy) => { + MetaTransaction::Deploy(meta_deploy) => { if let ExecutableDeployItem::StoredContractByHash { hash, entry_point, .. - } = deploy.session() + } = meta_deploy.session() { return Some((hash.value(), entry_point.clone())); } @@ -208,9 +216,15 @@ impl MetaTransaction { transaction_config: &TransactionConfig, ) -> Result { match transaction { - Transaction::Deploy(deploy) => Ok(MetaTransaction::Deploy(deploy.clone())), - Transaction::V1(v1) => MetaTransactionV1::from_transaction_v1(v1, transaction_config) - .map(MetaTransaction::V1), + Transaction::Deploy(deploy) => { + MetaDeploy::from(deploy.clone(), &transaction_config.transaction_v1_config) + .map(MetaTransaction::Deploy) + } + Transaction::V1(v1) => MetaTransactionV1::from_transaction_v1( + v1, + &transaction_config.transaction_v1_config, + ) + .map(MetaTransaction::V1), } } @@ -221,7 +235,8 @@ impl MetaTransaction { at: Timestamp, ) -> Result<(), InvalidTransaction> { match self { - MetaTransaction::Deploy(deploy) => deploy + MetaTransaction::Deploy(meta_deploy) => meta_deploy + .deploy() .is_config_compliant(chainspec, timestamp_leeway, at) .map_err(InvalidTransaction::from), MetaTransaction::V1(v1) => v1 @@ -232,7 +247,7 @@ impl MetaTransaction { pub fn payload_hash(&self) -> Digest { match self { - MetaTransaction::Deploy(deploy) => *deploy.body_hash(), + MetaTransaction::Deploy(meta_deploy) => *meta_deploy.deploy().body_hash(), MetaTransaction::V1(v1) => *v1.payload_hash(), } } @@ -241,7 +256,8 @@ impl MetaTransaction { let initiator_addr = self.initiator_addr(); let is_standard_payment = self.is_standard_payment(); match self { - MetaTransaction::Deploy(deploy) => { + MetaTransaction::Deploy(meta_deploy) => { + let deploy = meta_deploy.deploy(); let data = SessionDataDeploy::new( deploy.hash(), deploy.session(), @@ -256,7 +272,7 @@ impl MetaTransaction { v1.args().as_named().expect("V1 wasm args should be named and validated at the transaction acceptor level"), v1.target(), v1.entry_point(), - v1.transaction_lane() == INSTALL_UPGRADE_LANE_ID, + v1.lane_id() == INSTALL_UPGRADE_LANE_ID, v1.hash(), v1.pricing_mode(), initiator_addr, @@ -271,7 +287,7 @@ impl MetaTransaction { /// Size estimate. pub fn size_estimate(&self) -> usize { match self { - MetaTransaction::Deploy(deploy) => deploy.serialized_length(), + MetaTransaction::Deploy(meta_deploy) => meta_deploy.deploy().serialized_length(), MetaTransaction::V1(v1) => v1.serialized_length(), } } @@ -294,7 +310,7 @@ impl MetaTransaction { match self { MetaTransaction::Deploy(_) => false, MetaTransaction::V1(meta_transaction_v1) => { - meta_transaction_v1.transaction_lane() == INSTALL_UPGRADE_LANE_ID + meta_transaction_v1.lane_id() == INSTALL_UPGRADE_LANE_ID } } } @@ -317,7 +333,7 @@ impl MetaTransaction { impl Display for MetaTransaction { fn fmt(&self, formatter: &mut Formatter) -> fmt::Result { match self { - MetaTransaction::Deploy(deploy) => Display::fmt(deploy, formatter), + MetaTransaction::Deploy(meta_deploy) => Display::fmt(meta_deploy.deploy(), formatter), MetaTransaction::V1(txn) => Display::fmt(txn, formatter), } } @@ -326,13 +342,30 @@ impl Display for MetaTransaction { #[cfg(test)] mod proptests { use super::*; - use casper_types::gens::legal_transaction_arb; + use casper_types::{gens::legal_transaction_arb, TransactionLanesDefinition}; use proptest::prelude::*; proptest! { #[test] fn construction_roundtrip(transaction in legal_transaction_arb()) { - let maybe_transaction = MetaTransaction::from_transaction(&transaction, &TransactionConfig::default()); + let mut transaction_config = TransactionConfig::default(); + transaction_config.transaction_v1_config.set_wasm_lanes(vec![ + TransactionLanesDefinition { + 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 { + id: 4, + max_transaction_length: u64::MAX, + max_transaction_args_length: 100, + max_transaction_gas_limit: u64::MAX, + max_transaction_count: 10, + }, + ]); + let maybe_transaction = MetaTransaction::from_transaction(&transaction, &transaction_config); prop_assert!(maybe_transaction.is_ok(), "{:?}", maybe_transaction); } } diff --git a/node/src/types/transaction/meta_transaction/meta_deploy.rs b/node/src/types/transaction/meta_transaction/meta_deploy.rs new file mode 100644 index 0000000000..74df7c26c6 --- /dev/null +++ b/node/src/types/transaction/meta_transaction/meta_deploy.rs @@ -0,0 +1,150 @@ +use casper_types::{ + Deploy, ExecutableDeployItem, InvalidDeploy, InvalidTransaction, TransactionLanesDefinition, + TransactionV1Config, MINT_LANE_ID, +}; +use datasize::DataSize; +use serde::Serialize; + +#[derive(Clone, Debug, Serialize, DataSize)] +pub(crate) struct MetaDeploy { + deploy: Deploy, + //When a deploy is a WASM we categorize it as "largest wasm possible". + //We need to keep that id here since we can fetch it only from chainspec. + largest_wasm_id: u8, +} + +impl MetaDeploy { + pub(crate) fn from( + deploy: Deploy, + config: &TransactionV1Config, + ) -> Result { + let maybe_biggest_lane_limit = Self::calculate_lane_id_of_biggest_wasm(config.wasm_lanes()); + if let Some(largest_wasm_id) = maybe_biggest_lane_limit { + Ok(MetaDeploy { + deploy, + largest_wasm_id, + }) + } else { + // Seems like chainspec didn't have any wasm lanes configured + Err(InvalidTransaction::Deploy( + InvalidDeploy::InvalidChainspecConfiguration, + )) + } + } + + pub(crate) fn lane_id(&self) -> u8 { + if self.deploy.is_transfer() { + MINT_LANE_ID + } else { + self.largest_wasm_id + } + } + + fn calculate_lane_id_of_biggest_wasm(wasm_lanes: &[TransactionLanesDefinition]) -> Option { + wasm_lanes + .iter() + .max_by(|left, right| { + left.max_transaction_length + .cmp(&right.max_transaction_length) + }) + .map(|definition| definition.id) + } + + pub(crate) fn session(&self) -> &ExecutableDeployItem { + self.deploy.session() + } + + pub(crate) fn deploy(&self) -> &Deploy { + &self.deploy + } +} + +#[cfg(test)] +mod tests { + use super::MetaDeploy; + use casper_types::TransactionLanesDefinition; + #[test] + fn calculate_lane_id_of_biggest_wasm_should_return_none_on_empty() { + let wasms = vec![]; + assert!(MetaDeploy::calculate_lane_id_of_biggest_wasm(&wasms).is_none()); + } + + #[test] + fn calculate_lane_id_of_biggest_wasm_should_return_biggest() { + let wasms = vec![ + TransactionLanesDefinition { + id: 0, + max_transaction_length: 1, + max_transaction_args_length: 2, + max_transaction_gas_limit: 3, + max_transaction_count: 4, + }, + TransactionLanesDefinition { + id: 1, + max_transaction_length: 10, + max_transaction_args_length: 2, + max_transaction_gas_limit: 3, + max_transaction_count: 4, + }, + ]; + assert_eq!( + MetaDeploy::calculate_lane_id_of_biggest_wasm(&wasms), + Some(1) + ); + let wasms = vec![ + TransactionLanesDefinition { + id: 0, + max_transaction_length: 1, + max_transaction_args_length: 2, + max_transaction_gas_limit: 3, + max_transaction_count: 4, + }, + TransactionLanesDefinition { + id: 1, + max_transaction_length: 10, + max_transaction_args_length: 2, + max_transaction_gas_limit: 3, + max_transaction_count: 4, + }, + TransactionLanesDefinition { + id: 2, + max_transaction_length: 7, + max_transaction_args_length: 2, + max_transaction_gas_limit: 3, + max_transaction_count: 4, + }, + ]; + assert_eq!( + MetaDeploy::calculate_lane_id_of_biggest_wasm(&wasms), + Some(1) + ); + + let wasms = vec![ + TransactionLanesDefinition { + id: 0, + max_transaction_length: 1, + max_transaction_args_length: 2, + max_transaction_gas_limit: 3, + max_transaction_count: 4, + }, + TransactionLanesDefinition { + id: 1, + max_transaction_length: 10, + max_transaction_args_length: 2, + max_transaction_gas_limit: 3, + max_transaction_count: 4, + }, + TransactionLanesDefinition { + id: 2, + max_transaction_length: 70, + max_transaction_args_length: 2, + max_transaction_gas_limit: 3, + max_transaction_count: 4, + }, + ]; + assert_eq!( + MetaDeploy::calculate_lane_id_of_biggest_wasm(&wasms), + Some(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 b5afa8ecdf..e1d016fc7b 100644 --- a/node/src/types/transaction/meta_transaction/meta_transaction_v1.rs +++ b/node/src/types/transaction/meta_transaction/meta_transaction_v1.rs @@ -1,11 +1,12 @@ -use super::transaction_lane::{calculate_transaction_lane, TransactionLane}; +use super::transaction_lane::calculate_transaction_lane; use crate::types::transaction::arg_handling; use casper_types::{ bytesrepr::ToBytes, crypto, Approval, Chainspec, ContractRuntimeTag, Digest, DisplayIter, Gas, HashAddr, InitiatorAddr, InvalidTransaction, InvalidTransactionV1, PricingHandling, PricingMode, TimeDiff, Timestamp, TransactionArgs, TransactionConfig, TransactionEntryPoint, TransactionRuntimeParams, TransactionScheduling, TransactionTarget, TransactionV1, - TransactionV1ExcessiveSizeError, TransactionV1Hash, U512, + TransactionV1Config, TransactionV1ExcessiveSizeError, TransactionV1Hash, AUCTION_LANE_ID, + MINT_LANE_ID, U512, }; use core::fmt::{self, Debug, Display, Formatter}; use datasize::DataSize; @@ -31,7 +32,7 @@ pub struct MetaTransactionV1 { args: TransactionArgs, target: TransactionTarget, entry_point: TransactionEntryPoint, - transaction_lane: TransactionLane, + lane_id: u8, scheduling: TransactionScheduling, approvals: BTreeSet, serialized_length: usize, @@ -45,7 +46,7 @@ pub struct MetaTransactionV1 { impl MetaTransactionV1 { pub fn from_transaction_v1( v1: &TransactionV1, - transaction_config: &TransactionConfig, + transaction_v1_config: &TransactionV1Config, ) -> Result { let args: TransactionArgs = v1.deserialize_field(ARGS_MAP_KEY).map_err(|error| { InvalidTransaction::V1(InvalidTransactionV1::CouldNotDeserializeField { error }) @@ -70,16 +71,15 @@ impl MetaTransactionV1 { let payload_hash = v1.payload_hash()?; let serialized_length = v1.serialized_length(); + let pricing_mode = v1.payload().pricing_mode(); let lane_id = calculate_transaction_lane( &entry_point, &target, - v1.pricing_mode().additional_computation_factor(), - transaction_config, + pricing_mode, + transaction_v1_config, serialized_length as u64, )?; - let transaction_lane = - TransactionLane::try_from(lane_id).map_err(Into::::into)?; let has_valid_hash = v1.has_valid_hash(); let approvals = v1.approvals().clone(); Ok(MetaTransactionV1::new( @@ -92,7 +92,7 @@ impl MetaTransactionV1 { args, target, entry_point, - transaction_lane, + lane_id, scheduling, serialized_length, payload_hash, @@ -102,11 +102,11 @@ impl MetaTransactionV1 { } fn is_native_mint(&self) -> bool { - self.transaction_lane == TransactionLane::Mint + self.lane_id == MINT_LANE_ID } fn is_native_auction(&self) -> bool { - self.transaction_lane == TransactionLane::Auction + self.lane_id == AUCTION_LANE_ID } pub(crate) fn is_v2_wasm(&self) -> bool { @@ -140,7 +140,7 @@ impl MetaTransactionV1 { args: TransactionArgs, target: TransactionTarget, entry_point: TransactionEntryPoint, - transaction_lane: TransactionLane, + lane_id: u8, scheduling: TransactionScheduling, serialized_length: usize, payload_hash: Digest, @@ -157,7 +157,7 @@ impl MetaTransactionV1 { args, target, entry_point, - transaction_lane, + lane_id, scheduling, approvals, serialized_length, @@ -236,8 +236,8 @@ impl MetaTransactionV1 { } /// Returns the transaction lane. - pub fn transaction_lane(&self) -> u8 { - self.transaction_lane as u8 + pub fn lane_id(&self) -> u8 { + self.lane_id } /// Returns payload hash of the transaction. @@ -367,7 +367,7 @@ impl MetaTransactionV1 { self.is_valid_size( transaction_config .transaction_v1_config - .get_max_serialized_length(self.transaction_lane as u8) as u32, + .get_max_serialized_length(self.lane_id) as u32, )?; let chain_name = chainspec.network_config.name.clone(); @@ -382,7 +382,7 @@ impl MetaTransactionV1 { initiator_addr= %self.initiator_addr, target= %self.target, entry_point= %self.entry_point, - transaction_lane= %self.transaction_lane, + lane_id= %self.lane_id, scheduling= %self.scheduling, "invalid chain identifier" ); @@ -451,7 +451,7 @@ impl MetaTransactionV1 { let gas_limit = self .pricing_mode - .gas_limit(chainspec, &self.entry_point, self.transaction_lane as u8) + .gas_limit(chainspec, &self.entry_point, self.lane_id) .map_err(Into::::into)?; let block_gas_limit = Gas::new(U512::from(transaction_config.block_gas_limit)); if gas_limit > block_gas_limit { @@ -473,7 +473,7 @@ impl MetaTransactionV1 { &self, config: &TransactionConfig, ) -> Result<(), InvalidTransactionV1> { - let lane_id = self.transaction_lane as u8; + let lane_id = self.lane_id; if !config.transaction_v1_config.is_supported(lane_id) { return Err(InvalidTransactionV1::InvalidTransactionLane(lane_id)); } @@ -667,7 +667,7 @@ impl MetaTransactionV1 { /// Returns the gas limit for the transaction. pub fn gas_limit(&self, chainspec: &Chainspec) -> Result { self.pricing_mode() - .gas_limit(chainspec, self.entry_point(), self.transaction_lane as u8) + .gas_limit(chainspec, self.entry_point(), self.lane_id) .map_err(Into::into) } @@ -713,7 +713,7 @@ impl Display for MetaTransactionV1 { fn fmt(&self, formatter: &mut Formatter) -> fmt::Result { write!( formatter, - "meta-transaction-v1[hash: {}, chain_name: {}, timestamp: {}, ttl: {}, pricing_mode: {}, initiator_addr: {}, target: {}, entry_point: {}, transaction_lane: {}, scheduling: {}, approvals: {}]", + "meta-transaction-v1[hash: {}, chain_name: {}, timestamp: {}, ttl: {}, pricing_mode: {}, initiator_addr: {}, target: {}, entry_point: {}, lane_id: {}, scheduling: {}, approvals: {}]", self.hash, self.chain_name, self.timestamp, @@ -722,9 +722,180 @@ impl Display for MetaTransactionV1 { self.initiator_addr, self.target, self.entry_point, - self.transaction_lane, + self.lane_id, self.scheduling, DisplayIter::new(self.approvals.iter()) ) } } + +#[cfg(test)] +mod tests { + use super::MetaTransactionV1; + use crate::types::transaction::transaction_v1_builder::TransactionV1Builder; + use casper_types::{ + testing::TestRng, InvalidTransaction, InvalidTransactionV1, PricingMode, SecretKey, + TransactionInvocationTarget, TransactionLanesDefinition, TransactionRuntimeParams, + TransactionV1Config, + }; + + #[test] + fn limited_amount_should_determine_transaction_lane_for_session() { + let rng = &mut TestRng::new(); + let secret_key = SecretKey::random(rng); + let pricing_mode = PricingMode::PaymentLimited { + payment_amount: 1001, + gas_price_tolerance: 1, + standard_payment: true, + }; + + let transaction_v1 = TransactionV1Builder::new_session( + false, + vec![1; 30].into(), + TransactionRuntimeParams::VmCasperV1, + ) + .with_chain_name("x".to_string()) + .with_pricing_mode(pricing_mode) + .with_secret_key(&secret_key) + .build() + .unwrap(); + let config = build_v1_config(); + + let meta_transaction = MetaTransactionV1::from_transaction_v1(&transaction_v1, &config) + .expect("meta transaction should be valid"); + assert_eq!(meta_transaction.lane_id(), 4); + } + + #[test] + fn limited_amount_should_fail_if_does_not_fit_in_any_lane() { + let rng = &mut TestRng::new(); + let secret_key = SecretKey::random(rng); + let pricing_mode = PricingMode::PaymentLimited { + payment_amount: 1000000, + gas_price_tolerance: 1, + standard_payment: true, + }; + + let transaction_v1 = TransactionV1Builder::new_session( + false, + vec![1; 30].into(), + TransactionRuntimeParams::VmCasperV1, + ) + .with_chain_name("x".to_string()) + .with_pricing_mode(pricing_mode) + .with_secret_key(&secret_key) + .build() + .unwrap(); + let config = build_v1_config(); + + let res = MetaTransactionV1::from_transaction_v1(&transaction_v1, &config); + assert!(matches!( + res, + Err(InvalidTransaction::V1( + InvalidTransactionV1::NoWasmLaneMatchesTransaction() + )) + )) + } + + #[test] + fn limited_amount_should_fail_if_transaction_size_does_not_fit_in_any_lane() { + let rng = &mut TestRng::new(); + let secret_key = SecretKey::random(rng); + let pricing_mode = PricingMode::PaymentLimited { + payment_amount: 100, + gas_price_tolerance: 1, + standard_payment: true, + }; + + let transaction_v1 = TransactionV1Builder::new_session( + false, + vec![1; 3000].into(), + TransactionRuntimeParams::VmCasperV1, + ) + .with_chain_name("x".to_string()) + .with_pricing_mode(pricing_mode) + .with_secret_key(&secret_key) + .build() + .unwrap(); + let mut config = TransactionV1Config::default(); + config.set_wasm_lanes(vec![ + TransactionLanesDefinition { + id: 3, + max_transaction_length: 200, + max_transaction_args_length: 100, + max_transaction_gas_limit: 100, + max_transaction_count: 10, + }, + TransactionLanesDefinition { + id: 4, + max_transaction_length: 500, + max_transaction_args_length: 100, + max_transaction_gas_limit: 10000, + max_transaction_count: 10, + }, + ]); + + let res = MetaTransactionV1::from_transaction_v1(&transaction_v1, &config); + assert!(matches!( + res, + Err(InvalidTransaction::V1( + InvalidTransactionV1::NoWasmLaneMatchesTransaction() + )) + )) + } + + #[test] + fn limited_amount_should_determine_transaction_lane_for_stored() { + let rng = &mut TestRng::new(); + let secret_key = SecretKey::random(rng); + let pricing_mode = PricingMode::PaymentLimited { + payment_amount: 1001, + gas_price_tolerance: 1, + standard_payment: true, + }; + + let transaction_v1 = TransactionV1Builder::new_targeting_stored( + TransactionInvocationTarget::ByName("xyz".to_string()), + "abc", + TransactionRuntimeParams::VmCasperV1, + ) + .with_chain_name("x".to_string()) + .with_secret_key(&secret_key) + .with_pricing_mode(pricing_mode) + .build() + .unwrap(); + let config = build_v1_config(); + + let meta_transaction = MetaTransactionV1::from_transaction_v1(&transaction_v1, &config) + .expect("meta transaction should be valid"); + assert_eq!(meta_transaction.lane_id(), 4); + } + + fn build_v1_config() -> TransactionV1Config { + let mut config = TransactionV1Config::default(); + config.set_wasm_lanes(vec![ + TransactionLanesDefinition { + id: 3, + max_transaction_length: 10000, + max_transaction_args_length: 100, + max_transaction_gas_limit: 100, + max_transaction_count: 10, + }, + TransactionLanesDefinition { + id: 4, + max_transaction_length: 10001, + max_transaction_args_length: 100, + max_transaction_gas_limit: 10000, + max_transaction_count: 10, + }, + TransactionLanesDefinition { + id: 5, + max_transaction_length: 10002, + max_transaction_args_length: 100, + max_transaction_gas_limit: 1000, + max_transaction_count: 10, + }, + ]); + config + } +} diff --git a/node/src/types/transaction/meta_transaction/transaction_lane.rs b/node/src/types/transaction/meta_transaction/transaction_lane.rs index 66cbc54db1..7f6f3b15a1 100644 --- a/node/src/types/transaction/meta_transaction/transaction_lane.rs +++ b/node/src/types/transaction/meta_transaction/transaction_lane.rs @@ -1,79 +1,15 @@ -use core::{ - convert::TryFrom, - fmt::{self, Formatter}, -}; - use casper_types::{ - InvalidTransaction, InvalidTransactionV1, TransactionConfig, TransactionEntryPoint, - TransactionRuntimeParams, TransactionTarget, TransactionV1Config, AUCTION_LANE_ID, - INSTALL_UPGRADE_LANE_ID, MINT_LANE_ID, + InvalidTransactionV1, PricingMode, TransactionEntryPoint, TransactionRuntimeParams, + TransactionTarget, TransactionV1Config, AUCTION_LANE_ID, INSTALL_UPGRADE_LANE_ID, MINT_LANE_ID, }; -use datasize::DataSize; -use serde::Serialize; - -/// The category of a Transaction. -#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Serialize, DataSize)] -#[repr(u8)] -pub enum TransactionLane { - /// Native mint interaction (the default). - Mint = 0, - /// Native auction interaction. - Auction = 1, - /// InstallUpgradeWasm - InstallUpgradeWasm = 2, - /// A large Wasm based transaction. - Large = 3, - /// A medium Wasm based transaction. - Medium = 4, - /// A small Wasm based transaction. - Small = 5, -} - -#[derive(Debug)] -pub struct TransactionLaneConversionError(u8); - -impl From for InvalidTransaction { - fn from(value: TransactionLaneConversionError) -> InvalidTransaction { - InvalidTransaction::V1(InvalidTransactionV1::InvalidTransactionLane(value.0)) - } -} - -impl TryFrom for TransactionLane { - type Error = TransactionLaneConversionError; - - fn try_from(value: u8) -> Result { - match value { - 0 => Ok(Self::Mint), - 1 => Ok(Self::Auction), - 2 => Ok(Self::InstallUpgradeWasm), - 3 => Ok(Self::Large), - 4 => Ok(Self::Medium), - 5 => Ok(Self::Small), - _ => Err(TransactionLaneConversionError(value)), - } - } -} - -impl fmt::Display for TransactionLane { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - match self { - TransactionLane::Mint => write!(f, "Mint"), - TransactionLane::Auction => write!(f, "Auction"), - TransactionLane::Large => write!(f, "Large"), - TransactionLane::Medium => write!(f, "Medium"), - TransactionLane::Small => write!(f, "Small"), - TransactionLane::InstallUpgradeWasm => write!(f, "InstallUpgradeWASM"), - } - } -} /// Calculates the laned based on properties of the transaction pub(crate) fn calculate_transaction_lane( entry_point: &TransactionEntryPoint, target: &TransactionTarget, - additional_computation_factor: u8, - transaction_config: &TransactionConfig, - transaction_size: u64, + pricing_mode: &PricingMode, + config: &TransactionV1Config, + size_estimation: u64, ) -> Result { match target { TransactionTarget::Native => match entry_point { @@ -95,11 +31,9 @@ pub(crate) fn calculate_transaction_lane( } }, TransactionTarget::Stored { .. } => match entry_point { - TransactionEntryPoint::Custom(_) => get_lane_for_non_install_wasm( - &transaction_config.transaction_v1_config, - transaction_size, - additional_computation_factor, - ), + TransactionEntryPoint::Custom(_) => { + get_lane_for_non_install_wasm(config, size_estimation, pricing_mode) + } TransactionEntryPoint::Call | TransactionEntryPoint::Transfer | TransactionEntryPoint::AddBid @@ -125,11 +59,7 @@ pub(crate) fn calculate_transaction_lane( if *is_install_upgrade { Ok(INSTALL_UPGRADE_LANE_ID) } else { - get_lane_for_non_install_wasm( - &transaction_config.transaction_v1_config, - transaction_size, - additional_computation_factor, - ) + get_lane_for_non_install_wasm(config, size_estimation, pricing_mode) } } TransactionEntryPoint::Custom(_) @@ -157,11 +87,7 @@ pub(crate) fn calculate_transaction_lane( if *is_install_upgrade { Ok(INSTALL_UPGRADE_LANE_ID) } else { - get_lane_for_non_install_wasm( - &transaction_config.transaction_v1_config, - transaction_size, - additional_computation_factor, - ) + get_lane_for_non_install_wasm(config, size_estimation, pricing_mode) } } TransactionEntryPoint::Transfer @@ -185,9 +111,18 @@ pub(crate) fn calculate_transaction_lane( fn get_lane_for_non_install_wasm( config: &TransactionV1Config, transaction_size: u64, - additional_computation_factor: u8, + pricing_mode: &PricingMode, ) -> Result { - config - .get_wasm_lane_id(transaction_size, additional_computation_factor) - .ok_or(InvalidTransactionV1::NoWasmLaneMatchesTransaction()) + match pricing_mode { + PricingMode::PaymentLimited { payment_amount, .. } => config + .get_wasm_lane_id_by_payment_limited(*payment_amount, transaction_size) + .ok_or(InvalidTransactionV1::NoWasmLaneMatchesTransaction()), + PricingMode::Fixed { + additional_computation_factor, + .. + } => config + .get_wasm_lane_id_by_size(transaction_size, *additional_computation_factor) + .ok_or(InvalidTransactionV1::NoWasmLaneMatchesTransaction()), + PricingMode::Prepaid { .. } => Err(InvalidTransactionV1::PricingModeNotSupported), + } } diff --git a/node/src/types/transaction/transaction_v1_builder.rs b/node/src/types/transaction/transaction_v1_builder.rs index 5fbcfa0f79..174422022c 100644 --- a/node/src/types/transaction/transaction_v1_builder.rs +++ b/node/src/types/transaction/transaction_v1_builder.rs @@ -176,7 +176,7 @@ impl<'a> TransactionV1Builder<'a> { /// Returns a new `TransactionV1Builder` suitable for building a native transfer transaction. #[cfg(test)] - pub fn new_transfer, T: Into>( + pub(crate) fn new_transfer, T: Into>( amount: A, maybe_source: Option, target: T, @@ -193,7 +193,7 @@ impl<'a> TransactionV1Builder<'a> { /// Returns a new `TransactionV1Builder` suitable for building a native add_bid transaction. #[cfg(test)] - pub fn new_add_bid>( + pub(crate) fn new_add_bid>( public_key: PublicKey, delegation_rate: u8, amount: A, @@ -220,7 +220,7 @@ impl<'a> TransactionV1Builder<'a> { /// Returns a new `TransactionV1Builder` suitable for building a native withdraw_bid /// transaction. #[cfg(test)] - pub fn new_withdraw_bid>( + pub(crate) fn new_withdraw_bid>( public_key: PublicKey, amount: A, ) -> Result { @@ -235,7 +235,7 @@ impl<'a> TransactionV1Builder<'a> { /// Returns a new `TransactionV1Builder` suitable for building a native delegate transaction. #[cfg(test)] - pub fn new_delegate>( + pub(crate) fn new_delegate>( delegator: PublicKey, validator: PublicKey, amount: A, @@ -251,7 +251,7 @@ impl<'a> TransactionV1Builder<'a> { /// Returns a new `TransactionV1Builder` suitable for building a native undelegate transaction. #[cfg(test)] - pub fn new_undelegate>( + pub(crate) fn new_undelegate>( delegator: PublicKey, validator: PublicKey, amount: A, @@ -266,7 +266,7 @@ impl<'a> TransactionV1Builder<'a> { } #[cfg(test)] - fn new_targeting_stored>( + pub(crate) fn new_targeting_stored>( id: TransactionInvocationTarget, entry_point: E, runtime: TransactionRuntimeParams, @@ -283,7 +283,7 @@ impl<'a> TransactionV1Builder<'a> { /// Returns a new `TransactionV1Builder` suitable for building a transaction targeting a stored /// entity. #[cfg(test)] - pub fn new_targeting_invocable_entity>( + pub(crate) fn new_targeting_invocable_entity>( hash: AddressableEntityHash, entry_point: E, runtime: TransactionRuntimeParams, @@ -295,7 +295,7 @@ impl<'a> TransactionV1Builder<'a> { /// Returns a new `TransactionV1Builder` suitable for building a transaction targeting a stored /// entity via its alias. #[cfg(test)] - pub fn new_targeting_invocable_entity_via_alias, E: Into>( + pub(crate) fn new_targeting_invocable_entity_via_alias, E: Into>( alias: A, entry_point: E, runtime: TransactionRuntimeParams, @@ -307,7 +307,7 @@ impl<'a> TransactionV1Builder<'a> { /// Returns a new `TransactionV1Builder` suitable for building a transaction targeting a /// package. #[cfg(test)] - pub fn new_targeting_package>( + pub(crate) fn new_targeting_package>( hash: PackageHash, version: Option, entry_point: E, @@ -320,7 +320,7 @@ impl<'a> TransactionV1Builder<'a> { /// Returns a new `TransactionV1Builder` suitable for building a transaction targeting a /// package via its alias. #[cfg(test)] - pub fn new_targeting_package_via_alias, E: Into>( + pub(crate) fn new_targeting_package_via_alias, E: Into>( alias: A, version: Option, entry_point: E, @@ -332,7 +332,7 @@ impl<'a> TransactionV1Builder<'a> { /// Returns a new `TransactionV1Builder` suitable for building a transaction for running session /// logic, i.e. compiled Wasm. - pub fn new_session( + pub(crate) fn new_session( is_install_upgrade: bool, module_bytes: Bytes, runtime: TransactionRuntimeParams, @@ -357,7 +357,7 @@ impl<'a> TransactionV1Builder<'a> { /// * unsigned by calling `with_no_secret_key` /// * given an invalid approval by calling `with_invalid_approval` #[cfg(test)] - pub fn new_random(rng: &mut TestRng) -> Self { + pub(crate) fn new_random(rng: &mut TestRng) -> Self { let secret_key = SecretKey::random(rng); let ttl_millis = rng.gen_range(60_000..TransactionConfig::default().max_ttl.millis()); let fields = FieldsContainer::random(rng); @@ -384,7 +384,7 @@ impl<'a> TransactionV1Builder<'a> { } #[cfg(test)] - pub fn new_random_with_category_and_timestamp_and_ttl( + pub(crate) fn new_random_with_category_and_timestamp_and_ttl( rng: &mut TestRng, lane: u8, timestamp: Option, @@ -426,7 +426,7 @@ impl<'a> TransactionV1Builder<'a> { /// Sets the `chain_name` in the transaction. /// /// Must be provided or building will fail. - pub fn with_chain_name>(mut self, chain_name: C) -> Self { + pub(crate) fn with_chain_name>(mut self, chain_name: C) -> Self { self.chain_name = Some(chain_name.into()); self } @@ -434,7 +434,7 @@ impl<'a> TransactionV1Builder<'a> { /// Sets the `timestamp` in the transaction. /// /// If not provided, the timestamp will be set to the time when the builder was constructed. - pub fn with_timestamp(mut self, timestamp: Timestamp) -> Self { + pub(crate) fn with_timestamp(mut self, timestamp: Timestamp) -> Self { self.timestamp = timestamp; self } @@ -442,7 +442,7 @@ impl<'a> TransactionV1Builder<'a> { /// Sets the `ttl` (time-to-live) in the transaction. /// /// If not provided, the ttl will be set to [`Self::DEFAULT_TTL`]. - pub fn with_ttl(mut self, ttl: TimeDiff) -> Self { + pub(crate) fn with_ttl(mut self, ttl: TimeDiff) -> Self { self.ttl = ttl; self } @@ -451,7 +451,7 @@ impl<'a> TransactionV1Builder<'a> { /// /// If not provided, the pricing mode will be set to [`Self::DEFAULT_PRICING_MODE`]. #[cfg(test)] - pub fn with_pricing_mode(mut self, pricing_mode: PricingMode) -> Self { + pub(crate) fn with_pricing_mode(mut self, pricing_mode: PricingMode) -> Self { self.pricing_mode = pricing_mode; self } @@ -461,7 +461,7 @@ impl<'a> TransactionV1Builder<'a> { /// If not provided, the public key derived from the secret key used in the builder will be /// used as the `InitiatorAddr::PublicKey` in the transaction. #[cfg(test)] - pub fn with_initiator_addr>(mut self, initiator_addr: I) -> Self { + pub(crate) fn with_initiator_addr>(mut self, initiator_addr: I) -> Self { self.initiator_addr = Some(initiator_addr.into()); self } @@ -470,7 +470,7 @@ impl<'a> TransactionV1Builder<'a> { /// /// If not provided, the transaction can still be built, but will be unsigned and will be /// invalid until subsequently signed. - pub fn with_secret_key(mut self, secret_key: &'a SecretKey) -> Self { + pub(crate) fn with_secret_key(mut self, secret_key: &'a SecretKey) -> Self { #[cfg(not(test))] { self.secret_key = Some(secret_key); @@ -487,7 +487,10 @@ impl<'a> TransactionV1Builder<'a> { /// Manually sets additional fields #[cfg(test)] - pub fn with_additional_fields(mut self, additional_fields: BTreeMap) -> Self { + pub(crate) fn with_additional_fields( + mut self, + additional_fields: BTreeMap, + ) -> Self { self.additional_fields = additional_fields; self } @@ -497,7 +500,7 @@ impl<'a> TransactionV1Builder<'a> { /// NOTE: this overwrites any existing runtime args. To append to existing args, use /// [`TransactionV1Builder::with_runtime_arg`]. #[cfg(test)] - pub fn with_runtime_args(mut self, args: RuntimeArgs) -> Self { + pub(crate) fn with_runtime_args(mut self, args: RuntimeArgs) -> Self { self.args = TransactionArgs::Named(args); self } @@ -514,7 +517,7 @@ impl<'a> TransactionV1Builder<'a> { /// Returns the new transaction, or an error if non-defaulted fields were not set. /// /// For more info, see [the `TransactionBuilder` documentation](TransactionV1Builder). - pub fn build(self) -> Result { + pub(crate) fn build(self) -> Result { self.do_build() } diff --git a/node/src/utils/chain_specification.rs b/node/src/utils/chain_specification.rs index fc5521cfb6..5b8c1c9ae8 100644 --- a/node/src/utils/chain_specification.rs +++ b/node/src/utils/chain_specification.rs @@ -1,16 +1,23 @@ pub(crate) mod error; pub(crate) mod parse_toml; +use std::collections::HashSet; + use num_rational::Ratio; +use once_cell::sync::Lazy; use tracing::{error, info, warn}; use casper_types::{ system::auction::VESTING_SCHEDULE_LENGTH_MILLIS, Chainspec, ConsensusProtocolName, CoreConfig, - ProtocolConfig, TimeDiff, TransactionConfig, + ProtocolConfig, TimeDiff, TransactionConfig, AUCTION_LANE_ID, INSTALL_UPGRADE_LANE_ID, + MINT_LANE_ID, }; use crate::components::network; +static RESERVED_LANE_IDS: Lazy> = + Lazy::new(|| vec![MINT_LANE_ID, AUCTION_LANE_ID, INSTALL_UPGRADE_LANE_ID]); + /// Returns `false` and logs errors if the values set in the config don't make sense. #[tracing::instrument(ret, level = "info", skip(chainspec), fields(hash = % chainspec.hash()))] pub fn validate_chainspec(chainspec: &Chainspec) -> bool { @@ -140,7 +147,42 @@ pub(crate) fn validate_transaction_config(transaction_config: &TransactionConfig let total_txn_slots = transaction_config .transaction_v1_config .get_max_block_count(); - transaction_config.block_max_approval_count >= total_txn_slots as u32 + if transaction_config.block_max_approval_count < total_txn_slots as u32 { + return false; + } + let mut seen_max_transaction_size = HashSet::new(); + if transaction_config + .transaction_v1_config + .wasm_lanes() + .is_empty() + { + error!("Wasm lanes chainspec config is empty."); + return false; + } + for wasm_lane_config in transaction_config.transaction_v1_config.wasm_lanes().iter() { + if RESERVED_LANE_IDS.contains(&wasm_lane_config.id) { + error!("One of the defined wasm lanes has declared an id that is reserved for system lanes. Offending lane id: {}", wasm_lane_config.id); + return false; + } + let max_transaction_length = wasm_lane_config.max_transaction_length; + if seen_max_transaction_size.contains(&max_transaction_length) { + error!("Found wasm lane configuration that has non-unique max_transaction_length. Duplicate value: {}", max_transaction_length); + return false; + } + seen_max_transaction_size.insert(max_transaction_length); + } + + let mut seen_max_gas_prices = HashSet::new(); + for wasm_lane_config in transaction_config.transaction_v1_config.wasm_lanes().iter() { + //No need to check reserved lanes, we just did that + let max_transaction_gas_limit = wasm_lane_config.max_transaction_gas_limit; + if seen_max_gas_prices.contains(&max_transaction_gas_limit) { + error!("Found wasm lane configuration that has non-unique max_transaction_gas_limit. Duplicate value: {}", max_transaction_gas_limit); + return false; + } + seen_max_gas_prices.insert(max_transaction_gas_limit); + } + true } #[cfg(test)] @@ -154,8 +196,8 @@ mod tests { bytesrepr::FromBytes, ActivationPoint, BrTableCost, ChainspecRawBytes, ControlFlowCosts, CoreConfig, EraId, GlobalStateUpdate, HighwayConfig, HostFunction, HostFunctionCosts, MessageLimits, Motes, OpcodeCosts, ProtocolConfig, ProtocolVersion, StoredValue, - TestBlockBuilder, TimeDiff, Timestamp, TransactionConfig, TransactionV1Config, WasmConfig, - WasmV1Config, MINT_LANE_ID, + TestBlockBuilder, TimeDiff, Timestamp, TransactionConfig, TransactionLanesDefinition, + TransactionV1Config, WasmConfig, WasmV1Config, MINT_LANE_ID, }; use super::*; @@ -654,4 +696,135 @@ mod tests { let (chainspec, _) = <(Chainspec, ChainspecRawBytes)>::from_resources("test/valid/1_0_0"); check_spec(chainspec, false); } + + #[test] + fn should_fail_when_wasm_lanes_have_duplicate_max_transaction_length() { + let mut v1_config = TransactionV1Config::default(); + let definition_1 = TransactionLanesDefinition { + id: 3, + max_transaction_length: 100, + max_transaction_args_length: 100, + max_transaction_gas_limit: 100, + max_transaction_count: 10, + }; + let definition_2 = TransactionLanesDefinition { + id: 4, + max_transaction_length: 10000, + max_transaction_args_length: 100, + max_transaction_gas_limit: 101, + max_transaction_count: 10, + }; + let definition_3 = TransactionLanesDefinition { + id: 5, + max_transaction_length: 1000, + max_transaction_args_length: 100, + max_transaction_gas_limit: 102, + max_transaction_count: 10, + }; + v1_config.set_wasm_lanes(vec![ + definition_1.clone(), + definition_2.clone(), + definition_3.clone(), + ]); + let transaction_config = TransactionConfig { + transaction_v1_config: v1_config.clone(), + ..Default::default() + }; + assert!(validate_transaction_config(&transaction_config)); + let mut definition_2 = definition_2.clone(); + definition_2.max_transaction_length = definition_1.max_transaction_length; + v1_config.set_wasm_lanes(vec![ + definition_1.clone(), + definition_2.clone(), + definition_3.clone(), + ]); + let transaction_config = TransactionConfig { + transaction_v1_config: v1_config, + ..Default::default() + }; + assert!(!validate_transaction_config(&transaction_config)); + } + + #[test] + fn should_fail_when_wasm_lanes_have_duplicate_max_gas_price() { + let mut v1_config = TransactionV1Config::default(); + let definition_1 = TransactionLanesDefinition { + id: 3, + max_transaction_length: 100, + max_transaction_args_length: 100, + max_transaction_gas_limit: 100, + max_transaction_count: 10, + }; + let definition_2 = TransactionLanesDefinition { + id: 4, + max_transaction_length: 10000, + max_transaction_args_length: 100, + max_transaction_gas_limit: 101, + max_transaction_count: 10, + }; + let definition_3 = TransactionLanesDefinition { + id: 5, + max_transaction_length: 1000, + max_transaction_args_length: 100, + max_transaction_gas_limit: 102, + max_transaction_count: 10, + }; + v1_config.set_wasm_lanes(vec![ + definition_1.clone(), + definition_2.clone(), + definition_3.clone(), + ]); + let transaction_config = TransactionConfig { + transaction_v1_config: v1_config.clone(), + ..Default::default() + }; + assert!(validate_transaction_config(&transaction_config)); + let mut definition_2 = definition_2.clone(); + definition_2.max_transaction_gas_limit = definition_1.max_transaction_gas_limit; + v1_config.set_wasm_lanes(vec![ + definition_1.clone(), + definition_2.clone(), + definition_3.clone(), + ]); + let transaction_config = TransactionConfig { + transaction_v1_config: v1_config, + ..Default::default() + }; + assert!(!validate_transaction_config(&transaction_config)); + } + + #[test] + fn should_fail_when_wasm_lanes_have_reseved_ids() { + fail_validation_with_lane_id(MINT_LANE_ID); + fail_validation_with_lane_id(AUCTION_LANE_ID); + fail_validation_with_lane_id(INSTALL_UPGRADE_LANE_ID); + } + + fn fail_validation_with_lane_id(lane_id: u8) { + let mut v1_config = TransactionV1Config::default(); + let definition_1 = TransactionLanesDefinition { + id: lane_id, + max_transaction_length: 100, + max_transaction_args_length: 100, + max_transaction_gas_limit: 100, + max_transaction_count: 10, + }; + v1_config.set_wasm_lanes(vec![definition_1.clone()]); + let transaction_config = TransactionConfig { + transaction_v1_config: v1_config.clone(), + ..Default::default() + }; + assert!(!validate_transaction_config(&transaction_config)); + } + + #[test] + fn should_valid_no_wasm_lanes() { + let mut v1_config = TransactionV1Config::default(); + v1_config.set_wasm_lanes(vec![]); + let transaction_config = TransactionConfig { + transaction_v1_config: v1_config.clone(), + ..Default::default() + }; + assert!(!validate_transaction_config(&transaction_config)); + } } diff --git a/node/src/utils/specimen.rs b/node/src/utils/specimen.rs index a411c4dc0a..7a0fcf1224 100644 --- a/node/src/utils/specimen.rs +++ b/node/src/utils/specimen.rs @@ -28,8 +28,7 @@ use casper_types::{ ProtocolVersion, RewardedSignatures, RuntimeArgs, SecretKey, SemVer, SignedBlockHeader, SingleBlockRewardedSignatures, TimeDiff, Timestamp, Transaction, TransactionHash, TransactionId, TransactionRuntimeParams, TransactionV1, TransactionV1Hash, URef, - AUCTION_LANE_ID, INSTALL_UPGRADE_LANE_ID, KEY_HASH_LENGTH, LARGE_WASM_LANE_ID, MINT_LANE_ID, - U512, + AUCTION_LANE_ID, INSTALL_UPGRADE_LANE_ID, KEY_HASH_LENGTH, MINT_LANE_ID, U512, }; use crate::{ @@ -859,7 +858,7 @@ impl LargestSpecimen for BlockPayload { ], ); transactions.insert( - LARGE_WASM_LANE_ID, + 3, vec![ large_txn_hash_with_approvals.clone(); estimator.parameter::("max_standard_transactions_per_block") diff --git a/types/src/block/test_block_builder/test_block_v2_builder.rs b/types/src/block/test_block_builder/test_block_v2_builder.rs index d2c268a2f1..d23490a585 100644 --- a/types/src/block/test_block_builder/test_block_v2_builder.rs +++ b/types/src/block/test_block_builder/test_block_v2_builder.rs @@ -248,7 +248,7 @@ impl TestBlockV2Builder { // A simplified way of calculating transaction lanes. It doesn't take // into consideration the size of the transaction against the chainspec -// and doesn't take `additional_compufsdetation_factor` into consideration. +// and doesn't take `additional_computation_factor` into consideration. // This is only used for tests purposes. fn simplified_calculate_transaction_lane_from_values( entry_point: &TransactionEntryPoint, diff --git a/types/src/chainspec.rs b/types/src/chainspec.rs index d421f4fd92..a4108ffa41 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, TransactionLimitsDefinition, TransactionV1Config, + DeployConfig, TransactionConfig, TransactionLanesDefinition, 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 d80e9aeb84..7443ea3cd7 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::{TransactionLimitsDefinition, TransactionV1Config}; +pub use transaction_v1_config::{TransactionLanesDefinition, 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 d423bb225d..09d31ecf7d 100644 --- a/types/src/chainspec/transaction_config/transaction_v1_config.rs +++ b/types/src/chainspec/transaction_config/transaction_v1_config.rs @@ -35,10 +35,10 @@ 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 TransactionLimitsDefinition { +pub struct TransactionLanesDefinition { /// The lane identifier pub id: u8, - /// The maximum length of a transaction i bytes + /// The maximum length of a transaction in bytes pub max_transaction_length: u64, /// The maximum number of runtime args pub max_transaction_args_length: u64, @@ -48,14 +48,14 @@ pub struct TransactionLimitsDefinition { pub max_transaction_count: u64, } -impl TryFrom> for TransactionLimitsDefinition { +impl TryFrom> for TransactionLanesDefinition { type Error = TransactionConfigError; fn try_from(v: Vec) -> Result { if v.len() != 5 { return Err(TransactionConfigError::InvalidArgsProvided); } - Ok(TransactionLimitsDefinition { + Ok(TransactionLanesDefinition { 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 TransactionLimitsDefinition { } } -impl TransactionLimitsDefinition { +impl TransactionLanesDefinition { /// Creates a new instance of TransactionLimitsDefinition pub fn new( id: u8, @@ -135,32 +135,39 @@ pub struct TransactionV1Config { deserialize_with = "vec_to_limit_definition" )] /// Lane configuration of the native mint interaction. - pub native_mint_lane: TransactionLimitsDefinition, + pub native_mint_lane: TransactionLanesDefinition, #[serde( serialize_with = "limit_definition_to_vec", deserialize_with = "vec_to_limit_definition" )] /// Lane configuration for the native auction interaction. - pub native_auction_lane: TransactionLimitsDefinition, + pub native_auction_lane: TransactionLanesDefinition, #[serde( serialize_with = "limit_definition_to_vec", deserialize_with = "vec_to_limit_definition" )] /// Lane configuration for the install/upgrade interaction. - pub install_upgrade_lane: TransactionLimitsDefinition, + pub install_upgrade_lane: TransactionLanesDefinition, #[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. - pub 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>, } impl PartialEq for TransactionV1Config { @@ -173,6 +180,8 @@ impl PartialEq for TransactionV1Config { wasm_lanes, #[cfg(any(feature = "once_cell", test))] wasm_lanes_ordered_by_transaction_size: _, + #[cfg(any(feature = "once_cell", test))] + wasm_lanes_ordered_by_transaction_gas_limit: _, } = self; *native_mint_lane == other.native_mint_lane && *native_auction_lane == other.native_auction_lane @@ -184,15 +193,19 @@ impl PartialEq for TransactionV1Config { impl TransactionV1Config { /// Cretaes a new instance of TransactionV1Config pub fn new( - native_mint_lane: TransactionLimitsDefinition, - native_auction_lane: TransactionLimitsDefinition, - install_upgrade_lane: TransactionLimitsDefinition, - wasm_lanes: Vec, + native_mint_lane: TransactionLanesDefinition, + native_auction_lane: TransactionLanesDefinition, + install_upgrade_lane: TransactionLanesDefinition, + wasm_lanes: Vec, ) -> Self { #[cfg(any(feature = "once_cell", test))] let wasm_lanes_ordered_by_transaction_size = OnceCell::with_value( Self::build_wasm_lanes_ordered_by_transaction_size(wasm_lanes.clone()), ); + #[cfg(any(feature = "once_cell", test))] + let wasm_lanes_ordered_by_transaction_gas_limit = OnceCell::with_value( + Self::build_wasm_lanes_ordered_by_transaction_gas_limit(wasm_lanes.clone()), + ); TransactionV1Config { native_mint_lane, native_auction_lane, @@ -200,6 +213,8 @@ impl TransactionV1Config { wasm_lanes, #[cfg(any(feature = "once_cell", test))] wasm_lanes_ordered_by_transaction_size, + #[cfg(any(feature = "once_cell", test))] + wasm_lanes_ordered_by_transaction_gas_limit, } } @@ -354,13 +369,13 @@ impl TransactionV1Config { /// Returns a wasm lane id based on the transaction size adjusted by /// maybe_additional_computation_factor if necessary. - pub fn get_wasm_lane_id( + pub fn get_wasm_lane_id_by_size( &self, transaction_size: u64, additional_computation_factor: u8, ) -> Option { let mut maybe_adequate_lane_index = None; - let buckets = self.get_wasm_lanes_ordered(); + let buckets = self.get_wasm_lanes_ordered_by_transaction_size(); let number_of_lanes = buckets.len(); for (i, lane) in buckets.iter().enumerate() { let lane_size = lane.max_transaction_length; @@ -378,10 +393,28 @@ impl TransactionV1Config { maybe_adequate_lane_index.map(|index| buckets[index].id) } + pub fn get_wasm_lane_id_by_payment_limited( + &self, + gas_limit: u64, + transaction_size: u64, + ) -> Option { + let mut maybe_adequate_lane_index = None; + let lanes = self.get_wasm_lanes_ordered_by_gas_limit(); + for (i, lane) in lanes.iter().enumerate() { + let max_transaction_gas = lane.max_transaction_gas_limit; + let max_transaction_size = lane.max_transaction_length; + if max_transaction_gas >= gas_limit && max_transaction_size >= transaction_size { + maybe_adequate_lane_index = Some(i); + break; + } + } + maybe_adequate_lane_index.map(|index| lanes[index].id) + } + #[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(&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()) @@ -389,13 +422,57 @@ impl TransactionV1Config { &Self::build_wasm_lanes_ordered_by_transaction_size(self.wasm_lanes.clone()) } + #[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 { + #[cfg(any(feature = "once_cell", test))] + return self + .wasm_lanes_ordered_by_transaction_gas_limit + .get_or_init(|| { + Self::build_wasm_lanes_ordered_by_transaction_gas_limit(self.wasm_lanes.clone()) + }); + &Self::build_wasm_lanes_ordered_by_transaction_gas_limit(self.wasm_lanes.clone()) + } + + fn build_wasm_lanes_ordered_by_transaction_gas_limit( + wasm_lanes: Vec, + ) -> Vec { + let mut ordered = wasm_lanes; + ordered.sort_by(|a, b| { + a.max_transaction_gas_limit + .cmp(&b.max_transaction_gas_limit) + }); + ordered + } + fn build_wasm_lanes_ordered_by_transaction_size( - wasm_lanes: Vec, - ) -> Vec { - let mut wasm_lanes_ordered_by_transaction_size = wasm_lanes; - wasm_lanes_ordered_by_transaction_size - .sort_by(|a, b| a.max_transaction_length.cmp(&b.max_transaction_length)); - wasm_lanes_ordered_by_transaction_size + 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 { + &self.wasm_lanes + } + + #[cfg(any(feature = "testing", test))] + pub fn set_wasm_lanes(&mut self, wasm_lanes: Vec) { + self.wasm_lanes = wasm_lanes; + #[cfg(any(feature = "once_cell", test))] + { + let wasm_lanes_ordered_by_transaction_size = OnceCell::with_value( + Self::build_wasm_lanes_ordered_by_transaction_size(self.wasm_lanes.clone()), + ); + self.wasm_lanes_ordered_by_transaction_size = wasm_lanes_ordered_by_transaction_size; + let wasm_lanes_ordered_by_transaction_gas_limit = OnceCell::with_value( + Self::build_wasm_lanes_ordered_by_transaction_gas_limit(self.wasm_lanes.clone()), + ); + self.wasm_lanes_ordered_by_transaction_gas_limit = + wasm_lanes_ordered_by_transaction_gas_limit; + } } } @@ -414,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( @@ -434,7 +511,7 @@ impl ToBytes for TransactionV1Config { let wasm_lanes_as_vecs: Vec> = self .wasm_lanes .iter() - .map(TransactionLimitsDefinition::as_vec) + .map(TransactionLanesDefinition::as_vec) .collect(); wasm_lanes_as_vecs.write_bytes(writer) } @@ -449,7 +526,7 @@ impl ToBytes for TransactionV1Config { let wasm_lanes_as_vecs: Vec> = self .wasm_lanes .iter() - .map(TransactionLimitsDefinition::as_vec) + .map(TransactionLanesDefinition::as_vec) .collect(); self.native_mint_lane.as_vec().serialized_length() + self.native_auction_lane.as_vec().serialized_length() @@ -475,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, @@ -487,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 = TransactionLimitsDefinition::try_from(vec).map_err(|_| { + let limits = TransactionLanesDefinition::try_from(vec).map_err(|_| { D::Error::invalid_value( Unexpected::Seq, &"expected 5 u64 compliant numbers to create a TransactionLimitsDefinition", @@ -502,7 +579,7 @@ where } fn limit_definition_to_vec( - limits: &TransactionLimitsDefinition, + limits: &TransactionLanesDefinition, serializer: S, ) -> Result where @@ -516,14 +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( @@ -534,7 +609,7 @@ where } fn wasm_definitions_to_vec( - limits: &[TransactionLimitsDefinition], + limits: &[TransactionLanesDefinition], serializer: S, ) -> Result where @@ -579,20 +654,20 @@ mod tests { #[test] fn should_get_configuration_for_wasm() { let config = build_example_transaction_config(); - let got = config.get_wasm_lane_id(100, 0); + let got = config.get_wasm_lane_id_by_size(100, 0); assert_eq!(got, Some(3)); let config = build_example_transaction_config_reverse_wasm_ids(); - let got = config.get_wasm_lane_id(100, 0); + let got = config.get_wasm_lane_id_by_size(100, 0); assert_eq!(got, Some(5)); } #[test] fn given_too_big_transaction_should_return_none() { let config = build_example_transaction_config(); - let got = config.get_wasm_lane_id(100000000, 0); + let got = config.get_wasm_lane_id_by_size(100000000, 0); assert!(got.is_none()); let config = build_example_transaction_config_reverse_wasm_ids(); - let got = config.get_wasm_lane_id(100000000, 0); + let got = config.get_wasm_lane_id_by_size(100000000, 0); assert!(got.is_none()); } @@ -600,75 +675,180 @@ mod tests { fn given_wasm_should_return_first_fit() { let config = build_example_transaction_config(); - let got = config.get_wasm_lane_id(660, 0); + let got = config.get_wasm_lane_id_by_size(660, 0); assert_eq!(got, Some(4)); - let got = config.get_wasm_lane_id(800, 0); + let got = config.get_wasm_lane_id_by_size(800, 0); assert_eq!(got, Some(5)); - let got = config.get_wasm_lane_id(1, 0); + let got = config.get_wasm_lane_id_by_size(1, 0); assert_eq!(got, Some(3)); let config = build_example_transaction_config_reverse_wasm_ids(); - let got = config.get_wasm_lane_id(660, 0); + let got = config.get_wasm_lane_id_by_size(660, 0); assert_eq!(got, Some(4)); - let got = config.get_wasm_lane_id(800, 0); + let got = config.get_wasm_lane_id_by_size(800, 0); assert_eq!(got, Some(3)); - let got = config.get_wasm_lane_id(1, 0); + let got = config.get_wasm_lane_id_by_size(1, 0); assert_eq!(got, Some(5)); } #[test] fn given_additional_computation_factor_should_be_applied() { let config = build_example_transaction_config(); - let got = config.get_wasm_lane_id(660, 1); + let got = config.get_wasm_lane_id_by_size(660, 1); assert_eq!(got, Some(5)); let config = build_example_transaction_config_reverse_wasm_ids(); - let got = config.get_wasm_lane_id(660, 1); + let got = config.get_wasm_lane_id_by_size(660, 1); assert_eq!(got, Some(3)); } #[test] fn given_additional_computation_factor_should_not_overflow() { let config = build_example_transaction_config(); - let got = config.get_wasm_lane_id(660, 2); + let got = config.get_wasm_lane_id_by_size(660, 2); assert_eq!(got, Some(5)); - let got_2 = config.get_wasm_lane_id(660, 20); + let got_2 = config.get_wasm_lane_id_by_size(660, 20); assert_eq!(got_2, Some(5)); let config = build_example_transaction_config_reverse_wasm_ids(); - let got = config.get_wasm_lane_id(660, 2); + let got = config.get_wasm_lane_id_by_size(660, 2); assert_eq!(got, Some(3)); - let got_2 = config.get_wasm_lane_id(660, 20); + let got_2 = config.get_wasm_lane_id_by_size(660, 20); assert_eq!(got_2, Some(3)); } #[test] fn given_no_wasm_lanes_should_return_none() { let config = build_example_transaction_config_no_wasms(); - let got = config.get_wasm_lane_id(660, 2); + let got = config.get_wasm_lane_id_by_size(660, 2); assert!(got.is_none()); - let got = config.get_wasm_lane_id(660, 0); + let got = config.get_wasm_lane_id_by_size(660, 0); assert!(got.is_none()); - let got = config.get_wasm_lane_id(660, 20); + let got = config.get_wasm_lane_id_by_size(660, 20); assert!(got.is_none()); + + let got = config.get_wasm_lane_id_by_payment_limited(100, 1); + assert!(got.is_none()); + } + + #[test] + fn given_wasm_when_by_payment_should_find_smallest_lane() { + let config = TransactionV1Config::new( + example_native(), + example_auction(), + example_install_upgrade(), + vec![ + TransactionLanesDefinition { + id: 3, + max_transaction_length: 10, + max_transaction_args_length: 1, + max_transaction_gas_limit: 5, + max_transaction_count: 1, + }, + TransactionLanesDefinition { + id: 4, + max_transaction_length: 11, + max_transaction_args_length: 1, + max_transaction_gas_limit: 55, + max_transaction_count: 1, + }, + TransactionLanesDefinition { + id: 5, + max_transaction_length: 12, + max_transaction_args_length: 1, + max_transaction_gas_limit: 155, + max_transaction_count: 1, + }, + ], + ); + let got = config.get_wasm_lane_id_by_payment_limited(54, 1); + assert_eq!(got, Some(4)); + } + + #[test] + fn given_wasm_when_by_payment_should_take_size_into_consideration() { + let config = TransactionV1Config::new( + example_native(), + example_auction(), + example_install_upgrade(), + vec![ + TransactionLanesDefinition { + id: 3, + max_transaction_length: 10, + max_transaction_args_length: 1, + max_transaction_gas_limit: 5, + max_transaction_count: 1, + }, + TransactionLanesDefinition { + id: 4, + max_transaction_length: 11, + max_transaction_args_length: 1, + max_transaction_gas_limit: 55, + max_transaction_count: 1, + }, + TransactionLanesDefinition { + id: 5, + max_transaction_length: 12, + max_transaction_args_length: 1, + max_transaction_gas_limit: 155, + max_transaction_count: 1, + }, + ], + ); + let got = config.get_wasm_lane_id_by_payment_limited(54, 12); + assert_eq!(got, Some(5)); + } + + #[test] + fn given_wasm_when_by_payment_should_return_none_if_no_size_fits() { + let config = TransactionV1Config::new( + example_native(), + example_auction(), + example_install_upgrade(), + vec![ + TransactionLanesDefinition { + id: 3, + max_transaction_length: 10, + max_transaction_args_length: 1, + max_transaction_gas_limit: 5, + max_transaction_count: 1, + }, + TransactionLanesDefinition { + id: 4, + max_transaction_length: 11, + max_transaction_args_length: 1, + max_transaction_gas_limit: 55, + max_transaction_count: 1, + }, + TransactionLanesDefinition { + id: 5, + max_transaction_length: 12, + max_transaction_args_length: 1, + max_transaction_gas_limit: 155, + max_transaction_count: 1, + }, + ], + ); + let got = config.get_wasm_lane_id_by_payment_limited(54, 120); + assert_eq!(got, None); } #[test] fn should_deserialize() { let got: TransactionV1Config = serde_json::from_str(EXAMPLE_JSON).unwrap(); let expected = TransactionV1Config::new( - TransactionLimitsDefinition::new(0, 1, 2, 3, 4), - TransactionLimitsDefinition::new(1, 5, 6, 7, 8), - TransactionLimitsDefinition::new(2, 9, 10, 11, 12), + TransactionLanesDefinition::new(0, 1, 2, 3, 4), + TransactionLanesDefinition::new(1, 5, 6, 7, 8), + TransactionLanesDefinition::new(2, 9, 10, 11, 12), vec![ - TransactionLimitsDefinition::new(3, 13, 14, 15, 16), - TransactionLimitsDefinition::new(4, 17, 18, 19, 20), - TransactionLimitsDefinition::new(5, 21, 22, 23, 24), + TransactionLanesDefinition::new(3, 13, 14, 15, 16), + TransactionLanesDefinition::new(4, 17, 18, 19, 20), + TransactionLanesDefinition::new(5, 21, 22, 23, 24), ], ); assert_eq!(got, expected); @@ -677,13 +857,13 @@ mod tests { #[test] fn should_serialize() { let input = TransactionV1Config::new( - TransactionLimitsDefinition::new(0, 1, 2, 3, 4), - TransactionLimitsDefinition::new(1, 5, 6, 7, 8), - TransactionLimitsDefinition::new(2, 9, 10, 11, 12), + TransactionLanesDefinition::new(0, 1, 2, 3, 4), + TransactionLanesDefinition::new(1, 5, 6, 7, 8), + TransactionLanesDefinition::new(2, 9, 10, 11, 12), vec![ - TransactionLimitsDefinition::new(3, 13, 14, 15, 16), - TransactionLimitsDefinition::new(4, 17, 18, 19, 20), - TransactionLimitsDefinition::new(5, 21, 22, 23, 24), + TransactionLanesDefinition::new(3, 13, 14, 15, 16), + TransactionLanesDefinition::new(4, 17, 18, 19, 20), + TransactionLanesDefinition::new(5, 21, 22, 23, 24), ], ); let raw = serde_json::to_string(&input).unwrap(); @@ -692,35 +872,35 @@ mod tests { assert_eq!(got, expected); } - fn example_native() -> TransactionLimitsDefinition { - TransactionLimitsDefinition::new(0, 1500, 1024, 1_500_000_000, 150) + fn example_native() -> TransactionLanesDefinition { + TransactionLanesDefinition::new(0, 1500, 1024, 1_500_000_000, 150) } - fn example_auction() -> TransactionLimitsDefinition { - TransactionLimitsDefinition::new(1, 500, 3024, 3_500_000_000, 350) + fn example_auction() -> TransactionLanesDefinition { + TransactionLanesDefinition::new(1, 500, 3024, 3_500_000_000, 350) } - fn example_install_upgrade() -> TransactionLimitsDefinition { - TransactionLimitsDefinition::new(2, 10000, 2024, 2_500_000_000, 250) + fn example_install_upgrade() -> TransactionLanesDefinition { + TransactionLanesDefinition::new(2, 10000, 2024, 2_500_000_000, 250) } - fn wasm_small(id: u8) -> TransactionLimitsDefinition { - TransactionLimitsDefinition::new(id, 600, 4024, 4_500_000_000, 450) + fn wasm_small(id: u8) -> TransactionLanesDefinition { + TransactionLanesDefinition::new(id, 600, 4024, 4_500_000_000, 450) } - fn wasm_medium(id: u8) -> TransactionLimitsDefinition { - TransactionLimitsDefinition::new(id, 700, 5024, 5_500_000_000, 550) + fn wasm_medium(id: u8) -> TransactionLanesDefinition { + TransactionLanesDefinition::new(id, 700, 5024, 5_500_000_000, 550) } - fn wasm_large(id: u8) -> TransactionLimitsDefinition { - TransactionLimitsDefinition::new(id, 800, 6024, 6_500_000_000, 650) + fn wasm_large(id: u8) -> TransactionLanesDefinition { + TransactionLanesDefinition::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/gens.rs b/types/src/gens.rs index 1ba74b984e..168527938f 100644 --- a/types/src/gens.rs +++ b/types/src/gens.rs @@ -1293,11 +1293,6 @@ pub fn pricing_mode_arb() -> impl Strategy { } ), fixed_pricing_mode_arb(), - u8_slice_32().prop_map(|receipt| { - PricingMode::Prepaid { - receipt: receipt.into(), - } - }), ] } diff --git a/types/src/lib.rs b/types/src/lib.rs index fddd2454a2..ab07d01d2e 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, TransactionLimitsDefinition, TransactionV1Config, VacancyConfig, + TransactionConfig, TransactionLanesDefinition, TransactionV1Config, VacancyConfig, ValidatorConfig, WasmConfig, WasmV1Config, DEFAULT_GAS_HOLD_INTERVAL, DEFAULT_HOST_FUNCTION_NEW_DICTIONARY, DEFAULT_MINIMUM_BID_AMOUNT, DEFAULT_REFUND_HANDLING, }; @@ -216,11 +216,11 @@ pub const AUCTION_LANE_ID: u8 = 1; /// The lane identifier for the install/upgrade auction interaction. pub const INSTALL_UPGRADE_LANE_ID: u8 = 2; /// The lane identifier for large wasms. -pub const LARGE_WASM_LANE_ID: u8 = 3; +pub(crate) const LARGE_WASM_LANE_ID: u8 = 3; /// The lane identifier for medium wasms. -pub const MEDIUM_WASM_LANE_ID: u8 = 4; +pub(crate) const MEDIUM_WASM_LANE_ID: u8 = 4; /// The lane identifier for small wasms. -pub const SMALL_WASM_LANE_ID: u8 = 5; +pub(crate) const SMALL_WASM_LANE_ID: u8 = 5; /// OS page size. #[cfg(feature = "std")] diff --git a/types/src/transaction/deploy/error.rs b/types/src/transaction/deploy/error.rs index 69c4d9bf8c..ba86afd521 100644 --- a/types/src/transaction/deploy/error.rs +++ b/types/src/transaction/deploy/error.rs @@ -138,6 +138,9 @@ pub enum InvalidDeploy { /// Invalid runtime. InvalidRuntime, + + //Invalida chainspec configuration - seems that chainspec has no wasm lanes defined + InvalidChainspecConfiguration, } impl Display for InvalidDeploy { @@ -266,6 +269,7 @@ impl Display for InvalidDeploy { InvalidDeploy::InvalidRuntime => { write!(formatter, "invalid runtime",) } + InvalidDeploy::InvalidChainspecConfiguration => write!(formatter, "chainspec didnt have any wasm lanes defined which is required for wasm based deploys",), } } } @@ -302,7 +306,8 @@ impl StdError for InvalidDeploy { | InvalidDeploy::GasLimitNotSupported | InvalidDeploy::UnableToCalculateGasCost | InvalidDeploy::GasPriceToleranceTooLow { .. } - | InvalidDeploy::InvalidRuntime => None, + | InvalidDeploy::InvalidRuntime + | InvalidDeploy::InvalidChainspecConfiguration => None, } } } diff --git a/types/src/transaction/transaction_v1/errors_v1.rs b/types/src/transaction/transaction_v1/errors_v1.rs index 24ab2c95fe..87847be88e 100644 --- a/types/src/transaction/transaction_v1/errors_v1.rs +++ b/types/src/transaction/transaction_v1/errors_v1.rs @@ -202,6 +202,8 @@ pub enum InvalidTransaction { }, /// The transaction is missing a seed field. MissingSeed, + // Pricing mode not implemented yet + PricingModeNotSupported, } impl Display for InvalidTransaction { @@ -394,8 +396,9 @@ impl Display for InvalidTransaction { InvalidTransaction::MissingSeed => { write!(formatter, "missing seed for install or upgrade") } - - + InvalidTransaction::PricingModeNotSupported => { + write!(formatter, "Pricing mode not supported") + } } } } @@ -447,7 +450,8 @@ impl StdError for InvalidTransaction { InvalidTransaction::ExpectedNamedArguments | InvalidTransaction::ExpectedBytesArguments | InvalidTransaction::InvalidTransactionRuntime { .. } - | InvalidTransaction::MissingSeed => None, + | InvalidTransaction::MissingSeed + | InvalidTransaction::PricingModeNotSupported => None, } } } From 8fbf38794fc79cc98fe71a6b8bf054bc335a87b0 Mon Sep 17 00:00:00 2001 From: Jakub Zajkowski Date: Mon, 16 Dec 2024 12:38:56 +0100 Subject: [PATCH 2/3] 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, }; From c7ac14421baed1011c32c22efe2d51e58c016484 Mon Sep 17 00:00:00 2001 From: Jakub Zajkowski Date: Mon, 16 Dec 2024 16:26:19 +0100 Subject: [PATCH 3/3] using LARGE_WASM_LANE_ID constant in block_validator/tests.rs --- node/src/components/block_validator/tests.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/node/src/components/block_validator/tests.rs b/node/src/components/block_validator/tests.rs index aab43fdf14..25051eaf33 100644 --- a/node/src/components/block_validator/tests.rs +++ b/node/src/components/block_validator/tests.rs @@ -19,6 +19,7 @@ use crate::{ }, effect::requests::StorageRequest, reactor::{EventQueueHandle, QueueKind, Scheduler}, + testing::LARGE_WASM_LANE_ID, types::{BlockPayload, ValidatorMatrix}, utils::{self, Loadable}, }; @@ -152,7 +153,7 @@ pub(super) fn new_proposed_block_with_cited_signatures( INSTALL_UPGRADE_LANE_ID, install_upgrade.into_iter().collect(), ); - ret.insert(3, standard.into_iter().collect()); + ret.insert(LARGE_WASM_LANE_ID, standard.into_iter().collect()); ret }; let block_payload = BlockPayload::new(transactions, vec![], cited_signatures, true, 1u8);