]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Universally Require Writeable for ChannelKeys
authorMatt Corallo <git@bluematt.me>
Wed, 25 Nov 2020 17:23:37 +0000 (12:23 -0500)
committerMatt Corallo <git@bluematt.me>
Mon, 4 Jan 2021 17:40:40 +0000 (12:40 -0500)
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
lightning/src/chain/channelmonitor.rs
lightning/src/chain/keysinterface.rs
lightning/src/ln/channel.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/onchaintx.rs

index 48d4d0aa810c3b4b0ca8645acd8485646a9722e7..ec08e948f60411e41aa00c0bc60d4704b8e71fce 100644 (file)
@@ -43,7 +43,7 @@ trait DiskWriteable {
        fn write(&self, writer: &mut fs::File) -> Result<(), Error>;
 }
 
-impl<ChanSigner: ChannelKeys + Writeable> DiskWriteable for ChannelMonitor<ChanSigner> {
+impl<ChanSigner: ChannelKeys> DiskWriteable for ChannelMonitor<ChanSigner> {
        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<ChanSigner: ChannelKeys + Readable + Writeable>(&self) ->
+       fn load_channel_data<ChanSigner: ChannelKeys + Readable>(&self) ->
                Result<HashMap<OutPoint, ChannelMonitor<ChanSigner>>, ChannelMonitorUpdateErr> {
                if let Err(_) = fs::create_dir_all(&self.path_to_channel_data) {
                        return Err(ChannelMonitorUpdateErr::PermanentFailure);
@@ -128,7 +128,7 @@ impl FilesystemPersister {
        }
 }
 
-impl<ChanSigner: ChannelKeys + Readable + Writeable + Send + Sync> channelmonitor::Persist<ChanSigner> for FilesystemPersister {
+impl<ChanSigner: ChannelKeys + Readable + Send + Sync> channelmonitor::Persist<ChanSigner> for FilesystemPersister {
        fn persist_new_channel(&self, funding_txo: OutPoint, monitor: &ChannelMonitor<ChanSigner>) -> Result<(), ChannelMonitorUpdateErr> {
                self.write_channel_data(funding_txo, monitor)
                  .map_err(|_| ChannelMonitorUpdateErr::PermanentFailure)
index 3c58e9a2888d7b7cea4eda3376648a72fd0abd95..548c8f06c2051225391a6c3a7563520a43b809af 100644 (file)
@@ -755,7 +755,7 @@ impl<ChanSigner: ChannelKeys> PartialEq for ChannelMonitor<ChanSigner> {
        }
 }
 
-impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
+impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
        /// Writes this monitor into the given writer, suitable for writing to disk.
        ///
        /// Note that the deserializer is only implemented for (Sha256dHash, ChannelMonitor), which
index 085a2f87154b1b5a09c9cd9a32757bf8f164dc49..47ad84bbc596f1de3e0e387df7add2a67ad859a8 100644 (file)
@@ -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.
index c319c5524cef4768239eebcd05b510b492a8e57f..5477485d5a16ee74e9bcb22472b99e627e07ef56 100644 (file)
@@ -4055,7 +4055,7 @@ impl Readable for InboundHTLCRemovalReason {
        }
 }
 
-impl<ChanSigner: ChannelKeys + Writeable> Writeable for Channel<ChanSigner> {
+impl<ChanSigner: ChannelKeys> Writeable for Channel<ChanSigner> {
        fn write<W: Writer>(&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).
index c39eef3ea477a9d7558b69629601c4be14d6dbfc..63466f9f3d003f3978214e6c1a11830b6490a75b 100644 (file)
@@ -3693,7 +3693,7 @@ impl Readable for HTLCForwardInfo {
        }
 }
 
-impl<ChanSigner: ChannelKeys + Writeable, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> Writeable for ChannelManager<ChanSigner, M, T, K, F, L>
+impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> Writeable for ChannelManager<ChanSigner, M, T, K, F, L>
        where M::Target: chain::Watch<Keys=ChanSigner>,
         T::Target: BroadcasterInterface,
         K::Target: KeysInterface<ChanKeySigner = ChanSigner>,
index 146a4d57c8b27d68bef808a45e3ec6789c464a9b..513e4a136dc742dc9d5f2ad8268271658d7ff511 100644 (file)
@@ -286,7 +286,7 @@ pub struct OnchainTxHandler<ChanSigner: ChannelKeys> {
        secp_ctx: Secp256k1<secp256k1::All>,
 }
 
-impl<ChanSigner: ChannelKeys + Writeable> OnchainTxHandler<ChanSigner> {
+impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
        pub(crate) fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
                self.destination_script.write(writer)?;
                self.holder_commitment.write(writer)?;