From ce6c980b7e597904631d6a838ef9c76093f3a84c Mon Sep 17 00:00:00 2001 From: Marco Granelli Date: Thu, 9 Oct 2025 10:07:33 +0200 Subject: [PATCH 1/3] Updates events fetching for CometBFT v0.38 --- shared/src/block_result.rs | 17 ++++++++--------- transactions/src/services/tx.rs | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/shared/src/block_result.rs b/shared/src/block_result.rs index 80290ebb..ca2aa895 100644 --- a/shared/src/block_result.rs +++ b/shared/src/block_result.rs @@ -54,7 +54,7 @@ impl From<&String> for EventKind { pub struct BlockResult { pub height: u64, pub begin_events: Vec, - pub end_events: Vec, + pub finalize_events: Vec, } #[derive(Debug, Clone)] @@ -433,9 +433,8 @@ impl From for BlockResult { Event { kind, attributes } }) .collect::>(); - let end_events = value - .end_block_events - .unwrap_or_default() + let finalize_events = value + .finalize_block_events .iter() .map(|event| { let kind = EventKind::from(&event.kind); @@ -457,7 +456,7 @@ impl From for BlockResult { Self { height: value.height.value(), begin_events, - end_events, + finalize_events, } } } @@ -471,7 +470,7 @@ impl From<&TendermintBlockResultResponse> for BlockResult { impl BlockResult { pub fn is_wrapper_tx_applied(&self, tx_hash: &Id) -> TransactionExitStatus { let exit_status = self - .end_events + .finalize_events .iter() .filter_map(|event| { if let Some(TxAttributesType::TxApplied(data)) = @@ -490,7 +489,7 @@ impl BlockResult { } pub fn gas_used(&self, tx_hash: &Id) -> Option { - self.end_events + self.finalize_events .iter() .filter_map(|event| { if let Some(TxAttributesType::TxApplied(data)) = @@ -511,7 +510,7 @@ impl BlockResult { inner_hash: &Id, ) -> TransactionExitStatus { let exit_status = self - .end_events + .finalize_events .iter() .filter_map(|event| { if let Some(TxAttributesType::TxApplied(data)) = @@ -532,7 +531,7 @@ impl BlockResult { } pub fn masp_ref(&self, indexed_tx: &IndexedTx) -> Option<(MaspRef, bool)> { - self.end_events + self.finalize_events .iter() .find_map(|event| match event.kind { EventKind::MaspFeePayment => { diff --git a/transactions/src/services/tx.rs b/transactions/src/services/tx.rs index 51b79d5a..7cacd96d 100644 --- a/transactions/src/services/tx.rs +++ b/transactions/src/services/tx.rs @@ -12,7 +12,7 @@ use shared::transaction::{ pub fn get_ibc_token_flows( block_results: &BlockResult, ) -> impl Iterator + use<'_> { - block_results.end_events.iter().filter_map(|event| { + block_results.finalize_events.iter().filter_map(|event| { let (action, original_packet, fungible_token_packet) = event.attributes.as_ref()?.as_fungible_token_packet()?; @@ -59,7 +59,7 @@ pub fn get_ibc_packets( ); block_results - .end_events + .finalize_events .iter() .filter_map(|event| { if let Some(attributes) = &event.attributes { From d7320c4e6db75cccc745d1a78367afc0633c55cc Mon Sep 17 00:00:00 2001 From: Marco Granelli Date: Thu, 9 Oct 2025 13:22:01 +0200 Subject: [PATCH 2/3] Changes end events fetching to be backward-compatible --- shared/src/block_result.rs | 73 +++++++++++++++------------------ transactions/src/services/tx.rs | 4 +- 2 files changed, 35 insertions(+), 42 deletions(-) diff --git a/shared/src/block_result.rs b/shared/src/block_result.rs index ca2aa895..8c1f3417 100644 --- a/shared/src/block_result.rs +++ b/shared/src/block_result.rs @@ -54,7 +54,7 @@ impl From<&String> for EventKind { pub struct BlockResult { pub height: u64, pub begin_events: Vec, - pub finalize_events: Vec, + pub end_events: Vec, } #[derive(Debug, Clone)] @@ -412,51 +412,44 @@ impl TxAttributesType { impl From for BlockResult { fn from(value: TendermintBlockResultResponse) -> Self { + fn cast_event(event: &tendermint::abci::Event) -> Event { + let kind = EventKind::from(&event.kind); + let raw_attributes = event.attributes.iter().fold( + BTreeMap::default(), + |mut acc, attribute| { + acc.insert( + String::from(attribute.key_str().unwrap()), + String::from(attribute.value_str().unwrap()), + ); + acc + }, + ); + let attributes = + TxAttributesType::deserialize(&kind, &raw_attributes); + Event { kind, attributes } + } + let begin_events = value .begin_block_events .unwrap_or_default() .iter() - .map(|event| { - let kind = EventKind::from(&event.kind); - let raw_attributes = event.attributes.iter().fold( - BTreeMap::default(), - |mut acc, attribute| { - acc.insert( - String::from(attribute.key_str().unwrap()), - String::from(attribute.value_str().unwrap()), - ); - acc - }, - ); - let attributes = - TxAttributesType::deserialize(&kind, &raw_attributes); - Event { kind, attributes } - }) + .map(cast_event) .collect::>(); - let finalize_events = value - .finalize_block_events + // NOTE: starting with comet v0.38, end events are only avialable from + // the `finalize_block_events` field. For backward-compatibility + // reasons we still evaluate the `end_block_events` field as + // well and merge the two outputs + let end_events = value + .end_block_events + .unwrap_or_default() .iter() - .map(|event| { - let kind = EventKind::from(&event.kind); - let raw_attributes = event.attributes.iter().fold( - BTreeMap::default(), - |mut acc, attribute| { - acc.insert( - String::from(attribute.key_str().unwrap()), - String::from(attribute.value_str().unwrap()), - ); - acc - }, - ); - let attributes = - TxAttributesType::deserialize(&kind, &raw_attributes); - Event { kind, attributes } - }) + .map(cast_event) + .chain(value.finalize_block_events.iter().map(cast_event)) .collect::>(); Self { height: value.height.value(), begin_events, - finalize_events, + end_events, } } } @@ -470,7 +463,7 @@ impl From<&TendermintBlockResultResponse> for BlockResult { impl BlockResult { pub fn is_wrapper_tx_applied(&self, tx_hash: &Id) -> TransactionExitStatus { let exit_status = self - .finalize_events + .end_events .iter() .filter_map(|event| { if let Some(TxAttributesType::TxApplied(data)) = @@ -489,7 +482,7 @@ impl BlockResult { } pub fn gas_used(&self, tx_hash: &Id) -> Option { - self.finalize_events + self.end_events .iter() .filter_map(|event| { if let Some(TxAttributesType::TxApplied(data)) = @@ -510,7 +503,7 @@ impl BlockResult { inner_hash: &Id, ) -> TransactionExitStatus { let exit_status = self - .finalize_events + .end_events .iter() .filter_map(|event| { if let Some(TxAttributesType::TxApplied(data)) = @@ -531,7 +524,7 @@ impl BlockResult { } pub fn masp_ref(&self, indexed_tx: &IndexedTx) -> Option<(MaspRef, bool)> { - self.finalize_events + self.end_events .iter() .find_map(|event| match event.kind { EventKind::MaspFeePayment => { diff --git a/transactions/src/services/tx.rs b/transactions/src/services/tx.rs index 7cacd96d..51b79d5a 100644 --- a/transactions/src/services/tx.rs +++ b/transactions/src/services/tx.rs @@ -12,7 +12,7 @@ use shared::transaction::{ pub fn get_ibc_token_flows( block_results: &BlockResult, ) -> impl Iterator + use<'_> { - block_results.finalize_events.iter().filter_map(|event| { + block_results.end_events.iter().filter_map(|event| { let (action, original_packet, fungible_token_packet) = event.attributes.as_ref()?.as_fungible_token_packet()?; @@ -59,7 +59,7 @@ pub fn get_ibc_packets( ); block_results - .finalize_events + .end_events .iter() .filter_map(|event| { if let Some(attributes) = &event.attributes { From 6ed51cfdca04b01127c24cd12cefb9c4e120c2bd Mon Sep 17 00:00:00 2001 From: Marco Granelli Date: Thu, 9 Oct 2025 13:26:37 +0200 Subject: [PATCH 3/3] Fixes typo --- shared/src/block_result.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shared/src/block_result.rs b/shared/src/block_result.rs index 8c1f3417..5f79ea6d 100644 --- a/shared/src/block_result.rs +++ b/shared/src/block_result.rs @@ -435,10 +435,10 @@ impl From for BlockResult { .iter() .map(cast_event) .collect::>(); - // NOTE: starting with comet v0.38, end events are only avialable from + // NOTE: starting with comet v0.38, end events are only available from // the `finalize_block_events` field. For backward-compatibility - // reasons we still evaluate the `end_block_events` field as - // well and merge the two outputs + // reasons we still evaluate `end_block_events` as well and merge the + // two outputs let end_events = value .end_block_events .unwrap_or_default()