mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-05 17:05:50 +02:00
channeldb+lnrpc: store the payment pre-image not rhash
Fixes #481. Prior to this commit, payments stored in the channel DB only kept a record of the payment hash. This is a problem as the preimage is what serves as proof of payment and a user should be able to look up this value in the future (not just immediately after payment). Instead of storing both the payment hash and the preimage, we store the preimage only since the hash can be derrived from this using a SHA256. In the RPC listpayments command, we now give the preimage in addition to the payment hash.
This commit is contained in:
committed by
Olaoluwa Osuntokun
parent
fc18db0130
commit
0f161c5033
@@ -37,11 +37,9 @@ type OutgoingPayment struct {
|
||||
// compressed public key of each of the nodes involved in the payment.
|
||||
Path [][33]byte
|
||||
|
||||
// PaymentHash is the payment hash (r-hash) used to send the payment.
|
||||
//
|
||||
// TODO(roasbeef): weave through preimage on payment success to can
|
||||
// store only supplemental info the embedded Invoice
|
||||
PaymentHash [32]byte
|
||||
// PaymentPreimage is the preImage of a successful payment. This is used
|
||||
// to calculate the PaymentHash as well as serve as a proof of payment.
|
||||
PaymentPreimage [32]byte
|
||||
}
|
||||
|
||||
// AddPayment saves a successful payment to the database. It is assumed that
|
||||
@@ -163,7 +161,7 @@ func serializeOutgoingPayment(w io.Writer, p *OutgoingPayment) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := w.Write(p.PaymentHash[:]); err != nil {
|
||||
if _, err := w.Write(p.PaymentPreimage[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -204,7 +202,7 @@ func deserializeOutgoingPayment(r io.Reader) (*OutgoingPayment, error) {
|
||||
}
|
||||
p.TimeLockLength = byteOrder.Uint32(scratch[:4])
|
||||
|
||||
if _, err := r.Read(p.PaymentHash[:]); err != nil {
|
||||
if _, err := r.Read(p.PaymentPreimage[:]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user