feat(json-rpc): add view_gas_key_nonces module#14930
Conversation
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| }, | ||
| #[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}" |
There was a problem hiding this comment.
This seemed incorrect and minor enough to fix in this PR
There was a problem hiding this comment.
I'd avoid this, especially considering that the message is rather "imprecise" than "incorrect". feel free to open a separate PR for this
d0f8370 to
06d8e7c
Compare
There was a problem hiding this comment.
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
ViewGasKeyNoncesErrorerror type with proper error conversion implementations - Implemented
view_gas_key_noncesfunction in the state viewer to retrieve nonces for gas keys - Added
EXPERIMENTAL_view_gas_key_noncesJSON-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
left a comment
There was a problem hiding this comment.
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")] |
There was a problem hiding this comment.
same for both changes here, please move to a separate PR
5665f6e to
bcf0301
Compare
# 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.
This PR resolves a gas-keys TODO item by implementing the
view_gas_key_noncesmodule and adding the correspondingEXPERIMENTAL_view_gas_key_noncesAPI call.Also in this PR, I give
view_gas_key_noncesa dedicated error type. The reason is becauseAccessKeyDoesNotExistseems like a bad error to get in case the key we query for nonces is an ordinary access key.This change returns
GasKeyDoesNotExistin this case. I’m open to alternatives such as introducing separateAccessKeyDoesNotExistandAccessKeyNotGasKeyvariants, but it still seems nice to keep a dedicatedViewGasKeyNoncesErrorerror type.