Merge pull request #911 from TheBlueMatt/2021-05-fix-cltv-diff
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Thu, 6 May 2021 21:49:24 +0000 (21:49 +0000)
committerGitHub <noreply@github.com>
Thu, 6 May 2021 21:49:24 +0000 (21:49 +0000)
lightning/src/chain/channelmonitor.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/msgs.rs
lightning/src/ln/onchaintx.rs
lightning/src/util/macro_logger.rs

index a2c1abe756bfa7d282e10e11722cbed8232cb5cb..62cb740e816d94ab517335d88e562a40191126fd 100644 (file)
@@ -1568,6 +1568,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
                                        L::Target: Logger,
        {
                for tx in self.get_latest_holder_commitment_txn(logger).iter() {
+                       log_info!(logger, "Broadcasting local {}", log_tx!(tx));
                        broadcaster.broadcast_transaction(tx);
                }
                self.pending_monitor_events.push(MonitorEvent::CommitmentTxBroadcasted(self.funding_info.0));
index 9cff2fcfc2aed35aca74ba7e7cc836e57e074483..52ea21f07591e86eaff4436c1d4dc515c9a9725c 100644 (file)
@@ -1746,13 +1746,17 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
        /// only Tor Onion addresses.
        ///
        /// Panics if addresses is absurdly large (more than 500).
-       pub fn broadcast_node_announcement(&self, rgb: [u8; 3], alias: [u8; 32], addresses: Vec<NetAddress>) {
+       pub fn broadcast_node_announcement(&self, rgb: [u8; 3], alias: [u8; 32], mut addresses: Vec<NetAddress>) {
                let _persistence_guard = PersistenceNotifierGuard::new(&self.total_consistency_lock, &self.persistence_notifier);
 
                if addresses.len() > 500 {
                        panic!("More than half the message size was taken up by public addresses!");
                }
 
+               // While all existing nodes handle unsorted addresses just fine, the spec requires that
+               // addresses be sorted for future compatibility.
+               addresses.sort_by_key(|addr| addr.get_id());
+
                let announcement = msgs::UnsignedNodeAnnouncement {
                        features: NodeFeatures::known(),
                        timestamp: self.last_node_announcement_serial.fetch_add(1, Ordering::AcqRel) as u32,
@@ -2539,6 +2543,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
                                },
                        }
                        if let Some(tx) = funding_broadcastable {
+                               log_info!(self.logger, "Broadcasting funding transaction with txid {}", tx.txid());
                                self.tx_broadcaster.broadcast_transaction(&tx);
                        }
                        if let Some(msg) = funding_locked {
@@ -2694,6 +2699,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
                                hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
                        }
                };
+               log_info!(self.logger, "Broadcasting funding transaction with txid {}", funding_tx.txid());
                self.tx_broadcaster.broadcast_transaction(&funding_tx);
                Ok(())
        }
@@ -2808,7 +2814,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
                        }
                };
                if let Some(broadcast_tx) = tx {
-                       log_trace!(self.logger, "Broadcast onchain {}", log_tx!(broadcast_tx));
+                       log_info!(self.logger, "Broadcasting {}", log_tx!(broadcast_tx));
                        self.tx_broadcaster.broadcast_transaction(&broadcast_tx);
                }
                if let Some(chan) = chan_option {
index 974e30095109e3647e2acd006ce36bad03e9e928..be99596becd82d4627c21c229d9b6172ac385615 100644 (file)
@@ -390,6 +390,17 @@ pub enum NetAddress {
        },
 }
 impl NetAddress {
+       /// Gets the ID of this address type. Addresses in node_announcement messages should be sorted
+       /// by this.
+       pub(crate) fn get_id(&self) -> u8 {
+               match self {
+                       &NetAddress::IPv4 {..} => { 1 },
+                       &NetAddress::IPv6 {..} => { 2 },
+                       &NetAddress::OnionV2 {..} => { 3 },
+                       &NetAddress::OnionV3 {..} => { 4 },
+               }
+       }
+
        /// Strict byte-length of address descriptor, 1-byte type not recorded
        fn len(&self) -> u16 {
                match self {
index e154e5f8f226d73a6a2604bc0fae8d9823ac632c..053502495268bb7c184a01ccd309a98ee89ccc10 100644 (file)
@@ -742,7 +742,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
                                        self.claimable_outpoints.insert(k.clone(), (txid, height));
                                }
                                self.pending_claim_requests.insert(txid, claim_material);
-                               log_trace!(logger, "Broadcast onchain {}", log_tx!(tx));
+                               log_info!(logger, "Broadcasting onchain {}", log_tx!(tx));
                                broadcaster.broadcast_transaction(&tx);
                        }
                }
@@ -859,7 +859,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
                log_trace!(logger, "Bumping {} candidates", bump_candidates.len());
                for (first_claim_txid, claim_material) in bump_candidates.iter() {
                        if let Some((new_timer, new_feerate, bump_tx)) = self.generate_claim_tx(height, &claim_material, &*fee_estimator, &*logger) {
-                               log_trace!(logger, "Broadcast onchain {}", log_tx!(bump_tx));
+                               log_info!(logger, "Broadcasting onchain {}", log_tx!(bump_tx));
                                broadcaster.broadcast_transaction(&bump_tx);
                                if let Some(claim_material) = self.pending_claim_requests.get_mut(first_claim_txid) {
                                        claim_material.height_timer = new_timer;
@@ -926,6 +926,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
                        if let Some((new_timer, new_feerate, bump_tx)) = self.generate_claim_tx(height, &claim_material, &&*fee_estimator, &&*logger) {
                                claim_material.height_timer = new_timer;
                                claim_material.feerate_previous = new_feerate;
+                               log_info!(logger, "Broadcasting onchain {}", log_tx!(bump_tx));
                                broadcaster.broadcast_transaction(&bump_tx);
                        }
                }
index 90a1bdb4814f454de1c4f01d4639a58d36a761ac..330d31b683b56d5f8cef7ff1901061005986c083 100644 (file)
@@ -100,15 +100,15 @@ impl<'a> std::fmt::Display for DebugTx<'a> {
                if self.0.input.len() >= 1 && self.0.input.iter().any(|i| !i.witness.is_empty()) {
                        if self.0.input.len() == 1 && self.0.input[0].witness.last().unwrap().len() == 71 &&
                                        (self.0.input[0].sequence >> 8*3) as u8 == 0x80 {
-                               write!(f, "commitment tx")?;
+                               write!(f, "commitment tx ")?;
                        } else if self.0.input.len() == 1 && self.0.input[0].witness.last().unwrap().len() == 71 {
-                               write!(f, "closing tx")?;
+                               write!(f, "closing tx ")?;
                        } else if self.0.input.len() == 1 && HTLCType::scriptlen_to_htlctype(self.0.input[0].witness.last().unwrap().len()) == Some(HTLCType::OfferedHTLC) &&
                                        self.0.input[0].witness.len() == 5 {
-                               write!(f, "HTLC-timeout tx")?;
+                               write!(f, "HTLC-timeout tx ")?;
                        } else if self.0.input.len() == 1 && HTLCType::scriptlen_to_htlctype(self.0.input[0].witness.last().unwrap().len()) == Some(HTLCType::AcceptedHTLC) &&
                                        self.0.input[0].witness.len() == 5 {
-                               write!(f, "HTLC-success tx")?;
+                               write!(f, "HTLC-success tx ")?;
                        } else {
                                for inp in &self.0.input {
                                        if !inp.witness.is_empty() {
@@ -116,11 +116,13 @@ impl<'a> std::fmt::Display for DebugTx<'a> {
                                                else if HTLCType::scriptlen_to_htlctype(inp.witness.last().unwrap().len()) == Some(HTLCType::AcceptedHTLC) { write!(f, "timeout-")?; break }
                                        }
                                }
-                               write!(f, "tx")?;
+                               write!(f, "tx ")?;
                        }
                } else {
-                       write!(f, "INVALID TRANSACTION")?;
+                       debug_assert!(false, "We should never generate unknown transaction types");
+                       write!(f, "unknown tx type ").unwrap();
                }
+               write!(f, "with txid {}", self.0.txid())?;
                Ok(())
        }
 }