Skip to content

Commit 701f897

Browse files
committed
return unencrypted failure messages with channel update
1 parent c19e992 commit 701f897

File tree

4 files changed

+62
-16
lines changed

4 files changed

+62
-16
lines changed

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ require (
103103
github.com/lightningnetwork/lnd/kvdb v1.3.1 // indirect
104104
github.com/lightningnetwork/lnd/ticker v1.1.0 // indirect
105105
github.com/lightningnetwork/lnd/tlv v1.0.3 // indirect
106-
github.com/lightningnetwork/lnd/tor v1.0.1 // indirect
106+
github.com/lightningnetwork/lnd/tor v1.1.0 // indirect
107107
github.com/ltcsuite/ltcd v0.20.1-beta // indirect
108108
github.com/mailru/easyjson v0.7.6 // indirect
109109
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
@@ -182,3 +182,5 @@ require (
182182
)
183183

184184
replace github.com/bottlepay/lnmux/lnmuxrpc => ./lnmuxrpc
185+
186+
replace github.com/lightningnetwork/lnd => /users/Joost.Jager/lightninglabs/lnd

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,6 @@ github.com/lightninglabs/neutrino v0.14.2 h1:yrnZUCYMZ5ECtXhgDrzqPq2oX8awoAN2D/c
507507
github.com/lightninglabs/neutrino v0.14.2/go.mod h1:OICUeTCn+4Tu27YRJIpWvvqySxx4oH4vgdP33Sw9RDc=
508508
github.com/lightningnetwork/lightning-onion v1.0.2-0.20220211021909-bb84a1ccb0c5 h1:TkKwqFcQTGYoI+VEqyxA8rxpCin8qDaYX0AfVRinT3k=
509509
github.com/lightningnetwork/lightning-onion v1.0.2-0.20220211021909-bb84a1ccb0c5/go.mod h1:7dDx73ApjEZA0kcknI799m2O5kkpfg4/gr7N092ojNo=
510-
github.com/lightningnetwork/lnd v0.15.4-beta h1:vO+UZjuA8RqJdDlfwQeS0h2PCocYwwqv5HkX2IXf5/M=
511-
github.com/lightningnetwork/lnd v0.15.4-beta/go.mod h1:6aoOkifcI9tuk8UV5l2rVZSq0681obuP4zvfK+2ZrT0=
512510
github.com/lightningnetwork/lnd/clock v1.0.1/go.mod h1:KnQudQ6w0IAMZi1SgvecLZQZ43ra2vpDNj7H/aasemg=
513511
github.com/lightningnetwork/lnd/clock v1.1.0 h1:/yfVAwtPmdx45aQBoXQImeY7sOIEr7IXlImRMBOZ7GQ=
514512
github.com/lightningnetwork/lnd/clock v1.1.0/go.mod h1:KnQudQ6w0IAMZi1SgvecLZQZ43ra2vpDNj7H/aasemg=
@@ -527,8 +525,8 @@ github.com/lightningnetwork/lnd/tlv v1.0.2/go.mod h1:fICAfsqk1IOsC1J7G9IdsWX1EqW
527525
github.com/lightningnetwork/lnd/tlv v1.0.3 h1:0xBZcPuXagP6f7TY/RnLNR4igE21ov6qUdTr5NyvhhI=
528526
github.com/lightningnetwork/lnd/tlv v1.0.3/go.mod h1:dzR/aZetBri+ZY/fHbwV06fNn/3UID6htQzbHfREFdo=
529527
github.com/lightningnetwork/lnd/tor v1.0.0/go.mod h1:RDtaAdwfAm+ONuPYwUhNIH1RAvKPv+75lHPOegUcz64=
530-
github.com/lightningnetwork/lnd/tor v1.0.1 h1:A11FrpU0Y//g+fA827W4VnjOeoIvExONdchlLX8wYkA=
531-
github.com/lightningnetwork/lnd/tor v1.0.1/go.mod h1:RDtaAdwfAm+ONuPYwUhNIH1RAvKPv+75lHPOegUcz64=
528+
github.com/lightningnetwork/lnd/tor v1.1.0 h1:iXO7fSzjxTI+p88KmtpbuyuRJeNfgtpl9QeaAliILXE=
529+
github.com/lightningnetwork/lnd/tor v1.1.0/go.mod h1:RDtaAdwfAm+ONuPYwUhNIH1RAvKPv+75lHPOegUcz64=
532530
github.com/ltcsuite/ltcd v0.20.1-beta h1:ka9ZwUG7oUPppl+7ptuh5VDxGD7TWEJXu/IOOOz1yfY=
533531
github.com/ltcsuite/ltcd v0.20.1-beta/go.mod h1:ZFQaYdYULIuTQiWqs7AUiHD2XhDFeeHW1IH+UYMdABU=
534532
github.com/ltcsuite/ltcutil v0.0.0-20191227053721-6bec450ea6ad/go.mod h1:8Vg/LTOO0KYa/vlHWJ6XZAevPQThGH5sufO0Hrou/lA=

interceptor.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,11 @@ func (i *interceptor) start(ctx context.Context) error {
156156
ChanId: item.incomingKey.ChanID,
157157
HtlcId: item.incomingKey.HtlcID,
158158
},
159-
Action: item.resp.action,
160-
Preimage: item.resp.preimage[:],
161-
FailureMessage: item.resp.failureMessage,
162-
FailureCode: item.resp.failureCode,
159+
Action: item.resp.action,
160+
Preimage: item.resp.preimage[:],
161+
FailureMessage: item.resp.failureMessage,
162+
FailureCode: item.resp.failureCode,
163+
FailureMessageUnencrypted: item.resp.failureMessageUnencrypted,
163164
}
164165

165166
if err := send(rpcResp); err != nil {

mux.go

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import (
55
"context"
66
"fmt"
77
"sync"
8+
"time"
89

10+
"github.com/bottlepay/lnmux/common"
911
"github.com/bottlepay/lnmux/lnd"
1012
"github.com/bottlepay/lnmux/types"
1113
"github.com/btcsuite/btcd/chaincfg"
@@ -30,6 +32,8 @@ type Mux struct {
3032
routingPolicy RoutingPolicy
3133

3234
virtualChannel uint64
35+
muxKey common.PubKey
36+
nodeKey common.PubKey
3337
}
3438

3539
type MuxConfig struct {
@@ -52,9 +56,7 @@ type RoutingPolicy struct {
5256
FeeRatePpm int64
5357
}
5458

55-
func New(cfg *MuxConfig) (*Mux,
56-
error) {
57-
59+
func New(cfg *MuxConfig) (*Mux, error) {
5860
idKeyDesc, err := cfg.KeyRing.DeriveKey(
5961
keychain.KeyLocator{
6062
Family: keychain.KeyFamilyNodeKey,
@@ -67,6 +69,17 @@ func New(cfg *MuxConfig) (*Mux,
6769

6870
nodeKeyECDH := keychain.NewPubKeyECDH(idKeyDesc, cfg.KeyRing)
6971

72+
muxKubKey, err := cfg.KeyRing.DeriveKey(keychain.KeyLocator{})
73+
if err != nil {
74+
return nil, err
75+
}
76+
muxKey, err := common.NewPubKeyFromBytes(
77+
muxKubKey.PubKey.SerializeCompressed(),
78+
)
79+
if err != nil {
80+
return nil, err
81+
}
82+
7083
replayLog := &replayLog{}
7184

7285
sphinxRouter := sphinx.NewRouter(
@@ -88,6 +101,8 @@ func New(cfg *MuxConfig) (*Mux,
88101
settledHandler: cfg.SettledHandler,
89102
routingPolicy: cfg.RoutingPolicy,
90103
virtualChannel: virtualChannel,
104+
muxKey: muxKey,
105+
nodeKey: cfg.Lnd.PubKey(),
91106
}, nil
92107
}
93108

@@ -105,10 +120,11 @@ type interceptedHtlc struct {
105120
}
106121

107122
type interceptedHtlcResponse struct {
108-
action routerrpc.ResolveHoldForwardAction
109-
preimage lntypes.Preimage
110-
failureMessage []byte
111-
failureCode lnrpc.Failure_FailureCode
123+
action routerrpc.ResolveHoldForwardAction
124+
preimage lntypes.Preimage
125+
failureMessage []byte
126+
failureCode lnrpc.Failure_FailureCode
127+
failureMessageUnencrypted bool
112128
}
113129

114130
func (p *Mux) Run(mainCtx context.Context) error {
@@ -221,6 +237,35 @@ func (p *Mux) ProcessHtlc(
221237
fail := func(code lnwire.FailCode) error {
222238
logger.Debugw("Failing htlc", "code", code)
223239

240+
if code == lnwire.CodeFeeInsufficient {
241+
var channelFlags lnwire.ChanUpdateChanFlags
242+
243+
if bytes.Compare(p.muxKey[:], p.nodeKey[:]) == 1 {
244+
channelFlags |= lnwire.ChanUpdateDirection
245+
}
246+
247+
wireMsg := lnwire.NewFeeInsufficient(0, lnwire.ChannelUpdate{
248+
ChainHash: *p.lnd.Network().GenesisHash,
249+
ShortChannelID: lnwire.NewShortChanIDFromInt(p.virtualChannel),
250+
Timestamp: uint32(time.Now().Unix()),
251+
ChannelFlags: channelFlags,
252+
TimeLockDelta: uint16(p.routingPolicy.CltvDelta),
253+
BaseFee: uint32(p.routingPolicy.FeeBaseMsat),
254+
FeeRate: uint32(p.routingPolicy.FeeRatePpm),
255+
})
256+
var w bytes.Buffer
257+
err := lnwire.EncodeFailureMessage(&w, wireMsg, 0)
258+
if err != nil {
259+
return err
260+
}
261+
262+
return htlc.reply(&interceptedHtlcResponse{
263+
action: routerrpc.ResolveHoldForwardAction_FAIL,
264+
failureMessage: w.Bytes(),
265+
failureMessageUnencrypted: true,
266+
})
267+
}
268+
224269
rpcCode, err := marshallFailureCode(code)
225270
if err != nil {
226271
return err

0 commit comments

Comments
 (0)