Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime gas meter #2838

Merged
merged 25 commits into from Apr 12, 2024
Merged

Runtime gas meter #2838

merged 25 commits into from Apr 12, 2024

Conversation

grarco
Copy link
Contributor

@grarco grarco commented Mar 7, 2024

Describe your changes

Closes #2816.
Closes #2674.

This PR:

  • Removes the whitelisted gas for txs and vps
  • Removes the relative gas host function
  • Adds tests to check that an out of gas error forces the termination of the execution from the host (i.e. without the need for the wasm code to be cooperative)
  • Adds benchmarks for shielded actions
  • Adds benchmarks for wasm opcodes
  • Removes benchmarks for vp_validator (no longer existing)
  • Removes the testing feature from the benchmark crate which was pulling in some mock functions that should not be used in benchmarks
  • Improves gas metering for masp vp by splitting the cost for every single note
  • Replaces the wasmer ConstantGasRules with a custom one based on the benchmarks
  • Adds gas metering in PseudoExecutionContext
  • Adjusts the gas SCALE for the now increased gas costs to keep the average cost of a tx around 20_000 gas units

The runtime gas meter has the following drawbacks:

  • Makes execution times worse (approx. 2-3 times)
  • Increases the size of the wasm codes because of the instrumentation, which might have consequences on the cache performance

Indicate on which release or other PRs this topic is based on

v0.31.9

Checklist before merging to draft

  • I have added a changelog
  • Git history is in acceptable state

Copy link

codecov bot commented Mar 7, 2024

Codecov Report

Attention: Patch coverage is 50.93458% with 210 lines in your changes are missing coverage. Please review.

Project coverage is 53.92%. Comparing base (cc3edde) to head (eb302a8).
Report is 117 commits behind head on main.

Files Patch % Lines
crates/namada/src/vm/wasm/run.rs 58.00% 84 Missing ⚠️
crates/apps/src/lib/bench_utils.rs 0.00% 76 Missing ⚠️
crates/sdk/src/masp.rs 0.00% 27 Missing ⚠️
crates/namada/src/ledger/native_vp/ibc/context.rs 63.63% 8 Missing ⚠️
crates/macros/src/lib.rs 0.00% 6 Missing ⚠️
crates/apps/src/lib/node/ledger/mod.rs 0.00% 5 Missing ⚠️
crates/namada/src/ledger/native_vp/masp.rs 0.00% 3 Missing ⚠️
crates/namada/src/vm/host_env.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2838      +/-   ##
==========================================
+ Coverage   53.88%   53.92%   +0.04%     
==========================================
  Files         308      308              
  Lines      100154   100479     +325     
==========================================
+ Hits        53967    54186     +219     
- Misses      46187    46293     +106     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@grarco grarco force-pushed the grarco/runtime-gas-meter branch 2 times, most recently from 1ad1048 to a28e64b Compare March 12, 2024 14:13
@grarco grarco marked this pull request as ready for review March 18, 2024 16:00
@grarco grarco requested review from tzemanovic and sug0 March 18, 2024 16:00
tzemanovic
tzemanovic previously approved these changes Mar 19, 2024
Copy link
Contributor

@sug0 sug0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some comments

crates/benches/vps.rs Show resolved Hide resolved
crates/namada/src/vm/wasm/run.rs Show resolved Hide resolved
crates/namada/src/vm/wasm/run.rs Show resolved Hide resolved
wasm_for_tests/wasm_source/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@sug0 sug0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

tzemanovic added a commit that referenced this pull request Mar 28, 2024
* origin/grarco/runtime-gas-meter:
  Test that native VPs correctly run out of gas
  Empty loop in out of gas unit tests
  Adds source for wasm gas costs
  Changelog #2838
  Increases gas limits in unit tests
  Increases gas scale
  Gas metering in `PseudoExecutionContext`
  Updates gas costs
  Singlepass compiler for wasm benchmarks
  Iterations and improvements for wasm opcodes benchmarks
  Removes old comment
  Renames vp user benchmark
  Updates beatch size for benchmarks
  Fixes make clippy for benchmarks
  Higher resolution gas metering for masp
  Updates masp vp checks
  Removes testing dependency from the benchmarks crate
  Clippy + fmt
  Removes benchmark for vp validator
  Benchmarks for shielded actions
  Adds wasm opcodes benchmarks
  Changes docstrings for signature verification
  Adds unit tests for out of gas
  Gas for ibc tx and removes unused host fn for whitelisted gas
  Removes whitelisted gas and sets a constant for the runtime gas meter
@grarco grarco mentioned this pull request Apr 2, 2024
2 tasks
tzemanovic added a commit that referenced this pull request Apr 10, 2024
* origin/grarco/runtime-gas-meter:
  Test that native VPs correctly run out of gas
  Empty loop in out of gas unit tests
  Adds source for wasm gas costs
  Changelog #2838
  Increases gas limits in unit tests
  Increases gas scale
  Gas metering in `PseudoExecutionContext`
  Updates gas costs
  Singlepass compiler for wasm benchmarks
  Iterations and improvements for wasm opcodes benchmarks
  Removes old comment
  Renames vp user benchmark
  Updates beatch size for benchmarks
  Fixes make clippy for benchmarks
  Higher resolution gas metering for masp
  Updates masp vp checks
  Removes testing dependency from the benchmarks crate
  Clippy + fmt
  Removes benchmark for vp validator
  Benchmarks for shielded actions
  Adds wasm opcodes benchmarks
  Changes docstrings for signature verification
  Adds unit tests for out of gas
  Gas for ibc tx and removes unused host fn for whitelisted gas
  Removes whitelisted gas and sets a constant for the runtime gas meter

# Conflicts:
#	crates/apps/src/lib/bench_utils.rs
#	crates/apps/src/lib/node/ledger/shell/finalize_block.rs
#	crates/benches/Cargo.toml
#	crates/benches/native_vps.rs
#	crates/benches/txs.rs
#	crates/core/Cargo.toml
#	crates/macros/src/lib.rs
#	crates/namada/Cargo.toml
#	crates/namada/src/ledger/protocol/mod.rs
#	crates/namada/src/vm/host_env.rs
#	crates/namada/src/vm/wasm/run.rs
#	crates/state/Cargo.toml
#	crates/test_utils/src/lib.rs
#	wasm/wasm_source/src/tx_ibc.rs
#	wasm_for_tests/tx_fail.wasm
#	wasm_for_tests/tx_memory_limit.wasm
#	wasm_for_tests/tx_mint_tokens.wasm
#	wasm_for_tests/tx_no_op.wasm
#	wasm_for_tests/tx_proposal_code.wasm
#	wasm_for_tests/tx_proposal_masp_reward.wasm
#	wasm_for_tests/tx_read_storage_key.wasm
#	wasm_for_tests/tx_write.wasm
#	wasm_for_tests/tx_write_storage_key.wasm
#	wasm_for_tests/vp_always_false.wasm
#	wasm_for_tests/vp_always_true.wasm
#	wasm_for_tests/vp_eval.wasm
#	wasm_for_tests/vp_memory_limit.wasm
#	wasm_for_tests/vp_read_storage_key.wasm
#	wasm_for_tests/wasm_source/Cargo.toml
#	wasm_for_tests/wasm_source/Makefile
@tzemanovic tzemanovic merged commit 7beccde into main Apr 12, 2024
17 of 19 checks passed
@tzemanovic tzemanovic deleted the grarco/runtime-gas-meter branch April 12, 2024 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configure non-zero instruction cost in wasm Benchmarks improvements
3 participants