mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
multi: rename key_send, key-send and key send to keysend
This commit is contained in:
parent
3aba0f1eaf
commit
51dbdd3b38
@ -220,7 +220,7 @@ type Invoice struct {
|
||||
Memo []byte
|
||||
|
||||
// PaymentRequest is the encoded payment request for this invoice. For
|
||||
// spontaneous (key send) payments, this field will be empty.
|
||||
// spontaneous (keysend) payments, this field will be empty.
|
||||
PaymentRequest []byte
|
||||
|
||||
// CreationDate is the exact time the invoice was created.
|
||||
|
@ -2179,7 +2179,7 @@ var sendPaymentCommand = cli.Command{
|
||||
Usage: "the number of blocks the last hop has to reveal the preimage",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "key_send",
|
||||
Name: "keysend",
|
||||
Usage: "will generate a pre-image and encode it in the sphinx packet, a dest must be set [experimental]",
|
||||
},
|
||||
),
|
||||
@ -2287,10 +2287,10 @@ func sendPayment(ctx *cli.Context) error {
|
||||
|
||||
var rHash []byte
|
||||
|
||||
if ctx.Bool("key_send") {
|
||||
if ctx.Bool("keysend") {
|
||||
if ctx.IsSet("payment_hash") {
|
||||
return errors.New("cannot set payment hash when using " +
|
||||
"key send")
|
||||
"keysend")
|
||||
}
|
||||
var preimage lntypes.Preimage
|
||||
if _, err := rand.Read(preimage[:]); err != nil {
|
||||
|
@ -326,7 +326,7 @@ type config struct {
|
||||
|
||||
EnableUpfrontShutdown bool `long:"enable-upfront-shutdown" description:"If true, option upfront shutdown script will be enabled. If peers that we open channels with support this feature, we will automatically set the script to which cooperative closes should be paid out to on channel open. This offers the partial protection of a channel peer disconnecting from us if cooperative close is attempted with a different script."`
|
||||
|
||||
AcceptKeySend bool `long:"accept-key-send" description:"If true, spontaneous payments through key send will be accepted. [experimental]"`
|
||||
AcceptKeySend bool `long:"accept-keysend" description:"If true, spontaneous payments through keysend will be accepted. [experimental]"`
|
||||
|
||||
Routing *routing.Conf `group:"routing" namespace:"routing"`
|
||||
|
||||
|
@ -695,12 +695,12 @@ func (i *InvoiceRegistry) cancelSingleHtlc(hash lntypes.Hash,
|
||||
return nil
|
||||
}
|
||||
|
||||
// processKeySend just-in-time inserts an invoice if this htlc is a key send
|
||||
// processKeySend just-in-time inserts an invoice if this htlc is a keysend
|
||||
// htlc.
|
||||
func (i *InvoiceRegistry) processKeySend(ctx invoiceUpdateCtx,
|
||||
hash lntypes.Hash) error {
|
||||
|
||||
// Retrieve key send record if present.
|
||||
// Retrieve keysend record if present.
|
||||
preimageSlice, ok := ctx.customRecords[record.KeySendType]
|
||||
if !ok {
|
||||
return nil
|
||||
@ -709,25 +709,25 @@ func (i *InvoiceRegistry) processKeySend(ctx invoiceUpdateCtx,
|
||||
// Cancel htlc is preimage is invalid.
|
||||
preimage, err := lntypes.MakePreimage(preimageSlice)
|
||||
if err != nil || preimage.Hash() != hash {
|
||||
return errors.New("invalid key send preimage")
|
||||
return errors.New("invalid keysend preimage")
|
||||
}
|
||||
|
||||
// Don't accept zero preimages as those have a special meaning in our
|
||||
// database for hodl invoices.
|
||||
if preimage == channeldb.UnknownPreimage {
|
||||
return errors.New("invalid key send preimage")
|
||||
return errors.New("invalid keysend preimage")
|
||||
}
|
||||
|
||||
// Only allow key send for non-mpp payments.
|
||||
// Only allow keysend for non-mpp payments.
|
||||
if ctx.mpp != nil {
|
||||
return errors.New("no mpp key send supported")
|
||||
return errors.New("no mpp keysend supported")
|
||||
}
|
||||
|
||||
// Create an invoice for the htlc amount.
|
||||
amt := ctx.amtPaid
|
||||
|
||||
// Set tlv optional feature vector on the invoice. Otherwise we wouldn't
|
||||
// be able to pay to it with key send.
|
||||
// be able to pay to it with keysend.
|
||||
rawFeatures := lnwire.NewRawFeatureVector(
|
||||
lnwire.TLVOnionPayloadOptional,
|
||||
)
|
||||
@ -802,13 +802,13 @@ func (i *InvoiceRegistry) NotifyExitHopHtlc(rHash lntypes.Hash,
|
||||
mpp: mpp,
|
||||
}
|
||||
|
||||
// Process key send if present. Do this outside of the lock, because
|
||||
// Process keysend if present. Do this outside of the lock, because
|
||||
// AddInvoice obtains its own lock. This is no problem, because the
|
||||
// operation is idempotent.
|
||||
if i.cfg.AcceptKeySend {
|
||||
err := i.processKeySend(updateCtx, rHash)
|
||||
if err != nil {
|
||||
debugLog(fmt.Sprintf("key send error: %v", err))
|
||||
debugLog(fmt.Sprintf("keysend error: %v", err))
|
||||
|
||||
return NewFailureResolution(
|
||||
circuitKey, currentHeight, ResultKeySendError,
|
||||
|
@ -598,7 +598,7 @@ func TestUnknownInvoice(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestKeySend tests receiving a spontaneous payment with and without key send
|
||||
// TestKeySend tests receiving a spontaneous payment with and without keysend
|
||||
// enabled.
|
||||
func TestKeySend(t *testing.T) {
|
||||
t.Run("enabled", func(t *testing.T) {
|
||||
@ -609,7 +609,7 @@ func TestKeySend(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// testKeySend is the inner test function that tests key send for a particular
|
||||
// testKeySend is the inner test function that tests keysend for a particular
|
||||
// enabled state on the receiver end.
|
||||
func testKeySend(t *testing.T, keySendEnabled bool) {
|
||||
defer timeout()()
|
||||
@ -627,11 +627,11 @@ func testKeySend(t *testing.T, keySendEnabled bool) {
|
||||
amt := lnwire.MilliSatoshi(1000)
|
||||
expiry := uint32(testCurrentHeight + 20)
|
||||
|
||||
// Create key for key send.
|
||||
// Create key for keysend.
|
||||
preimage := lntypes.Preimage{1, 2, 3}
|
||||
hash := preimage.Hash()
|
||||
|
||||
// Try to settle invoice with an invalid key send htlc.
|
||||
// Try to settle invoice with an invalid keysend htlc.
|
||||
invalidKeySendPayload := &mockPayload{
|
||||
customRecords: map[uint64][]byte{
|
||||
record.KeySendType: {1, 2, 3},
|
||||
@ -656,10 +656,10 @@ func testKeySend(t *testing.T, keySendEnabled bool) {
|
||||
t.Fatal("expected invoice not found outcome")
|
||||
|
||||
case keySendEnabled && resolution.Outcome != ResultKeySendError:
|
||||
t.Fatal("expected key send error")
|
||||
t.Fatal("expected keysend error")
|
||||
}
|
||||
|
||||
// Try to settle invoice with a valid key send htlc.
|
||||
// Try to settle invoice with a valid keysend htlc.
|
||||
keySendPayload := &mockPayload{
|
||||
customRecords: map[uint64][]byte{
|
||||
record.KeySendType: preimage[:],
|
||||
@ -674,10 +674,10 @@ func testKeySend(t *testing.T, keySendEnabled bool) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Expect a cancel resolution if key send is disabled.
|
||||
// Expect a cancel resolution if keysend is disabled.
|
||||
if !keySendEnabled {
|
||||
if resolution.Outcome != ResultInvoiceNotFound {
|
||||
t.Fatal("expected key send payment not to be accepted")
|
||||
t.Fatal("expected keysend payment not to be accepted")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ const (
|
||||
// invoice that is unknown to us.
|
||||
ResultInvoiceNotFound
|
||||
|
||||
// ResultKeySendError is returned when we receive invalid key send
|
||||
// ResultKeySendError is returned when we receive invalid keysend
|
||||
// parameters.
|
||||
ResultKeySendError
|
||||
)
|
||||
@ -150,7 +150,7 @@ func (u ResolutionResult) String() string {
|
||||
return "mpp is overpaying set total"
|
||||
|
||||
case ResultKeySendError:
|
||||
return "invalid key send parameters"
|
||||
return "invalid keysend parameters"
|
||||
|
||||
default:
|
||||
return "unknown"
|
||||
|
@ -15,7 +15,7 @@ import (
|
||||
// decodePayReq decodes the invoice payment request if present. This is needed,
|
||||
// because not all information is stored in dedicated invoice fields. If there
|
||||
// is no payment request present, a dummy request will be returned. This can
|
||||
// happen with just-in-time inserted key send invoices.
|
||||
// happen with just-in-time inserted keysend invoices.
|
||||
func decodePayReq(invoice *channeldb.Invoice,
|
||||
activeNetParams *chaincfg.Params) (*zpay32.Invoice, error) {
|
||||
|
||||
@ -146,7 +146,7 @@ func CreateRPCInvoice(invoice *channeldb.Invoice,
|
||||
State: state,
|
||||
Htlcs: rpcHtlcs,
|
||||
Features: CreateRPCFeatures(invoice.Terms.Features),
|
||||
IsKeySend: len(invoice.PaymentRequest) == 0,
|
||||
IsKeysend: len(invoice.PaymentRequest) == 0,
|
||||
}
|
||||
|
||||
if preimage != channeldb.UnknownPreimage {
|
||||
|
1205
lnrpc/rpc.pb.go
1205
lnrpc/rpc.pb.go
File diff suppressed because it is too large
Load Diff
@ -2575,7 +2575,7 @@ message Invoice {
|
||||
Indicates if this invoice was a spontaneous payment that arrived via keysend
|
||||
[EXPERIMENTAL].
|
||||
*/
|
||||
bool is_key_send = 25 [json_name = "is_key_send"];
|
||||
bool is_keysend = 25 [json_name = "is_keysend"];
|
||||
}
|
||||
|
||||
enum InvoiceHTLCState {
|
||||
|
@ -2943,7 +2943,7 @@
|
||||
},
|
||||
"description": "/ List of features advertised on the invoice."
|
||||
},
|
||||
"is_key_send": {
|
||||
"is_keysend": {
|
||||
"type": "boolean",
|
||||
"format": "boolean",
|
||||
"description": "*\nIndicates if this invoice was a spontaneous payment that arrived via keysend\n[EXPERIMENTAL]."
|
||||
|
@ -140,7 +140,7 @@ func testSingleHopInvoice(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
t.Fatalf(err.Error())
|
||||
}
|
||||
|
||||
// Next send a key send payment.
|
||||
// Next send a keysend payment.
|
||||
keySendPreimage := lntypes.Preimage{3, 4, 5, 11}
|
||||
keySendHash := keySendPreimage.Hash()
|
||||
|
||||
@ -162,7 +162,7 @@ func testSingleHopInvoice(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
t.Fatalf("error when attempting recv: %v", resp.PaymentError)
|
||||
}
|
||||
|
||||
// The key send payment should also have succeeded, with the balances
|
||||
// The keysend payment should also have succeeded, with the balances
|
||||
// being update accordingly.
|
||||
err = wait.NoError(
|
||||
assertAmountSent(3*paymentAmt, net.Alice, net.Bob),
|
||||
|
@ -228,7 +228,7 @@ func (cfg NodeConfig) genArgs() []string {
|
||||
}
|
||||
|
||||
if cfg.AcceptKeySend {
|
||||
args = append(args, "--accept-key-send")
|
||||
args = append(args, "--accept-keysend")
|
||||
}
|
||||
|
||||
return args
|
||||
@ -317,9 +317,9 @@ func newNode(cfg NodeConfig) (*HarnessNode, error) {
|
||||
|
||||
cfg.P2PPort, cfg.RPCPort, cfg.RESTPort, cfg.ProfilePort = generateListeningPorts()
|
||||
|
||||
// Run all tests with accept key send. The key send code is very
|
||||
// isolated and it is highly unlikely that it would affect regular
|
||||
// itests when enabled.
|
||||
// Run all tests with accept keysend. The keysend code is very isolated
|
||||
// and it is highly unlikely that it would affect regular itests when
|
||||
// enabled.
|
||||
cfg.AcceptKeySend = true
|
||||
|
||||
numActiveNodesMtx.Lock()
|
||||
|
@ -1,6 +1,6 @@
|
||||
package record
|
||||
|
||||
const (
|
||||
// KeySendType is the custom record identifier for key send preimages.
|
||||
// KeySendType is the custom record identifier for keysend preimages.
|
||||
KeySendType uint64 = 5482373484
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user