mirror of
https://github.com/aljazceru/lspd.git
synced 2026-02-18 12:34:22 +01:00
Open a channel only if the nextHop is unknown or the destination
This commit is contained in:
@@ -133,11 +133,26 @@ func (i *ClnHtlcInterceptor) intercept() error {
|
||||
log.Printf("unexpected error in interceptor.Recv() %v", err)
|
||||
break
|
||||
}
|
||||
nextHop := "<unknown>"
|
||||
channels, err := i.client.client.GetChannel(request.Onion.ShortChannelId)
|
||||
if err != nil {
|
||||
for _, c := range channels {
|
||||
if c.Source == i.config.NodePubkey {
|
||||
nextHop = c.Destination
|
||||
break
|
||||
}
|
||||
if c.Destination == i.config.NodePubkey {
|
||||
nextHop = c.Source
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("correlationid: %v\nhtlc: %v\nchanID: %v\nincoming amount: %v\noutgoing amount: %v\nincoming expiry: %v\noutgoing expiry: %v\npaymentHash: %v\nonionBlob: %v\n\n",
|
||||
log.Printf("correlationid: %v\nhtlc: %v\nchanID: %v\nnextHop: %v\nincoming amount: %v\noutgoing amount: %v\nincoming expiry: %v\noutgoing expiry: %v\npaymentHash: %v\nonionBlob: %v\n\n",
|
||||
request.Correlationid,
|
||||
request.Htlc,
|
||||
request.Onion.ShortChannelId,
|
||||
nextHop,
|
||||
request.Htlc.AmountMsat, //with fees
|
||||
request.Onion.ForwardMsat,
|
||||
request.Htlc.CltvExpiryRelative,
|
||||
@@ -153,7 +168,7 @@ func (i *ClnHtlcInterceptor) intercept() error {
|
||||
interceptorClient.Send(i.defaultResolution(request))
|
||||
i.doneWg.Done()
|
||||
}
|
||||
interceptResult := intercept(i.client, i.config, paymentHash, request.Onion.ForwardMsat, request.Htlc.CltvExpiry)
|
||||
interceptResult := intercept(i.client, i.config, nextHop, paymentHash, request.Onion.ForwardMsat, request.Htlc.CltvExpiry)
|
||||
switch interceptResult.action {
|
||||
case INTERCEPT_RESUME_WITH_ONION:
|
||||
interceptorClient.Send(i.resumeWithOnion(request, interceptResult))
|
||||
|
||||
@@ -45,7 +45,7 @@ type interceptResult struct {
|
||||
onionBlob []byte
|
||||
}
|
||||
|
||||
func intercept(client LightningClient, config *NodeConfig, reqPaymentHash []byte, reqOutgoingAmountMsat uint64, reqOutgoingExpiry uint32) interceptResult {
|
||||
func intercept(client LightningClient, config *NodeConfig, nextHop string, reqPaymentHash []byte, reqOutgoingAmountMsat uint64, reqOutgoingExpiry uint32) interceptResult {
|
||||
reqPaymentHashStr := hex.EncodeToString(reqPaymentHash)
|
||||
resp, _, _ := payHashGroup.Do(reqPaymentHashStr, func() (interface{}, error) {
|
||||
paymentHash, paymentSecret, destination, incomingAmountMsat, outgoingAmountMsat, channelPoint, err := paymentInfo(reqPaymentHash)
|
||||
@@ -58,7 +58,7 @@ func intercept(client LightningClient, config *NodeConfig, reqPaymentHash []byte
|
||||
}
|
||||
log.Printf("paymentHash:%x\npaymentSecret:%x\ndestination:%x\nincomingAmountMsat:%v\noutgoingAmountMsat:%v",
|
||||
paymentHash, paymentSecret, destination, incomingAmountMsat, outgoingAmountMsat)
|
||||
if paymentSecret == nil {
|
||||
if paymentSecret == nil || (nextHop != "<unknown>" && nextHop != hex.EncodeToString(destination)) {
|
||||
return interceptResult{
|
||||
action: INTERCEPT_RESUME,
|
||||
}, nil
|
||||
|
||||
@@ -123,9 +123,21 @@ func (i *LndHtlcInterceptor) intercept() error {
|
||||
break
|
||||
}
|
||||
|
||||
fmt.Printf("htlc: %v\nchanID: %v\nincoming amount: %v\noutgoing amount: %v\nincomin expiry: %v\noutgoing expiry: %v\npaymentHash: %x\nonionBlob: %x\n\n",
|
||||
nextHop := "<unknown>"
|
||||
chanInfo, err := i.client.client.GetChanInfo(context.Background(), &lnrpc.ChanInfoRequest{ChanId: request.OutgoingRequestedChanId})
|
||||
if err == nil && chanInfo != nil {
|
||||
if chanInfo.Node1Pub == i.config.NodePubkey {
|
||||
nextHop = chanInfo.Node2Pub
|
||||
}
|
||||
if chanInfo.Node2Pub == i.config.NodePubkey {
|
||||
nextHop = chanInfo.Node1Pub
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("htlc: %v\nchanID: %v\nnextHop: %v\nincoming amount: %v\noutgoing amount: %v\nincomin expiry: %v\noutgoing expiry: %v\npaymentHash: %x\nonionBlob: %x\n\n",
|
||||
request.IncomingCircuitKey.HtlcId,
|
||||
request.IncomingCircuitKey.ChanId,
|
||||
nextHop,
|
||||
request.IncomingAmountMsat,
|
||||
request.OutgoingAmountMsat,
|
||||
request.IncomingExpiry,
|
||||
@@ -136,7 +148,7 @@ func (i *LndHtlcInterceptor) intercept() error {
|
||||
|
||||
i.doneWg.Add(1)
|
||||
go func() {
|
||||
interceptResult := intercept(i.client, i.config, request.PaymentHash, request.OutgoingAmountMsat, request.OutgoingExpiry)
|
||||
interceptResult := intercept(i.client, i.config, nextHop, request.PaymentHash, request.OutgoingAmountMsat, request.OutgoingExpiry)
|
||||
switch interceptResult.action {
|
||||
case INTERCEPT_RESUME_WITH_ONION:
|
||||
interceptorClient.Send(&routerrpc.ForwardHtlcInterceptResponse{
|
||||
|
||||
Reference in New Issue
Block a user