From: Elias Rohrer Date: Thu, 6 Jun 2024 07:18:04 +0000 (+0200) Subject: Make `confirmables` `Deref` X-Git-Tag: v0.0.124-beta~90^2~7 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=777ce7b059c0e81cbb36813d9ad028f767985fdd;p=rust-lightning Make `confirmables` `Deref` .. the bindings branch needed a small patch as it doesn't support `dyn` traits. Here, we opt to use `Deref` in the hopes this works with bindings, rendering the patch unnecessary. --- diff --git a/lightning-transaction-sync/src/common.rs b/lightning-transaction-sync/src/common.rs index c635f7385..d68ac9591 100644 --- a/lightning-transaction-sync/src/common.rs +++ b/lightning-transaction-sync/src/common.rs @@ -4,6 +4,7 @@ use bitcoin::{Txid, BlockHash, Transaction, OutPoint}; use bitcoin::block::Header; use std::collections::{HashSet, HashMap}; +use std::ops::Deref; // Represents the current state. @@ -33,10 +34,12 @@ impl SyncState { pending_sync: false, } } - pub fn sync_unconfirmed_transactions( - &mut self, confirmables: &Vec<&(dyn Confirm + Sync + Send)>, + pub fn sync_unconfirmed_transactions( + &mut self, confirmables: &Vec, unconfirmed_txs: Vec, - ) { + ) + where C::Target: Confirm, + { for txid in unconfirmed_txs { for c in confirmables { c.transaction_unconfirmed(&txid); @@ -57,10 +60,12 @@ impl SyncState { } } - pub fn sync_confirmed_transactions( - &mut self, confirmables: &Vec<&(dyn Confirm + Sync + Send)>, + pub fn sync_confirmed_transactions( + &mut self, confirmables: &Vec, confirmed_txs: Vec - ) { + ) + where C::Target: Confirm, + { for ctx in confirmed_txs { for c in confirmables { c.transactions_confirmed( diff --git a/lightning-transaction-sync/src/electrum.rs b/lightning-transaction-sync/src/electrum.rs index d2cb7256f..4c809d407 100644 --- a/lightning-transaction-sync/src/electrum.rs +++ b/lightning-transaction-sync/src/electrum.rs @@ -83,7 +83,9 @@ where /// [`ChainMonitor`]: lightning::chain::chainmonitor::ChainMonitor /// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager /// [`Filter`]: lightning::chain::Filter - pub fn sync(&self, confirmables: Vec<&(dyn Confirm + Sync + Send)>) -> Result<(), TxSyncError> { + pub fn sync(&self, confirmables: Vec) -> Result<(), TxSyncError> + where C::Target: Confirm + { // This lock makes sure we're syncing once at a time. let mut sync_state = self.sync_state.lock().unwrap(); @@ -378,9 +380,11 @@ where Ok(confirmed_txs) } - fn get_unconfirmed_transactions( - &self, confirmables: &Vec<&(dyn Confirm + Sync + Send)>, - ) -> Result, InternalError> { + fn get_unconfirmed_transactions( + &self, confirmables: &Vec, + ) -> Result, InternalError> + where C::Target: Confirm + { // Query the interface for relevant txids and check whether the relevant blocks are still // in the best chain, mark them unconfirmed otherwise let relevant_txids = confirmables diff --git a/lightning-transaction-sync/src/esplora.rs b/lightning-transaction-sync/src/esplora.rs index 2e35a150c..82c49b9f9 100644 --- a/lightning-transaction-sync/src/esplora.rs +++ b/lightning-transaction-sync/src/esplora.rs @@ -84,7 +84,9 @@ where /// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager /// [`Filter`]: lightning::chain::Filter #[maybe_async] - pub fn sync(&self, confirmables: Vec<&(dyn Confirm + Sync + Send)>) -> Result<(), TxSyncError> { + pub fn sync(&self, confirmables: Vec) -> Result<(), TxSyncError> + where C::Target: Confirm + { // This lock makes sure we're syncing once at a time. #[cfg(not(feature = "async-interface"))] let mut sync_state = self.sync_state.lock().unwrap(); @@ -239,10 +241,11 @@ where } #[maybe_async] - fn sync_best_block_updated( - &self, confirmables: &Vec<&(dyn Confirm + Sync + Send)>, sync_state: &mut SyncState, tip_hash: &BlockHash, - ) -> Result<(), InternalError> { - + fn sync_best_block_updated( + &self, confirmables: &Vec, sync_state: &mut SyncState, tip_hash: &BlockHash, + ) -> Result<(), InternalError> + where C::Target: Confirm + { // Inform the interface of the new block. let tip_header = maybe_await!(self.client.get_header_by_hash(tip_hash))?; let tip_status = maybe_await!(self.client.get_block_status(&tip_hash))?; @@ -369,9 +372,11 @@ where } #[maybe_async] - fn get_unconfirmed_transactions( - &self, confirmables: &Vec<&(dyn Confirm + Sync + Send)>, - ) -> Result, InternalError> { + fn get_unconfirmed_transactions( + &self, confirmables: &Vec, + ) -> Result, InternalError> + where C::Target: Confirm + { // Query the interface for relevant txids and check whether the relevant blocks are still // in the best chain, mark them unconfirmed otherwise let relevant_txids = confirmables