Skip to content

refactor(core): replace SignedData trait with a closed enum - #700

Merged
varex83 merged 5 commits into
mainfrom
fix/issue-639-signeddata-enum
Sep 18, 2026
Merged

varex83 merged 5 commits into
mainfrom
fix/issue-639-signeddata-enum

Conversation

@varex83agent

Copy link
Copy Markdown
Collaborator

Closes #639.

SignedData is now a closed enum in crates/core/src/signeddata.rs (mirroring UnsignedDutyData) instead of an object-safe trait: signature/set_signature/message_root are exhaustive matches, and every Box<dyn SignedData> / &dyn SignedData becomes a plain value or reference (SignedDataSet is now HashMap<PubKey, SignedData>, ParSignedData derives Clone/PartialEq).
This deletes the Any supertrait, the dyn-clone/dyn-eq dependencies (no other crate used them), the set_signature/set_signature_boxed duplication, the 12-arm downcast_ref chain in parsigex_codec's encode side, and the ad-hoc downcasts in sigagg, bcast, fetcher, tracker/inclusion and validatorapi — each is now a pattern match on the expected variant.
Eth2SignedData is a borrowed sub-enum built by SignedData::as_eth2_signed_data (Go's data.(core.Eth2SignedData) assertion); as the compiler-checked match forced a decision, SyncContributionAndProof is now included, matching charon (core/signeddata.go gives it DomainName/Epoch), where the previous hand-written ladder silently returned None. Test mocks are consolidated into one #[cfg(test)] MockSignedData variant. The parsigex decode probing (#640) and SomeMsg::as_any are left for the follow-ups.

Co-Authored-By: Bohdan Ohorodnii 35969035+varex83@users.noreply.github.com

Closes #639.

Co-Authored-By: Bohdan Ohorodnii <35969035+varex83@users.noreply.github.com>

@emlautarom1 emlautarom1 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The code is pretty much the same but relies on match instead of downcasting which could have caused problems in the future. We also skip some Boxes and we can drop the dyn-* dependencies.

Comment thread crates/core/src/parsigex_codec.rs Outdated
Comment on lines +96 to +98
// ---------------------------------------------------------------
// SSZ-capable types — encode as SSZ binary (matching Go `marshal`)
// ---------------------------------------------------------------

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we use a closed enum we could remove all of these comments, the match is already exhaustive.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — dropped the section banners and the per-arm restatements in serialize_signed_data; only the note explaining why SyncContributionAndProof has no wire encoding is left, since that one is not derivable from the match.

varex83agent and others added 4 commits September 16, 2026 12:08
Co-Authored-By: Bohdan Ohorodnii <35969035+varex83@users.noreply.github.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ata-enum

# Conflicts:
#	crates/core/Cargo.toml
The module docs for `eth2signeddata` linked `[`SignedData`]`, which rustdoc
could not resolve, failing the docs job under `RUSTDOCFLAGS=-D warnings`.
Qualify the link with its defining path.

Co-Authored-By: Bohdan Ohorodnii <35969035+varex83@users.noreply.github.com>
…ata-enum

Resolved conflicts between the SignedData enum refactor and main's eth2api
client rewrite:

- core/types.rs: dropped the trait-era imports (dyn_clone, dyn_eq, HashRoot,
  SignedDataError) and signeddata::AttesterDuty; kept main's pluto_eth2api::v1
  for the reworked DutyDefinition variants.
- core/fetcher: dropped both `downcast` (removed here) and
  `attestation_payload` (moved into eth2api on main); test imports keep the
  signeddata selection/message types alongside main's types::SlotNumber.
- core/sigagg: new_verifier takes main's unwrapped EthBeaconNodeApiClient and
  the enum-typed `&SignedData` closure argument.
- core/bcast: proposal submission goes through main's publish_block_v2 against
  the enum-matched block; the now-unused std::any::Any / StdError import is
  gone.

Also ported main's new sync-contribution fetcher test off `Box<dyn SignedData>`
onto the enum.

Co-Authored-By: Bohdan Ohorodnii <35969035+varex83@users.noreply.github.com>
@varex83
varex83 merged commit fc63c5e into main Sep 18, 2026
16 checks passed
@varex83
varex83 deleted the fix/issue-639-signeddata-enum branch September 18, 2026 11:06
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.

Refactor SignedData from a downcast-based trait to a closed enum

3 participants