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 2024-08-08 14:18:07 +02:00
parent 5a84ca8032
commit 5e84ba92af
No known key found for this signature in database
GPG key ID: D7D916376026F177
9 changed files with 1226 additions and 1175 deletions

View file

@ -183,6 +183,7 @@ func addInvoice(ctx *cli.Context) error {
CltvExpiry: ctx.Uint64("cltv_expiry_delta"),
Private: ctx.Bool("private"),
IsAmp: ctx.Bool("amp"),
IsBlinded: ctx.Bool("blind"),
BlindedPathConfig: blindedPathCfg,
}

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.
type HtlcState uint8

View file

@ -382,6 +382,7 @@ func (b *blindedForwardTest) buildBlindedPath() *lnrpc.BlindedPaymentPath {
RPreimage: b.preimage[:],
Memo: "test",
ValueMsat: 10_000_000,
IsBlinded: true,
BlindedPathConfig: &lnrpc.BlindedPathConfig{
MinNumRealHops: &minNumRealHops,
NumHops: &numHops,
@ -625,6 +626,7 @@ func testBlindedRouteInvoices(ht *lntest.HarnessTest) {
invoice := testCase.dave.RPC.AddInvoice(&lnrpc.Invoice{
Memo: "test",
ValueMsat: 10_000_000,
IsBlinded: true,
BlindedPathConfig: &lnrpc.BlindedPathConfig{
MinNumRealHops: &minNumRealHops,
NumHops: &numHops,
@ -643,6 +645,7 @@ func testBlindedRouteInvoices(ht *lntest.HarnessTest) {
invoice = testCase.dave.RPC.AddInvoice(&lnrpc.Invoice{
Memo: "test",
ValueMsat: 10_000_000,
IsBlinded: true,
BlindedPathConfig: &lnrpc.BlindedPathConfig{
MinNumRealHops: &minNumRealHops,
NumHops: &numHops,
@ -997,8 +1000,9 @@ func testMPPToSingleBlindedPath(ht *lntest.HarnessTest) {
minNumRealHops uint32 = 1
)
invoice := &lnrpc.Invoice{
Memo: "test",
Value: int64(paymentAmt),
Memo: "test",
Value: int64(paymentAmt),
IsBlinded: true,
BlindedPathConfig: &lnrpc.BlindedPathConfig{
NumHops: &numHops,
MinNumRealHops: &minNumRealHops,
@ -1167,8 +1171,9 @@ func testBlindedRouteDummyHops(ht *lntest.HarnessTest) {
numHops uint32 = 2
)
invoice := &lnrpc.Invoice{
Memo: "test",
Value: int64(paymentAmt),
Memo: "test",
Value: int64(paymentAmt),
IsBlinded: true,
BlindedPathConfig: &lnrpc.BlindedPathConfig{
MinNumRealHops: &minNumRealHops,
NumHops: &numHops,
@ -1208,8 +1213,9 @@ func testBlindedRouteDummyHops(ht *lntest.HarnessTest) {
// that one dummy hop should be added.
minNumRealHops = 1
invoice = &lnrpc.Invoice{
Memo: "test",
Value: int64(paymentAmt),
Memo: "test",
Value: int64(paymentAmt),
IsBlinded: true,
BlindedPathConfig: &lnrpc.BlindedPathConfig{
MinNumRealHops: &minNumRealHops,
NumHops: &numHops,
@ -1334,8 +1340,9 @@ func testMPPToMultipleBlindedPaths(ht *lntest.HarnessTest) {
numHops uint32 = 1
)
invoice := &lnrpc.Invoice{
Memo: "test",
Value: int64(paymentAmt),
Memo: "test",
Value: int64(paymentAmt),
IsBlinded: true,
BlindedPathConfig: &lnrpc.BlindedPathConfig{
MinNumRealHops: &minNumRealHops,
NumHops: &numHops,

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.",
"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": {
"$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."
}
}
},

View file

@ -176,6 +176,7 @@ func CreateRPCInvoice(invoice *invoices.Invoice,
IsKeysend: invoice.IsKeysend(),
PaymentAddr: invoice.Terms.PaymentAddr[:],
IsAmp: invoice.IsAMP(),
IsBlinded: invoice.IsBlinded(),
}
rpcInvoice.AmpInvoiceState = make(map[string]*lnrpc.AMPInvoiceState)

File diff suppressed because it is too large Load diff

View file

@ -3843,7 +3843,14 @@ message Invoice {
Signals that the invoice should include blinded paths to hide the true
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 {

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.",
"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": {
"$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."
}
}
},

View file

@ -5781,7 +5781,7 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
var (
defaultDelta = r.cfg.Bitcoin.TimeLockDelta
blindCfg = invoice.BlindedPathConfig
blind = blindCfg != nil
blind = invoice.IsBlinded
)
globalBlindCfg := r.server.cfg.Routing.BlindedPaths
@ -5792,7 +5792,12 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
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 {
blindingRestrictions.MinDistanceFromIntroNode =
uint8(*blindCfg.MinNumRealHops)