lnwallet: pack update logs into Dual
This commit, like the last one packs the update logs into a symmetric Dual structure. This will allow us to index into them more concisely in higher order logic.
This commit is contained in:
2 files changed
+235
-193
No files matched your search
+105
-90
@@ -874,8 +874,7 @@ type LightningChannel struct {
|
|||||||
// updates to this channel. The log is walked backwards as HTLC updates
|
// updates to this channel. The log is walked backwards as HTLC updates
|
||||||
// are applied in order to re-construct a commitment transaction from a
|
// are applied in order to re-construct a commitment transaction from a
|
||||||
// commitment. The log is compacted once a revocation is received.
|
// commitment. The log is compacted once a revocation is received.
|
||||||
localUpdateLog *updateLog
|
updateLogs lntypes.Dual[*updateLog]
|
||||||
remoteUpdateLog *updateLog
|
|
||||||
|
|
||||||
// log is a channel-specific logging instance.
|
// log is a channel-specific logging instance.
|
||||||
log btclog.Logger
|
log btclog.Logger
|
||||||
@@ -980,6 +979,10 @@ func NewLightningChannel(signer input.Signer,
|
|||||||
remoteUpdateLog := newUpdateLog(
|
remoteUpdateLog := newUpdateLog(
|
||||||
localCommit.RemoteLogIndex, localCommit.RemoteHtlcIndex,
|
localCommit.RemoteLogIndex, localCommit.RemoteHtlcIndex,
|
||||||
)
|
)
|
||||||
|
updateLogs := lntypes.Dual[*updateLog]{
|
||||||
|
Local: localUpdateLog,
|
||||||
|
Remote: remoteUpdateLog,
|
||||||
|
}
|
||||||
|
|
||||||
logPrefix := fmt.Sprintf("ChannelPoint(%v):", state.FundingOutpoint)
|
logPrefix := fmt.Sprintf("ChannelPoint(%v):", state.FundingOutpoint)
|
||||||
|
|
||||||
@@ -1005,8 +1008,7 @@ func NewLightningChannel(signer input.Signer,
|
|||||||
commitBuilder: NewCommitmentBuilder(
|
commitBuilder: NewCommitmentBuilder(
|
||||||
state, opts.leafStore,
|
state, opts.leafStore,
|
||||||
),
|
),
|
||||||
localUpdateLog: localUpdateLog,
|
updateLogs: updateLogs,
|
||||||
remoteUpdateLog: remoteUpdateLog,
|
|
||||||
Capacity: state.Capacity,
|
Capacity: state.Capacity,
|
||||||
taprootNonceProducer: taprootNonceProducer,
|
taprootNonceProducer: taprootNonceProducer,
|
||||||
log: build.NewPrefixLog(logPrefix, walletLog),
|
log: build.NewPrefixLog(logPrefix, walletLog),
|
||||||
@@ -1662,7 +1664,7 @@ func (lc *LightningChannel) restoreStateLogs(
|
|||||||
htlc.addCommitHeightRemote = incomingRemoteAddHeights[htlc.HtlcIndex]
|
htlc.addCommitHeightRemote = incomingRemoteAddHeights[htlc.HtlcIndex]
|
||||||
|
|
||||||
// Restore the htlc back to the remote log.
|
// Restore the htlc back to the remote log.
|
||||||
lc.remoteUpdateLog.restoreHtlc(&htlc)
|
lc.updateLogs.Remote.restoreHtlc(&htlc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Similarly, we'll do the same for the outgoing HTLCs within the
|
// Similarly, we'll do the same for the outgoing HTLCs within the
|
||||||
@@ -1677,7 +1679,7 @@ func (lc *LightningChannel) restoreStateLogs(
|
|||||||
htlc.addCommitHeightLocal = outgoingLocalAddHeights[htlc.HtlcIndex]
|
htlc.addCommitHeightLocal = outgoingLocalAddHeights[htlc.HtlcIndex]
|
||||||
|
|
||||||
// Restore the htlc back to the local log.
|
// Restore the htlc back to the local log.
|
||||||
lc.localUpdateLog.restoreHtlc(&htlc)
|
lc.updateLogs.Local.restoreHtlc(&htlc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have a dangling (un-acked) commit for the remote party, then we
|
// If we have a dangling (un-acked) commit for the remote party, then we
|
||||||
@@ -1722,7 +1724,7 @@ func (lc *LightningChannel) restorePendingRemoteUpdates(
|
|||||||
logUpdate := logUpdate
|
logUpdate := logUpdate
|
||||||
|
|
||||||
payDesc, err := lc.remoteLogUpdateToPayDesc(
|
payDesc, err := lc.remoteLogUpdateToPayDesc(
|
||||||
&logUpdate, lc.localUpdateLog, localCommitmentHeight,
|
&logUpdate, lc.updateLogs.Local, localCommitmentHeight,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -1732,7 +1734,7 @@ func (lc *LightningChannel) restorePendingRemoteUpdates(
|
|||||||
|
|
||||||
// Sanity check that we are not restoring a remote log update
|
// Sanity check that we are not restoring a remote log update
|
||||||
// that we haven't received a sig for.
|
// that we haven't received a sig for.
|
||||||
if logIdx >= lc.remoteUpdateLog.logIndex {
|
if logIdx >= lc.updateLogs.Remote.logIndex {
|
||||||
return fmt.Errorf("attempted to restore an "+
|
return fmt.Errorf("attempted to restore an "+
|
||||||
"unsigned remote update: log_index=%v",
|
"unsigned remote update: log_index=%v",
|
||||||
logIdx)
|
logIdx)
|
||||||
@@ -1773,15 +1775,17 @@ func (lc *LightningChannel) restorePendingRemoteUpdates(
|
|||||||
payDesc.removeCommitHeightRemote = height
|
payDesc.removeCommitHeightRemote = height
|
||||||
}
|
}
|
||||||
|
|
||||||
lc.remoteUpdateLog.restoreUpdate(payDesc)
|
lc.updateLogs.Remote.restoreUpdate(payDesc)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if heightSet {
|
if heightSet {
|
||||||
payDesc.removeCommitHeightRemote = height
|
payDesc.removeCommitHeightRemote = height
|
||||||
}
|
}
|
||||||
|
|
||||||
lc.remoteUpdateLog.restoreUpdate(payDesc)
|
lc.updateLogs.Remote.restoreUpdate(payDesc)
|
||||||
lc.localUpdateLog.markHtlcModified(payDesc.ParentIndex)
|
lc.updateLogs.Local.markHtlcModified(
|
||||||
|
payDesc.ParentIndex,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1800,20 +1804,23 @@ func (lc *LightningChannel) restorePeerLocalUpdates(updates []channeldb.LogUpdat
|
|||||||
logUpdate := logUpdate
|
logUpdate := logUpdate
|
||||||
|
|
||||||
payDesc, err := lc.localLogUpdateToPayDesc(
|
payDesc, err := lc.localLogUpdateToPayDesc(
|
||||||
&logUpdate, lc.remoteUpdateLog, remoteCommitmentHeight,
|
&logUpdate, lc.updateLogs.Remote,
|
||||||
|
remoteCommitmentHeight,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
lc.localUpdateLog.restoreUpdate(payDesc)
|
lc.updateLogs.Local.restoreUpdate(payDesc)
|
||||||
|
|
||||||
// Since Add updates are not stored and FeeUpdates don't have a
|
// Since Add updates are not stored and FeeUpdates don't have a
|
||||||
// corresponding entry in the remote update log, we only need to
|
// corresponding entry in the remote update log, we only need to
|
||||||
// mark the htlc as modified if the update was Settle, Fail, or
|
// mark the htlc as modified if the update was Settle, Fail, or
|
||||||
// MalformedFail.
|
// MalformedFail.
|
||||||
if payDesc.EntryType != FeeUpdate {
|
if payDesc.EntryType != FeeUpdate {
|
||||||
lc.remoteUpdateLog.markHtlcModified(payDesc.ParentIndex)
|
lc.updateLogs.Remote.markHtlcModified(
|
||||||
|
payDesc.ParentIndex,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1848,7 +1855,7 @@ func (lc *LightningChannel) restorePendingLocalUpdates(
|
|||||||
logUpdate := logUpdate
|
logUpdate := logUpdate
|
||||||
|
|
||||||
payDesc, err := lc.logUpdateToPayDesc(
|
payDesc, err := lc.logUpdateToPayDesc(
|
||||||
&logUpdate, lc.remoteUpdateLog, pendingHeight,
|
&logUpdate, lc.updateLogs.Remote, pendingHeight,
|
||||||
chainfee.SatPerKWeight(pendingCommit.FeePerKw),
|
chainfee.SatPerKWeight(pendingCommit.FeePerKw),
|
||||||
pendingRemoteKeys,
|
pendingRemoteKeys,
|
||||||
lc.channelState.RemoteChanCfg.DustLimit,
|
lc.channelState.RemoteChanCfg.DustLimit,
|
||||||
@@ -1862,9 +1869,9 @@ func (lc *LightningChannel) restorePendingLocalUpdates(
|
|||||||
// updates, so they will be unset. To account for this we set
|
// updates, so they will be unset. To account for this we set
|
||||||
// them to to current update log index.
|
// them to to current update log index.
|
||||||
if payDesc.EntryType == FeeUpdate && payDesc.LogIndex == 0 &&
|
if payDesc.EntryType == FeeUpdate && payDesc.LogIndex == 0 &&
|
||||||
lc.localUpdateLog.logIndex > 0 {
|
lc.updateLogs.Local.logIndex > 0 {
|
||||||
|
|
||||||
payDesc.LogIndex = lc.localUpdateLog.logIndex
|
payDesc.LogIndex = lc.updateLogs.Local.logIndex
|
||||||
lc.log.Debugf("Found FeeUpdate on "+
|
lc.log.Debugf("Found FeeUpdate on "+
|
||||||
"pendingRemoteCommitDiff without logIndex, "+
|
"pendingRemoteCommitDiff without logIndex, "+
|
||||||
"using %v", payDesc.LogIndex)
|
"using %v", payDesc.LogIndex)
|
||||||
@@ -1872,10 +1879,10 @@ func (lc *LightningChannel) restorePendingLocalUpdates(
|
|||||||
|
|
||||||
// At this point the restored update's logIndex must be equal
|
// At this point the restored update's logIndex must be equal
|
||||||
// to the update log, otherwise something is horribly wrong.
|
// to the update log, otherwise something is horribly wrong.
|
||||||
if payDesc.LogIndex != lc.localUpdateLog.logIndex {
|
if payDesc.LogIndex != lc.updateLogs.Local.logIndex {
|
||||||
panic(fmt.Sprintf("log index mismatch: "+
|
panic(fmt.Sprintf("log index mismatch: "+
|
||||||
"%v vs %v", payDesc.LogIndex,
|
"%v vs %v", payDesc.LogIndex,
|
||||||
lc.localUpdateLog.logIndex))
|
lc.updateLogs.Local.logIndex))
|
||||||
}
|
}
|
||||||
|
|
||||||
switch payDesc.EntryType {
|
switch payDesc.EntryType {
|
||||||
@@ -1885,21 +1892,25 @@ func (lc *LightningChannel) restorePendingLocalUpdates(
|
|||||||
// panic to catch this.
|
// panic to catch this.
|
||||||
// TODO(halseth): remove when cause of htlc entry bug
|
// TODO(halseth): remove when cause of htlc entry bug
|
||||||
// is found.
|
// is found.
|
||||||
if payDesc.HtlcIndex != lc.localUpdateLog.htlcCounter {
|
if payDesc.HtlcIndex !=
|
||||||
|
lc.updateLogs.Local.htlcCounter {
|
||||||
|
|
||||||
panic(fmt.Sprintf("htlc index mismatch: "+
|
panic(fmt.Sprintf("htlc index mismatch: "+
|
||||||
"%v vs %v", payDesc.HtlcIndex,
|
"%v vs %v", payDesc.HtlcIndex,
|
||||||
lc.localUpdateLog.htlcCounter))
|
lc.updateLogs.Local.htlcCounter))
|
||||||
}
|
}
|
||||||
|
|
||||||
lc.localUpdateLog.appendHtlc(payDesc)
|
lc.updateLogs.Local.appendHtlc(payDesc)
|
||||||
|
|
||||||
case FeeUpdate:
|
case FeeUpdate:
|
||||||
lc.localUpdateLog.appendUpdate(payDesc)
|
lc.updateLogs.Local.appendUpdate(payDesc)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
lc.localUpdateLog.appendUpdate(payDesc)
|
lc.updateLogs.Local.appendUpdate(payDesc)
|
||||||
|
|
||||||
lc.remoteUpdateLog.markHtlcModified(payDesc.ParentIndex)
|
lc.updateLogs.Remote.markHtlcModified(
|
||||||
|
payDesc.ParentIndex,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2617,7 +2628,7 @@ func (lc *LightningChannel) fetchHTLCView(theirLogIndex,
|
|||||||
ourLogIndex uint64) *HtlcView {
|
ourLogIndex uint64) *HtlcView {
|
||||||
|
|
||||||
var ourHTLCs []*PaymentDescriptor
|
var ourHTLCs []*PaymentDescriptor
|
||||||
for e := lc.localUpdateLog.Front(); e != nil; e = e.Next() {
|
for e := lc.updateLogs.Local.Front(); e != nil; e = e.Next() {
|
||||||
htlc := e.Value
|
htlc := e.Value
|
||||||
|
|
||||||
// This HTLC is active from this point-of-view iff the log
|
// This HTLC is active from this point-of-view iff the log
|
||||||
@@ -2629,7 +2640,7 @@ func (lc *LightningChannel) fetchHTLCView(theirLogIndex,
|
|||||||
}
|
}
|
||||||
|
|
||||||
var theirHTLCs []*PaymentDescriptor
|
var theirHTLCs []*PaymentDescriptor
|
||||||
for e := lc.remoteUpdateLog.Front(); e != nil; e = e.Next() {
|
for e := lc.updateLogs.Remote.Front(); e != nil; e = e.Next() {
|
||||||
htlc := e.Value
|
htlc := e.Value
|
||||||
|
|
||||||
// If this is an incoming HTLC, then it is only active from
|
// If this is an incoming HTLC, then it is only active from
|
||||||
@@ -2953,10 +2964,10 @@ func (lc *LightningChannel) fetchParent(entry *PaymentDescriptor,
|
|||||||
)
|
)
|
||||||
|
|
||||||
if whoseUpdateLog.IsRemote() {
|
if whoseUpdateLog.IsRemote() {
|
||||||
updateLog = lc.remoteUpdateLog
|
updateLog = lc.updateLogs.Remote
|
||||||
logName = "remote"
|
logName = "remote"
|
||||||
} else {
|
} else {
|
||||||
updateLog = lc.localUpdateLog
|
updateLog = lc.updateLogs.Local
|
||||||
logName = "local"
|
logName = "local"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3354,7 +3365,7 @@ func (lc *LightningChannel) createCommitDiff(newCommit *commitment,
|
|||||||
// were only just committed within this pending state. This will be the
|
// were only just committed within this pending state. This will be the
|
||||||
// set of items we need to retransmit if we reconnect and find that
|
// set of items we need to retransmit if we reconnect and find that
|
||||||
// they didn't process this new state fully.
|
// they didn't process this new state fully.
|
||||||
for e := lc.localUpdateLog.Front(); e != nil; e = e.Next() {
|
for e := lc.updateLogs.Local.Front(); e != nil; e = e.Next() {
|
||||||
pd := e.Value
|
pd := e.Value
|
||||||
|
|
||||||
// If this entry wasn't committed at the exact height of this
|
// If this entry wasn't committed at the exact height of this
|
||||||
@@ -3492,7 +3503,7 @@ func (lc *LightningChannel) getUnsignedAckedUpdates() []channeldb.LogUpdate {
|
|||||||
// restore if we reconnect in order to produce the signature that the
|
// restore if we reconnect in order to produce the signature that the
|
||||||
// remote party expects.
|
// remote party expects.
|
||||||
var logUpdates []channeldb.LogUpdate
|
var logUpdates []channeldb.LogUpdate
|
||||||
for e := lc.remoteUpdateLog.Front(); e != nil; e = e.Next() {
|
for e := lc.updateLogs.Remote.Front(); e != nil; e = e.Next() {
|
||||||
pd := e.Value
|
pd := e.Value
|
||||||
|
|
||||||
// Skip all remote updates that we have already included in our
|
// Skip all remote updates that we have already included in our
|
||||||
@@ -3982,7 +3993,7 @@ func (lc *LightningChannel) SignNextCommitment() (*NewCommitState, error) {
|
|||||||
// point all updates will have to get locked-in so we enforce the
|
// point all updates will have to get locked-in so we enforce the
|
||||||
// minimum requirement.
|
// minimum requirement.
|
||||||
err := lc.validateCommitmentSanity(
|
err := lc.validateCommitmentSanity(
|
||||||
remoteACKedIndex, lc.localUpdateLog.logIndex, lntypes.Remote,
|
remoteACKedIndex, lc.updateLogs.Local.logIndex, lntypes.Remote,
|
||||||
NoBuffer, nil, nil,
|
NoBuffer, nil, nil,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -4005,8 +4016,8 @@ func (lc *LightningChannel) SignNextCommitment() (*NewCommitState, error) {
|
|||||||
// _all_ of our changes (pending or committed) but only the remote
|
// _all_ of our changes (pending or committed) but only the remote
|
||||||
// node's changes up to the last change we've ACK'd.
|
// node's changes up to the last change we've ACK'd.
|
||||||
newCommitView, err := lc.fetchCommitmentView(
|
newCommitView, err := lc.fetchCommitmentView(
|
||||||
lntypes.Remote, lc.localUpdateLog.logIndex,
|
lntypes.Remote, lc.updateLogs.Local.logIndex,
|
||||||
lc.localUpdateLog.htlcCounter, remoteACKedIndex,
|
lc.updateLogs.Local.htlcCounter, remoteACKedIndex,
|
||||||
remoteHtlcIndex, keyRing,
|
remoteHtlcIndex, keyRing,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -4016,7 +4027,7 @@ func (lc *LightningChannel) SignNextCommitment() (*NewCommitState, error) {
|
|||||||
lc.log.Tracef("extending remote chain to height %v, "+
|
lc.log.Tracef("extending remote chain to height %v, "+
|
||||||
"local_log=%v, remote_log=%v",
|
"local_log=%v, remote_log=%v",
|
||||||
newCommitView.height,
|
newCommitView.height,
|
||||||
lc.localUpdateLog.logIndex, remoteACKedIndex)
|
lc.updateLogs.Local.logIndex, remoteACKedIndex)
|
||||||
|
|
||||||
lc.log.Tracef("remote chain: our_balance=%v, "+
|
lc.log.Tracef("remote chain: our_balance=%v, "+
|
||||||
"their_balance=%v, commit_tx: %v",
|
"their_balance=%v, commit_tx: %v",
|
||||||
@@ -4983,7 +4994,7 @@ func (lc *LightningChannel) ReceiveNewCommitment(commitSigs *CommitSigs) error {
|
|||||||
// the UpdateAddHTLC msg from our peer prior to receiving the
|
// the UpdateAddHTLC msg from our peer prior to receiving the
|
||||||
// commit-sig).
|
// commit-sig).
|
||||||
err := lc.validateCommitmentSanity(
|
err := lc.validateCommitmentSanity(
|
||||||
lc.remoteUpdateLog.logIndex, localACKedIndex, lntypes.Local,
|
lc.updateLogs.Remote.logIndex, localACKedIndex, lntypes.Local,
|
||||||
NoBuffer, nil, nil,
|
NoBuffer, nil, nil,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -5011,7 +5022,7 @@ func (lc *LightningChannel) ReceiveNewCommitment(commitSigs *CommitSigs) error {
|
|||||||
// up to the last change the remote node has ACK'd.
|
// up to the last change the remote node has ACK'd.
|
||||||
localCommitmentView, err := lc.fetchCommitmentView(
|
localCommitmentView, err := lc.fetchCommitmentView(
|
||||||
lntypes.Local, localACKedIndex, localHtlcIndex,
|
lntypes.Local, localACKedIndex, localHtlcIndex,
|
||||||
lc.remoteUpdateLog.logIndex, lc.remoteUpdateLog.htlcCounter,
|
lc.updateLogs.Remote.logIndex, lc.updateLogs.Remote.htlcCounter,
|
||||||
keyRing,
|
keyRing,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -5021,7 +5032,7 @@ func (lc *LightningChannel) ReceiveNewCommitment(commitSigs *CommitSigs) error {
|
|||||||
lc.log.Tracef("extending local chain to height %v, "+
|
lc.log.Tracef("extending local chain to height %v, "+
|
||||||
"local_log=%v, remote_log=%v",
|
"local_log=%v, remote_log=%v",
|
||||||
localCommitmentView.height,
|
localCommitmentView.height,
|
||||||
localACKedIndex, lc.remoteUpdateLog.logIndex)
|
localACKedIndex, lc.updateLogs.Remote.logIndex)
|
||||||
|
|
||||||
lc.log.Tracef("local chain: our_balance=%v, "+
|
lc.log.Tracef("local chain: our_balance=%v, "+
|
||||||
"their_balance=%v, commit_tx: %v",
|
"their_balance=%v, commit_tx: %v",
|
||||||
@@ -5175,7 +5186,11 @@ func (lc *LightningChannel) ReceiveNewCommitment(commitSigs *CommitSigs) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var txBytes bytes.Buffer
|
var txBytes bytes.Buffer
|
||||||
localCommitTx.Serialize(&txBytes)
|
err = localCommitTx.Serialize(&txBytes)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return &InvalidHtlcSigError{
|
return &InvalidHtlcSigError{
|
||||||
commitHeight: nextHeight,
|
commitHeight: nextHeight,
|
||||||
htlcSig: sig.ToSignatureBytes(),
|
htlcSig: sig.ToSignatureBytes(),
|
||||||
@@ -5297,7 +5312,7 @@ func (lc *LightningChannel) oweCommitment(issuer lntypes.ChannelParty) bool {
|
|||||||
|
|
||||||
// There are local updates pending if our local update log is
|
// There are local updates pending if our local update log is
|
||||||
// not in sync with our remote commitment tx.
|
// not in sync with our remote commitment tx.
|
||||||
localUpdatesPending = lc.localUpdateLog.logIndex !=
|
localUpdatesPending = lc.updateLogs.Local.logIndex !=
|
||||||
lastRemoteCommit.ourMessageIndex
|
lastRemoteCommit.ourMessageIndex
|
||||||
|
|
||||||
// There are remote updates pending if their remote commitment
|
// There are remote updates pending if their remote commitment
|
||||||
@@ -5312,7 +5327,7 @@ func (lc *LightningChannel) oweCommitment(issuer lntypes.ChannelParty) bool {
|
|||||||
// perspective of the remote party) if the remote party has
|
// perspective of the remote party) if the remote party has
|
||||||
// updates to their remote tx pending for which they haven't
|
// updates to their remote tx pending for which they haven't
|
||||||
// signed yet.
|
// signed yet.
|
||||||
localUpdatesPending = lc.remoteUpdateLog.logIndex !=
|
localUpdatesPending = lc.updateLogs.Remote.logIndex !=
|
||||||
lastLocalCommit.theirMessageIndex
|
lastLocalCommit.theirMessageIndex
|
||||||
|
|
||||||
// There are remote updates pending (remote updates from the
|
// There are remote updates pending (remote updates from the
|
||||||
@@ -5341,7 +5356,7 @@ func (lc *LightningChannel) PendingLocalUpdateCount() uint64 {
|
|||||||
|
|
||||||
lastRemoteCommit := lc.commitChains.Remote.tip()
|
lastRemoteCommit := lc.commitChains.Remote.tip()
|
||||||
|
|
||||||
return lc.localUpdateLog.logIndex - lastRemoteCommit.ourMessageIndex
|
return lc.updateLogs.Local.logIndex - lastRemoteCommit.ourMessageIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
// RevokeCurrentCommitment revokes the next lowest unrevoked commitment
|
// RevokeCurrentCommitment revokes the next lowest unrevoked commitment
|
||||||
@@ -5477,7 +5492,7 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var addIndex, settleFailIndex uint16
|
var addIndex, settleFailIndex uint16
|
||||||
for e := lc.remoteUpdateLog.Front(); e != nil; e = e.Next() {
|
for e := lc.updateLogs.Remote.Front(); e != nil; e = e.Next() {
|
||||||
pd := e.Value
|
pd := e.Value
|
||||||
|
|
||||||
// Fee updates are local to this particular channel, and should
|
// Fee updates are local to this particular channel, and should
|
||||||
@@ -5668,7 +5683,7 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
|
|||||||
// can remove any entries from the update log which have been removed
|
// can remove any entries from the update log which have been removed
|
||||||
// from the PoV of both commitment chains.
|
// from the PoV of both commitment chains.
|
||||||
compactLogs(
|
compactLogs(
|
||||||
lc.localUpdateLog, lc.remoteUpdateLog, localChainTail,
|
lc.updateLogs.Local, lc.updateLogs.Remote, localChainTail,
|
||||||
remoteChainTail,
|
remoteChainTail,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -5774,7 +5789,7 @@ func (lc *LightningChannel) addHTLC(htlc *lnwire.UpdateAddHTLC,
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
lc.localUpdateLog.appendHtlc(pd)
|
lc.updateLogs.Local.appendHtlc(pd)
|
||||||
|
|
||||||
return pd.HtlcIndex, nil
|
return pd.HtlcIndex, nil
|
||||||
}
|
}
|
||||||
@@ -5807,7 +5822,7 @@ func (lc *LightningChannel) GetDustSum(whoseCommit lntypes.ChannelParty,
|
|||||||
feeRate = dryRunFee.UnwrapOr(feeRate)
|
feeRate = dryRunFee.UnwrapOr(feeRate)
|
||||||
|
|
||||||
// Grab all of our HTLCs and evaluate against the dust limit.
|
// Grab all of our HTLCs and evaluate against the dust limit.
|
||||||
for e := lc.localUpdateLog.Front(); e != nil; e = e.Next() {
|
for e := lc.updateLogs.Local.Front(); e != nil; e = e.Next() {
|
||||||
pd := e.Value
|
pd := e.Value
|
||||||
if pd.EntryType != Add {
|
if pd.EntryType != Add {
|
||||||
continue
|
continue
|
||||||
@@ -5826,7 +5841,7 @@ func (lc *LightningChannel) GetDustSum(whoseCommit lntypes.ChannelParty,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Grab all of their HTLCs and evaluate against the dust limit.
|
// Grab all of their HTLCs and evaluate against the dust limit.
|
||||||
for e := lc.remoteUpdateLog.Front(); e != nil; e = e.Next() {
|
for e := lc.updateLogs.Remote.Front(); e != nil; e = e.Next() {
|
||||||
pd := e.Value
|
pd := e.Value
|
||||||
if pd.EntryType != Add {
|
if pd.EntryType != Add {
|
||||||
continue
|
continue
|
||||||
@@ -5906,8 +5921,8 @@ func (lc *LightningChannel) htlcAddDescriptor(htlc *lnwire.UpdateAddHTLC,
|
|||||||
RHash: PaymentHash(htlc.PaymentHash),
|
RHash: PaymentHash(htlc.PaymentHash),
|
||||||
Timeout: htlc.Expiry,
|
Timeout: htlc.Expiry,
|
||||||
Amount: htlc.Amount,
|
Amount: htlc.Amount,
|
||||||
LogIndex: lc.localUpdateLog.logIndex,
|
LogIndex: lc.updateLogs.Local.logIndex,
|
||||||
HtlcIndex: lc.localUpdateLog.htlcCounter,
|
HtlcIndex: lc.updateLogs.Local.htlcCounter,
|
||||||
OnionBlob: htlc.OnionBlob[:],
|
OnionBlob: htlc.OnionBlob[:],
|
||||||
OpenCircuitKey: openKey,
|
OpenCircuitKey: openKey,
|
||||||
BlindingPoint: htlc.BlindingPoint,
|
BlindingPoint: htlc.BlindingPoint,
|
||||||
@@ -5928,7 +5943,7 @@ func (lc *LightningChannel) validateAddHtlc(pd *PaymentDescriptor,
|
|||||||
// First we'll check whether this HTLC can be added to the remote
|
// First we'll check whether this HTLC can be added to the remote
|
||||||
// commitment transaction without violation any of the constraints.
|
// commitment transaction without violation any of the constraints.
|
||||||
err := lc.validateCommitmentSanity(
|
err := lc.validateCommitmentSanity(
|
||||||
remoteACKedIndex, lc.localUpdateLog.logIndex, lntypes.Remote,
|
remoteACKedIndex, lc.updateLogs.Local.logIndex, lntypes.Remote,
|
||||||
buffer, pd, nil,
|
buffer, pd, nil,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -5941,7 +5956,7 @@ func (lc *LightningChannel) validateAddHtlc(pd *PaymentDescriptor,
|
|||||||
// concurrently, but if we fail this check there is for sure not
|
// concurrently, but if we fail this check there is for sure not
|
||||||
// possible for us to add the HTLC.
|
// possible for us to add the HTLC.
|
||||||
err = lc.validateCommitmentSanity(
|
err = lc.validateCommitmentSanity(
|
||||||
lc.remoteUpdateLog.logIndex, lc.localUpdateLog.logIndex,
|
lc.updateLogs.Remote.logIndex, lc.updateLogs.Local.logIndex,
|
||||||
lntypes.Local, buffer, pd, nil,
|
lntypes.Local, buffer, pd, nil,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -5960,9 +5975,9 @@ func (lc *LightningChannel) ReceiveHTLC(htlc *lnwire.UpdateAddHTLC) (uint64,
|
|||||||
lc.Lock()
|
lc.Lock()
|
||||||
defer lc.Unlock()
|
defer lc.Unlock()
|
||||||
|
|
||||||
if htlc.ID != lc.remoteUpdateLog.htlcCounter {
|
if htlc.ID != lc.updateLogs.Remote.htlcCounter {
|
||||||
return 0, fmt.Errorf("ID %d on HTLC add does not match expected next "+
|
return 0, fmt.Errorf("ID %d on HTLC add does not match expected next "+
|
||||||
"ID %d", htlc.ID, lc.remoteUpdateLog.htlcCounter)
|
"ID %d", htlc.ID, lc.updateLogs.Remote.htlcCounter)
|
||||||
}
|
}
|
||||||
|
|
||||||
pd := &PaymentDescriptor{
|
pd := &PaymentDescriptor{
|
||||||
@@ -5970,8 +5985,8 @@ func (lc *LightningChannel) ReceiveHTLC(htlc *lnwire.UpdateAddHTLC) (uint64,
|
|||||||
RHash: PaymentHash(htlc.PaymentHash),
|
RHash: PaymentHash(htlc.PaymentHash),
|
||||||
Timeout: htlc.Expiry,
|
Timeout: htlc.Expiry,
|
||||||
Amount: htlc.Amount,
|
Amount: htlc.Amount,
|
||||||
LogIndex: lc.remoteUpdateLog.logIndex,
|
LogIndex: lc.updateLogs.Remote.logIndex,
|
||||||
HtlcIndex: lc.remoteUpdateLog.htlcCounter,
|
HtlcIndex: lc.updateLogs.Remote.htlcCounter,
|
||||||
OnionBlob: htlc.OnionBlob[:],
|
OnionBlob: htlc.OnionBlob[:],
|
||||||
BlindingPoint: htlc.BlindingPoint,
|
BlindingPoint: htlc.BlindingPoint,
|
||||||
// TODO(guggero): Add custom records from HTLC here once we have
|
// TODO(guggero): Add custom records from HTLC here once we have
|
||||||
@@ -5988,14 +6003,14 @@ func (lc *LightningChannel) ReceiveHTLC(htlc *lnwire.UpdateAddHTLC) (uint64,
|
|||||||
// we use it here. The current lightning protocol does not allow to
|
// we use it here. The current lightning protocol does not allow to
|
||||||
// reject ADDs already sent by the peer.
|
// reject ADDs already sent by the peer.
|
||||||
err := lc.validateCommitmentSanity(
|
err := lc.validateCommitmentSanity(
|
||||||
lc.remoteUpdateLog.logIndex, localACKedIndex, lntypes.Local,
|
lc.updateLogs.Remote.logIndex, localACKedIndex, lntypes.Local,
|
||||||
NoBuffer, nil, pd,
|
NoBuffer, nil, pd,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
lc.remoteUpdateLog.appendHtlc(pd)
|
lc.updateLogs.Remote.appendHtlc(pd)
|
||||||
|
|
||||||
return pd.HtlcIndex, nil
|
return pd.HtlcIndex, nil
|
||||||
}
|
}
|
||||||
@@ -6031,7 +6046,7 @@ func (lc *LightningChannel) SettleHTLC(preimage [32]byte,
|
|||||||
lc.Lock()
|
lc.Lock()
|
||||||
defer lc.Unlock()
|
defer lc.Unlock()
|
||||||
|
|
||||||
htlc := lc.remoteUpdateLog.lookupHtlc(htlcIndex)
|
htlc := lc.updateLogs.Remote.lookupHtlc(htlcIndex)
|
||||||
if htlc == nil {
|
if htlc == nil {
|
||||||
return ErrUnknownHtlcIndex{lc.ShortChanID(), htlcIndex}
|
return ErrUnknownHtlcIndex{lc.ShortChanID(), htlcIndex}
|
||||||
}
|
}
|
||||||
@@ -6039,7 +6054,7 @@ func (lc *LightningChannel) SettleHTLC(preimage [32]byte,
|
|||||||
// Now that we know the HTLC exists, before checking to see if the
|
// Now that we know the HTLC exists, before checking to see if the
|
||||||
// preimage matches, we'll ensure that we haven't already attempted to
|
// preimage matches, we'll ensure that we haven't already attempted to
|
||||||
// modify the HTLC.
|
// modify the HTLC.
|
||||||
if lc.remoteUpdateLog.htlcHasModification(htlcIndex) {
|
if lc.updateLogs.Remote.htlcHasModification(htlcIndex) {
|
||||||
return ErrHtlcIndexAlreadySettled(htlcIndex)
|
return ErrHtlcIndexAlreadySettled(htlcIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6050,7 +6065,7 @@ func (lc *LightningChannel) SettleHTLC(preimage [32]byte,
|
|||||||
pd := &PaymentDescriptor{
|
pd := &PaymentDescriptor{
|
||||||
Amount: htlc.Amount,
|
Amount: htlc.Amount,
|
||||||
RPreimage: preimage,
|
RPreimage: preimage,
|
||||||
LogIndex: lc.localUpdateLog.logIndex,
|
LogIndex: lc.updateLogs.Local.logIndex,
|
||||||
ParentIndex: htlcIndex,
|
ParentIndex: htlcIndex,
|
||||||
EntryType: Settle,
|
EntryType: Settle,
|
||||||
SourceRef: sourceRef,
|
SourceRef: sourceRef,
|
||||||
@@ -6058,12 +6073,12 @@ func (lc *LightningChannel) SettleHTLC(preimage [32]byte,
|
|||||||
ClosedCircuitKey: closeKey,
|
ClosedCircuitKey: closeKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
lc.localUpdateLog.appendUpdate(pd)
|
lc.updateLogs.Local.appendUpdate(pd)
|
||||||
|
|
||||||
// With the settle added to our local log, we'll now mark the HTLC as
|
// With the settle added to our local log, we'll now mark the HTLC as
|
||||||
// modified to prevent ourselves from accidentally attempting a
|
// modified to prevent ourselves from accidentally attempting a
|
||||||
// duplicate settle.
|
// duplicate settle.
|
||||||
lc.remoteUpdateLog.markHtlcModified(htlcIndex)
|
lc.updateLogs.Remote.markHtlcModified(htlcIndex)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -6076,7 +6091,7 @@ func (lc *LightningChannel) ReceiveHTLCSettle(preimage [32]byte, htlcIndex uint6
|
|||||||
lc.Lock()
|
lc.Lock()
|
||||||
defer lc.Unlock()
|
defer lc.Unlock()
|
||||||
|
|
||||||
htlc := lc.localUpdateLog.lookupHtlc(htlcIndex)
|
htlc := lc.updateLogs.Local.lookupHtlc(htlcIndex)
|
||||||
if htlc == nil {
|
if htlc == nil {
|
||||||
return ErrUnknownHtlcIndex{lc.ShortChanID(), htlcIndex}
|
return ErrUnknownHtlcIndex{lc.ShortChanID(), htlcIndex}
|
||||||
}
|
}
|
||||||
@@ -6084,7 +6099,7 @@ func (lc *LightningChannel) ReceiveHTLCSettle(preimage [32]byte, htlcIndex uint6
|
|||||||
// Now that we know the HTLC exists, before checking to see if the
|
// Now that we know the HTLC exists, before checking to see if the
|
||||||
// preimage matches, we'll ensure that they haven't already attempted
|
// preimage matches, we'll ensure that they haven't already attempted
|
||||||
// to modify the HTLC.
|
// to modify the HTLC.
|
||||||
if lc.localUpdateLog.htlcHasModification(htlcIndex) {
|
if lc.updateLogs.Local.htlcHasModification(htlcIndex) {
|
||||||
return ErrHtlcIndexAlreadySettled(htlcIndex)
|
return ErrHtlcIndexAlreadySettled(htlcIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6097,16 +6112,16 @@ func (lc *LightningChannel) ReceiveHTLCSettle(preimage [32]byte, htlcIndex uint6
|
|||||||
RPreimage: preimage,
|
RPreimage: preimage,
|
||||||
ParentIndex: htlc.HtlcIndex,
|
ParentIndex: htlc.HtlcIndex,
|
||||||
RHash: htlc.RHash,
|
RHash: htlc.RHash,
|
||||||
LogIndex: lc.remoteUpdateLog.logIndex,
|
LogIndex: lc.updateLogs.Remote.logIndex,
|
||||||
EntryType: Settle,
|
EntryType: Settle,
|
||||||
}
|
}
|
||||||
|
|
||||||
lc.remoteUpdateLog.appendUpdate(pd)
|
lc.updateLogs.Remote.appendUpdate(pd)
|
||||||
|
|
||||||
// With the settle added to the remote log, we'll now mark the HTLC as
|
// With the settle added to the remote log, we'll now mark the HTLC as
|
||||||
// modified to prevent the remote party from accidentally attempting a
|
// modified to prevent the remote party from accidentally attempting a
|
||||||
// duplicate settle.
|
// duplicate settle.
|
||||||
lc.localUpdateLog.markHtlcModified(htlcIndex)
|
lc.updateLogs.Local.markHtlcModified(htlcIndex)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -6142,14 +6157,14 @@ func (lc *LightningChannel) FailHTLC(htlcIndex uint64, reason []byte,
|
|||||||
lc.Lock()
|
lc.Lock()
|
||||||
defer lc.Unlock()
|
defer lc.Unlock()
|
||||||
|
|
||||||
htlc := lc.remoteUpdateLog.lookupHtlc(htlcIndex)
|
htlc := lc.updateLogs.Remote.lookupHtlc(htlcIndex)
|
||||||
if htlc == nil {
|
if htlc == nil {
|
||||||
return ErrUnknownHtlcIndex{lc.ShortChanID(), htlcIndex}
|
return ErrUnknownHtlcIndex{lc.ShortChanID(), htlcIndex}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now that we know the HTLC exists, we'll ensure that we haven't
|
// Now that we know the HTLC exists, we'll ensure that we haven't
|
||||||
// already attempted to fail the HTLC.
|
// already attempted to fail the HTLC.
|
||||||
if lc.remoteUpdateLog.htlcHasModification(htlcIndex) {
|
if lc.updateLogs.Remote.htlcHasModification(htlcIndex) {
|
||||||
return ErrHtlcIndexAlreadyFailed(htlcIndex)
|
return ErrHtlcIndexAlreadyFailed(htlcIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6157,7 +6172,7 @@ func (lc *LightningChannel) FailHTLC(htlcIndex uint64, reason []byte,
|
|||||||
Amount: htlc.Amount,
|
Amount: htlc.Amount,
|
||||||
RHash: htlc.RHash,
|
RHash: htlc.RHash,
|
||||||
ParentIndex: htlcIndex,
|
ParentIndex: htlcIndex,
|
||||||
LogIndex: lc.localUpdateLog.logIndex,
|
LogIndex: lc.updateLogs.Local.logIndex,
|
||||||
EntryType: Fail,
|
EntryType: Fail,
|
||||||
FailReason: reason,
|
FailReason: reason,
|
||||||
SourceRef: sourceRef,
|
SourceRef: sourceRef,
|
||||||
@@ -6165,12 +6180,12 @@ func (lc *LightningChannel) FailHTLC(htlcIndex uint64, reason []byte,
|
|||||||
ClosedCircuitKey: closeKey,
|
ClosedCircuitKey: closeKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
lc.localUpdateLog.appendUpdate(pd)
|
lc.updateLogs.Local.appendUpdate(pd)
|
||||||
|
|
||||||
// With the fail added to the remote log, we'll now mark the HTLC as
|
// With the fail added to the remote log, we'll now mark the HTLC as
|
||||||
// modified to prevent ourselves from accidentally attempting a
|
// modified to prevent ourselves from accidentally attempting a
|
||||||
// duplicate fail.
|
// duplicate fail.
|
||||||
lc.remoteUpdateLog.markHtlcModified(htlcIndex)
|
lc.updateLogs.Remote.markHtlcModified(htlcIndex)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -6192,14 +6207,14 @@ func (lc *LightningChannel) MalformedFailHTLC(htlcIndex uint64,
|
|||||||
lc.Lock()
|
lc.Lock()
|
||||||
defer lc.Unlock()
|
defer lc.Unlock()
|
||||||
|
|
||||||
htlc := lc.remoteUpdateLog.lookupHtlc(htlcIndex)
|
htlc := lc.updateLogs.Remote.lookupHtlc(htlcIndex)
|
||||||
if htlc == nil {
|
if htlc == nil {
|
||||||
return ErrUnknownHtlcIndex{lc.ShortChanID(), htlcIndex}
|
return ErrUnknownHtlcIndex{lc.ShortChanID(), htlcIndex}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now that we know the HTLC exists, we'll ensure that we haven't
|
// Now that we know the HTLC exists, we'll ensure that we haven't
|
||||||
// already attempted to fail the HTLC.
|
// already attempted to fail the HTLC.
|
||||||
if lc.remoteUpdateLog.htlcHasModification(htlcIndex) {
|
if lc.updateLogs.Remote.htlcHasModification(htlcIndex) {
|
||||||
return ErrHtlcIndexAlreadyFailed(htlcIndex)
|
return ErrHtlcIndexAlreadyFailed(htlcIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6207,19 +6222,19 @@ func (lc *LightningChannel) MalformedFailHTLC(htlcIndex uint64,
|
|||||||
Amount: htlc.Amount,
|
Amount: htlc.Amount,
|
||||||
RHash: htlc.RHash,
|
RHash: htlc.RHash,
|
||||||
ParentIndex: htlcIndex,
|
ParentIndex: htlcIndex,
|
||||||
LogIndex: lc.localUpdateLog.logIndex,
|
LogIndex: lc.updateLogs.Local.logIndex,
|
||||||
EntryType: MalformedFail,
|
EntryType: MalformedFail,
|
||||||
FailCode: failCode,
|
FailCode: failCode,
|
||||||
ShaOnionBlob: shaOnionBlob,
|
ShaOnionBlob: shaOnionBlob,
|
||||||
SourceRef: sourceRef,
|
SourceRef: sourceRef,
|
||||||
}
|
}
|
||||||
|
|
||||||
lc.localUpdateLog.appendUpdate(pd)
|
lc.updateLogs.Local.appendUpdate(pd)
|
||||||
|
|
||||||
// With the fail added to the remote log, we'll now mark the HTLC as
|
// With the fail added to the remote log, we'll now mark the HTLC as
|
||||||
// modified to prevent ourselves from accidentally attempting a
|
// modified to prevent ourselves from accidentally attempting a
|
||||||
// duplicate fail.
|
// duplicate fail.
|
||||||
lc.remoteUpdateLog.markHtlcModified(htlcIndex)
|
lc.updateLogs.Remote.markHtlcModified(htlcIndex)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -6234,14 +6249,14 @@ func (lc *LightningChannel) ReceiveFailHTLC(htlcIndex uint64, reason []byte,
|
|||||||
lc.Lock()
|
lc.Lock()
|
||||||
defer lc.Unlock()
|
defer lc.Unlock()
|
||||||
|
|
||||||
htlc := lc.localUpdateLog.lookupHtlc(htlcIndex)
|
htlc := lc.updateLogs.Local.lookupHtlc(htlcIndex)
|
||||||
if htlc == nil {
|
if htlc == nil {
|
||||||
return ErrUnknownHtlcIndex{lc.ShortChanID(), htlcIndex}
|
return ErrUnknownHtlcIndex{lc.ShortChanID(), htlcIndex}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now that we know the HTLC exists, we'll ensure that they haven't
|
// Now that we know the HTLC exists, we'll ensure that they haven't
|
||||||
// already attempted to fail the HTLC.
|
// already attempted to fail the HTLC.
|
||||||
if lc.localUpdateLog.htlcHasModification(htlcIndex) {
|
if lc.updateLogs.Local.htlcHasModification(htlcIndex) {
|
||||||
return ErrHtlcIndexAlreadyFailed(htlcIndex)
|
return ErrHtlcIndexAlreadyFailed(htlcIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6249,17 +6264,17 @@ func (lc *LightningChannel) ReceiveFailHTLC(htlcIndex uint64, reason []byte,
|
|||||||
Amount: htlc.Amount,
|
Amount: htlc.Amount,
|
||||||
RHash: htlc.RHash,
|
RHash: htlc.RHash,
|
||||||
ParentIndex: htlc.HtlcIndex,
|
ParentIndex: htlc.HtlcIndex,
|
||||||
LogIndex: lc.remoteUpdateLog.logIndex,
|
LogIndex: lc.updateLogs.Remote.logIndex,
|
||||||
EntryType: Fail,
|
EntryType: Fail,
|
||||||
FailReason: reason,
|
FailReason: reason,
|
||||||
}
|
}
|
||||||
|
|
||||||
lc.remoteUpdateLog.appendUpdate(pd)
|
lc.updateLogs.Remote.appendUpdate(pd)
|
||||||
|
|
||||||
// With the fail added to the remote log, we'll now mark the HTLC as
|
// With the fail added to the remote log, we'll now mark the HTLC as
|
||||||
// modified to prevent ourselves from accidentally attempting a
|
// modified to prevent ourselves from accidentally attempting a
|
||||||
// duplicate fail.
|
// duplicate fail.
|
||||||
lc.localUpdateLog.markHtlcModified(htlcIndex)
|
lc.updateLogs.Local.markHtlcModified(htlcIndex)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -8127,7 +8142,7 @@ func (lc *LightningChannel) availableBalance(
|
|||||||
// ACKed.
|
// ACKed.
|
||||||
remoteACKedIndex := lc.commitChains.Local.tip().theirMessageIndex
|
remoteACKedIndex := lc.commitChains.Local.tip().theirMessageIndex
|
||||||
htlcView := lc.fetchHTLCView(remoteACKedIndex,
|
htlcView := lc.fetchHTLCView(remoteACKedIndex,
|
||||||
lc.localUpdateLog.logIndex)
|
lc.updateLogs.Local.logIndex)
|
||||||
|
|
||||||
// Calculate our available balance from our local commitment.
|
// Calculate our available balance from our local commitment.
|
||||||
// TODO(halseth): could reuse parts validateCommitmentSanity to do this
|
// TODO(halseth): could reuse parts validateCommitmentSanity to do this
|
||||||
@@ -8359,12 +8374,12 @@ func (lc *LightningChannel) UpdateFee(feePerKw chainfee.SatPerKWeight) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pd := &PaymentDescriptor{
|
pd := &PaymentDescriptor{
|
||||||
LogIndex: lc.localUpdateLog.logIndex,
|
LogIndex: lc.updateLogs.Local.logIndex,
|
||||||
Amount: lnwire.NewMSatFromSatoshis(btcutil.Amount(feePerKw)),
|
Amount: lnwire.NewMSatFromSatoshis(btcutil.Amount(feePerKw)),
|
||||||
EntryType: FeeUpdate,
|
EntryType: FeeUpdate,
|
||||||
}
|
}
|
||||||
|
|
||||||
lc.localUpdateLog.appendUpdate(pd)
|
lc.updateLogs.Local.appendUpdate(pd)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -8383,8 +8398,8 @@ func (lc *LightningChannel) CommitFeeTotalAt(
|
|||||||
|
|
||||||
// We want to grab every update in both update logs to calculate the
|
// We want to grab every update in both update logs to calculate the
|
||||||
// commitment fees in the worst-case with this fee-rate.
|
// commitment fees in the worst-case with this fee-rate.
|
||||||
localIdx := lc.localUpdateLog.logIndex
|
localIdx := lc.updateLogs.Local.logIndex
|
||||||
remoteIdx := lc.remoteUpdateLog.logIndex
|
remoteIdx := lc.updateLogs.Remote.logIndex
|
||||||
|
|
||||||
localHtlcView := lc.fetchHTLCView(remoteIdx, localIdx)
|
localHtlcView := lc.fetchHTLCView(remoteIdx, localIdx)
|
||||||
|
|
||||||
@@ -8431,12 +8446,12 @@ func (lc *LightningChannel) ReceiveUpdateFee(feePerKw chainfee.SatPerKWeight) er
|
|||||||
|
|
||||||
// TODO(roasbeef): or just modify to use the other balance?
|
// TODO(roasbeef): or just modify to use the other balance?
|
||||||
pd := &PaymentDescriptor{
|
pd := &PaymentDescriptor{
|
||||||
LogIndex: lc.remoteUpdateLog.logIndex,
|
LogIndex: lc.updateLogs.Remote.logIndex,
|
||||||
Amount: lnwire.NewMSatFromSatoshis(btcutil.Amount(feePerKw)),
|
Amount: lnwire.NewMSatFromSatoshis(btcutil.Amount(feePerKw)),
|
||||||
EntryType: FeeUpdate,
|
EntryType: FeeUpdate,
|
||||||
}
|
}
|
||||||
|
|
||||||
lc.remoteUpdateLog.appendUpdate(pd)
|
lc.updateLogs.Remote.appendUpdate(pd)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -8905,7 +8920,7 @@ func (lc *LightningChannel) unsignedLocalUpdates(remoteMessageIndex,
|
|||||||
localMessageIndex uint64, chanID lnwire.ChannelID) []channeldb.LogUpdate {
|
localMessageIndex uint64, chanID lnwire.ChannelID) []channeldb.LogUpdate {
|
||||||
|
|
||||||
var localPeerUpdates []channeldb.LogUpdate
|
var localPeerUpdates []channeldb.LogUpdate
|
||||||
for e := lc.localUpdateLog.Front(); e != nil; e = e.Next() {
|
for e := lc.updateLogs.Local.Front(); e != nil; e = e.Next() {
|
||||||
pd := e.Value
|
pd := e.Value
|
||||||
|
|
||||||
// We don't save add updates as they are restored from the
|
// We don't save add updates as they are restored from the
|
||||||
|
|||||||
+130
-103
@@ -335,21 +335,23 @@ func testAddSettleWorkflow(t *testing.T, tweakless bool,
|
|||||||
// The logs of both sides should now be cleared since the entry adding
|
// The logs of both sides should now be cleared since the entry adding
|
||||||
// the HTLC should have been removed once both sides receive the
|
// the HTLC should have been removed once both sides receive the
|
||||||
// revocation.
|
// revocation.
|
||||||
if aliceChannel.localUpdateLog.Len() != 0 {
|
if aliceChannel.updateLogs.Local.Len() != 0 {
|
||||||
t.Fatalf("alice's local not updated, should be empty, has %v "+
|
t.Fatalf("alice's local not updated, should be empty, has %v "+
|
||||||
"entries instead", aliceChannel.localUpdateLog.Len())
|
"entries instead", aliceChannel.updateLogs.Local.Len())
|
||||||
}
|
}
|
||||||
if aliceChannel.remoteUpdateLog.Len() != 0 {
|
if aliceChannel.updateLogs.Remote.Len() != 0 {
|
||||||
t.Fatalf("alice's remote not updated, should be empty, has %v "+
|
t.Fatalf("alice's remote not updated, should be empty, has %v "+
|
||||||
"entries instead", aliceChannel.remoteUpdateLog.Len())
|
"entries instead", aliceChannel.updateLogs.Remote.Len())
|
||||||
}
|
}
|
||||||
if len(aliceChannel.localUpdateLog.updateIndex) != 0 {
|
if len(aliceChannel.updateLogs.Local.updateIndex) != 0 {
|
||||||
t.Fatalf("alice's local log index not cleared, should be empty but "+
|
t.Fatalf("alice's local log index not cleared, should be "+
|
||||||
"has %v entries", len(aliceChannel.localUpdateLog.updateIndex))
|
"empty but has %v entries",
|
||||||
|
len(aliceChannel.updateLogs.Local.updateIndex))
|
||||||
}
|
}
|
||||||
if len(aliceChannel.remoteUpdateLog.updateIndex) != 0 {
|
if len(aliceChannel.updateLogs.Remote.updateIndex) != 0 {
|
||||||
t.Fatalf("alice's remote log index not cleared, should be empty but "+
|
t.Fatalf("alice's remote log index not cleared, should be "+
|
||||||
"has %v entries", len(aliceChannel.remoteUpdateLog.updateIndex))
|
"empty but has %v entries",
|
||||||
|
len(aliceChannel.updateLogs.Remote.updateIndex))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1773,26 +1775,26 @@ func TestStateUpdatePersistence(t *testing.T) {
|
|||||||
// Helper method that asserts the expected number of updates are found
|
// Helper method that asserts the expected number of updates are found
|
||||||
// in the update logs.
|
// in the update logs.
|
||||||
assertNumLogUpdates := func(numAliceUpdates, numBobUpdates int) {
|
assertNumLogUpdates := func(numAliceUpdates, numBobUpdates int) {
|
||||||
if aliceChannel.localUpdateLog.Len() != numAliceUpdates {
|
if aliceChannel.updateLogs.Local.Len() != numAliceUpdates {
|
||||||
t.Fatalf("expected %d local updates, found %d",
|
t.Fatalf("expected %d local updates, found %d",
|
||||||
numAliceUpdates,
|
numAliceUpdates,
|
||||||
aliceChannel.localUpdateLog.Len())
|
aliceChannel.updateLogs.Local.Len())
|
||||||
}
|
}
|
||||||
if aliceChannel.remoteUpdateLog.Len() != numBobUpdates {
|
if aliceChannel.updateLogs.Remote.Len() != numBobUpdates {
|
||||||
t.Fatalf("expected %d remote updates, found %d",
|
t.Fatalf("expected %d remote updates, found %d",
|
||||||
numBobUpdates,
|
numBobUpdates,
|
||||||
aliceChannel.remoteUpdateLog.Len())
|
aliceChannel.updateLogs.Remote.Len())
|
||||||
}
|
}
|
||||||
|
|
||||||
if bobChannel.localUpdateLog.Len() != numBobUpdates {
|
if bobChannel.updateLogs.Local.Len() != numBobUpdates {
|
||||||
t.Fatalf("expected %d local updates, found %d",
|
t.Fatalf("expected %d local updates, found %d",
|
||||||
numBobUpdates,
|
numBobUpdates,
|
||||||
bobChannel.localUpdateLog.Len())
|
bobChannel.updateLogs.Local.Len())
|
||||||
}
|
}
|
||||||
if bobChannel.remoteUpdateLog.Len() != numAliceUpdates {
|
if bobChannel.updateLogs.Remote.Len() != numAliceUpdates {
|
||||||
t.Fatalf("expected %d remote updates, found %d",
|
t.Fatalf("expected %d remote updates, found %d",
|
||||||
numAliceUpdates,
|
numAliceUpdates,
|
||||||
bobChannel.remoteUpdateLog.Len())
|
bobChannel.updateLogs.Remote.Len())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1868,62 +1870,72 @@ func TestStateUpdatePersistence(t *testing.T) {
|
|||||||
|
|
||||||
// The state update logs of the new channels and the old channels
|
// The state update logs of the new channels and the old channels
|
||||||
// should now be identical other than the height the HTLCs were added.
|
// should now be identical other than the height the HTLCs were added.
|
||||||
if aliceChannel.localUpdateLog.logIndex !=
|
if aliceChannel.updateLogs.Local.logIndex !=
|
||||||
aliceChannelNew.localUpdateLog.logIndex {
|
aliceChannelNew.updateLogs.Local.logIndex {
|
||||||
|
|
||||||
t.Fatalf("alice log counter: expected %v, got %v",
|
t.Fatalf("alice log counter: expected %v, got %v",
|
||||||
aliceChannel.localUpdateLog.logIndex,
|
aliceChannel.updateLogs.Local.logIndex,
|
||||||
aliceChannelNew.localUpdateLog.logIndex)
|
aliceChannelNew.updateLogs.Local.logIndex)
|
||||||
}
|
}
|
||||||
if aliceChannel.remoteUpdateLog.logIndex !=
|
if aliceChannel.updateLogs.Remote.logIndex !=
|
||||||
aliceChannelNew.remoteUpdateLog.logIndex {
|
aliceChannelNew.updateLogs.Remote.logIndex {
|
||||||
|
|
||||||
t.Fatalf("alice log counter: expected %v, got %v",
|
t.Fatalf("alice log counter: expected %v, got %v",
|
||||||
aliceChannel.remoteUpdateLog.logIndex,
|
aliceChannel.updateLogs.Remote.logIndex,
|
||||||
aliceChannelNew.remoteUpdateLog.logIndex)
|
aliceChannelNew.updateLogs.Remote.logIndex)
|
||||||
}
|
}
|
||||||
if aliceChannel.localUpdateLog.Len() !=
|
if aliceChannel.updateLogs.Local.Len() !=
|
||||||
aliceChannelNew.localUpdateLog.Len() {
|
aliceChannelNew.updateLogs.Local.Len() {
|
||||||
|
|
||||||
t.Fatalf("alice log len: expected %v, got %v",
|
t.Fatalf("alice log len: expected %v, got %v",
|
||||||
aliceChannel.localUpdateLog.Len(),
|
aliceChannel.updateLogs.Local.Len(),
|
||||||
aliceChannelNew.localUpdateLog.Len())
|
aliceChannelNew.updateLogs.Local.Len())
|
||||||
}
|
}
|
||||||
if aliceChannel.remoteUpdateLog.Len() !=
|
if aliceChannel.updateLogs.Remote.Len() !=
|
||||||
aliceChannelNew.remoteUpdateLog.Len() {
|
aliceChannelNew.updateLogs.Remote.Len() {
|
||||||
|
|
||||||
t.Fatalf("alice log len: expected %v, got %v",
|
t.Fatalf("alice log len: expected %v, got %v",
|
||||||
aliceChannel.remoteUpdateLog.Len(),
|
aliceChannel.updateLogs.Remote.Len(),
|
||||||
aliceChannelNew.remoteUpdateLog.Len())
|
aliceChannelNew.updateLogs.Remote.Len())
|
||||||
}
|
}
|
||||||
if bobChannel.localUpdateLog.logIndex !=
|
if bobChannel.updateLogs.Local.logIndex !=
|
||||||
bobChannelNew.localUpdateLog.logIndex {
|
bobChannelNew.updateLogs.Local.logIndex {
|
||||||
|
|
||||||
t.Fatalf("bob log counter: expected %v, got %v",
|
t.Fatalf("bob log counter: expected %v, got %v",
|
||||||
bobChannel.localUpdateLog.logIndex,
|
bobChannel.updateLogs.Local.logIndex,
|
||||||
bobChannelNew.localUpdateLog.logIndex)
|
bobChannelNew.updateLogs.Local.logIndex)
|
||||||
}
|
}
|
||||||
if bobChannel.remoteUpdateLog.logIndex !=
|
if bobChannel.updateLogs.Remote.logIndex !=
|
||||||
bobChannelNew.remoteUpdateLog.logIndex {
|
bobChannelNew.updateLogs.Remote.logIndex {
|
||||||
|
|
||||||
t.Fatalf("bob log counter: expected %v, got %v",
|
t.Fatalf("bob log counter: expected %v, got %v",
|
||||||
bobChannel.remoteUpdateLog.logIndex,
|
bobChannel.updateLogs.Remote.logIndex,
|
||||||
bobChannelNew.remoteUpdateLog.logIndex)
|
bobChannelNew.updateLogs.Remote.logIndex)
|
||||||
}
|
}
|
||||||
if bobChannel.localUpdateLog.Len() !=
|
if bobChannel.updateLogs.Local.Len() !=
|
||||||
bobChannelNew.localUpdateLog.Len() {
|
bobChannelNew.updateLogs.Local.Len() {
|
||||||
|
|
||||||
t.Fatalf("bob log len: expected %v, got %v",
|
t.Fatalf("bob log len: expected %v, got %v",
|
||||||
bobChannel.localUpdateLog.Len(),
|
bobChannel.updateLogs.Local.Len(),
|
||||||
bobChannelNew.localUpdateLog.Len())
|
bobChannelNew.updateLogs.Local.Len())
|
||||||
}
|
}
|
||||||
if bobChannel.remoteUpdateLog.Len() !=
|
if bobChannel.updateLogs.Remote.Len() !=
|
||||||
bobChannelNew.remoteUpdateLog.Len() {
|
bobChannelNew.updateLogs.Remote.Len() {
|
||||||
|
|
||||||
t.Fatalf("bob log len: expected %v, got %v",
|
t.Fatalf("bob log len: expected %v, got %v",
|
||||||
bobChannel.remoteUpdateLog.Len(),
|
bobChannel.updateLogs.Remote.Len(),
|
||||||
bobChannelNew.remoteUpdateLog.Len())
|
bobChannelNew.updateLogs.Remote.Len())
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(roasbeef): expand test to also ensure state revocation log has
|
// TODO(roasbeef): expand test to also ensure state revocation log has
|
||||||
// proper pk scripts
|
// proper pk scripts
|
||||||
|
|
||||||
// Newly generated pkScripts for HTLCs should be the same as in the old channel.
|
// Newly generated pkScripts for HTLCs should be the same as in the old channel.
|
||||||
for _, entry := range aliceChannel.localUpdateLog.htlcIndex {
|
for _, entry := range aliceChannel.updateLogs.Local.htlcIndex {
|
||||||
htlc := entry.Value
|
htlc := entry.Value
|
||||||
restoredHtlc := aliceChannelNew.localUpdateLog.lookupHtlc(htlc.HtlcIndex)
|
restoredHtlc := aliceChannelNew.updateLogs.Local.lookupHtlc(
|
||||||
|
htlc.HtlcIndex,
|
||||||
|
)
|
||||||
if !bytes.Equal(htlc.ourPkScript, restoredHtlc.ourPkScript) {
|
if !bytes.Equal(htlc.ourPkScript, restoredHtlc.ourPkScript) {
|
||||||
t.Fatalf("alice ourPkScript in ourLog: expected %X, got %X",
|
t.Fatalf("alice ourPkScript in ourLog: expected %X, got %X",
|
||||||
htlc.ourPkScript[:5], restoredHtlc.ourPkScript[:5])
|
htlc.ourPkScript[:5], restoredHtlc.ourPkScript[:5])
|
||||||
@@ -1933,9 +1945,11 @@ func TestStateUpdatePersistence(t *testing.T) {
|
|||||||
htlc.theirPkScript[:5], restoredHtlc.theirPkScript[:5])
|
htlc.theirPkScript[:5], restoredHtlc.theirPkScript[:5])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, entry := range aliceChannel.remoteUpdateLog.htlcIndex {
|
for _, entry := range aliceChannel.updateLogs.Remote.htlcIndex {
|
||||||
htlc := entry.Value
|
htlc := entry.Value
|
||||||
restoredHtlc := aliceChannelNew.remoteUpdateLog.lookupHtlc(htlc.HtlcIndex)
|
restoredHtlc := aliceChannelNew.updateLogs.Remote.lookupHtlc(
|
||||||
|
htlc.HtlcIndex,
|
||||||
|
)
|
||||||
if !bytes.Equal(htlc.ourPkScript, restoredHtlc.ourPkScript) {
|
if !bytes.Equal(htlc.ourPkScript, restoredHtlc.ourPkScript) {
|
||||||
t.Fatalf("alice ourPkScript in theirLog: expected %X, got %X",
|
t.Fatalf("alice ourPkScript in theirLog: expected %X, got %X",
|
||||||
htlc.ourPkScript[:5], restoredHtlc.ourPkScript[:5])
|
htlc.ourPkScript[:5], restoredHtlc.ourPkScript[:5])
|
||||||
@@ -1945,9 +1959,11 @@ func TestStateUpdatePersistence(t *testing.T) {
|
|||||||
htlc.theirPkScript[:5], restoredHtlc.theirPkScript[:5])
|
htlc.theirPkScript[:5], restoredHtlc.theirPkScript[:5])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, entry := range bobChannel.localUpdateLog.htlcIndex {
|
for _, entry := range bobChannel.updateLogs.Local.htlcIndex {
|
||||||
htlc := entry.Value
|
htlc := entry.Value
|
||||||
restoredHtlc := bobChannelNew.localUpdateLog.lookupHtlc(htlc.HtlcIndex)
|
restoredHtlc := bobChannelNew.updateLogs.Local.lookupHtlc(
|
||||||
|
htlc.HtlcIndex,
|
||||||
|
)
|
||||||
if !bytes.Equal(htlc.ourPkScript, restoredHtlc.ourPkScript) {
|
if !bytes.Equal(htlc.ourPkScript, restoredHtlc.ourPkScript) {
|
||||||
t.Fatalf("bob ourPkScript in ourLog: expected %X, got %X",
|
t.Fatalf("bob ourPkScript in ourLog: expected %X, got %X",
|
||||||
htlc.ourPkScript[:5], restoredHtlc.ourPkScript[:5])
|
htlc.ourPkScript[:5], restoredHtlc.ourPkScript[:5])
|
||||||
@@ -1957,9 +1973,11 @@ func TestStateUpdatePersistence(t *testing.T) {
|
|||||||
htlc.theirPkScript[:5], restoredHtlc.theirPkScript[:5])
|
htlc.theirPkScript[:5], restoredHtlc.theirPkScript[:5])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, entry := range bobChannel.remoteUpdateLog.htlcIndex {
|
for _, entry := range bobChannel.updateLogs.Remote.htlcIndex {
|
||||||
htlc := entry.Value
|
htlc := entry.Value
|
||||||
restoredHtlc := bobChannelNew.remoteUpdateLog.lookupHtlc(htlc.HtlcIndex)
|
restoredHtlc := bobChannelNew.updateLogs.Remote.lookupHtlc(
|
||||||
|
htlc.HtlcIndex,
|
||||||
|
)
|
||||||
if !bytes.Equal(htlc.ourPkScript, restoredHtlc.ourPkScript) {
|
if !bytes.Equal(htlc.ourPkScript, restoredHtlc.ourPkScript) {
|
||||||
t.Fatalf("bob ourPkScript in theirLog: expected %X, got %X",
|
t.Fatalf("bob ourPkScript in theirLog: expected %X, got %X",
|
||||||
htlc.ourPkScript[:5], restoredHtlc.ourPkScript[:5])
|
htlc.ourPkScript[:5], restoredHtlc.ourPkScript[:5])
|
||||||
@@ -3245,39 +3263,39 @@ func TestChanSyncOweCommitment(t *testing.T) {
|
|||||||
// Alice's local log counter should be 4 and her HTLC index 3. She
|
// Alice's local log counter should be 4 and her HTLC index 3. She
|
||||||
// should detect Bob's remote log counter as being 3 and his HTLC index
|
// should detect Bob's remote log counter as being 3 and his HTLC index
|
||||||
// 3 as well.
|
// 3 as well.
|
||||||
if aliceChannel.localUpdateLog.logIndex != 4 {
|
if aliceChannel.updateLogs.Local.logIndex != 4 {
|
||||||
t.Fatalf("incorrect log index: expected %v, got %v", 4,
|
t.Fatalf("incorrect log index: expected %v, got %v", 4,
|
||||||
aliceChannel.localUpdateLog.logIndex)
|
aliceChannel.updateLogs.Local.logIndex)
|
||||||
}
|
}
|
||||||
if aliceChannel.localUpdateLog.htlcCounter != 1 {
|
if aliceChannel.updateLogs.Local.htlcCounter != 1 {
|
||||||
t.Fatalf("incorrect htlc index: expected %v, got %v", 1,
|
t.Fatalf("incorrect htlc index: expected %v, got %v", 1,
|
||||||
aliceChannel.localUpdateLog.htlcCounter)
|
aliceChannel.updateLogs.Local.htlcCounter)
|
||||||
}
|
}
|
||||||
if aliceChannel.remoteUpdateLog.logIndex != 3 {
|
if aliceChannel.updateLogs.Remote.logIndex != 3 {
|
||||||
t.Fatalf("incorrect log index: expected %v, got %v", 3,
|
t.Fatalf("incorrect log index: expected %v, got %v", 3,
|
||||||
aliceChannel.localUpdateLog.logIndex)
|
aliceChannel.updateLogs.Local.logIndex)
|
||||||
}
|
}
|
||||||
if aliceChannel.remoteUpdateLog.htlcCounter != 3 {
|
if aliceChannel.updateLogs.Remote.htlcCounter != 3 {
|
||||||
t.Fatalf("incorrect htlc index: expected %v, got %v", 3,
|
t.Fatalf("incorrect htlc index: expected %v, got %v", 3,
|
||||||
aliceChannel.localUpdateLog.htlcCounter)
|
aliceChannel.updateLogs.Local.htlcCounter)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bob should also have the same state, but mirrored.
|
// Bob should also have the same state, but mirrored.
|
||||||
if bobChannel.localUpdateLog.logIndex != 3 {
|
if bobChannel.updateLogs.Local.logIndex != 3 {
|
||||||
t.Fatalf("incorrect log index: expected %v, got %v", 3,
|
t.Fatalf("incorrect log index: expected %v, got %v", 3,
|
||||||
bobChannel.localUpdateLog.logIndex)
|
bobChannel.updateLogs.Local.logIndex)
|
||||||
}
|
}
|
||||||
if bobChannel.localUpdateLog.htlcCounter != 3 {
|
if bobChannel.updateLogs.Local.htlcCounter != 3 {
|
||||||
t.Fatalf("incorrect htlc index: expected %v, got %v", 3,
|
t.Fatalf("incorrect htlc index: expected %v, got %v", 3,
|
||||||
bobChannel.localUpdateLog.htlcCounter)
|
bobChannel.updateLogs.Local.htlcCounter)
|
||||||
}
|
}
|
||||||
if bobChannel.remoteUpdateLog.logIndex != 4 {
|
if bobChannel.updateLogs.Remote.logIndex != 4 {
|
||||||
t.Fatalf("incorrect log index: expected %v, got %v", 4,
|
t.Fatalf("incorrect log index: expected %v, got %v", 4,
|
||||||
bobChannel.localUpdateLog.logIndex)
|
bobChannel.updateLogs.Local.logIndex)
|
||||||
}
|
}
|
||||||
if bobChannel.remoteUpdateLog.htlcCounter != 1 {
|
if bobChannel.updateLogs.Remote.htlcCounter != 1 {
|
||||||
t.Fatalf("incorrect htlc index: expected %v, got %v", 1,
|
t.Fatalf("incorrect htlc index: expected %v, got %v", 1,
|
||||||
bobChannel.localUpdateLog.htlcCounter)
|
bobChannel.updateLogs.Local.htlcCounter)
|
||||||
}
|
}
|
||||||
|
|
||||||
// We'll conclude the test by having Bob settle Alice's HTLC, then
|
// We'll conclude the test by having Bob settle Alice's HTLC, then
|
||||||
@@ -4507,7 +4525,7 @@ func TestFeeUpdateOldDiskFormat(t *testing.T) {
|
|||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
expUpd := expFee + expAdd
|
expUpd := expFee + expAdd
|
||||||
upd, fees := countLog(aliceChannel.localUpdateLog)
|
upd, fees := countLog(aliceChannel.updateLogs.Local)
|
||||||
if upd != expUpd {
|
if upd != expUpd {
|
||||||
t.Fatalf("expected %d updates, found %d in Alice's "+
|
t.Fatalf("expected %d updates, found %d in Alice's "+
|
||||||
"log", expUpd, upd)
|
"log", expUpd, upd)
|
||||||
@@ -4516,7 +4534,7 @@ func TestFeeUpdateOldDiskFormat(t *testing.T) {
|
|||||||
t.Fatalf("expected %d fee updates, found %d in "+
|
t.Fatalf("expected %d fee updates, found %d in "+
|
||||||
"Alice's log", expFee, fees)
|
"Alice's log", expFee, fees)
|
||||||
}
|
}
|
||||||
upd, fees = countLog(bobChannel.remoteUpdateLog)
|
upd, fees = countLog(bobChannel.updateLogs.Remote)
|
||||||
if upd != expUpd {
|
if upd != expUpd {
|
||||||
t.Fatalf("expected %d updates, found %d in Bob's log",
|
t.Fatalf("expected %d updates, found %d in Bob's log",
|
||||||
expUpd, upd)
|
expUpd, upd)
|
||||||
@@ -5215,7 +5233,7 @@ func TestChanCommitWeightDustHtlcs(t *testing.T) {
|
|||||||
lc.commitChains.Local.tip().theirMessageIndex
|
lc.commitChains.Local.tip().theirMessageIndex
|
||||||
|
|
||||||
htlcView := lc.fetchHTLCView(remoteACKedIndex,
|
htlcView := lc.fetchHTLCView(remoteACKedIndex,
|
||||||
lc.localUpdateLog.logIndex)
|
lc.updateLogs.Local.logIndex)
|
||||||
|
|
||||||
_, w := lc.availableCommitmentBalance(
|
_, w := lc.availableCommitmentBalance(
|
||||||
htlcView, lntypes.Remote, FeeBuffer,
|
htlcView, lntypes.Remote, FeeBuffer,
|
||||||
@@ -6922,20 +6940,20 @@ func TestChannelRestoreUpdateLogs(t *testing.T) {
|
|||||||
|
|
||||||
// compare all the logs between the old and new channels, to make sure
|
// compare all the logs between the old and new channels, to make sure
|
||||||
// they all got restored properly.
|
// they all got restored properly.
|
||||||
err = compareLogs(aliceChannel.localUpdateLog,
|
err = compareLogs(aliceChannel.updateLogs.Local,
|
||||||
newAliceChannel.localUpdateLog)
|
newAliceChannel.updateLogs.Local)
|
||||||
require.NoError(t, err, "alice local log not restored")
|
require.NoError(t, err, "alice local log not restored")
|
||||||
|
|
||||||
err = compareLogs(aliceChannel.remoteUpdateLog,
|
err = compareLogs(aliceChannel.updateLogs.Remote,
|
||||||
newAliceChannel.remoteUpdateLog)
|
newAliceChannel.updateLogs.Remote)
|
||||||
require.NoError(t, err, "alice remote log not restored")
|
require.NoError(t, err, "alice remote log not restored")
|
||||||
|
|
||||||
err = compareLogs(bobChannel.localUpdateLog,
|
err = compareLogs(bobChannel.updateLogs.Local,
|
||||||
newBobChannel.localUpdateLog)
|
newBobChannel.updateLogs.Local)
|
||||||
require.NoError(t, err, "bob local log not restored")
|
require.NoError(t, err, "bob local log not restored")
|
||||||
|
|
||||||
err = compareLogs(bobChannel.remoteUpdateLog,
|
err = compareLogs(bobChannel.updateLogs.Remote,
|
||||||
newBobChannel.remoteUpdateLog)
|
newBobChannel.updateLogs.Remote)
|
||||||
require.NoError(t, err, "bob remote log not restored")
|
require.NoError(t, err, "bob remote log not restored")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6968,8 +6986,9 @@ func assertInLog(t *testing.T, log *updateLog, numAdds, numFails int) {
|
|||||||
// the local and remote update log of the given channel.
|
// the local and remote update log of the given channel.
|
||||||
func assertInLogs(t *testing.T, channel *LightningChannel, numAddsLocal,
|
func assertInLogs(t *testing.T, channel *LightningChannel, numAddsLocal,
|
||||||
numFailsLocal, numAddsRemote, numFailsRemote int) {
|
numFailsLocal, numAddsRemote, numFailsRemote int) {
|
||||||
assertInLog(t, channel.localUpdateLog, numAddsLocal, numFailsLocal)
|
|
||||||
assertInLog(t, channel.remoteUpdateLog, numAddsRemote, numFailsRemote)
|
assertInLog(t, channel.updateLogs.Local, numAddsLocal, numFailsLocal)
|
||||||
|
assertInLog(t, channel.updateLogs.Remote, numAddsRemote, numFailsRemote)
|
||||||
}
|
}
|
||||||
|
|
||||||
// restoreAndAssert creates a new LightningChannel from the given channel's
|
// restoreAndAssert creates a new LightningChannel from the given channel's
|
||||||
@@ -6984,8 +7003,10 @@ func restoreAndAssert(t *testing.T, channel *LightningChannel, numAddsLocal,
|
|||||||
)
|
)
|
||||||
require.NoError(t, err, "unable to create new channel")
|
require.NoError(t, err, "unable to create new channel")
|
||||||
|
|
||||||
assertInLog(t, newChannel.localUpdateLog, numAddsLocal, numFailsLocal)
|
assertInLog(t, newChannel.updateLogs.Local, numAddsLocal, numFailsLocal)
|
||||||
assertInLog(t, newChannel.remoteUpdateLog, numAddsRemote, numFailsRemote)
|
assertInLog(
|
||||||
|
t, newChannel.updateLogs.Remote, numAddsRemote, numFailsRemote,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestChannelRestoreUpdateLogsFailedHTLC runs through a scenario where an
|
// TestChannelRestoreUpdateLogsFailedHTLC runs through a scenario where an
|
||||||
@@ -7249,16 +7270,18 @@ func TestChannelRestoreCommitHeight(t *testing.T) {
|
|||||||
|
|
||||||
var pd *PaymentDescriptor
|
var pd *PaymentDescriptor
|
||||||
if remoteLog {
|
if remoteLog {
|
||||||
if newChannel.localUpdateLog.lookupHtlc(htlcIndex) != nil {
|
h := newChannel.updateLogs.Local.lookupHtlc(htlcIndex)
|
||||||
|
if h != nil {
|
||||||
t.Fatalf("htlc found in wrong log")
|
t.Fatalf("htlc found in wrong log")
|
||||||
}
|
}
|
||||||
pd = newChannel.remoteUpdateLog.lookupHtlc(htlcIndex)
|
pd = newChannel.updateLogs.Remote.lookupHtlc(htlcIndex)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if newChannel.remoteUpdateLog.lookupHtlc(htlcIndex) != nil {
|
h := newChannel.updateLogs.Remote.lookupHtlc(htlcIndex)
|
||||||
|
if h != nil {
|
||||||
t.Fatalf("htlc found in wrong log")
|
t.Fatalf("htlc found in wrong log")
|
||||||
}
|
}
|
||||||
pd = newChannel.localUpdateLog.lookupHtlc(htlcIndex)
|
pd = newChannel.updateLogs.Local.lookupHtlc(htlcIndex)
|
||||||
}
|
}
|
||||||
if pd == nil {
|
if pd == nil {
|
||||||
t.Fatalf("htlc not found in log")
|
t.Fatalf("htlc not found in log")
|
||||||
@@ -8196,16 +8219,18 @@ func TestFetchParent(t *testing.T) {
|
|||||||
// Create a lightning channel with newly initialized
|
// Create a lightning channel with newly initialized
|
||||||
// local and remote logs.
|
// local and remote logs.
|
||||||
lc := LightningChannel{
|
lc := LightningChannel{
|
||||||
localUpdateLog: newUpdateLog(0, 0),
|
updateLogs: lntypes.Dual[*updateLog]{
|
||||||
remoteUpdateLog: newUpdateLog(0, 0),
|
Local: newUpdateLog(0, 0),
|
||||||
|
Remote: newUpdateLog(0, 0),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the local and remote entries to update logs.
|
// Add the local and remote entries to update logs.
|
||||||
for _, entry := range test.localEntries {
|
for _, entry := range test.localEntries {
|
||||||
lc.localUpdateLog.appendHtlc(entry)
|
lc.updateLogs.Local.appendHtlc(entry)
|
||||||
}
|
}
|
||||||
for _, entry := range test.remoteEntries {
|
for _, entry := range test.remoteEntries {
|
||||||
lc.remoteUpdateLog.appendHtlc(entry)
|
lc.updateLogs.Remote.appendHtlc(entry)
|
||||||
}
|
}
|
||||||
|
|
||||||
parent, err := lc.fetchParent(
|
parent, err := lc.fetchParent(
|
||||||
@@ -8532,23 +8557,25 @@ func TestEvaluateView(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Create update logs for local and remote.
|
// Create update logs for local and remote.
|
||||||
localUpdateLog: newUpdateLog(0, 0),
|
updateLogs: lntypes.Dual[*updateLog]{
|
||||||
remoteUpdateLog: newUpdateLog(0, 0),
|
Local: newUpdateLog(0, 0),
|
||||||
|
Remote: newUpdateLog(0, 0),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, htlc := range test.ourHtlcs {
|
for _, htlc := range test.ourHtlcs {
|
||||||
if htlc.EntryType == Add {
|
if htlc.EntryType == Add {
|
||||||
lc.localUpdateLog.appendHtlc(htlc)
|
lc.updateLogs.Local.appendHtlc(htlc)
|
||||||
} else {
|
} else {
|
||||||
lc.localUpdateLog.appendUpdate(htlc)
|
lc.updateLogs.Local.appendUpdate(htlc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, htlc := range test.theirHtlcs {
|
for _, htlc := range test.theirHtlcs {
|
||||||
if htlc.EntryType == Add {
|
if htlc.EntryType == Add {
|
||||||
lc.remoteUpdateLog.appendHtlc(htlc)
|
lc.updateLogs.Remote.appendHtlc(htlc)
|
||||||
} else {
|
} else {
|
||||||
lc.remoteUpdateLog.appendUpdate(htlc)
|
lc.updateLogs.Remote.appendUpdate(htlc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user