mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-07 19:30:46 +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
@@ -2,7 +2,6 @@ package channeldb
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"reflect"
|
||||
@@ -31,13 +30,14 @@ func makeFakePayment() *OutgoingPayment {
|
||||
copy(fakePath[i][:], bytes.Repeat([]byte{byte(i)}, 33))
|
||||
}
|
||||
|
||||
return &OutgoingPayment{
|
||||
fakePayment := &OutgoingPayment{
|
||||
Invoice: *fakeInvoice,
|
||||
Fee: 101,
|
||||
Path: fakePath,
|
||||
TimeLockLength: 1000,
|
||||
PaymentHash: sha256.Sum256(rev[:]),
|
||||
}
|
||||
copy(fakePayment.PaymentPreimage[:], rev[:])
|
||||
return fakePayment
|
||||
}
|
||||
|
||||
// randomBytes creates random []byte with length in range [minLen, maxLen)
|
||||
@@ -90,14 +90,13 @@ func makeRandomFakePayment() (*OutgoingPayment, error) {
|
||||
copy(fakePath[i][:], b)
|
||||
}
|
||||
|
||||
rHash := sha256.Sum256(fakeInvoice.Terms.PaymentPreimage[:])
|
||||
fakePayment := &OutgoingPayment{
|
||||
Invoice: *fakeInvoice,
|
||||
Fee: lnwire.MilliSatoshi(rand.Intn(1001)),
|
||||
Path: fakePath,
|
||||
TimeLockLength: uint32(rand.Intn(10000)),
|
||||
PaymentHash: rHash,
|
||||
}
|
||||
copy(fakePayment.PaymentPreimage[:], fakeInvoice.Terms.PaymentPreimage[:])
|
||||
|
||||
return fakePayment, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user