Skip to content

Commit e03a27b

Browse files
committed
removes vector of u32
1 parent a38fba6 commit e03a27b

File tree

2 files changed

+21
-31
lines changed

2 files changed

+21
-31
lines changed

src/ln/channelmanager.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,9 @@ impl ChannelManager {
703703

704704
/// Force closes a channel, immediately broadcasting the latest local commitment transaction to
705705
/// the chain and rejecting new HTLCs on the given channel.
706-
pub fn force_close_channel(&self, channel_id: &[u8; 32], store_closed : bool) {
706+
/// delay_tx_broadcast parameter is there to stop the immediate broadcast of the channel TX. This is delayed by one week.
707+
/// Look in bolt spec under data loss protect.
708+
pub fn force_close_channel(&self, channel_id: &[u8; 32], delay_tx_broadcast : bool) {
707709
let _ = self.total_consistency_lock.read().unwrap();
708710

709711
let mut chan = {
@@ -720,7 +722,7 @@ impl ChannelManager {
720722
};
721723
log_trace!(self, "Force-closing channel {}", log_bytes!(channel_id[..]));
722724
let mut shutdown_result = chan.force_shutdown();
723-
if store_closed{
725+
if delay_tx_broadcast{
724726
shutdown_result.2 = false;
725727
self.finish_force_close_channel(shutdown_result);
726728
let mut chan_monitor = chan.get_channel_monitor();
@@ -3017,7 +3019,7 @@ impl<'a, R : ::std::io::Read> ReadableArgs<R, ChannelManagerReadArgs<'a>> for (S
30173019
claimable_htlcs.insert(payment_hash, previous_hops);
30183020
}
30193021

3020-
let mut channel_manager = ChannelManager {
3022+
let channel_manager = ChannelManager {
30213023
genesis_hash,
30223024
fee_estimator: args.fee_estimator,
30233025
monitor: args.monitor,

src/ln/channelmonitor.rs

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,9 @@ pub struct ChannelMonitor {
394394
pub(crate) last_block_hash: Sha256dHash,
395395
secp_ctx: Secp256k1<secp256k1::All>, //TODO: dedup this a bit...
396396

397-
//this is all channels transactions that failed in the data_loss_protect protocol
398-
//The first index is the height that we attempt to claim it at, this claimed height is by default one week later, and it is there to claim if the other party did not claim
399-
transactions_awaiting_claiming : Vec<u32>,
397+
//This is the block height blocks the finishing transactions from being claimed till the chain reaches the mentioned block height.
398+
//If this is set to 0, it is not used at that moment.
399+
blockheight_block : u32,
400400

401401
logger: Arc<Logger>,
402402
}
@@ -472,7 +472,7 @@ impl ChannelMonitor {
472472

473473
last_block_hash: Default::default(),
474474
secp_ctx: Secp256k1::new(),
475-
transactions_awaiting_claiming : Vec::new(),
475+
blockheight_block : 0,
476476
logger,
477477
}
478478
}
@@ -969,10 +969,7 @@ impl ChannelMonitor {
969969

970970
self.last_block_hash.write(writer)?;
971971
self.destination_script.write(writer)?;
972-
writer.write_all(&byte_utils::be64_to_array(self.transactions_awaiting_claiming.len() as u64))?;
973-
for transaction in self.transactions_awaiting_claiming.iter(){
974-
writer.write_all(&byte_utils::be32_to_array(*transaction))?;
975-
};
972+
writer.write_all(&byte_utils::be32_to_array(self.blockheight_block))?;
976973

977974
Ok(())
978975
}
@@ -1701,22 +1698,18 @@ impl ChannelMonitor {
17011698

17021699
///this is used by the channel manager to add transactions that should only be broadcasted at a much later height
17031700
pub fn broadcast_transaction_at_height(&mut self, broadcast_height: u32) {
1704-
self.transactions_awaiting_claiming.push(broadcast_height);
1701+
self.blockheight_block = broadcast_height;
17051702
}
17061703

17071704
fn block_connected(&mut self, txn_matched: &[&Transaction], height: u32, block_hash: &Sha256dHash, broadcaster: &BroadcasterInterface)-> (Vec<(Sha256dHash, Vec<TxOut>)>, Vec<SpendableOutputDescriptor>, Vec<(HTLCSource, Option<PaymentPreimage>, PaymentHash)>) {
1708-
if !self.transactions_awaiting_claiming.is_empty() {
1709-
for i in 0..self.transactions_awaiting_claiming.len(){
1710-
if self.transactions_awaiting_claiming[i] >= height
1711-
{
1712-
let transactions = self.get_latest_local_commitment_txn();
1713-
let mut ref_transactions = Vec::new();
1714-
for trans in transactions.iter(){ref_transactions.push(trans)};
1715-
self.block_connected_logic(&ref_transactions[..], height, block_hash, broadcaster);
1716-
self.transactions_awaiting_claiming.remove(i);
1717-
};
1718-
};
1719-
}
1705+
if self.blockheight_block >= height //we dont need to check for 0, because if blockheight_block > height, 0 will be too
1706+
{
1707+
let transactions = self.get_latest_local_commitment_txn();
1708+
let mut ref_transactions = Vec::new();
1709+
for trans in transactions.iter(){ref_transactions.push(trans)};
1710+
self.block_connected_logic(&ref_transactions[..], height, block_hash, broadcaster);
1711+
self.blockheight_block = 0;
1712+
};
17201713
self.block_connected_logic(txn_matched, height, block_hash, broadcaster)
17211714
}
17221715

@@ -2199,12 +2192,7 @@ impl<R: ::std::io::Read> ReadableArgs<R, Arc<Logger>> for (Sha256dHash, ChannelM
21992192

22002193
let last_block_hash: Sha256dHash = Readable::read(reader)?;
22012194
let destination_script = Readable::read(reader)?;
2202-
let mut transactions_awaiting_claiming = Vec::new();
2203-
let transactions_awaiting_claiming_len: u64 = Readable::read(reader)?;
2204-
for _ in 0..transactions_awaiting_claiming_len {
2205-
let transaction: u32 = Readable::read(reader)?;
2206-
transactions_awaiting_claiming.push(transaction);
2207-
}
2195+
let blockheight_block: u32 = Readable::read(reader)?;
22082196

22092197
Ok((last_block_hash.clone(), ChannelMonitor {
22102198
commitment_transaction_number_obscure_factor,
@@ -2231,7 +2219,7 @@ impl<R: ::std::io::Read> ReadableArgs<R, Arc<Logger>> for (Sha256dHash, ChannelM
22312219
destination_script,
22322220
last_block_hash,
22332221
secp_ctx,
2234-
transactions_awaiting_claiming,
2222+
blockheight_block,
22352223
logger,
22362224
}))
22372225
}

0 commit comments

Comments
 (0)