Repository navigation
Description
Follow-up from review of #1367 (G-GOV-03). No defect today — this is about making a security-relevant invariant unrepresentable rather than documented.
Current shape
pub struct UpstreamRefused {
pub error: StreamError,
pub response: Option<StreamResponse>, // added in #1367
}The field docs assert four invariants, all enforced only by convention:
response == Some(r)iff the refusal arrived at the open stage;Noneiff a mid-streamClientMessage::StreamErrorframe (which carries no signature).- When
Some(r):self.error == r.error.unwrap()— the wire code is duplicated in two places that nothing keeps in sync. - When
Some(r):r.body.ok == false. - When
Some(r):r.slash_sigrecovers toexpected_signer.
Both fields are pub, there is no constructor, and the struct is exported from the crate root with 8+ construction sites outside client-pull. The only thing keeping 2–4 true is that the single production path goes through the private refusal(), which derives error from response.
Why it is worth doing
This is not diagnostic state. response is the payload a challenger replays to SlashJudge, which burns a challengeBond and slashes an operator's stake. crates/e2e/src/client.rs already consumes refused.response and forwards it to an on-chain challenge with no re-verification, trusting invariant 4 entirely on the strength of a doc comment. The failure mode this admits is a silently mis-attributed accusation.
Suggested shape
pub enum UpstreamRefused {
/// Open-stage: the peer signed `ok == false`, verified against `expected_signer`.
Open { error: StreamError, response: StreamResponse },
/// Mid-stream `ClientMessage::StreamError` — unsigned, never evidence.
MidStream { error: StreamError },
}with private fields, a fallible open(response) that derives error from the response, mid_stream(error), a total error() accessor, and evidence() -> Option<&StreamResponse>.
Invariant 1 becomes the variant tag; 2 becomes unviolatable; 3 follows from open() requiring response.error.is_some() (which validate() already ties to ok == false). Invariant 4 cannot be enforced here (the type does not know the expected signer) — leave that check where it is and document it.
Cost
Lower than it looks: 5 downcast consumers change .error to .error() and still match fine; 8 test construction sites become UpstreamRefused::mid_stream(err), which is shorter than the current literal. No public-API snapshot churn — decdn-client-pull is not covered by that job, which runs -p decdn-protocol only.
Related
- The type is also still used as an anyhow context marker (
crates/node/src/node_origin.rs, insidemod tests). Sincedowncast_refreturns the outermost match, a.context(UpstreamRefused { response: None })layered over an evidence-carrying error would silently drop the signed attestation. Constructors would make that misuse obviously wrong. - Derived
Debugnow renders the full signed body plus the 65-byteslash_sig; a manualDebugeliding the signature to a length would keeptracing::error!(?err)readable.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
fix(e2e,client-pull): correct two false doc claims, reuse typed rever…
feat(e2e,client-pull): real daemon responses as on-chain slash eviden…
fix: buyer-side rate integrity & slash evidence on the paid-pull path (…
fix: buyer-side rate integrity & slash evidence on the paid-pull path (…
fix: buyer-side rate integrity & slash evidence on the paid-pull path (…