From: Matt Corallo Date: Wed, 25 Nov 2020 17:23:37 +0000 (-0500) Subject: Universally Require Writeable for ChannelKeys X-Git-Tag: v0.0.13~47^2~4 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=4345aa88ae415e558a177321a87905a134d4e24a;p=rust-lightning 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. --- diff --git a/lightning-persister/src/lib.rs b/lightning-persister/src/lib.rs index 48d4d0aa8..ec08e948f 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 3c58e9a28..548c8f06c 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 085a2f871..47ad84bbc 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 c319c5524..5477485d5 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 c39eef3ea..63466f9f3 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 146a4d57c..513e4a136 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)?;