From 4345aa88ae415e558a177321a87905a134d4e24a Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 25 Nov 2020 12:23:37 -0500 Subject: [PATCH] Universally Require Writeable for ChannelKeys It doesn't make sense to ever build a lightning node which doesn't ever write ChannelMonitors to disk, so having a ChannelKeys object which doesn't implement Writeable is nonsense. Here we require Writeable for all ChannelKeys objects, simplifying code generation for C bindings somewhat. --- lightning-persister/src/lib.rs | 6 +++--- lightning/src/chain/channelmonitor.rs | 2 +- lightning/src/chain/keysinterface.rs | 2 +- lightning/src/ln/channel.rs | 2 +- lightning/src/ln/channelmanager.rs | 2 +- lightning/src/ln/onchaintx.rs | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lightning-persister/src/lib.rs b/lightning-persister/src/lib.rs index 48d4d0aa..ec08e948 100644 --- a/lightning-persister/src/lib.rs +++ b/lightning-persister/src/lib.rs @@ -43,7 +43,7 @@ trait DiskWriteable { fn write(&self, writer: &mut fs::File) -> Result<(), Error>; } -impl DiskWriteable for ChannelMonitor { +impl DiskWriteable for ChannelMonitor { fn write(&self, writer: &mut fs::File) -> Result<(), Error> { self.serialize_for_disk(writer) } @@ -94,7 +94,7 @@ impl FilesystemPersister { } #[cfg(test)] - fn load_channel_data(&self) -> + fn load_channel_data(&self) -> Result>, ChannelMonitorUpdateErr> { if let Err(_) = fs::create_dir_all(&self.path_to_channel_data) { return Err(ChannelMonitorUpdateErr::PermanentFailure); @@ -128,7 +128,7 @@ impl FilesystemPersister { } } -impl channelmonitor::Persist for FilesystemPersister { +impl channelmonitor::Persist for FilesystemPersister { fn persist_new_channel(&self, funding_txo: OutPoint, monitor: &ChannelMonitor) -> Result<(), ChannelMonitorUpdateErr> { self.write_channel_data(funding_txo, monitor) .map_err(|_| ChannelMonitorUpdateErr::PermanentFailure) diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index 3c58e9a2..548c8f06 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -755,7 +755,7 @@ impl PartialEq for ChannelMonitor { } } -impl ChannelMonitor { +impl ChannelMonitor { /// Writes this monitor into the given writer, suitable for writing to disk. /// /// Note that the deserializer is only implemented for (Sha256dHash, ChannelMonitor), which diff --git a/lightning/src/chain/keysinterface.rs b/lightning/src/chain/keysinterface.rs index 085a2f87..47ad84bb 100644 --- a/lightning/src/chain/keysinterface.rs +++ b/lightning/src/chain/keysinterface.rs @@ -204,7 +204,7 @@ impl Readable for SpendableOutputDescriptor { // routine). // TODO: We should remove Clone by instead requesting a new ChannelKeys copy when we create // ChannelMonitors instead of expecting to clone the one out of the Channel into the monitors. -pub trait ChannelKeys : Send+Clone { +pub trait ChannelKeys : Send+Clone + Writeable { /// Gets the per-commitment point for a specific commitment number /// /// Note that the commitment number starts at (1 << 48) - 1 and counts backwards. diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index c319c552..5477485d 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -4055,7 +4055,7 @@ impl Readable for InboundHTLCRemovalReason { } } -impl Writeable for Channel { +impl Writeable for Channel { fn write(&self, writer: &mut W) -> Result<(), ::std::io::Error> { // Note that we write out as if remove_uncommitted_htlcs_and_mark_paused had just been // called but include holding cell updates (and obviously we don't modify self). diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index c39eef3e..63466f9f 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -3693,7 +3693,7 @@ impl Readable for HTLCForwardInfo { } } -impl Writeable for ChannelManager +impl Writeable for ChannelManager where M::Target: chain::Watch, T::Target: BroadcasterInterface, K::Target: KeysInterface, diff --git a/lightning/src/ln/onchaintx.rs b/lightning/src/ln/onchaintx.rs index 146a4d57..513e4a13 100644 --- a/lightning/src/ln/onchaintx.rs +++ b/lightning/src/ln/onchaintx.rs @@ -286,7 +286,7 @@ pub struct OnchainTxHandler { secp_ctx: Secp256k1, } -impl OnchainTxHandler { +impl OnchainTxHandler { pub(crate) fn write(&self, writer: &mut W) -> Result<(), ::std::io::Error> { self.destination_script.write(writer)?; self.holder_commitment.write(writer)?; -- 2.30.2