From 28204b7c40bfe609f175a34d302affbc42a6d360 Mon Sep 17 00:00:00 2001 From: tompro Date: Tue, 28 Apr 2026 10:40:02 +0200 Subject: [PATCH] Make metadata sync safer --- .../src/handler/bill_chain_event_processor.rs | 18 +++++++------- .../handler/company_chain_event_processor.rs | 21 +++++++++------- .../handler/identity_chain_event_processor.rs | 24 ++++++++++--------- 3 files changed, 36 insertions(+), 27 deletions(-) diff --git a/crates/bcr-ebill-transport/src/handler/bill_chain_event_processor.rs b/crates/bcr-ebill-transport/src/handler/bill_chain_event_processor.rs index 81a852cd..8986cc80 100644 --- a/crates/bcr-ebill-transport/src/handler/bill_chain_event_processor.rs +++ b/crates/bcr-ebill-transport/src/handler/bill_chain_event_processor.rs @@ -133,14 +133,6 @@ impl BillChainEventProcessorApi for BillChainEventProcessor { ) .await { - if let Err(e) = self - .chain_event_store - .remove_chain_events(&bill_id.to_string(), BlockchainType::Bill) - .await - { - error!("Failed to invalidate old bill chain events during resync: {e}"); - } - for data in chain_data.iter() { let blocks: Vec = data .iter() @@ -208,6 +200,16 @@ impl BillChainEventProcessorApi for BillChainEventProcessor { return Err(e); } + if let Err(e) = self + .chain_event_store + .remove_chain_events(&bill_id.to_string(), BlockchainType::Bill) + .await + { + error!( + "Failed to invalidate old bill chain events during resync: {e}" + ); + } + for event_container in data.iter() { let event = event_container.as_chain_store_event( &bill_id.to_string(), diff --git a/crates/bcr-ebill-transport/src/handler/company_chain_event_processor.rs b/crates/bcr-ebill-transport/src/handler/company_chain_event_processor.rs index 0bbc180d..30ff380b 100644 --- a/crates/bcr-ebill-transport/src/handler/company_chain_event_processor.rs +++ b/crates/bcr-ebill-transport/src/handler/company_chain_event_processor.rs @@ -144,14 +144,6 @@ impl CompanyChainEventProcessorApi for CompanyChainEventProcessor { ) .await { - if let Err(e) = self - .chain_event_store - .remove_chain_events(&company_id.to_string(), BlockchainType::Company) - .await - { - error!("Failed to invalidate old company chain events during resync: {e}"); - } - for data in chain_data.iter() { let blocks: Vec = data .iter() @@ -219,6 +211,19 @@ impl CompanyChainEventProcessorApi for CompanyChainEventProcessor { return Err(e); } + if let Err(e) = self + .chain_event_store + .remove_chain_events( + &company_id.to_string(), + BlockchainType::Company, + ) + .await + { + error!( + "Failed to invalidate old company chain events during resync: {e}" + ); + } + for event_container in data.iter() { let event = event_container.as_chain_store_event( &company_id.to_string(), diff --git a/crates/bcr-ebill-transport/src/handler/identity_chain_event_processor.rs b/crates/bcr-ebill-transport/src/handler/identity_chain_event_processor.rs index acecf3b7..763df832 100644 --- a/crates/bcr-ebill-transport/src/handler/identity_chain_event_processor.rs +++ b/crates/bcr-ebill-transport/src/handler/identity_chain_event_processor.rs @@ -101,17 +101,6 @@ impl IdentityChainEventProcessorApi for IdentityChainEventProcessor { ) .await { - if let Err(e) = self - .chain_event_store - .remove_chain_events( - &identity.node_id.to_string(), - BlockchainType::Identity, - ) - .await - { - error!("Failed to invalidate old identity chain events during resync: {e}"); - } - for data in chain_data.iter() { let blocks: Vec = data .iter() @@ -167,6 +156,19 @@ impl IdentityChainEventProcessorApi for IdentityChainEventProcessor { return Err(e); } + if let Err(e) = self + .chain_event_store + .remove_chain_events( + &identity.node_id.to_string(), + BlockchainType::Identity, + ) + .await + { + error!( + "Failed to invalidate old identity chain events during resync: {e}" + ); + } + for event_container in data.iter() { let event = event_container.as_chain_store_event( &identity.node_id.to_string(),