Skip to content

Comments

feat: replace SharedDomainType with SharedForkLifecycle for fork-aware peer selection#2

Closed
diegomrsantos wants to merge 4 commits intofix/fork-aware-observed-peer-subnetsfrom
feat/shared-fork-lifecycle
Closed

feat: replace SharedDomainType with SharedForkLifecycle for fork-aware peer selection#2
diegomrsantos wants to merge 4 commits intofix/fork-aware-observed-peer-subnetsfrom
feat/shared-fork-lifecycle

Conversation

@diegomrsantos
Copy link
Owner

Issue Addressed

Follows up on PR sigp#820 (fork-aware observed_peer_subnets). While sigp#820 correctly stores per-fork bitmaps, all query methods still aggregate across forks with a blind union(). After the Boole grace period ends, peers only subscribed to Alan topics appear useful for Boole subnets — leading to incorrect peer selection.

Proposed Changes

  • Introduce ForkLifecycle enum (Normal, WarmUp, GracePeriod) and SharedForkLifecycle shared state in the fork crate, replacing SharedDomainType
  • ForkMonitor updates the shared lifecycle state before broadcasting each ForkPhase event
  • Peer selection queries in ConnectionManager now consult the lifecycle: in Normal state only the current fork's bitmap is considered; during WarmUp/GracePeriod both forks are aggregated
  • All components that previously read SharedDomainType (Discovery, Handshake) now read SharedForkLifecycle::domain_type() instead
  • Network::on_fork_phase simplified — no longer sets domain type (monitor handles it), only updates ENR

Additional Info

  • SharedForkLifecycle follows the same Arc<RwLock<T>> single-writer pattern as the SharedDomainType it replaces
  • The enum makes invalid states unrepresentable — a single value captures fork identity, domain type, and transition phase
  • ENR updates remain in Network::on_fork_phase because they require explicit discv5 mutation
  • count_observed_peers_for_subnets hoists the lifecycle read outside the per-peer loop to avoid repeated lock acquisition

diegomrsantos and others added 4 commits February 11, 2026 12:17
Add a new lifecycle module to the fork crate that models fork transition
states as a single enum with three variants:

- Normal: operating on a single fork (pre-fork or post-grace-period)
- WarmUp: preparing for an upcoming fork (dual-subscribing to new topics)
- GracePeriod: fork activated but keeping old subscriptions for late messages

SharedForkLifecycle wraps this in Arc<RwLock<T>> for cross-component
sharing, following the same pattern as the SharedDomainType it will
replace. Each variant carries domain_type, making invalid states
unrepresentable.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ForkMonitor now accepts a SharedForkLifecycle and updates it right
before broadcasting each ForkPhase event:

- Preparing  → WarmUp { current, upcoming, domain_type }
- Activated  → GracePeriod { current, previous, domain_type }
- GracePeriodEnded → Normal { current, domain_type }

This makes ForkMonitor the single writer of fork lifecycle state.
Components that previously needed to react to events just to cache
derived values can now read the shared state directly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace the SharedDomainType abstraction with SharedForkLifecycle
across all network components, making peer selection fork-aware.

Key changes:
- Remove SharedDomainType from network crate entirely
- Discovery and Handshake read domain_type via fork_lifecycle
- Network::on_fork_phase simplified to only update ENR (domain type
  updates are now handled by ForkMonitor via SharedForkLifecycle)
- ConnectionManager uses fork lifecycle to filter peer subnets:
  in Normal state only the current fork's bitmap is returned;
  during WarmUp/GracePeriod both forks are aggregated
- Client creates SharedForkLifecycle and passes to both ForkMonitor
  and Network

This prevents peers subscribed only to a defunct fork from appearing
useful for subnet coverage after the grace period ends.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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