@@ -2070,7 +2070,7 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement(
2070
2070
// A new authenticated channel edge update has arrived. This indicates
2071
2071
// that the directional information for an already known channel has
2072
2072
// been updated.
2073
- case * lnwire.ChannelUpdate1 :
2073
+ case lnwire.ChannelUpdate :
2074
2074
return d .handleChanUpdate (nMsg , msg , schedulerOp )
2075
2075
2076
2076
// A new signature announcement has been received. This indicates
@@ -2825,40 +2825,45 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
2825
2825
2826
2826
// handleChanUpdate processes a new channel update.
2827
2827
func (d * AuthenticatedGossiper ) handleChanUpdate (nMsg * networkMsg ,
2828
- upd * lnwire.ChannelUpdate1 ,
2829
- ops []batch. SchedulerOption ) ([] networkMsg , bool ) {
2828
+ upd lnwire.ChannelUpdate , ops []batch. SchedulerOption ) ([] networkMsg ,
2829
+ bool ) {
2830
2830
2831
- log .Debugf ("Processing ChannelUpdate1: peer=%v, short_chan_id=%v, " ,
2832
- nMsg .peer , upd .ShortChannelID .ToUint64 ())
2831
+ var (
2832
+ scid = upd .SCID ()
2833
+ chainHash = upd .GetChainHash ()
2834
+ )
2835
+
2836
+ log .Debugf ("Processing ChannelUpdate: peer=%v, short_chan_id=%v, " ,
2837
+ nMsg .peer , scid )
2833
2838
2834
2839
// We'll ignore any channel updates that target any chain other than
2835
2840
// the set of chains we know of.
2836
- if ! bytes .Equal (upd .ChainHash [:], d .cfg .ChainHash [:]) {
2837
- err := fmt .Errorf ("ignoring ChannelUpdate1 from chain=%v, " +
2838
- "gossiper on chain=%v" , upd .ChainHash , d .cfg .ChainHash )
2841
+ if ! bytes .Equal (chainHash [:], d .cfg .ChainHash [:]) {
2842
+ err := fmt .Errorf ("ignoring %s from chain=%v, " +
2843
+ "gossiper on chain=%v" , upd .MsgType (), chainHash ,
2844
+ d .cfg .ChainHash )
2839
2845
log .Errorf (err .Error ())
2840
2846
2841
2847
key := newRejectCacheKey (
2842
- upd .ShortChannelID .ToUint64 (),
2843
- sourceToPub (nMsg .source ),
2848
+ scid .ToUint64 (), sourceToPub (nMsg .source ),
2844
2849
)
2845
2850
_ , _ = d .recentRejects .Put (key , & cachedReject {})
2846
2851
2847
2852
nMsg .err <- err
2848
2853
return nil , false
2849
2854
}
2850
2855
2851
- blockHeight := upd .ShortChannelID .BlockHeight
2852
- shortChanID := upd .ShortChannelID .ToUint64 ()
2856
+ blockHeight := upd .SCID () .BlockHeight
2857
+ shortChanID := upd .SCID () .ToUint64 ()
2853
2858
2854
2859
// If the advertised inclusionary block is beyond our knowledge of the
2855
2860
// chain tip, then we'll put the announcement in limbo to be fully
2856
2861
// verified once we advance forward in the chain. If the update has an
2857
2862
// alias SCID, we'll skip the isPremature check. This is necessary
2858
2863
// since aliases start at block height 16_000_000.
2859
2864
d .Lock ()
2860
- if nMsg .isRemote && ! d .cfg .IsAlias (upd . ShortChannelID ) &&
2861
- d .isPremature (upd . ShortChannelID , 0 , nMsg ) {
2865
+ if nMsg .isRemote && ! d .cfg .IsAlias (scid ) &&
2866
+ d .isPremature (scid , 0 , nMsg ) {
2862
2867
2863
2868
log .Warnf ("Update announcement for short_chan_id(%v), is " +
2864
2869
"premature: advertises height %v, only height %v is " +
@@ -2869,31 +2874,28 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
2869
2874
}
2870
2875
d .Unlock ()
2871
2876
2872
- // Before we perform any of the expensive checks below, we'll check
2873
- // whether this update is stale or is for a zombie channel in order to
2874
- // quickly reject it.
2875
- timestamp := time .Unix (int64 (upd .Timestamp ), 0 )
2876
-
2877
2877
// Fetch the SCID we should be using to lock the channelMtx and make
2878
2878
// graph queries with.
2879
- graphScid , err := d .cfg .FindBaseByAlias (upd . ShortChannelID )
2879
+ graphScid , err := d .cfg .FindBaseByAlias (scid )
2880
2880
if err != nil {
2881
2881
// Fallback and set the graphScid to the peer-provided SCID.
2882
2882
// This will occur for non-option-scid-alias channels and for
2883
2883
// public option-scid-alias channels after 6 confirmations.
2884
2884
// Once public option-scid-alias channels have 6 confs, we'll
2885
2885
// ignore ChannelUpdates with one of their aliases.
2886
- graphScid = upd . ShortChannelID
2886
+ graphScid = scid
2887
2887
}
2888
2888
2889
+ // Before we perform any of the expensive checks below, we'll check
2890
+ // whether this update is stale or is for a zombie channel in order to
2891
+ // quickly reject it.
2889
2892
if d .cfg .Router .IsStaleEdgePolicy (graphScid , upd ) {
2890
2893
log .Debugf ("Ignored stale edge policy for short_chan_id(%v): " +
2891
2894
"peer=%v, msg=%s, is_remote=%v" , shortChanID ,
2892
2895
nMsg .peer , nMsg .msg .MsgType (), nMsg .isRemote ,
2893
2896
)
2894
2897
2895
2898
nMsg .err <- nil
2896
-
2897
2899
return nil , true
2898
2900
}
2899
2901
@@ -2935,7 +2937,7 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
2935
2937
// If the edge corresponding to this ChannelUpdate1 was not
2936
2938
// found in the graph, this might be a channel in the process
2937
2939
// of being opened, and we haven't processed our own
2938
- // ChannelAnnouncement1 yet, hence it is not found in the
2940
+ // ChannelAnnouncement yet, hence it is not found in the
2939
2941
// graph. This usually gets resolved after the channel proofs
2940
2942
// are exchanged and the channel is broadcasted to the rest of
2941
2943
// the network, but in case this is a private channel this
@@ -2972,7 +2974,7 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
2972
2974
})
2973
2975
}
2974
2976
2975
- log .Debugf ("Got ChannelUpdate1 for edge not found in graph" +
2977
+ log .Debugf ("Got ChannelUpdate for edge not found in graph" +
2976
2978
"(shortChanID=%v), saving for reprocessing later" ,
2977
2979
shortChanID )
2978
2980
@@ -2988,7 +2990,7 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
2988
2990
nMsg .err <- err
2989
2991
2990
2992
key := newRejectCacheKey (
2991
- upd . ShortChannelID .ToUint64 (),
2993
+ scid .ToUint64 (),
2992
2994
sourceToPub (nMsg .source ),
2993
2995
)
2994
2996
_ , _ = d .recentRejects .Put (key , & cachedReject {})
@@ -3002,21 +3004,20 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
3002
3004
var (
3003
3005
pubKey * btcec.PublicKey
3004
3006
edgeToUpdate models.ChannelEdgePolicy
3007
+ direction int
3005
3008
)
3006
- direction := upd .ChannelFlags & lnwire .ChanUpdateDirection
3007
- switch direction {
3008
- case 0 :
3009
+ if upd .IsNode1 () {
3009
3010
pubKey , _ = chanInfo .NodeKey1 ()
3010
3011
edgeToUpdate = e1
3011
- case 1 :
3012
+ direction = 0
3013
+ } else {
3012
3014
pubKey , _ = chanInfo .NodeKey2 ()
3013
3015
edgeToUpdate = e2
3016
+ direction = 1
3014
3017
}
3015
3018
3016
- var chanID = chanInfo .GetChanID ()
3017
-
3018
3019
log .Debugf ("Validating ChannelUpdate1: channel=%v, from node=%x, has " +
3019
- "edge=%v" , chanID , pubKey .SerializeCompressed (),
3020
+ "edge=%v" , chanInfo . GetChanID () , pubKey .SerializeCompressed (),
3020
3021
edgeToUpdate != nil )
3021
3022
3022
3023
// Validate the channel announcement with the expected public key and
@@ -3028,7 +3029,7 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
3028
3029
if err != nil {
3029
3030
rErr := fmt .Errorf ("unable to validate channel update " +
3030
3031
"announcement for short_chan_id=%v: %v" ,
3031
- spew .Sdump (upd . ShortChannelID ), err )
3032
+ spew .Sdump (scid ), err )
3032
3033
3033
3034
log .Error (rErr )
3034
3035
nMsg .err <- rErr
@@ -3038,24 +3039,11 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
3038
3039
// If we have a previous version of the edge being updated, we'll want
3039
3040
// to rate limit its updates to prevent spam throughout the network.
3040
3041
if nMsg .isRemote && edgeToUpdate != nil {
3041
- edge , ok := edgeToUpdate .(* models.ChannelEdgePolicy1 )
3042
- if ! ok {
3043
- rErr := fmt .Errorf ("expected " +
3044
- "*models.ChannelEdgePolicy1, got: %T" ,
3045
- edgeToUpdate )
3046
-
3047
- log .Error (rErr )
3048
- nMsg .err <- rErr
3049
-
3050
- return nil , false
3051
- }
3052
-
3053
3042
// If it's a keep-alive update, we'll only propagate one if
3054
3043
// it's been a day since the previous. This follows our own
3055
3044
// heuristic of sending keep-alive updates after the same
3056
3045
// duration (see retransmitStaleAnns).
3057
- timeSinceLastUpdate := timestamp .Sub (edge .LastUpdate )
3058
- isKeepAlive , err := IsKeepAliveUpdate (upd , edge )
3046
+ isKeepAlive , err := IsKeepAliveUpdate (upd , edgeToUpdate )
3059
3047
if err != nil {
3060
3048
log .Errorf ("Could not determine if update is " +
3061
3049
"keepalive: %v" , err )
@@ -3065,7 +3053,18 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
3065
3053
}
3066
3054
3067
3055
if isKeepAlive {
3068
- if timeSinceLastUpdate < d .cfg .RebroadcastInterval {
3056
+ within , err := d .updateWithinRebroadcastInterval (
3057
+ upd , edgeToUpdate ,
3058
+ )
3059
+ if err != nil {
3060
+ log .Errorf ("Could not determine if update is " +
3061
+ "within rebroadcast interval: %v" , err )
3062
+ nMsg .err <- err
3063
+
3064
+ return nil , false
3065
+ }
3066
+
3067
+ if ! within {
3069
3068
log .Debugf ("Ignoring keep alive update not " +
3070
3069
"within %v period for channel %v" ,
3071
3070
d .cfg .RebroadcastInterval , shortChanID )
@@ -3084,7 +3083,7 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
3084
3083
// multiple aliases for a channel and we may otherwise
3085
3084
// rate-limit only a single alias of the channel,
3086
3085
// instead of the whole channel.
3087
- baseScid := chanID
3086
+ baseScid := chanInfo . GetChanID ()
3088
3087
d .Lock ()
3089
3088
rls , ok := d .chanUpdateRateLimiter [baseScid ]
3090
3089
if ! ok {
@@ -3115,18 +3114,22 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
3115
3114
// different alias. This might mean that SigBytes is incorrect as it
3116
3115
// signs a different SCID than the database SCID, but since there will
3117
3116
// only be a difference if AuthProof == nil, this is fine.
3118
- update := & models.ChannelEdgePolicy1 {
3119
- SigBytes : upd .Signature .ToSignatureBytes (),
3120
- ChannelID : chanID ,
3121
- LastUpdate : timestamp ,
3122
- MessageFlags : upd .MessageFlags ,
3123
- ChannelFlags : upd .ChannelFlags ,
3124
- TimeLockDelta : upd .TimeLockDelta ,
3125
- MinHTLC : upd .HtlcMinimumMsat ,
3126
- MaxHTLC : upd .HtlcMaximumMsat ,
3127
- FeeBaseMSat : lnwire .MilliSatoshi (upd .BaseFee ),
3128
- FeeProportionalMillionths : lnwire .MilliSatoshi (upd .FeeRate ),
3129
- ExtraOpaqueData : upd .ExtraOpaqueData ,
3117
+ update , err := models .EdgePolicyFromUpdate (upd )
3118
+ if err != nil {
3119
+ rErr := fmt .Errorf ("unable to convert update to policy for " +
3120
+ "short_chan_id=%v: %v" , spew .Sdump (scid ), err )
3121
+
3122
+ log .Error (rErr )
3123
+ nMsg .err <- rErr
3124
+ return nil , false
3125
+ }
3126
+ switch upd := update .(type ) {
3127
+ case * models.ChannelEdgePolicy1 :
3128
+ upd .ChannelID = chanInfo .GetChanID ()
3129
+ case * models.ChannelEdgePolicy2 :
3130
+ upd .ShortChannelID = lnwire .NewShortChanIDFromInt (
3131
+ chanInfo .GetChanID (),
3132
+ )
3130
3133
}
3131
3134
3132
3135
if err := d .cfg .Router .UpdateEdge (update , ops ... ); err != nil {
@@ -3142,7 +3145,8 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
3142
3145
// Since we know the stored SCID in the graph, we'll
3143
3146
// cache that SCID.
3144
3147
key := newRejectCacheKey (
3145
- chanID , sourceToPub (nMsg .source ),
3148
+ chanInfo .GetChanID (),
3149
+ sourceToPub (nMsg .source ),
3146
3150
)
3147
3151
_ , _ = d .recentRejects .Put (key , & cachedReject {})
3148
3152
@@ -3151,32 +3155,33 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
3151
3155
}
3152
3156
3153
3157
nMsg .err <- err
3158
+
3154
3159
return nil , false
3155
3160
}
3156
3161
3157
3162
// If this is a local ChannelUpdate1 without an AuthProof, it means it
3158
3163
// is an update to a channel that is not (yet) supposed to be announced
3159
- // to the greater network. However, our channel counter party will need
3164
+ // to the greater network. However, our channel counterparty will need
3160
3165
// to be given the update, so we'll try sending the update directly to
3161
3166
// the remote peer.
3162
3167
if ! nMsg .isRemote && chanInfo .GetAuthProof () == nil {
3163
- if nMsg .optionalMsgFields != nil {
3168
+ if nMsg .optionalMsgFields != nil &&
3169
+ nMsg .optionalMsgFields .remoteAlias != nil {
3170
+
3171
+ // The remoteAlias field was specified, meaning
3172
+ // that we should replace the SCID in the
3173
+ // update with the remote's alias. We'll also
3174
+ // need to re-sign the channel update. This is
3175
+ // required for option-scid-alias feature-bit
3176
+ // negotiated channels.
3164
3177
remoteAlias := nMsg .optionalMsgFields .remoteAlias
3165
- if remoteAlias != nil {
3166
- // The remoteAlias field was specified, meaning
3167
- // that we should replace the SCID in the
3168
- // update with the remote's alias. We'll also
3169
- // need to re-sign the channel update. This is
3170
- // required for option-scid-alias feature-bit
3171
- // negotiated channels.
3172
- upd .ShortChannelID = * remoteAlias
3173
-
3174
- err := d .cfg .SignAliasUpdate (upd )
3175
- if err != nil {
3176
- log .Error (err )
3177
- nMsg .err <- err
3178
- return nil , false
3179
- }
3178
+ upd .SetSCID (* remoteAlias )
3179
+
3180
+ err := d .cfg .SignAliasUpdate (upd )
3181
+ if err != nil {
3182
+ log .Error (err )
3183
+ nMsg .err <- err
3184
+ return nil , false
3180
3185
}
3181
3186
}
3182
3187
@@ -3193,7 +3198,7 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
3193
3198
if err != nil {
3194
3199
err := fmt .Errorf ("unable to reliably send %v for " +
3195
3200
"channel=%v to peer=%x: %v" , upd .MsgType (),
3196
- upd . ShortChannelID , remotePubKey , err )
3201
+ scid , remotePubKey , err )
3197
3202
nMsg .err <- err
3198
3203
return nil , false
3199
3204
}
@@ -3206,7 +3211,7 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
3206
3211
// contains an alias because the network would reject this.
3207
3212
var announcements []networkMsg
3208
3213
if chanInfo .GetAuthProof () != nil &&
3209
- ! d .cfg .IsAlias (upd . ShortChannelID ) {
3214
+ ! d .cfg .IsAlias (scid ) {
3210
3215
3211
3216
announcements = append (announcements , networkMsg {
3212
3217
peer : nMsg .peer ,
@@ -3218,9 +3223,9 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
3218
3223
3219
3224
nMsg .err <- nil
3220
3225
3221
- log .Debugf ("Processed ChannelUpdate1 : peer=%v, short_chan_id=%v, " +
3222
- "timestamp=%v" , nMsg .peer , upd . ShortChannelID . ToUint64 (),
3223
- timestamp )
3226
+ log .Debugf ("Processed %s : peer=%v, short_chan_id=%v, " , upd . MsgType (),
3227
+ nMsg .peer , scid . ToUint64 ())
3228
+
3224
3229
return announcements , true
3225
3230
}
3226
3231
@@ -3646,6 +3651,38 @@ func (d *AuthenticatedGossiper) handleAnnSig(nMsg *networkMsg,
3646
3651
return announcements , true
3647
3652
}
3648
3653
3654
+ func (d * AuthenticatedGossiper ) updateWithinRebroadcastInterval (
3655
+ upd lnwire.ChannelUpdate , policy models.ChannelEdgePolicy ) (bool ,
3656
+ error ) {
3657
+
3658
+ switch update := upd .(type ) {
3659
+ case * lnwire.ChannelUpdate1 :
3660
+ pol , ok := policy .(* models.ChannelEdgePolicy1 )
3661
+ if ! ok {
3662
+ return false , fmt .Errorf ("expected chan edge policy 1" )
3663
+ }
3664
+
3665
+ timestamp := time .Unix (int64 (update .Timestamp ), 0 )
3666
+ timeSinceLastUpdate := timestamp .Sub (pol .LastUpdate )
3667
+
3668
+ return timeSinceLastUpdate >= d .cfg .RebroadcastInterval , nil
3669
+
3670
+ case * lnwire.ChannelUpdate2 :
3671
+ pol , ok := policy .(* models.ChannelEdgePolicy2 )
3672
+ if ! ok {
3673
+ return false , fmt .Errorf ("expected chan edge policy 2" )
3674
+ }
3675
+
3676
+ blocksSinceLastUpdate := update .BlockHeight - pol .BlockHeight
3677
+
3678
+ return blocksSinceLastUpdate >=
3679
+ uint32 (d .cfg .RebroadcastInterval .Hours ()* 6 ), nil
3680
+
3681
+ default :
3682
+ return false , fmt .Errorf ("unhandled impl of Chan Update" )
3683
+ }
3684
+ }
3685
+
3649
3686
func buildChanProof (ann lnwire.ChannelAnnouncement ) (
3650
3687
models.ChannelAuthProof , error ) {
3651
3688
0 commit comments