Skip to content

fix(runtime): fix record_contract_call using RuntimeContractIdentifier#15430

Merged
pugachAG merged 4 commits into
masterfrom
fix-record-contract-call
Mar 23, 2026
Merged

fix(runtime): fix record_contract_call using RuntimeContractIdentifier#15430
pugachAG merged 4 commits into
masterfrom
fix-record-contract-call

Conversation

@pugachAG

@pugachAG pugachAG commented Mar 21, 2026

Copy link
Copy Markdown
Contributor

record_contract_call was using AccountContract (the on-chain stored value) to determine which contract code hash to record for distribution to validators. This is incorrect for the old ETH wallet accounts: the stored hash is the magic bytes hash, not the actual contract code hash, and for accounts using global contracts the wrong trie key was used. This is a better alternative to #15415.

  • Move record_contract_call from TrieUpdate method to a standalone function in function_call.rs that dispatches on RuntimeContractIdentifier, which already has the correctly resolved code hash and contract type
  • Remove GlobalEthWallet variant and old_hash() — no longer needed since the standalone function records the correct code hash directly from the resolved identifier
  • Remove LegacyEthWallet::magic_bytes_hash() as it has no remaining callers
  • Carry GlobalContractIdentifier in the Global variant and AccountId in the AccountLocal variant so record_contract_call can construct the correct trie key without extra arguments
  • Convert AccountLocal and Global to named-field struct variants
  • Drop Copy from RuntimeContractIdentifier since GlobalContractIdentifier contains AccountId
  • Add a regression test: extend test_eth_implicit_global_contract_mainnet_upgrade with a stateless validator that has its compiled contract cache cleared, verifying the global contract is properly distributed via the witness

Stacked on #15429.

@pugachAG pugachAG changed the title fix(runtime): fix record_contract_call to use RuntimeContractIdentifier fix(runtime): fix record_contract_call using RuntimeContractIdentifier Mar 21, 2026
@codecov

codecov Bot commented Mar 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.46154% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.10%. Comparing base (cd42973) to head (cafd904).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
runtime/runtime/src/function_call.rs 86.66% 1 Missing and 3 partials ⚠️
runtime/runtime/src/contract_code.rs 90.90% 0 Missing and 1 partial ⚠️
runtime/runtime/src/lib.rs 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #15430      +/-   ##
==========================================
- Coverage   69.11%   69.10%   -0.02%     
==========================================
  Files         935      936       +1     
  Lines      210213   210309      +96     
  Branches   210213   210309      +96     
==========================================
+ Hits       145283   145328      +45     
- Misses      58944    58979      +35     
- Partials     5986     6002      +16     
Flag Coverage Δ
pytests-nightly 1.16% <0.00%> (-0.01%) ⬇️
unittests 68.43% <84.61%> (-0.02%) ⬇️
unittests-nightly 68.62% <88.46%> (-0.01%) ⬇️

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

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pugachAG pugachAG requested review from Trisfald and wacban March 23, 2026 09:45
@pugachAG pugachAG marked this pull request as ready for review March 23, 2026 09:45
@pugachAG pugachAG requested a review from a team as a code owner March 23, 2026 09:45

@Trisfald Trisfald left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Comment thread runtime/runtime/src/function_call.rs Outdated

@wacban wacban left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Base automatically changed from runtime-contract-identifier-refactor to master March 23, 2026 14:22
pugachAG and others added 3 commits March 23, 2026 16:32
…ntifier

- Move record_contract_call from TrieUpdate method to standalone function
  in function_call.rs that dispatches based on RuntimeContractIdentifier
- Remove GlobalEthWallet variant and old_hash() — no longer needed since
  record_contract_call now uses the resolved contract identifier directly
- Remove LegacyEthWallet::magic_bytes_hash() as it has no remaining callers
- Change Global variant to carry GlobalContractIdentifier for trie key
  construction in record_contract_call
- Add AccountId to AccountLocal variant for the same reason
- Convert AccountLocal and Global to named-field struct variants
- Drop Copy from RuntimeContractIdentifier (GlobalContractIdentifier
  contains AccountId)

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Copilot AI review requested due to automatic review settings March 23, 2026 15:39
@pugachAG pugachAG force-pushed the fix-record-contract-call branch from 214b581 to 6b6af53 Compare March 23, 2026 15:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes contract-access recording during function calls so stateless validation / contract distribution records the effective executed contract (including ETH implicit/global-contract cases) by keying off RuntimeContractIdentifier rather than the on-chain AccountContract representation.

Changes:

  • Move and reimplement record_contract_call as a runtime-local helper that dispatches on RuntimeContractIdentifier and records the correct trie key + code hash.
  • Simplify RuntimeContractIdentifier (remove GlobalEthWallet/stored_hash, switch to named-field variants carrying AccountId / GlobalContractIdentifier, drop Copy).
  • Extend the existing test-loop regression by adding a chunk-only validator and clearing its compiled-contract cache to verify contract propagation via witness distribution.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
runtime/runtime/src/function_call.rs Replace TrieUpdate::record_contract_call usage with a new helper based on RuntimeContractIdentifier and correct trie key selection.
runtime/runtime/src/contract_code.rs Update RuntimeContractIdentifier variants to carry enough context (account/global identifier) and remove legacy hash plumbing.
runtime/runtime/src/ext.rs Adjust contract code lookup to match the updated RuntimeContractIdentifier variants.
core/store/src/trie/update.rs Remove the old TrieUpdate::record_contract_call method now handled in runtime.
runtime/near-wallet-contract/src/lib.rs Remove LegacyEthWallet::magic_bytes_hash() (no remaining callers).
test-loop-tests/src/utils/node.rs Add a test-feature-only helper to clear a node’s compiled-contract cache.
test-loop-tests/src/tests/mod.rs Gate eth_implicit_global_contract test module behind test_features.
test-loop-tests/src/tests/eth_implicit_global_contract.rs Add a chunk-only validator and clear its cache to validate global contract distribution behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread runtime/runtime/src/function_call.rs
Comment thread test-loop-tests/src/utils/node.rs
Comment thread test-loop-tests/src/tests/eth_implicit_global_contract.rs Outdated

@wacban wacban left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

stamp after rebase

@pugachAG pugachAG added this pull request to the merge queue Mar 23, 2026
Merged via the queue into master with commit d071938 Mar 23, 2026
32 checks passed
@pugachAG pugachAG deleted the fix-record-contract-call branch March 23, 2026 22:30
pugachAG added a commit that referenced this pull request Mar 24, 2026
Reverts #15415 (fix: properly include accessed contracts for eth
implicit account) and replaces it with #15430 which uses
RuntimeContractIdentifier for correct dispatch.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
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.

4 participants