Use scid_from_parts in Channel::block_connected
authorbmancini55 <bmancini@gmail.com>
Tue, 9 Mar 2021 20:42:45 +0000 (15:42 -0500)
committerbmancini55 <bmancini@gmail.com>
Tue, 9 Mar 2021 20:42:45 +0000 (15:42 -0500)
Refactors validation and short_channel_id construction to use
the new scid_from_parts function.

lightning/src/ln/channel.rs

index 633652222d11352f64be2f1f13a75d543e07eca4..7a992f64f1e29b65b0a8ba0d31024407a1b98954 100644 (file)
@@ -37,6 +37,7 @@ use util::ser::{Readable, ReadableArgs, Writeable, Writer, VecWriter};
 use util::logger::Logger;
 use util::errors::APIError;
 use util::config::{UserConfig,ChannelConfig};
+use util::scid_utils::scid_from_parts;
 
 use std;
 use std::default::Default;
@@ -3556,14 +3557,11 @@ impl<Signer: Sign> Channel<Signer> {
                                                                }
                                                        }
                                                }
-                                               if height > 0xff_ff_ff || (index_in_block) > 0xff_ff_ff {
-                                                       panic!("Block was bogus - either height 16 million or had > 16 million transactions");
-                                               }
-                                               assert!(txo_idx <= 0xffff); // txo_idx is a (u16 as usize), so this is just listed here for completeness
                                                self.funding_tx_confirmations = 1;
-                                               self.short_channel_id = Some(((height as u64)         << (5*8)) |
-                                                                            ((index_in_block as u64) << (2*8)) |
-                                                                            ((txo_idx as u64)        << (0*8)));
+                                               self.short_channel_id = match scid_from_parts(height as u64, index_in_block as u64, txo_idx as u64) {
+                                                       Ok(scid) => Some(scid),
+                                                       Err(_) => panic!("Block was bogus - either height was > 16 million, had > 16 million transactions, or had > 65k outputs"),
+                                               }
                                        }
                                }
                        }