From 4f58c555a92ce38208a103c4b66c175ff98183a0 Mon Sep 17 00:00:00 2001 From: Peter Davies Date: Fri, 15 Jul 2022 14:16:00 +0000 Subject: [PATCH] Add Merge support to web3signer validators (#3318) ## Issue Addressed Web3signer validators can't produce post-Bellatrix blocks. ## Proposed Changes Add support for Bellatrix to web3signer validators. ## Additional Info I am running validators with this code on Ropsten, but it may be a while for them to get a proposal. --- testing/web3signer_tests/src/lib.rs | 37 +++++++++++++++++++ .../src/signing_method/web3signer.rs | 30 +++++++++++---- 2 files changed, 59 insertions(+), 8 deletions(-) diff --git a/testing/web3signer_tests/src/lib.rs b/testing/web3signer_tests/src/lib.rs index 5803f360a..eb307290c 100644 --- a/testing/web3signer_tests/src/lib.rs +++ b/testing/web3signer_tests/src/lib.rs @@ -612,6 +612,28 @@ mod tests { .await; } + /// Test all the Merge types. + async fn test_merge_types(network: &str, listen_port: u16) { + let network_config = Eth2NetworkConfig::constant(network).unwrap().unwrap(); + let spec = &network_config.chain_spec::().unwrap(); + let merge_fork_slot = spec + .bellatrix_fork_epoch + .unwrap() + .start_slot(E::slots_per_epoch()); + + TestingRig::new(network, spec.clone(), listen_port) + .await + .assert_signatures_match("beacon_block_merge", |pubkey, validator_store| async move { + let mut merge_block = BeaconBlockMerge::empty(spec); + merge_block.slot = merge_fork_slot; + validator_store + .sign_block(pubkey, BeaconBlock::Merge(merge_block), merge_fork_slot) + .await + .unwrap() + }) + .await; + } + #[tokio::test] async fn mainnet_base_types() { test_base_types("mainnet", 4242).await @@ -631,4 +653,19 @@ mod tests { async fn prater_altair_types() { test_altair_types("prater", 4247).await } + + #[tokio::test] + async fn ropsten_base_types() { + test_base_types("ropsten", 4250).await + } + + #[tokio::test] + async fn ropsten_altair_types() { + test_altair_types("ropsten", 4251).await + } + + #[tokio::test] + async fn ropsten_merge_types() { + test_merge_types("ropsten", 4252).await + } } diff --git a/validator_client/src/signing_method/web3signer.rs b/validator_client/src/signing_method/web3signer.rs index 0ab37484b..cf02ae0c3 100644 --- a/validator_client/src/signing_method/web3signer.rs +++ b/validator_client/src/signing_method/web3signer.rs @@ -25,6 +25,7 @@ pub enum MessageType { pub enum ForkName { Phase0, Altair, + Bellatrix, } #[derive(Debug, PartialEq, Serialize)] @@ -43,7 +44,10 @@ pub enum Web3SignerObject<'a, T: EthSpec, Payload: ExecPayload> { Attestation(&'a AttestationData), BeaconBlock { version: ForkName, - block: &'a BeaconBlock, + #[serde(skip_serializing_if = "Option::is_none")] + block: Option<&'a BeaconBlock>, + #[serde(skip_serializing_if = "Option::is_none")] + block_header: Option, }, #[allow(dead_code)] Deposit { @@ -70,13 +74,23 @@ pub enum Web3SignerObject<'a, T: EthSpec, Payload: ExecPayload> { impl<'a, T: EthSpec, Payload: ExecPayload> Web3SignerObject<'a, T, Payload> { pub fn beacon_block(block: &'a BeaconBlock) -> Result { - let version = match block { - BeaconBlock::Base(_) => ForkName::Phase0, - BeaconBlock::Altair(_) => ForkName::Altair, - BeaconBlock::Merge(_) => return Err(Error::MergeForkNotSupported), - }; - - Ok(Web3SignerObject::BeaconBlock { version, block }) + match block { + BeaconBlock::Base(_) => Ok(Web3SignerObject::BeaconBlock { + version: ForkName::Phase0, + block: Some(block), + block_header: None, + }), + BeaconBlock::Altair(_) => Ok(Web3SignerObject::BeaconBlock { + version: ForkName::Altair, + block: Some(block), + block_header: None, + }), + BeaconBlock::Merge(_) => Ok(Web3SignerObject::BeaconBlock { + version: ForkName::Bellatrix, + block: None, + block_header: Some(block.block_header()), + }), + } } pub fn message_type(&self) -> MessageType {