Skip to content

fix: number of shards calculation#579

Merged
r-near merged 2 commits into
mainfrom
fix/number-of-shards-calculation
Mar 31, 2026
Merged

fix: number of shards calculation#579
r-near merged 2 commits into
mainfrom
fix/number-of-shards-calculation

Conversation

@frolvanya

@frolvanya frolvanya commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

The EXPERIMENTAL_protocol_config RPC response includes "account_id_validity_rules_version": 2, but the AccountIdValidityRulesVersion enum in the published near-primitives-core crate v0.34.7 only defines variants V0 and V1, so serde rejects the value during deserialization. This will be added in near-primitives-core crate v0.35.0, but I think it's safer and faster to eliminate additional RPC request by fetching number of shards from an existing block fetch request

image

@frolvanya frolvanya requested a review from a team as a code owner March 30, 2026 20:53
Copilot AI review requested due to automatic review settings March 30, 2026 20:53
@github-project-automation github-project-automation Bot moved this to NEW❗ in DevTools Mar 30, 2026

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 avoids using the EXPERIMENTAL_protocol_config RPC (which currently fails to deserialize due to an enum-version mismatch in near-primitives-core v0.34.7) by deriving the shard count from an already-fetched block response.

Changes:

  • Fetch the full block once and compute number_of_shards from block.chunks.len() instead of calling EXPERIMENTAL_protocol_config.
  • Remove the extra RPC request previously used to determine shard layout / shard count.
  • Update Cargo.lock with a broad set of dependency version changes.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/commands/contract/download_wasm/mod.rs Uses the block response (header + chunks) to derive shard count and removes the protocol-config RPC call.
Cargo.lock Large lockfile refresh including near-* patch bumps and transitive dependency upgrades (notably ureq major version bump).

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

Comment on lines +363 to 367
let block_height = block.header.height;
let number_of_shards = block.chunks.len() as u64;

for block_height in block_height..=block_height + number_of_shards * 2 {
tracing::info!(

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

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

The loop variable block_height shadows the outer block_height derived from the fetched block. This makes the control flow and the final error message harder to reason about. Consider renaming the loop variable (e.g., height) to avoid shadowing and improve readability.

Copilot uses AI. Check for mistakes.

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.

It was already like that before, I don't see any issue

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

No great in general as the block.header.height could have used a more descriptive name that would communicate the fact that it is the first block where should start searching from since it is the block that the transaction landed. Yet, I don't see a reason to re-run the CI just for this

@frolvanya

frolvanya commented Mar 30, 2026

Copy link
Copy Markdown
Contributor Author

We need to do something with flaky tests. 3 reruns with 3 different outcomes is not okay

P.S: I see that fix is already in main branch

@vsavchyn-dev

Copy link
Copy Markdown
Contributor

@frolvanya it should be fixed in general with upcoming 2.11 release of sandboxed nearcore - fast_forward wasn't producing blocks in sandboxed neard. Fix for it is already merged to main and is included to 2.11 release branch: near/nearcore#14899

@r-near r-near merged commit ddb3927 into main Mar 31, 2026
13 checks passed
@r-near r-near deleted the fix/number-of-shards-calculation branch March 31, 2026 02:45
@github-project-automation github-project-automation Bot moved this from NEW❗ to Shipped 🚀 in DevTools Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Shipped 🚀

Development

Successfully merging this pull request may close these issues.

6 participants