Skip to content

Commit 01db259

Browse files
committed
Drop ChannelMonitor::write_for_watchtower
Not only was watchtower mode never implemented, but the bits that we had were removed some time ago. It doesn't seem likely we'll move forward with a "watchtower-mode" ChannelMonitor, instead we'll likely have some other, separate struct for this.
1 parent c89514c commit 01db259

File tree

3 files changed

+14
-49
lines changed

3 files changed

+14
-49
lines changed

fuzz/src/chanmon_deser.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ pub fn do_test(data: &[u8]) {
3232
let deserialized_copy = <(Sha256dHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(&mut Cursor::new(&w.0), logger.clone()).unwrap();
3333
assert!(latest_block_hash == deserialized_copy.0);
3434
assert!(monitor == deserialized_copy.1);
35-
w.0.clear();
36-
monitor.write_for_watchtower(&mut w).unwrap();
3735
}
3836
}
3937

lightning/src/ln/channelmonitor.rs

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -833,8 +833,14 @@ impl<ChanSigner: ChannelKeys> PartialEq for ChannelMonitor<ChanSigner> {
833833
}
834834

835835
impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
836-
/// Serializes into a vec, with various modes for the exposed pub fns
837-
fn write<W: Writer>(&self, writer: &mut W, for_local_storage: bool) -> Result<(), ::std::io::Error> {
836+
/// Writes this monitor into the given writer, suitable for writing to disk.
837+
///
838+
/// Note that the deserializer is only implemented for (Sha256dHash, ChannelMonitor), which
839+
/// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
840+
/// the "reorg path" (ie not just starting at the same height but starting at the highest
841+
/// common block that appears on your best chain as well as on the chain which contains the
842+
/// last block hash returned) upon deserializing the object!
843+
pub fn write_for_disk<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
838844
//TODO: We still write out all the serialization here manually instead of using the fancy
839845
//serialization framework we have, we should migrate things over to it.
840846
writer.write_all(&[SERIALIZATION_VERSION; 1])?;
@@ -929,14 +935,10 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
929935
}
930936
}
931937

932-
if for_local_storage {
933-
writer.write_all(&byte_utils::be64_to_array(self.remote_hash_commitment_number.len() as u64))?;
934-
for (ref payment_hash, commitment_number) in self.remote_hash_commitment_number.iter() {
935-
writer.write_all(&payment_hash.0[..])?;
936-
writer.write_all(&byte_utils::be48_to_array(*commitment_number))?;
937-
}
938-
} else {
939-
writer.write_all(&byte_utils::be64_to_array(0))?;
938+
writer.write_all(&byte_utils::be64_to_array(self.remote_hash_commitment_number.len() as u64))?;
939+
for (ref payment_hash, commitment_number) in self.remote_hash_commitment_number.iter() {
940+
writer.write_all(&payment_hash.0[..])?;
941+
writer.write_all(&byte_utils::be48_to_array(*commitment_number))?;
940942
}
941943

942944
macro_rules! serialize_local_tx {
@@ -977,17 +979,8 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
977979
writer.write_all(&[0; 1])?;
978980
}
979981

980-
if for_local_storage {
981-
writer.write_all(&byte_utils::be48_to_array(self.current_remote_commitment_number))?;
982-
} else {
983-
writer.write_all(&byte_utils::be48_to_array(0))?;
984-
}
985-
986-
if for_local_storage {
987-
writer.write_all(&byte_utils::be48_to_array(self.current_local_commitment_number))?;
988-
} else {
989-
writer.write_all(&byte_utils::be48_to_array(0))?;
990-
}
982+
writer.write_all(&byte_utils::be48_to_array(self.current_remote_commitment_number))?;
983+
writer.write_all(&byte_utils::be48_to_array(self.current_local_commitment_number))?;
991984

992985
writer.write_all(&byte_utils::be64_to_array(self.payment_preimages.len() as u64))?;
993986
for payment_preimage in self.payment_preimages.values() {
@@ -1039,28 +1032,6 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
10391032

10401033
Ok(())
10411034
}
1042-
1043-
/// Writes this monitor into the given writer, suitable for writing to disk.
1044-
///
1045-
/// Note that the deserializer is only implemented for (Sha256dHash, ChannelMonitor), which
1046-
/// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
1047-
/// the "reorg path" (ie not just starting at the same height but starting at the highest
1048-
/// common block that appears on your best chain as well as on the chain which contains the
1049-
/// last block hash returned) upon deserializing the object!
1050-
pub fn write_for_disk<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
1051-
self.write(writer, true)
1052-
}
1053-
1054-
/// Encodes this monitor into the given writer, suitable for sending to a remote watchtower
1055-
///
1056-
/// Note that the deserializer is only implemented for (Sha256dHash, ChannelMonitor), which
1057-
/// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
1058-
/// the "reorg path" (ie not just starting at the same height but starting at the highest
1059-
/// common block that appears on your best chain as well as on the chain which contains the
1060-
/// last block hash returned) upon deserializing the object!
1061-
pub fn write_for_watchtower<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
1062-
self.write(writer, false)
1063-
}
10641035
}
10651036

10661037
impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {

lightning/src/util/test_utils.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ impl<'a> channelmonitor::ManyChannelMonitor<EnforcingChannelKeys> for TestChanne
7171
let new_monitor = <(Sha256dHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(
7272
&mut ::std::io::Cursor::new(&w.0), Arc::new(TestLogger::new())).unwrap().1;
7373
assert!(new_monitor == monitor);
74-
w.0.clear();
75-
monitor.write_for_watchtower(&mut w).unwrap(); // This at least shouldn't crash...
7674
self.latest_monitor_update_id.lock().unwrap().insert(funding_txo.to_channel_id(), (funding_txo, monitor.get_latest_update_id()));
7775
self.added_monitors.lock().unwrap().push((funding_txo, monitor));
7876
assert!(self.simple_monitor.add_monitor(funding_txo, new_monitor).is_ok());
@@ -97,8 +95,6 @@ impl<'a> channelmonitor::ManyChannelMonitor<EnforcingChannelKeys> for TestChanne
9795
let new_monitor = <(Sha256dHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(
9896
&mut ::std::io::Cursor::new(&w.0), Arc::new(TestLogger::new())).unwrap().1;
9997
assert!(new_monitor == *monitor);
100-
w.0.clear();
101-
monitor.write_for_watchtower(&mut w).unwrap(); // This at least shouldn't crash...
10298
self.added_monitors.lock().unwrap().push((funding_txo, new_monitor));
10399
self.update_ret.lock().unwrap().clone()
104100
}

0 commit comments

Comments
 (0)