@@ -1433,6 +1433,28 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1433
1433
return Err ( LightningError { err : "Channel announcement node had a channel with itself" . to_owned ( ) , action : ErrorAction :: IgnoreError } ) ;
1434
1434
}
1435
1435
1436
+ {
1437
+ let channels = self . channels . read ( ) . unwrap ( ) ;
1438
+
1439
+ if let Some ( chan) = channels. get ( & msg. short_channel_id ) {
1440
+ if chan. capacity_sats . is_some ( ) {
1441
+ // If we'd previously looked up the channel on-chain and checked the script
1442
+ // against what appears on-chain, ignore the duplicate announcement.
1443
+ return Err ( LightningError {
1444
+ err : "Already have chain-validated channel" . to_owned ( ) ,
1445
+ action : ErrorAction :: IgnoreDuplicateGossip
1446
+ } ) ;
1447
+ } else if chain_access. is_none ( ) {
1448
+ // Similarly, if we can't check the chain right now anyway, ignore the
1449
+ // duplicate announcement without bothering to take the channels write lock.
1450
+ return Err ( LightningError {
1451
+ err : "Already have non-chain-validated channel" . to_owned ( ) ,
1452
+ action : ErrorAction :: IgnoreDuplicateGossip
1453
+ } ) ;
1454
+ }
1455
+ }
1456
+ }
1457
+
1436
1458
let utxo_value = match & chain_access {
1437
1459
& None => {
1438
1460
// Tentatively accept, potentially exposing us to DoS attacks
@@ -2046,7 +2068,7 @@ mod tests {
2046
2068
// drop new one on the floor, since we can't see any changes.
2047
2069
match gossip_sync. handle_channel_announcement ( & valid_announcement) {
2048
2070
Ok ( _) => panic ! ( ) ,
2049
- Err ( e) => assert_eq ! ( e. err, "Already have knowledge of channel" )
2071
+ Err ( e) => assert_eq ! ( e. err, "Already have non-chain-validated channel" )
2050
2072
} ;
2051
2073
2052
2074
// Test if an associated transaction were not on-chain (or not confirmed).
@@ -2080,32 +2102,13 @@ mod tests {
2080
2102
} ;
2081
2103
}
2082
2104
2083
- // If we receive announcement for the same channel (but TX is not confirmed),
2084
- // drop new one on the floor, since we can't see any changes.
2085
- * chain_source. utxo_ret . lock ( ) . unwrap ( ) = Err ( chain:: AccessError :: UnknownTx ) ;
2086
- match gossip_sync. handle_channel_announcement ( & valid_announcement) {
2087
- Ok ( _) => panic ! ( ) ,
2088
- Err ( e) => assert_eq ! ( e. err, "Channel announced without corresponding UTXO entry" )
2089
- } ;
2090
-
2091
- // But if it is confirmed, replace the channel
2105
+ // If we receive announcement for the same channel, once we've validated it against the
2106
+ // chain, we simply ignore all new (duplicate) announcements.
2092
2107
* chain_source. utxo_ret . lock ( ) . unwrap ( ) = Ok ( TxOut { value : 0 , script_pubkey : good_script } ) ;
2093
- let valid_announcement = get_signed_channel_announcement ( |unsigned_announcement| {
2094
- unsigned_announcement. features = ChannelFeatures :: empty ( ) ;
2095
- unsigned_announcement. short_channel_id += 2 ;
2096
- } , node_1_privkey, node_2_privkey, & secp_ctx) ;
2097
2108
match gossip_sync. handle_channel_announcement ( & valid_announcement) {
2098
- Ok ( res ) => assert ! ( res ) ,
2099
- _ => panic ! ( )
2109
+ Ok ( _ ) => panic ! ( ) ,
2110
+ Err ( e ) => assert_eq ! ( e . err , "Already have chain-validated channel" )
2100
2111
} ;
2101
- {
2102
- match network_graph. read_only ( ) . channels ( ) . get ( & valid_announcement. contents . short_channel_id ) {
2103
- Some ( channel_entry) => {
2104
- assert_eq ! ( channel_entry. features, ChannelFeatures :: empty( ) ) ;
2105
- } ,
2106
- _ => panic ! ( )
2107
- } ;
2108
- }
2109
2112
2110
2113
// Don't relay valid channels with excess data
2111
2114
let valid_announcement = get_signed_channel_announcement ( |unsigned_announcement| {
0 commit comments