Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/4685-faster-gas.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Perform wasm gas accounting using mutable global, to avoid frequent host/guest
vm context switches. ([\#4685](https://github.com/anoma/namada/pull/4685))
23 changes: 12 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ typed-builder = "0.20"
uint = "0.10"
warp = "0.3"
wasmparser = "0.121"
wasm-instrument = {version = "0.4.0", features = ["sign_ext"]}
wasm-instrument = { package = "nam-wasm-instrument", version = "0.5.2", features = ["sign_ext"] }
wasmer = "4.3.5"
wasmer-cache = "4.3.5"
wasmer-compiler = "4.3.5"
Expand Down
3 changes: 2 additions & 1 deletion crates/benches/host_env.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use criterion::{Criterion, criterion_group, criterion_main};
use namada_apps_lib::account::AccountPublicKeysMap;
use namada_apps_lib::collections::{HashMap, HashSet};
use namada_apps_lib::gas::GasMeterKind;
use namada_apps_lib::storage::DB;
use namada_apps_lib::token::{Amount, Transfer};
use namada_apps_lib::tx::Authorization;
Expand Down Expand Up @@ -99,7 +100,7 @@ fn compile_wasm(c: &mut Criterion) {
shell
.write()
.tx_wasm_cache
.compile_or_fetch(&wasm_code)
.compile_or_fetch(&wasm_code, GasMeterKind::MutGlobal)
.unwrap()
.unwrap()
},
Expand Down
14 changes: 13 additions & 1 deletion crates/benches/native_vps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use namada_apps_lib::eth_bridge::read_native_erc20_address;
use namada_apps_lib::eth_bridge::storage::eth_bridge_queries::is_bridge_comptime_enabled;
use namada_apps_lib::eth_bridge::storage::whitelist;
use namada_apps_lib::eth_bridge_pool::{GasFee, PendingTransfer};
use namada_apps_lib::gas::{TxGasMeter, VpGasMeter};
use namada_apps_lib::gas::{GasMeterKind, TxGasMeter, VpGasMeter};
use namada_apps_lib::governance::pgf::storage::steward::StewardDetail;
use namada_apps_lib::governance::storage::proposal::ProposalType;
use namada_apps_lib::governance::storage::vote::ProposalVote;
Expand Down Expand Up @@ -231,6 +231,7 @@ fn governance(c: &mut Criterion) {
&keys_changed,
&verifiers,
shell.vp_wasm_cache.clone(),
GasMeterKind::MutGlobal,
);

group.bench_function(bench_name, |b| {
Expand Down Expand Up @@ -459,6 +460,7 @@ fn ibc(c: &mut Criterion) {
&keys_changed,
&verifiers,
shell_read.vp_wasm_cache.clone(),
GasMeterKind::MutGlobal,
));

group.bench_function(bench_name, |b| {
Expand Down Expand Up @@ -526,6 +528,7 @@ fn vp_multitoken(c: &mut Criterion) {
&keys_changed,
&verifiers,
shell.vp_wasm_cache.clone(),
GasMeterKind::MutGlobal,
);

group.bench_function(bench_name, |b| {
Expand Down Expand Up @@ -651,6 +654,7 @@ fn masp(c: &mut Criterion) {
&keys_changed,
&verifiers,
shell_read.vp_wasm_cache.clone(),
GasMeterKind::MutGlobal,
);

b.iter(|| {
Expand Down Expand Up @@ -1264,6 +1268,7 @@ fn pgf(c: &mut Criterion) {
&keys_changed,
&verifiers,
shell.vp_wasm_cache.clone(),
GasMeterKind::MutGlobal,
);

group.bench_function(bench_name, |b| {
Expand Down Expand Up @@ -1341,6 +1346,7 @@ fn eth_bridge_nut(c: &mut Criterion) {
&keys_changed,
&verifiers,
shell.vp_wasm_cache.clone(),
GasMeterKind::MutGlobal,
);

c.bench_function("vp_eth_bridge_nut", |b| {
Expand Down Expand Up @@ -1414,6 +1420,7 @@ fn eth_bridge(c: &mut Criterion) {
&keys_changed,
&verifiers,
shell.vp_wasm_cache.clone(),
GasMeterKind::MutGlobal,
);

c.bench_function("vp_eth_bridge", |b| {
Expand Down Expand Up @@ -1512,6 +1519,7 @@ fn eth_bridge_pool(c: &mut Criterion) {
&keys_changed,
&verifiers,
shell.vp_wasm_cache.clone(),
GasMeterKind::MutGlobal,
);

c.bench_function("vp_eth_bridge_pool", |b| {
Expand Down Expand Up @@ -1585,6 +1593,7 @@ fn parameters(c: &mut Criterion) {
&keys_changed,
&verifiers,
shell.vp_wasm_cache.clone(),
GasMeterKind::MutGlobal,
);

group.bench_function(bench_name, |b| {
Expand Down Expand Up @@ -1661,6 +1670,7 @@ fn pos(c: &mut Criterion) {
&keys_changed,
&verifiers,
shell.vp_wasm_cache.clone(),
GasMeterKind::MutGlobal,
);

group.bench_function(bench_name, |b| {
Expand Down Expand Up @@ -1714,6 +1724,7 @@ fn ibc_vp_validate_action(c: &mut Criterion) {
&keys_changed,
&verifiers,
shell_read.vp_wasm_cache.clone(),
GasMeterKind::MutGlobal,
));
// Use an empty verifiers set placeholder for validation, this is only
// needed in actual txs to addresses whose VPs should be triggered
Expand Down Expand Up @@ -1777,6 +1788,7 @@ fn ibc_vp_execute_action(c: &mut Criterion) {
&keys_changed,
&verifiers,
shell_read.vp_wasm_cache.clone(),
GasMeterKind::MutGlobal,
));
// Use an empty verifiers set placeholder for validation, this is only
// needed in actual txs to addresses whose VPs should be triggered
Expand Down
3 changes: 2 additions & 1 deletion crates/ethereum_bridge/src/vp/bridge_pool_vp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ mod test_bridge_pool_vp {
use namada_core::borsh::BorshSerializeExt;
use namada_core::eth_bridge_pool::{GasFee, TransferToEthereum};
use namada_core::hash::Hash;
use namada_gas::{TxGasMeter, VpGasMeter};
use namada_gas::{GasMeterKind, TxGasMeter, VpGasMeter};
use namada_state::testing::TestState;
use namada_state::write_log::WriteLog;
use namada_state::{StateRead, StorageWrite, TxIndex};
Expand Down Expand Up @@ -925,6 +925,7 @@ mod test_bridge_pool_vp {
keys_changed,
verifiers,
VpCache::new(temp_dir(), 100usize),
GasMeterKind::MutGlobal,
)
}

Expand Down
3 changes: 2 additions & 1 deletion crates/ethereum_bridge/src/vp/eth_bridge_vp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ mod tests {
use namada_core::borsh::BorshSerializeExt;
use namada_core::ethereum_events;
use namada_core::ethereum_events::EthAddress;
use namada_gas::{TxGasMeter, VpGasMeter};
use namada_gas::{GasMeterKind, TxGasMeter, VpGasMeter};
use namada_state::testing::TestState;
use namada_state::{StateRead, StorageWrite, TxIndex};
use namada_trans_token::storage_key::{balance_key, minted_balance_key};
Expand Down Expand Up @@ -249,6 +249,7 @@ mod tests {
keys_changed,
verifiers,
VpCache::new(temp_dir(), 100usize),
GasMeterKind::MutGlobal,
)
}

Expand Down
3 changes: 2 additions & 1 deletion crates/ethereum_bridge/src/vp/nut_vp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ mod test_nuts {
use namada_core::borsh::BorshSerializeExt;
use namada_core::ethereum_events::testing::DAI_ERC20_ETH_ADDRESS;
use namada_core::storage::TxIndex;
use namada_gas::{TxGasMeter, VpGasMeter};
use namada_gas::{GasMeterKind, TxGasMeter, VpGasMeter};
use namada_state::testing::TestState;
use namada_state::{StateRead, StorageWrite};
use namada_trans_token::storage_key::balance_key;
Expand Down Expand Up @@ -196,6 +196,7 @@ mod test_nuts {
&keys_changed,
&verifiers,
VpCache::new(temp_dir(), 100usize),
GasMeterKind::MutGlobal,
);

// print debug info in case we run into failures
Expand Down
Loading
Loading