@@ -2100,7 +2100,7 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement(
2100
2100
// A new authenticated channel edge update has arrived. This indicates
2101
2101
// that the directional information for an already known channel has
2102
2102
// been updated.
2103
- case * lnwire.ChannelUpdate1 :
2103
+ case lnwire.ChannelUpdate :
2104
2104
return d .handleChanUpdate (nMsg , msg , schedulerOp )
2105
2105
2106
2106
// A new signature announcement has been received. This indicates
@@ -2861,40 +2861,45 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
2861
2861
2862
2862
// handleChanUpdate processes a new channel update.
2863
2863
func (d * AuthenticatedGossiper ) handleChanUpdate (nMsg * networkMsg ,
2864
- upd * lnwire.ChannelUpdate1 ,
2865
- ops []batch. SchedulerOption ) ([] networkMsg , bool ) {
2864
+ upd lnwire.ChannelUpdate , ops []batch. SchedulerOption ) ([] networkMsg ,
2865
+ bool ) {
2866
2866
2867
- log .Debugf ("Processing ChannelUpdate1: peer=%v, short_chan_id=%v, " ,
2868
- nMsg .peer , upd .ShortChannelID .ToUint64 ())
2867
+ var (
2868
+ scid = upd .SCID ()
2869
+ chainHash = upd .GetChainHash ()
2870
+ )
2871
+
2872
+ log .Debugf ("Processing ChannelUpdate: peer=%v, short_chan_id=%v, " ,
2873
+ nMsg .peer , scid )
2869
2874
2870
2875
// We'll ignore any channel updates that target any chain other than
2871
2876
// the set of chains we know of.
2872
- if ! bytes .Equal (upd .ChainHash [:], d .cfg .ChainHash [:]) {
2873
- err := fmt .Errorf ("ignoring ChannelUpdate1 from chain=%v, " +
2874
- "gossiper on chain=%v" , upd .ChainHash , d .cfg .ChainHash )
2877
+ if ! bytes .Equal (chainHash [:], d .cfg .ChainHash [:]) {
2878
+ err := fmt .Errorf ("ignoring %s from chain=%v, " +
2879
+ "gossiper on chain=%v" , upd .MsgType (), chainHash ,
2880
+ d .cfg .ChainHash )
2875
2881
log .Errorf (err .Error ())
2876
2882
2877
2883
key := newRejectCacheKey (
2878
- upd .ShortChannelID .ToUint64 (),
2879
- sourceToPub (nMsg .source ),
2884
+ scid .ToUint64 (), sourceToPub (nMsg .source ),
2880
2885
)
2881
2886
_ , _ = d .recentRejects .Put (key , & cachedReject {})
2882
2887
2883
2888
nMsg .err <- err
2884
2889
return nil , false
2885
2890
}
2886
2891
2887
- blockHeight := upd .ShortChannelID .BlockHeight
2888
- shortChanID := upd .ShortChannelID .ToUint64 ()
2892
+ blockHeight := upd .SCID () .BlockHeight
2893
+ shortChanID := upd .SCID () .ToUint64 ()
2889
2894
2890
2895
// If the advertised inclusionary block is beyond our knowledge of the
2891
2896
// chain tip, then we'll put the announcement in limbo to be fully
2892
2897
// verified once we advance forward in the chain. If the update has an
2893
2898
// alias SCID, we'll skip the isPremature check. This is necessary
2894
2899
// since aliases start at block height 16_000_000.
2895
2900
d .Lock ()
2896
- if nMsg .isRemote && ! d .cfg .IsAlias (upd . ShortChannelID ) &&
2897
- d .isPremature (upd . ShortChannelID , 0 , nMsg ) {
2901
+ if nMsg .isRemote && ! d .cfg .IsAlias (scid ) &&
2902
+ d .isPremature (scid , 0 , nMsg ) {
2898
2903
2899
2904
log .Warnf ("Update announcement for short_chan_id(%v), is " +
2900
2905
"premature: advertises height %v, only height %v is " +
@@ -2905,31 +2910,28 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
2905
2910
}
2906
2911
d .Unlock ()
2907
2912
2908
- // Before we perform any of the expensive checks below, we'll check
2909
- // whether this update is stale or is for a zombie channel in order to
2910
- // quickly reject it.
2911
- timestamp := time .Unix (int64 (upd .Timestamp ), 0 )
2912
-
2913
2913
// Fetch the SCID we should be using to lock the channelMtx and make
2914
2914
// graph queries with.
2915
- graphScid , err := d .cfg .FindBaseByAlias (upd . ShortChannelID )
2915
+ graphScid , err := d .cfg .FindBaseByAlias (scid )
2916
2916
if err != nil {
2917
2917
// Fallback and set the graphScid to the peer-provided SCID.
2918
2918
// This will occur for non-option-scid-alias channels and for
2919
2919
// public option-scid-alias channels after 6 confirmations.
2920
2920
// Once public option-scid-alias channels have 6 confs, we'll
2921
2921
// ignore ChannelUpdates with one of their aliases.
2922
- graphScid = upd . ShortChannelID
2922
+ graphScid = scid
2923
2923
}
2924
2924
2925
+ // Before we perform any of the expensive checks below, we'll check
2926
+ // whether this update is stale or is for a zombie channel in order to
2927
+ // quickly reject it.
2925
2928
if d .cfg .Router .IsStaleEdgePolicy (graphScid , upd ) {
2926
2929
log .Debugf ("Ignored stale edge policy for short_chan_id(%v): " +
2927
2930
"peer=%v, msg=%s, is_remote=%v" , shortChanID ,
2928
2931
nMsg .peer , nMsg .msg .MsgType (), nMsg .isRemote ,
2929
2932
)
2930
2933
2931
2934
nMsg .err <- nil
2932
-
2933
2935
return nil , true
2934
2936
}
2935
2937
@@ -2971,7 +2973,7 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
2971
2973
// If the edge corresponding to this ChannelUpdate1 was not
2972
2974
// found in the graph, this might be a channel in the process
2973
2975
// of being opened, and we haven't processed our own
2974
- // ChannelAnnouncement1 yet, hence it is not found in the
2976
+ // ChannelAnnouncement yet, hence it is not found in the
2975
2977
// graph. This usually gets resolved after the channel proofs
2976
2978
// are exchanged and the channel is broadcasted to the rest of
2977
2979
// the network, but in case this is a private channel this
@@ -3008,7 +3010,7 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
3008
3010
})
3009
3011
}
3010
3012
3011
- log .Debugf ("Got ChannelUpdate1 for edge not found in graph" +
3013
+ log .Debugf ("Got ChannelUpdate for edge not found in graph" +
3012
3014
"(shortChanID=%v), saving for reprocessing later" ,
3013
3015
shortChanID )
3014
3016
@@ -3024,7 +3026,7 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
3024
3026
nMsg .err <- err
3025
3027
3026
3028
key := newRejectCacheKey (
3027
- upd . ShortChannelID .ToUint64 (),
3029
+ scid .ToUint64 (),
3028
3030
sourceToPub (nMsg .source ),
3029
3031
)
3030
3032
_ , _ = d .recentRejects .Put (key , & cachedReject {})
@@ -3038,21 +3040,20 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
3038
3040
var (
3039
3041
pubKey * btcec.PublicKey
3040
3042
edgeToUpdate models.ChannelEdgePolicy
3043
+ direction int
3041
3044
)
3042
- direction := upd .ChannelFlags & lnwire .ChanUpdateDirection
3043
- switch direction {
3044
- case 0 :
3045
+ if upd .IsNode1 () {
3045
3046
pubKey , _ = chanInfo .NodeKey1 ()
3046
3047
edgeToUpdate = e1
3047
- case 1 :
3048
+ direction = 0
3049
+ } else {
3048
3050
pubKey , _ = chanInfo .NodeKey2 ()
3049
3051
edgeToUpdate = e2
3052
+ direction = 1
3050
3053
}
3051
3054
3052
- var chanID = chanInfo .GetChanID ()
3053
-
3054
3055
log .Debugf ("Validating ChannelUpdate1: channel=%v, from node=%x, has " +
3055
- "edge=%v" , chanID , pubKey .SerializeCompressed (),
3056
+ "edge=%v" , chanInfo . GetChanID () , pubKey .SerializeCompressed (),
3056
3057
edgeToUpdate != nil )
3057
3058
3058
3059
// Validate the channel announcement with the expected public key and
@@ -3064,38 +3065,21 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
3064
3065
if err != nil {
3065
3066
rErr := fmt .Errorf ("unable to validate channel update " +
3066
3067
"announcement for short_chan_id=%v: %v" ,
3067
- spew .Sdump (upd . ShortChannelID ), err )
3068
+ spew .Sdump (scid ), err )
3068
3069
3069
3070
log .Error (rErr )
3070
3071
nMsg .err <- rErr
3071
3072
return nil , false
3072
3073
}
3073
3074
3074
- var edge * models.ChannelEdgePolicy1
3075
- if edgeToUpdate != nil {
3076
- var ok bool
3077
- edge , ok = edgeToUpdate .(* models.ChannelEdgePolicy1 )
3078
- if ! ok {
3079
- rErr := fmt .Errorf ("expected " +
3080
- "*models.ChannelEdgePolicy1, got: %T" ,
3081
- edgeToUpdate )
3082
-
3083
- log .Error (rErr )
3084
- nMsg .err <- rErr
3085
-
3086
- return nil , false
3087
- }
3088
- }
3089
-
3090
3075
// If we have a previous version of the edge being updated, we'll want
3091
3076
// to rate limit its updates to prevent spam throughout the network.
3092
- if nMsg .isRemote && edge != nil {
3077
+ if nMsg .isRemote && edgeToUpdate != nil {
3093
3078
// If it's a keep-alive update, we'll only propagate one if
3094
3079
// it's been a day since the previous. This follows our own
3095
3080
// heuristic of sending keep-alive updates after the same
3096
3081
// duration (see retransmitStaleAnns).
3097
- timeSinceLastUpdate := timestamp .Sub (edge .LastUpdate )
3098
- isKeepAlive , err := IsKeepAliveUpdate (upd , edge )
3082
+ isKeepAlive , err := IsKeepAliveUpdate (upd , edgeToUpdate )
3099
3083
if err != nil {
3100
3084
log .Errorf ("Could not determine if update is " +
3101
3085
"keepalive: %v" , err )
@@ -3105,7 +3089,18 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
3105
3089
}
3106
3090
3107
3091
if isKeepAlive {
3108
- if timeSinceLastUpdate < d .cfg .RebroadcastInterval {
3092
+ within , err := d .updateWithinRebroadcastInterval (
3093
+ upd , edgeToUpdate ,
3094
+ )
3095
+ if err != nil {
3096
+ log .Errorf ("Could not determine if update is " +
3097
+ "within rebroadcast interval: %v" , err )
3098
+ nMsg .err <- err
3099
+
3100
+ return nil , false
3101
+ }
3102
+
3103
+ if ! within {
3109
3104
log .Debugf ("Ignoring keep alive update not " +
3110
3105
"within %v period for channel %v" ,
3111
3106
d .cfg .RebroadcastInterval , shortChanID )
@@ -3124,7 +3119,7 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
3124
3119
// multiple aliases for a channel and we may otherwise
3125
3120
// rate-limit only a single alias of the channel,
3126
3121
// instead of the whole channel.
3127
- baseScid := chanID
3122
+ baseScid := chanInfo . GetChanID ()
3128
3123
d .Lock ()
3129
3124
rls , ok := d .chanUpdateRateLimiter [baseScid ]
3130
3125
if ! ok {
@@ -3155,18 +3150,23 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
3155
3150
// different alias. This might mean that SigBytes is incorrect as it
3156
3151
// signs a different SCID than the database SCID, but since there will
3157
3152
// only be a difference if AuthProof == nil, this is fine.
3158
- update := & models.ChannelEdgePolicy1 {
3159
- SigBytes : upd .Signature .ToSignatureBytes (),
3160
- ChannelID : chanID ,
3161
- LastUpdate : timestamp ,
3162
- MessageFlags : upd .MessageFlags ,
3163
- ChannelFlags : upd .ChannelFlags ,
3164
- TimeLockDelta : upd .TimeLockDelta ,
3165
- MinHTLC : upd .HtlcMinimumMsat ,
3166
- MaxHTLC : upd .HtlcMaximumMsat ,
3167
- FeeBaseMSat : lnwire .MilliSatoshi (upd .BaseFee ),
3168
- FeeProportionalMillionths : lnwire .MilliSatoshi (upd .FeeRate ),
3169
- ExtraOpaqueData : upd .ExtraOpaqueData ,
3153
+ update , err := models .EdgePolicyFromUpdate (upd )
3154
+ if err != nil {
3155
+ rErr := fmt .Errorf ("unable to convert update to policy for " +
3156
+ "short_chan_id=%v: %v" , spew .Sdump (scid ), err )
3157
+
3158
+ log .Error (rErr )
3159
+ nMsg .err <- rErr
3160
+
3161
+ return nil , false
3162
+ }
3163
+ switch upd := update .(type ) {
3164
+ case * models.ChannelEdgePolicy1 :
3165
+ upd .ChannelID = chanInfo .GetChanID ()
3166
+ case * models.ChannelEdgePolicy2 :
3167
+ upd .ShortChannelID .Val = lnwire .NewShortChanIDFromInt (
3168
+ chanInfo .GetChanID (),
3169
+ )
3170
3170
}
3171
3171
3172
3172
if err := d .cfg .Router .UpdateEdge (update , ops ... ); err != nil {
@@ -3182,7 +3182,8 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
3182
3182
// Since we know the stored SCID in the graph, we'll
3183
3183
// cache that SCID.
3184
3184
key := newRejectCacheKey (
3185
- chanID , sourceToPub (nMsg .source ),
3185
+ chanInfo .GetChanID (),
3186
+ sourceToPub (nMsg .source ),
3186
3187
)
3187
3188
_ , _ = d .recentRejects .Put (key , & cachedReject {})
3188
3189
@@ -3191,32 +3192,33 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
3191
3192
}
3192
3193
3193
3194
nMsg .err <- err
3195
+
3194
3196
return nil , false
3195
3197
}
3196
3198
3197
3199
// If this is a local ChannelUpdate1 without an AuthProof, it means it
3198
3200
// is an update to a channel that is not (yet) supposed to be announced
3199
- // to the greater network. However, our channel counter party will need
3201
+ // to the greater network. However, our channel counterparty will need
3200
3202
// to be given the update, so we'll try sending the update directly to
3201
3203
// the remote peer.
3202
- if ! nMsg .isRemote && chanInfo .GetAuthProof () == nil { //nolint:nestif
3203
- if nMsg .optionalMsgFields != nil {
3204
+ if ! nMsg .isRemote && chanInfo .GetAuthProof () == nil {
3205
+ if nMsg .optionalMsgFields != nil &&
3206
+ nMsg .optionalMsgFields .remoteAlias != nil {
3207
+
3208
+ // The remoteAlias field was specified, meaning
3209
+ // that we should replace the SCID in the
3210
+ // update with the remote's alias. We'll also
3211
+ // need to re-sign the channel update. This is
3212
+ // required for option-scid-alias feature-bit
3213
+ // negotiated channels.
3204
3214
remoteAlias := nMsg .optionalMsgFields .remoteAlias
3205
- if remoteAlias != nil {
3206
- // The remoteAlias field was specified, meaning
3207
- // that we should replace the SCID in the
3208
- // update with the remote's alias. We'll also
3209
- // need to re-sign the channel update. This is
3210
- // required for option-scid-alias feature-bit
3211
- // negotiated channels.
3212
- upd .ShortChannelID = * remoteAlias
3213
-
3214
- err := d .cfg .SignAliasUpdate (upd )
3215
- if err != nil {
3216
- log .Error (err )
3217
- nMsg .err <- err
3218
- return nil , false
3219
- }
3215
+ upd .SetSCID (* remoteAlias )
3216
+
3217
+ err := d .cfg .SignAliasUpdate (upd )
3218
+ if err != nil {
3219
+ log .Error (err )
3220
+ nMsg .err <- err
3221
+ return nil , false
3220
3222
}
3221
3223
}
3222
3224
@@ -3233,7 +3235,7 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
3233
3235
if err != nil {
3234
3236
err := fmt .Errorf ("unable to reliably send %v for " +
3235
3237
"channel=%v to peer=%x: %v" , upd .MsgType (),
3236
- upd . ShortChannelID , remotePubKey , err )
3238
+ scid , remotePubKey , err )
3237
3239
nMsg .err <- err
3238
3240
return nil , false
3239
3241
}
@@ -3246,7 +3248,7 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
3246
3248
// contains an alias because the network would reject this.
3247
3249
var announcements []networkMsg
3248
3250
if chanInfo .GetAuthProof () != nil &&
3249
- ! d .cfg .IsAlias (upd . ShortChannelID ) {
3251
+ ! d .cfg .IsAlias (scid ) {
3250
3252
3251
3253
announcements = append (announcements , networkMsg {
3252
3254
peer : nMsg .peer ,
@@ -3258,9 +3260,9 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
3258
3260
3259
3261
nMsg .err <- nil
3260
3262
3261
- log .Debugf ("Processed ChannelUpdate1 : peer=%v, short_chan_id=%v, " +
3262
- "timestamp=%v" , nMsg .peer , upd . ShortChannelID . ToUint64 (),
3263
- timestamp )
3263
+ log .Debugf ("Processed %s : peer=%v, short_chan_id=%v, " , upd . MsgType (),
3264
+ nMsg .peer , scid . ToUint64 ())
3265
+
3264
3266
return announcements , true
3265
3267
}
3266
3268
@@ -3687,6 +3689,39 @@ func (d *AuthenticatedGossiper) handleAnnSig(nMsg *networkMsg,
3687
3689
return announcements , true
3688
3690
}
3689
3691
3692
+ func (d * AuthenticatedGossiper ) updateWithinRebroadcastInterval (
3693
+ upd lnwire.ChannelUpdate , policy models.ChannelEdgePolicy ) (bool ,
3694
+ error ) {
3695
+
3696
+ switch update := upd .(type ) {
3697
+ case * lnwire.ChannelUpdate1 :
3698
+ pol , ok := policy .(* models.ChannelEdgePolicy1 )
3699
+ if ! ok {
3700
+ return false , fmt .Errorf ("expected chan edge policy 1" )
3701
+ }
3702
+
3703
+ timestamp := time .Unix (int64 (update .Timestamp ), 0 )
3704
+ timeSinceLastUpdate := timestamp .Sub (pol .LastUpdate )
3705
+
3706
+ return timeSinceLastUpdate >= d .cfg .RebroadcastInterval , nil
3707
+
3708
+ case * lnwire.ChannelUpdate2 :
3709
+ pol , ok := policy .(* models.ChannelEdgePolicy2 )
3710
+ if ! ok {
3711
+ return false , fmt .Errorf ("expected chan edge policy 2" )
3712
+ }
3713
+
3714
+ blocksSinceLastUpdate := update .BlockHeight .Val -
3715
+ pol .BlockHeight .Val
3716
+
3717
+ return blocksSinceLastUpdate >=
3718
+ uint32 (d .cfg .RebroadcastInterval .Hours ()* 6 ), nil
3719
+
3720
+ default :
3721
+ return false , fmt .Errorf ("unhandled impl of Chan Update" )
3722
+ }
3723
+ }
3724
+
3690
3725
func buildChanProof (ann lnwire.ChannelAnnouncement ) (
3691
3726
models.ChannelAuthProof , error ) {
3692
3727
0 commit comments