Skip to content

Commit

Permalink
fix relay tx
Browse files Browse the repository at this point in the history
  • Loading branch information
nkitlabs committed Nov 1, 2024
1 parent 59a4856 commit 27484ce
Show file tree
Hide file tree
Showing 13 changed files with 185 additions and 124 deletions.
15 changes: 10 additions & 5 deletions cmd/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"strconv"
"strings"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -33,13 +34,17 @@ func txRelayCmd(app *relayer.App) *cobra.Command {
cmd := &cobra.Command{
Use: "relay [tunnel_id]",
Aliases: []string{"rly"},
Short: "Relay a specific message to the destination chain",
Args: withUsage(cobra.ExactArgs(2)),
Short: "Relay the next sequence message to the destination tunnel contract address",
Args: withUsage(cobra.ExactArgs(1)),
Example: strings.TrimSpace(fmt.Sprintf(`
$ %s tx relay 1 1, # relay the message with tunnelID 1 and sequence 1`, appName)),
$ %s tx relay 1, # relay the next sequence message of the tunnelID 1`, appName)),
RunE: func(cmd *cobra.Command, args []string) error {
_ = app
return nil
tunnelID, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return err
}

return app.Relay(cmd.Context(), tunnelID)
},
}

Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ require (
github.com/99designs/keyring v1.2.1 // indirect
github.com/DataDog/datadog-go v3.2.0+incompatible // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/Masterminds/semver/v3 v3.3.0 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/bandprotocol/go-owasm v0.3.1 // indirect
Expand Down Expand Up @@ -128,7 +129,7 @@ require (
github.com/petermattis/goid v0.0.0-20231207134359-e60b3f734c67 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.20.1 // indirect
github.com/prometheus/client_golang v1.20.5 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
Expand Down Expand Up @@ -167,7 +168,6 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
nhooyr.io/websocket v1.8.6 // indirect
Expand All @@ -180,7 +180,7 @@ replace (
// use cosmos fork of keyring
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
// // replace bandprotocol chain with private chain
github.com/bandprotocol/chain/v3 => github.com/bandprotocol/private-chain/v3 v3.0.0-20241022085810-642e764518fa
github.com/bandprotocol/chain/v3 => github.com/bandprotocol/private-chain/v3 v3.0.0-20241031180150-de8d5c14cdde
// replace broken goleveldb
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
// stick with compatible version of rapid in v0.47.x line
Expand Down
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3
github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ=
github.com/DataDog/zstd v1.5.5/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+hmvYS0=
github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
Expand Down Expand Up @@ -61,8 +63,8 @@ github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/bandprotocol/go-owasm v0.3.1 h1:L38qAEmb0KyTICHBHJaBoo6yy5+BlbOzQeQ+ioUV5Uw=
github.com/bandprotocol/go-owasm v0.3.1/go.mod h1:SAzGihlBl8eZDXA1dO2aeAZLm8J2QkNd+KvnA2Dw9Kg=
github.com/bandprotocol/private-chain/v3 v3.0.0-20241022085810-642e764518fa h1:uoMqJVyqsujYl+g2zhz/ztqBPia0HNg1YyDRsLEvDxo=
github.com/bandprotocol/private-chain/v3 v3.0.0-20241022085810-642e764518fa/go.mod h1:gddpk4SowgqQj2Cveg9DVkYO/u7S46Bz8UHoxu1rNdk=
github.com/bandprotocol/private-chain/v3 v3.0.0-20241031180150-de8d5c14cdde h1:BcDHxykep68HARNcu/eJJjrOCN/U/bRiMzbxoV184kE=
github.com/bandprotocol/private-chain/v3 v3.0.0-20241031180150-de8d5c14cdde/go.mod h1:nuzf8uzuukOjHDiawAdrfdP1MaEeZ10rWiNfVbkmtX4=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
Expand Down Expand Up @@ -630,8 +632,8 @@ github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5Fsn
github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og=
github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU=
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
github.com/prometheus/client_golang v1.20.1 h1:IMJXHOD6eARkQpxo8KkhgEVFlBNm+nkrFUyGlIu7Na8=
github.com/prometheus/client_golang v1.20.1/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y=
github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
Expand Down
16 changes: 8 additions & 8 deletions internal/relayertest/mocks/chain_provider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 44 additions & 9 deletions relayer/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,19 +276,54 @@ func (a *App) QueryTunnelPacketInfo(ctx context.Context, tunnelID uint64, sequen
return c.GetTunnelPacket(ctx, tunnelID, sequence)
}

// Relay relays the packet from the source chain to the destination chain.
func (a *App) Relay(ctx context.Context, tunnelID uint64) error {
a.Log.Debug("query tunnel info on band chain", zap.Uint64("tunnel_id", tunnelID))
tunnel, err := a.BandClient.GetTunnel(ctx, tunnelID)
if err != nil {
return err
}

chainProvider, ok := a.targetChains[tunnel.TargetChainID]
if !ok {
return fmt.Errorf("target chain provider not found: %s", tunnel.TargetChainID)
}

tr := NewTunnelRelayer(
a.Log,
tunnel.ID,
tunnel.TargetAddress,
a.Config.Global.CheckingPacketInterval,
a.BandClient,
chainProvider,
)

return tr.CheckAndRelay(ctx)
}

// Start starts the tunnel relayer program.
func (a *App) Start(ctx context.Context, tunnelIDs []uint64) error {
a.Log.Info("starting tunnel relayer")

// TODO: load the tunnel information from the bandchain.
// If len(tunnelIDs == 0), load all tunnels info.
tunnels := []*bandtypes.Tunnel{
{
ID: 1,
LatestSequence: 0,
TargetChainID: "testnet_evm",
TargetAddress: "0x5FbDB2315678afecb367f032d93F642f64180aa3",
},
// query tunnels
var tunnels []bandtypes.Tunnel
if len(tunnelIDs) == 0 {
// TODO: query all tunnels
} else {
tunnels = make([]bandtypes.Tunnel, 0, len(tunnelIDs))
for _, tunnelID := range tunnelIDs {
tunnel, err := a.BandClient.GetTunnel(ctx, tunnelID)
if err != nil {
return err
}
tunnels = append(tunnels, *tunnel)
}
}

// TODO: query tunnels
if len(tunnels) == 0 {
a.Log.Error("no tunnel ID provided")
return fmt.Errorf("no tunnel ID provided")
}

// initialize the tunnel relayer
Expand Down
2 changes: 0 additions & 2 deletions relayer/band/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,12 @@ func MakeEncodingConfig() EncodingConfig {
"tunnel.v1beta1.RouteI",
(*tunneltypes.RouteI)(nil),
&tunneltypes.TSSRoute{},
&tunneltypes.AxelarRoute{},
)

interfaceRegistry.RegisterInterface(
"tunnel.v1beta1.PacketContentI",
(*tunneltypes.PacketContentI)(nil),
&tunneltypes.TSSPacketContent{},
&tunneltypes.AxelarPacketContent{},
)

cdc := codec.NewProtoCodec(interfaceRegistry)
Expand Down
27 changes: 20 additions & 7 deletions relayer/chains/evm/abi/TunnelRouter.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
[
{
"type": "function",
"name": "isActive",
"inputs": [
{ "name": "tunnelID", "type": "uint64", "internalType": "uint64" },
{ "name": "targetAddr", "type": "address", "internalType": "address" }
{ "internalType": "uint64", "name": "tunnelId", "type": "uint64" },
{ "internalType": "address", "name": "addr", "type": "address" }
],
"stateMutability": "view",
"type": "function",
"name": "tunnelInfo",
"outputs": [
{ "name": "is_active", "type": "bool", "internalType": "bool" }
],
"stateMutability": "view"
{
"internalType": "struct ITunnelRouter.TunnelInfo",
"name": "tunnelInfo",
"type": "tuple",
"components": [
{ "internalType": "bool", "name": "isActive", "type": "bool" },
{
"internalType": "uint64",
"name": "latestSequence",
"type": "uint64"
},
{ "internalType": "uint256", "name": "balance", "type": "uint256" }
]
}
]
},
{
"type": "function",
Expand Down
17 changes: 13 additions & 4 deletions relayer/chains/evm/abis.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
package evm

import _ "embed"
import (
_ "embed"
"math/big"
)

//go:embed abi/TunnelRouter.json
var gasPriceTunnelRouterABI string

// TunnelRouterIsActiveOutput defines the output parameters for the TunnelRouter.isActive method.
type TunnelRouterIsActiveOutput struct {
IsActive bool `json:"is_active"`
// TunnelInfoOutput defines the output parameters for the TunnelRouter.isActive method.
type TunnelInfoOutput struct {
IsActive bool `json:"is_active"`
LatestSequence uint64 `json:"latest_sequence"`
Balance *big.Int `json:"balance"`
}

type TunnelInfoOutputRaw struct {
Info TunnelInfoOutput `json:"tunnel_info"`
}
Loading

0 comments on commit 27484ce

Please sign in to comment.