Skip to content

Commit cb83937

Browse files
committed
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.
1 parent 750d58e commit cb83937

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

lightning/src/routing/gossip_checking.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,39 @@ pub trait ChainAccess {
3737
pub(crate) fn check_channel_announcement<A: Deref>(
3838
chain_access: &Option<A>, msg: &msgs::UnsignedChannelAnnouncement
3939
) -> Result<Option<u64>, msgs::LightningError> where A::Target: ChainAccess {
40-
let utxo_value = match chain_access {
40+
match chain_access {
4141
&None => {
4242
// Tentatively accept, potentially exposing us to DoS attacks
43-
None
43+
Ok(None)
4444
},
4545
&Some(ref chain_access) => {
4646
match chain_access.get_utxo(&msg.chain_hash, msg.short_channel_id) {
4747
Ok(TxOut { value, script_pubkey }) => {
4848
let expected_script =
4949
make_funding_redeemscript(&msg.bitcoin_key_1, &msg.bitcoin_key_2).to_v0_p2wsh();
5050
if script_pubkey != expected_script {
51-
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});
51+
return Err(LightningError{
52+
err: format!("Channel announcement key ({}) didn't match on-chain script ({})",
53+
expected_script.to_hex(), script_pubkey.to_hex()),
54+
action: ErrorAction::IgnoreError
55+
});
5256
}
53-
//TODO: Check if value is worth storing, use it to inform routing, and compare it
54-
//to the new HTLC max field in channel_update
55-
Some(value)
57+
Ok(Some(value))
5658
},
5759
Err(ChainAccessError::UnknownChain) => {
58-
return Err(LightningError{err: format!("Channel announced on an unknown chain ({})", msg.chain_hash.encode().to_hex()), action: ErrorAction::IgnoreError});
60+
Err(LightningError {
61+
err: format!("Channel announced on an unknown chain ({})",
62+
msg.chain_hash.encode().to_hex()),
63+
action: ErrorAction::IgnoreError
64+
})
5965
},
6066
Err(ChainAccessError::UnknownTx) => {
61-
return Err(LightningError{err: "Channel announced without corresponding UTXO entry".to_owned(), action: ErrorAction::IgnoreError});
67+
Err(LightningError {
68+
err: "Channel announced without corresponding UTXO entry".to_owned(),
69+
action: ErrorAction::IgnoreError
70+
})
6271
},
6372
}
6473
}
65-
};
66-
Ok(utxo_value)
74+
}
6775
}

0 commit comments

Comments
 (0)