feature: expose preimage in forward+settle event
Until now, clients of SubscribeHTLCEvents didn't have access to the settled preimage. The API allows to intercept forward event and to be updated on forward events however the forward+settle event does not include the payment preimage. This pr changes allows it.
This commit is contained in:
1 parent
1868c7dec1
commit
2c4dbfa19f
10 files changed
+295
-251
No files matched your search
+19
-10
@@ -2762,7 +2762,8 @@ func TestInvalidFailure(t *testing.T) {
|
||||
// these tests.
|
||||
type htlcNotifierEvents func(channels *clusterChannels, htlcID uint64,
|
||||
ts time.Time, htlc *lnwire.UpdateAddHTLC,
|
||||
hops []*hop.Payload) ([]interface{}, []interface{}, []interface{})
|
||||
hops []*hop.Payload,
|
||||
preimage *lntypes.Preimage) ([]interface{}, []interface{}, []interface{})
|
||||
|
||||
// TestHtlcNotifier tests the notifying of htlc events that are routed over a
|
||||
// three hop network. It sets up an Alice -> Bob -> Carol network and routes
|
||||
@@ -2793,11 +2794,12 @@ func TestHtlcNotifier(t *testing.T) {
|
||||
expectedEvents: func(channels *clusterChannels,
|
||||
htlcID uint64, ts time.Time,
|
||||
htlc *lnwire.UpdateAddHTLC,
|
||||
hops []*hop.Payload) ([]interface{},
|
||||
hops []*hop.Payload,
|
||||
preimage *lntypes.Preimage) ([]interface{},
|
||||
[]interface{}, []interface{}) {
|
||||
|
||||
return getThreeHopEvents(
|
||||
channels, htlcID, ts, htlc, hops, nil,
|
||||
channels, htlcID, ts, htlc, hops, nil, preimage,
|
||||
)
|
||||
},
|
||||
iterations: 2,
|
||||
@@ -2812,7 +2814,8 @@ func TestHtlcNotifier(t *testing.T) {
|
||||
expectedEvents: func(channels *clusterChannels,
|
||||
htlcID uint64, ts time.Time,
|
||||
htlc *lnwire.UpdateAddHTLC,
|
||||
hops []*hop.Payload) ([]interface{},
|
||||
hops []*hop.Payload,
|
||||
preimage *lntypes.Preimage) ([]interface{},
|
||||
[]interface{}, []interface{}) {
|
||||
|
||||
return getThreeHopEvents(
|
||||
@@ -2821,6 +2824,7 @@ func TestHtlcNotifier(t *testing.T) {
|
||||
msg: &lnwire.FailChannelDisabled{},
|
||||
FailureDetail: OutgoingFailureForwardsDisabled,
|
||||
},
|
||||
preimage,
|
||||
)
|
||||
},
|
||||
iterations: 1,
|
||||
@@ -2942,11 +2946,12 @@ func testHtcNotifier(t *testing.T, testOpts []serverOption, iterations int,
|
||||
// of htlc ids.
|
||||
for i := 0; i < iterations; i++ {
|
||||
// We'll start off by making a payment from
|
||||
// Alice -> Bob -> Carol.
|
||||
htlc, hops := n.sendThreeHopPayment(t)
|
||||
// Alice -> Bob -> Carol. The preimage, generated
|
||||
// by Carol's Invoice is expected in the Settle events
|
||||
htlc, hops, preimage := n.sendThreeHopPayment(t)
|
||||
|
||||
alice, bob, carol := getEvents(
|
||||
channels, uint64(i), now, htlc, hops,
|
||||
channels, uint64(i), now, htlc, hops, preimage,
|
||||
)
|
||||
|
||||
checkHtlcEvents(t, aliceEvents.Updates(), alice)
|
||||
@@ -2981,7 +2986,7 @@ func checkHtlcEvents(t *testing.T, events <-chan interface{},
|
||||
// Alice -> Bob -> Carol in a three hop network and returns Alice's first htlc
|
||||
// and the remainder of the hops.
|
||||
func (n *threeHopNetwork) sendThreeHopPayment(t *testing.T) (*lnwire.UpdateAddHTLC,
|
||||
[]*hop.Payload) {
|
||||
[]*hop.Payload, *lntypes.Preimage) {
|
||||
|
||||
amount := lnwire.NewMSatFromSatoshis(btcutil.SatoshiPerBitcoin)
|
||||
|
||||
@@ -3009,7 +3014,7 @@ func (n *threeHopNetwork) sendThreeHopPayment(t *testing.T) (*lnwire.UpdateAddHT
|
||||
t.Fatalf("could not send htlc")
|
||||
}
|
||||
|
||||
return htlc, hops
|
||||
return htlc, hops, invoice.Terms.PaymentPreimage
|
||||
}
|
||||
|
||||
// getThreeHopEvents gets the set of htlc events that we expect for a payment
|
||||
@@ -3017,7 +3022,8 @@ func (n *threeHopNetwork) sendThreeHopPayment(t *testing.T) (*lnwire.UpdateAddHT
|
||||
// of events will fail on Bob's outgoing link.
|
||||
func getThreeHopEvents(channels *clusterChannels, htlcID uint64,
|
||||
ts time.Time, htlc *lnwire.UpdateAddHTLC, hops []*hop.Payload,
|
||||
linkError *LinkError) ([]interface{}, []interface{}, []interface{}) {
|
||||
linkError *LinkError,
|
||||
preimage *lntypes.Preimage) ([]interface{}, []interface{}, []interface{}) {
|
||||
|
||||
aliceKey := HtlcKey{
|
||||
IncomingCircuit: zeroCircuit,
|
||||
@@ -3091,6 +3097,7 @@ func getThreeHopEvents(channels *clusterChannels, htlcID uint64,
|
||||
aliceEvents,
|
||||
&SettleEvent{
|
||||
HtlcKey: aliceKey,
|
||||
Preimage: *preimage,
|
||||
HtlcEventType: HtlcEventTypeSend,
|
||||
Timestamp: ts,
|
||||
},
|
||||
@@ -3105,6 +3112,7 @@ func getThreeHopEvents(channels *clusterChannels, htlcID uint64,
|
||||
},
|
||||
&SettleEvent{
|
||||
HtlcKey: bobKey,
|
||||
Preimage: *preimage,
|
||||
HtlcEventType: HtlcEventTypeForward,
|
||||
Timestamp: ts,
|
||||
},
|
||||
@@ -3119,6 +3127,7 @@ func getThreeHopEvents(channels *clusterChannels, htlcID uint64,
|
||||
},
|
||||
OutgoingCircuit: zeroCircuit,
|
||||
},
|
||||
Preimage: *preimage,
|
||||
HtlcEventType: HtlcEventTypeReceive,
|
||||
Timestamp: ts,
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user