Skip to content

Commit 9ac4510

Browse files
5014: Update wasm lanes r=darthsiroftardis a=darthsiroftardis Updated the Wasm lanes adjusting gas limit for and the max serialized length for the native mint and auction lanes Updated pricing mode from fixed to classic Co-authored-by: Karan Dhareshwar <[email protected]>
2 parents 68be3ff + 1204760 commit 9ac4510

File tree

6 files changed

+79
-60
lines changed

6 files changed

+79
-60
lines changed

node/src/components/transaction_acceptor/tests.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ use casper_types::{
3636
global_state::TrieMerkleProof,
3737
testing::TestRng,
3838
Block, BlockV2, CLValue, Chainspec, ChainspecRawBytes, Contract, Deploy, EraId, HashAddr,
39-
InvalidDeploy, InvalidTransaction, InvalidTransactionV1, Package, PricingMode, ProtocolVersion,
40-
PublicKey, SecretKey, StoredValue, TestBlockBuilder, TimeDiff, Timestamp, Transaction,
41-
TransactionConfig, TransactionRuntime, TransactionV1, URef, U512,
39+
InvalidDeploy, InvalidTransaction, InvalidTransactionV1, Package, PricingHandling, PricingMode,
40+
ProtocolVersion, PublicKey, SecretKey, StoredValue, TestBlockBuilder, TimeDiff, Timestamp,
41+
Transaction, TransactionConfig, TransactionRuntime, TransactionV1, URef, U512,
4242
};
4343

4444
use super::*;
@@ -595,10 +595,9 @@ impl TestScenario {
595595
}
596596
TestScenario::InvalidPricingModeForTransactionV1 => {
597597
let classic_mode_transaction = TransactionV1Builder::new_random(rng)
598-
.with_pricing_mode(PricingMode::PaymentLimited {
599-
payment_amount: 10000u64,
600-
gas_price_tolerance: 1u8,
601-
standard_payment: true,
598+
.with_pricing_mode(PricingMode::Fixed {
599+
gas_price_tolerance: 5,
600+
additional_computation_factor: 0,
602601
})
603602
.with_chain_name("casper-example")
604603
.build()
@@ -1152,6 +1151,14 @@ async fn run_transaction_acceptor_without_timeout(
11521151
let admin = SecretKey::random(rng);
11531152
let (mut chainspec, chainspec_raw_bytes) =
11541153
<(Chainspec, ChainspecRawBytes)>::from_resources("local");
1154+
let mut chainspec = if let TestScenario::TooLowGasPriceToleranceForTransactionV1 = test_scenario
1155+
{
1156+
chainspec.with_pricing_handling(PricingHandling::Fixed);
1157+
chainspec
1158+
} else {
1159+
chainspec
1160+
};
1161+
11551162
chainspec.core_config.administrators = iter::once(PublicKey::from(&admin)).collect();
11561163

11571164
let chainspec = Arc::new(chainspec);

node/src/reactor/main_reactor/tests/transactions.rs

+33-34
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static CHARLIE_SECRET_KEY: Lazy<Arc<SecretKey>> = Lazy::new(|| {
3232
static CHARLIE_PUBLIC_KEY: Lazy<PublicKey> =
3333
Lazy::new(|| PublicKey::from(&*CHARLIE_SECRET_KEY.clone()));
3434

35-
const MIN_GAS_PRICE: u8 = 5;
35+
const MIN_GAS_PRICE: u8 = 1;
3636
const CHAIN_NAME: &str = "single-transaction-test-net";
3737

3838
async fn transfer_to_account<A: Into<U512>>(
@@ -1023,8 +1023,6 @@ impl SingleTransactionTestCase {
10231023
ConfigsOverride::default()
10241024
.with_minimum_era_height(5) // make the era longer so that the transaction doesn't land in the switch block.
10251025
.with_balance_hold_interval(TimeDiff::from_seconds(5))
1026-
.with_min_gas_price(MIN_GAS_PRICE)
1027-
.with_max_gas_price(MIN_GAS_PRICE)
10281026
.with_chain_name("single-transaction-test-net".to_string())
10291027
}
10301028

@@ -3045,25 +3043,27 @@ async fn insufficient_funds_transfer_from_account() {
30453043

30463044
let transfer_amount = U512::max_value();
30473045

3048-
let mut txn = Transaction::from(
3046+
let txn_v1 =
30493047
TransactionV1Builder::new_transfer(transfer_amount, None, ALICE_PUBLIC_KEY.clone(), None)
30503048
.unwrap()
30513049
.with_chain_name(CHAIN_NAME)
30523050
.with_initiator_addr(PublicKey::from(&**BOB_SECRET_KEY))
30533051
.build()
3054-
.unwrap(),
3055-
);
3052+
.unwrap();
3053+
let price = txn_v1
3054+
.payment_amount()
3055+
.expect("must have payment amount as txns are using classic");
3056+
let mut txn = Transaction::from(txn_v1);
30563057
txn.sign(&BOB_SECRET_KEY);
30573058

30583059
let (_txn_hash, _block_height, exec_result) = test.send_transaction(txn).await;
30593060
let ExecutionResult::V2(result) = exec_result else {
30603061
panic!("Expected ExecutionResult::V2 but got {:?}", exec_result);
30613062
};
3062-
let transfer_cost: U512 =
3063-
U512::from(test.chainspec().system_costs_config.mint_costs().transfer) * MIN_GAS_PRICE;
3063+
let expected_cost: U512 = U512::from(price) * MIN_GAS_PRICE;
30643064

30653065
assert_eq!(result.error_message.as_deref(), Some("Insufficient funds"));
3066-
assert_eq!(result.cost, transfer_cost);
3066+
assert_eq!(result.cost, expected_cost);
30673067
}
30683068

30693069
#[tokio::test]
@@ -3089,22 +3089,22 @@ async fn insufficient_funds_add_bid() {
30893089
let (_, bob_initial_balance, _) = test.get_balances(None);
30903090
let bid_amount = bob_initial_balance.total;
30913091

3092-
let mut txn = Transaction::from(
3092+
let txn =
30933093
TransactionV1Builder::new_add_bid(BOB_PUBLIC_KEY.clone(), 0, bid_amount, None, None, None)
30943094
.unwrap()
30953095
.with_chain_name(CHAIN_NAME)
30963096
.with_initiator_addr(PublicKey::from(&**BOB_SECRET_KEY))
30973097
.build()
3098-
.unwrap(),
3099-
);
3098+
.unwrap();
3099+
let price = txn.payment_amount().expect("must get payment amount");
3100+
let mut txn = Transaction::from(txn);
31003101
txn.sign(&BOB_SECRET_KEY);
31013102

31023103
let (_txn_hash, _block_height, exec_result) = test.send_transaction(txn).await;
31033104
let ExecutionResult::V2(result) = exec_result else {
31043105
panic!("Expected ExecutionResult::V2 but got {:?}", exec_result);
31053106
};
3106-
let bid_cost: U512 =
3107-
U512::from(test.chainspec().system_costs_config.auction_costs().add_bid) * MIN_GAS_PRICE;
3107+
let bid_cost: U512 = U512::from(price) * MIN_GAS_PRICE;
31083108

31093109
assert_eq!(
31103110
result.error_message.as_deref(),
@@ -3175,27 +3175,26 @@ async fn insufficient_funds_transfer_from_purse() {
31753175

31763176
// now we try to transfer from the purse we just created
31773177
let transfer_amount = U512::max_value();
3178-
let mut txn = Transaction::from(
3179-
TransactionV1Builder::new_transfer(
3180-
transfer_amount,
3181-
Some(uref),
3182-
ALICE_PUBLIC_KEY.clone(),
3183-
None,
3184-
)
3185-
.unwrap()
3186-
.with_chain_name(CHAIN_NAME)
3187-
.with_initiator_addr(PublicKey::from(&**BOB_SECRET_KEY))
3188-
.build()
3189-
.unwrap(),
3190-
);
3178+
let txn = TransactionV1Builder::new_transfer(
3179+
transfer_amount,
3180+
Some(uref),
3181+
ALICE_PUBLIC_KEY.clone(),
3182+
None,
3183+
)
3184+
.unwrap()
3185+
.with_chain_name(CHAIN_NAME)
3186+
.with_initiator_addr(PublicKey::from(&**BOB_SECRET_KEY))
3187+
.build()
3188+
.unwrap();
3189+
let price = txn.payment_amount().expect("must get payment amount");
3190+
let mut txn = Transaction::from(txn);
31913191
txn.sign(&BOB_SECRET_KEY);
31923192

31933193
let (_txn_hash, _block_height, exec_result) = test.send_transaction(txn).await;
31943194
let ExecutionResult::V2(result) = exec_result else {
31953195
panic!("Expected ExecutionResult::V2 but got {:?}", exec_result);
31963196
};
3197-
let transfer_cost: U512 =
3198-
U512::from(test.chainspec().system_costs_config.mint_costs().transfer) * MIN_GAS_PRICE;
3197+
let transfer_cost: U512 = U512::from(price) * MIN_GAS_PRICE;
31993198

32003199
assert_eq!(result.error_message.as_deref(), Some("Insufficient funds"));
32013200
assert_eq!(result.cost, transfer_cost);
@@ -3223,22 +3222,22 @@ async fn insufficient_funds_when_caller_lacks_minimum_balance() {
32233222

32243223
let (_, bob_initial_balance, _) = test.get_balances(None);
32253224
let transfer_amount = bob_initial_balance.total - U512::one();
3226-
let mut txn = Transaction::from(
3225+
let txn =
32273226
TransactionV1Builder::new_transfer(transfer_amount, None, ALICE_PUBLIC_KEY.clone(), None)
32283227
.unwrap()
32293228
.with_chain_name(CHAIN_NAME)
32303229
.with_initiator_addr(PublicKey::from(&**BOB_SECRET_KEY))
32313230
.build()
3232-
.unwrap(),
3233-
);
3231+
.unwrap();
3232+
let price = txn.payment_amount().expect("must get payment amount");
3233+
let mut txn = Transaction::from(txn);
32343234
txn.sign(&BOB_SECRET_KEY);
32353235

32363236
let (_txn_hash, _block_height, exec_result) = test.send_transaction(txn).await;
32373237
let ExecutionResult::V2(result) = exec_result else {
32383238
panic!("Expected ExecutionResult::V2 but got {:?}", exec_result);
32393239
};
3240-
let transfer_cost: U512 =
3241-
U512::from(test.chainspec().system_costs_config.mint_costs().transfer) * MIN_GAS_PRICE;
3240+
let transfer_cost: U512 = U512::from(price) * MIN_GAS_PRICE;
32423241

32433242
assert_eq!(result.error_message.as_deref(), Some("Insufficient funds"));
32443243
assert_eq!(result.cost, transfer_cost);

node/src/types/transaction/transaction_v1_builder.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,10 @@ impl<'a> TransactionV1Builder<'a> {
107107
/// The default time-to-live for transactions, i.e. 30 minutes.
108108
pub const DEFAULT_TTL: TimeDiff = TimeDiff::from_millis(30 * 60 * 1_000);
109109
/// The default pricing mode for v1 transactions, ie FIXED cost.
110-
pub const DEFAULT_PRICING_MODE: PricingMode = PricingMode::Fixed {
111-
gas_price_tolerance: 5,
112-
additional_computation_factor: 0,
110+
pub const DEFAULT_PRICING_MODE: PricingMode = PricingMode::PaymentLimited {
111+
payment_amount: 10_000_000_000,
112+
gas_price_tolerance: 3,
113+
standard_payment: true,
113114
};
114115
/// The default scheduling for transactions, i.e. `Standard`.
115116
pub const DEFAULT_SCHEDULING: TransactionScheduling = TransactionScheduling::Standard;
@@ -384,9 +385,10 @@ impl<'a> TransactionV1Builder<'a> {
384385
target: fields.target,
385386
entry_point: fields.entry_point,
386387
scheduling: fields.scheduling,
387-
pricing_mode: PricingMode::Fixed {
388-
gas_price_tolerance: 5,
389-
additional_computation_factor: 0,
388+
pricing_mode: PricingMode::PaymentLimited {
389+
payment_amount: 2_500_000_000,
390+
gas_price_tolerance: 3,
391+
standard_payment: true,
390392
},
391393
initiator_addr: Some(InitiatorAddr::PublicKey(PublicKey::from(&secret_key))),
392394
secret_key: Some(secret_key),
@@ -423,9 +425,10 @@ impl<'a> TransactionV1Builder<'a> {
423425
target,
424426
entry_point,
425427
scheduling,
426-
pricing_mode: PricingMode::Fixed {
427-
gas_price_tolerance: 5,
428-
additional_computation_factor: 0,
428+
pricing_mode: PricingMode::PaymentLimited {
429+
payment_amount: 2_500_000_000,
430+
gas_price_tolerance: 3,
431+
standard_payment: true,
429432
},
430433
initiator_addr: Some(InitiatorAddr::PublicKey(PublicKey::from(&secret_key))),
431434
secret_key: Some(secret_key),

resources/local/chainspec.toml.in

+5-5
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ validator_credit_cap = [1, 5]
134134
# 'classic': senders of transaction self-specify how much they pay.
135135
# 'fixed': costs are fixed, per the cost table
136136
# 'prepaid': prepaid transaction (currently not supported)
137-
pricing_handling = { type = 'fixed' }
137+
pricing_handling = { type = 'classic' }
138138
# Does the network allow pre-payment for future
139139
# execution? Currently not supported.
140140
#
@@ -199,14 +199,14 @@ vm_casper_v2 = false
199199
# Note: For the given mainnet implementation we specially reserve the label 2 for install and upgrades and
200200
# the lane must be present and defined.
201201
# Different casper networks may not impose such a restriction.
202-
# [1] -> Max transaction size in bytes for a given transaction in a certain lane
202+
# [1] -> Max serialized length of the entire transaction in bytes for a given transaction in a certain lane
203203
# [2] -> Max args length size in bytes for a given transaction in a certain lane
204204
# [3] -> Transaction gas limit size in bytes for a given transaction in a certain lane
205205
# [4] -> The maximum number of transactions the lane can contain
206-
native_mint_lane = [0, 1024, 1024, 65_000_000_000, 650]
207-
native_auction_lane = [1, 2048, 2048, 2_500_000_000, 145]
206+
native_mint_lane = [0, 2048, 1024, 2_500_000_000, 650]
207+
native_auction_lane = [1, 3096, 2048, 2_500_000_000, 145]
208208
install_upgrade_lane = [2, 1_048_576, 2048, 100_000_000_000, 1]
209-
wasm_lanes = [[3, 344_064, 1024, 100_000_000_000, 3], [4, 172_032, 1024, 50_000_000_000, 7], [5, 12_288, 512, 1_500_000_000, 15]]
209+
wasm_lanes = [[3, 344_064, 1024, 100_000_000_000, 3], [4, 172_032, 1024, 50_000_000_000, 7], [5, 12_288, 512, 2_500_000_000, 25]]
210210

211211
[transactions.deploy]
212212
# The maximum number of Motes allowed to be spent during payment. 0 means unlimited.

resources/production/chainspec.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ validator_credit_cap = [1, 5]
141141
# 'classic': senders of transaction self-specify how much they pay.
142142
# 'fixed': costs are fixed, per the cost table
143143
# 'prepaid': prepaid transaction (currently not supported)
144-
pricing_handling = { type = 'fixed' }
144+
pricing_handling = { type = 'classic' }
145145
# Does the network allow pre-payment for future
146146
# execution? Currently not supported.
147147
#
@@ -207,14 +207,14 @@ vm_casper_v2 = false
207207
# Note: For the given mainnet implementation we specially reserve the label 2 for install and upgrades and
208208
# the lane must be present and defined.
209209
# Different casper networks may not impose such a restriction.
210-
# [1] -> Max transaction size in bytes for a given transaction in a certain lane
210+
# [1] -> Max serialized length of the entire transaction in bytes for a given transaction in a certain lane
211211
# [2] -> Max args length size in bytes for a given transaction in a certain lane
212212
# [3] -> Transaction gas limit size in bytes for a given transaction in a certain lane
213213
# [4] -> The maximum number of transactions the lane can contain
214-
native_mint_lane = [0, 1024, 1024, 65_000_000_000, 650]
215-
native_auction_lane = [1, 2048, 2048, 2_500_000_000, 145]
214+
native_mint_lane = [0, 2048, 1024, 2_500_000_000, 650]
215+
native_auction_lane = [1, 3096, 2048, 2_500_000_000, 145]
216216
install_upgrade_lane = [2, 1_048_576, 2048, 100_000_000_000, 1]
217-
wasm_lanes = [[3, 344_064, 1024, 100_000_000_000, 3], [4, 172_032, 1024, 50_000_000_000, 7], [5, 12_288, 512, 1_500_000_000, 15]]
217+
wasm_lanes = [[3, 344_064, 1024, 100_000_000_000, 3], [4, 172_032, 1024, 50_000_000_000, 7], [5, 12_288, 512, 2_500_000_000, 25]]
218218

219219
[transactions.deploy]
220220
# The maximum number of Motes allowed to be spent during payment. 0 means unlimited.

types/src/transaction/transaction_v1.rs

+10
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,16 @@ impl TransactionV1 {
281281
self.approvals.extend(approvals);
282282
}
283283

284+
/// Returns the payment amount if the txn is using classic mode.
285+
#[cfg(any(all(feature = "std", feature = "testing"), test))]
286+
pub fn payment_amount(&self) -> Option<u64> {
287+
if let PricingMode::PaymentLimited { payment_amount, .. } = self.pricing_mode() {
288+
Some(*payment_amount)
289+
} else {
290+
None
291+
}
292+
}
293+
284294
/// Returns a random, valid but possibly expired transaction.
285295
#[cfg(any(all(feature = "std", feature = "testing"), test))]
286296
pub fn random(rng: &mut TestRng) -> Self {

0 commit comments

Comments
 (0)