Skip to content

Commit

Permalink
Merge branch 'main' into migrate_release_new_workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
otani88 authored Nov 11, 2024
2 parents 9662dcd + 8552d9c commit 279471f
Show file tree
Hide file tree
Showing 20 changed files with 262 additions and 52 deletions.
11 changes: 6 additions & 5 deletions bin/run_loadtest_from_github_actions
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ export TRANSACTION_WEIGHTS_WITHDRAWAL=${weights[3]}

read -ra execution_params <<<"$CONTRACT_EXECUTION_PARAMS" #reading $CONTRACT_EXECUTION_PARAMS as an array as tokens separated by IFS
export CONTRACT_EXECUTION_PARAMS_READS=${execution_params[0]}
export CONTRACT_EXECUTION_PARAMS_WRITES=${execution_params[1]}
export CONTRACT_EXECUTION_PARAMS_EVENTS=${execution_params[2]}
export CONTRACT_EXECUTION_PARAMS_HASHES=${execution_params[3]}
export CONTRACT_EXECUTION_PARAMS_RECURSIVE_CALLS=${execution_params[4]}
export CONTRACT_EXECUTION_PARAMS_DEPLOYS=${execution_params[5]}
export CONTRACT_EXECUTION_PARAMS_INITIAL_WRITES=${execution_params[1]}
export CONTRACT_EXECUTION_PARAMS_REPEATED_WRITES=${execution_params[2]}
export CONTRACT_EXECUTION_PARAMS_EVENTS=${execution_params[3]}
export CONTRACT_EXECUTION_PARAMS_HASHES=${execution_params[4]}
export CONTRACT_EXECUTION_PARAMS_RECURSIVE_CALLS=${execution_params[5]}
export CONTRACT_EXECUTION_PARAMS_DEPLOYS=${execution_params[6]}

# Run the test
cargo run --bin loadnext
12 changes: 8 additions & 4 deletions core/lib/contracts/src/test_contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use crate::get_loadnext_contract;
#[derive(Debug, Clone, Deserialize)]
pub struct LoadnextContractExecutionParams {
pub reads: usize,
pub writes: usize,
pub initial_writes: usize,
pub repeated_writes: usize,
pub events: usize,
pub hashes: usize,
pub recursive_calls: usize,
Expand All @@ -21,7 +22,8 @@ impl LoadnextContractExecutionParams {
pub fn empty() -> Self {
Self {
reads: 0,
writes: 0,
initial_writes: 0,
repeated_writes: 0,
events: 0,
hashes: 0,
recursive_calls: 0,
Expand All @@ -34,7 +36,8 @@ impl Default for LoadnextContractExecutionParams {
fn default() -> Self {
Self {
reads: 10,
writes: 10,
initial_writes: 10,
repeated_writes: 10,
events: 10,
hashes: 10,
recursive_calls: 1,
Expand All @@ -50,7 +53,8 @@ impl LoadnextContractExecutionParams {

let params = vec![
Token::Uint(U256::from(self.reads)),
Token::Uint(U256::from(self.writes)),
Token::Uint(U256::from(self.initial_writes)),
Token::Uint(U256::from(self.repeated_writes)),
Token::Uint(U256::from(self.hashes)),
Token::Uint(U256::from(self.events)),
Token::Uint(U256::from(self.recursive_calls)),
Expand Down
6 changes: 4 additions & 2 deletions core/lib/multivm/src/versions/testonly/rollbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ pub(crate) fn test_vm_loadnext_rollbacks<VM: TestedVm>() {
contract_address: Some(address),
calldata: LoadnextContractExecutionParams {
reads: 100,
writes: 100,
initial_writes: 100,
repeated_writes: 100,
events: 100,
hashes: 500,
recursive_calls: 10,
Expand All @@ -123,7 +124,8 @@ pub(crate) fn test_vm_loadnext_rollbacks<VM: TestedVm>() {
contract_address: Some(address),
calldata: LoadnextContractExecutionParams {
reads: 100,
writes: 100,
initial_writes: 100,
repeated_writes: 100,
events: 100,
hashes: 500,
recursive_calls: 10,
Expand Down
2 changes: 1 addition & 1 deletion core/lib/multivm/src/versions/vm_latest/tests/rollbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn test_layered_rollback() {
let loadnext_transaction = account.get_loadnext_transaction(
address,
LoadnextContractExecutionParams {
writes: 1,
initial_writes: 1,
recursive_calls: 20,
..LoadnextContractExecutionParams::empty()
},
Expand Down
3 changes: 2 additions & 1 deletion core/node/api_server/src/tx_sender/tests/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ async fn eth_call_with_load_test_transactions() {
},
LoadnextContractExecutionParams {
reads: 100,
writes: 100,
initial_writes: 100,
repeated_writes: 100,
..LoadnextContractExecutionParams::empty()
},
];
Expand Down
2 changes: 1 addition & 1 deletion core/node/api_server/src/tx_sender/tests/gas_estimation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ async fn initial_estimate_for_deep_recursion(with_reads: bool) {
(75, 1.2),
(100, 1.4),
(125, 1.7),
(150, 2.1),
(150, 2.2),
]
};
for &(recursion_depth, multiplier) in depths_and_multipliers {
Expand Down
3 changes: 2 additions & 1 deletion core/node/api_server/src/tx_sender/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const LOAD_TEST_CASES: TestCases<LoadnextContractExecutionParams> = test_casing:
LoadnextContractExecutionParams::default(),
// No storage modification
LoadnextContractExecutionParams {
writes: 0,
initial_writes: 0,
repeated_writes: 0,
events: 0,
..LoadnextContractExecutionParams::default()
},
Expand Down
4 changes: 2 additions & 2 deletions core/node/state_keeper/src/executor/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ async fn deploy_and_call_loadtest(vm_mode: FastVmMode) {
);
assert_executed(
&executor
.execute_tx(alice.loadnext_custom_writes_call(tx.address, 1, 500_000_000))
.execute_tx(alice.loadnext_custom_initial_writes_call(tx.address, 1, 500_000_000))
.await
.unwrap(),
);
Expand Down Expand Up @@ -344,7 +344,7 @@ async fn execute_reverted_tx(vm_mode: FastVmMode) {

assert_reverted(
&executor
.execute_tx(alice.loadnext_custom_writes_call(
.execute_tx(alice.loadnext_custom_initial_writes_call(
tx.address, 1,
1_000_000, // We provide enough gas for tx to be executed, but not enough for the call to be successful.
))
Expand Down
11 changes: 6 additions & 5 deletions core/node/state_keeper/src/executor/tests/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ pub trait AccountLoadNextExecutable {
/// Returns an `execute` transaction with custom factory deps (which aren't used in a transaction,
/// so they are mostly useful to test bytecode compression).
fn execute_with_factory_deps(&mut self, factory_deps: Vec<Vec<u8>>) -> Transaction;
fn loadnext_custom_writes_call(
fn loadnext_custom_initial_writes_call(
&mut self,
address: Address,
writes: u32,
Expand Down Expand Up @@ -407,17 +407,17 @@ impl AccountLoadNextExecutable for Account {

/// Returns a transaction to the loadnext contract with custom amount of write requests.
/// Increments the account nonce.
fn loadnext_custom_writes_call(
fn loadnext_custom_initial_writes_call(
&mut self,
address: Address,
writes: u32,
initial_writes: u32,
gas_limit: u32,
) -> Transaction {
// For each iteration of the expensive contract, there are two slots that are updated:
// the length of the vector and the new slot with the element itself.
let minimal_fee = 2
* testonly::DEFAULT_GAS_PER_PUBDATA
* writes
* initial_writes
* INITIAL_STORAGE_WRITE_PUBDATA_BYTES as u32;

let fee = testonly::fee(minimal_fee + gas_limit);
Expand All @@ -427,7 +427,8 @@ impl AccountLoadNextExecutable for Account {
contract_address: Some(address),
calldata: LoadnextContractExecutionParams {
reads: 100,
writes: writes as usize,
initial_writes: initial_writes as usize,
repeated_writes: 100,
events: 100,
hashes: 100,
recursive_calls: 0,
Expand Down
1 change: 1 addition & 0 deletions core/tests/loadnext/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ license.workspace = true
keywords.workspace = true
categories.workspace = true
publish = false
exclude = ["./dump"]

[dependencies]
zksync_types.workspace = true
Expand Down
28 changes: 16 additions & 12 deletions core/tests/loadnext/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,22 @@ It:

## Transactions Parameters

The smart contract that is used for every l2 transaction can be found here:
`etc/contracts-test-data/contracts/loadnext/loadnext_contract.sol`.
The smart contract that is used for every L2 transaction can be found here:
[`etc/contracts-test-data/contracts/loadnext/loadnext_contract.sol`](../../../etc/contracts-test-data/contracts/loadnext/loadnext_contract.sol).

The `execute` function of the contract has the following parameters:

```
function execute(uint reads, uint writes, uint hashes, uint events, uint max_recursion, uint deploys) external returns(uint) {
```solidity
function execute(uint reads, uint initialWrites, uint repeatedWrites, uint hashes, uint events, uint maxRecursion, uint deploys) external returns(uint) {
```

which correspond to the following configuration options:

```
```rust
pub struct LoadnextContractExecutionParams {
pub reads: usize,
pub writes: usize,
pub initial_writes: usize,
pub repeated_writes: usize,
pub events: usize,
pub hashes: usize,
pub recursive_calls: usize,
Expand All @@ -51,8 +52,9 @@ pub struct LoadnextContractExecutionParams {

For example, to simulate an average transaction on mainnet, one could do:

```
CONTRACT_EXECUTION_PARAMS_WRITES=2
```env
CONTRACT_EXECUTION_PARAMS_INITIAL_WRITES=2
CONTRACT_EXECUTION_PARAMS_REPEATED_WRITES=2
CONTRACT_EXECUTION_PARAMS_READS=6
CONTRACT_EXECUTION_PARAMS_EVENTS=2
CONTRACT_EXECUTION_PARAMS_HASHES=10
Expand All @@ -62,8 +64,9 @@ CONTRACT_EXECUTION_PARAMS_DEPLOYS=0

Similarly, to simulate a lightweight transaction:

```
CONTRACT_EXECUTION_PARAMS_WRITES=0
```env
CONTRACT_EXECUTION_PARAMS_INITIAL_WRITES=0
CONTRACT_EXECUTION_PARAMS_REPEATED_WRITES=0
CONTRACT_EXECUTION_PARAMS_READS=0
CONTRACT_EXECUTION_PARAMS_EVENTS=0
CONTRACT_EXECUTION_PARAMS_HASHES=0
Expand All @@ -86,10 +89,11 @@ Example invocation:
- `MASTER_WALLET_PK` needs to be set to the private key of the master account.
- `MAIN_TOKEN` needs to be set to the address of the token to be used for the loadtest.

```
```sh
cargo build

CONTRACT_EXECUTION_PARAMS_WRITES=2 \
CONTRACT_EXECUTION_PARAMS_INITIAL_WRITES=2 \
CONTRACT_EXECUTION_PARAMS_REPEATED_WRITES=2 \
CONTRACT_EXECUTION_PARAMS_READS=6 \
CONTRACT_EXECUTION_PARAMS_EVENTS=2 \
CONTRACT_EXECUTION_PARAMS_HASHES=10 \
Expand Down
3 changes: 2 additions & 1 deletion core/tests/loadnext/src/account/tx_command_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ impl AccountLifespan {
function
.encode_input(&vec![
ethabi::Token::Uint(U256::from(self.contract_execution_params.reads)),
ethabi::Token::Uint(U256::from(self.contract_execution_params.writes)),
ethabi::Token::Uint(U256::from(self.contract_execution_params.initial_writes)),
ethabi::Token::Uint(U256::from(self.contract_execution_params.repeated_writes)),
ethabi::Token::Uint(U256::from(self.contract_execution_params.hashes)),
ethabi::Token::Uint(U256::from(self.contract_execution_params.events)),
ethabi::Token::Uint(U256::from(self.contract_execution_params.recursive_calls)),
Expand Down
21 changes: 12 additions & 9 deletions core/tests/vm-benchmark/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use zksync_types::{
};
use zksync_utils::bytecode::hash_bytecode;

const LOAD_TEST_MAX_READS: usize = 100;
const LOAD_TEST_MAX_READS: usize = 3000;

pub(crate) static PRIVATE_KEY: Lazy<K256PrivateKey> =
Lazy::new(|| K256PrivateKey::from_bytes(H256([42; 32])).expect("invalid key bytes"));
Expand Down Expand Up @@ -112,7 +112,7 @@ pub fn get_load_test_deploy_tx() -> Transaction {
Some(CONTRACT_DEPLOYER_ADDRESS),
create_calldata,
Nonce(0),
tx_fee(100_000_000),
tx_fee(500_000_000),
U256::zero(),
L2ChainId::from(270),
&PRIVATE_KEY,
Expand All @@ -138,7 +138,8 @@ pub fn get_load_test_tx(nonce: u32, gas_limit: u32, params: LoadTestParams) -> T
let calldata = execute_function
.encode_input(&vec![
Token::Uint(U256::from(params.reads)),
Token::Uint(U256::from(params.writes)),
Token::Uint(U256::from(params.initial_writes)),
Token::Uint(U256::from(params.repeated_writes)),
Token::Uint(U256::from(params.hashes)),
Token::Uint(U256::from(params.events)),
Token::Uint(U256::from(params.recursive_calls)),
Expand Down Expand Up @@ -168,9 +169,10 @@ pub fn get_realistic_load_test_tx(nonce: u32) -> Transaction {
nonce,
10_000_000,
LoadTestParams {
reads: 30,
writes: 2,
events: 5,
reads: 243,
initial_writes: 1,
repeated_writes: 11,
events: 6,
hashes: 10,
recursive_calls: 0,
deploys: 0,
Expand All @@ -183,9 +185,10 @@ pub fn get_heavy_load_test_tx(nonce: u32) -> Transaction {
nonce,
10_000_000,
LoadTestParams {
reads: 100,
writes: 5,
events: 20,
reads: 296,
initial_writes: 13,
repeated_writes: 92,
events: 140,
hashes: 100,
recursive_calls: 20,
deploys: 5,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Calculating loadtest profiles

Use the SQL scripts in this directory to calculate the characteristics of transactions within a miniblock range.

Calculate `CONTRACT_EXECUTION_PARAMS` as follows:

- `light`: all zeroes.
- `realistic`: median (50th percentile).
- `heavy`: generally use 2.5&times; the values in the 99th percentile. However, some operations are even less frequent than that (e.g. contract deployments). At the time of writing, contract deployments is set to 5.

Metrics may be averaged across different block ranges to calculate a more holistic "characteristic."

## Compensating for implicit activity

The mere act of executing a transaction entails some ancillary activity on the network. For example, some events are emitted when tokens are transferred for gas payments. The loadtest contract does not compensate for this activity, so it should be kept in mind when evaluating loadtest activity.
Loading

0 comments on commit 279471f

Please sign in to comment.