routing+routerrpc: take max cltv limit into account within path finding
With the introduction of the max CLTV limit parameter, nodes are able to reject HTLCs that exceed it. This should also be applied to path finding, otherwise HTLCs crafted by the same node that exceed it never left the switch. This wasn't a big deal since the previous max CLTV limit was ~5000 blocks. Once it was lowered to 1008, the issue became more apparent. Therefore, all of our path finding attempts now have a restriction of said limit in in order to properly carry out HTLCs to the network.
This commit is contained in:
14 files changed
+75
-46
No files matched your search
@@ -212,8 +212,9 @@ type SendPaymentRequest struct {
|
||||
//any channel may be used.
|
||||
OutgoingChanId uint64 `protobuf:"varint,8,opt,name=outgoing_chan_id,json=outgoingChanId,proto3" json:"outgoing_chan_id,omitempty"`
|
||||
//*
|
||||
//An optional maximum total time lock for the route. If zero, there is no
|
||||
//maximum enforced.
|
||||
//An optional maximum total time lock for the route. This should not exceed
|
||||
//lnd's `--max-cltv-expiry` setting. If zero, then the value of
|
||||
//`--max-cltv-expiry` is enforced.
|
||||
CltvLimit int32 `protobuf:"varint,9,opt,name=cltv_limit,json=cltvLimit,proto3" json:"cltv_limit,omitempty"`
|
||||
//*
|
||||
//Optional route hints to reach the destination through private channels.
|
||||
|
||||
@@ -54,8 +54,9 @@ message SendPaymentRequest {
|
||||
uint64 outgoing_chan_id = 8;
|
||||
|
||||
/**
|
||||
An optional maximum total time lock for the route. If zero, there is no
|
||||
maximum enforced.
|
||||
An optional maximum total time lock for the route. This should not exceed
|
||||
lnd's `--max-cltv-expiry` setting. If zero, then the value of
|
||||
`--max-cltv-expiry` is enforced.
|
||||
*/
|
||||
int32 cltv_limit = 9;
|
||||
|
||||
|
||||
@@ -55,6 +55,10 @@ type RouterBackend struct {
|
||||
// Tower is the ControlTower instance that is used to track pending
|
||||
// payments.
|
||||
Tower routing.ControlTower
|
||||
|
||||
// MaxTotalTimelock is the maximum total time lock a route is allowed to
|
||||
// have.
|
||||
MaxTotalTimelock uint32
|
||||
}
|
||||
|
||||
// MissionControl defines the mission control dependencies of routerrpc.
|
||||
@@ -471,11 +475,14 @@ func (r *RouterBackend) extractIntentFromSendRequest(
|
||||
payIntent.OutgoingChannelID = &rpcPayReq.OutgoingChanId
|
||||
}
|
||||
|
||||
// Take cltv limit from request if set.
|
||||
if rpcPayReq.CltvLimit != 0 {
|
||||
cltvLimit := uint32(rpcPayReq.CltvLimit)
|
||||
payIntent.CltvLimit = &cltvLimit
|
||||
// Take the CLTV limit from the request if set, otherwise use the max.
|
||||
cltvLimit, err := ValidateCLTVLimit(
|
||||
uint32(rpcPayReq.CltvLimit), r.MaxTotalTimelock,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
payIntent.CltvLimit = cltvLimit
|
||||
|
||||
// Take fee limit from request.
|
||||
payIntent.FeeLimit = lnwire.NewMSatFromSatoshis(
|
||||
@@ -675,3 +682,18 @@ func ValidatePayReqExpiry(payReq *zpay32.Invoice) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateCLTVLimit returns a valid CLTV limit given a value and a maximum. If
|
||||
// the value exceeds the maximum, then an error is returned. If the value is 0,
|
||||
// then the maximum is used.
|
||||
func ValidateCLTVLimit(val, max uint32) (uint32, error) {
|
||||
switch {
|
||||
case val == 0:
|
||||
return max, nil
|
||||
case val > max:
|
||||
return 0, fmt.Errorf("total time lock of %v exceeds max "+
|
||||
"allowed %v", val, max)
|
||||
default:
|
||||
return val, nil
|
||||
}
|
||||
}
|
||||
@@ -248,11 +248,14 @@ func (s *Server) EstimateRouteFee(ctx context.Context,
|
||||
feeLimit := lnwire.NewMSatFromSatoshis(btcutil.SatoshiPerBitcoin)
|
||||
|
||||
// Finally, we'll query for a route to the destination that can carry
|
||||
// that target amount, we'll only request a single route.
|
||||
// that target amount, we'll only request a single route. Set a
|
||||
// restriction for the default CLTV limit, otherwise we can find a route
|
||||
// that exceeds it and is useless to us.
|
||||
route, err := s.cfg.Router.FindRoute(
|
||||
s.cfg.RouterBackend.SelfNode, destNode, amtMsat,
|
||||
&routing.RestrictParams{
|
||||
FeeLimit: feeLimit,
|
||||
FeeLimit: feeLimit,
|
||||
CltvLimit: s.cfg.RouterBackend.MaxTotalTimelock,
|
||||
}, nil,
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
+3
-2
@@ -1052,8 +1052,9 @@ type SendRequest struct {
|
||||
//any channel may be used.
|
||||
OutgoingChanId uint64 `protobuf:"varint,9,opt,name=outgoing_chan_id,json=outgoingChanId,proto3" json:"outgoing_chan_id,omitempty"`
|
||||
//*
|
||||
//An optional maximum total time lock for the route. If zero, there is no
|
||||
//maximum enforced.
|
||||
//An optional maximum total time lock for the route. This should not exceed
|
||||
//lnd's `--max-cltv-expiry` setting. If zero, then the value of
|
||||
//`--max-cltv-expiry` is enforced.
|
||||
CltvLimit uint32 `protobuf:"varint,10,opt,name=cltv_limit,json=cltvLimit,proto3" json:"cltv_limit,omitempty"`
|
||||
//*
|
||||
//An optional field that can be used to pass an arbitrary set of TLV records
|
||||
|
||||
+3
-2
@@ -888,8 +888,9 @@ message SendRequest {
|
||||
uint64 outgoing_chan_id = 9;
|
||||
|
||||
/**
|
||||
An optional maximum total time lock for the route. If zero, there is no
|
||||
maximum enforced.
|
||||
An optional maximum total time lock for the route. This should not exceed
|
||||
lnd's `--max-cltv-expiry` setting. If zero, then the value of
|
||||
`--max-cltv-expiry` is enforced.
|
||||
*/
|
||||
uint32 cltv_limit = 10;
|
||||
|
||||
|
||||
@@ -3437,7 +3437,7 @@
|
||||
"cltv_limit": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"description": "* \nAn optional maximum total time lock for the route. If zero, there is no\nmaximum enforced."
|
||||
"description": "* \nAn optional maximum total time lock for the route. This should not exceed\nlnd's `--max-cltv-expiry` setting. If zero, then the value of\n`--max-cltv-expiry` is enforced."
|
||||
},
|
||||
"dest_tlv": {
|
||||
"type": "object",
|
||||
|
||||
Reference in new issue
Block a user