From: Matt Corallo Date: Sat, 21 Jan 2023 03:51:22 +0000 (+0000) Subject: Clean up `check_channel_announcement` style X-Git-Tag: v0.0.114-beta~22^2~12 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=1e8553fc675698bd3142459ad6421d5bd7aa72c7;p=rust-lightning Clean up `check_channel_announcement` style `check_channel_announcement` had long lines, a (very-)stale TODO and confusing variable assignment, which is all cleaned up here. --- diff --git a/lightning/src/routing/utxo.rs b/lightning/src/routing/utxo.rs index 828ea3764..ee56f2d92 100644 --- a/lightning/src/routing/utxo.rs +++ b/lightning/src/routing/utxo.rs @@ -47,10 +47,10 @@ pub trait UtxoLookup { pub(crate) fn check_channel_announcement( utxo_lookup: &Option, msg: &msgs::UnsignedChannelAnnouncement ) -> Result, msgs::LightningError> where U::Target: UtxoLookup { - let utxo_value = match utxo_lookup { + match utxo_lookup { &None => { // Tentatively accept, potentially exposing us to DoS attacks - None + Ok(None) }, &Some(ref utxo_lookup) => { match utxo_lookup.get_utxo(&msg.chain_hash, msg.short_channel_id) { @@ -58,20 +58,28 @@ pub(crate) fn check_channel_announcement( let expected_script = make_funding_redeemscript_from_slices(msg.bitcoin_key_1.as_slice(), msg.bitcoin_key_2.as_slice()).to_v0_p2wsh(); if script_pubkey != expected_script { - return Err(LightningError{err: format!("Channel announcement key ({}) didn't match on-chain script ({})", expected_script.to_hex(), script_pubkey.to_hex()), action: ErrorAction::IgnoreError}); + return Err(LightningError{ + err: format!("Channel announcement key ({}) didn't match on-chain script ({})", + expected_script.to_hex(), script_pubkey.to_hex()), + action: ErrorAction::IgnoreError + }); } - //TODO: Check if value is worth storing, use it to inform routing, and compare it - //to the new HTLC max field in channel_update - Some(value) + Ok(Some(value)) }, Err(UtxoLookupError::UnknownChain) => { - return Err(LightningError{err: format!("Channel announced on an unknown chain ({})", msg.chain_hash.encode().to_hex()), action: ErrorAction::IgnoreError}); + Err(LightningError { + err: format!("Channel announced on an unknown chain ({})", + msg.chain_hash.encode().to_hex()), + action: ErrorAction::IgnoreError + }) }, Err(UtxoLookupError::UnknownTx) => { - return Err(LightningError{err: "Channel announced without corresponding UTXO entry".to_owned(), action: ErrorAction::IgnoreError}); + Err(LightningError { + err: "Channel announced without corresponding UTXO entry".to_owned(), + action: ErrorAction::IgnoreError + }) }, } } - }; - Ok(utxo_value) + } }