diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 6d9837229..1e9ba5842 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -168,103 +168,6 @@ func (e *ErrCommitSyncLocalDataLoss) Error() string { // payments requested by the wallet/daemon. type PaymentHash [32]byte -// PayDescsFromRemoteLogUpdates converts a slice of LogUpdates received from the -// remote peer into PaymentDescriptors to inform a link's forwarding decisions. -// -// NOTE: The provided `logUpdates` MUST correspond exactly to either the Adds -// or SettleFails in this channel's forwarding package at `height`. -func PayDescsFromRemoteLogUpdates(chanID lnwire.ShortChannelID, height uint64, - logUpdates []channeldb.LogUpdate) ([]*PaymentDescriptor, error) { - - // Allocate enough space to hold all of the payment descriptors we will - // reconstruct, and also the list of pointers that will be returned to - // the caller. - payDescs := make([]PaymentDescriptor, 0, len(logUpdates)) - payDescPtrs := make([]*PaymentDescriptor, 0, len(logUpdates)) - - // Iterate over the log updates we loaded from disk, and reconstruct the - // payment descriptor corresponding to one of the four types of htlcs we - // can receive from the remote peer. We only repopulate the information - // necessary to process the packets and, if necessary, forward them to - // the switch. - // - // For each log update, we include either an AddRef or a SettleFailRef - // so that they can be ACK'd and garbage collected. - for i, logUpdate := range logUpdates { - var pd PaymentDescriptor - switch wireMsg := logUpdate.UpdateMsg.(type) { - - case *lnwire.UpdateAddHTLC: - pd = PaymentDescriptor{ - ChanID: wireMsg.ChanID, - RHash: wireMsg.PaymentHash, - Timeout: wireMsg.Expiry, - Amount: wireMsg.Amount, - EntryType: Add, - HtlcIndex: wireMsg.ID, - LogIndex: logUpdate.LogIndex, - SourceRef: &channeldb.AddRef{ - Height: height, - Index: uint16(i), - }, - BlindingPoint: wireMsg.BlindingPoint, - CustomRecords: wireMsg.CustomRecords.Copy(), - } - pd.OnionBlob = wireMsg.OnionBlob - - case *lnwire.UpdateFulfillHTLC: - pd = PaymentDescriptor{ - ChanID: wireMsg.ChanID, - RPreimage: wireMsg.PaymentPreimage, - ParentIndex: wireMsg.ID, - EntryType: Settle, - DestRef: &channeldb.SettleFailRef{ - Source: chanID, - Height: height, - Index: uint16(i), - }, - } - - case *lnwire.UpdateFailHTLC: - pd = PaymentDescriptor{ - ChanID: wireMsg.ChanID, - ParentIndex: wireMsg.ID, - EntryType: Fail, - FailReason: wireMsg.Reason[:], - DestRef: &channeldb.SettleFailRef{ - Source: chanID, - Height: height, - Index: uint16(i), - }, - } - - case *lnwire.UpdateFailMalformedHTLC: - pd = PaymentDescriptor{ - ChanID: wireMsg.ChanID, - ParentIndex: wireMsg.ID, - EntryType: MalformedFail, - FailCode: wireMsg.FailureCode, - ShaOnionBlob: wireMsg.ShaOnionBlob, - DestRef: &channeldb.SettleFailRef{ - Source: chanID, - Height: height, - Index: uint16(i), - }, - } - - // NOTE: UpdateFee is not expected since they are not forwarded. - case *lnwire.UpdateFee: - return nil, fmt.Errorf("unexpected update fee") - - } - - payDescs = append(payDescs, pd) - payDescPtrs = append(payDescPtrs, &payDescs[i]) - } - - return payDescPtrs, nil -} - // commitment represents a commitment to a new state within an active channel. // New commitments can be initiated by either side. Commitments are ordered // into a commitment chain, with one existing for both parties. Each side can