htlcswicth+channel: switch to store onion blobs in payment descriptor

After addition of the retransmission logic in the channel link, we
should make the onion blobs persistant, the proper way to do this is
include the onion blobs in the payment descriptor rather than storing
them in the distinct struct in the channel link.
This commit is contained in:
Andrey Samokhvalov
2017-07-09 02:38:50 +03:00
committed by Olaoluwa Osuntokun
parent 3555c4c463
commit 1b4e723a5d
2 changed files with 16 additions and 26 deletions

View File

@@ -166,16 +166,6 @@ type channelLink struct {
// htlc cancel reasons. // htlc cancel reasons.
cancelReasons map[uint64]lnwire.OpaqueReason cancelReasons map[uint64]lnwire.OpaqueReason
// clearedOnionBlobs tracks the remote log index of the incoming
// htlc's, mapped to the htlc onion blob which encapsulates the next
// hop. HTLC's are added to this map once the HTLC has been cleared,
// meaning the commitment state reflects the update encoded within this
// HTLC.
//
// TODO(andrew.shvv) remove after payment descriptor start store
// htlc onion blobs.
clearedOnionBlobs map[uint64][lnwire.OnionPacketSize]byte
// batchCounter is the number of updates which we received from remote // batchCounter is the number of updates which we received from remote
// side, but not include in commitment transaction yet and plus the // side, but not include in commitment transaction yet and plus the
// current number of settles that have been sent, but not yet committed // current number of settles that have been sent, but not yet committed
@@ -239,12 +229,11 @@ func NewChannelLink(cfg ChannelLinkConfig, channel *lnwallet.LightningChannel,
currentHeight uint32) ChannelLink { currentHeight uint32) ChannelLink {
return &channelLink{ return &channelLink{
cfg: cfg, cfg: cfg,
channel: channel, channel: channel,
clearedOnionBlobs: make(map[uint64][lnwire.OnionPacketSize]byte), upstream: make(chan lnwire.Message),
upstream: make(chan lnwire.Message), downstream: make(chan *htlcPacket),
downstream: make(chan *htlcPacket), linkControl: make(chan interface{}),
linkControl: make(chan interface{}),
// TODO(roasbeef): just do reserve here? // TODO(roasbeef): just do reserve here?
availableBandwidth: uint64(channel.StateSnapshot().LocalBalance), availableBandwidth: uint64(channel.StateSnapshot().LocalBalance),
cancelReasons: make(map[uint64]lnwire.OpaqueReason), cancelReasons: make(map[uint64]lnwire.OpaqueReason),
@@ -747,11 +736,6 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
log.Tracef("Receive upstream htlc with payment hash(%x), "+ log.Tracef("Receive upstream htlc with payment hash(%x), "+
"assigning index: %v", msg.PaymentHash[:], index) "assigning index: %v", msg.PaymentHash[:], index)
// Store the onion blob which encapsulate the htlc route and
// use in on stage of HTLC inclusion to retrieve the next hop
// and propagate the HTLC along the remaining route.
l.clearedOnionBlobs[index] = msg.OnionBlob
case *lnwire.UpdateFufillHTLC: case *lnwire.UpdateFufillHTLC:
pre := msg.PaymentPreimage pre := msg.PaymentPreimage
idx := msg.ID idx := msg.ID
@@ -1144,8 +1128,8 @@ func (l *channelLink) processLockedInHtlcs(
case lnwallet.Add: case lnwallet.Add:
// Fetch the onion blob that was included within this // Fetch the onion blob that was included within this
// processed payment descriptor. // processed payment descriptor.
onionBlob := l.clearedOnionBlobs[pd.HtlcIndex] var onionBlob [lnwire.OnionPacketSize]byte
delete(l.clearedOnionBlobs, pd.HtlcIndex) copy(onionBlob[:], pd.OnionBlob)
// Retrieve onion obfuscator from onion blob in order // Retrieve onion obfuscator from onion blob in order
// to produce initial obfuscation of the onion // to produce initial obfuscation of the onion

View File

@@ -208,9 +208,11 @@ type PaymentDescriptor struct {
removeCommitHeightRemote uint64 removeCommitHeightRemote uint64
removeCommitHeightLocal uint64 removeCommitHeightLocal uint64
// Payload is an opaque blob which is used to complete multi-hop // OnionBlob is an opaque blob which is used to complete multi-hop
// routing. // routing.
Payload []byte //
// NOTE: Populated only on add payment descriptor entry types.
OnionBlob []byte
// [our|their|]PkScript are the raw public key scripts that encodes the // [our|their|]PkScript are the raw public key scripts that encodes the
// redemption rules for this particular HTLC. These fields will only be // redemption rules for this particular HTLC. These fields will only be
@@ -534,6 +536,7 @@ func (c *commitment) toChannelDelta(ourCommit bool) (*channeldb.ChannelDelta, er
RHash: htlc.RHash, RHash: htlc.RHash,
RefundTimeout: htlc.Timeout, RefundTimeout: htlc.Timeout,
OutputIndex: outputIndex, OutputIndex: outputIndex,
OnionBlob: htlc.OnionBlob,
} }
if ourCommit && htlc.sig != nil { if ourCommit && htlc.sig != nil {
@@ -1688,6 +1691,7 @@ func (lc *LightningChannel) restoreStateLogs() error {
EntryType: Add, EntryType: Add,
addCommitHeightRemote: pastHeight, addCommitHeightRemote: pastHeight,
addCommitHeightLocal: pastHeight, addCommitHeightLocal: pastHeight,
OnionBlob: htlc.OnionBlob,
ourPkScript: ourP2WSH, ourPkScript: ourP2WSH,
ourWitnessScript: ourWitnessScript, ourWitnessScript: ourWitnessScript,
theirPkScript: theirP2WSH, theirPkScript: theirP2WSH,
@@ -2487,7 +2491,7 @@ func (lc *LightningChannel) ReceiveReestablish(msg *lnwire.ChannelReestablish) (
switch htlc.EntryType { switch htlc.EntryType {
case Add: case Add:
var onionBlob [lnwire.OnionPacketSize]byte var onionBlob [lnwire.OnionPacketSize]byte
copy(onionBlob[:], htlc.Payload) copy(onionBlob[:], htlc.OnionBlob)
updates = append(updates, &lnwire.UpdateAddHTLC{ updates = append(updates, &lnwire.UpdateAddHTLC{
ChanID: chanID, ChanID: chanID,
ID: htlc.Index, ID: htlc.Index,
@@ -3102,6 +3106,7 @@ func (lc *LightningChannel) AddHTLC(htlc *lnwire.UpdateAddHTLC) (uint64, error)
Amount: htlc.Amount, Amount: htlc.Amount,
LogIndex: lc.localUpdateLog.logIndex, LogIndex: lc.localUpdateLog.logIndex,
HtlcIndex: lc.localUpdateLog.htlcCounter, HtlcIndex: lc.localUpdateLog.htlcCounter,
OnionBlob: htlc.OnionBlob[:],
} }
lc.localUpdateLog.appendHtlc(pd) lc.localUpdateLog.appendHtlc(pd)
@@ -3128,6 +3133,7 @@ func (lc *LightningChannel) ReceiveHTLC(htlc *lnwire.UpdateAddHTLC) (uint64, err
Amount: htlc.Amount, Amount: htlc.Amount,
LogIndex: lc.remoteUpdateLog.logIndex, LogIndex: lc.remoteUpdateLog.logIndex,
HtlcIndex: lc.remoteUpdateLog.htlcCounter, HtlcIndex: lc.remoteUpdateLog.htlcCounter,
OnionBlob: htlc.OnionBlob[:],
} }
lc.remoteUpdateLog.appendHtlc(pd) lc.remoteUpdateLog.appendHtlc(pd)