From b244b8159f16a582f22265a7ff283e2fe29a28f2 Mon Sep 17 00:00:00 2001 From: Philip Robinson Date: Mon, 15 Jun 2020 10:08:26 +0200 Subject: [PATCH] Fix unexpected error with wallet power updates If the power state is updated in the wallet before any Transaction activity occurs there are no subscribers to the broadcast channel which produced an incorrect error. This PR logs the event but does not send it back across the FFI as an error. --- base_layer/wallet/src/transaction_service/service.rs | 10 +++++++--- base_layer/wallet/tests/transaction_service/service.rs | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/base_layer/wallet/src/transaction_service/service.rs b/base_layer/wallet/src/transaction_service/service.rs index 7026fbbb1c..e6b72cbb70 100644 --- a/base_layer/wallet/src/transaction_service/service.rs +++ b/base_layer/wallet/src/transaction_service/service.rs @@ -1228,9 +1228,13 @@ where PowerMode::Low => self.config.low_power_polling_timeout, PowerMode::Normal => self.config.base_node_monitoring_timeout, }; - self.timeout_update_publisher - .send(timeout) - .map_err(|_| TransactionServiceError::ProtocolChannelError)?; + if let Err(e) = self.timeout_update_publisher.send(timeout) { + trace!( + target: LOG_TARGET, + "Could not send Timeout update, no subscribers to receive. (Err {:?})", + e + ); + } Ok(()) } diff --git a/base_layer/wallet/tests/transaction_service/service.rs b/base_layer/wallet/tests/transaction_service/service.rs index a446d79dde..5b140e7982 100644 --- a/base_layer/wallet/tests/transaction_service/service.rs +++ b/base_layer/wallet/tests/transaction_service/service.rs @@ -1813,6 +1813,9 @@ fn transaction_base_node_monitoring() { let (_, _, bob_outbound_service, mut bob_tx_sender, _, _, _, _) = setup_transaction_service_no_comms(&mut runtime, factories.clone(), TransactionMemoryDatabase::new(), None); + runtime.block_on(alice_ts.set_low_power_mode()).unwrap(); + runtime.block_on(alice_ts.set_normal_power_mode()).unwrap(); + let mut alice_total_available = 250000 * uT; let (_utxo, uo) = make_input(&mut OsRng, alice_total_available, &factories.commitment); runtime.block_on(alice_output_manager.add_output(uo)).unwrap();