Skip to content

Commit caabc4e

Browse files
committed
Remove last_block_connected from Channel
Tracking the last block was only used to de-duplicate block_connected calls, but this is no longer required as of the previous commit. Further, the ChannelManager can pass the latest block hash when needing to create a ChannelMonitor rather than have each Channel maintain an up-to-date copy. This is implemented in the next commit.
1 parent ff4b4c4 commit caabc4e

File tree

2 files changed

+2
-18
lines changed

2 files changed

+2
-18
lines changed

lightning/src/ln/channel.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ use util::errors::APIError;
3939
use util::config::{UserConfig,ChannelConfig};
4040

4141
use std;
42-
use std::default::Default;
4342
use std::{cmp,mem,fmt};
4443
use std::ops::Deref;
4544
#[cfg(any(test, feature = "fuzztarget"))]
@@ -368,8 +367,6 @@ pub(super) struct Channel<Signer: Sign> {
368367
/// could miss the funding_tx_confirmed_in block as well, but it serves as a useful fallback.
369368
funding_tx_confirmed_in: Option<BlockHash>,
370369
short_channel_id: Option<u64>,
371-
/// Used to verify consistency during ChannelManager deserialization (hence pub(super)).
372-
pub(super) last_block_connected: BlockHash,
373370
funding_tx_confirmations: u64,
374371

375372
counterparty_dust_limit_satoshis: u64,
@@ -568,7 +565,6 @@ impl<Signer: Sign> Channel<Signer> {
568565

569566
funding_tx_confirmed_in: None,
570567
short_channel_id: None,
571-
last_block_connected: Default::default(),
572568
funding_tx_confirmations: 0,
573569

574570
feerate_per_kw: feerate,
@@ -804,7 +800,6 @@ impl<Signer: Sign> Channel<Signer> {
804800

805801
funding_tx_confirmed_in: None,
806802
short_channel_id: None,
807-
last_block_connected: Default::default(),
808803
funding_tx_confirmations: 0,
809804

810805
feerate_per_kw: msg.feerate_per_kw,
@@ -3568,7 +3563,6 @@ impl<Signer: Sign> Channel<Signer> {
35683563
}
35693564
}
35703565

3571-
self.last_block_connected = header.block_hash();
35723566
self.update_time_counter = cmp::max(self.update_time_counter, header.time);
35733567
if self.funding_tx_confirmations > 0 {
35743568
if self.funding_tx_confirmations == self.minimum_depth as u64 {
@@ -3590,7 +3584,7 @@ impl<Signer: Sign> Channel<Signer> {
35903584
// funding_tx_confirmed_in and return.
35913585
false
35923586
};
3593-
self.funding_tx_confirmed_in = Some(self.last_block_connected);
3587+
self.funding_tx_confirmed_in = Some(header.block_hash());
35943588

35953589
//TODO: Note that this must be a duplicate of the previous commitment point they sent us,
35963590
//as otherwise we will have a commitment transaction that they can't revoke (well, kinda,
@@ -3623,8 +3617,7 @@ impl<Signer: Sign> Channel<Signer> {
36233617
return true;
36243618
}
36253619
}
3626-
self.last_block_connected = header.block_hash();
3627-
if Some(self.last_block_connected) == self.funding_tx_confirmed_in {
3620+
if Some(header.block_hash()) == self.funding_tx_confirmed_in {
36283621
self.funding_tx_confirmations = self.minimum_depth as u64 - 1;
36293622
}
36303623
false
@@ -4433,8 +4426,6 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
44334426

44344427
self.funding_tx_confirmed_in.write(writer)?;
44354428
self.short_channel_id.write(writer)?;
4436-
4437-
self.last_block_connected.write(writer)?;
44384429
self.funding_tx_confirmations.write(writer)?;
44394430

44404431
self.counterparty_dust_limit_satoshis.write(writer)?;
@@ -4595,8 +4586,6 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
45954586

45964587
let funding_tx_confirmed_in = Readable::read(reader)?;
45974588
let short_channel_id = Readable::read(reader)?;
4598-
4599-
let last_block_connected = Readable::read(reader)?;
46004589
let funding_tx_confirmations = Readable::read(reader)?;
46014590

46024591
let counterparty_dust_limit_satoshis = Readable::read(reader)?;
@@ -4667,7 +4656,6 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
46674656

46684657
funding_tx_confirmed_in,
46694658
short_channel_id,
4670-
last_block_connected,
46714659
funding_tx_confirmations,
46724660

46734661
counterparty_dust_limit_satoshis,

lightning/src/ln/channelmanager.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4153,10 +4153,6 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
41534153
let mut short_to_id = HashMap::with_capacity(cmp::min(channel_count as usize, 128));
41544154
for _ in 0..channel_count {
41554155
let mut channel: Channel<Signer> = Channel::read(reader, &args.keys_manager)?;
4156-
if channel.last_block_connected != Default::default() && channel.last_block_connected != last_block_hash {
4157-
return Err(DecodeError::InvalidValue);
4158-
}
4159-
41604156
let funding_txo = channel.get_funding_txo().ok_or(DecodeError::InvalidValue)?;
41614157
funding_txo_set.insert(funding_txo.clone());
41624158
if let Some(ref mut monitor) = args.channel_monitors.get_mut(&funding_txo) {

0 commit comments

Comments
 (0)