diff --git a/channelAcceptor.go b/channelAcceptor.go index 6f27168..9a4fbe9 100644 --- a/channelAcceptor.go +++ b/channelAcceptor.go @@ -150,7 +150,7 @@ func (app *App) logChannelEvents(ctx context.Context) error { event.GetOpenChannel().Capacity, 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()) } diff --git a/go.mod b/go.mod index 2d26792..2e5978a 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/callebtc/electronwall go 1.16 require ( + github.com/aarzilli/golua v0.0.0-20210507130708-11106aa57765 // indirect github.com/jinzhu/configor v1.2.1 github.com/lightningnetwork/lnd v0.14.3-beta github.com/sirupsen/logrus v1.8.1 diff --git a/go.sum b/go.sum index b8bb2ab..e45edb8 100644 --- a/go.sum +++ b/go.sum @@ -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/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/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/go.mod h1:eHEWzANqSiWQsof+nXEI9bUVUyV6F53Fp89EuCh2EAA= github.com/aead/siphash v1.0.1 h1:FwHfE/T45KPKYuuSAKyyvE+oPWcaQ+CUmFW0bPlM+kg= diff --git a/helpers.go b/helpers.go index 3e11457..64e61b3 100644 --- a/helpers.go +++ b/helpers.go @@ -44,9 +44,12 @@ func intToHex(i int64) string { 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() hexstr := hex.EncodeToString(byte_e) + if len(hexstr) < 12 { + return "" + } int_block3, _ := strconv.ParseInt(hexstr[:6], 16, 64) int_block2, _ := strconv.ParseInt(hexstr[6:12], 16, 64) int_block1, _ := strconv.ParseInt(hexstr[12:], 16, 64) diff --git a/htlcInterceptor.go b/htlcInterceptor.go index c64b861..50e1740 100644 --- a/htlcInterceptor.go +++ b/htlcInterceptor.go @@ -52,7 +52,7 @@ func (app *App) interceptHtlcEvents(ctx context.Context) error { channelEdge, err := app.lnd.getPubKeyFromChannel(ctx, event.IncomingCircuitKey.ChanId) 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 @@ -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 channelEdgeTo, err := app.lnd.getPubKeyFromChannel(ctx, event.OutgoingRequestedChanId) 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 { pubkeyTo = channelEdgeTo.Node1Pub @@ -89,8 +89,8 @@ func (app *App) interceptHtlcEvents(ctx context.Context) error { aliasFrom, aliasTo, event.IncomingAmountMsat/1000, - parse_channelID(event.IncomingCircuitKey.ChanId), - parse_channelID(event.OutgoingRequestedChanId), + ParseChannelID(event.IncomingCircuitKey.ChanId), + ParseChannelID(event.OutgoingRequestedChanId), 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 split := strings.Split(forward_list_entry, "->") from_channel_id, to_channel_id := split[0], split[1] - if (parse_channelID(event.IncomingCircuitKey.ChanId) == from_channel_id || from_channel_id == "*") && - (parse_channelID(event.OutgoingRequestedChanId) == to_channel_id || to_channel_id == "*") { + if (ParseChannelID(event.IncomingCircuitKey.ChanId) == from_channel_id || from_channel_id == "*") && + (ParseChannelID(event.OutgoingRequestedChanId) == to_channel_id || to_channel_id == "*") { 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 } } else { // single entry - if parse_channelID(event.IncomingCircuitKey.ChanId) == forward_list_entry { + if ParseChannelID(event.IncomingCircuitKey.ChanId) == forward_list_entry { accept = !accept break } @@ -183,16 +183,16 @@ func (app *App) logHtlcEvents(ctx context.Context) error { switch event.Event.(type) { 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: - 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: - 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: - 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) } }