Skip to content

feat(gas-keys): gas-key nonce routing for DelegateV2 (2/3)#15884

Closed
darioush wants to merge 4 commits into
darioush/gas-keys/delegate-v2-core-typesfrom
darioush/gas-keys/delegate-v2-core-exec
Closed

feat(gas-keys): gas-key nonce routing for DelegateV2 (2/3)#15884
darioush wants to merge 4 commits into
darioush/gas-keys/delegate-v2-core-typesfrom
darioush/gas-keys/delegate-v2-core-exec

Conversation

@darioush

@darioush darioush commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Second of the 3-PR stack (builds on #15883, original non-splitted: #15877)

Flips DelegateV2 from "rejected at validation" to fully executed: validate_delegate_action_key now threads Option<&DelegateActionExtension> and routes a GasKey { nonce_index } through the per-index gas key nonce storage (gated on ProtocolFeature::GasKeys, range-checked, relayer prepays). A missing in-range nonce row is treated as StorageInconsistentState rather than defaulting to 0, matching the transaction path.

Tests: unit coverage for validate_delegate_action_key (full-access / function-call permissions, invalid nonce index, pre-feature rejection) and an end-to-end test-loop meta transaction (relayer wraps the gas-key-signed DelegateV2, inner action executes, only the chosen nonce index advances, replay fails).

Copilot AI review requested due to automatic review settings June 9, 2026 19:09
@darioush darioush requested a review from a team as a code owner June 9, 2026 19:09
@darioush darioush requested review from saketh-are and removed request for a team June 9, 2026 19:09

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

Enables end-to-end execution of Action::DelegateV2 for gas-key meta transactions by routing delegate nonces through per-nonce_index gas-key nonce storage (behind ProtocolFeature::GasKeys) and adding tests to cover the new behavior across validation and execution.

Changes:

  • Execute Action::DelegateV2 in the runtime and apply delegate actions via a shared inner path that supports optional DelegateActionExtension.
  • Update delegate action key validation to (a) forbid gas keys for “plain” delegates, and (b) for gas-key delegates, range-check nonce_index and persist the nonce in per-index gas-key storage.
  • Add unit + test-loop coverage for gas-key DelegateV2 meta-transaction execution, nonce advancement behavior, and pre-feature rejection.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
test-loop-tests/src/tests/gas_keys.rs Adds an end-to-end test-loop meta-transaction using DelegateV2 + gas-key nonce index, asserting nonce routing and replay rejection.
runtime/runtime/src/lib.rs Switches Action::DelegateV2 from “graceful failure” to actual execution via apply_delegate_action_v2.
runtime/runtime/src/actions.rs Implements apply_delegate_action_v2 and extends delegate nonce validation/persistence to support gas-key per-index nonces via DelegateActionExtension.
runtime/runtime/src/action_validation.rs Accepts DelegateV2 in action validation, gating gas-key extension on ProtocolFeature::GasKeys, and adds a regression test for pre-feature rejection.

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

Comment thread runtime/runtime/src/actions.rs
Comment thread test-loop-tests/src/tests/gas_keys.rs Outdated
@darioush darioush marked this pull request as draft June 9, 2026 19:14
@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.24771% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.95%. Comparing base (0dc2ee5) to head (1a4c979).

Files with missing lines Patch % Lines
runtime/runtime/src/actions.rs 97.06% 6 Missing and 2 partials ⚠️
runtime/runtime/src/lib.rs 90.00% 1 Missing ⚠️
Additional details and impacted files
@@                             Coverage Diff                              @@
##           darioush/gas-keys/delegate-v2-core-types   #15884      +/-   ##
============================================================================
+ Coverage                                     69.89%   69.95%   +0.05%     
============================================================================
  Files                                           945      945              
  Lines                                        202448   202736     +288     
  Branches                                     202448   202736     +288     
============================================================================
+ Hits                                         141503   141820     +317     
+ Misses                                        56180    56149      -31     
- Partials                                       4765     4767       +2     
Flag Coverage Δ
pytests-nightly 1.11% <0.00%> (-0.01%) ⬇️
unittests 69.68% <97.24%> (+0.04%) ⬆️
unittests-nightly 69.64% <97.24%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.

@darioush darioush force-pushed the darioush/gas-keys/delegate-v2-core-types branch from 67e0a4c to cc524e6 Compare June 9, 2026 19:24
@darioush darioush force-pushed the darioush/gas-keys/delegate-v2-core-exec branch 3 times, most recently from b3b6201 to 9c68ba6 Compare June 9, 2026 19:36
@darioush darioush changed the title feat(gas-keys): execute DelegateV2 (gas-key nonce routing) feat(gas-keys): DelegateV2 gas-key nonce routing (2/3) Jun 9, 2026
@darioush darioush changed the title feat(gas-keys): DelegateV2 gas-key nonce routing (2/3) feat(gas-keys): gas-key nonce routing for DelegateV2 (2/3) Jun 9, 2026
@darioush darioush force-pushed the darioush/gas-keys/delegate-v2-core-exec branch from 9c68ba6 to 9305229 Compare June 9, 2026 19:45
@darioush darioush requested review from pugachAG and removed request for saketh-are June 9, 2026 20:17
@darioush darioush marked this pull request as ready for review June 9, 2026 20:24
@darioush darioush marked this pull request as draft June 12, 2026 03:18
@darioush darioush closed this Jun 12, 2026
pull Bot pushed a commit to Superoldman96/nearcore that referenced this pull request Jun 12, 2026
…ions (1/3) (near#15904)

First of a 3-PR stack adding gas-key support to meta transactions via a
new `Action::DelegateV2`. Replaces the extension-based stack (near#15883,
near#15884, near#15885) with the versioned design suggested in review there.

Adds the wire types and the nesting guard, but no execution yet:
validation rejects `DelegateV2` (`UnsupportedProtocolFeature`) and the
apply path fails it gracefully. Execution lands in the next PR in the
stack.

Design:
- `DelegateActionV2` mirrors `TransactionV1`: its `nonce:
TransactionNonce` selects either the access key nonce or one of a gas
key's parallel nonces by index.
- `VersionedDelegateActionPayload` (wire enum, currently just `V2`) is
the signed payload of `VersionedSignedDelegateAction`. Future versions
add a variant here instead of a new `Action` variant, so the delegate
nesting guard stays frozen, and the variant byte is covered by the
signature so versions cannot be confused.
- `DelegateV2` signs under its own NEP-461 discriminant (NEP-611, gas
keys), making V1 and V2 signing domains disjoint by construction.
- `VersionedDelegateActionRef`/`VersionedSignedDelegateActionRef` are
borrowing wrappers for code handling V1 and V2 uniformly (the
`VersionedActionReceipt` pattern).
- A dedicated `ProtocolFeature::DelegateV2` (protocol version 85) gates
the action independently of `ProtocolFeature::GasKeys`, so it can be
pulled from the release on its own if needed.

Includes `ActionView::DelegateV2`, cost/fee handling, and trivial match
arms across the workspace.

Protocol schema and openapi specs (1.2.11) are regenerated.
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.

2 participants