Skip to content

Commit f2b6c3a

Browse files
committed
[workaround]lnwallet: set remote update log blinding point from pending
This commit adds a workaround for the fact that we don't have our extra htlc data (ie, that provided in tlvs) stored in channeldb.HTLC. It ensures that we have the blinding point populated on restart for the following set of circumstances: * The incoming HTLC is irrevocably committed to in our local commitment, ie: we have received a CommitSig and sent a RevokeAndAck for a commitment that includes the incoming HTLC. * The incoming HTLC is still pending on the sender, ie: we have not yet sent the remote party a CommitSig covering the incoming HTLC. If we restart at this point, the htlc will be stored as an incoming htlc on our local commitment (with no blinding point) and the full log update will be saved as a LogUpdate in our remote pending updates (because we have not yet provided the remote party with a signature). We restore our remoteUpdateLog from the local commit's incoming htlcs, so before this change these htlcs would be loaded into our in-memory log without their blinding point set (and operation would incorrectly resume as usual without it). This commit updates our logic to restore blinding points (if set) to the htlcs in the remoteUpdateLog.
1 parent cfc48bd commit f2b6c3a

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

lnwallet/channel.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ var (
107107
// ErrOutputIndexOutOfRange is returned when an output index is greater
108108
// than or equal to the length of a given transaction's outputs.
109109
ErrOutputIndexOutOfRange = errors.New("output index is out of range")
110+
111+
// ErrModDescriptorNotFound indicates that a payment descriptor we
112+
// aimed to modify was not found.
113+
ErrModDescriptorNotFound = errors.New("payment descriptor for " +
114+
"modification not found")
110115
)
111116

112117
// ErrCommitSyncLocalDataLoss is returned in the case that we receive a valid
@@ -1112,6 +1117,23 @@ func (u *updateLog) restoreUpdate(pd *PaymentDescriptor) {
11121117
u.updateIndex[pd.LogIndex] = u.PushBack(pd)
11131118
}
11141119

1120+
// restoreExtraData looks up a log update and updates additional data that
1121+
// would not have been recovered from our on-disk commitments. It will fail if
1122+
// the update index provided is not in the log.
1123+
//
1124+
// Note: this is a workaround for channeldb.HTLC not storing additional data
1125+
// passed in update_add_htlc tlvs.
1126+
func (u *updateLog) restoreExtraAddData(i uint64, b *btcec.PublicKey) error {
1127+
pd := u.lookupHtlc(i)
1128+
if pd == nil {
1129+
return fmt.Errorf("%w: index: %v", ErrModDescriptorNotFound, i)
1130+
}
1131+
1132+
pd.BlindingPoint = b
1133+
1134+
return nil
1135+
}
1136+
11151137
// appendHtlc appends a new HTLC offer to the tip of the update log. The entry
11161138
// is also added to the offer index accordingly.
11171139
func (u *updateLog) appendHtlc(pd *PaymentDescriptor) {
@@ -2039,7 +2061,17 @@ func (lc *LightningChannel) restorePendingRemoteUpdates(
20392061
// but this Add restoration was a no-op as every single one of
20402062
// these Adds was already restored since they're all incoming
20412063
// htlcs on the local commitment.
2064+
//
2065+
// Since our on-disk commitment does not store extra data for
2066+
// htlcs, we restore the update on the local log from our log
2067+
// update.
20422068
if payDesc.EntryType == Add {
2069+
if err = lc.remoteUpdateLog.restoreExtraAddData(
2070+
payDesc.HtlcIndex, payDesc.BlindingPoint,
2071+
); err != nil {
2072+
return err
2073+
}
2074+
20432075
continue
20442076
}
20452077

0 commit comments

Comments
 (0)