From e0b019e80a0ca40ac98a00dd5a4c2104f0dcaeb2 Mon Sep 17 00:00:00 2001 From: "Biru C. Sainju" Date: Mon, 28 Oct 2024 12:23:04 +0545 Subject: [PATCH 1/2] feat: added command to get suggested fee cap for evm chains --- cmd/debug.go | 31 +++++++++++++++++++++++++++- relayer/chains/evm/provider.go | 9 ++++++++ relayer/chains/icon/provider.go | 4 ++++ relayer/chains/mockchain/provider.go | 4 ++++ relayer/chains/solana/provider.go | 4 ++++ relayer/chains/steller/provider.go | 4 ++++ relayer/chains/sui/keys_test.go | 10 +++++++++ relayer/chains/sui/provider.go | 4 ++++ relayer/chains/wasm/provider.go | 4 ++++ relayer/provider/provider.go | 1 + relayer/socket/client.go | 19 +++++++++++++++++ relayer/socket/server.go | 11 ++++++++++ relayer/socket/types.go | 9 ++++++++ 13 files changed, 113 insertions(+), 1 deletion(-) diff --git a/cmd/debug.go b/cmd/debug.go index c905dcd4..a2ab869d 100644 --- a/cmd/debug.go +++ b/cmd/debug.go @@ -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", diff --git a/relayer/chains/evm/provider.go b/relayer/chains/evm/provider.go index 3974dce2..fa9f10fa 100644 --- a/relayer/chains/evm/provider.go +++ b/relayer/chains/evm/provider.go @@ -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 + +} diff --git a/relayer/chains/icon/provider.go b/relayer/chains/icon/provider.go index bc7bb2c3..98825f19 100644 --- a/relayer/chains/icon/provider.go +++ b/relayer/chains/icon/provider.go @@ -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 +} diff --git a/relayer/chains/mockchain/provider.go b/relayer/chains/mockchain/provider.go index 6a3a5d9f..c6ead66c 100644 --- a/relayer/chains/mockchain/provider.go +++ b/relayer/chains/mockchain/provider.go @@ -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 +} diff --git a/relayer/chains/solana/provider.go b/relayer/chains/solana/provider.go index 576fdebe..0f2467c9 100644 --- a/relayer/chains/solana/provider.go +++ b/relayer/chains/solana/provider.go @@ -547,3 +547,7 @@ func (p *Provider) queryRevertMessageAccounts( return &acRes, nil } + +func (p *Provider) QueryGasTip(context.Context) *big.Int { + return nil +} diff --git a/relayer/chains/steller/provider.go b/relayer/chains/steller/provider.go index 948b150d..acd1d318 100644 --- a/relayer/chains/steller/provider.go +++ b/relayer/chains/steller/provider.go @@ -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 +} diff --git a/relayer/chains/sui/keys_test.go b/relayer/chains/sui/keys_test.go index 0cadb1d9..55db92e6 100644 --- a/relayer/chains/sui/keys_test.go +++ b/relayer/chains/sui/keys_test.go @@ -2,8 +2,10 @@ package sui import ( "encoding/hex" + "fmt" "testing" + "github.com/coming-chat/go-sui/v2/sui_types" "github.com/stretchr/testify/assert" ) @@ -18,4 +20,12 @@ 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])) + + sign, _ := key.SignSecureWithoutEncode([]byte("helloworld"), sui_types.DefaultIntent()) + signs := sign.Ed25519SuiSignature.Signature + // ms, _ := sign.MarshalJSON() + fmt.Println(hex.EncodeToString(key.KeyPair.PublicKey())) + fmt.Println(key.Address) + + fmt.Println("message", hex.EncodeToString(signs[:])) } diff --git a/relayer/chains/sui/provider.go b/relayer/chains/sui/provider.go index 5af1ded8..3a7b4e7a 100644 --- a/relayer/chains/sui/provider.go +++ b/relayer/chains/sui/provider.go @@ -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 +} diff --git a/relayer/chains/wasm/provider.go b/relayer/chains/wasm/provider.go index 652eb111..2748c552 100644 --- a/relayer/chains/wasm/provider.go +++ b/relayer/chains/wasm/provider.go @@ -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 +} diff --git a/relayer/provider/provider.go b/relayer/provider/provider.go index 29d6139c..0c977aa9 100644 --- a/relayer/provider/provider.go +++ b/relayer/provider/provider.go @@ -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 diff --git a/relayer/socket/client.go b/relayer/socket/client.go index 68815056..2523e427 100644 --- a/relayer/socket/client.go +++ b/relayer/socket/client.go @@ -29,6 +29,7 @@ const ( EventRelayerInfo Event = "RelayerInfo" EventMessageReceived Event = "MessageReceived" EventGetBlockEvents Event = "GetBlockEvents" + EventGetGasCap Event = "EventGetGasTip" ) var ( @@ -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 +} diff --git a/relayer/socket/server.go b/relayer/socket/server.go index 8297662f..fa43be91 100644 --- a/relayer/socket/server.go +++ b/relayer/socket/server.go @@ -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)) } diff --git a/relayer/socket/types.go b/relayer/socket/types.go index 206d606e..e9026054 100644 --- a/relayer/socket/types.go +++ b/relayer/socket/types.go @@ -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"` +} From d12d2e0cb2e4a23f2737b8833eaa48ae63369c43 Mon Sep 17 00:00:00 2001 From: "Biru C. Sainju" Date: Tue, 29 Oct 2024 10:05:50 +0545 Subject: [PATCH 2/2] feat: revert unintended changes --- relayer/chains/sui/keys_test.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/relayer/chains/sui/keys_test.go b/relayer/chains/sui/keys_test.go index 55db92e6..58bb6348 100644 --- a/relayer/chains/sui/keys_test.go +++ b/relayer/chains/sui/keys_test.go @@ -2,10 +2,8 @@ package sui import ( "encoding/hex" - "fmt" "testing" - "github.com/coming-chat/go-sui/v2/sui_types" "github.com/stretchr/testify/assert" ) @@ -21,11 +19,4 @@ func TestRestoreKey(t *testing.T) { assert.Equal(t, expectedAddr, key.Address) assert.Equal(t, expectedPrivKey, hex.EncodeToString(key.KeyPair.PrivateKey()[:32])) - sign, _ := key.SignSecureWithoutEncode([]byte("helloworld"), sui_types.DefaultIntent()) - signs := sign.Ed25519SuiSignature.Signature - // ms, _ := sign.MarshalJSON() - fmt.Println(hex.EncodeToString(key.KeyPair.PublicKey())) - fmt.Println(key.Address) - - fmt.Println("message", hex.EncodeToString(signs[:])) }