Skip to content

Commit

Permalink
chore: rollback impl of get_trie_node_count
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksuss committed Jan 17, 2024
1 parent e47d699 commit 26347de
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 227 deletions.
401 changes: 206 additions & 195 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions engine-tests/src/tests/one_inch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ fn test_1inch_liquidity_protocol() {

let (result, profile, deployer_address) = helper.create_mooniswap_deployer();
assert!(result.gas_used >= 5_100_000); // more than 5.1M EVM gas used
assert_gas_bound(profile.all_gas(), 10); // less than 10 NEAR Tgas used
assert_gas_bound(profile.all_gas(), 11); // less than 11 NEAR Tgas used

let (result, profile, pool_factory) = helper.create_pool_factory(&deployer_address);
assert!(result.gas_used >= 2_800_000); // more than 2.8M EVM gas used
assert_gas_bound(profile.all_gas(), 7); // less than 7 NEAR Tgas used
assert_gas_bound(profile.all_gas(), 9); // less than 9 NEAR Tgas used

// create some ERC-20 tokens to have a liquidity pool for
let signer_address = utils::address_from_secret_key(&helper.signer.secret_key);
Expand All @@ -38,7 +38,7 @@ fn test_1inch_liquidity_protocol() {
let (result, profile, pool) =
helper.create_pool(&pool_factory, token_a.0.address, token_b.0.address);
assert!(result.gas_used >= 4_500_000); // more than 4.5M EVM gas used
assert_gas_bound(profile.all_gas(), 14);
assert_gas_bound(profile.all_gas(), 18);

// Approve giving ERC-20 tokens to the pool
helper.approve_erc20_tokens(&token_a, pool.address());
Expand All @@ -57,7 +57,7 @@ fn test_1inch_liquidity_protocol() {
},
);
assert!(result.gas_used >= 302_000); // more than 302k EVM gas used
assert_gas_bound(profile.all_gas(), 17);
assert_gas_bound(profile.all_gas(), 23);

// Same here
helper.runner.context.block_timestamp += 10_000_000 * 1_000_000_000;
Expand All @@ -72,7 +72,7 @@ fn test_1inch_liquidity_protocol() {
},
);
assert!(result.gas_used >= 210_000); // more than 210k EVM gas used
assert_gas_bound(profile.all_gas(), 18);
assert_gas_bound(profile.all_gas(), 24);

let (result, profile) = helper.pool_withdraw(
&pool,
Expand All @@ -83,7 +83,7 @@ fn test_1inch_liquidity_protocol() {
},
);
assert!(result.gas_used >= 150_000); // more than 150k EVM gas used
assert_gas_bound(profile.all_gas(), 15);
assert_gas_bound(profile.all_gas(), 20);
}

#[test]
Expand All @@ -104,7 +104,7 @@ fn test_1_inch_limit_order_deploy() {
// at least 45% of which is from wasm execution
let wasm_fraction = 100 * profile.wasm_gas() / profile.all_gas();
assert!(
(55..=60).contains(&wasm_fraction),
(45..=55).contains(&wasm_fraction),
"{wasm_fraction}% is not between 45% and 55%",
);
}
Expand Down
4 changes: 2 additions & 2 deletions engine-tests/src/tests/promise_results_precompile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ fn test_promise_result_gas_cost() {
let total_gas1 = y1 + baseline.all_gas();
let total_gas2 = y2 + baseline.all_gas();
assert!(
utils::within_x_percent(35, evm1, total_gas1 / NEAR_GAS_PER_EVM),
utils::within_x_percent(15, evm1, total_gas1 / NEAR_GAS_PER_EVM),
"Incorrect EVM gas used. Expected: {} Actual: {}",
evm1,
total_gas1 / NEAR_GAS_PER_EVM
);
assert!(
utils::within_x_percent(35, evm2, total_gas2 / NEAR_GAS_PER_EVM),
utils::within_x_percent(15, evm2, total_gas2 / NEAR_GAS_PER_EVM),
"Incorrect EVM gas used. Expected: {} Actual: {}",
evm2,
total_gas2 / NEAR_GAS_PER_EVM
Expand Down
12 changes: 6 additions & 6 deletions engine-tests/src/tests/repro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn repro_GdASJ3KESs() {
block_timestamp: 1_645_717_564_644_206_730,
input_path: "src/tests/res/input_GdASJ3KESs.hex",
evm_gas_used: 706_713,
near_gas_used: 98,
near_gas_used: 116,
});
}

Expand All @@ -51,7 +51,7 @@ fn repro_8ru7VEA() {
block_timestamp: 1_648_829_935_343_349_589,
input_path: "src/tests/res/input_8ru7VEA.hex",
evm_gas_used: 1_732_181,
near_gas_used: 178,
near_gas_used: 210,
});
}

Expand All @@ -71,7 +71,7 @@ fn repro_FRcorNv() {
block_timestamp: 1_650_960_438_774_745_116,
input_path: "src/tests/res/input_FRcorNv.hex",
evm_gas_used: 1_239_721,
near_gas_used: 147,
near_gas_used: 170,
});
}

Expand All @@ -88,7 +88,7 @@ fn repro_5bEgfRQ() {
block_timestamp: 1_651_073_772_931_594_646,
input_path: "src/tests/res/input_5bEgfRQ.hex",
evm_gas_used: 6_414_105,
near_gas_used: 638,
near_gas_used: 655,
});
}

Expand All @@ -106,7 +106,7 @@ fn repro_D98vwmi() {
block_timestamp: 1_651_753_443_421_003_245,
input_path: "src/tests/res/input_D98vwmi.hex",
evm_gas_used: 1_035_348,
near_gas_used: 150,
near_gas_used: 172,
});
}

Expand All @@ -125,7 +125,7 @@ fn repro_Emufid2() {
block_timestamp: 1_662_118_048_636_713_538,
input_path: "src/tests/res/input_Emufid2.hex",
evm_gas_used: 1_156_364,
near_gas_used: 285,
near_gas_used: 296,
});
}

Expand Down
2 changes: 1 addition & 1 deletion engine-tests/src/tests/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ fn test_deploy_largest_contract() {
);

// Less than 12 NEAR Tgas
utils::assert_gas_bound(profile.all_gas(), 10);
utils::assert_gas_bound(profile.all_gas(), 11);
}

#[test]
Expand Down
18 changes: 9 additions & 9 deletions engine-tests/src/tests/standard_precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,55 +30,55 @@ fn test_standard_precompiles() {
#[test]
fn profile_ecrecover() {
let profile = precompile_execution_profile("test_ecrecover");
utils::assert_gas_bound(profile.all_gas(), 3);
utils::assert_gas_bound(profile.all_gas(), 5);
}

#[test]
fn profile_sha256() {
let profile = precompile_execution_profile("test_sha256");
utils::assert_gas_bound(profile.all_gas(), 3);
utils::assert_gas_bound(profile.all_gas(), 5);
}

#[test]
fn profile_ripemd160() {
let profile = precompile_execution_profile("test_ripemd160");
utils::assert_gas_bound(profile.all_gas(), 3);
utils::assert_gas_bound(profile.all_gas(), 5);
}

#[test]
fn profile_identity() {
let profile = precompile_execution_profile("test_identity");
utils::assert_gas_bound(profile.all_gas(), 3);
utils::assert_gas_bound(profile.all_gas(), 5);
}

#[test]
fn profile_modexp() {
let profile = precompile_execution_profile("test_modexp");
utils::assert_gas_bound(profile.all_gas(), 5);
utils::assert_gas_bound(profile.all_gas(), 7);
}

#[test]
fn profile_ecadd() {
let profile = precompile_execution_profile("test_ecadd");
utils::assert_gas_bound(profile.all_gas(), 3);
utils::assert_gas_bound(profile.all_gas(), 5);
}

#[test]
fn profile_ecmul() {
let profile = precompile_execution_profile("test_ecmul");
utils::assert_gas_bound(profile.all_gas(), 4);
utils::assert_gas_bound(profile.all_gas(), 6);
}

#[test]
fn profile_ecpair() {
let profile = precompile_execution_profile("test_ecpair");
utils::assert_gas_bound(profile.all_gas(), 113);
utils::assert_gas_bound(profile.all_gas(), 115);
}

#[test]
fn profile_blake2f() {
let profile = precompile_execution_profile("test_blake2f");
utils::assert_gas_bound(profile.all_gas(), 3);
utils::assert_gas_bound(profile.all_gas(), 5);
}

fn initialize() -> (AuroraRunner, Signer, PrecompilesContract) {
Expand Down
12 changes: 6 additions & 6 deletions engine-tests/src/tests/uniswap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn test_uniswap_input_multihop() {

let (_amount_out, _evm_gas, profile) = context.exact_input(&tokens, INPUT_AMOUNT.into());

assert_eq!(91, profile.all_gas() / 1_000_000_000_000);
assert_eq!(109, profile.all_gas() / 1_000_000_000_000);
}

#[test]
Expand All @@ -49,20 +49,20 @@ fn test_uniswap_exact_output() {

let (_result, profile) =
context.add_equal_liquidity(LIQUIDITY_AMOUNT.into(), &token_a, &token_b);
utils::assert_gas_bound(profile.all_gas(), 23);
utils::assert_gas_bound(profile.all_gas(), 31);
let wasm_fraction = 100 * profile.wasm_gas() / profile.all_gas();
assert!(
(50..=60).contains(&wasm_fraction),
(40..=50).contains(&wasm_fraction),
"{wasm_fraction}% is not between 40% and 50%",
);

let (_amount_in, profile) =
context.exact_output_single(&token_a, &token_b, OUTPUT_AMOUNT.into());
utils::assert_gas_bound(profile.all_gas(), 13);
utils::assert_gas_bound(profile.all_gas(), 16);
let wasm_fraction = 100 * profile.wasm_gas() / profile.all_gas();
assert!(
(50..=60).contains(&wasm_fraction),
"{wasm_fraction}% is not between 45% and 55%",
(40..=50).contains(&wasm_fraction),
"{wasm_fraction}% is not between 40% and 50%",
);
}

Expand Down
8 changes: 7 additions & 1 deletion engine-tests/src/utils/mocked_external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ impl near_vm_runner::logic::External for MockedExternalWithTrie {
}

fn get_trie_nodes_count(&self) -> TrieNodesCount {
self.underlying.get_trie_nodes_count()
let db_reads = self.new_trie_node_count.get();
let mem_reads = self.cached_trie_node_count.get();

TrieNodesCount {
db_reads,
mem_reads,
}
}

fn validator_stake(&self, account_id: &AccountId) -> Result<Option<Balance>, VMLogicError> {
Expand Down

0 comments on commit 26347de

Please sign in to comment.