Skip to content

Commit b572e0d

Browse files
committed
htlcswitch+channeldb: add htlcidx to fwding log
In this commit we add htlcindex field to the forwardingevent struct, which is persisted alongside the other event fields.
1 parent 71dbc18 commit b572e0d

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

channeldb/forwarding_log.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ const (
2525
// is as follows:
2626
//
2727
// * 8 byte incoming chan ID || 8 byte outgoing chan ID || 8 byte value in
28-
// || 8 byte value out
28+
// || 8 byte value out || 8 byte htlc index
2929
//
3030
// From the value in and value out, callers can easily compute the
3131
// total fee extract from a forwarding event.
32-
forwardingEventSize = 32
32+
forwardingEventSize = 40
3333

3434
// MaxResponseEvents is the max number of forwarding events that will
3535
// be returned by a single query response. This size was selected to
@@ -78,6 +78,10 @@ type ForwardingEvent struct {
7878
// AmtOut is the amount of the outgoing HTLC. Subtracting the incoming
7979
// amount from this gives the total fees for this payment circuit.
8080
AmtOut lnwire.MilliSatoshi
81+
82+
// HtlcIndex is the index of the HTLC in the channel. This is used to
83+
// match the HTLC in the channel with the HTLC in the forwarding log.
84+
HtlcIndex uint64
8185
}
8286

8387
// encodeForwardingEvent writes out the target forwarding event to the passed
@@ -86,6 +90,7 @@ type ForwardingEvent struct {
8690
func encodeForwardingEvent(w io.Writer, f *ForwardingEvent) error {
8791
return WriteElements(
8892
w, f.IncomingChanID, f.OutgoingChanID, f.AmtIn, f.AmtOut,
93+
f.HtlcIndex,
8994
)
9095
}
9196

@@ -96,6 +101,7 @@ func encodeForwardingEvent(w io.Writer, f *ForwardingEvent) error {
96101
func decodeForwardingEvent(r io.Reader, f *ForwardingEvent) error {
97102
return ReadElements(
98103
r, &f.IncomingChanID, &f.OutgoingChanID, &f.AmtIn, &f.AmtOut,
104+
&f.HtlcIndex,
99105
)
100106
}
101107

channeldb/forwarding_log_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func TestForwardingLogBasicStorageAndQuery(t *testing.T) {
4141
OutgoingChanID: lnwire.NewShortChanIDFromInt(uint64(rand.Int63())),
4242
AmtIn: lnwire.MilliSatoshi(rand.Int63()),
4343
AmtOut: lnwire.MilliSatoshi(rand.Int63()),
44+
HtlcIndex: uint64(i),
4445
}
4546

4647
timestamp = timestamp.Add(time.Minute * 10)
@@ -109,6 +110,7 @@ func TestForwardingLogQueryOptions(t *testing.T) {
109110
OutgoingChanID: lnwire.NewShortChanIDFromInt(uint64(rand.Int63())),
110111
AmtIn: lnwire.MilliSatoshi(rand.Int63()),
111112
AmtOut: lnwire.MilliSatoshi(rand.Int63()),
113+
HtlcIndex: uint64(i),
112114
}
113115

114116
endTime = endTime.Add(time.Minute * 10)
@@ -208,6 +210,7 @@ func TestForwardingLogQueryLimit(t *testing.T) {
208210
OutgoingChanID: lnwire.NewShortChanIDFromInt(uint64(rand.Int63())),
209211
AmtIn: lnwire.MilliSatoshi(rand.Int63()),
210212
AmtOut: lnwire.MilliSatoshi(rand.Int63()),
213+
HtlcIndex: uint64(i),
211214
}
212215

213216
endTime = endTime.Add(time.Minute * 10)
@@ -317,6 +320,7 @@ func TestForwardingLogStoreEvent(t *testing.T) {
317320
OutgoingChanID: lnwire.NewShortChanIDFromInt(uint64(rand.Int63())),
318321
AmtIn: lnwire.MilliSatoshi(rand.Int63()),
319322
AmtOut: lnwire.MilliSatoshi(rand.Int63()),
323+
HtlcIndex: uint64(i),
320324
}
321325
}
322326

htlcswitch/switch.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3074,6 +3074,7 @@ func (s *Switch) handlePacketSettle(packet *htlcPacket) error {
30743074
OutgoingChanID: circuit.Outgoing.ChanID,
30753075
AmtIn: circuit.IncomingAmount,
30763076
AmtOut: circuit.OutgoingAmount,
3077+
HtlcIndex: circuit.Incoming.HtlcID,
30773078
},
30783079
)
30793080
s.fwdEventMtx.Unlock()

0 commit comments

Comments
 (0)