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

Remove 0 as a special case in gas/storage meters #6890

Merged
merged 43 commits into from
Jan 15, 2025

Conversation

rockbmb
Copy link
Contributor

@rockbmb rockbmb commented Dec 13, 2024

Closes #6846 .

@rockbmb rockbmb added T2-pallets This PR/Issue is related to a particular pallet. T7-smart_contracts This PR/Issue is related to smart contracts. T10-tests This PR/Issue is related to tests. labels Dec 13, 2024
@rockbmb rockbmb self-assigned this Dec 13, 2024
@rockbmb rockbmb force-pushed the evm-contracts-limit-nested-calls-gas branch 2 times, most recently from 376e944 to 4832380 Compare December 17, 2024 02:17
Also, a limit of 0 when determining a nested call's metering limit would
mean it was free to use all of the callee's resources.
Now, a limit of 0 means that the nested call will have an empty storage
meter.
In particular, this commit removes the usage of `0` as unlimited
metering in the following tests:

- `nonce`
- `last_frame_output_works_on_instantiate`
- `instantiation_from_contract`
- `immutable_data_set_works_only_once`
- `immutable_data_set_errors_with_empty_data`
- `immutable_data_access_checks_work`
@rockbmb rockbmb force-pushed the evm-contracts-limit-nested-calls-gas branch from ed1f312 to 8e66f50 Compare December 17, 2024 19:15
@rockbmb rockbmb marked this pull request as ready for review December 17, 2024 19:31
@athei athei requested review from athei and xermicus December 17, 2024 20:08
Copy link
Member

@xermicus xermicus left a comment

Choose a reason for hiding this comment

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

The basic idea of the 63/64 rule looks correct to me but there are many failing tests. I left some nits.

substrate/frame/revive/src/gas.rs Outdated Show resolved Hide resolved
substrate/frame/revive/src/storage/meter.rs Outdated Show resolved Hide resolved
substrate/frame/revive/src/storage/meter.rs Outdated Show resolved Hide resolved
This fixes, among other tests:
* `tests::gas_consumed_is_linear_for_nested_calls` test
* `tests::deposit_limit_in_nested_calls`
* `tests::transient_storage_limit_in_call`
* `tests::call_return_code`
* `test::chain_extension_temp_storage_works`
* `tests::origin_api_works`
* `tests::read_only_call_works`
@rockbmb
Copy link
Contributor Author

rockbmb commented Dec 19, 2024

@xermicus the meters in frame::contracts::{gas, storage::meter} also need to reflect this, correct?

@athei
Copy link
Member

athei commented Dec 19, 2024

Sorry if this wasn't clear: Only pallet_revive and its supporting crates should be changed. pallet_contracts should remain untouched. It does't receive any updates beyond critical bug fixes anymore. Can you roll back the changes there? Will have a deeper look then.

@rockbmb
Copy link
Contributor Author

rockbmb commented Dec 19, 2024

@athei frame/contracts changes have been reverted, thanks for explaining this.

Most of the previously failing tests were caused by the contract code of those tests using the now-removed '0 means "use all available gas"' semantic.

After fixing this, cargo test --package pallet-revive:0.1.0 --lib --all-features yields:

failures:
    benchmarking::benchmarks::bench_seal_instantiate
    tests::call_diverging_out_len_works
    tests::create1_with_value_works
    tests::delegate_call
    tests::deploy_and_call_other_contract
    tests::deposit_limit_in_nested_calls
    tests::deposit_limit_in_nested_instantiate
    tests::destroy_contract_and_transfer_funds
    tests::failed_deposit_charge_should_roll_back_call
    tests::gas_estimation_call_runtime
    tests::gas_estimation_for_subcalls
    tests::return_data_api_works
    tests::skip_transfer_works
    tests::storage_deposit_callee_works
    tests::test_debug::debugging_works

The contracts the above tests rely on have removed usages of 0 as "use all", so their failures are somewhere else.

@athei
Copy link
Member

athei commented Jan 10, 2025

I don't get why the benchmarks are failing.

@rockbmb
Copy link
Contributor Author

rockbmb commented Jan 10, 2025

@athei I can always run /cmd bench --pallet pallet_revive.

No significant code was added, only removed (enfore_subcall_limit is only a handful of instructions), but maybe the numbers were lowered enough to warrant rerunning benchmarks.

@rockbmb
Copy link
Contributor Author

rockbmb commented Jan 10, 2025

/cmd bench --pallet pallet_revive

Copy link

Command "bench --pallet pallet_revive" has started 🚀 See logs here

Copy link

Command "bench --pallet pallet_revive" has failed ❌! See logs here

Command output:

❌ Failed benchmarks of runtimes/pallets:
-- dev: ['pallet_revive']
-- asset-hub-westend: ['pallet_revive']

Copy link

Command "bench --pallet pallet_revive" has started 🚀 See logs here

Copy link

Command "bench --pallet pallet_revive" has finished ✅ See logs here

Subweight results:
File Extrinsic Old New Change [%]
cumulus/pallets/collator-selection/src/weights.rs leave_intent - - ERROR
cumulus/pallets/collator-selection/src/weights.rs new_session - - ERROR
cumulus/pallets/collator-selection/src/weights.rs register_as_candidate - - ERROR
cumulus/pallets/collator-selection/src/weights.rs set_invulnerables - - ERROR
cumulus/pallets/collator-selection/src/weights.rs take_candidate_slot - - ERROR
cumulus/pallets/collator-selection/src/weights.rs update_bond - - ERROR
cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_collator_selection.rs update_bond - - ERROR
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_collator_selection.rs update_bond - - ERROR
cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/pallet_collator_selection.rs update_bond - - ERROR
cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/pallet_collator_selection.rs update_bond - - ERROR
cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_collator_selection.rs update_bond - - ERROR
cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_preimage.rs ensure_updated - - ERROR
cumulus/parachains/runtimes/people/people-rococo/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/people/people-rococo/src/weights/pallet_collator_selection.rs update_bond - - ERROR
cumulus/parachains/runtimes/people/people-westend/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/people/people-westend/src/weights/pallet_collator_selection.rs update_bond - - ERROR
polkadot/runtime/westend/src/weights/pallet_preimage.rs ensure_updated - - ERROR
substrate/frame/election-provider-support/src/weights.rs phragmen - - ERROR
substrate/frame/election-provider-support/src/weights.rs phragmms - - ERROR
Command output:

❌ Failed benchmarks of runtimes/pallets:
-- dev: ['pallet_revive']
-- asset-hub-westend: ['pallet_revive']

@athei
Copy link
Member

athei commented Jan 13, 2025

@athei I can always run /cmd bench --pallet pallet_revive.

No significant code was added, only removed (enfore_subcall_limit is only a handful of instructions), but maybe the numbers were lowered enough to warrant rerunning benchmarks.

No the execution of some benchmarks do fail (see failing CI). Which means this PR broke something there. Re-running them will fail for the same reason:
Screenshot 2025-01-13 at 11 09 37

Keep in mind that the benchmarks run with the actual (kitchensink) runtime while the test use the testing config. So this is why the tests can be successful while the benchmark CI job fails. So some debugging needed.

@athei
Copy link
Member

athei commented Jan 14, 2025

The tests which is failing now uses a pre-compiled test fixture written in Solidity. We need to adapt revive to the new behavior and update the pre-compiled test fixtures. The one failing is native_evm_ratio_works.

@xermicus We need to change revive to pass u64::MAX and u256::MAX into delegate_call,call and instantiate for gas limits and storage deposit limits respectively.

Once we have a new revive we can run build-contracts.ts in the pallet-revive-rpc crate in order to update the fixtures.

@paritytech-workflow-stopper
Copy link

All GitHub workflows were cancelled due to failure one of the required jobs.
Failed workflow url: https://github.com/paritytech/polkadot-sdk/actions/runs/12770605066
Failed job name: test-linux-stable

@xermicus
Copy link
Member

Ok @rockbmb @athei I'll prepare a revive compiler companion PR and re-build the fixtures.

Signed-off-by: xermicus <[email protected]>
@xermicus
Copy link
Member

@rockbmb I pushed the updated fixtures directly to your branch.

Copy link
Member

@athei athei left a comment

Choose a reason for hiding this comment

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

@xermicus I think we are good to go here with this PR. Can you review?

prdoc/pr_6890.prdoc Outdated Show resolved Hide resolved
prdoc/pr_6890.prdoc Outdated Show resolved Hide resolved
@athei athei enabled auto-merge January 15, 2025 12:21
@athei athei added this pull request to the merge queue Jan 15, 2025
auto-merge was automatically disabled January 15, 2025 13:55

Pull Request is not mergeable

Merged via the queue into master with commit cb0d854 Jan 15, 2025
189 of 204 checks passed
@athei athei deleted the evm-contracts-limit-nested-calls-gas branch January 15, 2025 14:00
ordian added a commit that referenced this pull request Jan 16, 2025
* master: (33 commits)
  Implement `pallet-asset-rewards` (#3926)
  [pallet-revive] Add host function `to_account_id` (#7091)
  [pallet-revive] Remove revive events (#7164)
  [pallet-revive] Remove debug buffer (#7163)
  litep2p: Provide partial results to speedup GetRecord queries (#7099)
  [pallet-revive] Bump asset-hub westend spec version (#7176)
  Remove 0 as a special case in gas/storage meters (#6890)
  [pallet-revive] Fix `caller_is_root` return value (#7086)
  req-resp/litep2p: Reject inbound requests from banned peers (#7158)
  Add "run to block" tools (#7109)
  Fix reversed error message in DispatchInfo (#7170)
  approval-voting: Make importing of duplicate assignment idempotent (#6971)
  Parachains: Use relay chain slot for velocity measurement (#6825)
  PRDOC: Document `validate: false` (#7117)
  xcm: convert properly assets in xcmpayment apis (#7134)
  CI: Only format umbrella crate during umbrella check (#7139)
  approval-voting: Fix sending of assignments after restart (#6973)
  Retry approval on availability failure if the check is still needed (#6807)
  [pallet-revive-eth-rpc] persist eth transaction hash (#6836)
  litep2p: Sufix litep2p to the identify agent version for visibility (#7133)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T2-pallets This PR/Issue is related to a particular pallet. T7-smart_contracts This PR/Issue is related to smart contracts. T10-tests This PR/Issue is related to tests.
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Limit resources to 63/64 on sub calls and remove 0 as special case for "take all"
3 participants