Skip to content

fix(runtime): trie viewer view contract code and call function#15437

Merged
pugachAG merged 2 commits into
masterfrom
fix-view-account-contract-code
Mar 24, 2026
Merged

fix(runtime): trie viewer view contract code and call function#15437
pugachAG merged 2 commits into
masterfrom
fix-view-account-contract-code

Conversation

@pugachAG

@pugachAG pugachAG commented Mar 23, 2026

Copy link
Copy Markdown
Contributor
  • Fix view_account_contract_code (ViewCode RPC): was using AccountContractAccessExt::code which reads raw bytes from the trie, returning the magic bytes blob instead of actual wallet contract WASM for legacy ETH implicit accounts. Now uses RuntimeContractIdentifier::resolve() which correctly handles all contract types: local contracts, global contracts (by hash and by account id), and legacy ETH wallet contracts.
  • Fix call_function (view function calls): was using hardcoded PROTOCOL_VERSION to resolve the runtime config instead of view_state.current_protocol_version, which could return incorrect config for the actual protocol version of the block being queried.
  • Store RuntimeConfigStore on TrieViewer and pass it via new() instead of creating a new one on every call. Make max_gas_burnt_view an Option<Gas> that resolves from the runtime config for the current protocol version when not explicitly set.
  • Remove now-unused AccountContractAccessExt trait.

@codecov

codecov Bot commented Mar 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.17391% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.09%. Comparing base (d071938) to head (a8e652a).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
chain/chain/src/runtime/mod.rs 73.52% 5 Missing and 4 partials ⚠️
tools/state-viewer/src/commands.rs 0.00% 7 Missing ⚠️
runtime/runtime/src/state_viewer/mod.rs 88.88% 2 Missing and 3 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master   #15437   +/-   ##
=======================================
  Coverage   69.09%   69.09%           
=======================================
  Files         936      936           
  Lines      210309   210355   +46     
  Branches   210309   210355   +46     
=======================================
+ Hits       145314   145355   +41     
- Misses      58991    58997    +6     
+ Partials     6004     6003    -1     
Flag Coverage Δ
pytests-nightly 1.16% <0.00%> (-0.01%) ⬇️
unittests 68.44% <77.17%> (+<0.01%) ⬆️
unittests-nightly 68.62% <77.17%> (+<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 force-pushed the fix-view-account-contract-code branch from 0d92ea6 to 7f0573c Compare March 23, 2026 22:00
@pugachAG pugachAG changed the base branch from master to fix-record-contract-call March 23, 2026 22:00
@pugachAG pugachAG force-pushed the fix-view-account-contract-code branch 2 times, most recently from 93014d7 to aa1a154 Compare March 23, 2026 22:30
Base automatically changed from fix-record-contract-call to master March 23, 2026 22:30
@pugachAG pugachAG force-pushed the fix-view-account-contract-code branch 2 times, most recently from 8a69c21 to 34f5f40 Compare March 24, 2026 09:35
@pugachAG pugachAG changed the title fix(runtime): use RuntimeContractIdentifier in view_account_contract_code fix(runtime): fix view_account_contract_code and call_function in TrieViewer Mar 24, 2026
@pugachAG pugachAG changed the title fix(runtime): fix view_account_contract_code and call_function in TrieViewer fix(runtime): TrieViewer view contract code and call function Mar 24, 2026
@pugachAG pugachAG requested a review from wacban March 24, 2026 09:38
@pugachAG pugachAG changed the title fix(runtime): TrieViewer view contract code and call function fix(runtime): trie viewer view contract code and call function Mar 24, 2026
…code

The ViewCode RPC query used AccountContractAccessExt::code which reads
raw bytes from the trie. This returned incorrect results for legacy ETH
implicit accounts (magic bytes blob instead of actual wallet contract
WASM) and didn't handle all global contract edge cases.

Replace with RuntimeContractIdentifier::resolve() which already handles
all contract resolution cases correctly. Store chain_id and
RuntimeConfigStore on TrieViewer to support the resolution. Also
simplify call_function to reuse these stored fields.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@pugachAG pugachAG force-pushed the fix-view-account-contract-code branch from 34f5f40 to c89f56e Compare March 24, 2026 09:39
@pugachAG pugachAG marked this pull request as ready for review March 24, 2026 09:39
@pugachAG pugachAG requested a review from a team as a code owner March 24, 2026 09:39
Copilot AI review requested due to automatic review settings March 24, 2026 09:40

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

This PR updates the runtime trie viewer to correctly resolve and return executable contract code for all contract types (including legacy ETH implicit wallet accounts and global contracts), and fixes view-function execution to use the runtime config for the queried block’s protocol version.

Changes:

  • Reworks view_account_contract_code to use RuntimeContractIdentifier::resolve() instead of reading raw trie bytes, fixing legacy ETH implicit wallet code resolution.
  • Fixes call_function to use view_state.current_protocol_version when selecting runtime config, and caches RuntimeConfigStore on TrieViewer.
  • Removes the now-unused AccountContractAccessExt helper trait.

Reviewed changes

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

Show a summary per file
File Description
runtime/runtime/src/state_viewer/mod.rs Correct contract code resolution + protocol-version-aware view gas selection; stores RuntimeConfigStore on TrieViewer.
runtime/runtime/src/contract_code.rs Removes AccountContractAccessExt (no longer needed with identifier-based resolution).
integration-tests/src/user/runtime_user.rs Updates RuntimeUser to call new view_account_contract_code signature (adds protocol version + chain id args).
integration-tests/src/tests/runtime/state_viewer.rs Updates TrieViewer::new call sites to pass a RuntimeConfigStore.
chain/chain/src/runtime/mod.rs Constructs TrieViewer with a shared RuntimeConfigStore; updates ViewCode path to call new viewer API (but currently passes PROTOCOL_VERSION).

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

Comment thread chain/chain/src/runtime/mod.rs
Comment on lines +398 to +405
fn max_gas_burnt_view(&self, protocol_version: ProtocolVersion) -> Gas {
self.max_gas_burnt_view.unwrap_or_else(|| {
self.runtime_config_store
.get_config(protocol_version)
.wasm_config
.limit_config
.max_gas_burnt
})

Copilot AI Mar 24, 2026

Copy link

Choose a reason for hiding this comment

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

The struct field max_gas_burnt_view and the helper method max_gas_burnt_view(&self, ...) share the same name. This is easy to misread and may trigger clippy::same_name_method depending on the lint set used in CI. Consider renaming the method to something like resolved_max_gas_burnt_view (or renaming the field) to avoid ambiguity.

Copilot uses AI. Check for mistakes.
Comment thread integration-tests/src/user/runtime_user.rs

@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, but see comment about protocol version

Comment thread chain/chain/src/runtime/mod.rs Outdated
self.trie_viewer.view_account_contract_code(
&state_update,
account_id,
PROTOCOL_VERSION,

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.

this seems wrong, why not use the protocol version matching the state root?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, missed that, fixing now

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@pugachAG pugachAG enabled auto-merge March 24, 2026 10:14
@pugachAG pugachAG added this pull request to the merge queue Mar 24, 2026
Merged via the queue into master with commit 9700906 Mar 24, 2026
32 checks passed
@pugachAG pugachAG deleted the fix-view-account-contract-code branch March 24, 2026 10:43
pugachAG added a commit that referenced this pull request Mar 24, 2026
- Fix `view_account_contract_code` (ViewCode RPC): was using
`AccountContractAccessExt::code` which reads raw bytes from the trie,
returning the magic bytes blob instead of actual wallet contract WASM
for legacy ETH implicit accounts. Now uses
`RuntimeContractIdentifier::resolve()` which correctly handles all
contract types: local contracts, global contracts (by hash and by
account id), and legacy ETH wallet contracts.
- Fix `call_function` (view function calls): was using hardcoded
`PROTOCOL_VERSION` to resolve the runtime config instead of
`view_state.current_protocol_version`, which could return incorrect
config for the actual protocol version of the block being queried.
- Store `RuntimeConfigStore` on `TrieViewer` and pass it via `new()`
instead of creating a new one on every call. Make `max_gas_burnt_view`
an `Option<Gas>` that resolves from the runtime config for the current
protocol version when not explicitly set.
- Remove now-unused `AccountContractAccessExt` trait.

---------

Co-authored-by: Claude Opus 4.6 <[email protected]>
pugachAG added a commit that referenced this pull request Mar 24, 2026
…ract test

- Extend test_eth_implicit_global_contract_mainnet_upgrade to verify
  ViewCode and CallFunction (get_nonce) RPC queries before and after the
  PV 82 -> 83 protocol upgrade, covering the code paths fixed in #15437.
- At PV 82: verify ViewCode returns the legacy localnet wallet contract
  WASM and get_nonce returns 0.
- At PV 83: verify ViewCode returns the deployed global contract WASM
  for both old (magic-bytes) and new ETH implicit accounts, get_nonce
  returns 0 before and 1 after rlp_execute.
- Refactor NodeRunner::run_jsonrpc_query into run_with_jsonrpc_client
  (generic, takes closure) and a new run_jsonrpc_query that directly
  accepts RpcQueryRequest, simplifying all query call sites.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
pugachAG added a commit that referenced this pull request Mar 24, 2026
…ract test

- Extend test_eth_implicit_global_contract_mainnet_upgrade to verify
  ViewCode and CallFunction (get_nonce) RPC queries before and after the
  PV 82 -> 83 protocol upgrade, covering the code paths fixed in #15437.
- At PV 82: verify ViewCode returns the legacy localnet wallet contract
  WASM and get_nonce returns 0.
- At PV 83: verify ViewCode returns the deployed global contract WASM
  for both old (magic-bytes) and new ETH implicit accounts, get_nonce
  returns 0 before and 1 after rlp_execute.
- Refactor NodeRunner::run_jsonrpc_query into run_with_jsonrpc_client
  (generic, takes closure) and a new run_jsonrpc_query that directly
  accepts RpcQueryRequest, simplifying all query call sites.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
pugachAG added a commit that referenced this pull request Mar 24, 2026
…ract test

- Extend test_eth_implicit_global_contract_mainnet_upgrade to verify
  ViewCode and CallFunction (get_nonce) RPC queries before and after the
  PV 82 -> 83 protocol upgrade, covering the code paths fixed in #15437.
- At PV 82: verify ViewCode returns the legacy localnet wallet contract
  WASM and get_nonce returns 0.
- At PV 83: verify ViewCode returns the deployed global contract WASM
  for both old (magic-bytes) and new ETH implicit accounts, get_nonce
  returns 0 before and 1 after rlp_execute.
- Refactor NodeRunner::run_jsonrpc_query into run_with_jsonrpc_client
  (generic, takes closure) and a new run_jsonrpc_query that directly
  accepts RpcQueryRequest, simplifying all query call sites.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
pugachAG added a commit that referenced this pull request Mar 24, 2026
…ract test

- Extend test_eth_implicit_global_contract_mainnet_upgrade to verify
  ViewCode and CallFunction (get_nonce) RPC queries before and after the
  PV 82 -> 83 protocol upgrade, covering the code paths fixed in #15437.
- At PV 82: verify ViewCode returns the legacy localnet wallet contract
  WASM and get_nonce returns 0.
- At PV 83: verify ViewCode returns the deployed global contract WASM
  for both old (magic-bytes) and new ETH implicit accounts, get_nonce
  returns 0 before and 1 after rlp_execute.
- Refactor NodeRunner::run_jsonrpc_query into run_with_jsonrpc_client
  (generic, takes closure) and a new run_jsonrpc_query that directly
  accepts RpcQueryRequest, simplifying all query call sites.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
github-merge-queue Bot pushed a commit that referenced this pull request Mar 25, 2026
…ract test (#15446)

Extend `test_eth_implicit_global_contract_mainnet_upgrade` to verify
ViewCode and CallFunction (`get_nonce`) RPC queries before and after the
PV 82 -> 83 protocol upgrade, covering the code paths fixed in #15437.

- At PV 82: verify ViewCode returns the legacy localnet wallet contract
WASM and `get_nonce` returns 0.
- At PV 83: verify ViewCode returns the deployed global contract WASM
for both old (magic-bytes) and new ETH implicit accounts, `get_nonce`
returns 0 before and 1 after `rlp_execute`.
- Refactor `NodeRunner::run_jsonrpc_query` into
`run_with_jsonrpc_client` (generic, takes closure) and a new
`run_jsonrpc_query` that directly accepts `RpcQueryRequest`, simplifying
all query call sites.

Co-authored-by: Claude Opus 4.6 <[email protected]>
@VanBarbascu VanBarbascu mentioned this pull request Apr 15, 2026
25 tasks
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.

3 participants