-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[pallet-revive] implement the gas limit API #6926
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
Changes from 3 commits
9113580
4ca3271
d1d557e
e7cd288
23e145f
1dfbcdd
9ccddba
911c823
13dfd9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| title: '[pallet-revive] implement the gas limit API' | ||
| doc: | ||
| - audience: Runtime Dev | ||
| description: This PR implements the gas limit API, returning the maximum ref_time | ||
| per block. Solidity contracts only know a single weight dimension and can use | ||
| this method to get the block ref_time limit. | ||
| crates: | ||
| - name: pallet-revive-fixtures | ||
| bump: major | ||
| - name: pallet-revive | ||
| bump: major | ||
| - name: pallet-revive-uapi | ||
| bump: major |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // This file is part of Substrate. | ||
|
|
||
| // Copyright (C) Parity Technologies (UK) Ltd. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| //! Returns the block ref_time limit back to the caller. | ||
|
|
||
| #![no_std] | ||
| #![no_main] | ||
|
|
||
| extern crate common; | ||
| use uapi::{HostFn, HostFnImpl as api, ReturnFlags}; | ||
|
|
||
| #[no_mangle] | ||
| #[polkavm_derive::polkavm_export] | ||
| pub extern "C" fn deploy() {} | ||
|
|
||
| #[no_mangle] | ||
| #[polkavm_derive::polkavm_export] | ||
| pub extern "C" fn call() { | ||
| api::return_value(ReturnFlags::empty(), &api::gas_limit().to_le_bytes()); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -374,14 +374,15 @@ impl RegisteredChainExtension<Test> for TempStorageExtension { | |
| parameter_types! { | ||
| pub BlockWeights: frame_system::limits::BlockWeights = | ||
| frame_system::limits::BlockWeights::simple_max( | ||
| Weight::from_parts(2u64 * WEIGHT_REF_TIME_PER_SECOND, u64::MAX), | ||
| Weight::from_parts(2 * WEIGHT_REF_TIME_PER_SECOND, u64::MAX), | ||
| ); | ||
|
Comment on lines
375
to
378
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can't we delete this and just use the default
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I think we should have this consistent. But I think it should be the maximum we aim to support. What would that be?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bumped it a bit further to |
||
| pub static ExistentialDeposit: u64 = 1; | ||
| } | ||
|
|
||
| #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] | ||
| impl frame_system::Config for Test { | ||
| type Block = Block; | ||
| type BlockWeights = BlockWeights; | ||
| type AccountId = AccountId32; | ||
| type Lookup = IdentityLookup<Self::AccountId>; | ||
| type AccountData = pallet_balances::AccountData<u64>; | ||
|
|
@@ -3483,7 +3484,7 @@ fn deposit_limit_in_nested_calls() { | |
| // Require more than the sender's balance. | ||
| // Limit the sub call to little balance so it should fail in there | ||
| let ret = builder::bare_call(addr_caller) | ||
| .data((512u32, &addr_callee, U256::from(1u64)).encode()) | ||
| .data((384u32, &addr_callee, U256::from(1u64)).encode()) | ||
| .build_and_unwrap_result(); | ||
| assert_return_code!(ret, RuntimeReturnCode::OutOfResources); | ||
|
|
||
|
|
@@ -4818,6 +4819,27 @@ fn skip_transfer_works() { | |
| }); | ||
| } | ||
|
|
||
| #[test] | ||
| fn gas_limit_api_works() { | ||
| let (code, _) = compile_module("gas_limit").unwrap(); | ||
|
|
||
| ExtBuilder::default().existential_deposit(100).build().execute_with(|| { | ||
| let _ = <Test as Config>::Currency::set_balance(&ALICE, 1_000_000); | ||
|
|
||
| // Create fixture: Constructor does nothing | ||
| let Contract { addr, .. } = | ||
| builder::bare_instantiate(Code::Upload(code)).build_and_unwrap_contract(); | ||
|
|
||
| // Call the contract: It echoes back the value returned by the gas limit API. | ||
| let received = builder::bare_call(addr).build_and_unwrap_result(); | ||
| assert_eq!(received.flags, ReturnFlags::empty()); | ||
| assert_eq!( | ||
| u64::from_le_bytes(received.data[..].try_into().unwrap()), | ||
| <Test as frame_system::Config>::BlockWeights::get().max_block.ref_time() | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| #[test] | ||
| fn unknown_syscall_rejected() { | ||
| let (code, _) = compile_module("unknown_syscall").unwrap(); | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems unrelated. Why was this changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should have pointed out. The integrity checks fail with 2 seconds ref_time and payload bytes of 512 because the
max_events_size < storage_size_limitfails. I lowered this because I think we want 2s ref_time per block.If there is a better solution or the integrity check is incorrect we should fix that, I'm open.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a parachain you only have 0.5s of execution time. With async backing its 1 second I think. But probably better to lower this ratio in order to future proof.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correction 2s: https://wiki.polkadot.network/docs/maintain-guides-async-backing#phase-3---activate-async-backing