mirror of
https://github.com/aljazceru/lspd.git
synced 2025-12-18 22:34:22 +01:00
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
go.sum
|
||||||
|
lspd
|
||||||
1
go.mod
1
go.mod
@@ -17,7 +17,6 @@ require (
|
|||||||
github.com/lightningnetwork/lnd v0.11.0-beta
|
github.com/lightningnetwork/lnd v0.11.0-beta
|
||||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
|
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
|
||||||
google.golang.org/grpc v1.29.1
|
google.golang.org/grpc v1.29.1
|
||||||
google.golang.org/protobuf v1.23.0
|
|
||||||
)
|
)
|
||||||
|
|
||||||
replace github.com/lightningnetwork/lnd v0.11.0-beta => github.com/breez/lnd v0.11.0-beta.rc4.0.20210125150416-0c10146b223c
|
replace github.com/lightningnetwork/lnd v0.11.0-beta => github.com/breez/lnd v0.11.0-beta.rc4.0.20210125150416-0c10146b223c
|
||||||
|
|||||||
59
intercept.go
59
intercept.go
@@ -96,6 +96,13 @@ func getChannel(ctx context.Context, client lnrpc.LightningClient, node []byte,
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func failForwardSend(interceptorClient routerrpc.Router_HtlcInterceptorClient, incomingCircuitKey *routerrpc.CircuitKey) {
|
||||||
|
interceptorClient.Send(&routerrpc.ForwardHtlcInterceptResponse{
|
||||||
|
IncomingCircuitKey: incomingCircuitKey,
|
||||||
|
Action: routerrpc.ResolveHoldForwardAction_FAIL,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func intercept() {
|
func intercept() {
|
||||||
for {
|
for {
|
||||||
cancellableCtx, cancel := context.WithCancel(context.Background())
|
cancellableCtx, cancel := context.WithCancel(context.Background())
|
||||||
@@ -136,6 +143,8 @@ func intercept() {
|
|||||||
paymentHash, paymentSecret, destination, incomingAmountMsat, outgoingAmountMsat, fundingTxID, fundingTxOutnum, err := paymentInfo(request.PaymentHash)
|
paymentHash, paymentSecret, destination, incomingAmountMsat, outgoingAmountMsat, fundingTxID, fundingTxOutnum, err := paymentInfo(request.PaymentHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("paymentInfo(%x) error: %v", request.PaymentHash, err)
|
log.Printf("paymentInfo(%x) error: %v", request.PaymentHash, err)
|
||||||
|
failForwardSend(interceptorClient, request.IncomingCircuitKey)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
log.Printf("paymentHash:%x\npaymentSecret:%x\ndestination:%x\nincomingAmountMsat:%v\noutgoingAmountMsat:%v\n\n",
|
log.Printf("paymentHash:%x\npaymentSecret:%x\ndestination:%x\nincomingAmountMsat:%v\noutgoingAmountMsat:%v\n\n",
|
||||||
paymentHash, paymentSecret, destination, incomingAmountMsat, outgoingAmountMsat)
|
paymentHash, paymentSecret, destination, incomingAmountMsat, outgoingAmountMsat)
|
||||||
@@ -146,10 +155,7 @@ func intercept() {
|
|||||||
fundingTxID, fundingTxOutnum, err = openChannel(clientCtx, client, request.PaymentHash, destination, incomingAmountMsat)
|
fundingTxID, fundingTxOutnum, err = openChannel(clientCtx, client, request.PaymentHash, destination, incomingAmountMsat)
|
||||||
log.Printf("openChannel(%x, %v) err: %v", destination, incomingAmountMsat, err)
|
log.Printf("openChannel(%x, %v) err: %v", destination, incomingAmountMsat, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
interceptorClient.Send(&routerrpc.ForwardHtlcInterceptResponse{
|
failForwardSend(interceptorClient, request.IncomingCircuitKey)
|
||||||
IncomingCircuitKey: request.IncomingCircuitKey,
|
|
||||||
Action: routerrpc.ResolveHoldForwardAction_FAIL,
|
|
||||||
})
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
} else { //probing
|
} else { //probing
|
||||||
@@ -167,10 +173,18 @@ func intercept() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pubKey, err := btcec.ParsePubKey(destination, btcec.S256())
|
pubKey, err := btcec.ParsePubKey(destination, btcec.S256())
|
||||||
log.Printf("btcec.ParsePubKey(%x): %v", destination, err)
|
if err != nil {
|
||||||
|
log.Printf("btcec.ParsePubKey(%x): %v", destination, err)
|
||||||
|
failForwardSend(interceptorClient, request.IncomingCircuitKey)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
sessionKey, err := btcec.NewPrivateKey(btcec.S256())
|
sessionKey, err := btcec.NewPrivateKey(btcec.S256())
|
||||||
log.Printf("btcec.NewPrivateKey(): %v", err)
|
if err != nil {
|
||||||
|
log.Printf("btcec.NewPrivateKey(): %v", err)
|
||||||
|
failForwardSend(interceptorClient, request.IncomingCircuitKey)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
var bigProd, bigAmt big.Int
|
var bigProd, bigAmt big.Int
|
||||||
amt := (bigAmt.Div(bigProd.Mul(big.NewInt(outgoingAmountMsat), big.NewInt(int64(request.OutgoingAmountMsat))), big.NewInt(incomingAmountMsat))).Int64()
|
amt := (bigAmt.Div(bigProd.Mul(big.NewInt(outgoingAmountMsat), big.NewInt(int64(request.OutgoingAmountMsat))), big.NewInt(incomingAmountMsat))).Int64()
|
||||||
@@ -186,10 +200,18 @@ func intercept() {
|
|||||||
|
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
err = hop.PackHopPayload(&b, uint64(0))
|
err = hop.PackHopPayload(&b, uint64(0))
|
||||||
log.Printf("hop.PackHopPayload(): %v", err)
|
if err != nil {
|
||||||
|
log.Printf("hop.PackHopPayload(): %v", err)
|
||||||
|
failForwardSend(interceptorClient, request.IncomingCircuitKey)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
payload, err := sphinx.NewHopPayload(nil, b.Bytes())
|
payload, err := sphinx.NewHopPayload(nil, b.Bytes())
|
||||||
log.Printf("sphinx.NewHopPayload(): %v", err)
|
if err != nil {
|
||||||
|
log.Printf("sphinx.NewHopPayload(): %v", err)
|
||||||
|
failForwardSend(interceptorClient, request.IncomingCircuitKey)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
var sphinxPath sphinx.PaymentPath
|
var sphinxPath sphinx.PaymentPath
|
||||||
sphinxPath[0] = sphinx.OnionHop{
|
sphinxPath[0] = sphinx.OnionHop{
|
||||||
@@ -200,17 +222,23 @@ func intercept() {
|
|||||||
&sphinxPath, sessionKey, request.PaymentHash,
|
&sphinxPath, sessionKey, request.PaymentHash,
|
||||||
sphinx.DeterministicPacketFiller,
|
sphinx.DeterministicPacketFiller,
|
||||||
)
|
)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("sphinx.NewOnionPacket(): %v", err)
|
||||||
|
failForwardSend(interceptorClient, request.IncomingCircuitKey)
|
||||||
|
continue
|
||||||
|
}
|
||||||
var onionBlob bytes.Buffer
|
var onionBlob bytes.Buffer
|
||||||
err = sphinxPacket.Encode(&onionBlob)
|
err = sphinxPacket.Encode(&onionBlob)
|
||||||
log.Printf("sphinxPacket.Encode(): %v", err)
|
if err != nil {
|
||||||
|
log.Printf("sphinxPacket.Encode(): %v", err)
|
||||||
|
failForwardSend(interceptorClient, request.IncomingCircuitKey)
|
||||||
|
continue
|
||||||
|
}
|
||||||
var h chainhash.Hash
|
var h chainhash.Hash
|
||||||
err = h.SetBytes(fundingTxID)
|
err = h.SetBytes(fundingTxID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("h.SetBytes(%x) error: %v", fundingTxID, err)
|
log.Printf("h.SetBytes(%x) error: %v", fundingTxID, err)
|
||||||
interceptorClient.Send(&routerrpc.ForwardHtlcInterceptResponse{
|
failForwardSend(interceptorClient, request.IncomingCircuitKey)
|
||||||
IncomingCircuitKey: request.IncomingCircuitKey,
|
|
||||||
Action: routerrpc.ResolveHoldForwardAction_FAIL,
|
|
||||||
})
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
channelPoint := wire.NewOutPoint(&h, fundingTxOutnum).String()
|
channelPoint := wire.NewOutPoint(&h, fundingTxOutnum).String()
|
||||||
@@ -265,8 +293,5 @@ func resumeOrCancel(
|
|||||||
}
|
}
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
}
|
}
|
||||||
interceptorClient.Send(&routerrpc.ForwardHtlcInterceptResponse{
|
failForwardSend(interceptorClient, incomingCircuitKey)
|
||||||
IncomingCircuitKey: incomingCircuitKey,
|
|
||||||
Action: routerrpc.ResolveHoldForwardAction_FAIL,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user