Skip to content

feat(json-rpc): add view_gas_key_nonces module#14930

Merged
darioush merged 4 commits into
near:masterfrom
darioush:view-gas-key-nonces
Feb 19, 2026
Merged

feat(json-rpc): add view_gas_key_nonces module#14930
darioush merged 4 commits into
near:masterfrom
darioush:view-gas-key-nonces

Conversation

@darioush

@darioush darioush commented Jan 26, 2026

Copy link
Copy Markdown
Contributor

This PR resolves a gas-keys TODO item by implementing the view_gas_key_nonces module and adding the corresponding EXPERIMENTAL_view_gas_key_nonces API call.

Also in this PR, I give view_gas_key_nonces a dedicated error type. The reason is because AccessKeyDoesNotExist seems like a bad error to get in case the key we query for nonces is an ordinary access key.

This change returns GasKeyDoesNotExist in this case. I’m open to alternatives such as introducing separate AccessKeyDoesNotExist and AccessKeyNotGasKey variants, but it still seems nice to keep a dedicated ViewGasKeyNoncesError error type.

@codecov

codecov Bot commented Jan 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 2.50000% with 117 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.06%. Comparing base (fe7197c) to head (bcf0301).
⚠️ Report is 6 commits behind head on master.

Files with missing lines Patch % Lines
...sonrpc-primitives/src/types/view_gas_key_nonces.rs 0.00% 48 Missing ⚠️
chain/jsonrpc/src/lib.rs 3.12% 31 Missing ⚠️
chain/chain/src/runtime/errors.rs 0.00% 15 Missing ⚠️
chain/jsonrpc/src/api/view_gas_key_nonces.rs 0.00% 9 Missing ⚠️
chain/client/src/view_client_actor.rs 0.00% 4 Missing ⚠️
runtime/runtime/src/state_viewer/errors.rs 0.00% 3 Missing ⚠️
runtime/runtime/src/state_viewer/mod.rs 25.00% 3 Missing ⚠️
chain/jsonrpc/src/api/query.rs 0.00% 2 Missing ⚠️
chain/chain/src/runtime/mod.rs 50.00% 1 Missing ⚠️
tools/mirror/src/lib.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #14930      +/-   ##
==========================================
- Coverage   69.09%   69.06%   -0.04%     
==========================================
  Files         921      923       +2     
  Lines      204615   204728     +113     
  Branches   204615   204728     +113     
==========================================
+ Hits       141382   141395      +13     
- Misses      57437    57535      +98     
- Partials     5796     5798       +2     
Flag Coverage Δ
pytests-nightly 1.29% <0.00%> (-0.01%) ⬇️
unittests 68.57% <1.66%> (-0.04%) ⬇️
unittests-nightly 68.63% <2.50%> (-0.03%) ⬇️

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.

Comment thread chain/client-primitives/src/types.rs Outdated
},
#[error(
"Access key for public key {public_key} has never been observed on the node at block #{block_height}"
"Access key for public key {public_key} does not exist while viewing at block #{block_height}"

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.

This seemed incorrect and minor enough to fix in this PR

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.

I'd avoid this, especially considering that the message is rather "imprecise" than "incorrect". feel free to open a separate PR for this

@darioush darioush marked this pull request as ready for review January 26, 2026 23:05
@darioush darioush requested a review from a team as a code owner January 26, 2026 23:05
@darioush darioush force-pushed the view-gas-key-nonces branch from d0f8370 to 06d8e7c Compare February 19, 2026 17:32
Copilot AI review requested due to automatic review settings February 19, 2026 17:32

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 implements the view_gas_key_nonces module to query nonces for gas keys, resolving a TODO item. The implementation adds a new dedicated error type ViewGasKeyNoncesError (instead of reusing ViewAccessKeyError) to distinguish between access keys and gas keys when the queried key is not a gas key.

Changes:

  • Added ViewGasKeyNoncesError error type with proper error conversion implementations
  • Implemented view_gas_key_nonces function in the state viewer to retrieve nonces for gas keys
  • Added EXPERIMENTAL_view_gas_key_nonces JSON-RPC endpoint with complete request/response/error types

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.

Show a summary per file
File Description
runtime/runtime/src/state_viewer/errors.rs Defines new ViewGasKeyNoncesError enum with variants for invalid account, non-existent account, non-existent gas key, and internal errors
runtime/runtime/src/state_viewer/mod.rs Implements view_gas_key_nonces method that retrieves all nonces for a gas key
runtime/runtime/src/adapter.rs Updates ViewRuntimeAdapter trait method signature to return ViewGasKeyNoncesError
chain/chain/src/runtime/errors.rs Adds from_view_gas_key_nonces_error converter function to transform state viewer errors to query errors
chain/chain/src/runtime/mod.rs Implements query handling for ViewGasKeyNonces request type
chain/chain-primitives/src/error.rs Adds UnknownGasKey variant to QueryError enum
chain/client-primitives/src/types.rs Adds UnknownGasKey variant to client QueryError enum and updates error messages
chain/client/src/view_client_actor.rs Adds error conversion for UnknownGasKey from chain primitives to client types
chain/jsonrpc-primitives/src/types/view_gas_key_nonces.rs Defines RPC types: request, response, and error with proper conversions
chain/jsonrpc-primitives/src/types/query.rs Updates RpcQueryError with UnknownGasKey variant and improves error messages
chain/jsonrpc-primitives/src/types/mod.rs Adds view_gas_key_nonces module and removes TODO comment
chain/jsonrpc/src/api/view_gas_key_nonces.rs Implements RPC parsing and error conversion for the new endpoint
chain/jsonrpc/src/api/query.rs Adds conversion from QueryError::UnknownGasKey to RpcQueryError
chain/jsonrpc/src/api/mod.rs Adds view_gas_key_nonces module declaration
chain/jsonrpc/src/lib.rs Registers EXPERIMENTAL_view_gas_key_nonces endpoint and implements handler method
tools/mirror/src/lib.rs Adds UnknownGasKey handling in error conversions for the mirror tool

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

@pugachAG pugachAG removed the request for review from attila0x2A February 19, 2026 19:16

@pugachAG pugachAG 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.

please change the type in the title from chore to feat(json-rpc)

block_hash: near_primitives::hash::CryptoHash,
},
#[error("Access key for public key {public_key} has never been observed on the node")]
#[error("Access key for public key {public_key} does not exist while viewing")]

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.

same for both changes here, please move to a separate PR

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.

@darioush darioush force-pushed the view-gas-key-nonces branch from 5665f6e to bcf0301 Compare February 19, 2026 21:34
@darioush darioush changed the title chore: add view_gas_key_nonces module feat(json-rpc): add view_gas_key_nonces module Feb 19, 2026
@darioush darioush added this pull request to the merge queue Feb 19, 2026
Merged via the queue into near:master with commit 063a0ee Feb 19, 2026
31 of 33 checks passed
@darioush darioush deleted the view-gas-key-nonces branch February 19, 2026 22:08
pull Bot pushed a commit to See887777/nearcore that referenced this pull request Jun 3, 2026
# Gas Keys ([NEP-611](near/NEPs#611))
Gas keys are a new type of access key that carries a pre-funded NEAR
balance and multiple independent nonce sequences. When a transaction is
signed with a gas key, gas costs are deducted from the gas key's balance
rather than the signer's account balance (deposits like NEAR transfers
still come from the account).

## Why do we need gas keys?
- Enabling SPICE without a DoS vector. The SPICE project (Separation of
Execution from Consensus) decouples transaction execution from block
production: transactions are included in blocks first, and executed
asynchronously later. This means chunk producers can no longer verify
account balances at inclusion time. An attacker could drain an account's
balance in one transaction, then flood the chain with many transactions
signed by that account. All would be accepted (since execution hasn't
caught up), consuming block space for free when they inevitably fail.
Gas keys close this gap by requiring gas to be pre-committed in the key
itself, so chunk producers can verify gas availability without access to
the latest state.

- Parallel transaction submission. Today, programmatic users who submit
many transactions in parallel must manage multiple access keys (each
with its own nonce sequence). A gas key supports up to 1,024 independent
nonce slots via a single key, removing that complexity.

# Context

- NEP (if exists): near/NEPs#611
- Implementation: 
 - near#14868
 - near#14869
 - near#14883
 - near#14891
 - near#14892
 - near#14911
 - near#14924
 - near#14925
 - near#14930
 - near#14933
 - near#14969
 - near#14985
 - near#15033
 - near#15034
 - near#15067
 - near#15068
 - near#15100
 - near#15101
 - near#15186

# Testing and QA
- unit tests
- test-loop:
https://github.com/near/nearcore/blob/master/test-loop-tests/src/tests/gas_keys.rs
- forknet (automated): near#15207
- forknet (manual testing, planned)

# Checklist
- [x] Link to nightly nayduck run:
https://nayduck.nearone.org/#/run/4756
- [x] Update CHANGELOG.md to include this protocol feature in the
`Unreleased` section.
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