multi: add IsBlinded to lnrpc.Invoice for nicer UX

The BlindedPathConfig struct is nice for invoice creation but when we
use the Invoice message for viewing an invoice, it would be nicer to see
an "is_blinded" field.
This commit is contained in:
Elle Mouton committed 2024-08-08 16:46:01 +02:00
1 parent 5a84ca8032
commit 5e84ba92af
9 files changed
+1226 -1175

No files matched your search

+1
View File
@@ -183,6 +183,7 @@ func addInvoice(ctx *cli.Context) error {
CltvExpiry: ctx.Uint64("cltv_expiry_delta"), CltvExpiry: ctx.Uint64("cltv_expiry_delta"),
Private: ctx.Bool("private"), Private: ctx.Bool("private"),
IsAmp: ctx.Bool("amp"), IsAmp: ctx.Bool("amp"),
IsBlinded: ctx.Bool("blind"),
BlindedPathConfig: blindedPathCfg, BlindedPathConfig: blindedPathCfg,
} }
+9
View File
@@ -489,6 +489,15 @@ func (i *Invoice) IsAMP() bool {
) )
} }
// IsBlinded returns true if the invoice contains blinded paths.
func (i *Invoice) IsBlinded() bool {
if i.Terms.Features == nil {
return false
}
return i.Terms.Features.IsSet(lnwire.Bolt11BlindedPathsRequired)
}
// HtlcState defines the states an htlc paying to an invoice can be in. // HtlcState defines the states an htlc paying to an invoice can be in.
type HtlcState uint8 type HtlcState uint8
+15 -8
View File
@@ -382,6 +382,7 @@ func (b *blindedForwardTest) buildBlindedPath() *lnrpc.BlindedPaymentPath {
RPreimage: b.preimage[:], RPreimage: b.preimage[:],
Memo: "test", Memo: "test",
ValueMsat: 10_000_000, ValueMsat: 10_000_000,
IsBlinded: true,
BlindedPathConfig: &lnrpc.BlindedPathConfig{ BlindedPathConfig: &lnrpc.BlindedPathConfig{
MinNumRealHops: &minNumRealHops, MinNumRealHops: &minNumRealHops,
NumHops: &numHops, NumHops: &numHops,
@@ -625,6 +626,7 @@ func testBlindedRouteInvoices(ht *lntest.HarnessTest) {
invoice := testCase.dave.RPC.AddInvoice(&lnrpc.Invoice{ invoice := testCase.dave.RPC.AddInvoice(&lnrpc.Invoice{
Memo: "test", Memo: "test",
ValueMsat: 10_000_000, ValueMsat: 10_000_000,
IsBlinded: true,
BlindedPathConfig: &lnrpc.BlindedPathConfig{ BlindedPathConfig: &lnrpc.BlindedPathConfig{
MinNumRealHops: &minNumRealHops, MinNumRealHops: &minNumRealHops,
NumHops: &numHops, NumHops: &numHops,
@@ -643,6 +645,7 @@ func testBlindedRouteInvoices(ht *lntest.HarnessTest) {
invoice = testCase.dave.RPC.AddInvoice(&lnrpc.Invoice{ invoice = testCase.dave.RPC.AddInvoice(&lnrpc.Invoice{
Memo: "test", Memo: "test",
ValueMsat: 10_000_000, ValueMsat: 10_000_000,
IsBlinded: true,
BlindedPathConfig: &lnrpc.BlindedPathConfig{ BlindedPathConfig: &lnrpc.BlindedPathConfig{
MinNumRealHops: &minNumRealHops, MinNumRealHops: &minNumRealHops,
NumHops: &numHops, NumHops: &numHops,
@@ -997,8 +1000,9 @@ func testMPPToSingleBlindedPath(ht *lntest.HarnessTest) {
minNumRealHops uint32 = 1 minNumRealHops uint32 = 1
) )
invoice := &lnrpc.Invoice{ invoice := &lnrpc.Invoice{
Memo: "test", Memo: "test",
Value: int64(paymentAmt), Value: int64(paymentAmt),
IsBlinded: true,
BlindedPathConfig: &lnrpc.BlindedPathConfig{ BlindedPathConfig: &lnrpc.BlindedPathConfig{
NumHops: &numHops, NumHops: &numHops,
MinNumRealHops: &minNumRealHops, MinNumRealHops: &minNumRealHops,
@@ -1167,8 +1171,9 @@ func testBlindedRouteDummyHops(ht *lntest.HarnessTest) {
numHops uint32 = 2 numHops uint32 = 2
) )
invoice := &lnrpc.Invoice{ invoice := &lnrpc.Invoice{
Memo: "test", Memo: "test",
Value: int64(paymentAmt), Value: int64(paymentAmt),
IsBlinded: true,
BlindedPathConfig: &lnrpc.BlindedPathConfig{ BlindedPathConfig: &lnrpc.BlindedPathConfig{
MinNumRealHops: &minNumRealHops, MinNumRealHops: &minNumRealHops,
NumHops: &numHops, NumHops: &numHops,
@@ -1208,8 +1213,9 @@ func testBlindedRouteDummyHops(ht *lntest.HarnessTest) {
// that one dummy hop should be added. // that one dummy hop should be added.
minNumRealHops = 1 minNumRealHops = 1
invoice = &lnrpc.Invoice{ invoice = &lnrpc.Invoice{
Memo: "test", Memo: "test",
Value: int64(paymentAmt), Value: int64(paymentAmt),
IsBlinded: true,
BlindedPathConfig: &lnrpc.BlindedPathConfig{ BlindedPathConfig: &lnrpc.BlindedPathConfig{
MinNumRealHops: &minNumRealHops, MinNumRealHops: &minNumRealHops,
NumHops: &numHops, NumHops: &numHops,
@@ -1334,8 +1340,9 @@ func testMPPToMultipleBlindedPaths(ht *lntest.HarnessTest) {
numHops uint32 = 1 numHops uint32 = 1
) )
invoice := &lnrpc.Invoice{ invoice := &lnrpc.Invoice{
Memo: "test", Memo: "test",
Value: int64(paymentAmt), Value: int64(paymentAmt),
IsBlinded: true,
BlindedPathConfig: &lnrpc.BlindedPathConfig{ BlindedPathConfig: &lnrpc.BlindedPathConfig{
MinNumRealHops: &minNumRealHops, MinNumRealHops: &minNumRealHops,
NumHops: &numHops, NumHops: &numHops,
+5 -1
View File
@@ -607,9 +607,13 @@
"description": "Maps a 32-byte hex-encoded set ID to the sub-invoice AMP state for the\ngiven set ID. This field is always populated for AMP invoices, and can be\nused along side LookupInvoice to obtain the HTLC information related to a\ngiven sub-invoice.\nNote: Output only, don't specify for creating an invoice.", "description": "Maps a 32-byte hex-encoded set ID to the sub-invoice AMP state for the\ngiven set ID. This field is always populated for AMP invoices, and can be\nused along side LookupInvoice to obtain the HTLC information related to a\ngiven sub-invoice.\nNote: Output only, don't specify for creating an invoice.",
"title": "[EXPERIMENTAL]:" "title": "[EXPERIMENTAL]:"
}, },
"is_blinded": {
"type": "boolean",
"description": "Signals that the invoice should include blinded paths to hide the true\nidentity of the recipient."
},
"blinded_path_config": { "blinded_path_config": {
"$ref": "#/definitions/lnrpcBlindedPathConfig", "$ref": "#/definitions/lnrpcBlindedPathConfig",
"description": "Signals that the invoice should include blinded paths to hide the true\nidentity of the recipient." "description": "Config values to use when creating blinded paths for this invoice. These\ncan be used to override the defaults config values provided in by the\nglobal config. This field is only used if is_blinded is true."
} }
} }
}, },
+1
View File
@@ -176,6 +176,7 @@ func CreateRPCInvoice(invoice *invoices.Invoice,
IsKeysend: invoice.IsKeysend(), IsKeysend: invoice.IsKeysend(),
PaymentAddr: invoice.Terms.PaymentAddr[:], PaymentAddr: invoice.Terms.PaymentAddr[:],
IsAmp: invoice.IsAMP(), IsAmp: invoice.IsAMP(),
IsBlinded: invoice.IsBlinded(),
} }
rpcInvoice.AmpInvoiceState = make(map[string]*lnrpc.AMPInvoiceState) rpcInvoice.AmpInvoiceState = make(map[string]*lnrpc.AMPInvoiceState)
+1175 -1162
View File
File diff suppressed because it is too large. Load diff
+8 -1
View File
@@ -3843,7 +3843,14 @@ message Invoice {
Signals that the invoice should include blinded paths to hide the true Signals that the invoice should include blinded paths to hide the true
identity of the recipient. identity of the recipient.
*/ */
BlindedPathConfig blinded_path_config = 29; bool is_blinded = 29;
/*
Config values to use when creating blinded paths for this invoice. These
can be used to override the defaults config values provided in by the
global config. This field is only used if is_blinded is true.
*/
BlindedPathConfig blinded_path_config = 30;
} }
message BlindedPathConfig { message BlindedPathConfig {
+5 -1
View File
@@ -5519,9 +5519,13 @@
"description": "Maps a 32-byte hex-encoded set ID to the sub-invoice AMP state for the\ngiven set ID. This field is always populated for AMP invoices, and can be\nused along side LookupInvoice to obtain the HTLC information related to a\ngiven sub-invoice.\nNote: Output only, don't specify for creating an invoice.", "description": "Maps a 32-byte hex-encoded set ID to the sub-invoice AMP state for the\ngiven set ID. This field is always populated for AMP invoices, and can be\nused along side LookupInvoice to obtain the HTLC information related to a\ngiven sub-invoice.\nNote: Output only, don't specify for creating an invoice.",
"title": "[EXPERIMENTAL]:" "title": "[EXPERIMENTAL]:"
}, },
"is_blinded": {
"type": "boolean",
"description": "Signals that the invoice should include blinded paths to hide the true\nidentity of the recipient."
},
"blinded_path_config": { "blinded_path_config": {
"$ref": "#/definitions/lnrpcBlindedPathConfig", "$ref": "#/definitions/lnrpcBlindedPathConfig",
"description": "Signals that the invoice should include blinded paths to hide the true\nidentity of the recipient." "description": "Config values to use when creating blinded paths for this invoice. These\ncan be used to override the defaults config values provided in by the\nglobal config. This field is only used if is_blinded is true."
} }
} }
}, },
+7 -2
View File
@@ -5781,7 +5781,7 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
var ( var (
defaultDelta = r.cfg.Bitcoin.TimeLockDelta defaultDelta = r.cfg.Bitcoin.TimeLockDelta
blindCfg = invoice.BlindedPathConfig blindCfg = invoice.BlindedPathConfig
blind = blindCfg != nil blind = invoice.IsBlinded
) )
globalBlindCfg := r.server.cfg.Routing.BlindedPaths globalBlindCfg := r.server.cfg.Routing.BlindedPaths
@@ -5792,7 +5792,12 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
NodeOmissionSet: fn.NewSet[route.Vertex](), NodeOmissionSet: fn.NewSet[route.Vertex](),
} }
if blind { if blindCfg != nil && !blind {
return nil, fmt.Errorf("blinded path config provided but " +
"IsBlinded not set")
}
if blind && blindCfg != nil {
if blindCfg.MinNumRealHops != nil { if blindCfg.MinNumRealHops != nil {
blindingRestrictions.MinDistanceFromIntroNode = blindingRestrictions.MinDistanceFromIntroNode =
uint8(*blindCfg.MinNumRealHops) uint8(*blindCfg.MinNumRealHops)