Update events and types

This commit is contained in:
chonghe
2024-05-16 10:43:20 +08:00
parent ab9951481e
commit fa1aebe4ce
2 changed files with 17 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ pub struct ServerSentEventHandler<E: EthSpec> {
block_reward_tx: Sender<EventKind<E>>, block_reward_tx: Sender<EventKind<E>>,
proposer_slashing_tx: Sender<EventKind<E>>, proposer_slashing_tx: Sender<EventKind<E>>,
attester_slashing_tx: Sender<EventKind<E>>, attester_slashing_tx: Sender<EventKind<E>>,
bls_to_execution_change_tx: Sender<EventKind<E>>,
log: Logger, log: Logger,
} }
@@ -49,6 +50,7 @@ impl<E: EthSpec> ServerSentEventHandler<E> {
let (block_reward_tx, _) = broadcast::channel(capacity); let (block_reward_tx, _) = broadcast::channel(capacity);
let (proposer_slashing_tx, _) = broadcast::channel(capacity); let (proposer_slashing_tx, _) = broadcast::channel(capacity);
let (attester_slashing_tx, _) = broadcast::channel(capacity); let (attester_slashing_tx, _) = broadcast::channel(capacity);
let (bls_to_execution_change_tx, _) = broadcast::channel(capacity);
Self { Self {
attestation_tx, attestation_tx,
@@ -66,6 +68,7 @@ impl<E: EthSpec> ServerSentEventHandler<E> {
block_reward_tx, block_reward_tx,
proposer_slashing_tx, proposer_slashing_tx,
attester_slashing_tx, attester_slashing_tx,
bls_to_execution_change_tx,
log, log,
} }
} }
@@ -140,6 +143,10 @@ impl<E: EthSpec> ServerSentEventHandler<E> {
.attester_slashing_tx .attester_slashing_tx
.send(kind) .send(kind)
.map(|count| log_count("attester slashing", count)), .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 { if let Err(SendError(event)) = result {
trace!(self.log, "No receivers registered to listen for event"; "event" => ?event); trace!(self.log, "No receivers registered to listen for event"; "event" => ?event);

View File

@@ -1082,6 +1082,7 @@ pub enum EventKind<E: EthSpec> {
PayloadAttributes(VersionedSsePayloadAttributes), PayloadAttributes(VersionedSsePayloadAttributes),
ProposerSlashing(Box<ProposerSlashing>), ProposerSlashing(Box<ProposerSlashing>),
AttesterSlashing(Box<AttesterSlashing<E>>), AttesterSlashing(Box<AttesterSlashing<E>>),
BlsToExecutionChange(Box<BlsToExecutionChange>),
} }
impl<E: EthSpec> EventKind<E> { impl<E: EthSpec> EventKind<E> {
@@ -1103,6 +1104,7 @@ impl<E: EthSpec> EventKind<E> {
EventKind::BlockReward(_) => "block_reward", EventKind::BlockReward(_) => "block_reward",
EventKind::ProposerSlashing(_) => "proposer_slashing", EventKind::ProposerSlashing(_) => "proposer_slashing",
EventKind::AttesterSlashing(_) => "attester_slashing", EventKind::AttesterSlashing(_) => "attester_slashing",
EventKind::BlsToExecutionChange(_) => "bls_to_execution_change",
} }
} }
@@ -1193,6 +1195,11 @@ impl<E: EthSpec> EventKind<E> {
ServerError::InvalidServerSentEvent(format!("Proposer Slashing: {:?}", e)) 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( _ => Err(ServerError::InvalidServerSentEvent(
"Could not parse event tag".to_string(), "Could not parse event tag".to_string(),
)), )),
@@ -1226,6 +1233,7 @@ pub enum EventTopic {
BlockReward, BlockReward,
AttesterSlashing, AttesterSlashing,
ProposerSlashing, ProposerSlashing,
BlsToExecutionChange,
} }
impl FromStr for EventTopic { impl FromStr for EventTopic {
@@ -1249,6 +1257,7 @@ impl FromStr for EventTopic {
"block_reward" => Ok(EventTopic::BlockReward), "block_reward" => Ok(EventTopic::BlockReward),
"attester_slashing" => Ok(EventTopic::AttesterSlashing), "attester_slashing" => Ok(EventTopic::AttesterSlashing),
"proposer_slashing" => Ok(EventTopic::ProposerSlashing), "proposer_slashing" => Ok(EventTopic::ProposerSlashing),
"bls_to_execution_change" => Ok(EventTopic::BlsToExecutionChange),
_ => Err("event topic cannot be parsed.".to_string()), _ => Err("event topic cannot be parsed.".to_string()),
} }
} }
@@ -1273,6 +1282,7 @@ impl fmt::Display for EventTopic {
EventTopic::BlockReward => write!(f, "block_reward"), EventTopic::BlockReward => write!(f, "block_reward"),
EventTopic::AttesterSlashing => write!(f, "attester_slashing"), EventTopic::AttesterSlashing => write!(f, "attester_slashing"),
EventTopic::ProposerSlashing => write!(f, "proposer_slashing"), EventTopic::ProposerSlashing => write!(f, "proposer_slashing"),
EventTopic::BlsToExecutionChange => write!(f, "bls_to_execution_change"),
} }
} }
} }