Repository navigation
fix(message_validator): ignore duplicates relayed by another peer - #1375
Conversation
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.
|
This pull request is merged. |
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
shane-moore
left a comment
There was a problem hiding this comment.
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,SlotAlreadyAdvancedandDecidedWithSameSignersare 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.
| 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, | ||
| ); |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
| /// 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 |
There was a problem hiding this comment.
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_fromremoval (52ba589f) is already in this branch's base onunstable, not only onepbs. - "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
left a comment
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
Summary of what changed in response to the two reviews above. Posted by Claude Fable 5.2. f3842e9, for the first review:
a73ea71, for the second review:
Not done: a metric keyed on the failure variant (left with #1211), a test for the partial-signature path to Checks at a73ea71, run locally with rustc 1.100.1 in the debug profile: |
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.
|
On Anchor In the ordinary 2+2 run with Go #3142 |
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
DuplicatedMessageorInvalidPartialSignatureTypeCount. Both map to Reject, whoever delivered the copy, and Reject applies the gossipsub invalid-message penalty to the delivering peer.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::validatenow takes the relaying peer. The receiver passes the gossipsub propagation source.RelayedDuplicateMessage).OutboundRecordertrait, which the validator implements. Own messages are added to the all-peers counts only.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 andOutboundRecorder), then the call sites inmessage_receiver,message_senderandclient.About 270 production lines; the other 1,200 or so are tests.
Not changed:
DifferentProposalDatastays Reject for every peer. Go has a peer rule there too; it needs its own decision.ValidationFailurevariants, and the classification match is untouched (refactor(message_validator): make ValidationFailure -> MessageAcceptance classification exhaustive #1211 stays open).Risks, Trade-offs, and Mitigations (Required)
DecidedWithSameSigners. After it publishes for a later slot in a role whose slots only move forward, an older-slot message returnsSlotAlreadyAdvanced. Both are Ignore, and both are what any other node already computes for the same traffic.PeerIdof 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 warningson those crates andcargo 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 isSlotAlreadyAdvanced, 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
c4cc5f15and once witha73ea711. 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.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)
received_fromparameter was removed in refactor(message_validator): delete the unused received_from plumbing and peer-keyed preference map #1284 (closing refactor(message_validator): delete the unused received_from plumbing and peer-keyed preference map #1273) because nothing read it; that is already onunstableandepbs. This PR adds one that is read. A trial merge intoepbsat8bfd72beis textually clean.