lnwallet: expose a NextRevocationKey method in channel state machine

This commit adds a new method to the channel’s state machine:
NextRevocationKey. This method is being added in preparation for the
upcoming change to switch to the commitment transaction format outlined
in the spec. When this comes to pass, the ExtendRevocationWindow method
will be removed, as it will no longer be needed.

The NextRevocationKey method will be needed as to conform to the spec,
we’ll need to send the next revocation key within the `fundingLocked`
message.
This commit is contained in:
Olaoluwa Osuntokun 2017-02-24 16:09:21 -08:00
parent 9adc5f6484
commit f0c13c5a15
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -1749,15 +1749,15 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) ([]*P
}
}
// As we've just completed a new state transition, attempt to see if
// we can remove any entries from the update log which have been
// removed from the PoV of both commitment chains.
// As we've just completed a new state transition, attempt to see if we
// can remove any entries from the update log which have been removed
// from the PoV of both commitment chains.
compactLogs(lc.localUpdateLog, lc.remoteUpdateLog,
localChainTail, remoteChainTail)
// As a final step, now that we've received an ACK for our last
// batch of pending changes, we'll update our local ACK'd index to the
// now commitment index, and reset our pendingACKIndex.
// As a final step, now that we've received an ACK for our last batch
// of pending changes, we'll update our local ACK'd index to the now
// commitment index, and reset our pendingACKIndex.
lc.localUpdateLog.ackTransition()
return htlcsToForward, nil
@ -1792,6 +1792,27 @@ func (lc *LightningChannel) ExtendRevocationWindow() (*lnwire.RevokeAndAck, erro
return revMsg, nil
}
// NextRevocationKey returns the revocation key for the _next_ commitment
// height. The pubkey returned by this function is required by the remote party
// to extend our commitment chain with a new commitment.
//
// TODO(roasbeef): after commitment tx re-write add methdod to ingest
// revocation key
func (lc *LightningChannel) NextRevocationkey() (*btcec.PublicKey, error) {
lc.RLock()
defer lc.RUnlock()
nextHeight := lc.currentHeight + 1
revocation, err := lc.channelState.RevocationProducer.AtIndex(nextHeight)
if err != nil {
return nil, err
}
theirCommitKey := lc.channelState.TheirCommitKey
return DeriveRevocationPubkey(theirCommitKey,
revocation[:]), nil
}
// AddHTLC adds an HTLC to the state machine's local update log. This method
// should be called when preparing to send an outgoing HTLC.
//