Skip to content

refactor: migrate witness terminology to validator (one-cycle compat) - #3

Merged
On1x merged 14 commits into
masterfrom
witness-to-validator
May 19, 2026
Merged

On1x merged 14 commits into
masterfrom
witness-to-validator

Conversation

@chiliec

@chiliec chiliec commented May 19, 2026

Copy link
Copy Markdown
Member

Summary

  • Renames "witness" → "validator" across Swift types, fields, and JSON wire format, mirroring the migration already shipped in the JS/PHP libraries
  • Backwards compatible for one release cycle: decoders accept both old & new JSON keys; old Swift names kept as @available(*, deprecated, renamed:) aliases
  • Binary wire format unchanged (operation type IDs 6/7/8/30/42 stay the same; only string op-names change)

What changed

5 OperationId cases renamed; dual-string decode
witness_update→validator_update, account_witness_vote→account_validator_vote, account_witness_proxy→account_validator_proxy, shutdown_witness→shutdown_validator, witness_reward→validator_reward. Decoders accept both legacy and new op-name strings.

5 Operation.* Swift types renamed (with deprecated typealiases)
WitnessUpdate→ValidatorUpdate, AccountWitnessVote→AccountValidatorVote, AccountWitnessProxy→AccountValidatorProxy, ShutdownWitness→ShutdownValidator, WitnessReward→ValidatorReward.

3 inner field renames with manual dual-key init(from:)

  • Operation.AccountValidatorVote.witness → validator
  • Operation.ValidatorReward.witness → validator
  • BlockHeader / SignedBlockHeader: witness/witnessSignature → validator/validatorSignature

5 API response fields renamed

  • DynamicGlobalProperties: currentWitness → currentValidator, inflationWitnessPercent → inflationValidatorPercent
  • ExtendedAccount: witnessesVotedFor → validatorsVotedFor, witnessesVoteWeight → validatorsVoteWeight, witnessVotes → validatorVotes

Client namespace routing
Client.swift now routes both legacy *_witness* and new *_validator* JSON-RPC method names to the validator_api namespace.

Deprecated aliases compile-smoke test
New Tests/UnitTests/DeprecatedAliases.swift (class marked @available(*, deprecated) to suppress inner warnings) instantiates every deprecated alias/typealias/property/init overload at least once, guarding against accidental removal during Phase C cleanup.

Test plan

  • swift test --filter UnitTests — 120 tests pass (was 109 on master, +11 new tests covering legacy-key decode and deprecated-alias smoke)
  • swift build — 0 warnings
  • swift build --build-tests — 0 warnings (no stale witness* references in production code)
  • Linux test manifest (XCTestManifests.swift) aligned with all 120 tests; audit also caught 7 pre-existing manifest gaps (ChainIdTest, testGeneratePrivateFromSeed, testInitWithOp, testAppend, testOperationId_acceptsLegacyAndNewNames) and registered them
  • Integration tests (12 tests against https://node.viz.cx) — should be run after the node rolls forward; the live wire format is the canary

Phase C cleanup (future PR, after one release cycle)

The migration is reversible-by-deletion. Grep for these legacy* markers to find every back-compat code path:

legacyWitness, legacyWitnessSignature, legacyCurrentWitness, legacyInflationWitnessPercent,
legacyWitnessesVotedFor, legacyWitnessesVoteWeight, legacyWitnessVotes

Plus the // MARK: - Deprecated aliases (witness → validator migration, 2026-05-19) blocks at the bottom of Operation.swift, Block.swift, and API.swift.

References

  • Spec: docs/superpowers/specs/2026-05-19-witness-to-validator-design.md
  • Plan: docs/superpowers/plans/2026-05-19-witness-to-validator.md
  • Source migration reference: JS/PHP library equivalent migration

chiliec added 14 commits May 19, 2026 19:35
Rename the virtual op struct and its inner `witness` field to `validator`.
Add manual `init(from:)` with `legacyWitness = "witness"` CodingKey fallback so
legacy chain data still decodes. Add deprecated typealias `WitnessReward` and
a deprecated `init(witness:shares:)` overload plus `witness` computed property
for source compatibility.

Rename `testVirtualDecode_witnessReward` to `testVirtualDecode_validatorReward`
and add `testDecode_validatorReward_legacyWitnessKey` that exercises decoding
legacy JSON bodies directly via `AssertDecodes`. Update XCTestManifests.
Pins every deprecated typealias, computed property, and init overload
introduced by Tasks 2–9 of the witness→validator migration. The whole
XCTestCase is marked @available(*, deprecated) so deprecation warnings
inside it are suppressed — Swift propagates the deprecation context.

If any deprecated symbol is removed during Phase C cleanup, this file
fails to compile, surfacing the breaking change before release.
…alias use

- Register ChainIdTest (3 methods) which was entirely missing from the Linux manifest.
- Add testOperationId_acceptsLegacyAndNewNames, testGeneratePrivateFromSeed,
  testInitWithOp, testAppend to their respective manifest extensions.
- Annotate the DeprecatedAliasesTest manifest extension as deprecated so the
  reference to the deprecated class no longer emits a warning.
- Refactor testOperationId_acceptsLegacyAndNewNames to compare against the
  canonical Validator* types rather than the deprecated Witness* typealiases,
  eliminating 5 deprecation warnings while preserving the same semantics.

After this change the manifest registers exactly one entry per func test*
method (120 total, matching swift test --filter UnitTests), and the build
emits zero warnings.
@On1x
On1x merged commit 026ebc9 into master May 19, 2026
1 check passed
@chiliec
chiliec deleted the witness-to-validator branch May 19, 2026 15:39
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