Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added command to get gas cap for any evm chain #409

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion cmd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,40 @@ func debugCmd(a *appState) *cobra.Command {
queryCmd.Flags().Uint64Var(&state.fromHeight, "from_height", 0, "From Height")
queryCmd.Flags().Uint64Var(&state.toHeight, "to_height", 0, "To height")
queryCmd.MarkFlagsRequiredTogether("chain", "from_height", "to_height")
debug.AddCommand(heightCmd, blockCmd, queryCmd)
debug.AddCommand(heightCmd, blockCmd, queryCmd, state.getSuggestedGasCap(a))

return debug
}

func (c *DebugState) getSuggestedGasCap(app *appState) *cobra.Command {
getSuggestedGasCap := &cobra.Command{
Use: "gas-cap",
Short: "Get the suggested gas cap for evm chains",
Aliases: []string{"g"},
Example: strings.TrimSpace(fmt.Sprintf(`$ %s dbg gas --chain [chain-id]`, appName)),
RunE: func(cmd *cobra.Command, args []string) error {
client, err := c.getSocket(app)
if err != nil {
return err
}
defer client.Close()
if c.server != nil {
defer c.server.Close()
}
res, err := client.GetGasCap(c.chain)
if err != nil {
return err
}
printLabels("Chain", "Suggested Gas Cap")
printValues(c.chain, res.Cap)
return nil
},
}
getSuggestedGasCap.Flags().StringVar(&c.chain, "chain", "", "Chain ID")
getSuggestedGasCap.MarkFlagRequired("chain")
return getSuggestedGasCap
}

func (c *DebugState) getLatestHeight(app *appState) *cobra.Command {
getLatestHeight := &cobra.Command{
Use: "get",
Expand Down
9 changes: 9 additions & 0 deletions relayer/chains/evm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,12 @@ func (p *Provider) QueryBlockMessages(ctx context.Context, fromHeight, toHeight
}
return messages, nil
}

func (p *Provider) QueryGasTip(ctx context.Context) *big.Int {
gasPrice, err := p.client.SuggestGasPrice(ctx)
if err != nil {
return nil
}
return gasPrice

}
4 changes: 4 additions & 0 deletions relayer/chains/icon/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,7 @@ func (p *Provider) SetLastSavedHeightFunc(f func() uint64) {
func (p *Provider) GetLastSavedBlockHeight() uint64 {
return p.LastSavedHeightFunc()
}

func (p *Provider) QueryGasTip(context.Context) *big.Int {
return nil
}
4 changes: 4 additions & 0 deletions relayer/chains/mockchain/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,7 @@ func (p *MockProvider) GetLastProcessedBlockHeight(ctx context.Context) (uint64,
func (p *MockProvider) QueryBlockMessages(ctx context.Context, fromHeight, toHeight uint64) ([]*types.Message, error) {
return nil, nil
}

func (p *MockProvider) QueryGasTip(context.Context) *big.Int {
return nil
}
4 changes: 4 additions & 0 deletions relayer/chains/solana/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,3 +547,7 @@ func (p *Provider) queryRevertMessageAccounts(

return &acRes, nil
}

func (p *Provider) QueryGasTip(context.Context) *big.Int {
return nil
}
4 changes: 4 additions & 0 deletions relayer/chains/steller/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,7 @@ func (p *Provider) ShouldSendMessage(ctx context.Context, messageKey *relayertyp
func (p *Provider) SetLastSavedHeightFunc(f func() uint64) {
p.LastSavedHeightFunc = f
}

func (p *Provider) QueryGasTip(context.Context) *big.Int {
return nil
}
1 change: 1 addition & 0 deletions relayer/chains/sui/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ func TestRestoreKey(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, expectedAddr, key.Address)
assert.Equal(t, expectedPrivKey, hex.EncodeToString(key.KeyPair.PrivateKey()[:32]))

}
4 changes: 4 additions & 0 deletions relayer/chains/sui/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,7 @@ func (p *Provider) ShouldReceiveMessage(ctx context.Context, messagekey *relayer
func (p *Provider) ShouldSendMessage(ctx context.Context, messageKey *relayertypes.Message) (bool, error) {
return true, nil
}

func (p *Provider) QueryGasTip(context.Context) *big.Int {
return nil
}
4 changes: 4 additions & 0 deletions relayer/chains/wasm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -927,3 +927,7 @@ func (p *Provider) QueryBlockMessages(ctx context.Context, fromHeight, toHeight
}
return messages, nil
}

func (p *Provider) QueryGasTip(context.Context) *big.Int {
return nil
}
1 change: 1 addition & 0 deletions relayer/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type ChainProvider interface {
GetFee(context.Context, string, bool) (uint64, error)
SetFee(context.Context, string, *big.Int, *big.Int) error
ClaimFee(context.Context) error
QueryGasTip(context.Context) *big.Int
}

// CommonConfig is the common configuration for all chain providers
Expand Down
19 changes: 19 additions & 0 deletions relayer/socket/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
EventRelayerInfo Event = "RelayerInfo"
EventMessageReceived Event = "MessageReceived"
EventGetBlockEvents Event = "GetBlockEvents"
EventGetGasCap Event = "EventGetGasTip"
)

var (
Expand Down Expand Up @@ -310,3 +311,21 @@ func parseResData(data any, dest interface{}) error {

return nil
}

func (c *Client) GetGasCap(chain string) (*ResChainGasCap, error) {
req := &ReqChainGasCap{Chain: chain}
if err := c.send(&Request{Event: EventGetGasCap, Data: req}); err != nil {
return nil, err
}
res, err := c.read()
if err != nil {
return nil, err
}

resData := new(ResChainGasCap)
if err := parseResData(res.Data, &resData); err != nil {
return nil, err
}

return resData, nil
}
11 changes: 11 additions & 0 deletions relayer/socket/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,17 @@ func (s *Server) parseEvent(msg *Request) *Response {
}
}
return response.SetData(events)
case EventGetGasCap:
req := new(ReqChainGasCap)
if err := jsoniter.Unmarshal(data, req); err != nil {
return response.SetError(err)
}
chain, err := s.rly.FindChainRuntime(req.Chain)
if err != nil {
return response.SetError(err)
}
gasCap := chain.Provider.QueryGasTip(context.Background())
return response.SetData(&ResChainGasCap{Chain: req.Chain, Cap: gasCap})
default:
return response.SetError(fmt.Errorf("unknown event %s", msg.Event))
}
Expand Down
9 changes: 9 additions & 0 deletions relayer/socket/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,12 @@ type ResGetBlockEvents struct {
type ChainProviderError struct {
Message string
}

type ReqChainGasCap struct {
Chain string `json:"chain"`
}

type ResChainGasCap struct {
Chain string `json:"chain"`
Cap *big.Int `json:"cap"`
}
Loading