Skip to content

Commit cc64f68

Browse files
authored
Block propagation service (#724)
* Extract propagation service * Rename to transport_service * All tests pass * transport_service tests * Notification transport tests * Review fixes
1 parent eb2676d commit cc64f68

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+4972
-4319
lines changed

crates/bcr-ebill-api/src/service/bill_service/blocks.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,8 @@ impl BillService {
523523
timestamp,
524524
)?;
525525
self.identity_blockchain_store.add_block(&new_block).await?;
526-
self.notification_service
526+
self.transport_service
527+
.block_transport()
527528
.send_identity_chain_events(IdentityChainEvent::new(
528529
&identity.identity,
529530
&new_block,
@@ -555,7 +556,8 @@ impl BillService {
555556
timestamp,
556557
)?;
557558
self.identity_blockchain_store.add_block(&new_block).await?;
558-
self.notification_service
559+
self.transport_service
560+
.block_transport()
559561
.send_identity_chain_events(IdentityChainEvent::new(
560562
&identity.identity,
561563
&new_block,
@@ -599,7 +601,8 @@ impl BillService {
599601

600602
let chain = self.company_blockchain_store.get_chain(company_id).await?;
601603
let company = self.company_store.get(company_id).await?;
602-
self.notification_service
604+
self.transport_service
605+
.block_transport()
603606
.send_company_chain_events(CompanyChainEvent::new(
604607
&company,
605608
&chain,

crates/bcr-ebill-api/src/service/bill_service/data_fetching.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,8 @@ impl BillService {
899899

900900
// fetch active notification
901901
let active_notification = self
902-
.notification_service
902+
.transport_service
903+
.notification_transport()
903904
.get_active_bill_notification(&bill.id)
904905
.await;
905906

crates/bcr-ebill-api/src/service/bill_service/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{external, service::notification_service};
1+
use crate::{external, service::transport_service};
22
use bcr_ebill_core::{blockchain, util::crypto};
33
use thiserror::Error;
44

@@ -26,7 +26,7 @@ pub enum Error {
2626
Cryptography(#[from] crypto::Error),
2727

2828
#[error("Notification error: {0}")]
29-
Notification(#[from] notification_service::Error),
29+
Notification(#[from] transport_service::Error),
3030

3131
#[error("Protocol error: {0}")]
3232
Protocol(#[from] bcr_ebill_core::protocol::ProtocolError),

crates/bcr-ebill-api/src/service/bill_service/issue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ impl BillService {
255255

256256
// send notification and blocks to all required recipients
257257
if let Err(e) = self
258-
.notification_service
258+
.transport_service
259259
.send_bill_is_signed_event(&BillChainEvent::new(
260260
&bill,
261261
&chain,

crates/bcr-ebill-api/src/service/bill_service/payment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl BillService {
105105
true,
106106
&identity.node_id, // TODO(company-notifications): how to handle jobs as company participant?
107107
)?;
108-
self.notification_service
108+
self.transport_service
109109
.send_bill_is_paid_event(&chain_event)
110110
.await?;
111111
Ok(())

crates/bcr-ebill-api/src/service/bill_service/propagation.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ impl BillService {
3535

3636
match bill_action {
3737
BillAction::Accept => {
38-
self.notification_service
38+
self.transport_service
3939
.send_bill_is_accepted_event(&chain_event)
4040
.await?;
4141
}
4242
BillAction::RequestAcceptance(_) => {
43-
self.notification_service
43+
self.transport_service
4444
.send_request_to_accept_event(&chain_event)
4545
.await?;
4646
}
4747
BillAction::RequestToPay(_, _) => {
48-
self.notification_service
48+
self.transport_service
4949
.send_request_to_pay_event(&chain_event)
5050
.await?;
5151
}
@@ -54,52 +54,52 @@ impl BillService {
5454
RecourseReason::Accept => ActionType::AcceptBill,
5555
RecourseReason::Pay(_) => ActionType::PayBill,
5656
};
57-
self.notification_service
57+
self.transport_service
5858
.send_recourse_action_event(&chain_event, action_type, recoursee)
5959
.await?;
6060
}
6161
BillAction::Recourse(recoursee, _, _) => {
62-
self.notification_service
62+
self.transport_service
6363
.send_bill_recourse_paid_event(&chain_event, recoursee)
6464
.await?;
6565
}
6666
BillAction::Mint(_, _) => {
67-
self.notification_service
67+
self.transport_service
6868
.send_bill_is_endorsed_event(&chain_event)
6969
.await?;
7070
}
7171
BillAction::OfferToSell(buyer, _, _) => {
72-
self.notification_service
72+
self.transport_service
7373
.send_offer_to_sell_event(&chain_event, buyer)
7474
.await?;
7575
}
7676
BillAction::Sell(buyer, _, _) => {
77-
self.notification_service
77+
self.transport_service
7878
.send_bill_is_sold_event(&chain_event, buyer)
7979
.await?;
8080
}
8181
BillAction::Endorse(_) => {
82-
self.notification_service
82+
self.transport_service
8383
.send_bill_is_endorsed_event(&chain_event)
8484
.await?;
8585
}
8686
BillAction::RejectAcceptance => {
87-
self.notification_service
87+
self.transport_service
8888
.send_request_to_action_rejected_event(&chain_event, ActionType::AcceptBill)
8989
.await?;
9090
}
9191
BillAction::RejectBuying => {
92-
self.notification_service
92+
self.transport_service
9393
.send_request_to_action_rejected_event(&chain_event, ActionType::BuyBill)
9494
.await?;
9595
}
9696
BillAction::RejectPayment => {
97-
self.notification_service
97+
self.transport_service
9898
.send_request_to_action_rejected_event(&chain_event, ActionType::PayBill)
9999
.await?;
100100
}
101101
BillAction::RejectPaymentForRecourse => {
102-
self.notification_service
102+
self.transport_service
103103
.send_request_to_action_rejected_event(&chain_event, ActionType::RecourseBill)
104104
.await?;
105105
}

crates/bcr-ebill-api/src/service/bill_service/service.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::external::file_storage::{self, FileStorageClientApi};
77
use crate::external::mint::{MintClientApi, QuoteStatusReply, ResolveMintOffer};
88
use crate::get_config;
99
use crate::service::file_upload_service::UploadFileType;
10-
use crate::service::notification_service::NotificationServiceApi;
10+
use crate::service::transport_service::TransportServiceApi;
1111
use crate::util::{validate_bill_id_network, validate_node_id_network};
1212
use async_trait::async_trait;
1313
use bcr_common::core::{BillId, NodeId};
@@ -63,7 +63,7 @@ pub struct BillService {
6363
pub file_upload_store: Arc<dyn FileUploadStoreApi>,
6464
pub file_upload_client: Arc<dyn FileStorageClientApi>,
6565
pub bitcoin_client: Arc<dyn BitcoinClientApi>,
66-
pub notification_service: Arc<dyn NotificationServiceApi>,
66+
pub transport_service: Arc<dyn TransportServiceApi>,
6767
pub identity_blockchain_store: Arc<dyn IdentityChainStoreApi>,
6868
pub company_blockchain_store: Arc<dyn CompanyChainStoreApi>,
6969
pub contact_store: Arc<dyn ContactStoreApi>,
@@ -83,7 +83,7 @@ impl BillService {
8383
file_upload_store: Arc<dyn FileUploadStoreApi>,
8484
file_upload_client: Arc<dyn FileStorageClientApi>,
8585
bitcoin_client: Arc<dyn BitcoinClientApi>,
86-
notification_service: Arc<dyn NotificationServiceApi>,
86+
transport_service: Arc<dyn TransportServiceApi>,
8787
identity_blockchain_store: Arc<dyn IdentityChainStoreApi>,
8888
company_blockchain_store: Arc<dyn CompanyChainStoreApi>,
8989
contact_store: Arc<dyn ContactStoreApi>,
@@ -100,7 +100,7 @@ impl BillService {
100100
file_upload_store,
101101
file_upload_client,
102102
bitcoin_client,
103-
notification_service,
103+
transport_service,
104104
identity_blockchain_store,
105105
company_blockchain_store,
106106
contact_store,
@@ -273,7 +273,8 @@ impl BillService {
273273
} {
274274
// did we already send the notification
275275
let sent = self
276-
.notification_service
276+
.transport_service
277+
.notification_transport()
277278
.check_bill_notification_sent(
278279
bill_id,
279280
chain.block_height() as i32,
@@ -311,7 +312,8 @@ impl BillService {
311312
.flatten()
312313
.collect::<Vec<BillParticipant>>();
313314

314-
self.notification_service
315+
self.transport_service
316+
.notification_transport()
315317
.send_request_to_action_timed_out_event(
316318
&identity.node_id, // TODO(company-notifications): how to handle jobs as company participant?
317319
bill_id,
@@ -325,7 +327,8 @@ impl BillService {
325327
.await?;
326328

327329
// remember we have sent the notification
328-
self.notification_service
330+
self.transport_service
331+
.notification_transport()
329332
.mark_bill_notification_sent(bill_id, chain.block_height() as i32, action)
330333
.await?;
331334
}
@@ -655,7 +658,8 @@ impl BillService {
655658
identity: &Identity,
656659
) -> BillParticipant {
657660
let relays = match self
658-
.notification_service
661+
.transport_service
662+
.contact_transport()
659663
.resolve_contact(mint_node_id)
660664
.await
661665
{
@@ -901,7 +905,8 @@ impl BillServiceApi for BillService {
901905

902906
// fetch active notifications for bills
903907
let active_notifications = self
904-
.notification_service
908+
.transport_service
909+
.notification_transport()
905910
.get_active_bill_notifications(&bill_ids)
906911
.await;
907912
for bill in bills.iter_mut() {
@@ -1597,7 +1602,7 @@ impl BillServiceApi for BillService {
15971602

15981603
// Send notifications
15991604
if let Err(e) = self
1600-
.notification_service
1605+
.transport_service
16011606
.send_request_to_mint_event(
16021607
&signer_public_data.node_id(),
16031608
&mint_anon_participant,

crates/bcr-ebill-api/src/service/bill_service/test_utils.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use crate::{
33
external::{self, court::MockCourtClientApi, file_storage::MockFileStorageClientApi},
44
service::{
55
company_service::tests::get_valid_company_block,
6-
contact_service::tests::get_baseline_contact,
7-
notification_service::MockNotificationServiceApi,
6+
contact_service::tests::get_baseline_contact, transport_service::MockTransportServiceApi,
87
},
98
tests::tests::{
109
MockBillChainStoreApiMock, MockBillStoreApiMock, MockCompanyChainStoreApiMock,
@@ -62,7 +61,7 @@ pub struct MockBillContext {
6261
pub company_store: MockCompanyStoreApiMock,
6362
pub file_upload_store: MockFileUploadStoreApiMock,
6463
pub file_upload_client: MockFileStorageClientApi,
65-
pub notification_service: MockNotificationServiceApi,
64+
pub transport_service: MockTransportServiceApi,
6665
pub mint_store: MockMintStore,
6766
pub mint_client: MockMintClientApi,
6867
pub court_client: MockCourtClientApi,
@@ -291,9 +290,6 @@ pub fn get_service(mut ctx: MockBillContext) -> BillService {
291290
ctx.bill_store
292291
.expect_invalidate_bill_in_cache()
293292
.returning(|_| Ok(()));
294-
ctx.notification_service
295-
.expect_get_active_bill_notifications()
296-
.returning(|_| HashMap::new());
297293
ctx.bill_store
298294
.expect_save_bill_to_cache()
299295
.returning(|_, _, _| Ok(()));
@@ -314,7 +310,7 @@ pub fn get_service(mut ctx: MockBillContext) -> BillService {
314310
Arc::new(ctx.file_upload_store),
315311
Arc::new(ctx.file_upload_client),
316312
Arc::new(bitcoin_client),
317-
Arc::new(ctx.notification_service),
313+
Arc::new(ctx.transport_service),
318314
Arc::new(ctx.identity_chain_store),
319315
Arc::new(ctx.company_chain_store),
320316
Arc::new(ctx.contact_store),
@@ -337,7 +333,7 @@ pub fn get_ctx() -> MockBillContext {
337333
company_chain_store: MockCompanyChainStoreApiMock::new(),
338334
contact_store: MockContactStoreApiMock::new(),
339335
company_store: MockCompanyStoreApiMock::new(),
340-
notification_service: MockNotificationServiceApi::new(),
336+
transport_service: MockTransportServiceApi::new(),
341337
mint_store: MockMintStore::new(),
342338
mint_client: MockMintClientApi::new(),
343339
court_client: MockCourtClientApi::new(),

0 commit comments

Comments
 (0)