Add block_gossip Beacon API events (#5864)

* Add bls event

* Update events and types

* Add bls in event

* Event bls

* tests..rs

* change order

* another tests.rs

* Signed BLS

* Revert "another tests.rs"

This reverts commit 7f54e9c1ce.

* Revert "Signed BLS"

This reverts commit 1146bc734b.

* withdrawal_keyparis

* Fix genesis

* block gossip

* Add definition for BlockGossip

* Fix block gossip

* Tests.rs

* Update block and events

* Add bls event

* Event bls

* tests..rs

* change order

* another tests.rs

* Signed BLS

* Revert "another tests.rs"

This reverts commit 7f54e9c1ce.

* Revert "Signed BLS"

This reverts commit 1146bc734b.

* block gossip

* Add definition for BlockGossip

* Fix block gossip

* Tests.rs

* Update block and events

* Merge branch 'BeaconAPI-events-block-gossip' of https://github.com/chong-he/lighthouse into BeaconAPI-events-block-gossip

* Remove tests

* Tests.rs

* Tests.rs

* Tests.rs

* Tests similar to block event

* Update common/eth2/src/types.rs

Co-authored-by: Michael Sproul <micsproul@gmail.com>

* Merge remote-tracking branch 'origin/unstable' into BeaconAPI-events-block-gossip

* Fix tests
This commit is contained in:
chonghe
2024-07-16 12:39:55 +08:00
committed by GitHub
parent 6856134ded
commit 79680c886d
5 changed files with 55 additions and 3 deletions

View File

@@ -971,6 +971,11 @@ pub struct SseHead {
pub execution_optimistic: bool,
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct BlockGossip {
pub slot: Slot,
pub block: Hash256,
}
#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
pub struct SseChainReorg {
pub slot: Slot,
@@ -1100,6 +1105,7 @@ pub enum EventKind<E: EthSpec> {
ProposerSlashing(Box<ProposerSlashing>),
AttesterSlashing(Box<AttesterSlashing<E>>),
BlsToExecutionChange(Box<SignedBlsToExecutionChange>),
BlockGossip(Box<BlockGossip>),
}
impl<E: EthSpec> EventKind<E> {
@@ -1122,6 +1128,7 @@ impl<E: EthSpec> EventKind<E> {
EventKind::ProposerSlashing(_) => "proposer_slashing",
EventKind::AttesterSlashing(_) => "attester_slashing",
EventKind::BlsToExecutionChange(_) => "bls_to_execution_change",
EventKind::BlockGossip(_) => "block_gossip",
}
}
@@ -1217,6 +1224,9 @@ impl<E: EthSpec> EventKind<E> {
ServerError::InvalidServerSentEvent(format!("Bls To Execution Change: {:?}", e))
})?,
)),
"block_gossip" => Ok(EventKind::BlockGossip(serde_json::from_str(data).map_err(
|e| ServerError::InvalidServerSentEvent(format!("Block Gossip: {:?}", e)),
)?)),
_ => Err(ServerError::InvalidServerSentEvent(
"Could not parse event tag".to_string(),
)),
@@ -1251,6 +1261,7 @@ pub enum EventTopic {
AttesterSlashing,
ProposerSlashing,
BlsToExecutionChange,
BlockGossip,
}
impl FromStr for EventTopic {
@@ -1275,6 +1286,7 @@ impl FromStr for EventTopic {
"attester_slashing" => Ok(EventTopic::AttesterSlashing),
"proposer_slashing" => Ok(EventTopic::ProposerSlashing),
"bls_to_execution_change" => Ok(EventTopic::BlsToExecutionChange),
"block_gossip" => Ok(EventTopic::BlockGossip),
_ => Err("event topic cannot be parsed.".to_string()),
}
}
@@ -1300,6 +1312,7 @@ impl fmt::Display for EventTopic {
EventTopic::AttesterSlashing => write!(f, "attester_slashing"),
EventTopic::ProposerSlashing => write!(f, "proposer_slashing"),
EventTopic::BlsToExecutionChange => write!(f, "bls_to_execution_change"),
EventTopic::BlockGossip => write!(f, "block_gossip"),
}
}
}