Skip to content

Commit 5ed24c3

Browse files
authored
Merge branch 'main' into build/leanvm-track-main
2 parents abf11f9 + 8bdbfc9 commit 5ed24c3

5 files changed

Lines changed: 81 additions & 1 deletion

File tree

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ behavior.
398398

399399
## Resources
400400

401-
**Specs:** `leanSpec/src/lean_spec/` (Python reference implementation)
401+
**Specs:** `leanSpec/src/lean_spec/spec/` (Python reference implementation; fork logic under `forks/<fork>/`, e.g. `forks/lstar/`)
402402
**Devnet:** `lean-quickstart` (github.com/blockblaz/lean-quickstart)
403403
**Docs:** `docs/` — `rpc.md`, `metrics.md`, `checkpoint_sync.md`, `3sf_mini.md`, `lmd_ghost.md` (mdbook via `make docs`)
404404
**Releases:** See `RELEASE.md` for release process documentation

bin/ethlambda/src/cli.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,59 @@ pub(crate) struct CliOptions {
124124
/// `on_block`.
125125
#[arg(long, default_value = "3")]
126126
pub(crate) max_attestations_per_block: usize,
127+
#[command(flatten)]
128+
pub(crate) discovery: DiscoveryConfig,
127129
/// Shadow-simulator sim-cost + fake-XMSS flags (only under the
128130
/// `shadow-integration` feature).
129131
#[cfg(feature = "shadow-integration")]
130132
#[command(flatten)]
131133
pub(crate) shadow: ShadowOptions,
132134
}
133135

136+
/// discv5 peer discovery. Off by default: nothing else on the lean network
137+
/// speaks discv5 yet, so enabling it only finds other ethlambda nodes.
138+
#[derive(Debug, clap::Args)]
139+
pub(crate) struct DiscoveryConfig {
140+
/// Enable discv5 peer discovery.
141+
///
142+
/// Requires `--discovery.port` to differ from `--gossipsub-port`: both are
143+
/// UDP sockets and they cannot share one port.
144+
#[arg(long = "discovery.enable", default_value = "false")]
145+
pub(crate) enable: bool,
146+
/// UDP port for the discv5 socket.
147+
///
148+
/// Independent of `--gossipsub-port`, which carries libp2p QUIC. Both
149+
/// default to 9000, so enabling discovery means changing one of them.
150+
#[arg(long = "discovery.port", default_value = "9000")]
151+
pub(crate) port: u16,
152+
/// IP address to advertise in the ENR.
153+
///
154+
/// Defaults to the bind address, which is the wildcard `0.0.0.0` and is not
155+
/// dialable as published. Set this to the address peers should reach this
156+
/// node on: `127.0.0.1` for a local devnet, or the host's public address.
157+
/// discv5's PONG-based IP voting may still replace it at runtime.
158+
#[arg(long = "discovery.advertise-ip")]
159+
pub(crate) advertise_ip: Option<std::net::IpAddr>,
160+
}
161+
162+
impl CliOptions {
163+
/// Reject a discovery port that collides with the QUIC port.
164+
///
165+
/// Both are UDP. Without this the collision surfaces at bind time as an
166+
/// opaque `EADDRINUSE` on whichever socket loses the race.
167+
pub(crate) fn validate_discovery(&self) -> eyre::Result<()> {
168+
if self.discovery.enable && self.discovery.port == self.gossipsub_port {
169+
eyre::bail!(
170+
"--discovery.port ({}) must differ from --gossipsub-port ({}): \
171+
both bind UDP and cannot share a port",
172+
self.discovery.port,
173+
self.gossipsub_port
174+
);
175+
}
176+
Ok(())
177+
}
178+
}
179+
134180
/// Shadow-simulator sim-cost + fake-XMSS flags. Compiled only under the
135181
/// `shadow-integration` feature.
136182
#[cfg(feature = "shadow-integration")]

bin/ethlambda/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ async fn main() -> eyre::Result<()> {
8181
.wrap_err("failed to set global tracing subscriber")?;
8282

8383
let options = CliOptions::parse();
84+
options.validate_discovery()?;
8485

8586
#[cfg(feature = "shadow-integration")]
8687
init_shadow_cost(&options.shadow);

docs/SUMMARY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@
1515
- [Checkpoint Sync](./checkpoint_sync.md)
1616
- [Fork Choice Visualization](./fork_choice_visualization.md)
1717
- [Data Storage](./data_storage.md)
18+
19+
# Development
20+
21+
- [Spec Deviations](./spec_deviations.md)

docs/spec_deviations.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Spec Deviations
2+
3+
ethlambda diverges from the [leanSpec](https://github.com/leanEthereum/leanSpec)
4+
reference in a few places, mainly for performance reasons. This page lists those
5+
deviations; each will be fleshed out with rationale, implementation notes, and
6+
trade-offs over time.
7+
8+
## Asynchronous signature aggregation with an early start and an early stop
9+
10+
Aggregation runs off the main BlockChainServer actor loop, may start before its
11+
interval, and stops early once it runs out of time.
12+
13+
- **ethlambda:** the actor snapshots everything aggregation needs (`snapshot_aggregation_inputs`, `crates/blockchain/src/aggregation.rs`) and spawns a `tokio::task::spawn_blocking` worker (`run_aggregation_worker`, `aggregation.rs`). Candidates are the store's gossip-signature groups plus payload-only groups (`new_payload_keys`, which need at least two existing proofs to merge). A tiered greedy selector orders them by consensus value (current-slot before stale, then `Finalize > Justify > Build`, mirroring the block builder) and emits at most `MAX_AGGREGATION_JOBS` jobs, dropping to a single job in the slot before one of our validators proposes. The worker streams each finished group back as an `AggregateProduced` message; the actor loop is never blocked on XMSS work.
14+
- **Early start:** a session normally fires at interval 2, but may start up to `EARLY_AGGREGATION_WINDOW` earlier once the 2/3 signature threshold is already met (`maybe_start_early_aggregation`, `crates/blockchain/src/lib.rs`), so the proof lands earlier in the slot.
15+
- **Early stop:** a `send_after(AGGREGATION_DEADLINE, ...)` timer cancels the session that long after **session start**, so a session that started early also ends early (`AGGREGATION_DEADLINE`, `aggregation.rs`). The worker checks `cancel.is_cancelled()` before each job (`aggregation.rs`); in-flight jobs finish, remaining jobs are dropped.
16+
- **leanSpec:** `aggregate()` is called inline and synchronously from `tick_interval`, at interval 2 only. It walks every attestation data with fresh evidence, with no job cap, no time budget, no worker, and no cancellation.
17+
- **Equivalence:** on cancellation the worker emits only the groups that finished, so a slot may pack fewer aggregates than the synchronous path would; any such subset still yields a valid block, affecting how many votes are included rather than signature validity. The job cap has the same character: it bounds prover work per slot, not what a block may carry.
18+
19+
## Attestation scoring on block building
20+
21+
Attestations are scored and selected when packing a block, rather than taken in
22+
target-slot order as they are scanned.
23+
24+
- **ethlambda:** `select_attestations` (`crates/blockchain/src/block_builder.rs`) ranks candidate `AttestationData` entries by tier `Finalize > Justify > Build` (`enum Tier`, `block_builder.rs`). The within-tier order is tier-dependent (`EntryScore::ordering_key`, `block_builder.rs`): `Finalize`/`Justify` entries already cross 2/3, so newer chain progress leads (target slot, attestation slot, then new-voter count); `Build` entries only add marginal voters, so coverage leads (new-voter count, target slot, then attestation slot). `data_root` is the final deterministic tiebreak in both tiers. Each round picks the best candidate against a projected post-state.
25+
- **Proposer budget:** rounds stop at `max_attestations_per_block` distinct `AttestationData` entries (`--max-attestations-per-block`, default 3), clamped to `MAX_ATTESTATIONS_DATA`. The *consensus* cap is `MAX_ATTESTATIONS_DATA`, the same value leanSpec enforces in its state transition; only the proposer-side budget differs, and it is configurable.
26+
- **Collapsing duplicate data:** a winning entry may carry several proofs, which must collapse to one proof per `AttestationData` before the block is valid. By default ethlambda keeps only the best-coverage proof and **drops** the rest (`keep_best_proof_per_data`, `block_builder.rs`), skipping the leanVM merge at the cost of the voters those proofs carried. With `--enable-proposer-aggregation`, `compact_attestations` (`block_builder.rs`) instead merges them through recursive proof aggregation, which is what leanSpec always does.
27+
- **leanSpec:** `build_block` scans candidates sorted by `(target.slot, data_root)`, oldest target first, and includes the first ones that pass its filters (greedy, no scoring), re-running the scan as a fixed point when justification/finalization advances. Its proposer budget is `MAX_ATTESTATIONS_DATA` itself.
28+
- **Equivalence:** both produce a valid block. ethlambda front-loads the attestations that advance justification and finality, and within those tiers prefers the *newest* target where leanSpec takes the *oldest*; combined with the smaller default budget, an older entry can be outranked by newer ones round after round, so which votes reach peers through blocks differs even though every block stays valid. The smaller budget yields smaller blocks and lower build times.
29+
- **Upstream status:** the tiered strategy is proposed upstream as leanSpec [PR #1149](https://github.com/leanEthereum/leanSpec/pull/1149) (open at the time of writing), so this deviation may converge; the recursive-merge collapse follows leanSpec #510.

0 commit comments

Comments
 (0)