]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Clean up `check_channel_announcement` style
authorMatt Corallo <git@bluematt.me>
Sat, 21 Jan 2023 03:51:22 +0000 (03:51 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 8 Feb 2023 23:54:00 +0000 (23:54 +0000)
`check_channel_announcement` had long lines, a (very-)stale TODO
and confusing variable assignment, which is all cleaned up here.

lightning/src/routing/utxo.rs

index 828ea3764fb454f4ed8ef0d50719130ba941cb5c..ee56f2d928858aa8775a1f85d2211fbbc43ee094 100644 (file)
@@ -47,10 +47,10 @@ pub trait UtxoLookup {
 pub(crate) fn check_channel_announcement<U: Deref>(
        utxo_lookup: &Option<U>, msg: &msgs::UnsignedChannelAnnouncement
 ) -> Result<Option<u64>, 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<U: Deref>(
                                        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)
+       }
 }