Skip to content

Commit dd2ca27

Browse files
multi: change block_connected interface to take a list of Transactions instead of &Transactions
This allows us to avoid adding a bunch of lifetimes everywhere due to data flowing from &Block --> &Transaction in `block_connected`.
1 parent d960017 commit dd2ca27

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

src/chain/chaininterface.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub trait ChainListener: Sync + Send {
7979
///
8080
/// This also means those counting confirmations using block_connected callbacks should watch
8181
/// for duplicate headers and not count them towards confirmations!
82-
fn block_connected(&self, header: &BlockHeader, height: u32, txn_matched: &[&Transaction], indexes_of_txn_matched: &[u32]);
82+
fn block_connected(&self, header: &BlockHeader, height: u32, txn_matched: &[Transaction], indexes_of_txn_matched: &[u32]);
8383
/// Notifies a listener that a block was disconnected.
8484
/// Unlike block_connected, this *must* never be called twice for the same disconnect event.
8585
/// Height must be the one of the block which was disconnected (not new height of the best chain)

src/ln/channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2999,7 +2999,7 @@ impl Channel {
29992999
/// In case of Err, the channel may have been closed, at which point the standard requirements
30003000
/// apply - no calls may be made except those explicitly stated to be allowed post-shutdown.
30013001
/// Only returns an ErrorAction of DisconnectPeer, if Err.
3002-
pub fn block_connected(&mut self, header: &BlockHeader, height: u32, txn_matched: &[&Transaction], indexes_of_txn_matched: &[u32]) -> Result<Option<msgs::FundingLocked>, msgs::ErrorMessage> {
3002+
pub fn block_connected(&mut self, header: &BlockHeader, height: u32, txn_matched: &[Transaction], indexes_of_txn_matched: &[u32]) -> Result<Option<msgs::FundingLocked>, msgs::ErrorMessage> {
30033003
let non_shutdown_state = self.channel_state & (!MULTI_STATE_FLAGS);
30043004
if header.bitcoin_hash() != self.last_block_connected {
30053005
self.last_block_connected = header.bitcoin_hash();

src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2508,7 +2508,7 @@ impl events::EventsProvider for ChannelManager {
25082508
}
25092509

25102510
impl ChainListener for ChannelManager {
2511-
fn block_connected(&self, header: &BlockHeader, height: u32, txn_matched: &[&Transaction], indexes_of_txn_matched: &[u32]) {
2511+
fn block_connected(&self, header: &BlockHeader, height: u32, txn_matched: &[Transaction], indexes_of_txn_matched: &[u32]) {
25122512
let header_hash = header.bitcoin_hash();
25132513
log_trace!(self, "Block {} at height {} connected with {} txn matched", header_hash, height, txn_matched.len());
25142514
let _ = self.total_consistency_lock.read().unwrap();

src/ln/channelmonitor.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,15 @@ pub struct SimpleManyChannelMonitor<Key> {
147147
}
148148

149149
impl<Key : Send + cmp::Eq + hash::Hash> ChainListener for SimpleManyChannelMonitor<Key> {
150-
fn block_connected(&self, header: &BlockHeader, height: u32, txn_matched: &[&Transaction], _indexes_of_txn_matched: &[u32]) {
150+
151+
fn block_connected(&self, header: &BlockHeader, height: u32, txn_matched: &[Transaction], _indexes_of_txn_matched: &[u32]) {
151152
let block_hash = header.bitcoin_hash();
152153
let mut new_events: Vec<events::Event> = Vec::with_capacity(0);
153154
let mut htlc_updated_infos = Vec::new();
154155
{
155156
let mut monitors = self.monitors.lock().unwrap();
156157
for monitor in monitors.values_mut() {
157-
let (txn_outputs, spendable_outputs, mut htlc_updated) = monitor.block_connected(txn_matched, height, &block_hash, &*self.broadcaster, &*self.fee_estimator);
158+
let (txn_outputs, spendable_outputs, mut htlc_updated) = monitor.block_connected(txn_matched.clone(), height, &block_hash, &*self.broadcaster, &*self.fee_estimator);
158159
if spendable_outputs.len() > 0 {
159160
new_events.push(events::Event::SpendableOutputs {
160161
outputs: spendable_outputs,
@@ -2113,7 +2114,7 @@ impl ChannelMonitor {
21132114
}
21142115
}
21152116

2116-
fn block_connected(&mut self, txn_matched: &[&Transaction], height: u32, block_hash: &Sha256dHash, broadcaster: &BroadcasterInterface, fee_estimator: &FeeEstimator)-> (Vec<(Sha256dHash, Vec<TxOut>)>, Vec<SpendableOutputDescriptor>, Vec<(HTLCSource, Option<PaymentPreimage>, PaymentHash)>) {
2117+
fn block_connected(&mut self, txn_matched: &[Transaction], height: u32, block_hash: &Sha256dHash, broadcaster: &BroadcasterInterface, fee_estimator: &FeeEstimator)-> (Vec<(Sha256dHash, Vec<TxOut>)>, Vec<SpendableOutputDescriptor>, Vec<(HTLCSource, Option<PaymentPreimage>, PaymentHash)>) {
21172118
let mut watch_outputs = Vec::new();
21182119
let mut spendable_outputs = Vec::new();
21192120
let mut htlc_updated = Vec::new();
@@ -2135,14 +2136,14 @@ impl ChannelMonitor {
21352136
};
21362137
if funding_txo.is_none() || (prevout.txid == funding_txo.as_ref().unwrap().0.txid && prevout.vout == funding_txo.as_ref().unwrap().0.index as u32) {
21372138
if (tx.input[0].sequence >> 8*3) as u8 == 0x80 && (tx.lock_time >> 8*3) as u8 == 0x20 {
2138-
let (remote_txn, new_outputs, mut spendable_output) = self.check_spend_remote_transaction(tx, height, fee_estimator);
2139+
let (remote_txn, new_outputs, mut spendable_output) = self.check_spend_remote_transaction(&tx, height, fee_estimator);
21392140
txn = remote_txn;
21402141
spendable_outputs.append(&mut spendable_output);
21412142
if !new_outputs.1.is_empty() {
21422143
watch_outputs.push(new_outputs);
21432144
}
21442145
if txn.is_empty() {
2145-
let (local_txn, mut spendable_output, new_outputs) = self.check_spend_local_transaction(tx, height);
2146+
let (local_txn, mut spendable_output, new_outputs) = self.check_spend_local_transaction(&tx, height);
21462147
spendable_outputs.append(&mut spendable_output);
21472148
txn = local_txn;
21482149
if !new_outputs.1.is_empty() {
@@ -2151,13 +2152,13 @@ impl ChannelMonitor {
21512152
}
21522153
}
21532154
if !funding_txo.is_none() && txn.is_empty() {
2154-
if let Some(spendable_output) = self.check_spend_closing_transaction(tx) {
2155+
if let Some(spendable_output) = self.check_spend_closing_transaction(&tx) {
21552156
spendable_outputs.push(spendable_output);
21562157
}
21572158
}
21582159
} else {
21592160
if let Some(&(commitment_number, _)) = self.remote_commitment_txn_on_chain.get(&prevout.txid) {
2160-
let (tx, spendable_output) = self.check_spend_remote_htlc(tx, commitment_number, height, fee_estimator);
2161+
let (tx, spendable_output) = self.check_spend_remote_htlc(&tx, commitment_number, height, fee_estimator);
21612162
if let Some(tx) = tx {
21622163
txn.push(tx);
21632164
}
@@ -2173,7 +2174,7 @@ impl ChannelMonitor {
21732174
// While all commitment/HTLC-Success/HTLC-Timeout transactions have one input, HTLCs
21742175
// can also be resolved in a few other ways which can have more than one output. Thus,
21752176
// we call is_resolving_htlc_output here outside of the tx.input.len() == 1 check.
2176-
let mut updated = self.is_resolving_htlc_output(tx, height);
2177+
let mut updated = self.is_resolving_htlc_output(&tx, height);
21772178
if updated.len() > 0 {
21782179
htlc_updated.append(&mut updated);
21792180
}

0 commit comments

Comments
 (0)