Skip to content

Commit

Permalink
[Feature] - Fix falcon chain connection (#20)
Browse files Browse the repository at this point in the history
* add loadsender to new chain

* patch chain version

* fix

* fix lint

* change logic

* refactor code

* combine connect to init

* fix gas estimation

---------

Co-authored-by: Tanut Lertwarachai <tanutlertwarachai@Tanuts-MacBook-Pro.local>
Co-authored-by: nkitlabs <natthakunk0109@gmail.com>
  • Loading branch information
3 people authored Dec 12, 2024
1 parent 97c6db4 commit cc9e9af
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 16 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.3
require (
cosmossdk.io/math v1.4.0
cosmossdk.io/x/tx v0.13.5
github.com/bandprotocol/chain/v3 v3.0.0-20241202095241-21710ba55161
github.com/bandprotocol/chain/v3 v3.0.0-20241203075418-774ab7177a89
github.com/charmbracelet/huh v0.6.0
github.com/cometbft/cometbft v0.38.12
github.com/cosmos/cosmos-sdk v0.50.10
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ github.com/aws/aws-sdk-go v1.44.224/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/bandprotocol/chain/v3 v3.0.0-20241202095241-21710ba55161 h1:WMKRzgZL3OEiW2AbIzlYiHOplKY3ZBimTTPFNi8OhNA=
github.com/bandprotocol/chain/v3 v3.0.0-20241202095241-21710ba55161/go.mod h1:7609g+Iyhar8ySbKEJiqHfRq8xwJh5r2YE5vBebXMS4=
github.com/bandprotocol/chain/v3 v3.0.0-20241203075418-774ab7177a89 h1:l+b89+gNcBZQ6R7/hmDaw8jHgzQ4k5oQdSMK9/ZOkkI=
github.com/bandprotocol/chain/v3 v3.0.0-20241203075418-774ab7177a89/go.mod h1:7609g+Iyhar8ySbKEJiqHfRq8xwJh5r2YE5vBebXMS4=
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/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
Expand Down
38 changes: 25 additions & 13 deletions relayer/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (a *App) Init(ctx context.Context) error {
}

// initialize target chains
if err := a.initTargetChains(ctx); err != nil {
if err := a.initTargetChains(); err != nil {
return err
}

Expand Down Expand Up @@ -126,7 +126,7 @@ func (a *App) initLogger(configLogLevel string) error {
}

// InitTargetChains initializes the target chains.
func (a *App) initTargetChains(ctx context.Context) error {
func (a *App) initTargetChains() error {
a.targetChains = make(chains.ChainProviders)
if a.Config == nil || a.Config.TargetChains == nil {
a.Log.Error("Target chains not found in config")
Expand All @@ -143,13 +143,6 @@ func (a *App) initTargetChains(ctx context.Context) error {
return err
}

if err := cp.Init(ctx); err != nil {
a.Log.Error("Cannot initialize chain provider",
zap.Error(err),
zap.String("chain_name", chainName),
)
return err
}
a.targetChains[chainName] = cp
}
return nil
Expand Down Expand Up @@ -590,16 +583,30 @@ func (a *App) Start(ctx context.Context, tunnelIDs []uint64) error {
return err
}

for chainName, chainProvider := range a.targetChains {
if err := chainProvider.LoadFreeSenders(a.HomePath, a.EnvPassphrase); err != nil {
a.Log.Error("Cannot load keys in target chain",
zap.Error(err),
zap.String("chain_name", chainName),
)
return err
}

if err := chainProvider.Init(ctx); err != nil {
a.Log.Error("Cannot initialize chain provider",
zap.Error(err),
zap.String("chain_name", chainName),
)
return err
}
}

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

if err := chainProvider.LoadFreeSenders(a.HomePath, a.EnvPassphrase); err != nil {
return err
}

tr := NewTunnelRelayer(
a.Log,
tunnel.ID,
Expand All @@ -623,6 +630,7 @@ func (a *App) Start(ctx context.Context, tunnelIDs []uint64) error {
a.BandClient,
a.targetChains,
)

return scheduler.Start(ctx)
}

Expand All @@ -644,6 +652,10 @@ func (a *App) Relay(ctx context.Context, tunnelID uint64) error {
}

if err := chainProvider.LoadFreeSenders(a.HomePath, a.EnvPassphrase); err != nil {
a.Log.Error("Cannot load keys in target chain",
zap.Error(err),
zap.String("chain_name", tunnel.TargetChainID),
)
return err
}

Expand Down
3 changes: 3 additions & 0 deletions relayer/chains/evm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ func (c *client) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64,
return 0, fmt.Errorf("[EVMClient] failed to estimate gas: %w", err)
}

// NOTE: Add 20% buffer to the estimated gas.
gas = gas * 120 / 100

return gas, nil
}

Expand Down
4 changes: 4 additions & 0 deletions relayer/chains/evm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func NewEVMChainProvider(

// Connect connects to the EVM chain.
func (cp *EVMChainProvider) Init(ctx context.Context) error {
if err := cp.Client.Connect(ctx); err != nil {
return err
}

go cp.Client.StartLivelinessCheck(ctx, cp.Config.LivelinessCheckingInterval)

return nil
Expand Down

0 comments on commit cc9e9af

Please sign in to comment.