From: bmancini55 Date: Tue, 9 Mar 2021 20:42:45 +0000 (-0500) Subject: Use scid_from_parts in Channel::block_connected X-Git-Tag: v0.0.14~48^2~5 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=dd0bb256940d885a1e8dfd3ae8be6e5ea648944e;p=rust-lightning Use scid_from_parts in Channel::block_connected Refactors validation and short_channel_id construction to use the new scid_from_parts function. --- diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 633652222..7a992f64f 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -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 Channel { } } } - 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"), + } } } }