Skip to content

feat(gas-keys): add DelegateV2 action types for gas-key meta transactions (1/3)#15904

Merged
darioush merged 4 commits into
masterfrom
darioush/gas-keys/delegate-v2-versioned-types
Jun 12, 2026
Merged

feat(gas-keys): add DelegateV2 action types for gas-key meta transactions (1/3)#15904
darioush merged 4 commits into
masterfrom
darioush/gas-keys/delegate-v2-versioned-types

Conversation

@darioush

@darioush darioush commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

First of a 3-PR stack adding gas-key support to meta transactions via a new Action::DelegateV2. Replaces the extension-based stack (#15883, #15884, #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.

@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.93671% with 95 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.73%. Comparing base (ff90391) to head (32fe4b7).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
core/primitives/src/action/delegate.rs 76.96% 44 Missing ⚠️
runtime/runtime/src/lib.rs 0.00% 11 Missing ⚠️
core/primitives/src/views.rs 0.00% 9 Missing ⚠️
core/primitives/src/action/mod.rs 38.46% 8 Missing ⚠️
core/primitives/src/errors.rs 0.00% 5 Missing ⚠️
chain/rosetta-rpc/src/adapters/mod.rs 0.00% 4 Missing ⚠️
runtime/runtime/src/action_validation.rs 20.00% 4 Missing ⚠️
runtime/runtime/src/config.rs 95.52% 2 Missing and 1 partial ⚠️
chain/client/src/pending_transaction_queue.rs 0.00% 2 Missing ⚠️
core/primitives/src/transaction.rs 0.00% 2 Missing ⚠️
... and 3 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #15904      +/-   ##
==========================================
- Coverage   69.76%   69.73%   -0.03%     
==========================================
  Files         946      946              
  Lines      203016   203374     +358     
  Branches   203016   203374     +358     
==========================================
+ Hits       141636   141825     +189     
- Misses      56611    56777     +166     
- Partials     4769     4772       +3     
Flag Coverage Δ
pytests-nightly 1.11% <0.00%> (-0.01%) ⬇️
unittests 69.47% <69.93%> (-0.03%) ⬇️
unittests-nightly 69.45% <69.93%> (-0.03%) ⬇️

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-versioned-types branch from ff04076 to b37e34b Compare June 12, 2026 02:50
@darioush darioush changed the title feat(gas-keys): add DelegateV2 action types with versioned nonce (1/3) feat(gas-keys): add DelegateV2 action types for gas-key meta transactions (1/3) Jun 12, 2026
@darioush darioush requested a review from Copilot June 12, 2026 03:17
Comment thread core/primitives/src/action/delegate.rs Outdated
Comment on lines +159 to +161
pub enum DelegateActionV2Payload {
V2(DelegateActionV2) = 0,
}

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.

The main reason to introduce this is so future extensions don't need to add a new delegate action type & SignableMessageType.

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.

this is a bit confusing as it seems like V2 in DelegateActionV2Payload is the same as V2 in DelegateActionV2. I suggest renaming it to VersionedDelegateActionPayload

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

Adds the new Action::DelegateV2 wire/view types and supporting plumbing across nearcore for gas-key meta transactions, while intentionally keeping execution disabled (validation rejects; apply fails gracefully) until the next PR in the stack.

Changes:

  • Introduces DelegateActionV2/SignedDelegateActionV2 (+ versioned payload) and updates signing discriminant (NEP-611).
  • Extends action validation, cost/fee computation, and various match sites to recognize DelegateV2.
  • Adds view-layer support (ActionView::DelegateV2) and updates tooling/non-consensus components to tolerate/ignore the new variant.

Reviewed changes

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

Show a summary per file
File Description
tools/state-viewer/src/contract_accounts.rs Adds DelegateV2 to action filtering/mapping for state-viewer.
runtime/runtime/src/pipelining.rs Treats DelegateV2 like Delegate in the pipelining receipt prep logic.
runtime/runtime/src/lib.rs Adds a graceful runtime apply failure for DelegateV2 (should be unreachable due to validation for now).
runtime/runtime/src/config.rs Extends fee/cost/gas/deposit accounting to include DelegateV2 inner actions/signatures.
runtime/runtime/src/actions.rs Allows permission/existence checks to handle DelegateV2.
runtime/runtime/src/action_validation.rs Extends “only one delegate action” rule and explicitly rejects DelegateV2 until feature execution lands.
core/primitives/src/views.rs Adds JSON view round-trip support via ActionView::DelegateV2.
core/primitives/src/transaction.rs Makes TransactionNonce serde-serializable so it can be used in DelegateActionV2.
core/primitives/src/signable_message.rs Adds NEP-611 discriminant and SignableMessageType::DelegateActionV2.
core/primitives/src/errors.rs Adds gas-key related access-key errors and a nonce-index error kind.
core/primitives/src/action/mod.rs Adds Action::DelegateV2, introduces Action::is_delegate, and includes DelegateV2 in PQ signature recursion.
core/primitives/src/action/delegate.rs Implements the new delegate V2 types, versioned wrappers, and extends non-nesting guards/tests.
chain/rosetta-rpc/src/adapters/mod.rs Temporarily ignores DelegateV2 in Rosetta adapter (TODO).
chain/client/src/pending_transaction_queue.rs Treats DelegateV2 as deploy-like if its inner actions are deploy-like.
Comments suppressed due to low confidence (1)

runtime/runtime/src/action_validation.rs:109

  • This loop re-implements the “delegate-style” classification with an explicit Delegate | DelegateV2 pattern. Since Action::is_delegate() was added specifically to centralize that classification (and keep future variants from being missed), it’s better to use it here too.
            if let Action::Delegate(_) | Action::DelegateV2(_) = action {
                if found_delegate_action {
                    return Err(ActionsValidationError::DelegateActionMustBeOnlyOne);
                }
                found_delegate_action = true;

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

Comment thread core/primitives/src/action/delegate.rs
@darioush darioush force-pushed the darioush/gas-keys/delegate-v2-versioned-types branch from b37e34b to 8bdd4df Compare June 12, 2026 03:36
@darioush darioush marked this pull request as ready for review June 12, 2026 03:43
@darioush darioush requested a review from a team as a code owner June 12, 2026 03:43
@darioush darioush requested review from pugachAG and ssavenko-near and removed request for ssavenko-near June 12, 2026 03:43
Comment thread core/primitives/src/action/delegate.rs Outdated
Comment on lines +159 to +161
pub enum DelegateActionV2Payload {
V2(DelegateActionV2) = 0,
}

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.

this is a bit confusing as it seems like V2 in DelegateActionV2Payload is the same as V2 in DelegateActionV2. I suggest renaming it to VersionedDelegateActionPayload

Comment thread core/primitives/src/action/delegate.rs Outdated
ProtocolSchema,
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct SignedDelegateActionV2 {

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 here: VersionedSignedDelegateAction

Comment thread core/primitives/src/action/delegate.rs Outdated
/// Convenience wrapper for common logic accessing fields on delegate actions
/// of different versions.
#[derive(Clone, Copy, Debug)]
pub enum VersionedDelegateAction<'a> {

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.

nice, that is exactly what I meant 👍

Comment thread core/primitives/src/action/delegate.rs Outdated
/// Convenience wrapper for common logic accessing signed delegate actions of
/// different versions.
#[derive(Clone, Copy, Debug)]
pub enum VersionedSignedDelegateAction<'a> {

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.

nit: add ref suffix: VersionedSignedDelegateActionRef, also for VersionedDelegateAction

@darioush darioush requested a review from frol as a code owner June 12, 2026 13:00
@darioush darioush added this pull request to the merge queue Jun 12, 2026
Merged via the queue into master with commit 19dc2c6 Jun 12, 2026
31 of 33 checks passed
@darioush darioush deleted the darioush/gas-keys/delegate-v2-versioned-types branch June 12, 2026 22:28
github-merge-queue Bot pushed a commit that referenced this pull request Jun 12, 2026
…15905)

Second PR of the stack (on top of #15904). Wires up execution of
`DelegateV2`:
- `validate_delegate_action_key` dispatches on `TransactionNonce`: a
plain nonce advances `access_key.nonce` (and still rejects gas keys), a
gas key nonce range-checks `nonce_index` against `num_nonces` and
advances the selected gas key nonce row.
- The separate V1/V2 apply paths collapse into one
`apply_delegate_action` over `VersionedSignedDelegateActionRef`.
- Validation now accepts `DelegateV2` behind the dedicated
`ProtocolFeature::DelegateV2`, replacing the inert rejection arm from
the previous PR.

Adds an end-to-end test-loop test of a gas-key meta transaction plus
unit tests for the nonce routing.
darioush added a commit that referenced this pull request Jun 22, 2026
Adds a 2.13.0 changelog entry for the new `DelegateV2` meta-transaction
action (`ProtocolFeature::DelegateV2`, protocol version 85), which lets
gas keys ([NEP-611](near/NEPs#611)) sign relayed
meta transactions.
([#15904](#15904),
[#15905](#15905),
[#15906](#15906))

Sorry I forgot this as part of the feature.
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