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

feat: limit contract functions number #4954

Merged
merged 35 commits into from
Oct 18, 2021
Merged

feat: limit contract functions number #4954

merged 35 commits into from
Oct 18, 2021

Conversation

Longarithm
Copy link
Member

@Longarithm Longarithm commented Oct 8, 2021

Limit max contract functions number to 2000 10000.
See corresponding Zulip thread for more details.

Test plan

  • add new tests on config and vm side
  • check that this doesn't break existing contracts

Notes:

core/primitives-core/src/config.rs Outdated Show resolved Hide resolved
runtime/near-vm-runner/src/preload.rs Outdated Show resolved Hide resolved
runtime/near-vm-runner/src/prepare.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@EgorKulikov EgorKulikov left a comment

Choose a reason for hiding this comment

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

Looks good, but please address @matklad comments about tests

integration-tests/tests/client/process_blocks.rs Outdated Show resolved Hide resolved
runtime/near-vm-errors/src/lib.rs Outdated Show resolved Hide resolved
runtime/near-vm-runner/src/tests/contract_preload.rs Outdated Show resolved Hide resolved
runtime/near-vm-runner/src/tests/contract_preload.rs Outdated Show resolved Hide resolved
@Longarithm Longarithm self-assigned this Oct 18, 2021
@Longarithm Longarithm added the A-transaction-runtime Area: transaction runtime (transaction and receipts processing, state transition, etc) label Oct 18, 2021
@Longarithm
Copy link
Member Author

There was a problem with reusing make_simple_contract_call_with_gas_vm.
Tests like test_stack_overflow check exact number of gas spent, so it seems better to use test runtime configs there, to avoid recomputing numbers each time.
And new test test_limit_contract_functions_number need real vm configs to check enabling of functions number limit.
So now we have make_simple_contract_call_with_protocol_version_vm, make_simple_contract_call_with_gas_vm, make_cached_contract_call_vm and I think they can be united later.

Copy link
Contributor

@matklad matklad left a comment

Choose a reason for hiding this comment

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

LGTM, feel free to auto-merge!

Comment on lines +127 to +128
#[cfg(feature = "protocol_feature_limit_contract_functions_number")]
LimitContractFunctionsNumber,
Copy link
Contributor

Choose a reason for hiding this comment

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

The ProtocolFeature is a natural entry point for learning about implications of a particular feature, so I think comments on enum variants here have high leverage -- you can say little, but that wouldn't require ongoing maintanence, will help other people, and could be copy-pasted into the feature stabilization PR.

Comment on lines 179 to 185
let result = make_simple_contract_call_with_protocol_version_vm(
&code,
method_name,
new_protocol_version,
vm_kind,
);
assert_eq!(result.1, None);
Copy link
Contributor

Choose a reason for hiding this comment

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

As an alternative, I'd write this as

let (_outcome, err) = ...
assert_eq!(err, None);

Explicit tuple unpacking with naming of the ignored components improves readability.

@Longarithm Longarithm merged commit 90e182b into master Oct 18, 2021
@Longarithm Longarithm deleted the limit-functions branch October 18, 2021 13:22
near-bulldozer bot pushed a commit that referenced this pull request Oct 18, 2021
While working with #4954, initially I put new test into `contract_preload` test file, though `invalid_contracts` turned out to be a better place.

Rename test files, hope this will make the choice of places for new tests in the future clearer.

Test plan
---------
Existing tests.
near-bulldozer bot pushed a commit that referenced this pull request Nov 20, 2021
Stabilize limiting functions number in a contract to 10_000: #4954

While discussing #4826, we found that both contract compilation and function call require a lot of time, if number of wasm functions in it is huge. Even if we fix contract size, function number still makes a big difference.

To mitigate this issue, we limit number of functions in a contract. This shouldn't affect current mainnet contracts because maximal number of functions is ~5k.

## Test plan

* http://nayduck.near.org/#/run/2223
* existing tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-transaction-runtime Area: transaction runtime (transaction and receipts processing, state transition, etc)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants