invoices: use lntypes.Hash and lntypes.Preimage
Previously chainhash.Hash was used, which converts to/from string in reversed format. Payment hashes and preimages are supposed to be non-reversed.
This commit is contained in:
9 files changed
+35
-30
No files matched your search
@@ -1,9 +1,9 @@
|
||||
package htlcswitch
|
||||
|
||||
import (
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/lnpeer"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
|
||||
@@ -14,11 +14,11 @@ type InvoiceDatabase interface {
|
||||
// byte payment hash. This method should also reutrn the min final CLTV
|
||||
// delta for this invoice. We'll use this to ensure that the HTLC
|
||||
// extended to us gives us enough time to settle as we prescribe.
|
||||
LookupInvoice(chainhash.Hash) (channeldb.Invoice, uint32, error)
|
||||
LookupInvoice(lntypes.Hash) (channeldb.Invoice, uint32, error)
|
||||
|
||||
// SettleInvoice attempts to mark an invoice corresponding to the
|
||||
// passed payment hash as fully settled.
|
||||
SettleInvoice(payHash chainhash.Hash, paidAmount lnwire.MilliSatoshi) error
|
||||
SettleInvoice(payHash lntypes.Hash, paidAmount lnwire.MilliSatoshi) error
|
||||
}
|
||||
|
||||
// ChannelLink is an interface which represents the subsystem for managing the
|
||||
|
||||
+2
-2
@@ -9,7 +9,6 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
@@ -17,6 +16,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/htlcswitch/hodl"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/lnpeer"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/ticker"
|
||||
@@ -2312,7 +2312,7 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
|
||||
// We're the designated payment destination. Therefore
|
||||
// we attempt to see if we have an invoice locally
|
||||
// which'll allow us to settle this htlc.
|
||||
invoiceHash := chainhash.Hash(pd.RHash)
|
||||
invoiceHash := lntypes.Hash(pd.RHash)
|
||||
invoice, minCltvDelta, err := l.cfg.Registry.LookupInvoice(
|
||||
invoiceHash,
|
||||
)
|
||||
|
||||
+7
-7
@@ -17,7 +17,6 @@ import (
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/txscript"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/fastsha256"
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/lightningnetwork/lightning-onion"
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
@@ -25,6 +24,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/contractcourt"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/lnpeer"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/ticker"
|
||||
@@ -686,18 +686,18 @@ var _ ChannelLink = (*mockChannelLink)(nil)
|
||||
type mockInvoiceRegistry struct {
|
||||
sync.Mutex
|
||||
|
||||
invoices map[chainhash.Hash]channeldb.Invoice
|
||||
invoices map[lntypes.Hash]channeldb.Invoice
|
||||
finalDelta uint32
|
||||
}
|
||||
|
||||
func newMockRegistry(minDelta uint32) *mockInvoiceRegistry {
|
||||
return &mockInvoiceRegistry{
|
||||
finalDelta: minDelta,
|
||||
invoices: make(map[chainhash.Hash]channeldb.Invoice),
|
||||
invoices: make(map[lntypes.Hash]channeldb.Invoice),
|
||||
}
|
||||
}
|
||||
|
||||
func (i *mockInvoiceRegistry) LookupInvoice(rHash chainhash.Hash) (channeldb.Invoice, uint32, error) {
|
||||
func (i *mockInvoiceRegistry) LookupInvoice(rHash lntypes.Hash) (channeldb.Invoice, uint32, error) {
|
||||
i.Lock()
|
||||
defer i.Unlock()
|
||||
|
||||
@@ -710,7 +710,7 @@ func (i *mockInvoiceRegistry) LookupInvoice(rHash chainhash.Hash) (channeldb.Inv
|
||||
return invoice, i.finalDelta, nil
|
||||
}
|
||||
|
||||
func (i *mockInvoiceRegistry) SettleInvoice(rhash chainhash.Hash,
|
||||
func (i *mockInvoiceRegistry) SettleInvoice(rhash lntypes.Hash,
|
||||
amt lnwire.MilliSatoshi) error {
|
||||
|
||||
i.Lock()
|
||||
@@ -736,8 +736,8 @@ func (i *mockInvoiceRegistry) AddInvoice(invoice channeldb.Invoice) error {
|
||||
i.Lock()
|
||||
defer i.Unlock()
|
||||
|
||||
rhash := fastsha256.Sum256(invoice.Terms.PaymentPreimage[:])
|
||||
i.invoices[chainhash.Hash(rhash)] = invoice
|
||||
rhash := invoice.Terms.PaymentPreimage.Hash()
|
||||
i.invoices[rhash] = invoice
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
"github.com/lightningnetwork/lnd/lnpeer"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/shachain"
|
||||
@@ -651,11 +652,11 @@ func generateHops(payAmt lnwire.MilliSatoshi, startingHeight uint32,
|
||||
}
|
||||
|
||||
type paymentResponse struct {
|
||||
rhash chainhash.Hash
|
||||
rhash lntypes.Hash
|
||||
err chan error
|
||||
}
|
||||
|
||||
func (r *paymentResponse) Wait(d time.Duration) (chainhash.Hash, error) {
|
||||
func (r *paymentResponse) Wait(d time.Duration) (lntypes.Hash, error) {
|
||||
select {
|
||||
case err := <-r.err:
|
||||
close(r.err)
|
||||
@@ -680,7 +681,7 @@ func (n *threeHopNetwork) makePayment(sendingPeer, receivingPeer lnpeer.Peer,
|
||||
|
||||
paymentErr := make(chan error, 1)
|
||||
|
||||
var rhash chainhash.Hash
|
||||
var rhash lntypes.Hash
|
||||
|
||||
sender := sendingPeer.(*mockServer)
|
||||
receiver := receivingPeer.(*mockServer)
|
||||
|
||||
Reference in new issue
Block a user