From ab9951481ef6c1849cb8ff4653ad0086957f96c9 Mon Sep 17 00:00:00 2001 From: chonghe Date: Wed, 15 May 2024 08:22:58 +0800 Subject: [PATCH 01/12] Add bls event --- beacon_node/beacon_chain/src/beacon_chain.rs | 8 ++++++++ beacon_node/http_api/src/lib.rs | 3 +++ 2 files changed, 11 insertions(+) diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index 8eeb75fd7d7..2e41fd3f5ad 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -2515,6 +2515,14 @@ impl BeaconChain { .observed_bls_to_execution_changes .lock() .verify_and_observe(bls_to_execution_change, head_state, &self.spec)?) + + if let Some(event_handler) = self.event_handler.as_ref() { + if event_handler.has_bls_to_execution_change_subscribers() { + event_handler.register(EventKind::BlsToExecutionChange(Box::new( + Blt_To_Execution_Change.clone().into_inner(), + ))); + } + } } /// Verify a signed BLS to execution change before allowing it to propagate on the gossip network. diff --git a/beacon_node/http_api/src/lib.rs b/beacon_node/http_api/src/lib.rs index 024e268e2a5..fe2a54d71fa 100644 --- a/beacon_node/http_api/src/lib.rs +++ b/beacon_node/http_api/src/lib.rs @@ -4364,6 +4364,9 @@ pub fn serve( api_types::EventTopic::ProposerSlashing => { event_handler.subscribe_proposer_slashing() } + api_types::EventTopic::BlsToExecutionChange => { + event_handler.subscribe_bls_to_execution_change() + } }; receivers.push( From fa1aebe4ce307e6073c7b0af1fd1fae16e803e5f Mon Sep 17 00:00:00 2001 From: chonghe Date: Thu, 16 May 2024 10:43:20 +0800 Subject: [PATCH 02/12] Update events and types --- beacon_node/beacon_chain/src/events.rs | 7 +++++++ common/eth2/src/types.rs | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/beacon_node/beacon_chain/src/events.rs b/beacon_node/beacon_chain/src/events.rs index 8700675a66e..077388b86c3 100644 --- a/beacon_node/beacon_chain/src/events.rs +++ b/beacon_node/beacon_chain/src/events.rs @@ -22,6 +22,7 @@ pub struct ServerSentEventHandler { block_reward_tx: Sender>, proposer_slashing_tx: Sender>, attester_slashing_tx: Sender>, + bls_to_execution_change_tx: Sender>, log: Logger, } @@ -49,6 +50,7 @@ impl ServerSentEventHandler { let (block_reward_tx, _) = broadcast::channel(capacity); let (proposer_slashing_tx, _) = broadcast::channel(capacity); let (attester_slashing_tx, _) = broadcast::channel(capacity); + let (bls_to_execution_change_tx, _) = broadcast::channel(capacity); Self { attestation_tx, @@ -66,6 +68,7 @@ impl ServerSentEventHandler { block_reward_tx, proposer_slashing_tx, attester_slashing_tx, + bls_to_execution_change_tx, log, } } @@ -140,6 +143,10 @@ impl ServerSentEventHandler { .attester_slashing_tx .send(kind) .map(|count| log_count("attester slashing", count)), + EventKind::BlsToExecutionChange(_) => self + .bls_to_execution_change_tx + .send(kind) + .map(|count| log_count("bls to execution change", count)), }; if let Err(SendError(event)) = result { trace!(self.log, "No receivers registered to listen for event"; "event" => ?event); diff --git a/common/eth2/src/types.rs b/common/eth2/src/types.rs index b15246e7fdb..5b62177c0f4 100644 --- a/common/eth2/src/types.rs +++ b/common/eth2/src/types.rs @@ -1082,6 +1082,7 @@ pub enum EventKind { PayloadAttributes(VersionedSsePayloadAttributes), ProposerSlashing(Box), AttesterSlashing(Box>), + BlsToExecutionChange(Box), } impl EventKind { @@ -1103,6 +1104,7 @@ impl EventKind { EventKind::BlockReward(_) => "block_reward", EventKind::ProposerSlashing(_) => "proposer_slashing", EventKind::AttesterSlashing(_) => "attester_slashing", + EventKind::BlsToExecutionChange(_) => "bls_to_execution_change", } } @@ -1193,6 +1195,11 @@ impl EventKind { ServerError::InvalidServerSentEvent(format!("Proposer Slashing: {:?}", e)) })?, )), + "bls_to_execution_change" => Ok(EventKind::BlsToExecutionChange( + serde_json::from_str(data).map_err(|e| { + ServerError::InvalidServerSentEvent(format!("Bls To Execution Change: {:?}", e)) + })?, + )), _ => Err(ServerError::InvalidServerSentEvent( "Could not parse event tag".to_string(), )), @@ -1226,6 +1233,7 @@ pub enum EventTopic { BlockReward, AttesterSlashing, ProposerSlashing, + BlsToExecutionChange, } impl FromStr for EventTopic { @@ -1249,6 +1257,7 @@ impl FromStr for EventTopic { "block_reward" => Ok(EventTopic::BlockReward), "attester_slashing" => Ok(EventTopic::AttesterSlashing), "proposer_slashing" => Ok(EventTopic::ProposerSlashing), + "bls_to_execution_change" => Ok(EventTopic::BlsToExecutionChange), _ => Err("event topic cannot be parsed.".to_string()), } } @@ -1273,6 +1282,7 @@ impl fmt::Display for EventTopic { EventTopic::BlockReward => write!(f, "block_reward"), EventTopic::AttesterSlashing => write!(f, "attester_slashing"), EventTopic::ProposerSlashing => write!(f, "proposer_slashing"), + EventTopic::BlsToExecutionChange => write!(f, "bls_to_execution_change"), } } } From ecd82f302cd7d4b76b67d4cf1e63af046af50822 Mon Sep 17 00:00:00 2001 From: Tan Chee Keong Date: Wed, 22 May 2024 11:54:47 +0800 Subject: [PATCH 03/12] Add bls in event --- beacon_node/beacon_chain/src/events.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/beacon_node/beacon_chain/src/events.rs b/beacon_node/beacon_chain/src/events.rs index 077388b86c3..5f91fe5d0c9 100644 --- a/beacon_node/beacon_chain/src/events.rs +++ b/beacon_node/beacon_chain/src/events.rs @@ -213,6 +213,10 @@ impl ServerSentEventHandler { self.proposer_slashing_tx.subscribe() } + pub fn subscribe_bls_to_execution_change(&self) -> Receiver> { + self.bls_to_execution_change_tx.subscribe() + } + pub fn has_attestation_subscribers(&self) -> bool { self.attestation_tx.receiver_count() > 0 } @@ -264,4 +268,8 @@ impl ServerSentEventHandler { pub fn has_attester_slashing_subscribers(&self) -> bool { self.attester_slashing_tx.receiver_count() > 0 } + + pub fn has_bls_to_execution_change_subscribers(&self) -> bool { + self.bls_to_execution_change_tx.receiver_count() > 0 + } } From b5adaa55726670146a37cbe1f57e297b2245472d Mon Sep 17 00:00:00 2001 From: Tan Chee Keong Date: Wed, 22 May 2024 20:53:53 +0800 Subject: [PATCH 04/12] Event bls --- beacon_node/beacon_chain/src/beacon_chain.rs | 16 ++++++++-------- common/eth2/src/types.rs | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index 2e41fd3f5ad..0e5d3255735 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -2515,14 +2515,6 @@ impl BeaconChain { .observed_bls_to_execution_changes .lock() .verify_and_observe(bls_to_execution_change, head_state, &self.spec)?) - - if let Some(event_handler) = self.event_handler.as_ref() { - if event_handler.has_bls_to_execution_change_subscribers() { - event_handler.register(EventKind::BlsToExecutionChange(Box::new( - Blt_To_Execution_Change.clone().into_inner(), - ))); - } - } } /// Verify a signed BLS to execution change before allowing it to propagate on the gossip network. @@ -2562,6 +2554,14 @@ impl BeaconChain { bls_to_execution_change: SigVerifiedOp, received_pre_capella: ReceivedPreCapella, ) -> bool { + if let Some(event_handler) = self.event_handler.as_ref() { + if event_handler.has_bls_to_execution_change_subscribers() { + event_handler.register(EventKind::BlsToExecutionChange(Box::new( + bls_to_execution_change.clone().into_inner(), + ))); + } + } + if self.eth1_chain.is_some() { self.op_pool .insert_bls_to_execution_change(bls_to_execution_change, received_pre_capella) diff --git a/common/eth2/src/types.rs b/common/eth2/src/types.rs index 5b62177c0f4..2bb749af9f6 100644 --- a/common/eth2/src/types.rs +++ b/common/eth2/src/types.rs @@ -1082,7 +1082,7 @@ pub enum EventKind { PayloadAttributes(VersionedSsePayloadAttributes), ProposerSlashing(Box), AttesterSlashing(Box>), - BlsToExecutionChange(Box), + BlsToExecutionChange(Box), } impl EventKind { From 71cde606b85a0183e936061e0a88348b93193925 Mon Sep 17 00:00:00 2001 From: Tan Chee Keong Date: Thu, 23 May 2024 18:07:45 +0800 Subject: [PATCH 05/12] tests..rs --- beacon_node/http_api/tests/tests.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/beacon_node/http_api/tests/tests.rs b/beacon_node/http_api/tests/tests.rs index ace54714b26..49646478f05 100644 --- a/beacon_node/http_api/tests/tests.rs +++ b/beacon_node/http_api/tests/tests.rs @@ -70,6 +70,7 @@ struct ApiTester { attester_slashing: AttesterSlashing, proposer_slashing: ProposerSlashing, voluntary_exit: SignedVoluntaryExit, + bls_to_execution_change: SignedBlsToExecutionChange, network_rx: NetworkReceivers, local_enr: Enr, external_peer_id: PeerId, @@ -223,6 +224,7 @@ impl ApiTester { let attester_slashing = harness.make_attester_slashing(vec![0, 1]); let proposer_slashing = harness.make_proposer_slashing(2); let voluntary_exit = harness.make_voluntary_exit(3, harness.chain.epoch().unwrap()); + let bls_to_execution_change = harness.make_bls_to_execution_change(4, Address::zero()); let chain = harness.chain.clone(); @@ -289,6 +291,7 @@ impl ApiTester { attester_slashing, proposer_slashing, voluntary_exit, + bls_to_execution_change, network_rx, local_enr, external_peer_id, @@ -336,6 +339,7 @@ impl ApiTester { let attester_slashing = harness.make_attester_slashing(vec![0, 1]); let proposer_slashing = harness.make_proposer_slashing(2); let voluntary_exit = harness.make_voluntary_exit(3, harness.chain.epoch().unwrap()); + let bls_to_execution_change = harness.make_bls_to_execution_change(4, Address::zero()); let chain = harness.chain.clone(); @@ -373,6 +377,7 @@ impl ApiTester { attester_slashing, proposer_slashing, voluntary_exit, + bls_to_execution_change, network_rx, local_enr, external_peer_id, @@ -5216,6 +5221,7 @@ impl ApiTester { EventTopic::FinalizedCheckpoint, EventTopic::AttesterSlashing, EventTopic::ProposerSlashing, + EventTopic::BlsToExecutionChange, ]; let mut events_future = self .client @@ -5246,6 +5252,20 @@ impl ApiTester { .as_slice() ); + // Produce a BLS to execution change event + self.client + .post_beacon_pool_bls_to_execution_changes(&[self.bls_to_execution_change.clone()]) + .await + .unwrap(); + + let bls_events = poll_events(&mut events_future, 1, Duration::from_millis(10000)).await; + assert_eq!( + bls_events.as_slice(), + &[EventKind::BlsToExecutionChange(Box::new( + self.bls_to_execution_change.clone() + ))] + ); + // Produce a voluntary exit event self.client .post_beacon_pool_voluntary_exits(&self.voluntary_exit) From 10ba9ca30d74c4feb7d88287b0e60f17ae0d1177 Mon Sep 17 00:00:00 2001 From: Tan Chee Keong Date: Sun, 26 May 2024 09:11:19 +0800 Subject: [PATCH 06/12] change order --- beacon_node/http_api/tests/tests.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/beacon_node/http_api/tests/tests.rs b/beacon_node/http_api/tests/tests.rs index 49646478f05..e85ecd5ef11 100644 --- a/beacon_node/http_api/tests/tests.rs +++ b/beacon_node/http_api/tests/tests.rs @@ -5252,30 +5252,30 @@ impl ApiTester { .as_slice() ); - // Produce a BLS to execution change event + // Produce a voluntary exit event self.client - .post_beacon_pool_bls_to_execution_changes(&[self.bls_to_execution_change.clone()]) + .post_beacon_pool_voluntary_exits(&self.voluntary_exit) .await .unwrap(); - let bls_events = poll_events(&mut events_future, 1, Duration::from_millis(10000)).await; + let exit_events = poll_events(&mut events_future, 1, Duration::from_millis(10000)).await; assert_eq!( - bls_events.as_slice(), - &[EventKind::BlsToExecutionChange(Box::new( - self.bls_to_execution_change.clone() - ))] + exit_events.as_slice(), + &[EventKind::VoluntaryExit(self.voluntary_exit.clone())] ); - // Produce a voluntary exit event + // Produce a BLS to execution change event self.client - .post_beacon_pool_voluntary_exits(&self.voluntary_exit) + .post_beacon_pool_bls_to_execution_changes(&[self.bls_to_execution_change.clone()]) .await .unwrap(); - let exit_events = poll_events(&mut events_future, 1, Duration::from_millis(10000)).await; + let bls_events = poll_events(&mut events_future, 1, Duration::from_millis(10000)).await; assert_eq!( - exit_events.as_slice(), - &[EventKind::VoluntaryExit(self.voluntary_exit.clone())] + bls_events.as_slice(), + &[EventKind::BlsToExecutionChange(Box::new( + self.bls_to_execution_change.clone() + ))] ); // Submit the next block, which is on an epoch boundary, so this will produce a finalized From 7f54e9c1cea967e1fd6713fa7b11752c25d3b610 Mon Sep 17 00:00:00 2001 From: Tan Chee Keong Date: Mon, 27 May 2024 08:10:24 +0800 Subject: [PATCH 07/12] another tests.rs --- beacon_node/network/src/network_beacon_processor/tests.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/beacon_node/network/src/network_beacon_processor/tests.rs b/beacon_node/network/src/network_beacon_processor/tests.rs index 4ba4c4ddd1d..863d0d5f751 100644 --- a/beacon_node/network/src/network_beacon_processor/tests.rs +++ b/beacon_node/network/src/network_beacon_processor/tests.rs @@ -59,6 +59,7 @@ struct TestRig { attester_slashing: AttesterSlashing, proposer_slashing: ProposerSlashing, voluntary_exit: SignedVoluntaryExit, + bls_to_execution_change: SignedBlsToExecutionChange, beacon_processor_tx: BeaconProcessorSend, work_journal_rx: mpsc::Receiver<&'static str>, _network_rx: mpsc::UnboundedReceiver>, @@ -176,6 +177,7 @@ impl TestRig { let attester_slashing = harness.make_attester_slashing(vec![0, 1]); let proposer_slashing = harness.make_proposer_slashing(2); let voluntary_exit = harness.make_voluntary_exit(3, harness.chain.epoch().unwrap()); + let bls_to_execution_change = harness.make_bls_to_execution_change(4, Address::zero()); let chain = harness.chain.clone(); @@ -258,6 +260,7 @@ impl TestRig { attester_slashing, proposer_slashing, voluntary_exit, + bls_to_execution_change, beacon_processor_tx, work_journal_rx, _network_rx, From 1146bc734b3e8ed2067fb929d6b0a0b16b4154d3 Mon Sep 17 00:00:00 2001 From: Tan Chee Keong Date: Mon, 27 May 2024 08:27:45 +0800 Subject: [PATCH 08/12] Signed BLS --- beacon_node/network/src/network_beacon_processor/tests.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/beacon_node/network/src/network_beacon_processor/tests.rs b/beacon_node/network/src/network_beacon_processor/tests.rs index 863d0d5f751..13a2b078368 100644 --- a/beacon_node/network/src/network_beacon_processor/tests.rs +++ b/beacon_node/network/src/network_beacon_processor/tests.rs @@ -31,8 +31,8 @@ use tokio::sync::mpsc; use types::blob_sidecar::FixedBlobSidecarList; use types::{ Attestation, AttesterSlashing, BlobSidecar, BlobSidecarList, Epoch, Hash256, MainnetEthSpec, - ProposerSlashing, SignedAggregateAndProof, SignedBeaconBlock, SignedVoluntaryExit, Slot, - SubnetId, + ProposerSlashing, SignedAggregateAndProof, SignedBeaconBlock, SignedBlsToExecutionChange, + SignedVoluntaryExit, Slot, SubnetId, }; type E = MainnetEthSpec; From fc8351aa883d903425f2e5c4a084848b573eb665 Mon Sep 17 00:00:00 2001 From: Tan Chee Keong Date: Mon, 27 May 2024 19:16:31 +0800 Subject: [PATCH 09/12] Revert "another tests.rs" This reverts commit 7f54e9c1cea967e1fd6713fa7b11752c25d3b610. --- beacon_node/network/src/network_beacon_processor/tests.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/beacon_node/network/src/network_beacon_processor/tests.rs b/beacon_node/network/src/network_beacon_processor/tests.rs index 13a2b078368..158205fe55c 100644 --- a/beacon_node/network/src/network_beacon_processor/tests.rs +++ b/beacon_node/network/src/network_beacon_processor/tests.rs @@ -59,7 +59,6 @@ struct TestRig { attester_slashing: AttesterSlashing, proposer_slashing: ProposerSlashing, voluntary_exit: SignedVoluntaryExit, - bls_to_execution_change: SignedBlsToExecutionChange, beacon_processor_tx: BeaconProcessorSend, work_journal_rx: mpsc::Receiver<&'static str>, _network_rx: mpsc::UnboundedReceiver>, @@ -177,7 +176,6 @@ impl TestRig { let attester_slashing = harness.make_attester_slashing(vec![0, 1]); let proposer_slashing = harness.make_proposer_slashing(2); let voluntary_exit = harness.make_voluntary_exit(3, harness.chain.epoch().unwrap()); - let bls_to_execution_change = harness.make_bls_to_execution_change(4, Address::zero()); let chain = harness.chain.clone(); @@ -260,7 +258,6 @@ impl TestRig { attester_slashing, proposer_slashing, voluntary_exit, - bls_to_execution_change, beacon_processor_tx, work_journal_rx, _network_rx, From 9316cc5ab245d4a28694b3829eaa44291172deee Mon Sep 17 00:00:00 2001 From: Tan Chee Keong Date: Mon, 27 May 2024 19:33:24 +0800 Subject: [PATCH 10/12] Revert "Signed BLS" This reverts commit 1146bc734b3e8ed2067fb929d6b0a0b16b4154d3. --- beacon_node/network/src/network_beacon_processor/tests.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/beacon_node/network/src/network_beacon_processor/tests.rs b/beacon_node/network/src/network_beacon_processor/tests.rs index 158205fe55c..4ba4c4ddd1d 100644 --- a/beacon_node/network/src/network_beacon_processor/tests.rs +++ b/beacon_node/network/src/network_beacon_processor/tests.rs @@ -31,8 +31,8 @@ use tokio::sync::mpsc; use types::blob_sidecar::FixedBlobSidecarList; use types::{ Attestation, AttesterSlashing, BlobSidecar, BlobSidecarList, Epoch, Hash256, MainnetEthSpec, - ProposerSlashing, SignedAggregateAndProof, SignedBeaconBlock, SignedBlsToExecutionChange, - SignedVoluntaryExit, Slot, SubnetId, + ProposerSlashing, SignedAggregateAndProof, SignedBeaconBlock, SignedVoluntaryExit, Slot, + SubnetId, }; type E = MainnetEthSpec; From d6971b0612a5425762456a4595f0e1f624c73aec Mon Sep 17 00:00:00 2001 From: Tan Chee Keong Date: Mon, 27 May 2024 21:01:04 +0800 Subject: [PATCH 11/12] withdrawal_keyparis --- beacon_node/http_api/tests/tests.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/beacon_node/http_api/tests/tests.rs b/beacon_node/http_api/tests/tests.rs index e85ecd5ef11..c680acb2ba2 100644 --- a/beacon_node/http_api/tests/tests.rs +++ b/beacon_node/http_api/tests/tests.rs @@ -129,6 +129,7 @@ impl ApiTester { }) .logger(logging::test_logger()) .deterministic_keypairs(VALIDATOR_COUNT) + .deterministic_withdrawal_keypairs(VALIDATOR_COUNT) .fresh_ephemeral_store() .mock_execution_layer_with_config() .build(); From 34b102c9c1a9ede11d94c27247ab2d291bc15f05 Mon Sep 17 00:00:00 2001 From: Tan Chee Keong Date: Mon, 27 May 2024 21:47:23 +0800 Subject: [PATCH 12/12] Fix genesis --- beacon_node/http_api/tests/tests.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/beacon_node/http_api/tests/tests.rs b/beacon_node/http_api/tests/tests.rs index c680acb2ba2..2828b15a935 100644 --- a/beacon_node/http_api/tests/tests.rs +++ b/beacon_node/http_api/tests/tests.rs @@ -305,6 +305,7 @@ impl ApiTester { BeaconChainHarness::builder(MainnetEthSpec) .default_spec() .deterministic_keypairs(VALIDATOR_COUNT) + .deterministic_withdrawal_keypairs(VALIDATOR_COUNT) .fresh_ephemeral_store() .build(), );