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

[FVM] Fix metering limits #2217

Merged
merged 4 commits into from Mar 30, 2022

Conversation

janezpodhostnik
Copy link
Contributor

v0.25 version

This fixes three things:

  1. During testing with the emulator, I discovered that the metering "limit reached" error text did not include the correct limit. The error used the limit at the meters internal precision, instead of the actual limit. (now covered in the weighted meter tests)

  2. When testing I noticed that setting a gas limit of 999 I was only able to get a transaction to 941 execution effort before it failed. This was due to the limit enforcement happening after the fee deduction which added computation and potentially failed the transaction.

  3. When the transaction failed, the fee deduction code also failed due to meter.MergeMeter still emitting an error even though limit enforcement was off.

The new fvm/fvm_test.go test covers 2. and 3. It also makes sure that if the limit is reached (or overshot) the user is only charged up to their gas limit.

@janezpodhostnik janezpodhostnik force-pushed the janez/fix-execution-effort-metering-limits-port2master branch from 89d2e62 to d3ae6c6 Compare March 28, 2022 13:47
@github-actions
Copy link
Contributor

github-actions bot commented Mar 28, 2022

FVM Benchstat comparison

This branch with compared with the base branch onflow:master commit 7939698

The command (for i in {1..N}; do go test ./fvm --bench . --tags relic -shuffle=on; done) was used.

Bench tests were run a total of 7 times on each branch.

Results

old.txtnew.txt
time/opdelta
RuntimeNFTBatchTransfer-2144ms ± 6%142ms ± 4%~(p=1.000 n=7+7)
RuntimeTransaction/reference_tx-237.8ms ± 4%37.5ms ± 5%~(p=0.805 n=7+7)
RuntimeTransaction/convert_int_to_string-239.6ms ± 4%38.7ms ± 4%~(p=0.318 n=7+7)
RuntimeTransaction/convert_int_to_string_and_concatenate_it-240.4ms ± 3%40.5ms ± 3%~(p=0.731 n=6+7)
RuntimeTransaction/get_signer_address-238.2ms ± 7%37.5ms ± 3%~(p=0.456 n=7+7)
RuntimeTransaction/get_public_account-241.6ms ± 7%40.9ms ± 5%~(p=0.731 n=6+7)
RuntimeTransaction/get_account_and_get_balance-2697ms ± 4%685ms ± 3%~(p=0.259 n=7+7)
RuntimeTransaction/get_account_and_get_storage_used-254.8ms ± 4%53.1ms ± 3%~(p=0.051 n=7+6)
RuntimeTransaction/get_account_and_get_storage_capacity-2539ms ± 4%528ms ± 5%~(p=0.366 n=6+7)
RuntimeTransaction/get_signer_vault-247.2ms ± 8%46.6ms ± 3%~(p=0.234 n=6+7)
RuntimeTransaction/get_signer_receiver-258.2ms ± 9%58.2ms ± 3%~(p=0.731 n=6+7)
RuntimeTransaction/transfer_tokens-2235ms ±11%224ms ± 4%~(p=0.259 n=7+7)
RuntimeTransaction/load_and_save_empty_string_on_signers_address-246.2ms ±15%45.1ms ± 3%~(p=0.731 n=7+6)
RuntimeTransaction/load_and_save_long_string_on_signers_address-295.1ms ± 8%92.8ms ± 4%~(p=0.535 n=7+7)
RuntimeTransaction/create_new_account-21.40s ± 5%1.36s ± 1%~(p=0.165 n=7+7)
RuntimeTransaction/call_empty_contract_function-244.5ms ±12%43.2ms ± 6%~(p=0.620 n=7+7)
RuntimeTransaction/emit_event-259.2ms ± 8%58.5ms ± 6%~(p=0.710 n=7+7)
RuntimeTransaction/borrow_array_from_storage-2147ms ± 3%145ms ± 4%~(p=0.295 n=6+7)
RuntimeTransaction/copy_array_from_storage-2132ms ± 5%131ms ± 2%~(p=0.731 n=6+7)
RuntimeTransaction/get_account_and_get_available_balance-2591ms ± 5%569ms ± 2%−3.64%(p=0.002 n=7+7)
 
computationdelta
RuntimeTransaction/reference_tx-2202 ± 0%202 ± 0%~(all equal)
RuntimeTransaction/convert_int_to_string-2402 ± 0%402 ± 0%~(all equal)
RuntimeTransaction/convert_int_to_string_and_concatenate_it-2502 ± 0%502 ± 0%~(all equal)
RuntimeTransaction/get_signer_address-2302 ± 0%302 ± 0%~(all equal)
RuntimeTransaction/get_public_account-2402 ± 0%402 ± 0%~(all equal)
RuntimeTransaction/get_account_and_get_balance-2802 ± 0%802 ± 0%~(all equal)
RuntimeTransaction/get_account_and_get_available_balance-22.40k ± 0%2.40k ± 0%~(all equal)
RuntimeTransaction/get_account_and_get_storage_used-2402 ± 0%402 ± 0%~(all equal)
RuntimeTransaction/get_account_and_get_storage_capacity-21.10k ± 0%1.10k ± 0%~(all equal)
RuntimeTransaction/get_signer_vault-2402 ± 0%402 ± 0%~(all equal)
RuntimeTransaction/get_signer_receiver-2602 ± 0%602 ± 0%~(all equal)
RuntimeTransaction/transfer_tokens-23.50k ± 0%3.50k ± 0%~(all equal)
RuntimeTransaction/load_and_save_empty_string_on_signers_address-2602 ± 0%602 ± 0%~(all equal)
RuntimeTransaction/load_and_save_long_string_on_signers_address-2602 ± 0%602 ± 0%~(all equal)
RuntimeTransaction/create_new_account-2202 ± 0%202 ± 0%~(all equal)
RuntimeTransaction/call_empty_contract_function-2402 ± 0%402 ± 0%~(all equal)
RuntimeTransaction/emit_event-2602 ± 0%602 ± 0%~(all equal)
RuntimeTransaction/borrow_array_from_storage-22.60k ± 0%2.60k ± 0%~(all equal)
RuntimeTransaction/copy_array_from_storage-22.60k ± 0%2.60k ± 0%~(all equal)
 
interactionsdelta
RuntimeTransaction/reference_tx-2255k ± 0%255k ± 0%~(all equal)
RuntimeTransaction/convert_int_to_string-2255k ± 0%255k ± 0%~(all equal)
RuntimeTransaction/convert_int_to_string_and_concatenate_it-2255k ± 0%255k ± 0%~(all equal)
RuntimeTransaction/get_signer_address-2255k ± 0%255k ± 0%~(all equal)
RuntimeTransaction/get_public_account-2255k ± 0%255k ± 0%~(all equal)
RuntimeTransaction/get_account_and_get_balance-217.0M ± 0%17.0M ± 0%~(all equal)
RuntimeTransaction/get_account_and_get_available_balance-25.53M ± 0%5.53M ± 0%~(all equal)
RuntimeTransaction/get_account_and_get_storage_used-2258k ± 0%258k ± 0%~(all equal)
RuntimeTransaction/get_account_and_get_storage_capacity-25.53M ± 0%5.53M ± 0%~(all equal)
RuntimeTransaction/get_signer_vault-2256k ± 0%256k ± 0%~(all equal)
RuntimeTransaction/get_signer_receiver-2257k ± 0%257k ± 0%~(all equal)
RuntimeTransaction/transfer_tokens-2257k ± 0%257k ± 0%~(all equal)
RuntimeTransaction/load_and_save_empty_string_on_signers_address-2256k ± 0%256k ± 0%~(all equal)
RuntimeTransaction/load_and_save_long_string_on_signers_address-2261k ± 0%261k ± 0%~(all equal)
RuntimeTransaction/create_new_account-211.2M ± 0%11.2M ± 0%~(all equal)
RuntimeTransaction/call_empty_contract_function-2255k ± 0%255k ± 0%~(all equal)
RuntimeTransaction/emit_event-2255k ± 0%255k ± 0%~(all equal)
RuntimeTransaction/borrow_array_from_storage-2261k ± 0%261k ± 0%~(all equal)
RuntimeTransaction/copy_array_from_storage-2261k ± 0%261k ± 0%~(all equal)
 

@codecov-commenter
Copy link

Codecov Report

Merging #2217 (1c062a7) into master (7939698) will decrease coverage by 0.01%.
The diff coverage is 92.30%.

@@            Coverage Diff             @@
##           master    #2217      +/-   ##
==========================================
- Coverage   57.55%   57.54%   -0.02%     
==========================================
  Files         642      642              
  Lines       38129    38133       +4     
==========================================
- Hits        21946    21944       -2     
- Misses      13389    13400      +11     
+ Partials     2794     2789       -5     
Flag Coverage Δ
unittests 57.54% <92.30%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
fvm/meter/basic/meter.go 92.50% <50.00%> (ø)
fvm/meter/weighted/meter.go 82.53% <100.00%> (ø)
fvm/state/state.go 73.04% <100.00%> (ø)
fvm/transactionEnv.go 46.52% <100.00%> (-0.18%) ⬇️
fvm/transactionInvoker.go 70.96% <100.00%> (+1.20%) ⬆️
consensus/hotstuff/eventloop/event_loop.go 68.29% <0.00%> (-8.54%) ⬇️
...sus/approvals/assignment_collector_statemachine.go 44.23% <0.00%> (-2.89%) ⬇️
engine/collection/synchronization/engine.go 67.93% <0.00%> (-1.09%) ⬇️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7939698...1c062a7. Read the comment docs.

@janezpodhostnik
Copy link
Contributor Author

bors merge

@bors
Copy link
Contributor

bors bot commented Mar 30, 2022

@bors bors bot merged commit 0d15448 into master Mar 30, 2022
@bors bors bot deleted the janez/fix-execution-effort-metering-limits-port2master branch March 30, 2022 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants