Skip to content

fix(swarm,node): resolve pending offer slot leak, backoff accounting, glare finger rebind, and session key renewal (#1222, #1223) - #1237

Merged
RyanKung merged 2 commits into
developfrom
fix/1222-1223-swarm-and-session-delegation
Nov 10, 2026
Merged

RyanKung merged 2 commits into
developfrom
fix/1222-1223-swarm-and-session-delegation

Conversation

@RyanKung

@RyanKung RyanKung commented Nov 9, 2026

Copy link
Copy Markdown
Member

Summary

Closes #1222 and #1223.

Issue #1222

  1. send_connection_offer / Swarm::offer_connection pending slot leak:
    • Routes sender.originate(...) and self.mark_offer_sent(...) errors through SwarmTransport::classify_step_failure so any failure while attempt still owns the unadmitted slot immediately abandons the pending slot and closes the raw WebRTC connection.
  2. Candidate dial backoff misaccounting:
    • Tracks was_offering: bool on RetiredPendingConnection and ExpiredUnadmittedPeer at the atomic moment the Pending record is removed under the lifecycle lock.
    • Records record_candidate_dial_failure only when a retired/expired attempt owned an outbound Handshake::Offering slot, and exempts local capacity refusals (PendingConnectionCapacityExceeded, ConnectionCapacityExceeded) from peer backoff penalties.
  3. Glare finger lease rebind (yield_pending_in):
    • Adds SwarmTransport::rebind_pending_finger_updates(from, to) and updates yield_pending_in to rebind any queued finger convergence proof from the yielding outbound offering attempt to the replacing inbound answering attempt instead of cancelling the active finger lookup.

Issue #1223

  1. Preserve onion hop decryption across in-process delegation renewal:
    • Exposes decryption_keys_at(&self, now_ms: u128) -> Vec<DelegateeKey> on extension::ext::registry::{Core, Scope} backed by SessionKeyRing::decryption_keys_at.
    • Updates OnionCircuitShell::hop, circuit::hop::hop, Charged::peel, OnionCell::peel, and peel_in_place to accept keys: &[DelegateeKey] and try current followed by retained unexpired pre-renewal keys when verifying the per-hop Sphinx HMAC.
  2. Scope DelegationLessee::encode within_margin check to delegations.hop:
    • Enforces within_margin(delegations.hop.expires_at_ms(), now_ms) only on delegations.hop, allowing delegations.origin as long as expires_at_ms() > now_ms and falling back to DelegationRef::inline(delegation) inside the final LEASE_MARGIN_MS.
  3. Enforce delegator signature & monotone horizon in SwarmTransport::set_delegatee_key and serialize renewal under session_keys write lock.

Test Plan

  • cargo test -p rings-core --features dummy --lib swarm::session_link
  • cargo test -p rings-core --features dummy --lib swarm::transport::tests::test_finger
  • cargo test -p rings-core --features dummy --lib swarm::transport::tests::test_lifecycle
  • cargo test -p rings-node --lib onion::
  • cargo test -p rings-node --lib horizon

Copy link
Copy Markdown
Member Author

Reviewed at 38ef5e4efc98388dc1ad06728ea30c7a0f755919. I found no confirmed actionable defect introduced by this PR within the reviewed scope.

  • Handshake ownership and backoff: traced offer-origination and mark-sent failures through retirement. Outbound ownership is captured under the lifecycle lock; inbound Answering, superseded attempts, and capacity refusal do not incorrectly charge outbound dial backoff.
  • Glare and finger updates: checked rebinding the pending finger proof to the replacement generation. Old-generation cancellation cannot remove the newly keyed proof.
  • Decryption and authority: followed active and retained keys from SessionKeyRing into Sphinx peeling. Invalid group elements fail before key trial, and header mutation follows a matching HMAC. Retained keys are expiry-filtered; the setter checks delegation authority and the signing horizon.
  • Renewal and compatibility: checked validation, persistence, and swarm-key installation within the ring write-lock transaction, plus origin-versus-hop lease-margin behavior. Wire encoding is unchanged; retained-key trial cost is linear in the unexpired key count.

Local validation: cargo +nightly-2026-07-02 fmt --all -- --check passed. The added lifecycle, glare, setter, retained-key, and lease-margin tests were inspected, but Rust tests were not rebuilt or rerun locally at this head. Separately, the inspected current-head GitHub CI report showed 19 successful checks and one skipped check.

Limits: no local browser-runtime execution or retained-key performance benchmark. The overlapping registry changes in #1248 were not jointly tested with this PR.

@RyanKung
RyanKung merged commit ed6ed0e into develop Nov 10, 2026
20 checks passed
@RyanKung
RyanKung deleted the fix/1222-1223-swarm-and-session-delegation branch November 10, 2026 09:20
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.

1 participant