Merge pull request #3402 from joostjager/remove-debug-invoice
multi: remove debug invoices
This commit is contained in:
commit
701244012a
15
config.go
15
config.go
@ -269,7 +269,6 @@ type config struct {
|
|||||||
|
|
||||||
Profile string `long:"profile" description:"Enable HTTP profiling on given port -- NOTE port must be between 1024 and 65535"`
|
Profile string `long:"profile" description:"Enable HTTP profiling on given port -- NOTE port must be between 1024 and 65535"`
|
||||||
|
|
||||||
DebugHTLC bool `long:"debughtlc" description:"Activate the debug htlc mode. With the debug HTLC mode, all payments sent use a pre-determined R-Hash. Additionally, all HTLCs sent to a node with the debug HTLC R-Hash are immediately settled in the next available state transition."`
|
|
||||||
UnsafeDisconnect bool `long:"unsafe-disconnect" description:"Allows the rpcserver to intentionally disconnect from peers with open channels. USED FOR TESTING ONLY."`
|
UnsafeDisconnect bool `long:"unsafe-disconnect" description:"Allows the rpcserver to intentionally disconnect from peers with open channels. USED FOR TESTING ONLY."`
|
||||||
UnsafeReplay bool `long:"unsafe-replay" description:"Causes a link to replay the adds on its commitment txn after starting up, this enables testing of the sphinx replay logic."`
|
UnsafeReplay bool `long:"unsafe-replay" description:"Causes a link to replay the adds on its commitment txn after starting up, this enables testing of the sphinx replay logic."`
|
||||||
MaxPendingChannels int `long:"maxpendingchannels" description:"The maximum number of incoming pending channels permitted per peer."`
|
MaxPendingChannels int `long:"maxpendingchannels" description:"The maximum number of incoming pending channels permitted per peer."`
|
||||||
@ -718,13 +717,6 @@ func loadConfig() (*config, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.Litecoin.MainNet && cfg.DebugHTLC {
|
|
||||||
str := "%s: debug-htlc mode cannot be used " +
|
|
||||||
"on litecoin mainnet"
|
|
||||||
err := fmt.Errorf(str, funcName)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// The litecoin chain is the current active chain. However
|
// The litecoin chain is the current active chain. However
|
||||||
// throughout the codebase we required chaincfg.Params. So as a
|
// throughout the codebase we required chaincfg.Params. So as a
|
||||||
// temporary hack, we'll mutate the default net params for
|
// temporary hack, we'll mutate the default net params for
|
||||||
@ -807,13 +799,6 @@ func loadConfig() (*config, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.Bitcoin.MainNet && cfg.DebugHTLC {
|
|
||||||
str := "%s: debug-htlc mode cannot be used " +
|
|
||||||
"on bitcoin mainnet"
|
|
||||||
err := fmt.Errorf(str, funcName)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if cfg.Bitcoin.Node == "neutrino" && cfg.Bitcoin.MainNet {
|
if cfg.Bitcoin.Node == "neutrino" && cfg.Bitcoin.MainNet {
|
||||||
str := "%s: neutrino isn't yet supported for " +
|
str := "%s: neutrino isn't yet supported for " +
|
||||||
"bitcoin's mainnet"
|
"bitcoin's mainnet"
|
||||||
|
@ -191,16 +191,10 @@ type ChannelLinkConfig struct {
|
|||||||
// transaction to ensure timely confirmation.
|
// transaction to ensure timely confirmation.
|
||||||
FeeEstimator lnwallet.FeeEstimator
|
FeeEstimator lnwallet.FeeEstimator
|
||||||
|
|
||||||
// DebugHTLC should be turned on if you want all HTLCs sent to a node
|
|
||||||
// with the debug htlc R-Hash are immediately settled in the next
|
|
||||||
// available state transition.
|
|
||||||
DebugHTLC bool
|
|
||||||
|
|
||||||
// hodl.Mask is a bitvector composed of hodl.Flags, specifying breakpoints
|
// hodl.Mask is a bitvector composed of hodl.Flags, specifying breakpoints
|
||||||
// for HTLC forwarding internal to the switch.
|
// for HTLC forwarding internal to the switch.
|
||||||
//
|
//
|
||||||
// NOTE: This should only be used for testing, and should only be used
|
// NOTE: This should only be used for testing.
|
||||||
// simultaneously with DebugHTLC.
|
|
||||||
HodlMask hodl.Mask
|
HodlMask hodl.Mask
|
||||||
|
|
||||||
// SyncStates is used to indicate that we need send the channel
|
// SyncStates is used to indicate that we need send the channel
|
||||||
@ -1256,7 +1250,7 @@ func (l *channelLink) handleDownStreamPkt(pkt *htlcPacket, isReProcess bool) {
|
|||||||
// If hodl.AddOutgoing mode is active, we exit early to simulate
|
// If hodl.AddOutgoing mode is active, we exit early to simulate
|
||||||
// arbitrary delays between the switch adding an ADD to the
|
// arbitrary delays between the switch adding an ADD to the
|
||||||
// mailbox, and the HTLC being added to the commitment state.
|
// mailbox, and the HTLC being added to the commitment state.
|
||||||
if l.cfg.DebugHTLC && l.cfg.HodlMask.Active(hodl.AddOutgoing) {
|
if l.cfg.HodlMask.Active(hodl.AddOutgoing) {
|
||||||
l.warnf(hodl.AddOutgoing.Warning())
|
l.warnf(hodl.AddOutgoing.Warning())
|
||||||
l.mailBox.AckPacket(pkt.inKey())
|
l.mailBox.AckPacket(pkt.inKey())
|
||||||
return
|
return
|
||||||
@ -1378,7 +1372,7 @@ func (l *channelLink) handleDownStreamPkt(pkt *htlcPacket, isReProcess bool) {
|
|||||||
// simulate arbitrary delays between the switch adding the
|
// simulate arbitrary delays between the switch adding the
|
||||||
// SETTLE to the mailbox, and the HTLC being added to the
|
// SETTLE to the mailbox, and the HTLC being added to the
|
||||||
// commitment state.
|
// commitment state.
|
||||||
if l.cfg.DebugHTLC && l.cfg.HodlMask.Active(hodl.SettleOutgoing) {
|
if l.cfg.HodlMask.Active(hodl.SettleOutgoing) {
|
||||||
l.warnf(hodl.SettleOutgoing.Warning())
|
l.warnf(hodl.SettleOutgoing.Warning())
|
||||||
l.mailBox.AckPacket(pkt.inKey())
|
l.mailBox.AckPacket(pkt.inKey())
|
||||||
return
|
return
|
||||||
@ -1436,7 +1430,7 @@ func (l *channelLink) handleDownStreamPkt(pkt *htlcPacket, isReProcess bool) {
|
|||||||
// simulate arbitrary delays between the switch adding a FAIL to
|
// simulate arbitrary delays between the switch adding a FAIL to
|
||||||
// the mailbox, and the HTLC being added to the commitment
|
// the mailbox, and the HTLC being added to the commitment
|
||||||
// state.
|
// state.
|
||||||
if l.cfg.DebugHTLC && l.cfg.HodlMask.Active(hodl.FailOutgoing) {
|
if l.cfg.HodlMask.Active(hodl.FailOutgoing) {
|
||||||
l.warnf(hodl.FailOutgoing.Warning())
|
l.warnf(hodl.FailOutgoing.Warning())
|
||||||
l.mailBox.AckPacket(pkt.inKey())
|
l.mailBox.AckPacket(pkt.inKey())
|
||||||
return
|
return
|
||||||
@ -1948,7 +1942,7 @@ func (l *channelLink) updateCommitTx() error {
|
|||||||
// commit any in-memory modifications to the channel state. Exiting here
|
// commit any in-memory modifications to the channel state. Exiting here
|
||||||
// permits testing of either the switch or link's ability to trim
|
// permits testing of either the switch or link's ability to trim
|
||||||
// circuits that have been opened, but unsuccessfully committed.
|
// circuits that have been opened, but unsuccessfully committed.
|
||||||
if l.cfg.DebugHTLC && l.cfg.HodlMask.Active(hodl.Commit) {
|
if l.cfg.HodlMask.Active(hodl.Commit) {
|
||||||
l.warnf(hodl.Commit.Warning())
|
l.warnf(hodl.Commit.Warning())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -2445,7 +2439,7 @@ func (l *channelLink) processRemoteSettleFails(fwdPkg *channeldb.FwdPkg,
|
|||||||
// If hodl.SettleIncoming is requested, we will not
|
// If hodl.SettleIncoming is requested, we will not
|
||||||
// forward the SETTLE to the switch and will not signal
|
// forward the SETTLE to the switch and will not signal
|
||||||
// a free slot on the commitment transaction.
|
// a free slot on the commitment transaction.
|
||||||
if l.cfg.DebugHTLC && l.cfg.HodlMask.Active(hodl.SettleIncoming) {
|
if l.cfg.HodlMask.Active(hodl.SettleIncoming) {
|
||||||
l.warnf(hodl.SettleIncoming.Warning())
|
l.warnf(hodl.SettleIncoming.Warning())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -2473,7 +2467,7 @@ func (l *channelLink) processRemoteSettleFails(fwdPkg *channeldb.FwdPkg,
|
|||||||
// If hodl.SettleIncoming is requested, we will not
|
// If hodl.SettleIncoming is requested, we will not
|
||||||
// forward the FAIL to the switch and will not signal a
|
// forward the FAIL to the switch and will not signal a
|
||||||
// free slot on the commitment transaction.
|
// free slot on the commitment transaction.
|
||||||
if l.cfg.DebugHTLC && l.cfg.HodlMask.Active(hodl.FailIncoming) {
|
if l.cfg.HodlMask.Active(hodl.FailIncoming) {
|
||||||
l.warnf(hodl.FailIncoming.Warning())
|
l.warnf(hodl.FailIncoming.Warning())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -2654,8 +2648,7 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
|
|||||||
// If hodl.AddIncoming is requested, we will not
|
// If hodl.AddIncoming is requested, we will not
|
||||||
// validate the forwarded ADD, nor will we send the
|
// validate the forwarded ADD, nor will we send the
|
||||||
// packet to the htlc switch.
|
// packet to the htlc switch.
|
||||||
if l.cfg.DebugHTLC &&
|
if l.cfg.HodlMask.Active(hodl.AddIncoming) {
|
||||||
l.cfg.HodlMask.Active(hodl.AddIncoming) {
|
|
||||||
l.warnf(hodl.AddIncoming.Warning())
|
l.warnf(hodl.AddIncoming.Warning())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -2814,7 +2807,7 @@ func (l *channelLink) processExitHop(pd *lnwallet.PaymentDescriptor,
|
|||||||
// If hodl.ExitSettle is requested, we will not validate the final hop's
|
// If hodl.ExitSettle is requested, we will not validate the final hop's
|
||||||
// ADD, nor will we settle the corresponding invoice or respond with the
|
// ADD, nor will we settle the corresponding invoice or respond with the
|
||||||
// preimage.
|
// preimage.
|
||||||
if l.cfg.DebugHTLC && l.cfg.HodlMask.Active(hodl.ExitSettle) {
|
if l.cfg.HodlMask.Active(hodl.ExitSettle) {
|
||||||
l.warnf(hodl.ExitSettle.Warning())
|
l.warnf(hodl.ExitSettle.Warning())
|
||||||
|
|
||||||
return false, nil
|
return false, nil
|
||||||
@ -2823,7 +2816,7 @@ func (l *channelLink) processExitHop(pd *lnwallet.PaymentDescriptor,
|
|||||||
// As we're the exit hop, we'll double check the hop-payload included in
|
// As we're the exit hop, we'll double check the hop-payload included in
|
||||||
// the HTLC to ensure that it was crafted correctly by the sender and
|
// the HTLC to ensure that it was crafted correctly by the sender and
|
||||||
// matches the HTLC we were extended.
|
// matches the HTLC we were extended.
|
||||||
if !l.cfg.DebugHTLC && pd.Amount != fwdInfo.AmountToForward {
|
if pd.Amount != fwdInfo.AmountToForward {
|
||||||
|
|
||||||
log.Errorf("Onion payload of incoming htlc(%x) has incorrect "+
|
log.Errorf("Onion payload of incoming htlc(%x) has incorrect "+
|
||||||
"value: expected %v, got %v", pd.RHash,
|
"value: expected %v, got %v", pd.RHash,
|
||||||
@ -2837,7 +2830,7 @@ func (l *channelLink) processExitHop(pd *lnwallet.PaymentDescriptor,
|
|||||||
|
|
||||||
// We'll also ensure that our time-lock value has been computed
|
// We'll also ensure that our time-lock value has been computed
|
||||||
// correctly.
|
// correctly.
|
||||||
if !l.cfg.DebugHTLC && pd.Timeout != fwdInfo.OutgoingCTLV {
|
if pd.Timeout != fwdInfo.OutgoingCTLV {
|
||||||
log.Errorf("Onion payload of incoming htlc(%x) has incorrect "+
|
log.Errorf("Onion payload of incoming htlc(%x) has incorrect "+
|
||||||
"time-lock: expected %v, got %v",
|
"time-lock: expected %v, got %v",
|
||||||
pd.RHash[:], pd.Timeout, fwdInfo.OutgoingCTLV)
|
pd.RHash[:], pd.Timeout, fwdInfo.OutgoingCTLV)
|
||||||
@ -2914,7 +2907,7 @@ func (l *channelLink) settleHTLC(preimage lntypes.Preimage, htlcIndex uint64,
|
|||||||
|
|
||||||
// If the link is in hodl.BogusSettle mode, replace the preimage with a
|
// If the link is in hodl.BogusSettle mode, replace the preimage with a
|
||||||
// fake one before sending it to the peer.
|
// fake one before sending it to the peer.
|
||||||
if l.cfg.DebugHTLC && l.cfg.HodlMask.Active(hodl.BogusSettle) {
|
if l.cfg.HodlMask.Active(hodl.BogusSettle) {
|
||||||
l.warnf(hodl.BogusSettle.Warning())
|
l.warnf(hodl.BogusSettle.Warning())
|
||||||
preimage = [32]byte{}
|
preimage = [32]byte{}
|
||||||
copy(preimage[:], bytes.Repeat([]byte{2}, 32))
|
copy(preimage[:], bytes.Repeat([]byte{2}, 32))
|
||||||
|
@ -1908,7 +1908,6 @@ func TestChannelLinkBandwidthConsistency(t *testing.T) {
|
|||||||
// We put Alice into hodl.ExitSettle mode, such that she won't settle
|
// We put Alice into hodl.ExitSettle mode, such that she won't settle
|
||||||
// incoming HTLCs automatically.
|
// incoming HTLCs automatically.
|
||||||
coreLink.cfg.HodlMask = hodl.MaskFromFlags(hodl.ExitSettle)
|
coreLink.cfg.HodlMask = hodl.MaskFromFlags(hodl.ExitSettle)
|
||||||
coreLink.cfg.DebugHTLC = true
|
|
||||||
|
|
||||||
estimator := lnwallet.NewStaticFeeEstimator(6000, 0)
|
estimator := lnwallet.NewStaticFeeEstimator(6000, 0)
|
||||||
feePerKw, err := estimator.EstimateFeePerKW(1)
|
feePerKw, err := estimator.EstimateFeePerKW(1)
|
||||||
@ -2857,7 +2856,6 @@ func TestChannelLinkTrimCircuitsNoCommit(t *testing.T) {
|
|||||||
// outgoing ADDs are opened, but the changes are not committed in the
|
// outgoing ADDs are opened, but the changes are not committed in the
|
||||||
// channel state.
|
// channel state.
|
||||||
alice.coreLink.cfg.HodlMask = hodl.Commit.Mask()
|
alice.coreLink.cfg.HodlMask = hodl.Commit.Mask()
|
||||||
alice.coreLink.cfg.DebugHTLC = true
|
|
||||||
|
|
||||||
// Compute the static fees that will be used to determine the
|
// Compute the static fees that will be used to determine the
|
||||||
// correctness of Alice's bandwidth when forwarding HTLCs.
|
// correctness of Alice's bandwidth when forwarding HTLCs.
|
||||||
@ -4233,7 +4231,6 @@ func (h *persistentLinkHarness) restartLink(
|
|||||||
MaxFeeUpdateTimeout: 40 * time.Minute,
|
MaxFeeUpdateTimeout: 40 * time.Minute,
|
||||||
// Set any hodl flags requested for the new link.
|
// Set any hodl flags requested for the new link.
|
||||||
HodlMask: hodl.MaskFromFlags(hodlFlags...),
|
HodlMask: hodl.MaskFromFlags(hodlFlags...),
|
||||||
DebugHTLC: len(hodlFlags) > 0,
|
|
||||||
MaxOutgoingCltvExpiry: DefaultMaxOutgoingCltvExpiry,
|
MaxOutgoingCltvExpiry: DefaultMaxOutgoingCltvExpiry,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4934,7 +4931,6 @@ func TestChannelLinkCleanupSpuriousResponses(t *testing.T) {
|
|||||||
// Settle Alice in hodl ExitSettle mode so that she won't respond
|
// Settle Alice in hodl ExitSettle mode so that she won't respond
|
||||||
// immediately to the htlc's meant for her. This allows us to control
|
// immediately to the htlc's meant for her. This allows us to control
|
||||||
// the responses she gives back to Bob.
|
// the responses she gives back to Bob.
|
||||||
coreLink.cfg.DebugHTLC = true
|
|
||||||
coreLink.cfg.HodlMask = hodl.ExitSettle.Mask()
|
coreLink.cfg.HodlMask = hodl.ExitSettle.Mask()
|
||||||
|
|
||||||
// Add two HTLCs to Alice's registry, that Bob can pay.
|
// Add two HTLCs to Alice's registry, that Bob can pay.
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
package invoices
|
package invoices
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/btcsuite/btcutil"
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
"github.com/lightningnetwork/lnd/lntypes"
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
@ -16,18 +13,6 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/queue"
|
"github.com/lightningnetwork/lnd/queue"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
// DebugPre is the default debug preimage which is inserted into the
|
|
||||||
// invoice registry if the --debughtlc flag is activated on start up.
|
|
||||||
// All nodes initialized with the flag active will immediately settle
|
|
||||||
// any incoming HTLC whose rHash corresponds with the debug
|
|
||||||
// preimage.
|
|
||||||
DebugPre, _ = lntypes.MakePreimage(bytes.Repeat([]byte{1}, 32))
|
|
||||||
|
|
||||||
// DebugHash is the hash of the default preimage.
|
|
||||||
DebugHash = DebugPre.Hash()
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// ErrInvoiceExpiryTooSoon is returned when an invoice is attempted to be
|
// ErrInvoiceExpiryTooSoon is returned when an invoice is attempted to be
|
||||||
// accepted or settled with not enough blocks remaining.
|
// accepted or settled with not enough blocks remaining.
|
||||||
@ -73,11 +58,6 @@ type InvoiceRegistry struct {
|
|||||||
// new single invoice subscriptions are carried.
|
// new single invoice subscriptions are carried.
|
||||||
invoiceEvents chan interface{}
|
invoiceEvents chan interface{}
|
||||||
|
|
||||||
// debugInvoices is a map which stores special "debug" invoices which
|
|
||||||
// should be only created/used when manual tests require an invoice
|
|
||||||
// that *all* nodes are able to fully settle.
|
|
||||||
debugInvoices map[lntypes.Hash]*channeldb.Invoice
|
|
||||||
|
|
||||||
// decodeFinalCltvExpiry is a function used to decode the final expiry
|
// decodeFinalCltvExpiry is a function used to decode the final expiry
|
||||||
// value from the payment request.
|
// value from the payment request.
|
||||||
decodeFinalCltvExpiry func(invoice string) (uint32, error)
|
decodeFinalCltvExpiry func(invoice string) (uint32, error)
|
||||||
@ -110,7 +90,6 @@ func NewRegistry(cdb *channeldb.DB, decodeFinalCltvExpiry func(invoice string) (
|
|||||||
|
|
||||||
return &InvoiceRegistry{
|
return &InvoiceRegistry{
|
||||||
cdb: cdb,
|
cdb: cdb,
|
||||||
debugInvoices: make(map[lntypes.Hash]*channeldb.Invoice),
|
|
||||||
notificationClients: make(map[uint32]*InvoiceSubscription),
|
notificationClients: make(map[uint32]*InvoiceSubscription),
|
||||||
singleNotificationClients: make(map[uint32]*SingleInvoiceSubscription),
|
singleNotificationClients: make(map[uint32]*SingleInvoiceSubscription),
|
||||||
newSubscriptions: make(chan *InvoiceSubscription),
|
newSubscriptions: make(chan *InvoiceSubscription),
|
||||||
@ -392,32 +371,6 @@ func (i *InvoiceRegistry) deliverSingleBacklogEvents(
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddDebugInvoice adds a debug invoice for the specified amount, identified
|
|
||||||
// by the passed preimage. Once this invoice is added, subsystems within the
|
|
||||||
// daemon add/forward HTLCs that are able to obtain the proper preimage
|
|
||||||
// required for redemption in the case that we're the final destination.
|
|
||||||
func (i *InvoiceRegistry) AddDebugInvoice(amt btcutil.Amount,
|
|
||||||
preimage lntypes.Preimage) {
|
|
||||||
|
|
||||||
paymentHash := preimage.Hash()
|
|
||||||
|
|
||||||
invoice := &channeldb.Invoice{
|
|
||||||
CreationDate: time.Now(),
|
|
||||||
Terms: channeldb.ContractTerm{
|
|
||||||
Value: lnwire.NewMSatFromSatoshis(amt),
|
|
||||||
PaymentPreimage: preimage,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
i.Lock()
|
|
||||||
i.debugInvoices[paymentHash] = invoice
|
|
||||||
i.Unlock()
|
|
||||||
|
|
||||||
log.Debugf("Adding debug invoice %v", newLogClosure(func() string {
|
|
||||||
return spew.Sdump(invoice)
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddInvoice adds a regular invoice for the specified amount, identified by
|
// AddInvoice adds a regular invoice for the specified amount, identified by
|
||||||
// the passed preimage. Additionally, any memo or receipt data provided will
|
// the passed preimage. Additionally, any memo or receipt data provided will
|
||||||
// also be stored on-disk. Once this invoice is added, subsystems within the
|
// also be stored on-disk. Once this invoice is added, subsystems within the
|
||||||
@ -458,19 +411,8 @@ func (i *InvoiceRegistry) AddInvoice(invoice *channeldb.Invoice,
|
|||||||
//
|
//
|
||||||
// TODO(roasbeef): ignore if settled?
|
// TODO(roasbeef): ignore if settled?
|
||||||
func (i *InvoiceRegistry) LookupInvoice(rHash lntypes.Hash) (channeldb.Invoice, uint32, error) {
|
func (i *InvoiceRegistry) LookupInvoice(rHash lntypes.Hash) (channeldb.Invoice, uint32, error) {
|
||||||
// First check the in-memory debug invoice index to see if this is an
|
// We'll check the database to see if there's an existing matching
|
||||||
// existing invoice added for debugging.
|
// invoice.
|
||||||
i.RLock()
|
|
||||||
debugInv, ok := i.debugInvoices[rHash]
|
|
||||||
i.RUnlock()
|
|
||||||
|
|
||||||
// If found, then simply return the invoice directly.
|
|
||||||
if ok {
|
|
||||||
return *debugInv, 0, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, we'll check the database to see if there's an existing
|
|
||||||
// matching invoice.
|
|
||||||
invoice, err := i.cdb.LookupInvoice(rHash)
|
invoice, err := i.cdb.LookupInvoice(rHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return channeldb.Invoice{}, 0, err
|
return channeldb.Invoice{}, 0, err
|
||||||
@ -556,18 +498,6 @@ func (i *InvoiceRegistry) NotifyExitHopHtlc(rHash lntypes.Hash,
|
|||||||
log.Debugf("Invoice(%x): %v, amt=%v, expiry=%v",
|
log.Debugf("Invoice(%x): %v, amt=%v, expiry=%v",
|
||||||
rHash[:], s, amtPaid, expiry)
|
rHash[:], s, amtPaid, expiry)
|
||||||
}
|
}
|
||||||
// First check the in-memory debug invoice index to see if this is an
|
|
||||||
// existing invoice added for debugging.
|
|
||||||
if invoice, ok := i.debugInvoices[rHash]; ok {
|
|
||||||
debugLog("payment to debug invoice accepted")
|
|
||||||
|
|
||||||
// Debug invoices are never fully settled, so we just settle the
|
|
||||||
// htlc in this case.
|
|
||||||
return &HodlEvent{
|
|
||||||
Hash: rHash,
|
|
||||||
Preimage: &invoice.Terms.PaymentPreimage,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// If this isn't a debug invoice, then we'll attempt to settle an
|
// If this isn't a debug invoice, then we'll attempt to settle an
|
||||||
// invoice matching this rHash on disk (if one exists).
|
// invoice matching this rHash on disk (if one exists).
|
||||||
|
@ -2372,10 +2372,7 @@ func testChannelUnsettledBalance(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
ctxb := context.Background()
|
ctxb := context.Background()
|
||||||
|
|
||||||
// Create carol in hodl mode.
|
// Create carol in hodl mode.
|
||||||
carol, err := net.NewNode("Carol", []string{
|
carol, err := net.NewNode("Carol", []string{"--hodl.exit-settle"})
|
||||||
"--debughtlc",
|
|
||||||
"--hodl.exit-settle",
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create new nodes: %v", err)
|
t.Fatalf("unable to create new nodes: %v", err)
|
||||||
}
|
}
|
||||||
@ -2642,7 +2639,7 @@ func testChannelForceClosure(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
// Since we'd like to test failure scenarios with outstanding htlcs,
|
// Since we'd like to test failure scenarios with outstanding htlcs,
|
||||||
// we'll introduce another node into our test network: Carol.
|
// we'll introduce another node into our test network: Carol.
|
||||||
carol, err := net.NewNode("Carol", []string{"--debughtlc", "--hodl.exit-settle"})
|
carol, err := net.NewNode("Carol", []string{"--hodl.exit-settle"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create new nodes: %v", err)
|
t.Fatalf("unable to create new nodes: %v", err)
|
||||||
}
|
}
|
||||||
@ -3420,7 +3417,7 @@ func testSphinxReplayPersistence(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
chanAmt := btcutil.Amount(100000)
|
chanAmt := btcutil.Amount(100000)
|
||||||
|
|
||||||
// First, we'll create Dave, the receiver, and start him in hodl mode.
|
// First, we'll create Dave, the receiver, and start him in hodl mode.
|
||||||
dave, err := net.NewNode("Dave", []string{"--debughtlc", "--hodl.exit-settle"})
|
dave, err := net.NewNode("Dave", []string{"--hodl.exit-settle"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create new nodes: %v", err)
|
t.Fatalf("unable to create new nodes: %v", err)
|
||||||
}
|
}
|
||||||
@ -6277,8 +6274,7 @@ func testFailingChannel(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
// We'll introduce Carol, which will settle any incoming invoice with a
|
// We'll introduce Carol, which will settle any incoming invoice with a
|
||||||
// totally unrelated preimage.
|
// totally unrelated preimage.
|
||||||
carol, err := net.NewNode("Carol",
|
carol, err := net.NewNode("Carol", []string{"--hodl.bogus-settle"})
|
||||||
[]string{"--debughtlc", "--hodl.bogus-settle"})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create new nodes: %v", err)
|
t.Fatalf("unable to create new nodes: %v", err)
|
||||||
}
|
}
|
||||||
@ -6740,7 +6736,7 @@ func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// protection logic automatically.
|
// protection logic automatically.
|
||||||
carol, err := net.NewNode(
|
carol, err := net.NewNode(
|
||||||
"Carol",
|
"Carol",
|
||||||
[]string{"--debughtlc", "--hodl.exit-settle", "--nolisten"},
|
[]string{"--hodl.exit-settle", "--nolisten"},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create new carol node: %v", err)
|
t.Fatalf("unable to create new carol node: %v", err)
|
||||||
@ -6992,7 +6988,7 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(net *lntest.NetworkHarness
|
|||||||
|
|
||||||
// Since we'd like to test some multi-hop failure scenarios, we'll
|
// Since we'd like to test some multi-hop failure scenarios, we'll
|
||||||
// introduce another node into our test network: Carol.
|
// introduce another node into our test network: Carol.
|
||||||
carol, err := net.NewNode("Carol", []string{"--debughtlc", "--hodl.exit-settle"})
|
carol, err := net.NewNode("Carol", []string{"--hodl.exit-settle"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create new nodes: %v", err)
|
t.Fatalf("unable to create new nodes: %v", err)
|
||||||
}
|
}
|
||||||
@ -7003,7 +6999,7 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(net *lntest.NetworkHarness
|
|||||||
// protection logic automatically.
|
// protection logic automatically.
|
||||||
dave, err := net.NewNode(
|
dave, err := net.NewNode(
|
||||||
"Dave",
|
"Dave",
|
||||||
[]string{"--debughtlc", "--hodl.exit-settle", "--nolisten"},
|
[]string{"--hodl.exit-settle", "--nolisten"},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create new node: %v", err)
|
t.Fatalf("unable to create new node: %v", err)
|
||||||
@ -7240,7 +7236,7 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
|
|||||||
// Since this test will result in the counterparty being left in a
|
// Since this test will result in the counterparty being left in a
|
||||||
// weird state, we will introduce another node into our test network:
|
// weird state, we will introduce another node into our test network:
|
||||||
// Carol.
|
// Carol.
|
||||||
carol, err := net.NewNode("Carol", []string{"--debughtlc", "--hodl.exit-settle"})
|
carol, err := net.NewNode("Carol", []string{"--hodl.exit-settle"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create new nodes: %v", err)
|
t.Fatalf("unable to create new nodes: %v", err)
|
||||||
}
|
}
|
||||||
@ -7253,7 +7249,7 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
|
|||||||
// trigger the channel data protection logic automatically.
|
// trigger the channel data protection logic automatically.
|
||||||
dave, err := net.NewNode(
|
dave, err := net.NewNode(
|
||||||
"Dave",
|
"Dave",
|
||||||
[]string{"--debughtlc", "--hodl.exit-settle", "--nolisten"},
|
[]string{"--hodl.exit-settle", "--nolisten"},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create new dave node: %v", err)
|
t.Fatalf("unable to create new dave node: %v", err)
|
||||||
@ -7657,9 +7653,7 @@ func testRevokedCloseRetributionAltruistWatchtower(net *lntest.NetworkHarness,
|
|||||||
|
|
||||||
// Since we'd like to test some multi-hop failure scenarios, we'll
|
// Since we'd like to test some multi-hop failure scenarios, we'll
|
||||||
// introduce another node into our test network: Carol.
|
// introduce another node into our test network: Carol.
|
||||||
carol, err := net.NewNode("Carol", []string{
|
carol, err := net.NewNode("Carol", []string{"--hodl.exit-settle"})
|
||||||
"--debughtlc", "--hodl.exit-settle",
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create new nodes: %v", err)
|
t.Fatalf("unable to create new nodes: %v", err)
|
||||||
}
|
}
|
||||||
@ -9854,7 +9848,7 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
|
|||||||
// Next, we'll create a new node "carol" and have Bob connect to her. If
|
// Next, we'll create a new node "carol" and have Bob connect to her. If
|
||||||
// the carolHodl flag is set, we'll make carol always hold onto the
|
// the carolHodl flag is set, we'll make carol always hold onto the
|
||||||
// HTLC, this way it'll force Bob to go to chain to resolve the HTLC.
|
// HTLC, this way it'll force Bob to go to chain to resolve the HTLC.
|
||||||
carolFlags := []string{"--debughtlc"}
|
carolFlags := []string{}
|
||||||
if carolHodl {
|
if carolHodl {
|
||||||
carolFlags = append(carolFlags, "--hodl.exit-settle")
|
carolFlags = append(carolFlags, "--hodl.exit-settle")
|
||||||
}
|
}
|
||||||
@ -10694,7 +10688,7 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// Next, we'll create Carol and establish a channel to from her to
|
// Next, we'll create Carol and establish a channel to from her to
|
||||||
// Dave. Carol is started in htlchodl mode so that we can disconnect the
|
// Dave. Carol is started in htlchodl mode so that we can disconnect the
|
||||||
// intermediary hops before starting the settle.
|
// intermediary hops before starting the settle.
|
||||||
carol, err := net.NewNode("Carol", []string{"--debughtlc", "--hodl.exit-settle"})
|
carol, err := net.NewNode("Carol", []string{"--hodl.exit-settle"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create new nodes: %v", err)
|
t.Fatalf("unable to create new nodes: %v", err)
|
||||||
}
|
}
|
||||||
@ -11017,7 +11011,7 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// Next, we'll create Carol and establish a channel to from her to
|
// Next, we'll create Carol and establish a channel to from her to
|
||||||
// Dave. Carol is started in htlchodl mode so that we can disconnect the
|
// Dave. Carol is started in htlchodl mode so that we can disconnect the
|
||||||
// intermediary hops before starting the settle.
|
// intermediary hops before starting the settle.
|
||||||
carol, err := net.NewNode("Carol", []string{"--debughtlc", "--hodl.exit-settle"})
|
carol, err := net.NewNode("Carol", []string{"--hodl.exit-settle"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create new nodes: %v", err)
|
t.Fatalf("unable to create new nodes: %v", err)
|
||||||
}
|
}
|
||||||
@ -11348,7 +11342,7 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
|
|||||||
// Next, we'll create Carol and establish a channel to from her to
|
// Next, we'll create Carol and establish a channel to from her to
|
||||||
// Dave. Carol is started in htlchodl mode so that we can disconnect the
|
// Dave. Carol is started in htlchodl mode so that we can disconnect the
|
||||||
// intermediary hops before starting the settle.
|
// intermediary hops before starting the settle.
|
||||||
carol, err := net.NewNode("Carol", []string{"--debughtlc", "--hodl.exit-settle"})
|
carol, err := net.NewNode("Carol", []string{"--hodl.exit-settle"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create new nodes: %v", err)
|
t.Fatalf("unable to create new nodes: %v", err)
|
||||||
}
|
}
|
||||||
@ -11684,7 +11678,7 @@ func testSwitchOfflineDeliveryOutgoingOffline(
|
|||||||
// Next, we'll create Carol and establish a channel to from her to
|
// Next, we'll create Carol and establish a channel to from her to
|
||||||
// Dave. Carol is started in htlchodl mode so that we can disconnect the
|
// Dave. Carol is started in htlchodl mode so that we can disconnect the
|
||||||
// intermediary hops before starting the settle.
|
// intermediary hops before starting the settle.
|
||||||
carol, err := net.NewNode("Carol", []string{"--debughtlc", "--hodl.exit-settle"})
|
carol, err := net.NewNode("Carol", []string{"--hodl.exit-settle"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create new nodes: %v", err)
|
t.Fatalf("unable to create new nodes: %v", err)
|
||||||
}
|
}
|
||||||
|
1
peer.go
1
peer.go
@ -560,7 +560,6 @@ func (p *peer) addLink(chanPoint *wire.OutPoint,
|
|||||||
DecodeHopIterators: p.server.sphinx.DecodeHopIterators,
|
DecodeHopIterators: p.server.sphinx.DecodeHopIterators,
|
||||||
ExtractErrorEncrypter: p.server.sphinx.ExtractErrorEncrypter,
|
ExtractErrorEncrypter: p.server.sphinx.ExtractErrorEncrypter,
|
||||||
FetchLastChannelUpdate: p.server.fetchLastChanUpdate(),
|
FetchLastChannelUpdate: p.server.fetchLastChanUpdate(),
|
||||||
DebugHTLC: cfg.DebugHTLC,
|
|
||||||
HodlMask: cfg.Hodl.Mask(),
|
HodlMask: cfg.Hodl.Mask(),
|
||||||
Registry: p.server.invoices,
|
Registry: p.server.invoices,
|
||||||
Switch: p.server.htlcSwitch,
|
Switch: p.server.htlcSwitch,
|
||||||
|
10
rpcserver.go
10
rpcserver.go
@ -29,7 +29,7 @@ import (
|
|||||||
"github.com/btcsuite/btcwallet/wallet/txauthor"
|
"github.com/btcsuite/btcwallet/wallet/txauthor"
|
||||||
"github.com/coreos/bbolt"
|
"github.com/coreos/bbolt"
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/grpc-ecosystem/go-grpc-middleware"
|
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
|
||||||
proxy "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
proxy "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||||
"github.com/lightningnetwork/lnd/autopilot"
|
"github.com/lightningnetwork/lnd/autopilot"
|
||||||
"github.com/lightningnetwork/lnd/build"
|
"github.com/lightningnetwork/lnd/build"
|
||||||
@ -3067,14 +3067,6 @@ func extractPaymentIntent(rpcPayReq *rpcPaymentRequest) (rpcPaymentIntent, error
|
|||||||
|
|
||||||
copy(payIntent.rHash[:], paymentHash)
|
copy(payIntent.rHash[:], paymentHash)
|
||||||
|
|
||||||
// If we're in debug HTLC mode, then all outgoing HTLCs will pay to the
|
|
||||||
// same debug rHash. Otherwise, we pay to the rHash specified within
|
|
||||||
// the RPC request.
|
|
||||||
case cfg.DebugHTLC &&
|
|
||||||
bytes.Equal(payIntent.rHash[:], lntypes.ZeroHash[:]):
|
|
||||||
|
|
||||||
copy(payIntent.rHash[:], invoices.DebugHash[:])
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
copy(payIntent.rHash[:], rpcPayReq.PaymentHash)
|
copy(payIntent.rHash[:], rpcPayReq.PaymentHash)
|
||||||
}
|
}
|
||||||
|
10
server.go
10
server.go
@ -396,16 +396,6 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
|
|||||||
subscribers: make(map[uint64]*preimageSubscriber),
|
subscribers: make(map[uint64]*preimageSubscriber),
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the debug HTLC flag is on, then we invoice a "master debug"
|
|
||||||
// invoice which all outgoing payments will be sent and all incoming
|
|
||||||
// HTLCs with the debug R-Hash immediately settled.
|
|
||||||
if cfg.DebugHTLC {
|
|
||||||
kiloCoin := btcutil.Amount(btcutil.SatoshiPerBitcoin * 1000)
|
|
||||||
s.invoices.AddDebugInvoice(kiloCoin, invoices.DebugPre)
|
|
||||||
srvrLog.Debugf("Debug HTLC invoice inserted, preimage=%x, hash=%x",
|
|
||||||
invoices.DebugPre[:], invoices.DebugHash[:])
|
|
||||||
}
|
|
||||||
|
|
||||||
_, currentHeight, err := s.cc.chainIO.GetBestBlock()
|
_, currentHeight, err := s.cc.chainIO.GetBestBlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user