Skip to content

Commit

Permalink
Code fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Zajkowski committed Dec 16, 2024
1 parent 01968e7 commit 8fbf387
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 115 deletions.
17 changes: 8 additions & 9 deletions node/src/components/transaction_buffer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1122,10 +1121,10 @@ fn make_test_chainspec(max_standard_count: u64, max_mint_count: u64) -> Arc<Chai
];
let mut transaction_v1_config = TransactionV1Config::default();
transaction_v1_config.native_mint_lane =
TransactionLanesDefinition::try_from(vec![0, 1024, 1024, 65_000_000_000, max_mint_count])
TransactionLaneDefinition::try_from(vec![0, 1024, 1024, 65_000_000_000, max_mint_count])
.unwrap();
transaction_v1_config.set_wasm_lanes(vec![
TransactionLanesDefinition::try_from(large_lane).unwrap()
TransactionLaneDefinition::try_from(large_lane).unwrap()
]);

let transaction_config = TransactionConfig {
Expand Down
3 changes: 1 addition & 2 deletions node/src/reactor/main_reactor/tests/transactions.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use crate::types::MetaTransaction;
use crate::{testing::LARGE_WASM_LANE_ID, types::MetaTransaction};
use casper_execution_engine::engine_state::MAX_PAYMENT_AMOUNT;
use casper_storage::data_access_layer::{
AddressableEntityRequest, BalanceIdentifier, ProofHandling, QueryRequest, QueryResult,
Expand All @@ -15,7 +15,6 @@ use once_cell::sync::Lazy;

use casper_types::{bytesrepr::Bytes, execution::ExecutionResultV1};

const LARGE_WASM_LANE_ID: u8 = 3;
static ALICE_SECRET_KEY: Lazy<Arc<SecretKey>> = Lazy::new(|| {
Arc::new(SecretKey::ed25519_from_bytes([0xAA; SecretKey::ED25519_LENGTH]).unwrap())
});
Expand Down
2 changes: 2 additions & 0 deletions node/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ const TEST_PORT_RANGE: Range<u16> = 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 )* $(,)? ) => {{
Expand Down
3 changes: 2 additions & 1 deletion node/src/types/appendable_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TransactionHash> {
self.transactions.keys().copied().collect()
Expand Down
10 changes: 5 additions & 5 deletions node/src/types/transaction/meta_transaction.rs
Original file line number Diff line number Diff line change
@@ -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::*;

Expand Down Expand Up @@ -217,7 +217,7 @@ impl MetaTransaction {
) -> Result<Self, InvalidTransaction> {
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(
Expand Down Expand Up @@ -342,22 +342,22 @@ 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! {
#[test]
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,
Expand Down
24 changes: 12 additions & 12 deletions node/src/types/transaction/meta_transaction/meta_deploy.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use casper_types::{
Deploy, ExecutableDeployItem, InvalidDeploy, InvalidTransaction, TransactionLanesDefinition,
Deploy, ExecutableDeployItem, InvalidDeploy, InvalidTransaction, TransactionLaneDefinition,
TransactionV1Config, MINT_LANE_ID,
};
use datasize::DataSize;
Expand All @@ -14,7 +14,7 @@ pub(crate) struct MetaDeploy {
}

impl MetaDeploy {
pub(crate) fn from(
pub(crate) fn from_deploy(
deploy: Deploy,
config: &TransactionV1Config,
) -> Result<Self, InvalidTransaction> {
Expand All @@ -40,7 +40,7 @@ impl MetaDeploy {
}
}

fn calculate_lane_id_of_biggest_wasm(wasm_lanes: &[TransactionLanesDefinition]) -> Option<u8> {
fn calculate_lane_id_of_biggest_wasm(wasm_lanes: &[TransactionLaneDefinition]) -> Option<u8> {
wasm_lanes
.iter()
.max_by(|left, right| {
Expand All @@ -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![];
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
};

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions node/src/utils/chain_specification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion node/src/utils/specimen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -858,7 +859,7 @@ impl LargestSpecimen for BlockPayload {
],
);
transactions.insert(
3,
LARGE_WASM_LANE_ID,
vec![
large_txn_hash_with_approvals.clone();
estimator.parameter::<usize>("max_standard_transactions_per_block")
Expand Down
2 changes: 1 addition & 1 deletion types/src/chainspec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
2 changes: 1 addition & 1 deletion types/src/chainspec/transaction_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 8fbf387

Please sign in to comment.