Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e745f4b
feat: integrate with ethrex over Engine API
pablodeymo May 13, 2026
a17c2d9
Merge branch 'main' into engine-api-integration
pablodeymo May 14, 2026
d2dc7cf
fix(ethrex-client): address review feedback on wire types and scaffol…
pablodeymo May 14, 2026
33e9c9a
Merge remote-tracking branch 'origin/main' into engine-api-integration
pablodeymo May 18, 2026
0dc37b3
refactor(types): promote execution-payload schema into common/types
pablodeymo May 18, 2026
c9e57c1
refactor(types): make ExecutionPayloadV3 and Withdrawal SSZ-derivable
pablodeymo May 18, 2026
c0d2938
feat(types): add ExecutionPayloadHeader plus payload→header projection
pablodeymo May 18, 2026
8f29f73
feat(types): embed execution payload in BlockBody and State (schema b…
pablodeymo May 18, 2026
47ee3bc
feat(state-transition): wire process_execution_payload into STF
pablodeymo May 18, 2026
99a8e9d
feat(blockchain): validate received-block payloads via engine_newPayl…
pablodeymo May 18, 2026
2b09417
feat(blockchain): fetch real execution payloads from the EL on proposal
pablodeymo May 18, 2026
adcfba3
test(blockchain): cover Phase 4 payload threading + leanSpec proposal…
pablodeymo May 18, 2026
5c54490
feat(blockchain): forward real EL block hashes in engine_forkchoiceUp…
pablodeymo May 19, 2026
dc25b97
fix(ethlambda): parse the dual-pubkey annotated_validators.yaml schema
pablodeymo May 19, 2026
db76a86
Revert "fix(ethlambda): parse the dual-pubkey annotated_validators.ya…
pablodeymo May 19, 2026
69c92e5
feat(ethlambda): seed genesis EL block_hash via --execution-genesis-b…
pablodeymo May 19, 2026
b6ca292
feat(blockchain): inform EL of own-built blocks via engine_newPayloadV3
pablodeymo May 19, 2026
b669410
feat: bootstrap real EL payload flow end-to-end (V4 + genesis body seed)
pablodeymo May 19, 2026
d0c5b72
feat: complete the ethlambda↔ethrex EL pairing loop end-to-end
pablodeymo May 19, 2026
a141a4a
Switch the two remaining V4 call sites in the actor to engine_newPayl…
pablodeymo May 20, 2026
92474dc
Merge remote-tracking branch 'origin/main' into engine-api-integration
pablodeymo May 27, 2026
f85b259
Change compute_time_at_slot to take genesis_time directly instead of …
pablodeymo Jun 9, 2026
ca3dd80
Merge origin/main into engine-api-integration. Resolve additive confl…
pablodeymo Jun 9, 2026
6f4e453
Update the execution_client field doc-comment to describe the actual …
pablodeymo Jun 9, 2026
309590f
Rewrite the leanSpec execution-payload schema proposal into a fileabl…
pablodeymo Jun 9, 2026
8e810f6
Abstract the EngineClient behind an ExecutionEngine async trait so th…
pablodeymo Jun 9, 2026
546b87b
Replace the Engine API payload-attribute placeholders. suggested_fee_…
pablodeymo Jun 9, 2026
1f4f810
Pin the engine payload calls to V4 (Prague) instead of V5. Current et…
pablodeymo Jun 9, 2026
e956a8f
Add an ethlambda<->ethrex Engine API demo script. scripts/engine-api-…
pablodeymo Jun 9, 2026
18ba522
Simplify the Engine API integration after review. Make the ExecutionE…
pablodeymo Jun 9, 2026
e9097df
Restructure the PR to minimize the footprint on pre-existing files, m…
pablodeymo Jun 9, 2026
c70b47e
Add the new modules referenced by the restructure commit: el_integrat…
pablodeymo Jun 9, 2026
8c0ac81
Trim the ethrex-client to the methods ethlambda actually calls. Remov…
pablodeymo Jun 9, 2026
08e073f
Add transaction support to the Engine API demo. send-txs.sh signs EIP…
pablodeymo Jun 9, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ members = [
"crates/common/test-fixtures",
"crates/common/types",
"crates/net/api",
"crates/net/ethrex-client",
"crates/net/p2p",
"crates/net/rpc",
"crates/storage",
Expand All @@ -35,6 +36,7 @@ ethlambda-metrics = { path = "crates/common/metrics" }
ethlambda-test-fixtures = { path = "crates/common/test-fixtures" }
ethlambda-types = { path = "crates/common/types" }
ethlambda-network-api = { path = "crates/net/api" }
ethlambda-ethrex-client = { path = "crates/net/ethrex-client" }
ethlambda-p2p = { path = "crates/net/p2p" }
ethlambda-rpc = { path = "crates/net/rpc" }
ethlambda-storage = { path = "crates/storage" }
Expand All @@ -50,6 +52,7 @@ spawned-concurrency = "0.5.0"
spawned-rt = "0.5.0"
tokio = "1.0"
tokio-util = "0.7"
async-trait = "0.1.83"

prometheus = "0.14"

Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: help fmt lint docker-build shadow-build shadow-docker-build run-devnet test docs docs-deps docs-serve
.PHONY: help fmt lint docker-build shadow-build shadow-docker-build run-devnet run-el-demo test docs docs-deps docs-serve

help: ## πŸ“š Show help for each of the Makefile recipes
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
Expand Down Expand Up @@ -78,6 +78,9 @@ run-devnet: docker-build lean-quickstart ## πŸš€ Run a local devnet using lean-q
@cd lean-quickstart \
&& NETWORK_DIR=local-devnet ./spin-node.sh --node all --generateGenesis --metrics > ../devnet.log 2>&1

run-el-demo: ## πŸ”— Run the ethlambda <-> ethrex Engine API demo (see scripts/engine-api-demo/README.md)
@./scripts/engine-api-demo/run.sh

docs-deps: ## πŸ“¦ Install dependencies for generating the documentation
cargo install --version 0.5.2 --locked mdbook
cargo install --version 0.12.0 --locked mdbook-linkcheck2
Expand Down
1 change: 1 addition & 0 deletions bin/ethlambda/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ shadow-integration = []

[dependencies]
ethlambda-blockchain.workspace = true
ethlambda-ethrex-client.workspace = true
ethlambda-network-api.workspace = true
ethlambda-p2p.workspace = true
ethlambda-types.workspace = true
Expand Down
1 change: 1 addition & 0 deletions bin/ethlambda/src/checkpoint_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ mod tests {
justified_slots: JustifiedSlots::new(),
justifications_roots: Default::default(),
justifications_validators: JustificationValidators::new(),
latest_execution_payload_header: Default::default(),
}
}

Expand Down
175 changes: 170 additions & 5 deletions bin/ethlambda/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ use tracing::{error, info, warn};
use tracing_subscriber::{EnvFilter, Layer, Registry, layer::SubscriberExt};

use ethlambda_blockchain::BlockChain;
use ethlambda_ethrex_client::{
ETHLAMBDA_ENGINE_CAPABILITIES, EngineClient, ExecutionEngine, JwtSecret,
};
use ethlambda_rpc::RpcConfig;
use ethlambda_storage::{
MAX_RESUMABLE_DB_STATE_AGE, StorageBackend, Store, backend::RocksDBBackend,
Expand Down Expand Up @@ -131,6 +134,30 @@ struct CliOptions {
/// Directory for RocksDB storage
#[arg(long, default_value = "./data")]
data_dir: PathBuf,
/// URL of the ethrex (or other EL) Engine API auth endpoint, e.g. `http://127.0.0.1:8551`.
///
/// When unset, Engine API integration is disabled and ethlambda runs as
/// a consensus-only node. When set, `--execution-jwt-secret` is required.
#[arg(long, requires = "execution_jwt_secret")]
execution_endpoint: Option<String>,
/// Path to a file containing the 32-byte JWT secret shared with the EL,
/// as a single line of hex (optionally `0x`-prefixed). Same format used
/// by Lighthouse/Teku/Prysm/ethrex.
#[arg(long, requires = "execution_endpoint")]
execution_jwt_secret: Option<PathBuf>,
/// 32-byte hex hash of the EL's genesis block.
///
/// When set, seeds `state.latest_execution_payload_header.block_hash`
/// so the very first `engine_forkchoiceUpdatedV3` carries a head the
/// EL recognizes. Without this seed the EL replies `SYNCING` forever
/// and never starts building payloads, leaving the chain stuck with
/// synthetic zero-hash payloads.
///
/// Find ethrex's value in its boot log line `Genesis Block Hash: ...`.
/// Required when running paired with an EL; only meaningful alongside
/// `--execution-endpoint`.
#[arg(long, requires = "execution_endpoint")]
execution_genesis_block_hash: Option<String>,
}

// Shadow single-steps execution in a discrete-event simulation, so the default
Expand Down Expand Up @@ -244,6 +271,21 @@ async fn main() -> eyre::Result<()> {
);
ethlambda_blockchain::metrics::set_attestation_committee_count(attestation_committee_count);

// Resolve the suggested fee recipient: validator-config.yaml > zero
// address. Zero is valid on the wire but burns the block rewards, so
// EL-paired nodes get a warning below once the EL client is built.
let suggested_fee_recipient = validator_config_file
.config
.suggested_fee_recipient
.as_deref()
.map(parse_address_hex)
.transpose()
.map_err(|err| {
error!(%err, "Invalid suggested_fee_recipient in validator config");
eyre::eyre!(err)
})?
.unwrap_or([0u8; 20]);

let bootnodes = read_bootnodes(&bootnodes_path)?;

let validator_keys =
Expand All @@ -261,16 +303,31 @@ async fn main() -> eyre::Result<()> {
.wrap_err_with(|| format!("failed to open RocksDB at {}", data_dir.display()))?,
);

let execution_genesis_block_hash = options
.execution_genesis_block_hash
.as_deref()
.map(parse_h256_hex)
.transpose()
.map_err(|err| {
error!(%err, "Invalid --execution-genesis-block-hash");
eyre::eyre!(err)
})?;

let clean_checkpoint_urls: Vec<String> = options
.checkpoint_sync_url
.into_iter()
.map(|url| url.trim().to_string())
.filter(|url| !url.is_empty())
.collect();

let store = fetch_initial_state(&clean_checkpoint_urls, &genesis_config, backend.clone())
.await
.inspect_err(|err| error!(%err, "Failed to initialize state"))?;
let store = fetch_initial_state(
&clean_checkpoint_urls,
&genesis_config,
backend.clone(),
execution_genesis_block_hash,
)
.await
.inspect_err(|err| error!(%err, "Failed to initialize state"))?;

let validator_ids: Vec<u64> = validator_keys.keys().copied().collect();

Expand All @@ -279,11 +336,23 @@ async fn main() -> eyre::Result<()> {
// and the API server (which exposes GET/POST admin endpoints).
let aggregator = AggregatorController::new(options.is_aggregator);

let execution_client = build_execution_client(
options.execution_endpoint.as_deref(),
options.execution_jwt_secret.as_deref(),
)
.await;

if execution_client.is_some() && suggested_fee_recipient == [0u8; 20] {
warn!("suggested_fee_recipient not set in validator config; block rewards will be burned");
}

let blockchain = BlockChain::spawn(
store.clone(),
validator_keys,
aggregator.clone(),
attestation_committee_count,
execution_client,
suggested_fee_recipient,
);

// Note: SwarmConfig.is_aggregator is intentionally a plain bool, not the
Expand Down Expand Up @@ -415,6 +484,12 @@ struct ValidatorConfigFile {
struct ValidatorConfigBlock {
#[serde(default)]
attestation_committee_count: Option<u64>,
/// 20-byte hex address (optionally `0x`-prefixed) the EL is asked to
/// pay block rewards to via `PayloadAttributes.suggestedFeeRecipient`.
/// Only meaningful for EL-paired nodes; defaults to the zero address,
/// which burns the rewards.
#[serde(default)]
suggested_fee_recipient: Option<String>,
}

#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -626,6 +701,77 @@ fn read_validator_keys(
Ok(validator_keys)
}

/// Build the optional Engine API client and run the capability handshake.
///
/// Returns `None` when integration is disabled (neither flag provided).
/// Returns `None` and logs an error when construction or the handshake
/// fails β€” consensus must keep running regardless of EL state.
async fn build_execution_client(
endpoint: Option<&str>,
jwt_path: Option<&Path>,
) -> Option<Arc<dyn ExecutionEngine>> {
// CLI requires both-or-neither; defensive recheck for clarity.
let (endpoint, jwt_path) = match (endpoint, jwt_path) {
(Some(e), Some(p)) => (e, p),
(None, None) => return None,
_ => {
error!("Both --execution-endpoint and --execution-jwt-secret are required together");
return None;
}
};

let secret = match JwtSecret::from_file(jwt_path) {
Ok(s) => s,
Err(err) => {
error!(path = %jwt_path.display(), %err, "Failed to load JWT secret");
return None;
}
};

let client = match EngineClient::new(endpoint, secret) {
Ok(c) => c,
Err(err) => {
error!(%err, "Failed to construct EngineClient");
return None;
}
};

info!(endpoint, "Engine API integration enabled");

match client
.exchange_capabilities(ETHLAMBDA_ENGINE_CAPABILITIES)
.await
{
Ok(caps) => info!(count = caps.len(), "EL capability handshake succeeded"),
Err(err) => warn!(
%err,
"EL capability handshake failed; per-slot FCU calls will still be attempted"
),
}

Some(Arc::new(client))
}

/// Parse an `N`-byte array from a `0x`-prefixed or bare hex string.
fn parse_fixed_hex<const N: usize>(s: &str) -> Result<[u8; N], String> {
let stripped = s.strip_prefix("0x").unwrap_or(s);
let bytes = hex::decode(stripped).map_err(|e| format!("{s:?} is not valid hex: {e}"))?;
let len = bytes.len();
bytes
.try_into()
.map_err(|_| format!("{s:?} decoded to {len} bytes, expected {N}"))
}

/// Parse a 32-byte hex H256 from a `0x`-prefixed or bare hex string.
fn parse_h256_hex(s: &str) -> Result<H256, String> {
parse_fixed_hex::<32>(s).map(H256)
}

/// Parse a 20-byte hex address from a `0x`-prefixed or bare hex string.
fn parse_address_hex(s: &str) -> Result<[u8; 20], String> {
parse_fixed_hex(s)
}

fn read_hex_file_bytes(path: impl AsRef<Path>) -> eyre::Result<Vec<u8>> {
let path = path.as_ref();
let file_content = std::fs::read_to_string(path)
Expand Down Expand Up @@ -662,13 +808,32 @@ async fn fetch_initial_state(
checkpoint_urls: &[String],
genesis: &GenesisConfig,
backend: Arc<dyn StorageBackend>,
execution_genesis_block_hash: Option<H256>,
) -> Result<Store, checkpoint_sync::CheckpointSyncError> {
let validators = genesis.validators();

if checkpoint_urls.is_empty() {
info!("No checkpoint sync URL provided, initializing from genesis state");
let genesis_state = State::from_genesis(genesis.genesis_time, validators);
return Ok(Store::from_anchor_state(backend, genesis_state));
// M6: when paired with an EL, the genesis anchor pair must be seeded
// with the EL's genesis block hash. `from_genesis_with_el_hash` owns
// that protocol (see its doc comment).
return Ok(match execution_genesis_block_hash {
Some(el_hash) => {
info!(%el_hash, "Seeding genesis with EL block hash");
let (genesis_state, genesis_block) =
State::from_genesis_with_el_hash(genesis.genesis_time, validators, el_hash);
Store::get_forkchoice_store(backend, genesis_state, genesis_block).map_err(
|err| {
error!(%err, "Failed to initialize store with seeded genesis body");
checkpoint_sync::CheckpointSyncError::AnchorPairingMismatch
},
)?
}
None => Store::from_anchor_state(
backend,
State::from_genesis(genesis.genesis_time, validators),
),
});
};

// Checkpoint sync path: try URLs in order, fail over to the next on error.
Expand Down
Loading