You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Port subnet network topology from leanSpec PR #482 (#249)
## Motivation
leanSpec PR #482 (merged 2025-03-25) introduces `--aggregate-subnet-ids`
and changes how nodes subscribe to attestation subnets. The key
architectural shift: **subnet filtering moves from the fork choice store
to the P2P subscription layer**.
Before this PR, ethlambda had several gaps:
- Only the first validator's subnet was used (multi-validator nodes all
published/subscribed to one subnet)
- The store had a **hardcoded** `ATTESTATION_COMMITTEE_COUNT = 1`
constant (ignored the CLI parameter)
- The store performed per-attestation subnet filtering that the spec
removed
- No `--aggregate-subnet-ids` CLI flag existed
- Non-aggregator validators didn't subscribe to their subnet (should,
for gossipsub mesh health)
## Description
### Phase 1: CLI (`bin/ethlambda/src/main.rs`)
- Add `--aggregate-subnet-ids` CLI flag (comma-separated, `requires =
"is_aggregator"` via clap)
- Collect **all** validator IDs instead of just the first one
- Pass `validator_ids: Vec<u64>` and `aggregate_subnet_ids` to
`SwarmConfig`
### Phase 2: P2P layer (`crates/net/p2p/src/lib.rs`,
`crates/net/p2p/src/gossipsub/handler.rs`)
- `SwarmConfig`: `validator_id: Option<u64>` → `validator_ids: Vec<u64>`
+ `aggregate_subnet_ids: Option<Vec<u64>>`
- `BuiltSwarm` / `P2PServer`: single `attestation_topic` →
`attestation_topics: HashMap<u64, IdentTopic>` +
`attestation_committee_count: u64`
- **Multi-subnet subscription logic**:
- All nodes with validators subscribe to their validator subnets (for
gossipsub mesh health)
- Aggregators additionally subscribe to any explicitly requested
`--aggregate-subnet-ids`
- Aggregator with no validators and no explicit subnets: fallback to
subnet 0
- Non-validator non-aggregator nodes: no attestation subscriptions
- `publish_attestation`: routes per-validator to the correct subnet
topic (`validator_id % committee_count`); if the subnet isn't
subscribed, constructs the topic on-the-fly for gossipsub fanout
- Metric `lean_attestation_committee_subnet` reports the lowest
validator subnet (backward-compatible)
### Phase 3: Store simplification (`crates/blockchain/src/store.rs`)
- **Removed** `ATTESTATION_COMMITTEE_COUNT` constant and
`compute_subnet_id()` helper
- `on_gossip_attestation`: removed `local_validator_ids` parameter;
stores gossip signatures **unconditionally** (subnet filtering already
handled at P2P layer)
- `on_block` / `on_block_core`: removed `local_validator_ids` parameter;
stores proposer signature **unconditionally**
### Phase 4: Caller updates (`crates/blockchain/src/lib.rs`,
`crates/blockchain/tests/signature_spectests.rs`)
- Updated all call sites to match simplified store function signatures
## How to test
```bash
make fmt # ✅ passes
make lint # ✅ passes
make test # ✅ all 97 tests pass (forkchoice + signature + STF spec tests)
```
For devnet testing:
```bash
# Single subnet (existing behavior, unchanged)
--attestation-committee-count 1 --is-aggregator
# Multi-subnet with explicit aggregator subscription
--attestation-committee-count 2 --is-aggregator --aggregate-subnet-ids 0,1
# Multi-validator node (subscribes to all validator subnets automatically)
--attestation-committee-count 4 --is-aggregator
```
Verify via logs:
- Look for `Subscribed to attestation subnet` lines (one per subscribed
subnet)
- `Published attestation to gossipsub` now includes `subnet_id` field
- Gossip signatures are stored without subnet filtering (no more silent
drops)
## Notes
- **Non-aggregator subscription is new behavior**: previously
non-aggregators never subscribed to attestation subnets. Now they
subscribe for mesh health. This slightly increases bandwidth but matches
the spec.
- **Hardcoded `"devnet0"` network name**: existing limitation carried
forward in the fanout topic construction. Should be addressed
separately.
- **Subnet metric**: `lean_attestation_committee_subnet` is a single
gauge. With multiple subnets, we report the lowest validator's subnet
for backward compatibility. Can be improved in a follow-up.
## Related
- leanSpec PR #482 (upstream spec change)
---------
Co-authored-by: Tomás Grüner <47506558+MegaRedHand@users.noreply.github.com>
0 commit comments