channeldb: update the OutgoingPayment struct to use lnwire.MilliSatoshi

This commit is contained in:
Olaoluwa Osuntokun 2017-08-21 22:49:56 -07:00
parent 6e17c34229
commit 063525c6e0
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
3 changed files with 20 additions and 18 deletions

@ -6,7 +6,7 @@ import (
"io" "io"
"github.com/boltdb/bolt" "github.com/boltdb/bolt"
"github.com/roasbeef/btcutil" "github.com/lightningnetwork/lnd/lnwire"
) )
var ( var (
@ -25,8 +25,8 @@ var (
type OutgoingPayment struct { type OutgoingPayment struct {
Invoice Invoice
// Fee is the total fee paid for the payment in satoshis. // Fee is the total fee paid for the payment in milli-satoshis.
Fee btcutil.Amount Fee lnwire.MilliSatoshi
// TotalTimeLock is the total cumulative time-lock in the HTLC extended // TotalTimeLock is the total cumulative time-lock in the HTLC extended
// from the second-to-last hop to the destination. // from the second-to-last hop to the destination.
@ -184,7 +184,7 @@ func deserializeOutgoingPayment(r io.Reader) (*OutgoingPayment, error) {
if _, err := r.Read(scratch[:]); err != nil { if _, err := r.Read(scratch[:]); err != nil {
return nil, err return nil, err
} }
p.Fee = btcutil.Amount(byteOrder.Uint64(scratch[:])) p.Fee = lnwire.MilliSatoshi(byteOrder.Uint64(scratch[:]))
if _, err = r.Read(scratch[:4]); err != nil { if _, err = r.Read(scratch[:4]); err != nil {
return nil, err return nil, err

@ -10,7 +10,7 @@ import (
"time" "time"
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
"github.com/roasbeef/btcutil" "github.com/lightningnetwork/lnd/lnwire"
) )
func makeFakePayment() *OutgoingPayment { func makeFakePayment() *OutgoingPayment {
@ -21,7 +21,7 @@ func makeFakePayment() *OutgoingPayment {
} }
copy(fakeInvoice.Terms.PaymentPreimage[:], rev[:]) copy(fakeInvoice.Terms.PaymentPreimage[:], rev[:])
fakeInvoice.Terms.Value = btcutil.Amount(10000) fakeInvoice.Terms.Value = lnwire.NewMSatFromSatoshis(10000)
fakePath := make([][33]byte, 3) fakePath := make([][33]byte, 3)
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {
@ -71,7 +71,7 @@ func makeRandomFakePayment() (*OutgoingPayment, error) {
} }
copy(fakeInvoice.Terms.PaymentPreimage[:], preImg) copy(fakeInvoice.Terms.PaymentPreimage[:], preImg)
fakeInvoice.Terms.Value = btcutil.Amount(rand.Intn(10000)) fakeInvoice.Terms.Value = lnwire.MilliSatoshi(rand.Intn(10000))
fakePathLen := 1 + rand.Intn(5) fakePathLen := 1 + rand.Intn(5)
fakePath := make([][33]byte, fakePathLen) fakePath := make([][33]byte, fakePathLen)
@ -86,7 +86,7 @@ func makeRandomFakePayment() (*OutgoingPayment, error) {
rHash := sha256.Sum256(fakeInvoice.Terms.PaymentPreimage[:]) rHash := sha256.Sum256(fakeInvoice.Terms.PaymentPreimage[:])
fakePayment := &OutgoingPayment{ fakePayment := &OutgoingPayment{
Invoice: *fakeInvoice, Invoice: *fakeInvoice,
Fee: btcutil.Amount(rand.Intn(1001)), Fee: lnwire.MilliSatoshi(rand.Intn(1001)),
Path: fakePath, Path: fakePath,
TimeLockLength: uint32(rand.Intn(10000)), TimeLockLength: uint32(rand.Intn(10000)),
PaymentHash: rHash, PaymentHash: rHash,

@ -11,6 +11,7 @@ import (
"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/lnwire"
"github.com/roasbeef/btcd/blockchain" "github.com/roasbeef/btcd/blockchain"
"github.com/roasbeef/btcd/chaincfg/chainhash" "github.com/roasbeef/btcd/chaincfg/chainhash"
"github.com/roasbeef/btcutil/hdkeychain" "github.com/roasbeef/btcutil/hdkeychain"
@ -102,9 +103,9 @@ type initFundingReserveMsg struct {
// of the accepted base fee rate of the network. // of the accepted base fee rate of the network.
feePerKw btcutil.Amount feePerKw btcutil.Amount
// pushSat is the number of satoshis that should be pushed over the // pushMSat is the number of milli-satoshis that should be pushed over
// responder as part of the initial channel creation. // the responder as part of the initial channel creation.
pushSat btcutil.Amount pushMSat lnwire.MilliSatoshi
// err is a channel in which all errors will be sent across. Will be // err is a channel in which all errors will be sent across. Will be
// nil if this initial set is successful. // nil if this initial set is successful.
@ -444,7 +445,8 @@ out:
// transaction, and that the signature we records for our version of the // transaction, and that the signature we records for our version of the
// commitment transaction is valid. // commitment transaction is valid.
func (l *LightningWallet) InitChannelReservation( func (l *LightningWallet) InitChannelReservation(
capacity, ourFundAmt, pushSat, feePerKw btcutil.Amount, capacity, ourFundAmt btcutil.Amount, pushMSat lnwire.MilliSatoshi,
feePerKw btcutil.Amount,
theirID *btcec.PublicKey, theirAddr *net.TCPAddr, theirID *btcec.PublicKey, theirAddr *net.TCPAddr,
chainHash *chainhash.Hash) (*ChannelReservation, error) { chainHash *chainhash.Hash) (*ChannelReservation, error) {
@ -458,7 +460,7 @@ func (l *LightningWallet) InitChannelReservation(
fundingAmount: ourFundAmt, fundingAmount: ourFundAmt,
capacity: capacity, capacity: capacity,
feePerKw: feePerKw, feePerKw: feePerKw,
pushSat: pushSat, pushMSat: pushMSat,
err: errChan, err: errChan,
resp: respChan, resp: respChan,
} }
@ -489,7 +491,7 @@ func (l *LightningWallet) handleFundingReserveRequest(req *initFundingReserveMsg
id := atomic.AddUint64(&l.nextFundingID, 1) id := atomic.AddUint64(&l.nextFundingID, 1)
reservation := NewChannelReservation(req.capacity, req.fundingAmount, reservation := NewChannelReservation(req.capacity, req.fundingAmount,
req.feePerKw, l, id, req.pushSat, l.Cfg.NetParams.GenesisHash) req.feePerKw, l, id, req.pushMSat, l.Cfg.NetParams.GenesisHash)
// Grab the mutex on the ChannelReservation to ensure thread-safety // Grab the mutex on the ChannelReservation to ensure thread-safety
reservation.Lock() reservation.Lock()
@ -826,8 +828,8 @@ func (l *LightningWallet) handleContributionMsg(req *addContributionMsg) {
} }
// With the funding tx complete, create both commitment transactions. // With the funding tx complete, create both commitment transactions.
localBalance := pendingReservation.partialState.LocalBalance localBalance := pendingReservation.partialState.LocalBalance.ToSatoshis()
remoteBalance := pendingReservation.partialState.RemoteBalance remoteBalance := pendingReservation.partialState.RemoteBalance.ToSatoshis()
ourCommitTx, theirCommitTx, err := CreateCommitmentTxns( ourCommitTx, theirCommitTx, err := CreateCommitmentTxns(
localBalance, remoteBalance, ourContribution.ChannelConfig, localBalance, remoteBalance, ourContribution.ChannelConfig,
theirContribution.ChannelConfig, theirContribution.ChannelConfig,
@ -1141,8 +1143,8 @@ func (l *LightningWallet) handleSingleFunderSigs(req *addSingleFunderSigsMsg) {
// Now that we have the funding outpoint, we can generate both versions // Now that we have the funding outpoint, we can generate both versions
// of the commitment transaction, and generate a signature for the // of the commitment transaction, and generate a signature for the
// remote node's commitment transactions. // remote node's commitment transactions.
localBalance := pendingReservation.partialState.LocalBalance localBalance := pendingReservation.partialState.LocalBalance.ToSatoshis()
remoteBalance := pendingReservation.partialState.RemoteBalance remoteBalance := pendingReservation.partialState.RemoteBalance.ToSatoshis()
ourCommitTx, theirCommitTx, err := CreateCommitmentTxns( ourCommitTx, theirCommitTx, err := CreateCommitmentTxns(
localBalance, remoteBalance, localBalance, remoteBalance,
pendingReservation.ourContribution.ChannelConfig, pendingReservation.ourContribution.ChannelConfig,