Skip to content

fix(message_validator): ignore duplicates relayed by another peer - #1375

Merged
shane-moore merged 4 commits into
sigp:unstablefrom
shane-moore:fix/peer-aware-duplicate-verdicts
Dec 4, 2026
Merged

shane-moore merged 4 commits into
sigp:unstablefrom
shane-moore:fix/peer-aware-duplicate-verdicts

Conversation

@shane-moore

@shane-moore shane-moore commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Problem, Evidence, and Context (Required)

Anchor limits each signer to one proposal, prepare, commit and round change per round, and one pre-consensus and one post-consensus partial signature message per slot. When a second copy passes that limit, the validator returns DuplicatedMessage or InvalidPartialSignatureTypeCount. Both map to Reject, whoever delivered the copy, and Reject applies the gossipsub invalid-message penalty to the delivering peer.

  • Trigger. Peer A delivers a valid prepare, which is counted. Peer B then delivers a prepare for the same signer, slot and round. That reaches the validator in two cases: B relays the same bytes after the duplicate-cache entry expired (one epoch), or the signer produced a second, byte-different prepare and B relayed that one. Either way B did nothing wrong, and is penalized.
  • How often. Normally the duplicate cache stops the second copy before validation, so I expect this to be rare today and have not observed it on a live network. The point is that the validator should not rely on that cache to avoid punishing honest relayers.
  • go-ssv keeps two tiers of state: a repeat from the same peer is Reject, a repeat from a different peer is Ignore (consensus, partial signatures).
  • The divergence is recorded in this comment on #1211.
  • Direction. That comment lists three options. This PR takes the first, porting the two-tier for the six counters, for parity with go-ssv: both clients then score the same peer the same way, and the same-peer Reject is kept.

A second gap: gossipsub does not hand a node its own messages for validation, so the validator had no record of what this node published. A copy relayed back that the duplicate cache did not recognise was treated as a first copy. In Go the validator sees local publishes, because go-libp2p-pubsub runs topic validators on them. The reach is narrow: inside the one-epoch cache gossipsub drops the copy first, and after it most roles are already Ignore for lateness or round spread, so the record changes the verdict for partial-signature packets of the 34-slot roles for about two slots. The reason is parity with Go, not frequency.

Change Overview (Required)

  • Validator::validate now takes the relaying peer. The receiver passes the gossipsub propagation source.
  • Each signer's per-round state keeps the existing counts for all peers, plus the same counts per delivering peer. The limit check looks at the peer's counts first (Reject, same variants as before), then at the counts for all peers (Ignore, through the existing RelayedDuplicateMessage).
  • The message sender reports each message it queues for the network through a small OutboundRecorder trait, which the validator implements. Own messages are added to the all-peers counts only.
  • Counters now saturate.
  • An own single-signer message for a round the signer already left is not recorded, so own messages recorded out of order are not counted in a later round.
  • The validation-failure debug lines now name the delivering peer.

Reading order: message_counts.rs (the limit checks become predicates), duty_state.rs (per-peer counts and the two-tier check), lib.rs (peer plumbing and OutboundRecorder), then the call sites in message_receiver, message_sender and client.

About 270 production lines; the other 1,200 or so are tests.

Not changed:

Risks, Trade-offs, and Mitigations (Required)

  • Weaker punishment. A peer can no longer be penalized for delivering a message of an already-counted type that some other peer delivered first. The check compares type, not content, and runs before signature verification (as in Go), so this covers any such message, verified or not. This is the intended trade and matches Go. Such a message is still dropped and not forwarded.
  • Two verdicts change because own messages are now recorded. After this node publishes its own decided message, a later decided message with the same signers returns DecidedWithSameSigners. After it publishes for a later slot in a role whose slots only move forward, an older-slot message returns SlotAlreadyAdvanced. Both are Ignore, and both are what any other node already computes for the same traffic.
  • Own messages are recorded when queued, not when published. If gossipsub then finds no peers on the topic, the message never leaves but stays recorded, so a decided commit with the same signers that a peer delivers later is ignored and not forwarded. go-ssv has the same outcome: go-libp2p-pubsub marks a local message seen and validates it before it looks for peers.
  • Memory. Per-peer counts are allocated on first use and hold at most one entry per counter (six), with a PeerId of 80 bytes each. In the common case one peer delivers everything for a signer, so there is one entry. I did not measure this on a node subscribed to all subnets.

Validation (Required)

  • cargo test -p message_validator -p message_receiver -p message_sender -p network --lib: 185, 1, 0 and 64 passed, none failed.

  • Clippy with -D warnings on those crates and cargo fmt --all -- --check: clean.

  • New tests cover, for all six counted types: first copy accepted, same-peer repeat Reject, other-peer repeat Ignore, own publish then relayed copy Ignore, a higher round replacing the per-peer counts, and counter saturation. Two tests go through the full consensus and partial-signature pipelines. The two verdicts that change once own messages are recorded each have a validator-level test and a control: an own decided commit then the same signers is DecidedWithSameSigners, an own later-slot publish then an earlier-slot message is SlotAlreadyAdvanced, and both are accepted without the record.

  • 16 single-point mutations of the new logic each fail at least one test.

  • Local devnet with 2 Anchor and 2 go-ssv nodes on one host, run twice: once at c4cc5f15 and once with a73ea711. One Anchor node had this PR and the other did not. Both builds also carried another unmerged networking change, which at one point in the run made late copies miss the gossipsub duplicate cache. I delayed one go-ssv node's outbound traffic by 11 s across that point, so its copies arrived late.

    After that point Without this PR With this PR
    Duplicates rejected 23 and 23 2 and 1, all from the other Anchor node sending its own messages again; a same-peer repeat, which go-ssv also rejected
    Duplicates ignored as relayed by another peer none 28 and 41 (in the second run, which logs the peer, all 41 from the delayed go-ssv node)
    The delayed go-ssv node blocked within 25 s, for the rest of the run (8 and 5 epochs); peers 3 to 2 kept; peers 3 of 3
    Attestation aggregates published 9 and 2 39 and 14
    Selection-proof time, median 238 and 240 ms 39 and 30 ms

    With the delay on and before that point, neither node rejected a duplicate. Attestation duties were complete on both nodes, and go-ssv ignored the copies other peers relayed. The aggregate and selection-proof gaps appeared together with the blocked peer. I did not isolate another cause.

Rollback (Required for behavior or runtime changes; optional otherwise)

Revert the commit. No config, database or wire-format change.

Blockers / Dependencies (Optional)

N/A

Additional Info / Next Steps (Optional)

A repeat of an already counted consensus or partial signature message
was rejected whoever delivered it. An honest peer that relayed a copy
the gossipsub duplicate cache did not recognise was penalized for it.

Track which peer delivered each counted message per signer, slot and
round. A repeat from the same peer is still rejected. A repeat from a
different peer is now ignored, as in go-ssv. The node's own publishes
are recorded too, so a copy relayed back is ignored.
@mergify

mergify Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

This pull request is merged.

@codecov-commenter

codecov-commenter commented Dec 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.15164% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.29%. Comparing base (7c95e62) to head (ca3bf99).

Files with missing lines Patch % Lines
anchor/message_sender/src/network.rs 0.00% 3 Missing ⚠️
anchor/message_validator/src/lib.rs 99.01% 3 Missing ⚠️
anchor/client/src/lib.rs 0.00% 1 Missing ⚠️
anchor/message_receiver/src/manager.rs 85.71% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #1375      +/-   ##
============================================
+ Coverage     80.80%   81.29%   +0.49%     
============================================
  Files           180      180              
  Lines         42771    43642     +871     
============================================
+ Hits          34559    35477     +918     
+ Misses         8212     8165      -47     
Flag Coverage Δ
rust 81.29% <99.15%> (+0.49%) ⬆️

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.

@shane-moore shane-moore left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Review by Claude Fable 5.2 at c4cc5f15.

No correctness defect found. For peer-delivered messages the change only moves verdicts from Reject to Ignore: every Reject at head was a Reject at base, and no Accept changes. Own-publish recording only changes verdicts for messages that carry this operator's signature. The limit rules, and their position before signature verification, match go-ssv at 304ef0af. I did not run the tests locally; CI release and debug tests pass on this head.

Five comments inline: two small gaps (tests, logging), two design questions, one wording nit. None blocks merge if go-ssv parity is the stated goal.

Checked and dropped:

  • Own-publish recording cannot hide a twin from operator doppelgänger detection, because nothing is published during monitoring.
  • Own-recorded state cannot produce a new Reject for a single honest instance: RoundAlreadyAdvanced, SlotAlreadyAdvanced and DecidedWithSameSigners are all Ignore.
  • Per-peer entries are bounded at six per signer state, as the description says.

One thing I could not settle statically: record_outbound runs when the message is queued, so a failed gossipsub publish leaves a record for a message that never left. That only matters for decided commits, and only if Anchor and go-ssv produce byte-different commits for the same ordered signer set.

Comment on lines +784 to +791
match ssv_message.msg_type() {
MsgType::SSVConsensusMsgType => {
if let Ok(consensus_message) = QbftMessage::from_ssz_bytes(ssv_message.data()) {
duty_state().update_for_consensus_message(
signed_ssv_message,
&consensus_message,
None,
);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

minor (tests). The two verdict changes the description discloses (DecidedWithSameSigners after an own decided commit, SlotAlreadyAdvanced after an own publish for a later slot) are not pinned by a test. Both come from side effects of this call (the seen_signers insert and the max_slot update), not from the counters the new tests cover, and published_messages() only records a prepare and a post-consensus packet. A later change that skips multi-signer messages here would pass the suite and revert both.

Suggest two OwnPublishFixture cases: record an own decided commit, then deliver one with the same signers; record an own publish for slot S+1 in a monotonic-slot role, then deliver a slot-S message from this operator.

One consequence worth a line in the description: once this node has published for a later slot, a decided commit for the older slot that includes this operator is Ignored before it reaches qbft_manager. It needs this node to have committed but not decided, in a non-committee role with consecutive-slot duties, so it is rare.

let result = receiver.validator.validate(
&message.data,
&topic_context,
propagation_source,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

minor (observability). The verdict now depends on this peer, but the two "Validation failure" debug lines below log ?failure without it, and the got text shows the peer's counts but not which peer. The only peer log is the trace! at receipt in network.rs, which has to be joined on message id. As it stands neither tier can be observed on a live node, which is the gap the #1211 comment called blocking.

Adding peer = %propagation_source to those two lines would cover it. A counter keyed on the failure variant fits #1211 better than this PR.

///
/// A repeat from the peer that delivered the first copy is `DuplicatedMessage` (Reject).
/// A repeat from any other peer is `RelayedDuplicateMessage` (Ignore).
pub(crate) fn validate_consensus_message_limits(

@shane-moore shane-moore Dec 4, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

design, not a defect. The #1211 comment listed three directions and chose none. This implements the two-tier for the six counters. The description gives go-ssv parity as the reason but does not say why not the other option listed there: treat cryptographically valid signer-level duplicates (DuplicatedMessage, InvalidPartialSignatureTypeCount) as Ignore with no peer state in the validator, and handle transport abuse with a separate bounded per-peer rate limiter. That option has its own cost in the limiter, so it is not just a reclassification.

The main difference in verdicts between the two is the first-deliverer Reject, and what that catches is narrow. Inside the 6.4 minute duplicate cache, a second copy that reaches the validator is byte-different. Honest relayers apply the same limit and do not forward it. So a same-peer repeat is the equivocating operator's own node as a direct peer, or unverified bytes (this check runs before signature verification).

Meanwhile the common equivocation, two proposals with different data, still hits DifferentProposalData first and stays Reject for every peer. Full parity there means per-peer proposal hashes on top of this.

Counter-argument: scoring a peer the same way go-ssv does has value in a mixed mesh, and this keeps an existing penalty instead of weakening it. Worth two sentences in the description, or a decision on #1211, before the DifferentProposalData follow-up builds on this. It also brings back the peer parameter that 52ba589f removed.

}

/// Records the messages this node publishes in the gossip validation state.
pub trait OutboundRecorder: Send + Sync {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

design, minor. Own-publish recording is a second behavior change that the peer tier works without. It has its own trait, sender and client plumbing, an unvalidated state write, and two verdict changes. Its reachable benefit looks small:

  • gossipsub caches the id of every message it publishes, and the id is xxhash64 of the bytes, so a relayed own copy reaches the validator only after the cache expires (one epoch).
  • At that point base already Ignores it for the 3-slot roles (LateSlotMessage) and for consensus messages of the 34-slot roles (EstimatedRoundNotInAllowedSpread).
  • That leaves partial-signature packets of the 34-slot roles, for roughly two slots (TTL 34 against cache 32), plus decided commits where another node produces a byte-different commit with the same ordered signers.

Parity is a fair reason to keep it, since go-ssv validates local publishes. Either way, consider splitting it into its own PR so it can be reverted alone, or put this window in the "How often" paragraph and name the second change in the title.

Comment on lines +318 to +320
/// The same counts split by the peer that delivered each accepted message. A repeat from
/// the peer that delivered the first copy is that peer's fault; a repeat from any other
/// peer is an honest relay of a message this node already has. Boxed and lazily allocated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

nit (wording). The rule does not compare messages. It fires for any message whose (signer, slot, round, type) is already counted, before the outer signature is verified, so this can also be a different message from an equivocating signer, or bytes nobody signed. Suggest "a repeat from any other peer is not evidence against that peer". The test section header further down uses the same wording.

Three description statements to adjust while here:

  • Identical bytes always get the same gossipsub id, so "the same prepare ... different message IDs" is really the byte-different (equivocation) case.
  • The received_from removal (52ba589f) is already in this branch's base on unstable, not only on epbs.
  • "Weaker punishment" could say "any message for an already-counted type, verified or not, from a peer that did not deliver the first".

Follow-up to review of the peer-aware duplicate verdicts.

- Add validator-level tests, each with a control, for the two verdicts
  that change once own publishes are recorded: DecidedWithSameSigners
  after an own decided commit, and SlotAlreadyAdvanced after an own
  publish for a later slot. Neither was asserted before, so narrowing
  record_outbound to single-signer messages passed the suite.
- Name the delivering peer on the validation-failure debug lines. The
  repeat verdict now depends on that peer, and no log line carried it.
- Reword three comments: the repeat check compares message type, not
  content, and runs before signature verification, so a repeat from
  another peer is not necessarily a relay of the accepted message.

@shane-moore shane-moore left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I’d fix the stale-round update before merging. The two inline comments cover out-of-order sends and failed publishes. The new Accept controls and peer IDs in the failure logs address the earlier test and logging findings.

I traced both paths in source at f3842e9d. I didn’t reproduce either on a running node.

Reviewed by GPT-6.2 Astra (ultra).

match ssv_message.msg_type() {
MsgType::SSVConsensusMsgType => {
if let Ok(consensus_message) = QbftMessage::from_ssz_bytes(ssv_message.data()) {
duty_state().update_for_consensus_message(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fix before merge. Suppose the round-2 round change is recorded before a delayed round-1 prepare from the same signer for the same slot. Sign-and-send jobs can finish out of order. This call bypasses the inbound stale-round check, and OperatorState::update reuses the round-2 state for the older message. Round 2 now has a prepare count of one before its first prepare has been recorded, so an incoming round-2 prepare for that signer that reaches validation can be ignored as a duplicate. The local round-2 send itself still goes out.

Skip stale single-signer records under the duty-state lock and preserve the existing handling of multi-signer decided commits. A regression test can record the round-2 round change, then the round-1 prepare, and check that round 2 still admits its first prepare.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in a73ea71. OperatorState::update no longer records a single-signer message whose round is below the signer state's round. Decided commits still record their signers at any round. Inbound behaviour is unchanged: RoundAlreadyAdvanced already stops that case, under the same duty-state lock.

Two tests: test_own_lower_round_message_not_counted_in_higher_round_state (the sequence suggested here) and test_lower_round_decided_commit_still_records_its_signers. Removing the guard fails the first, and dropping the single-signer condition fails the second.

On impact: the stale count only touched this operator's own signer state, so the verdicts it could change were for relayed copies of our own messages, which are Ignore either way. The one wrong Reject I found is a stale own proposal overwriting proposal_hash, and that needs this node to lead both rounds.

Reply by Claude Fable 5.2.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Verified at a73ea711. The stale single-signer update returns before it can change the current round’s counters or proposal hash. The regression test checks both sides: round 2 still admits its first prepare and remembers its round change. The companion test preserves the signer set for an older decided commit. This addresses my blocker.

GPT-6.2 Astra (ultra)

match self.network_tx.try_send((topic.clone(), message_bytes)) {
Ok(_) => trace!(?subnet, %topic, "Successfully sent message to network"),
Ok(_) => {
self.outbound_recorder.record_outbound(&message);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Minor, forwarding after reconnect. This records a locally assembled decided commit as soon as the channel accepts it. If gossipsub then returns NoPeersSubscribedToTopic, it has sent nothing and exits before inserting the message ID into its duplicate cache. After reconnection, even a byte-identical commit from a peer can reach validation. The recorded signer set gives it DecidedWithSameSigners, so this node misses its first chance to forward it. Its local QBFT decision is already complete.

I’d record on successful gossipsub publication. If queue-time recording is intentional for parity with Go’s local validation, document that forwarding tradeoff and pin the no-peers case with a test.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Kept queue-time recording and documented the tradeoff in a73ea71: a comment at this call and a line under Risks in the description.

go-ssv has the same outcome in the no-peers case. go-libp2p-pubsub v0.15.0, the version it pins, marks a local message seen and runs the validator on it before it looks for peers (ValidateLocal calls validate, which calls markSeen first), so a later copy is not forwarded there either. Recording on publish would need the network task to report back to the validator and would diverge from that.

No no-peers test added. The verdict after an own decided commit is pinned by test_validator_ignores_decided_commit_with_signers_of_own_published_one, and the no-peers branch is inside gossipsub, which this layer cannot drive.

Reply by Claude Fable 5.2.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Verified the no-peers case against go-ssv v2.5.2 and its pinned go-libp2p-pubsub v0.15.0. A valid local decided commit goes through validation before Go selects recipients, so both clients suppress the later copy even if no peer received the original. I’m satisfied with keeping queue-time recording for that parity. The sender comment and PR description now spell out the missed relay.

The existing test covers the validator’s recorded and unrecorded verdicts directly. A publish failure followed by reconnection remains untested end to end. I’m comfortable leaving that as a coverage gap.

GPT-6.2 Astra (ultra)

Own publishes are recorded without validation, and sign-and-send jobs
can be recorded out of order. A round-1 message recorded after the same
signer's round-2 message was counted into the round-2 state, and a stale
proposal could overwrite that state's proposal hash.

- Do not record a single-signer consensus message whose round is below
  the signer state's round. Validation already stops such a message from
  a peer (RoundAlreadyAdvanced), so inbound behaviour is unchanged.
  Decided commits still record their signers at any round.
- Document that own messages are recorded when queued, not when
  gossipsub publishes, and what that means when a publish finds no
  peers. go-ssv has the same outcome.
@shane-moore

Copy link
Copy Markdown
Member Author

Summary of what changed in response to the two reviews above. Posted by Claude Fable 5.2.

f3842e9, for the first review:

  • Tests for the two verdicts that change once own messages are recorded (DecidedWithSameSigners, SlotAlreadyAdvanced), each with an Accept control.
  • Both "Validation failure" debug lines name the delivering peer.
  • Three comments reworded: the repeat check compares message type, not content.
  • Direction: two-tier for go-ssv parity, now stated in the description. Own-publish recording stays in this PR, with its reach stated.

a73ea71, for the second review:

  • An own single-signer message for a round the signer already left is no longer recorded, with two regression tests.
  • Queue-time recording is kept and documented, since go-ssv has the same outcome when a publish finds no peers.

Not done: a metric keyed on the failure variant (left with #1211), a test for the partial-signature path to SlotAlreadyAdvanced, and a test of the no-peers publish case.

Checks at a73ea71, run locally with rustc 1.100.1 in the debug profile: cargo test -p message_validator -p message_receiver -p message_sender -p network --lib gives 180, 1, 0 and 64 passed, none failed. Clippy with -D warnings on those crates and cargo fmt --check are clean. Not run locally: the workspace-wide make lint and make test.

Conflicts in the message_validator test module imports, resolved as the
union of both sides. The padding test added by sigp#1376 now passes a peer
to Validator::validate.
@shane-moore
shane-moore merged commit d4bb09e into sigp:unstable Dec 4, 2026
18 checks passed
@shane-moore

Copy link
Copy Markdown
Member Author

On Anchor d4bb09e8, the receiver accepted the first prepare and post-consensus partial, ignored the copy from a second peer and rejected the repeat from the original peer. Own-publish and missing-record controls also passed.

In the ordinary 2+2 run with Go #3142 74397840, each operator had three peers across the Fulu/Gloas boundary and all ten managed aggregates published in the first Gloas epoch. The peer-specific verdicts came from the receiver fixtures. Receiver test

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