Skip to content

feat: add delegated staking SDK support - #74

Open
teban-oss wants to merge 1 commit into
witnet:mainfrom
teban-oss:delegated-staking
Open

teban-oss wants to merge 1 commit into
witnet:mainfrom
teban-oss:delegated-staking

Conversation

@teban-oss

Copy link
Copy Markdown

Summary

This PR adds source-level support for Wit/2.1 delegated staking across the Witnet Rust node, wallet, storage, validation, RPC/CLI layers, and TypeScript SDK.

Delegated staking allows one validator to aggregate stake from multiple independent withdrawers while preserving each withdrawer’s ownership and withdrawal rights.

What changed

  • Added validator owner registration and persistent owner policies.
  • Added delegation, top-up, commission-update, and withdrawer-exit authorization actions.
  • Added multi-withdrawer stake accounting keyed by (validator, withdrawer).
  • Added deterministic reward allocation and validator commission handling.
  • Added exact collateral reservation, refund, and slashing accounting.
  • Added the 70% owner / 30% delegator collateral split.
  • Added Wit/2.1 transaction, protobuf, hashing, validation, mempool, mining, and consolidation support.
  • Added activation preflight and legacy-state classification.
  • Added persistence migration and compatibility handling for historical Wit/2.0 state.
  • Added delegated-staking snapshot validation and signed non-genesis snapshot trust checks.
  • Added node RPC, Rust CLI, wallet, SDK provider, farm, and CLI support.
  • Added failed-relay recovery and UTXO reservation cleanup.
  • Added Rust and TypeScript fixtures covering authorization, migration diagnostics, rewards, exits, recovery, snapshots, and RPC normalization.

Reasoning

Delegated staking requires explicit ownership and authorization boundaries because a validator may control stake belonging to many unrelated withdrawers.

Collateral reservations use exact debit vectors so refunds and slashes remain deterministic even when balances change after a Commit. Reward weights are fixed at commitment time to prevent later stake changes from altering an existing entitlement.

The activation and snapshot changes preserve legacy chain behavior while preventing ambiguous ownership, malformed migration state, nondeterministic schedule hashing, or untrusted snapshot data from producing divergent node state.

Compatibility and release safety

  • Wit/2.0 transaction and block compatibility remains isolated from native Wit/2.1 accounting.
  • Native delegated-staking actions require the Wit/2.1 activation boundary.
  • The production release gate remains closed:
    DELEGATED_STAKING_RELEASE_READY = false.
  • No activation schedule is enabled by this PR.

Verification

Previously reported verification includes:

  • 284/284 delegated-staking SDK tests passing.
  • Focused Rust tests for missing-owner snapshot replay, canonical schedule ordering, and snapshot-anchor signatures passing.
  • Historical migration and compatibility fixtures added.

A full Rust rebuild, complete Rust test suite, live SDK-to-node delegated-staking lifecycle, and non-genesis signed snapshot import still require final verification.

Remaining follow-up

Deferred legacy collateral and reward records are intentionally non-spendable until an approved recovery policy and claim path are defined.

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.

1 participant