This commit is contained in:
callebtc
2022-07-11 13:14:50 +02:00
parent a308fd8ead
commit 746e616b8e
5 changed files with 20 additions and 14 deletions

View File

@@ -150,7 +150,7 @@ func (app *App) logChannelEvents(ctx context.Context) error {
event.GetOpenChannel().Capacity, event.GetOpenChannel().Capacity,
alias, alias,
) )
log.Infof("[channel] Opened channel %s %s", parse_channelID(event.GetOpenChannel().ChanId), channel_info_string) log.Infof("[channel] Opened channel %s %s", ParseChannelID(event.GetOpenChannel().ChanId), channel_info_string)
} }
log.Tracef("[channel] Event: %s", event.String()) log.Tracef("[channel] Event: %s", event.String())
} }

1
go.mod
View File

@@ -3,6 +3,7 @@ module github.com/callebtc/electronwall
go 1.16 go 1.16
require ( require (
github.com/aarzilli/golua v0.0.0-20210507130708-11106aa57765 // indirect
github.com/jinzhu/configor v1.2.1 github.com/jinzhu/configor v1.2.1
github.com/lightningnetwork/lnd v0.14.3-beta github.com/lightningnetwork/lnd v0.14.3-beta
github.com/sirupsen/logrus v1.8.1 github.com/sirupsen/logrus v1.8.1

2
go.sum
View File

@@ -46,6 +46,8 @@ github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAE
github.com/OpenPeeDeeP/depguard v1.0.0/go.mod h1:7/4sitnI9YlQgTLLk734QlzXT8DuHVnAyztLplQjk+o= github.com/OpenPeeDeeP/depguard v1.0.0/go.mod h1:7/4sitnI9YlQgTLLk734QlzXT8DuHVnAyztLplQjk+o=
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/Yawning/aez v0.0.0-20180114000226-4dad034d9db2/go.mod h1:9pIqrY6SXNL8vjRQE5Hd/OL5GyK/9MrGUWs87z/eFfk= github.com/Yawning/aez v0.0.0-20180114000226-4dad034d9db2/go.mod h1:9pIqrY6SXNL8vjRQE5Hd/OL5GyK/9MrGUWs87z/eFfk=
github.com/aarzilli/golua v0.0.0-20210507130708-11106aa57765 h1:N6gB4UCRBZz8twlJbMFiCKj0zX5Et2nFU/LRafT4x80=
github.com/aarzilli/golua v0.0.0-20210507130708-11106aa57765/go.mod h1:hMjfaJVSqVnxenMlsxrq3Ni+vrm9Hs64tU4M7dhUoO4=
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da h1:KjTM2ks9d14ZYCvmHS9iAKVt9AyzRSqNU1qabPih5BY= github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da h1:KjTM2ks9d14ZYCvmHS9iAKVt9AyzRSqNU1qabPih5BY=
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da/go.mod h1:eHEWzANqSiWQsof+nXEI9bUVUyV6F53Fp89EuCh2EAA= github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da/go.mod h1:eHEWzANqSiWQsof+nXEI9bUVUyV6F53Fp89EuCh2EAA=
github.com/aead/siphash v1.0.1 h1:FwHfE/T45KPKYuuSAKyyvE+oPWcaQ+CUmFW0bPlM+kg= github.com/aead/siphash v1.0.1 h1:FwHfE/T45KPKYuuSAKyyvE+oPWcaQ+CUmFW0bPlM+kg=

View File

@@ -44,9 +44,12 @@ func intToHex(i int64) string {
return hex.EncodeToString(big.NewInt(i).Bytes()) return hex.EncodeToString(big.NewInt(i).Bytes())
} }
func parse_channelID(e uint64) string { func ParseChannelID(e uint64) string {
byte_e := big.NewInt(int64(e)).Bytes() byte_e := big.NewInt(int64(e)).Bytes()
hexstr := hex.EncodeToString(byte_e) hexstr := hex.EncodeToString(byte_e)
if len(hexstr) < 12 {
return ""
}
int_block3, _ := strconv.ParseInt(hexstr[:6], 16, 64) int_block3, _ := strconv.ParseInt(hexstr[:6], 16, 64)
int_block2, _ := strconv.ParseInt(hexstr[6:12], 16, 64) int_block2, _ := strconv.ParseInt(hexstr[6:12], 16, 64)
int_block1, _ := strconv.ParseInt(hexstr[12:], 16, 64) int_block1, _ := strconv.ParseInt(hexstr[12:], 16, 64)

View File

@@ -52,7 +52,7 @@ func (app *App) interceptHtlcEvents(ctx context.Context) error {
channelEdge, err := app.lnd.getPubKeyFromChannel(ctx, event.IncomingCircuitKey.ChanId) channelEdge, err := app.lnd.getPubKeyFromChannel(ctx, event.IncomingCircuitKey.ChanId)
if err != nil { if err != nil {
log.Errorf("[forward] Error getting pubkey for channel %s", parse_channelID(event.IncomingCircuitKey.ChanId)) log.Errorf("[forward] Error getting pubkey for channel %s", ParseChannelID(event.IncomingCircuitKey.ChanId))
} }
var pubkeyFrom, aliasFrom, pubkeyTo, aliasTo string var pubkeyFrom, aliasFrom, pubkeyTo, aliasTo string
@@ -70,7 +70,7 @@ func (app *App) interceptHtlcEvents(ctx context.Context) error {
// we need to figure out which side of the channel is the other end // we need to figure out which side of the channel is the other end
channelEdgeTo, err := app.lnd.getPubKeyFromChannel(ctx, event.OutgoingRequestedChanId) channelEdgeTo, err := app.lnd.getPubKeyFromChannel(ctx, event.OutgoingRequestedChanId)
if err != nil { if err != nil {
log.Errorf("[forward] Error getting pubkey for channel %s", parse_channelID(event.OutgoingRequestedChanId)) log.Errorf("[forward] Error getting pubkey for channel %s", ParseChannelID(event.OutgoingRequestedChanId))
} }
if channelEdgeTo.Node1Pub != app.myInfo.IdentityPubkey { if channelEdgeTo.Node1Pub != app.myInfo.IdentityPubkey {
pubkeyTo = channelEdgeTo.Node1Pub pubkeyTo = channelEdgeTo.Node1Pub
@@ -89,8 +89,8 @@ func (app *App) interceptHtlcEvents(ctx context.Context) error {
aliasFrom, aliasFrom,
aliasTo, aliasTo,
event.IncomingAmountMsat/1000, event.IncomingAmountMsat/1000,
parse_channelID(event.IncomingCircuitKey.ChanId), ParseChannelID(event.IncomingCircuitKey.ChanId),
parse_channelID(event.OutgoingRequestedChanId), ParseChannelID(event.OutgoingRequestedChanId),
event.IncomingCircuitKey.HtlcId, event.IncomingCircuitKey.HtlcId,
) )
@@ -146,15 +146,15 @@ func (app *App) htlcInterceptDecision(ctx context.Context, event *routerrpc.Forw
// check if entry is a pair of from->to // check if entry is a pair of from->to
split := strings.Split(forward_list_entry, "->") split := strings.Split(forward_list_entry, "->")
from_channel_id, to_channel_id := split[0], split[1] from_channel_id, to_channel_id := split[0], split[1]
if (parse_channelID(event.IncomingCircuitKey.ChanId) == from_channel_id || from_channel_id == "*") && if (ParseChannelID(event.IncomingCircuitKey.ChanId) == from_channel_id || from_channel_id == "*") &&
(parse_channelID(event.OutgoingRequestedChanId) == to_channel_id || to_channel_id == "*") { (ParseChannelID(event.OutgoingRequestedChanId) == to_channel_id || to_channel_id == "*") {
accept = !accept accept = !accept
log.Tracef("[test] Incoming: %s <-> %s, Outgoing: %s <-> %s", parse_channelID(event.IncomingCircuitKey.ChanId), from_channel_id, parse_channelID(event.OutgoingRequestedChanId), to_channel_id) log.Tracef("[test] Incoming: %s <-> %s, Outgoing: %s <-> %s", ParseChannelID(event.IncomingCircuitKey.ChanId), from_channel_id, ParseChannelID(event.OutgoingRequestedChanId), to_channel_id)
break break
} }
} else { } else {
// single entry // single entry
if parse_channelID(event.IncomingCircuitKey.ChanId) == forward_list_entry { if ParseChannelID(event.IncomingCircuitKey.ChanId) == forward_list_entry {
accept = !accept accept = !accept
break break
} }
@@ -183,16 +183,16 @@ func (app *App) logHtlcEvents(ctx context.Context) error {
switch event.Event.(type) { switch event.Event.(type) {
case *routerrpc.HtlcEvent_SettleEvent: case *routerrpc.HtlcEvent_SettleEvent:
log.Debugf("[forward] ⚡️ HTLC SettleEvent (chan_id:%s, htlc_id:%d)", parse_channelID(event.IncomingChannelId), event.IncomingHtlcId) log.Debugf("[forward] ⚡️ HTLC SettleEvent (chan_id:%s, htlc_id:%d)", ParseChannelID(event.IncomingChannelId), event.IncomingHtlcId)
case *routerrpc.HtlcEvent_ForwardFailEvent: case *routerrpc.HtlcEvent_ForwardFailEvent:
log.Debugf("[forward] HTLC ForwardFailEvent (chan_id:%s, htlc_id:%d)", parse_channelID(event.IncomingChannelId), event.IncomingHtlcId) log.Debugf("[forward] HTLC ForwardFailEvent (chan_id:%s, htlc_id:%d)", ParseChannelID(event.IncomingChannelId), event.IncomingHtlcId)
case *routerrpc.HtlcEvent_ForwardEvent: case *routerrpc.HtlcEvent_ForwardEvent:
log.Debugf("[forward] HTLC ForwardEvent (chan_id:%s, htlc_id:%d)", parse_channelID(event.IncomingChannelId), event.IncomingHtlcId) log.Debugf("[forward] HTLC ForwardEvent (chan_id:%s, htlc_id:%d)", ParseChannelID(event.IncomingChannelId), event.IncomingHtlcId)
case *routerrpc.HtlcEvent_LinkFailEvent: case *routerrpc.HtlcEvent_LinkFailEvent:
log.Debugf("[forward] HTLC LinkFailEvent (chan_id:%s, htlc_id:%d)", parse_channelID(event.IncomingChannelId), event.IncomingHtlcId) log.Debugf("[forward] HTLC LinkFailEvent (chan_id:%s, htlc_id:%d)", ParseChannelID(event.IncomingChannelId), event.IncomingHtlcId)
} }
} }