lnwallet: re-write and rename LastCounters to ChanSyncMsg
The new version has additional comments, and is also a bit simpler that the prior version.
This commit is contained in:
1 file changed
+29
-13
+29
-13
@@ -3082,21 +3082,37 @@ func (lc *LightningChannel) ProcessChanSyncMsg(msg *lnwire.ChannelReestablish) (
|
|||||||
return updates, nil
|
return updates, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// LastCounters returns the historical length of the local commimemnt
|
// ChanSyncMsg returns the ChannelReestablish message that should be sent upon
|
||||||
// transaction chain and the historical number of the the revocked commiment
|
// reconnection with the remote peer that we're maintaining this channel with.
|
||||||
// transactions, whicha are needed in order to generate the channel
|
// The information contained within this message is necessary to re-sync our
|
||||||
// reestablish message.
|
// commitment chains in the case of a last or only partially processed message.
|
||||||
func (lc *LightningChannel) LastCounters() (uint64, uint64) {
|
// When the remote party receiver this message one of three things may happen:
|
||||||
// As far we store on last commitment transaction we should rely on the
|
//
|
||||||
// height of the commitment transaction in order to calculate the length.
|
// 1. We're fully synced and no messages need to be sent.
|
||||||
numberLocalCommitments := lc.localCommitChain.tip().height + 1
|
// 2. We didn't get the lat CommitSig message they sent, to they'll re-send
|
||||||
|
// it.
|
||||||
|
// 3. We didn't get the last RevokeAndAck message they sent, so they'll
|
||||||
|
// re-send it.
|
||||||
|
func (lc *LightningChannel) ChanSyncMsg() *lnwire.ChannelReestablish {
|
||||||
|
// The remote commitment height that we we'll send in the
|
||||||
|
// ChannelReestablish message is our current commitment height plus
|
||||||
|
// one. If the receiver thinks that our commitment height is actually
|
||||||
|
// *equal* to this value, then they'll re-send the last commitment that
|
||||||
|
// they sent but we never fully processed.
|
||||||
|
nextLocalCommitHeight := lc.localCommitChain.tip().height + 1
|
||||||
|
|
||||||
// Number of the revocations might be calculated as the height of the
|
// The second value we'll send is the height of the remote commitment
|
||||||
// commitment transactions which will be revoked next minus one. And plus
|
// from our PoV. If the receiver thinks that their height is actually
|
||||||
// one because height starts from zero.
|
// *one plus* this value, then they'll re-send their last revocation.
|
||||||
numberRemoteRevocations := lc.remoteCommitChain.tail().height - 1 + 1
|
remoteChainTipHeight := lc.remoteCommitChain.tail().height
|
||||||
|
|
||||||
return numberLocalCommitments, numberRemoteRevocations
|
return &lnwire.ChannelReestablish{
|
||||||
|
ChanID: lnwire.NewChanIDFromOutPoint(
|
||||||
|
&lc.channelState.FundingOutpoint,
|
||||||
|
),
|
||||||
|
NextLocalCommitHeight: nextLocalCommitHeight,
|
||||||
|
RemoteCommitTailHeight: remoteChainTipHeight,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// validateCommitmentSanity is used to validate that on current state the commitment
|
// validateCommitmentSanity is used to validate that on current state the commitment
|
||||||
|
|||||||
Reference in new issue
Block a user