From 5f2d29734d86c1fce4e92d4be811f48a79802f91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Thu, 26 Nov 2026 19:10:40 -0300 Subject: [PATCH] perf(pq): sign a proposal's envelope alongside its block A PQ proposal signed the block, published it, and only then signed the envelope, so the envelope waited a whole leanXMSS signature (about 0.3 s of a core, sometimes several times that) after the block: 0.78 s in pq-devnet-0's slot 23740, 0.12 s in slot 23748. The node hands back the block and its envelope together, so the envelope's message is known as soon as the block's. Both signatures now start once the block is recorded in slashing protection, each on its own core. The block is published as soon as its own signature is done, then the envelope. An envelope signed for a block that then fails costs only the slot's envelope leaf, which no other message can use. --- crates/validator/src/proposal.rs | 51 ++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/crates/validator/src/proposal.rs b/crates/validator/src/proposal.rs index 29ac8f270..4c0cbeaef 100644 --- a/crates/validator/src/proposal.rs +++ b/crates/validator/src/proposal.rs @@ -448,9 +448,11 @@ impl ProposalService { /// A proposal at a PQ slot: the RANDAO reveal is the proposer's VRF proof, /// the beacon node builds a self-built block and its envelope (ethlambda's /// `pq_blocks` endpoint), and both are signed with leanXMSS at the slot's - /// proposer and envelope leaves. The slashing protection record guards - /// the block's leaf (one block per slot), `crate::pq` the envelope's. An - /// envelope failure is logged, not the proposal's: the block is out. + /// proposer and envelope leaves, side by side, the block published as + /// soon as its own signature is done. The slashing protection record + /// guards the block's leaf (one block per slot), `crate::pq` the + /// envelope's. An envelope failure is logged, not the proposal's: the + /// block is out. async fn propose_pq( &self, slot: Slot, @@ -497,10 +499,36 @@ impl ProposalService { .await; refuse_unless_safe(slot, validator, "record", recorded)?; + // Both signatures start now, on their own cores: a leanXMSS signature + // costs about 0.3 s of a core and sometimes several times that (see + // `pq::sign_batch`), and the envelope's message is known as soon as + // the block is, so it need not wait for the block's signature or its + // publish. The block still goes out first, as soon as its own is done. + // An envelope signed for a block that then fails costs only the + // slot's envelope leaf, which no other message can use. let signing_root = self.context.block_signing_root(block_root, slot); let leaf = crate::pq::slot_leaf(slot, crate::pq::LEAF_OFFSET_BEACON_PROPOSER); - let signature = crate::pq::sign(&pubkey, leaf, signing_root) + let block_signing = + tokio::spawn(async move { crate::pq::sign(&pubkey, leaf, signing_root).await }); + let envelope = contents.execution_payload_envelope; + let domain = self.context.domain( + ethlambda_types::beacon::constants::DOMAIN_BEACON_BUILDER, + compute_epoch_at_slot(slot), + ); + let envelope_root = ethlambda_types::beacon::signing::compute_signing_root( + envelope.hash_tree_root(), + domain, + ); + let envelope_leaf = + crate::pq::slot_leaf(slot, crate::pq::LEAF_OFFSET_EXECUTION_PAYLOAD_ENVELOPE); + let envelope_signing = + tokio::spawn( + async move { crate::pq::sign(&pubkey, envelope_leaf, envelope_root).await }, + ); + + let signature = block_signing .await + .unwrap_or_else(|err| Err(crate::pq::PqSignError::Task(err.to_string()))) .map_err(pq_error)?; let signed = pq::SignedBeaconBlock { message: contents.block, @@ -519,19 +547,12 @@ impl ProposalService { crate::metrics::inc_blocks_proposed(); self.observe_publication_delay(slot); - let envelope = contents.execution_payload_envelope; - let domain = self.context.domain( - ethlambda_types::beacon::constants::DOMAIN_BEACON_BUILDER, - compute_epoch_at_slot(slot), - ); - let envelope_root = ethlambda_types::beacon::signing::compute_signing_root( - envelope.hash_tree_root(), - domain, - ); - let leaf = crate::pq::slot_leaf(slot, crate::pq::LEAF_OFFSET_EXECUTION_PAYLOAD_ENVELOPE); // Logged and counted rather than propagated, as for gloas: the block // is out and the proposal did happen. - match crate::pq::sign(&pubkey, leaf, envelope_root).await { + let envelope_signature = envelope_signing + .await + .unwrap_or_else(|err| Err(crate::pq::PqSignError::Task(err.to_string()))); + match envelope_signature { Ok(signature) => { let signed = pq::SignedExecutionPayloadEnvelope { message: envelope,