lnwallet: update RevokeCurrentCommitment to use new DB API's

In this commit we update the RevokeCurrentCommitment method to properly
use the new database UpdateCommitment method along with properly
converting the in-memory commitment to its corresponding on-disk
format.
This commit is contained in:
Olaoluwa Osuntokun 2017-11-09 23:01:00 -08:00
parent 563c07ffa2
commit 4fa714afce
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -3331,6 +3331,7 @@ func (lc *LightningChannel) ReceiveNewCommitment(commitSig *btcec.Signature,
// Determine the last update on the local log that has been locked in. // Determine the last update on the local log that has been locked in.
localACKedIndex := lc.remoteCommitChain.tail().ourMessageIndex localACKedIndex := lc.remoteCommitChain.tail().ourMessageIndex
localHtlcIndex := lc.remoteCommitChain.tail().ourHtlcIndex
// Ensure that this new local update from the remote node respects all // Ensure that this new local update from the remote node respects all
// the constraints we specified during initial channel setup. If not, // the constraints we specified during initial channel setup. If not,
@ -3456,17 +3457,12 @@ func (lc *LightningChannel) FullySynced() bool {
oweCommitment := lastLocalCommit.height > lastRemoteCommit.height oweCommitment := lastLocalCommit.height > lastRemoteCommit.height
localUpdatesSynced := localUpdatesSynced := (lastLocalCommit.ourMessageIndex ==
lastLocalCommit.ourMessageIndex == lastRemoteCommit.ourMessageIndex lastRemoteCommit.ourMessageIndex)
remoteUpdatesSynced := remoteUpdatesSynced := (lastLocalCommit.theirMessageIndex ==
lastLocalCommit.theirMessageIndex == lastRemoteCommit.theirMessageIndex lastRemoteCommit.theirMessageIndex)
fmt.Println("remote, our:", lc.remoteCommitChain.tip().ourMessageIndex,
"local, our:", lc.localCommitChain.tip().ourMessageIndex)
fmt.Println("remote, their:", lc.remoteCommitChain.tip().theirMessageIndex,
"local, their:", lc.localCommitChain.tip().theirMessageIndex)
fmt.Println(!oweCommitment, localUpdatesSynced, remoteUpdatesSynced)
return !oweCommitment && localUpdatesSynced && remoteUpdatesSynced return !oweCommitment && localUpdatesSynced && remoteUpdatesSynced
} }
@ -3484,8 +3480,9 @@ func (lc *LightningChannel) RevokeCurrentCommitment() (*lnwire.RevokeAndAck, err
return nil, err return nil, err
} }
walletLog.Tracef("ChannelPoint(%v): revoking height=%v, now at height=%v", lc.channelState.FundingOutpoint, walletLog.Tracef("ChannelPoint(%v): revoking height=%v, now at height=%v",
lc.localCommitChain.tail().height, lc.currentHeight+1) lc.channelState.FundingOutpoint, lc.localCommitChain.tail().height,
lc.currentHeight+1)
// Advance our tail, as we've revoked our previous state. // Advance our tail, as we've revoked our previous state.
lc.localCommitChain.advanceTail() lc.localCommitChain.advanceTail()
@ -3493,20 +3490,17 @@ func (lc *LightningChannel) RevokeCurrentCommitment() (*lnwire.RevokeAndAck, err
// Additionally, generate a channel delta for this state transition for // Additionally, generate a channel delta for this state transition for
// persistent storage. // persistent storage.
tail := lc.localCommitChain.tail() chainTail := lc.localCommitChain.tail()
delta, err := tail.toChannelDelta(true) newCommitment := chainTail.toDiskCommit(true)
if err != nil { err = lc.channelState.UpdateCommitment(newCommitment)
return nil, err
}
err = lc.channelState.UpdateCommitment(tail.txn, tail.sig, delta)
if err != nil { if err != nil {
return nil, err return nil, err
} }
walletLog.Tracef("ChannelPoint(%v): state transition accepted: "+ walletLog.Tracef("ChannelPoint(%v): state transition accepted: "+
"our_balance=%v, their_balance=%v", "our_balance=%v, their_balance=%v",
lc.channelState.FundingOutpoint, tail.ourBalance, lc.channelState.FundingOutpoint, chainTail.ourBalance,
tail.theirBalance) chainTail.theirBalance)
revocationMsg.ChanID = lnwire.NewChanIDFromOutPoint( revocationMsg.ChanID = lnwire.NewChanIDFromOutPoint(
&lc.channelState.FundingOutpoint, &lc.channelState.FundingOutpoint,