lnwallet: update funding flow to use new channeldb API's

This commit is contained in:
Olaoluwa Osuntokun 2017-11-10 14:18:41 -08:00
parent 367c6b10fc
commit 7f667e2dbc
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
2 changed files with 31 additions and 21 deletions

@ -205,16 +205,24 @@ func NewChannelReservation(capacity, fundingAmt, feePerKw btcutil.Amount,
ChannelConfig: &channeldb.ChannelConfig{}, ChannelConfig: &channeldb.ChannelConfig{},
}, },
partialState: &channeldb.OpenChannel{ partialState: &channeldb.OpenChannel{
ChainHash: *chainHash, ChanType: chanType,
Db: wallet.Cfg.Database, ChainHash: *chainHash,
Capacity: capacity, IsPending: true,
IsInitiator: initiator, IsInitiator: initiator,
IsPending: true, Capacity: capacity,
ChanType: chanType, LocalCommitment: channeldb.ChannelCommitment{
LocalBalance: ourBalance, LocalBalance: ourBalance,
RemoteBalance: theirBalance, RemoteBalance: theirBalance,
FeePerKw: feePerKw, FeePerKw: feePerKw,
CommitFee: commitFee, CommitFee: commitFee,
},
RemoteCommitment: channeldb.ChannelCommitment{
LocalBalance: ourBalance,
RemoteBalance: theirBalance,
FeePerKw: feePerKw,
CommitFee: commitFee,
},
Db: wallet.Cfg.Database,
}, },
pushMSat: pushMSat, pushMSat: pushMSat,
reservationID: id, reservationID: id,

@ -805,8 +805,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.ToSatoshis() localBalance := pendingReservation.partialState.LocalCommitment.LocalBalance.ToSatoshis()
remoteBalance := pendingReservation.partialState.RemoteBalance.ToSatoshis() remoteBalance := pendingReservation.partialState.LocalCommitment.RemoteBalance.ToSatoshis()
ourCommitTx, theirCommitTx, err := CreateCommitmentTxns( ourCommitTx, theirCommitTx, err := CreateCommitmentTxns(
localBalance, remoteBalance, ourContribution.ChannelConfig, localBalance, remoteBalance, ourContribution.ChannelConfig,
theirContribution.ChannelConfig, theirContribution.ChannelConfig,
@ -857,7 +857,8 @@ func (l *LightningWallet) handleContributionMsg(req *addContributionMsg) {
// Record newly available information within the open channel state. // Record newly available information within the open channel state.
chanState.FundingOutpoint = *fundingOutpoint chanState.FundingOutpoint = *fundingOutpoint
chanState.CommitTx = *ourCommitTx chanState.LocalCommitment.CommitTx = ourCommitTx
chanState.RemoteCommitment.CommitTx = theirCommitTx
// Generate a signature for their version of the initial commitment // Generate a signature for their version of the initial commitment
// transaction. // transaction.
@ -999,7 +1000,7 @@ func (l *LightningWallet) handleFundingCounterPartySigs(msg *addCounterPartySigs
// At this point, we can also record and verify their signature for our // At this point, we can also record and verify their signature for our
// commitment transaction. // commitment transaction.
res.theirCommitmentSig = msg.theirCommitmentSig res.theirCommitmentSig = msg.theirCommitmentSig
commitTx := res.partialState.CommitTx commitTx := res.partialState.LocalCommitment.CommitTx
ourKey := res.ourContribution.MultiSigKey ourKey := res.ourContribution.MultiSigKey
theirKey := res.theirContribution.MultiSigKey theirKey := res.theirContribution.MultiSigKey
@ -1017,9 +1018,9 @@ func (l *LightningWallet) handleFundingCounterPartySigs(msg *addCounterPartySigs
// Next, create the spending scriptSig, and then verify that the script // Next, create the spending scriptSig, and then verify that the script
// is complete, allowing us to spend from the funding transaction. // is complete, allowing us to spend from the funding transaction.
channelValue := int64(res.partialState.Capacity) channelValue := int64(res.partialState.Capacity)
hashCache := txscript.NewTxSigHashes(&commitTx) hashCache := txscript.NewTxSigHashes(commitTx)
sigHash, err := txscript.CalcWitnessSigHash(witnessScript, hashCache, sigHash, err := txscript.CalcWitnessSigHash(witnessScript, hashCache,
txscript.SigHashAll, &commitTx, 0, channelValue) txscript.SigHashAll, commitTx, 0, channelValue)
if err != nil { if err != nil {
msg.err <- err msg.err <- err
msg.completeChan <- nil msg.completeChan <- nil
@ -1039,7 +1040,7 @@ func (l *LightningWallet) handleFundingCounterPartySigs(msg *addCounterPartySigs
msg.completeChan <- nil msg.completeChan <- nil
return return
} }
res.partialState.CommitSig = theirCommitSig res.partialState.LocalCommitment.CommitSig = theirCommitSig
// Funding complete, this entry can be removed from limbo. // Funding complete, this entry can be removed from limbo.
l.limboMtx.Lock() l.limboMtx.Lock()
@ -1119,8 +1120,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.ToSatoshis() localBalance := pendingReservation.partialState.LocalCommitment.LocalBalance.ToSatoshis()
remoteBalance := pendingReservation.partialState.RemoteBalance.ToSatoshis() remoteBalance := pendingReservation.partialState.LocalCommitment.RemoteBalance.ToSatoshis()
ourCommitTx, theirCommitTx, err := CreateCommitmentTxns( ourCommitTx, theirCommitTx, err := CreateCommitmentTxns(
localBalance, remoteBalance, localBalance, remoteBalance,
pendingReservation.ourContribution.ChannelConfig, pendingReservation.ourContribution.ChannelConfig,
@ -1148,7 +1149,8 @@ func (l *LightningWallet) handleSingleFunderSigs(req *addSingleFunderSigsMsg) {
// without further synchronization. // without further synchronization.
txsort.InPlaceSort(ourCommitTx) txsort.InPlaceSort(ourCommitTx)
txsort.InPlaceSort(theirCommitTx) txsort.InPlaceSort(theirCommitTx)
chanState.CommitTx = *ourCommitTx chanState.LocalCommitment.CommitTx = ourCommitTx
chanState.RemoteCommitment.CommitTx = theirCommitTx
channelValue := int64(pendingReservation.partialState.Capacity) channelValue := int64(pendingReservation.partialState.Capacity)
hashCache := txscript.NewTxSigHashes(ourCommitTx) hashCache := txscript.NewTxSigHashes(ourCommitTx)
@ -1182,7 +1184,7 @@ func (l *LightningWallet) handleSingleFunderSigs(req *addSingleFunderSigsMsg) {
req.completeChan <- nil req.completeChan <- nil
return return
} }
chanState.CommitSig = req.theirCommitmentSig chanState.LocalCommitment.CommitSig = req.theirCommitmentSig
// With their signature for our version of the commitment transactions // With their signature for our version of the commitment transactions
// verified, we can now generate a signature for their version, // verified, we can now generate a signature for their version,