From 064d010e76ec662f002fe62433dbd4e50835e51f Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Mon, 24 Oct 2022 11:33:00 +0200 Subject: [PATCH] wip --- go.mod | 4 +++- go.sum | 6 ++---- interceptor.go | 9 +++++---- mux.go | 24 ++++++++++++++++++++---- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index 3bddc7f..3ffa4a7 100644 --- a/go.mod +++ b/go.mod @@ -103,7 +103,7 @@ require ( github.com/lightningnetwork/lnd/kvdb v1.3.1 // indirect github.com/lightningnetwork/lnd/ticker v1.1.0 // indirect github.com/lightningnetwork/lnd/tlv v1.0.3 // indirect - github.com/lightningnetwork/lnd/tor v1.0.1 // indirect + github.com/lightningnetwork/lnd/tor v1.1.0 // indirect github.com/ltcsuite/ltcd v0.20.1-beta // indirect github.com/mailru/easyjson v0.7.6 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect @@ -182,3 +182,5 @@ require ( ) replace github.com/bottlepay/lnmux/lnmuxrpc => ./lnmuxrpc + +replace github.com/lightningnetwork/lnd => /users/Joost.Jager/lightninglabs/lnd diff --git a/go.sum b/go.sum index 168d310..8569031 100644 --- a/go.sum +++ b/go.sum @@ -507,8 +507,6 @@ github.com/lightninglabs/neutrino v0.14.2 h1:yrnZUCYMZ5ECtXhgDrzqPq2oX8awoAN2D/c github.com/lightninglabs/neutrino v0.14.2/go.mod h1:OICUeTCn+4Tu27YRJIpWvvqySxx4oH4vgdP33Sw9RDc= github.com/lightningnetwork/lightning-onion v1.0.2-0.20220211021909-bb84a1ccb0c5 h1:TkKwqFcQTGYoI+VEqyxA8rxpCin8qDaYX0AfVRinT3k= github.com/lightningnetwork/lightning-onion v1.0.2-0.20220211021909-bb84a1ccb0c5/go.mod h1:7dDx73ApjEZA0kcknI799m2O5kkpfg4/gr7N092ojNo= -github.com/lightningnetwork/lnd v0.15.3-beta h1:mm7fyXMgZPRyh0fFLO3tnvfvXszp/kVnGGciS76Wefs= -github.com/lightningnetwork/lnd v0.15.3-beta/go.mod h1:UaCwJBMCJbwPMsUjfTIaKPKF8K79btRPnhqfiNPyKtA= github.com/lightningnetwork/lnd/clock v1.0.1/go.mod h1:KnQudQ6w0IAMZi1SgvecLZQZ43ra2vpDNj7H/aasemg= github.com/lightningnetwork/lnd/clock v1.1.0 h1:/yfVAwtPmdx45aQBoXQImeY7sOIEr7IXlImRMBOZ7GQ= 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 github.com/lightningnetwork/lnd/tlv v1.0.3 h1:0xBZcPuXagP6f7TY/RnLNR4igE21ov6qUdTr5NyvhhI= github.com/lightningnetwork/lnd/tlv v1.0.3/go.mod h1:dzR/aZetBri+ZY/fHbwV06fNn/3UID6htQzbHfREFdo= github.com/lightningnetwork/lnd/tor v1.0.0/go.mod h1:RDtaAdwfAm+ONuPYwUhNIH1RAvKPv+75lHPOegUcz64= -github.com/lightningnetwork/lnd/tor v1.0.1 h1:A11FrpU0Y//g+fA827W4VnjOeoIvExONdchlLX8wYkA= -github.com/lightningnetwork/lnd/tor v1.0.1/go.mod h1:RDtaAdwfAm+ONuPYwUhNIH1RAvKPv+75lHPOegUcz64= +github.com/lightningnetwork/lnd/tor v1.1.0 h1:iXO7fSzjxTI+p88KmtpbuyuRJeNfgtpl9QeaAliILXE= +github.com/lightningnetwork/lnd/tor v1.1.0/go.mod h1:RDtaAdwfAm+ONuPYwUhNIH1RAvKPv+75lHPOegUcz64= github.com/ltcsuite/ltcd v0.20.1-beta h1:ka9ZwUG7oUPppl+7ptuh5VDxGD7TWEJXu/IOOOz1yfY= github.com/ltcsuite/ltcd v0.20.1-beta/go.mod h1:ZFQaYdYULIuTQiWqs7AUiHD2XhDFeeHW1IH+UYMdABU= github.com/ltcsuite/ltcutil v0.0.0-20191227053721-6bec450ea6ad/go.mod h1:8Vg/LTOO0KYa/vlHWJ6XZAevPQThGH5sufO0Hrou/lA= diff --git a/interceptor.go b/interceptor.go index b74ea84..be4d722 100644 --- a/interceptor.go +++ b/interceptor.go @@ -156,10 +156,11 @@ func (i *interceptor) start(ctx context.Context) error { ChanId: item.incomingKey.ChanID, HtlcId: item.incomingKey.HtlcID, }, - Action: item.resp.action, - Preimage: item.resp.preimage[:], - FailureMessage: item.resp.failureMessage, - FailureCode: item.resp.failureCode, + Action: item.resp.action, + Preimage: item.resp.preimage[:], + FailureMessage: item.resp.failureMessage, + FailureCode: item.resp.failureCode, + FailureMessageUnencrypted: item.resp.failureMessageUnencrypted, } if err := send(rpcResp); err != nil { diff --git a/mux.go b/mux.go index b915e19..0dd6d11 100644 --- a/mux.go +++ b/mux.go @@ -115,10 +115,11 @@ type interceptedHtlc struct { } type interceptedHtlcResponse struct { - action routerrpc.ResolveHoldForwardAction - preimage lntypes.Preimage - failureMessage []byte - failureCode lnrpc.Failure_FailureCode + action routerrpc.ResolveHoldForwardAction + preimage lntypes.Preimage + failureMessage []byte + failureCode lnrpc.Failure_FailureCode + failureMessageUnencrypted bool } func (p *Mux) run(mainCtx context.Context) error { @@ -236,6 +237,21 @@ func (p *Mux) ProcessHtlc( fail := func(code lnwire.FailCode) error { logger.Debugw("Failing htlc", "code", code) + if code == lnwire.CodeFeeInsufficient { + wireMsg := lnwire.NewFeeInsufficient(0, lnwire.ChannelUpdate{}) + var w bytes.Buffer + err := lnwire.EncodeFailureMessage(&w, wireMsg, 0) + if err != nil { + return err + } + + return htlc.reply(&interceptedHtlcResponse{ + action: routerrpc.ResolveHoldForwardAction_FAIL, + failureMessage: w.Bytes(), + failureMessageUnencrypted: true, + }) + } + rpcCode, err := marshallFailureCode(code) if err != nil { return err