mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-13 11:09:23 +01:00
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:
parent
8077862225
commit
2e7fbc446f
2 changed files with 235 additions and 193 deletions
|
@ -874,8 +874,7 @@ type LightningChannel struct {
|
|||
// updates to this channel. The log is walked backwards as HTLC updates
|
||||
// are applied in order to re-construct a commitment transaction from a
|
||||
// commitment. The log is compacted once a revocation is received.
|
||||
localUpdateLog *updateLog
|
||||
remoteUpdateLog *updateLog
|
||||
updateLogs lntypes.Dual[*updateLog]
|
||||
|
||||
// log is a channel-specific logging instance.
|
||||
log btclog.Logger
|
||||
|
@ -980,6 +979,10 @@ func NewLightningChannel(signer input.Signer,
|
|||
remoteUpdateLog := newUpdateLog(
|
||||
localCommit.RemoteLogIndex, localCommit.RemoteHtlcIndex,
|
||||
)
|
||||
updateLogs := lntypes.Dual[*updateLog]{
|
||||
Local: localUpdateLog,
|
||||
Remote: remoteUpdateLog,
|
||||
}
|
||||
|
||||
logPrefix := fmt.Sprintf("ChannelPoint(%v):", state.FundingOutpoint)
|
||||
|
||||
|
@ -1005,8 +1008,7 @@ func NewLightningChannel(signer input.Signer,
|
|||
commitBuilder: NewCommitmentBuilder(
|
||||
state, opts.leafStore,
|
||||
),
|
||||
localUpdateLog: localUpdateLog,
|
||||
remoteUpdateLog: remoteUpdateLog,
|
||||
updateLogs: updateLogs,
|
||||
Capacity: state.Capacity,
|
||||
taprootNonceProducer: taprootNonceProducer,
|
||||
log: build.NewPrefixLog(logPrefix, walletLog),
|
||||
|
@ -1662,7 +1664,7 @@ func (lc *LightningChannel) restoreStateLogs(
|
|||
htlc.addCommitHeightRemote = incomingRemoteAddHeights[htlc.HtlcIndex]
|
||||
|
||||
// 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
|
||||
|
@ -1677,7 +1679,7 @@ func (lc *LightningChannel) restoreStateLogs(
|
|||
htlc.addCommitHeightLocal = outgoingLocalAddHeights[htlc.HtlcIndex]
|
||||
|
||||
// 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
|
||||
|
@ -1722,7 +1724,7 @@ func (lc *LightningChannel) restorePendingRemoteUpdates(
|
|||
logUpdate := logUpdate
|
||||
|
||||
payDesc, err := lc.remoteLogUpdateToPayDesc(
|
||||
&logUpdate, lc.localUpdateLog, localCommitmentHeight,
|
||||
&logUpdate, lc.updateLogs.Local, localCommitmentHeight,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -1732,7 +1734,7 @@ func (lc *LightningChannel) restorePendingRemoteUpdates(
|
|||
|
||||
// Sanity check that we are not restoring a remote log update
|
||||
// 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 "+
|
||||
"unsigned remote update: log_index=%v",
|
||||
logIdx)
|
||||
|
@ -1773,15 +1775,17 @@ func (lc *LightningChannel) restorePendingRemoteUpdates(
|
|||
payDesc.removeCommitHeightRemote = height
|
||||
}
|
||||
|
||||
lc.remoteUpdateLog.restoreUpdate(payDesc)
|
||||
lc.updateLogs.Remote.restoreUpdate(payDesc)
|
||||
|
||||
default:
|
||||
if heightSet {
|
||||
payDesc.removeCommitHeightRemote = height
|
||||
}
|
||||
|
||||
lc.remoteUpdateLog.restoreUpdate(payDesc)
|
||||
lc.localUpdateLog.markHtlcModified(payDesc.ParentIndex)
|
||||
lc.updateLogs.Remote.restoreUpdate(payDesc)
|
||||
lc.updateLogs.Local.markHtlcModified(
|
||||
payDesc.ParentIndex,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1800,20 +1804,23 @@ func (lc *LightningChannel) restorePeerLocalUpdates(updates []channeldb.LogUpdat
|
|||
logUpdate := logUpdate
|
||||
|
||||
payDesc, err := lc.localLogUpdateToPayDesc(
|
||||
&logUpdate, lc.remoteUpdateLog, remoteCommitmentHeight,
|
||||
&logUpdate, lc.updateLogs.Remote,
|
||||
remoteCommitmentHeight,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
lc.localUpdateLog.restoreUpdate(payDesc)
|
||||
lc.updateLogs.Local.restoreUpdate(payDesc)
|
||||
|
||||
// Since Add updates are not stored and FeeUpdates don't have a
|
||||
// corresponding entry in the remote update log, we only need to
|
||||
// mark the htlc as modified if the update was Settle, Fail, or
|
||||
// MalformedFail.
|
||||
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
|
||||
|
||||
payDesc, err := lc.logUpdateToPayDesc(
|
||||
&logUpdate, lc.remoteUpdateLog, pendingHeight,
|
||||
&logUpdate, lc.updateLogs.Remote, pendingHeight,
|
||||
chainfee.SatPerKWeight(pendingCommit.FeePerKw),
|
||||
pendingRemoteKeys,
|
||||
lc.channelState.RemoteChanCfg.DustLimit,
|
||||
|
@ -1862,9 +1869,9 @@ func (lc *LightningChannel) restorePendingLocalUpdates(
|
|||
// updates, so they will be unset. To account for this we set
|
||||
// them to to current update log index.
|
||||
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 "+
|
||||
"pendingRemoteCommitDiff without logIndex, "+
|
||||
"using %v", payDesc.LogIndex)
|
||||
|
@ -1872,10 +1879,10 @@ func (lc *LightningChannel) restorePendingLocalUpdates(
|
|||
|
||||
// At this point the restored update's logIndex must be equal
|
||||
// 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: "+
|
||||
"%v vs %v", payDesc.LogIndex,
|
||||
lc.localUpdateLog.logIndex))
|
||||
lc.updateLogs.Local.logIndex))
|
||||
}
|
||||
|
||||
switch payDesc.EntryType {
|
||||
|
@ -1885,21 +1892,25 @@ func (lc *LightningChannel) restorePendingLocalUpdates(
|
|||
// panic to catch this.
|
||||
// TODO(halseth): remove when cause of htlc entry bug
|
||||
// is found.
|
||||
if payDesc.HtlcIndex != lc.localUpdateLog.htlcCounter {
|
||||
if payDesc.HtlcIndex !=
|
||||
lc.updateLogs.Local.htlcCounter {
|
||||
|
||||
panic(fmt.Sprintf("htlc index mismatch: "+
|
||||
"%v vs %v", payDesc.HtlcIndex,
|
||||
lc.localUpdateLog.htlcCounter))
|
||||
lc.updateLogs.Local.htlcCounter))
|
||||
}
|
||||
|
||||
lc.localUpdateLog.appendHtlc(payDesc)
|
||||
lc.updateLogs.Local.appendHtlc(payDesc)
|
||||
|
||||
case FeeUpdate:
|
||||
lc.localUpdateLog.appendUpdate(payDesc)
|
||||
lc.updateLogs.Local.appendUpdate(payDesc)
|
||||
|
||||
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 {
|
||||
|
||||
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
|
||||
|
||||
// This HTLC is active from this point-of-view iff the log
|
||||
|
@ -2629,7 +2640,7 @@ func (lc *LightningChannel) fetchHTLCView(theirLogIndex,
|
|||
}
|
||||
|
||||
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
|
||||
|
||||
// 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() {
|
||||
updateLog = lc.remoteUpdateLog
|
||||
updateLog = lc.updateLogs.Remote
|
||||
logName = "remote"
|
||||
} else {
|
||||
updateLog = lc.localUpdateLog
|
||||
updateLog = lc.updateLogs.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
|
||||
// set of items we need to retransmit if we reconnect and find that
|
||||
// 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
|
||||
|
||||
// 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
|
||||
// remote party expects.
|
||||
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
|
||||
|
||||
// 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
|
||||
// minimum requirement.
|
||||
err := lc.validateCommitmentSanity(
|
||||
remoteACKedIndex, lc.localUpdateLog.logIndex, lntypes.Remote,
|
||||
remoteACKedIndex, lc.updateLogs.Local.logIndex, lntypes.Remote,
|
||||
NoBuffer, nil, 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
|
||||
// node's changes up to the last change we've ACK'd.
|
||||
newCommitView, err := lc.fetchCommitmentView(
|
||||
lntypes.Remote, lc.localUpdateLog.logIndex,
|
||||
lc.localUpdateLog.htlcCounter, remoteACKedIndex,
|
||||
lntypes.Remote, lc.updateLogs.Local.logIndex,
|
||||
lc.updateLogs.Local.htlcCounter, remoteACKedIndex,
|
||||
remoteHtlcIndex, keyRing,
|
||||
)
|
||||
if err != nil {
|
||||
|
@ -4016,7 +4027,7 @@ func (lc *LightningChannel) SignNextCommitment() (*NewCommitState, error) {
|
|||
lc.log.Tracef("extending remote chain to height %v, "+
|
||||
"local_log=%v, remote_log=%v",
|
||||
newCommitView.height,
|
||||
lc.localUpdateLog.logIndex, remoteACKedIndex)
|
||||
lc.updateLogs.Local.logIndex, remoteACKedIndex)
|
||||
|
||||
lc.log.Tracef("remote chain: our_balance=%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
|
||||
// commit-sig).
|
||||
err := lc.validateCommitmentSanity(
|
||||
lc.remoteUpdateLog.logIndex, localACKedIndex, lntypes.Local,
|
||||
lc.updateLogs.Remote.logIndex, localACKedIndex, lntypes.Local,
|
||||
NoBuffer, nil, 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.
|
||||
localCommitmentView, err := lc.fetchCommitmentView(
|
||||
lntypes.Local, localACKedIndex, localHtlcIndex,
|
||||
lc.remoteUpdateLog.logIndex, lc.remoteUpdateLog.htlcCounter,
|
||||
lc.updateLogs.Remote.logIndex, lc.updateLogs.Remote.htlcCounter,
|
||||
keyRing,
|
||||
)
|
||||
if err != nil {
|
||||
|
@ -5021,7 +5032,7 @@ func (lc *LightningChannel) ReceiveNewCommitment(commitSigs *CommitSigs) error {
|
|||
lc.log.Tracef("extending local chain to height %v, "+
|
||||
"local_log=%v, remote_log=%v",
|
||||
localCommitmentView.height,
|
||||
localACKedIndex, lc.remoteUpdateLog.logIndex)
|
||||
localACKedIndex, lc.updateLogs.Remote.logIndex)
|
||||
|
||||
lc.log.Tracef("local chain: our_balance=%v, "+
|
||||
"their_balance=%v, commit_tx: %v",
|
||||
|
@ -5175,7 +5186,11 @@ func (lc *LightningChannel) ReceiveNewCommitment(commitSigs *CommitSigs) error {
|
|||
}
|
||||
|
||||
var txBytes bytes.Buffer
|
||||
localCommitTx.Serialize(&txBytes)
|
||||
err = localCommitTx.Serialize(&txBytes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return &InvalidHtlcSigError{
|
||||
commitHeight: nextHeight,
|
||||
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
|
||||
// not in sync with our remote commitment tx.
|
||||
localUpdatesPending = lc.localUpdateLog.logIndex !=
|
||||
localUpdatesPending = lc.updateLogs.Local.logIndex !=
|
||||
lastRemoteCommit.ourMessageIndex
|
||||
|
||||
// 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
|
||||
// updates to their remote tx pending for which they haven't
|
||||
// signed yet.
|
||||
localUpdatesPending = lc.remoteUpdateLog.logIndex !=
|
||||
localUpdatesPending = lc.updateLogs.Remote.logIndex !=
|
||||
lastLocalCommit.theirMessageIndex
|
||||
|
||||
// There are remote updates pending (remote updates from the
|
||||
|
@ -5341,7 +5356,7 @@ func (lc *LightningChannel) PendingLocalUpdateCount() uint64 {
|
|||
|
||||
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
|
||||
|
@ -5477,7 +5492,7 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
|
|||
)
|
||||
|
||||
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
|
||||
|
||||
// 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
|
||||
// from the PoV of both commitment chains.
|
||||
compactLogs(
|
||||
lc.localUpdateLog, lc.remoteUpdateLog, localChainTail,
|
||||
lc.updateLogs.Local, lc.updateLogs.Remote, localChainTail,
|
||||
remoteChainTail,
|
||||
)
|
||||
|
||||
|
@ -5774,7 +5789,7 @@ func (lc *LightningChannel) addHTLC(htlc *lnwire.UpdateAddHTLC,
|
|||
return 0, err
|
||||
}
|
||||
|
||||
lc.localUpdateLog.appendHtlc(pd)
|
||||
lc.updateLogs.Local.appendHtlc(pd)
|
||||
|
||||
return pd.HtlcIndex, nil
|
||||
}
|
||||
|
@ -5807,7 +5822,7 @@ func (lc *LightningChannel) GetDustSum(whoseCommit lntypes.ChannelParty,
|
|||
feeRate = dryRunFee.UnwrapOr(feeRate)
|
||||
|
||||
// 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
|
||||
if pd.EntryType != Add {
|
||||
continue
|
||||
|
@ -5826,7 +5841,7 @@ func (lc *LightningChannel) GetDustSum(whoseCommit lntypes.ChannelParty,
|
|||
}
|
||||
|
||||
// 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
|
||||
if pd.EntryType != Add {
|
||||
continue
|
||||
|
@ -5906,8 +5921,8 @@ func (lc *LightningChannel) htlcAddDescriptor(htlc *lnwire.UpdateAddHTLC,
|
|||
RHash: PaymentHash(htlc.PaymentHash),
|
||||
Timeout: htlc.Expiry,
|
||||
Amount: htlc.Amount,
|
||||
LogIndex: lc.localUpdateLog.logIndex,
|
||||
HtlcIndex: lc.localUpdateLog.htlcCounter,
|
||||
LogIndex: lc.updateLogs.Local.logIndex,
|
||||
HtlcIndex: lc.updateLogs.Local.htlcCounter,
|
||||
OnionBlob: htlc.OnionBlob[:],
|
||||
OpenCircuitKey: openKey,
|
||||
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
|
||||
// commitment transaction without violation any of the constraints.
|
||||
err := lc.validateCommitmentSanity(
|
||||
remoteACKedIndex, lc.localUpdateLog.logIndex, lntypes.Remote,
|
||||
remoteACKedIndex, lc.updateLogs.Local.logIndex, lntypes.Remote,
|
||||
buffer, pd, 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
|
||||
// possible for us to add the HTLC.
|
||||
err = lc.validateCommitmentSanity(
|
||||
lc.remoteUpdateLog.logIndex, lc.localUpdateLog.logIndex,
|
||||
lc.updateLogs.Remote.logIndex, lc.updateLogs.Local.logIndex,
|
||||
lntypes.Local, buffer, pd, nil,
|
||||
)
|
||||
if err != nil {
|
||||
|
@ -5960,9 +5975,9 @@ func (lc *LightningChannel) ReceiveHTLC(htlc *lnwire.UpdateAddHTLC) (uint64,
|
|||
lc.Lock()
|
||||
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 "+
|
||||
"ID %d", htlc.ID, lc.remoteUpdateLog.htlcCounter)
|
||||
"ID %d", htlc.ID, lc.updateLogs.Remote.htlcCounter)
|
||||
}
|
||||
|
||||
pd := &PaymentDescriptor{
|
||||
|
@ -5970,8 +5985,8 @@ func (lc *LightningChannel) ReceiveHTLC(htlc *lnwire.UpdateAddHTLC) (uint64,
|
|||
RHash: PaymentHash(htlc.PaymentHash),
|
||||
Timeout: htlc.Expiry,
|
||||
Amount: htlc.Amount,
|
||||
LogIndex: lc.remoteUpdateLog.logIndex,
|
||||
HtlcIndex: lc.remoteUpdateLog.htlcCounter,
|
||||
LogIndex: lc.updateLogs.Remote.logIndex,
|
||||
HtlcIndex: lc.updateLogs.Remote.htlcCounter,
|
||||
OnionBlob: htlc.OnionBlob[:],
|
||||
BlindingPoint: htlc.BlindingPoint,
|
||||
// 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
|
||||
// reject ADDs already sent by the peer.
|
||||
err := lc.validateCommitmentSanity(
|
||||
lc.remoteUpdateLog.logIndex, localACKedIndex, lntypes.Local,
|
||||
lc.updateLogs.Remote.logIndex, localACKedIndex, lntypes.Local,
|
||||
NoBuffer, nil, pd,
|
||||
)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
lc.remoteUpdateLog.appendHtlc(pd)
|
||||
lc.updateLogs.Remote.appendHtlc(pd)
|
||||
|
||||
return pd.HtlcIndex, nil
|
||||
}
|
||||
|
@ -6031,7 +6046,7 @@ func (lc *LightningChannel) SettleHTLC(preimage [32]byte,
|
|||
lc.Lock()
|
||||
defer lc.Unlock()
|
||||
|
||||
htlc := lc.remoteUpdateLog.lookupHtlc(htlcIndex)
|
||||
htlc := lc.updateLogs.Remote.lookupHtlc(htlcIndex)
|
||||
if htlc == nil {
|
||||
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
|
||||
// preimage matches, we'll ensure that we haven't already attempted to
|
||||
// modify the HTLC.
|
||||
if lc.remoteUpdateLog.htlcHasModification(htlcIndex) {
|
||||
if lc.updateLogs.Remote.htlcHasModification(htlcIndex) {
|
||||
return ErrHtlcIndexAlreadySettled(htlcIndex)
|
||||
}
|
||||
|
||||
|
@ -6050,7 +6065,7 @@ func (lc *LightningChannel) SettleHTLC(preimage [32]byte,
|
|||
pd := &PaymentDescriptor{
|
||||
Amount: htlc.Amount,
|
||||
RPreimage: preimage,
|
||||
LogIndex: lc.localUpdateLog.logIndex,
|
||||
LogIndex: lc.updateLogs.Local.logIndex,
|
||||
ParentIndex: htlcIndex,
|
||||
EntryType: Settle,
|
||||
SourceRef: sourceRef,
|
||||
|
@ -6058,12 +6073,12 @@ func (lc *LightningChannel) SettleHTLC(preimage [32]byte,
|
|||
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
|
||||
// modified to prevent ourselves from accidentally attempting a
|
||||
// duplicate settle.
|
||||
lc.remoteUpdateLog.markHtlcModified(htlcIndex)
|
||||
lc.updateLogs.Remote.markHtlcModified(htlcIndex)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -6076,7 +6091,7 @@ func (lc *LightningChannel) ReceiveHTLCSettle(preimage [32]byte, htlcIndex uint6
|
|||
lc.Lock()
|
||||
defer lc.Unlock()
|
||||
|
||||
htlc := lc.localUpdateLog.lookupHtlc(htlcIndex)
|
||||
htlc := lc.updateLogs.Local.lookupHtlc(htlcIndex)
|
||||
if htlc == nil {
|
||||
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
|
||||
// preimage matches, we'll ensure that they haven't already attempted
|
||||
// to modify the HTLC.
|
||||
if lc.localUpdateLog.htlcHasModification(htlcIndex) {
|
||||
if lc.updateLogs.Local.htlcHasModification(htlcIndex) {
|
||||
return ErrHtlcIndexAlreadySettled(htlcIndex)
|
||||
}
|
||||
|
||||
|
@ -6097,16 +6112,16 @@ func (lc *LightningChannel) ReceiveHTLCSettle(preimage [32]byte, htlcIndex uint6
|
|||
RPreimage: preimage,
|
||||
ParentIndex: htlc.HtlcIndex,
|
||||
RHash: htlc.RHash,
|
||||
LogIndex: lc.remoteUpdateLog.logIndex,
|
||||
LogIndex: lc.updateLogs.Remote.logIndex,
|
||||
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
|
||||
// modified to prevent the remote party from accidentally attempting a
|
||||
// duplicate settle.
|
||||
lc.localUpdateLog.markHtlcModified(htlcIndex)
|
||||
lc.updateLogs.Local.markHtlcModified(htlcIndex)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -6142,14 +6157,14 @@ func (lc *LightningChannel) FailHTLC(htlcIndex uint64, reason []byte,
|
|||
lc.Lock()
|
||||
defer lc.Unlock()
|
||||
|
||||
htlc := lc.remoteUpdateLog.lookupHtlc(htlcIndex)
|
||||
htlc := lc.updateLogs.Remote.lookupHtlc(htlcIndex)
|
||||
if htlc == nil {
|
||||
return ErrUnknownHtlcIndex{lc.ShortChanID(), htlcIndex}
|
||||
}
|
||||
|
||||
// Now that we know the HTLC exists, we'll ensure that we haven't
|
||||
// already attempted to fail the HTLC.
|
||||
if lc.remoteUpdateLog.htlcHasModification(htlcIndex) {
|
||||
if lc.updateLogs.Remote.htlcHasModification(htlcIndex) {
|
||||
return ErrHtlcIndexAlreadyFailed(htlcIndex)
|
||||
}
|
||||
|
||||
|
@ -6157,7 +6172,7 @@ func (lc *LightningChannel) FailHTLC(htlcIndex uint64, reason []byte,
|
|||
Amount: htlc.Amount,
|
||||
RHash: htlc.RHash,
|
||||
ParentIndex: htlcIndex,
|
||||
LogIndex: lc.localUpdateLog.logIndex,
|
||||
LogIndex: lc.updateLogs.Local.logIndex,
|
||||
EntryType: Fail,
|
||||
FailReason: reason,
|
||||
SourceRef: sourceRef,
|
||||
|
@ -6165,12 +6180,12 @@ func (lc *LightningChannel) FailHTLC(htlcIndex uint64, reason []byte,
|
|||
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
|
||||
// modified to prevent ourselves from accidentally attempting a
|
||||
// duplicate fail.
|
||||
lc.remoteUpdateLog.markHtlcModified(htlcIndex)
|
||||
lc.updateLogs.Remote.markHtlcModified(htlcIndex)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -6192,14 +6207,14 @@ func (lc *LightningChannel) MalformedFailHTLC(htlcIndex uint64,
|
|||
lc.Lock()
|
||||
defer lc.Unlock()
|
||||
|
||||
htlc := lc.remoteUpdateLog.lookupHtlc(htlcIndex)
|
||||
htlc := lc.updateLogs.Remote.lookupHtlc(htlcIndex)
|
||||
if htlc == nil {
|
||||
return ErrUnknownHtlcIndex{lc.ShortChanID(), htlcIndex}
|
||||
}
|
||||
|
||||
// Now that we know the HTLC exists, we'll ensure that we haven't
|
||||
// already attempted to fail the HTLC.
|
||||
if lc.remoteUpdateLog.htlcHasModification(htlcIndex) {
|
||||
if lc.updateLogs.Remote.htlcHasModification(htlcIndex) {
|
||||
return ErrHtlcIndexAlreadyFailed(htlcIndex)
|
||||
}
|
||||
|
||||
|
@ -6207,19 +6222,19 @@ func (lc *LightningChannel) MalformedFailHTLC(htlcIndex uint64,
|
|||
Amount: htlc.Amount,
|
||||
RHash: htlc.RHash,
|
||||
ParentIndex: htlcIndex,
|
||||
LogIndex: lc.localUpdateLog.logIndex,
|
||||
LogIndex: lc.updateLogs.Local.logIndex,
|
||||
EntryType: MalformedFail,
|
||||
FailCode: failCode,
|
||||
ShaOnionBlob: shaOnionBlob,
|
||||
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
|
||||
// modified to prevent ourselves from accidentally attempting a
|
||||
// duplicate fail.
|
||||
lc.remoteUpdateLog.markHtlcModified(htlcIndex)
|
||||
lc.updateLogs.Remote.markHtlcModified(htlcIndex)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -6234,14 +6249,14 @@ func (lc *LightningChannel) ReceiveFailHTLC(htlcIndex uint64, reason []byte,
|
|||
lc.Lock()
|
||||
defer lc.Unlock()
|
||||
|
||||
htlc := lc.localUpdateLog.lookupHtlc(htlcIndex)
|
||||
htlc := lc.updateLogs.Local.lookupHtlc(htlcIndex)
|
||||
if htlc == nil {
|
||||
return ErrUnknownHtlcIndex{lc.ShortChanID(), htlcIndex}
|
||||
}
|
||||
|
||||
// Now that we know the HTLC exists, we'll ensure that they haven't
|
||||
// already attempted to fail the HTLC.
|
||||
if lc.localUpdateLog.htlcHasModification(htlcIndex) {
|
||||
if lc.updateLogs.Local.htlcHasModification(htlcIndex) {
|
||||
return ErrHtlcIndexAlreadyFailed(htlcIndex)
|
||||
}
|
||||
|
||||
|
@ -6249,17 +6264,17 @@ func (lc *LightningChannel) ReceiveFailHTLC(htlcIndex uint64, reason []byte,
|
|||
Amount: htlc.Amount,
|
||||
RHash: htlc.RHash,
|
||||
ParentIndex: htlc.HtlcIndex,
|
||||
LogIndex: lc.remoteUpdateLog.logIndex,
|
||||
LogIndex: lc.updateLogs.Remote.logIndex,
|
||||
EntryType: Fail,
|
||||
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
|
||||
// modified to prevent ourselves from accidentally attempting a
|
||||
// duplicate fail.
|
||||
lc.localUpdateLog.markHtlcModified(htlcIndex)
|
||||
lc.updateLogs.Local.markHtlcModified(htlcIndex)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -8127,7 +8142,7 @@ func (lc *LightningChannel) availableBalance(
|
|||
// ACKed.
|
||||
remoteACKedIndex := lc.commitChains.Local.tip().theirMessageIndex
|
||||
htlcView := lc.fetchHTLCView(remoteACKedIndex,
|
||||
lc.localUpdateLog.logIndex)
|
||||
lc.updateLogs.Local.logIndex)
|
||||
|
||||
// Calculate our available balance from our local commitment.
|
||||
// TODO(halseth): could reuse parts validateCommitmentSanity to do this
|
||||
|
@ -8359,12 +8374,12 @@ func (lc *LightningChannel) UpdateFee(feePerKw chainfee.SatPerKWeight) error {
|
|||
}
|
||||
|
||||
pd := &PaymentDescriptor{
|
||||
LogIndex: lc.localUpdateLog.logIndex,
|
||||
LogIndex: lc.updateLogs.Local.logIndex,
|
||||
Amount: lnwire.NewMSatFromSatoshis(btcutil.Amount(feePerKw)),
|
||||
EntryType: FeeUpdate,
|
||||
}
|
||||
|
||||
lc.localUpdateLog.appendUpdate(pd)
|
||||
lc.updateLogs.Local.appendUpdate(pd)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -8383,8 +8398,8 @@ func (lc *LightningChannel) CommitFeeTotalAt(
|
|||
|
||||
// We want to grab every update in both update logs to calculate the
|
||||
// commitment fees in the worst-case with this fee-rate.
|
||||
localIdx := lc.localUpdateLog.logIndex
|
||||
remoteIdx := lc.remoteUpdateLog.logIndex
|
||||
localIdx := lc.updateLogs.Local.logIndex
|
||||
remoteIdx := lc.updateLogs.Remote.logIndex
|
||||
|
||||
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?
|
||||
pd := &PaymentDescriptor{
|
||||
LogIndex: lc.remoteUpdateLog.logIndex,
|
||||
LogIndex: lc.updateLogs.Remote.logIndex,
|
||||
Amount: lnwire.NewMSatFromSatoshis(btcutil.Amount(feePerKw)),
|
||||
EntryType: FeeUpdate,
|
||||
}
|
||||
|
||||
lc.remoteUpdateLog.appendUpdate(pd)
|
||||
lc.updateLogs.Remote.appendUpdate(pd)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -8905,7 +8920,7 @@ func (lc *LightningChannel) unsignedLocalUpdates(remoteMessageIndex,
|
|||
localMessageIndex uint64, chanID lnwire.ChannelID) []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
|
||||
|
||||
// We don't save add updates as they are restored from the
|
||||
|
|
|
@ -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 HTLC should have been removed once both sides receive the
|
||||
// revocation.
|
||||
if aliceChannel.localUpdateLog.Len() != 0 {
|
||||
if aliceChannel.updateLogs.Local.Len() != 0 {
|
||||
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 "+
|
||||
"entries instead", aliceChannel.remoteUpdateLog.Len())
|
||||
"entries instead", aliceChannel.updateLogs.Remote.Len())
|
||||
}
|
||||
if len(aliceChannel.localUpdateLog.updateIndex) != 0 {
|
||||
t.Fatalf("alice's local log index not cleared, should be empty but "+
|
||||
"has %v entries", len(aliceChannel.localUpdateLog.updateIndex))
|
||||
if len(aliceChannel.updateLogs.Local.updateIndex) != 0 {
|
||||
t.Fatalf("alice's local log index not cleared, should be "+
|
||||
"empty but has %v entries",
|
||||
len(aliceChannel.updateLogs.Local.updateIndex))
|
||||
}
|
||||
if len(aliceChannel.remoteUpdateLog.updateIndex) != 0 {
|
||||
t.Fatalf("alice's remote log index not cleared, should be empty but "+
|
||||
"has %v entries", len(aliceChannel.remoteUpdateLog.updateIndex))
|
||||
if len(aliceChannel.updateLogs.Remote.updateIndex) != 0 {
|
||||
t.Fatalf("alice's remote log index not cleared, should be "+
|
||||
"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
|
||||
// in the update logs.
|
||||
assertNumLogUpdates := func(numAliceUpdates, numBobUpdates int) {
|
||||
if aliceChannel.localUpdateLog.Len() != numAliceUpdates {
|
||||
if aliceChannel.updateLogs.Local.Len() != numAliceUpdates {
|
||||
t.Fatalf("expected %d local updates, found %d",
|
||||
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",
|
||||
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",
|
||||
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",
|
||||
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
|
||||
// should now be identical other than the height the HTLCs were added.
|
||||
if aliceChannel.localUpdateLog.logIndex !=
|
||||
aliceChannelNew.localUpdateLog.logIndex {
|
||||
if aliceChannel.updateLogs.Local.logIndex !=
|
||||
aliceChannelNew.updateLogs.Local.logIndex {
|
||||
|
||||
t.Fatalf("alice log counter: expected %v, got %v",
|
||||
aliceChannel.localUpdateLog.logIndex,
|
||||
aliceChannelNew.localUpdateLog.logIndex)
|
||||
aliceChannel.updateLogs.Local.logIndex,
|
||||
aliceChannelNew.updateLogs.Local.logIndex)
|
||||
}
|
||||
if aliceChannel.remoteUpdateLog.logIndex !=
|
||||
aliceChannelNew.remoteUpdateLog.logIndex {
|
||||
if aliceChannel.updateLogs.Remote.logIndex !=
|
||||
aliceChannelNew.updateLogs.Remote.logIndex {
|
||||
|
||||
t.Fatalf("alice log counter: expected %v, got %v",
|
||||
aliceChannel.remoteUpdateLog.logIndex,
|
||||
aliceChannelNew.remoteUpdateLog.logIndex)
|
||||
aliceChannel.updateLogs.Remote.logIndex,
|
||||
aliceChannelNew.updateLogs.Remote.logIndex)
|
||||
}
|
||||
if aliceChannel.localUpdateLog.Len() !=
|
||||
aliceChannelNew.localUpdateLog.Len() {
|
||||
if aliceChannel.updateLogs.Local.Len() !=
|
||||
aliceChannelNew.updateLogs.Local.Len() {
|
||||
|
||||
t.Fatalf("alice log len: expected %v, got %v",
|
||||
aliceChannel.localUpdateLog.Len(),
|
||||
aliceChannelNew.localUpdateLog.Len())
|
||||
aliceChannel.updateLogs.Local.Len(),
|
||||
aliceChannelNew.updateLogs.Local.Len())
|
||||
}
|
||||
if aliceChannel.remoteUpdateLog.Len() !=
|
||||
aliceChannelNew.remoteUpdateLog.Len() {
|
||||
if aliceChannel.updateLogs.Remote.Len() !=
|
||||
aliceChannelNew.updateLogs.Remote.Len() {
|
||||
|
||||
t.Fatalf("alice log len: expected %v, got %v",
|
||||
aliceChannel.remoteUpdateLog.Len(),
|
||||
aliceChannelNew.remoteUpdateLog.Len())
|
||||
aliceChannel.updateLogs.Remote.Len(),
|
||||
aliceChannelNew.updateLogs.Remote.Len())
|
||||
}
|
||||
if bobChannel.localUpdateLog.logIndex !=
|
||||
bobChannelNew.localUpdateLog.logIndex {
|
||||
if bobChannel.updateLogs.Local.logIndex !=
|
||||
bobChannelNew.updateLogs.Local.logIndex {
|
||||
|
||||
t.Fatalf("bob log counter: expected %v, got %v",
|
||||
bobChannel.localUpdateLog.logIndex,
|
||||
bobChannelNew.localUpdateLog.logIndex)
|
||||
bobChannel.updateLogs.Local.logIndex,
|
||||
bobChannelNew.updateLogs.Local.logIndex)
|
||||
}
|
||||
if bobChannel.remoteUpdateLog.logIndex !=
|
||||
bobChannelNew.remoteUpdateLog.logIndex {
|
||||
if bobChannel.updateLogs.Remote.logIndex !=
|
||||
bobChannelNew.updateLogs.Remote.logIndex {
|
||||
|
||||
t.Fatalf("bob log counter: expected %v, got %v",
|
||||
bobChannel.remoteUpdateLog.logIndex,
|
||||
bobChannelNew.remoteUpdateLog.logIndex)
|
||||
bobChannel.updateLogs.Remote.logIndex,
|
||||
bobChannelNew.updateLogs.Remote.logIndex)
|
||||
}
|
||||
if bobChannel.localUpdateLog.Len() !=
|
||||
bobChannelNew.localUpdateLog.Len() {
|
||||
if bobChannel.updateLogs.Local.Len() !=
|
||||
bobChannelNew.updateLogs.Local.Len() {
|
||||
|
||||
t.Fatalf("bob log len: expected %v, got %v",
|
||||
bobChannel.localUpdateLog.Len(),
|
||||
bobChannelNew.localUpdateLog.Len())
|
||||
bobChannel.updateLogs.Local.Len(),
|
||||
bobChannelNew.updateLogs.Local.Len())
|
||||
}
|
||||
if bobChannel.remoteUpdateLog.Len() !=
|
||||
bobChannelNew.remoteUpdateLog.Len() {
|
||||
if bobChannel.updateLogs.Remote.Len() !=
|
||||
bobChannelNew.updateLogs.Remote.Len() {
|
||||
|
||||
t.Fatalf("bob log len: expected %v, got %v",
|
||||
bobChannel.remoteUpdateLog.Len(),
|
||||
bobChannelNew.remoteUpdateLog.Len())
|
||||
bobChannel.updateLogs.Remote.Len(),
|
||||
bobChannelNew.updateLogs.Remote.Len())
|
||||
}
|
||||
|
||||
// TODO(roasbeef): expand test to also ensure state revocation log has
|
||||
// proper pk scripts
|
||||
|
||||
// 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
|
||||
restoredHtlc := aliceChannelNew.localUpdateLog.lookupHtlc(htlc.HtlcIndex)
|
||||
restoredHtlc := aliceChannelNew.updateLogs.Local.lookupHtlc(
|
||||
htlc.HtlcIndex,
|
||||
)
|
||||
if !bytes.Equal(htlc.ourPkScript, restoredHtlc.ourPkScript) {
|
||||
t.Fatalf("alice ourPkScript in ourLog: expected %X, got %X",
|
||||
htlc.ourPkScript[:5], restoredHtlc.ourPkScript[:5])
|
||||
|
@ -1933,9 +1945,11 @@ func TestStateUpdatePersistence(t *testing.T) {
|
|||
htlc.theirPkScript[:5], restoredHtlc.theirPkScript[:5])
|
||||
}
|
||||
}
|
||||
for _, entry := range aliceChannel.remoteUpdateLog.htlcIndex {
|
||||
for _, entry := range aliceChannel.updateLogs.Remote.htlcIndex {
|
||||
htlc := entry.Value
|
||||
restoredHtlc := aliceChannelNew.remoteUpdateLog.lookupHtlc(htlc.HtlcIndex)
|
||||
restoredHtlc := aliceChannelNew.updateLogs.Remote.lookupHtlc(
|
||||
htlc.HtlcIndex,
|
||||
)
|
||||
if !bytes.Equal(htlc.ourPkScript, restoredHtlc.ourPkScript) {
|
||||
t.Fatalf("alice ourPkScript in theirLog: expected %X, got %X",
|
||||
htlc.ourPkScript[:5], restoredHtlc.ourPkScript[:5])
|
||||
|
@ -1945,9 +1959,11 @@ func TestStateUpdatePersistence(t *testing.T) {
|
|||
htlc.theirPkScript[:5], restoredHtlc.theirPkScript[:5])
|
||||
}
|
||||
}
|
||||
for _, entry := range bobChannel.localUpdateLog.htlcIndex {
|
||||
for _, entry := range bobChannel.updateLogs.Local.htlcIndex {
|
||||
htlc := entry.Value
|
||||
restoredHtlc := bobChannelNew.localUpdateLog.lookupHtlc(htlc.HtlcIndex)
|
||||
restoredHtlc := bobChannelNew.updateLogs.Local.lookupHtlc(
|
||||
htlc.HtlcIndex,
|
||||
)
|
||||
if !bytes.Equal(htlc.ourPkScript, restoredHtlc.ourPkScript) {
|
||||
t.Fatalf("bob ourPkScript in ourLog: expected %X, got %X",
|
||||
htlc.ourPkScript[:5], restoredHtlc.ourPkScript[:5])
|
||||
|
@ -1957,9 +1973,11 @@ func TestStateUpdatePersistence(t *testing.T) {
|
|||
htlc.theirPkScript[:5], restoredHtlc.theirPkScript[:5])
|
||||
}
|
||||
}
|
||||
for _, entry := range bobChannel.remoteUpdateLog.htlcIndex {
|
||||
for _, entry := range bobChannel.updateLogs.Remote.htlcIndex {
|
||||
htlc := entry.Value
|
||||
restoredHtlc := bobChannelNew.remoteUpdateLog.lookupHtlc(htlc.HtlcIndex)
|
||||
restoredHtlc := bobChannelNew.updateLogs.Remote.lookupHtlc(
|
||||
htlc.HtlcIndex,
|
||||
)
|
||||
if !bytes.Equal(htlc.ourPkScript, restoredHtlc.ourPkScript) {
|
||||
t.Fatalf("bob ourPkScript in theirLog: expected %X, got %X",
|
||||
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
|
||||
// should detect Bob's remote log counter as being 3 and his HTLC index
|
||||
// 3 as well.
|
||||
if aliceChannel.localUpdateLog.logIndex != 4 {
|
||||
if aliceChannel.updateLogs.Local.logIndex != 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,
|
||||
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,
|
||||
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,
|
||||
aliceChannel.localUpdateLog.htlcCounter)
|
||||
aliceChannel.updateLogs.Local.htlcCounter)
|
||||
}
|
||||
|
||||
// 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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
bobChannel.localUpdateLog.htlcCounter)
|
||||
bobChannel.updateLogs.Local.htlcCounter)
|
||||
}
|
||||
|
||||
// We'll conclude the test by having Bob settle Alice's HTLC, then
|
||||
|
@ -4507,7 +4525,7 @@ func TestFeeUpdateOldDiskFormat(t *testing.T) {
|
|||
t.Helper()
|
||||
|
||||
expUpd := expFee + expAdd
|
||||
upd, fees := countLog(aliceChannel.localUpdateLog)
|
||||
upd, fees := countLog(aliceChannel.updateLogs.Local)
|
||||
if upd != expUpd {
|
||||
t.Fatalf("expected %d updates, found %d in Alice's "+
|
||||
"log", expUpd, upd)
|
||||
|
@ -4516,7 +4534,7 @@ func TestFeeUpdateOldDiskFormat(t *testing.T) {
|
|||
t.Fatalf("expected %d fee updates, found %d in "+
|
||||
"Alice's log", expFee, fees)
|
||||
}
|
||||
upd, fees = countLog(bobChannel.remoteUpdateLog)
|
||||
upd, fees = countLog(bobChannel.updateLogs.Remote)
|
||||
if upd != expUpd {
|
||||
t.Fatalf("expected %d updates, found %d in Bob's log",
|
||||
expUpd, upd)
|
||||
|
@ -5215,7 +5233,7 @@ func TestChanCommitWeightDustHtlcs(t *testing.T) {
|
|||
lc.commitChains.Local.tip().theirMessageIndex
|
||||
|
||||
htlcView := lc.fetchHTLCView(remoteACKedIndex,
|
||||
lc.localUpdateLog.logIndex)
|
||||
lc.updateLogs.Local.logIndex)
|
||||
|
||||
_, w := lc.availableCommitmentBalance(
|
||||
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
|
||||
// they all got restored properly.
|
||||
err = compareLogs(aliceChannel.localUpdateLog,
|
||||
newAliceChannel.localUpdateLog)
|
||||
err = compareLogs(aliceChannel.updateLogs.Local,
|
||||
newAliceChannel.updateLogs.Local)
|
||||
require.NoError(t, err, "alice local log not restored")
|
||||
|
||||
err = compareLogs(aliceChannel.remoteUpdateLog,
|
||||
newAliceChannel.remoteUpdateLog)
|
||||
err = compareLogs(aliceChannel.updateLogs.Remote,
|
||||
newAliceChannel.updateLogs.Remote)
|
||||
require.NoError(t, err, "alice remote log not restored")
|
||||
|
||||
err = compareLogs(bobChannel.localUpdateLog,
|
||||
newBobChannel.localUpdateLog)
|
||||
err = compareLogs(bobChannel.updateLogs.Local,
|
||||
newBobChannel.updateLogs.Local)
|
||||
require.NoError(t, err, "bob local log not restored")
|
||||
|
||||
err = compareLogs(bobChannel.remoteUpdateLog,
|
||||
newBobChannel.remoteUpdateLog)
|
||||
err = compareLogs(bobChannel.updateLogs.Remote,
|
||||
newBobChannel.updateLogs.Remote)
|
||||
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.
|
||||
func assertInLogs(t *testing.T, channel *LightningChannel, numAddsLocal,
|
||||
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
|
||||
|
@ -6984,8 +7003,10 @@ func restoreAndAssert(t *testing.T, channel *LightningChannel, numAddsLocal,
|
|||
)
|
||||
require.NoError(t, err, "unable to create new channel")
|
||||
|
||||
assertInLog(t, newChannel.localUpdateLog, numAddsLocal, numFailsLocal)
|
||||
assertInLog(t, newChannel.remoteUpdateLog, numAddsRemote, numFailsRemote)
|
||||
assertInLog(t, newChannel.updateLogs.Local, numAddsLocal, numFailsLocal)
|
||||
assertInLog(
|
||||
t, newChannel.updateLogs.Remote, numAddsRemote, numFailsRemote,
|
||||
)
|
||||
}
|
||||
|
||||
// TestChannelRestoreUpdateLogsFailedHTLC runs through a scenario where an
|
||||
|
@ -7249,16 +7270,18 @@ func TestChannelRestoreCommitHeight(t *testing.T) {
|
|||
|
||||
var pd *PaymentDescriptor
|
||||
if remoteLog {
|
||||
if newChannel.localUpdateLog.lookupHtlc(htlcIndex) != nil {
|
||||
h := newChannel.updateLogs.Local.lookupHtlc(htlcIndex)
|
||||
if h != nil {
|
||||
t.Fatalf("htlc found in wrong log")
|
||||
}
|
||||
pd = newChannel.remoteUpdateLog.lookupHtlc(htlcIndex)
|
||||
pd = newChannel.updateLogs.Remote.lookupHtlc(htlcIndex)
|
||||
|
||||
} else {
|
||||
if newChannel.remoteUpdateLog.lookupHtlc(htlcIndex) != nil {
|
||||
h := newChannel.updateLogs.Remote.lookupHtlc(htlcIndex)
|
||||
if h != nil {
|
||||
t.Fatalf("htlc found in wrong log")
|
||||
}
|
||||
pd = newChannel.localUpdateLog.lookupHtlc(htlcIndex)
|
||||
pd = newChannel.updateLogs.Local.lookupHtlc(htlcIndex)
|
||||
}
|
||||
if pd == nil {
|
||||
t.Fatalf("htlc not found in log")
|
||||
|
@ -8196,16 +8219,18 @@ func TestFetchParent(t *testing.T) {
|
|||
// Create a lightning channel with newly initialized
|
||||
// local and remote logs.
|
||||
lc := LightningChannel{
|
||||
localUpdateLog: newUpdateLog(0, 0),
|
||||
remoteUpdateLog: newUpdateLog(0, 0),
|
||||
updateLogs: lntypes.Dual[*updateLog]{
|
||||
Local: newUpdateLog(0, 0),
|
||||
Remote: newUpdateLog(0, 0),
|
||||
},
|
||||
}
|
||||
|
||||
// Add the local and remote entries to update logs.
|
||||
for _, entry := range test.localEntries {
|
||||
lc.localUpdateLog.appendHtlc(entry)
|
||||
lc.updateLogs.Local.appendHtlc(entry)
|
||||
}
|
||||
for _, entry := range test.remoteEntries {
|
||||
lc.remoteUpdateLog.appendHtlc(entry)
|
||||
lc.updateLogs.Remote.appendHtlc(entry)
|
||||
}
|
||||
|
||||
parent, err := lc.fetchParent(
|
||||
|
@ -8532,23 +8557,25 @@ func TestEvaluateView(t *testing.T) {
|
|||
},
|
||||
|
||||
// Create update logs for local and remote.
|
||||
localUpdateLog: newUpdateLog(0, 0),
|
||||
remoteUpdateLog: newUpdateLog(0, 0),
|
||||
updateLogs: lntypes.Dual[*updateLog]{
|
||||
Local: newUpdateLog(0, 0),
|
||||
Remote: newUpdateLog(0, 0),
|
||||
},
|
||||
}
|
||||
|
||||
for _, htlc := range test.ourHtlcs {
|
||||
if htlc.EntryType == Add {
|
||||
lc.localUpdateLog.appendHtlc(htlc)
|
||||
lc.updateLogs.Local.appendHtlc(htlc)
|
||||
} else {
|
||||
lc.localUpdateLog.appendUpdate(htlc)
|
||||
lc.updateLogs.Local.appendUpdate(htlc)
|
||||
}
|
||||
}
|
||||
|
||||
for _, htlc := range test.theirHtlcs {
|
||||
if htlc.EntryType == Add {
|
||||
lc.remoteUpdateLog.appendHtlc(htlc)
|
||||
lc.updateLogs.Remote.appendHtlc(htlc)
|
||||
} else {
|
||||
lc.remoteUpdateLog.appendUpdate(htlc)
|
||||
lc.updateLogs.Remote.appendUpdate(htlc)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue