-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Allow zero amount paths with MinHTLC policies #10029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -438,7 +438,13 @@ func collectRelayInfo(cfg *BuildBlindedPathCfg, path *candidatePath) ( | |
} | ||
} | ||
|
||
if policy.MinHTLCMsat > cfg.ValueMsat { | ||
// If the payment amount is 0, means the sender is deciding the | ||
// amount, so we don't need to check the min HTLC value while | ||
// building the path. Payment would fail if there is no | ||
// route with the min HTLC value from the sender's perspective. | ||
isZeroAmount := cfg.ValueMsat == 0 | ||
|
||
if !isZeroAmount && policy.MinHTLCMsat > cfg.ValueMsat { | ||
return nil, 0, 0, fmt.Errorf("%w: minHTLC of hop "+ | ||
"policy larger than payment amt: sentAmt(%v), "+ | ||
"minHTLC(%v)", errInvalidBlindedPath, | ||
|
@@ -450,12 +456,13 @@ func collectRelayInfo(cfg *BuildBlindedPathCfg, path *candidatePath) ( | |
return nil, 0, 0, err | ||
} | ||
|
||
// We only use the new buffered policy if the new minHTLC value | ||
// does not violate the sender amount. | ||
// We only use the new buffered policy if: | ||
// 1) Sender amount is 0, or | ||
// 2) The new minHTLC value does not violate the sender amount. | ||
a-mpch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// | ||
// NOTE: We don't check this for maxHTLC, because the payment | ||
// amount can always be splitted using MPP. | ||
if bufferPolicy.MinHTLCMsat <= cfg.ValueMsat { | ||
if isZeroAmount || bufferPolicy.MinHTLCMsat <= cfg.ValueMsat { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we explicitly need to set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ohh I see, the |
||
policy = bufferPolicy | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1059,3 +1059,110 @@ func decryptAndDecodeHopData(t *testing.T, priv *btcec.PrivateKey, | |
|
||
return routeData, nextEphem | ||
} | ||
|
||
// TestBuildBlindedPathZeroAmount tests that blinded paths can be built | ||
// successfully when ValueMsat is 0 (zero amount), even when channels have | ||
// MinHTLC policies > 0. This is important for building blinded paths invoices | ||
// for zero amount payments. | ||
a-mpch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
func TestBuildBlindedPathZeroAmount(t *testing.T) { | ||
// Alice chooses the following path to herself for blinded path | ||
// construction: | ||
// Carol -> Bob -> Alice. | ||
var ( | ||
_, pkC = btcec.PrivKeyFromBytes([]byte{1}) | ||
_, pkB = btcec.PrivKeyFromBytes([]byte{2}) | ||
_, pkA = btcec.PrivKeyFromBytes([]byte{3}) | ||
|
||
carol = route.NewVertex(pkC) | ||
bob = route.NewVertex(pkB) | ||
alice = route.NewVertex(pkA) | ||
|
||
chanCB = uint64(1) | ||
chanBA = uint64(2) | ||
) | ||
|
||
realRoute := &route.Route{ | ||
SourcePubKey: carol, | ||
Hops: []*route.Hop{ | ||
{ | ||
PubKeyBytes: bob, | ||
ChannelID: chanCB, | ||
}, | ||
{ | ||
PubKeyBytes: alice, | ||
ChannelID: chanBA, | ||
}, | ||
}, | ||
} | ||
|
||
realPolicies := map[uint64]*models.ChannelEdgePolicy{ | ||
chanCB: { | ||
ChannelID: chanCB, | ||
ToNode: bob, | ||
MinHTLC: 1000, // MinHTLC > 0 | ||
MaxHTLC: lnwire.MaxMilliSatoshi, | ||
FeeBaseMSat: 100, | ||
FeeProportionalMillionths: 500, | ||
TimeLockDelta: 144, | ||
}, | ||
chanBA: { | ||
ChannelID: chanBA, | ||
ToNode: alice, | ||
MinHTLC: 500, // MinHTLC > 0 | ||
MaxHTLC: lnwire.MaxMilliSatoshi, | ||
FeeBaseMSat: 50, | ||
FeeProportionalMillionths: 250, | ||
TimeLockDelta: 72, | ||
}, | ||
} | ||
|
||
paths, err := BuildBlindedPaymentPaths(&BuildBlindedPathCfg{ | ||
FindRoutes: func(_ lnwire.MilliSatoshi) ([]*route.Route, | ||
error) { | ||
|
||
return []*route.Route{realRoute}, nil | ||
}, | ||
FetchChannelEdgesByID: func(chanID uint64) ( | ||
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy, | ||
*models.ChannelEdgePolicy, error) { | ||
|
||
return nil, realPolicies[chanID], nil, nil | ||
}, | ||
BestHeight: func() (uint32, error) { | ||
return 1000, nil | ||
}, | ||
AddPolicyBuffer: func(policy *BlindedHopPolicy) ( | ||
*BlindedHopPolicy, error) { | ||
// We don't mind about maxHTLCs | ||
return AddPolicyBuffer(policy, 1.5, 0.0) | ||
}, | ||
PathID: []byte{1, 2, 3}, | ||
ValueMsat: 0, | ||
MinFinalCLTVExpiryDelta: 12, | ||
BlocksUntilExpiry: 200, | ||
}) | ||
|
||
require.NoError(t, err) | ||
require.Len(t, paths, 1, "Should return exactly one blinded path") | ||
a-mpch marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: additional context strings can be omitted. |
||
|
||
path := paths[0] | ||
require.Len( | ||
t, | ||
path.Hops, 3, | ||
"Path should have 3 hops (intro + 2 relay hops)", | ||
) | ||
|
||
hop := path.Hops[0] | ||
require.True( | ||
t, | ||
hop.BlindedNodePub.IsEqual(pkC), | ||
"First hop should be Carol (introduction node)", | ||
) | ||
|
||
require.EqualValues( | ||
t, | ||
path.HTLCMinMsat, | ||
uint64(1500), | ||
"Path MinHTLC should be 1500 with 1.5x policy buffer applied", | ||
a-mpch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.