Skip to content

Conversation

pugachAG
Copy link
Contributor

@pugachAG pugachAG commented May 15, 2025

This PR adds QueryRequest for retrieving global contract code. This is needed because ViewCode query only allows retrieving contracted used as part of the specified accounts. Global contracts deployed separately, so we need to have a dedicated view query.

2 separate enum variants are introduced for queries by hash (ViewGlobalContractCode) and by account id (ViewGlobalContractCodeByAccountId) to have simple API and keep it consistent with DeployGlobalContract/UseGlobalContract actions.

QueryResponseKind::ViewCode is reused for the response.

Also QueryError::NoGlobalContractCode error is introduced, similar to NoContractCode.

Closes #13531.

Copy link

codecov bot commented May 15, 2025

Codecov Report

Attention: Patch coverage is 82.17822% with 18 lines in your changes missing coverage. Please review.

Project coverage is 69.49%. Comparing base (221eb4f) to head (f13a8a5).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
chain/chain/src/runtime/mod.rs 86.00% 5 Missing and 2 partials ⚠️
chain/client/src/view_client_actor.rs 73.91% 4 Missing and 2 partials ⚠️
chain/chain/src/runtime/errors.rs 0.00% 2 Missing ⚠️
chain/jsonrpc/src/api/query.rs 0.00% 2 Missing ⚠️
runtime/runtime/src/state_viewer/mod.rs 90.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #13547       +/-   ##
===========================================
+ Coverage    1.62%   69.49%   +67.86%     
===========================================
  Files         660      855      +195     
  Lines      114960   167998    +53038     
  Branches   114960   167998    +53038     
===========================================
+ Hits         1873   116747   +114874     
+ Misses     113031    46481    -66550     
- Partials       56     4770     +4714     
Flag Coverage Δ
pytests 1.52% <0.00%> (?)
pytests-nightly 1.62% <0.00%> (-0.01%) ⬇️
unittests 69.11% <82.17%> (?)
unittests-nightly 69.02% <82.17%> (?)

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 rpc-view-global-contract-code branch 2 times, most recently from 5dfe82a to 47978a7 Compare May 15, 2025 12:15
@pugachAG pugachAG requested a review from wacban May 15, 2025 12:19
@pugachAG pugachAG marked this pull request as ready for review May 15, 2025 12:19
@pugachAG pugachAG requested a review from a team as a code owner May 15, 2025 12:19
@wacban
Copy link
Contributor

wacban commented May 15, 2025

hey, sorry, I'm OOO tomorrow and I won't be able to review it today, if you need a fast review please ask someone else, otherwise I'll have a look next week.

@pugachAG pugachAG requested a review from shreyan-gupta May 15, 2025 17:39
Copy link
Contributor

@wacban wacban left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +439 to +446
#[error(
"Global contract code with identifier {identifier:?} has never been observed on the node"
)]
NoGlobalContractCode {
identifier: near_primitives::action::GlobalContractIdentifier,
block_height: near_primitives::types::BlockHeight,
block_hash: near_primitives::hash::CryptoHash,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

This is duplicated, does it need to be?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

unfortunately yes, I was also annoyed by this ☹️

| QueryRequest::ViewGlobalContractCodeByAccountId { .. } => {
// for global contract queries we can use any shard_id, so just take the first one
let shard_ids = self.epoch_manager.shard_ids(&epoch_id)?;
Ok(*shard_ids.iter().next().expect("at least one shard should always exist"))
Copy link
Contributor

Choose a reason for hiding this comment

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

cc @staffik Just musing - this will be fun when we move to single shard tracking RPC

@pugachAG pugachAG force-pushed the rpc-view-global-contract-code branch from 6910ea6 to f13a8a5 Compare May 19, 2025 11:02
@pugachAG pugachAG added this pull request to the merge queue May 19, 2025
Merged via the queue into master with commit ab9ea00 May 19, 2025
28 checks passed
@pugachAG pugachAG deleted the rpc-view-global-contract-code branch May 19, 2025 11:55
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.

Feature: viewGlobalCode RPC request
2 participants