multi: rename key_send, key-send and key send to keysend

This commit is contained in:
Conner Fromknecht 2020-01-16 04:13:59 -08:00
parent 3aba0f1eaf
commit 51dbdd3b38
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
13 changed files with 638 additions and 637 deletions

View File

@ -220,7 +220,7 @@ type Invoice struct {
Memo []byte Memo []byte
// PaymentRequest is the encoded payment request for this invoice. For // 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 PaymentRequest []byte
// CreationDate is the exact time the invoice was created. // CreationDate is the exact time the invoice was created.

View File

@ -2179,7 +2179,7 @@ var sendPaymentCommand = cli.Command{
Usage: "the number of blocks the last hop has to reveal the preimage", Usage: "the number of blocks the last hop has to reveal the preimage",
}, },
cli.BoolFlag{ 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]", 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 var rHash []byte
if ctx.Bool("key_send") { if ctx.Bool("keysend") {
if ctx.IsSet("payment_hash") { if ctx.IsSet("payment_hash") {
return errors.New("cannot set payment hash when using " + return errors.New("cannot set payment hash when using " +
"key send") "keysend")
} }
var preimage lntypes.Preimage var preimage lntypes.Preimage
if _, err := rand.Read(preimage[:]); err != nil { if _, err := rand.Read(preimage[:]); err != nil {

View File

@ -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."` 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"` Routing *routing.Conf `group:"routing" namespace:"routing"`

View File

@ -695,12 +695,12 @@ func (i *InvoiceRegistry) cancelSingleHtlc(hash lntypes.Hash,
return nil 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. // htlc.
func (i *InvoiceRegistry) processKeySend(ctx invoiceUpdateCtx, func (i *InvoiceRegistry) processKeySend(ctx invoiceUpdateCtx,
hash lntypes.Hash) error { hash lntypes.Hash) error {
// Retrieve key send record if present. // Retrieve keysend record if present.
preimageSlice, ok := ctx.customRecords[record.KeySendType] preimageSlice, ok := ctx.customRecords[record.KeySendType]
if !ok { if !ok {
return nil return nil
@ -709,25 +709,25 @@ func (i *InvoiceRegistry) processKeySend(ctx invoiceUpdateCtx,
// Cancel htlc is preimage is invalid. // Cancel htlc is preimage is invalid.
preimage, err := lntypes.MakePreimage(preimageSlice) preimage, err := lntypes.MakePreimage(preimageSlice)
if err != nil || preimage.Hash() != hash { 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 // Don't accept zero preimages as those have a special meaning in our
// database for hodl invoices. // database for hodl invoices.
if preimage == channeldb.UnknownPreimage { 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 { 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. // Create an invoice for the htlc amount.
amt := ctx.amtPaid amt := ctx.amtPaid
// Set tlv optional feature vector on the invoice. Otherwise we wouldn't // 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( rawFeatures := lnwire.NewRawFeatureVector(
lnwire.TLVOnionPayloadOptional, lnwire.TLVOnionPayloadOptional,
) )
@ -802,13 +802,13 @@ func (i *InvoiceRegistry) NotifyExitHopHtlc(rHash lntypes.Hash,
mpp: mpp, 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 // AddInvoice obtains its own lock. This is no problem, because the
// operation is idempotent. // operation is idempotent.
if i.cfg.AcceptKeySend { if i.cfg.AcceptKeySend {
err := i.processKeySend(updateCtx, rHash) err := i.processKeySend(updateCtx, rHash)
if err != nil { if err != nil {
debugLog(fmt.Sprintf("key send error: %v", err)) debugLog(fmt.Sprintf("keysend error: %v", err))
return NewFailureResolution( return NewFailureResolution(
circuitKey, currentHeight, ResultKeySendError, circuitKey, currentHeight, ResultKeySendError,

View File

@ -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. // enabled.
func TestKeySend(t *testing.T) { func TestKeySend(t *testing.T) {
t.Run("enabled", func(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. // enabled state on the receiver end.
func testKeySend(t *testing.T, keySendEnabled bool) { func testKeySend(t *testing.T, keySendEnabled bool) {
defer timeout()() defer timeout()()
@ -627,11 +627,11 @@ func testKeySend(t *testing.T, keySendEnabled bool) {
amt := lnwire.MilliSatoshi(1000) amt := lnwire.MilliSatoshi(1000)
expiry := uint32(testCurrentHeight + 20) expiry := uint32(testCurrentHeight + 20)
// Create key for key send. // Create key for keysend.
preimage := lntypes.Preimage{1, 2, 3} preimage := lntypes.Preimage{1, 2, 3}
hash := preimage.Hash() hash := preimage.Hash()
// Try to settle invoice with an invalid key send htlc. // Try to settle invoice with an invalid keysend htlc.
invalidKeySendPayload := &mockPayload{ invalidKeySendPayload := &mockPayload{
customRecords: map[uint64][]byte{ customRecords: map[uint64][]byte{
record.KeySendType: {1, 2, 3}, record.KeySendType: {1, 2, 3},
@ -656,10 +656,10 @@ func testKeySend(t *testing.T, keySendEnabled bool) {
t.Fatal("expected invoice not found outcome") t.Fatal("expected invoice not found outcome")
case keySendEnabled && resolution.Outcome != ResultKeySendError: 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{ keySendPayload := &mockPayload{
customRecords: map[uint64][]byte{ customRecords: map[uint64][]byte{
record.KeySendType: preimage[:], record.KeySendType: preimage[:],
@ -674,10 +674,10 @@ func testKeySend(t *testing.T, keySendEnabled bool) {
t.Fatal(err) t.Fatal(err)
} }
// Expect a cancel resolution if key send is disabled. // Expect a cancel resolution if keysend is disabled.
if !keySendEnabled { if !keySendEnabled {
if resolution.Outcome != ResultInvoiceNotFound { if resolution.Outcome != ResultInvoiceNotFound {
t.Fatal("expected key send payment not to be accepted") t.Fatal("expected keysend payment not to be accepted")
} }
return return
} }

View File

@ -86,7 +86,7 @@ const (
// invoice that is unknown to us. // invoice that is unknown to us.
ResultInvoiceNotFound ResultInvoiceNotFound
// ResultKeySendError is returned when we receive invalid key send // ResultKeySendError is returned when we receive invalid keysend
// parameters. // parameters.
ResultKeySendError ResultKeySendError
) )
@ -150,7 +150,7 @@ func (u ResolutionResult) String() string {
return "mpp is overpaying set total" return "mpp is overpaying set total"
case ResultKeySendError: case ResultKeySendError:
return "invalid key send parameters" return "invalid keysend parameters"
default: default:
return "unknown" return "unknown"

View File

@ -15,7 +15,7 @@ import (
// decodePayReq decodes the invoice payment request if present. This is needed, // decodePayReq decodes the invoice payment request if present. This is needed,
// because not all information is stored in dedicated invoice fields. If there // 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 // 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, func decodePayReq(invoice *channeldb.Invoice,
activeNetParams *chaincfg.Params) (*zpay32.Invoice, error) { activeNetParams *chaincfg.Params) (*zpay32.Invoice, error) {
@ -146,7 +146,7 @@ func CreateRPCInvoice(invoice *channeldb.Invoice,
State: state, State: state,
Htlcs: rpcHtlcs, Htlcs: rpcHtlcs,
Features: CreateRPCFeatures(invoice.Terms.Features), Features: CreateRPCFeatures(invoice.Terms.Features),
IsKeySend: len(invoice.PaymentRequest) == 0, IsKeysend: len(invoice.PaymentRequest) == 0,
} }
if preimage != channeldb.UnknownPreimage { if preimage != channeldb.UnknownPreimage {

File diff suppressed because it is too large Load Diff

View File

@ -2575,7 +2575,7 @@ message Invoice {
Indicates if this invoice was a spontaneous payment that arrived via keysend Indicates if this invoice was a spontaneous payment that arrived via keysend
[EXPERIMENTAL]. [EXPERIMENTAL].
*/ */
bool is_key_send = 25 [json_name = "is_key_send"]; bool is_keysend = 25 [json_name = "is_keysend"];
} }
enum InvoiceHTLCState { enum InvoiceHTLCState {

View File

@ -2943,7 +2943,7 @@
}, },
"description": "/ List of features advertised on the invoice." "description": "/ List of features advertised on the invoice."
}, },
"is_key_send": { "is_keysend": {
"type": "boolean", "type": "boolean",
"format": "boolean", "format": "boolean",
"description": "*\nIndicates if this invoice was a spontaneous payment that arrived via keysend\n[EXPERIMENTAL]." "description": "*\nIndicates if this invoice was a spontaneous payment that arrived via keysend\n[EXPERIMENTAL]."

View File

@ -140,7 +140,7 @@ func testSingleHopInvoice(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf(err.Error()) t.Fatalf(err.Error())
} }
// Next send a key send payment. // Next send a keysend payment.
keySendPreimage := lntypes.Preimage{3, 4, 5, 11} keySendPreimage := lntypes.Preimage{3, 4, 5, 11}
keySendHash := keySendPreimage.Hash() keySendHash := keySendPreimage.Hash()
@ -162,7 +162,7 @@ func testSingleHopInvoice(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("error when attempting recv: %v", resp.PaymentError) 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. // being update accordingly.
err = wait.NoError( err = wait.NoError(
assertAmountSent(3*paymentAmt, net.Alice, net.Bob), assertAmountSent(3*paymentAmt, net.Alice, net.Bob),

View File

@ -228,7 +228,7 @@ func (cfg NodeConfig) genArgs() []string {
} }
if cfg.AcceptKeySend { if cfg.AcceptKeySend {
args = append(args, "--accept-key-send") args = append(args, "--accept-keysend")
} }
return args return args
@ -317,9 +317,9 @@ func newNode(cfg NodeConfig) (*HarnessNode, error) {
cfg.P2PPort, cfg.RPCPort, cfg.RESTPort, cfg.ProfilePort = generateListeningPorts() cfg.P2PPort, cfg.RPCPort, cfg.RESTPort, cfg.ProfilePort = generateListeningPorts()
// Run all tests with accept key send. The key send code is very // Run all tests with accept keysend. The keysend code is very isolated
// isolated and it is highly unlikely that it would affect regular // and it is highly unlikely that it would affect regular itests when
// itests when enabled. // enabled.
cfg.AcceptKeySend = true cfg.AcceptKeySend = true
numActiveNodesMtx.Lock() numActiveNodesMtx.Lock()

View File

@ -1,6 +1,6 @@
package record package record
const ( const (
// KeySendType is the custom record identifier for key send preimages. // KeySendType is the custom record identifier for keysend preimages.
KeySendType uint64 = 5482373484 KeySendType uint64 = 5482373484
) )