From 5f7a8b3b59b98ba31df01f59bb793deda3a4c682 Mon Sep 17 00:00:00 2001 From: Reece Williams Date: Tue, 3 Sep 2024 09:13:58 -0500 Subject: [PATCH] refactor: rename rclient -> cclient (consensus client) --- {client => cclient}/cmbft_client_wrapper.go | 7 ++-- {client => cclient}/cmbft_consensus.go | 5 ++- {client => cclient}/consensus.go | 5 ++- interchaintest/feegrant_test.go | 4 +-- .../chains/cosmos/cosmos_chain_processor.go | 6 ++-- relayer/chains/cosmos/provider.go | 6 ++-- relayer/chains/cosmos/query.go | 4 +-- relayer/chains/cosmos/tx.go | 4 +-- .../penumbra/penumbra_chain_processor.go | 2 +- relayer/chains/penumbra/provider.go | 32 +++++++++---------- relayer/chains/penumbra/query.go | 18 +++++------ relayer/chains/penumbra/tx.go | 14 ++++---- 12 files changed, 52 insertions(+), 55 deletions(-) rename {client => cclient}/cmbft_client_wrapper.go (99%) rename {client => cclient}/cmbft_consensus.go (98%) rename {client => cclient}/consensus.go (95%) diff --git a/client/cmbft_client_wrapper.go b/cclient/cmbft_client_wrapper.go similarity index 99% rename from client/cmbft_client_wrapper.go rename to cclient/cmbft_client_wrapper.go index 4f4c95f98..9338060f8 100644 --- a/client/cmbft_client_wrapper.go +++ b/cclient/cmbft_client_wrapper.go @@ -1,4 +1,4 @@ -package rclient +package cclient import ( "context" @@ -34,7 +34,7 @@ type CometRPCClient struct { c *client.Client } -func NewRPCClient(c *client.Client) CometRPCClient { +func NewCometRPCClient(c *client.Client) CometRPCClient { return CometRPCClient{c: c} } @@ -388,8 +388,7 @@ func (r CometRPCClient) BlockSearch( } return &coretypes.ResultBlockSearch{ - Blocks: blocks, - TotalCount: res.TotalCount, + Blocks: blocks, }, nil } diff --git a/client/cmbft_consensus.go b/cclient/cmbft_consensus.go similarity index 98% rename from client/cmbft_consensus.go rename to cclient/cmbft_consensus.go index b449af8c6..7a0a40e99 100644 --- a/client/cmbft_consensus.go +++ b/cclient/cmbft_consensus.go @@ -1,4 +1,4 @@ -package rclient +package cclient import ( "context" @@ -66,8 +66,7 @@ func (r CometRPCClient) GetTxSearch(ctx context.Context, query string, prove boo return nil, fmt.Errorf("failed to get tx search: %w", err) } return &ResultTxSearch{ - Txs: resp.Txs, - TotalCount: resp.TotalCount, + Txs: resp.Txs, }, nil } diff --git a/client/consensus.go b/cclient/consensus.go similarity index 95% rename from client/consensus.go rename to cclient/consensus.go index 1226799ce..b185d34af 100644 --- a/client/consensus.go +++ b/cclient/consensus.go @@ -1,4 +1,4 @@ -package rclient +package cclient import ( "context" @@ -71,8 +71,7 @@ func (q ABCIQueryResponse) ValueCleaned() string { // coretypes.ResultTxSearch type ResultTxSearch struct { - Txs []*coretypes.ResultTx `json:"txs"` - TotalCount int `json:"total_count"` + Txs []*coretypes.ResultTx `json:"txs"` } type ResultValidators struct { diff --git a/interchaintest/feegrant_test.go b/interchaintest/feegrant_test.go index 584df4b64..977bd792e 100644 --- a/interchaintest/feegrant_test.go +++ b/interchaintest/feegrant_test.go @@ -18,7 +18,7 @@ import ( "github.com/cosmos/go-bip39" transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" chantypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" - rclient "github.com/cosmos/relayer/v2/client" + "github.com/cosmos/relayer/v2/cclient" "github.com/cosmos/relayer/v2/relayer" "github.com/cosmos/relayer/v2/relayer/chains/cosmos" "github.com/cosmos/relayer/v2/relayer/processor" @@ -538,7 +538,7 @@ func TestRelayerFeeGrant(t *testing.T) { } } -func TxWithRetry(ctx context.Context, client rclient.ConsensusClient, hash []byte) (*coretypes.ResultTx, error) { +func TxWithRetry(ctx context.Context, client cclient.ConsensusClient, hash []byte) (*coretypes.ResultTx, error) { var err error var res *coretypes.ResultTx if err = retry.Do(func() error { diff --git a/relayer/chains/cosmos/cosmos_chain_processor.go b/relayer/chains/cosmos/cosmos_chain_processor.go index 0d8e9486f..dea00a435 100644 --- a/relayer/chains/cosmos/cosmos_chain_processor.go +++ b/relayer/chains/cosmos/cosmos_chain_processor.go @@ -13,7 +13,7 @@ import ( conntypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" chantypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" - rclient "github.com/cosmos/relayer/v2/client" + "github.com/cosmos/relayer/v2/cclient" "github.com/cosmos/relayer/v2/relayer/chains" "github.com/cosmos/relayer/v2/relayer/processor" "github.com/cosmos/relayer/v2/relayer/provider" @@ -149,7 +149,7 @@ func (ccp *CosmosChainProcessor) latestHeightWithRetry(ctx context.Context) (lat // nodeStatusWithRetry will query for the latest node status, retrying in case of failure. // It will delay by latestHeightQueryRetryDelay between attempts, up to latestHeightQueryRetries. -func (ccp *CosmosChainProcessor) nodeStatusWithRetry(ctx context.Context) (status *rclient.Status, err error) { +func (ccp *CosmosChainProcessor) nodeStatusWithRetry(ctx context.Context) (status *cclient.Status, err error) { return status, retry.Do(func() error { latestHeightQueryCtx, cancelLatestHeightQueryCtx := context.WithTimeout(ctx, queryTimeout) defer cancelLatestHeightQueryCtx() @@ -393,7 +393,7 @@ func (ccp *CosmosChainProcessor) queryCycle(ctx context.Context, persistence *qu for i := persistence.latestQueriedBlock + 1; i <= persistence.latestHeight; i++ { var ( eg errgroup.Group - blockRes *rclient.BlockResults + blockRes *cclient.BlockResults ibcHeader provider.IBCHeader ) diff --git a/relayer/chains/cosmos/provider.go b/relayer/chains/cosmos/provider.go index 75c458d00..11491be8c 100644 --- a/relayer/chains/cosmos/provider.go +++ b/relayer/chains/cosmos/provider.go @@ -19,7 +19,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/gogoproto/proto" commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" - rclient "github.com/cosmos/relayer/v2/client" + "github.com/cosmos/relayer/v2/cclient" "github.com/cosmos/relayer/v2/relayer/codecs/ethermint" "github.com/cosmos/relayer/v2/relayer/processor" "github.com/cosmos/relayer/v2/relayer/provider" @@ -127,7 +127,7 @@ type CosmosProvider struct { PCfg CosmosProviderConfig Keybase keyring.Keyring KeyringOptions []keyring.Option - ConsensusClient rclient.ConsensusClient + ConsensusClient cclient.ConsensusClient LightProvider provtypes.Provider Input io.Reader Output io.Writer @@ -401,7 +401,7 @@ func (cc *CosmosProvider) setRpcClient(onStartup bool, rpcAddr string, timeout t return err } - cc.ConsensusClient = rclient.NewRPCClient(c) + cc.ConsensusClient = cclient.NewCometRPCClient(c) // Only check status if not on startup, to ensure the relayer will not block on startup. // All subsequent calls will perform the status check to ensure RPC endpoints are rotated diff --git a/relayer/chains/cosmos/query.go b/relayer/chains/cosmos/query.go index 5be04f88a..0bce53f42 100644 --- a/relayer/chains/cosmos/query.go +++ b/relayer/chains/cosmos/query.go @@ -32,7 +32,7 @@ import ( host "github.com/cosmos/ibc-go/v8/modules/core/24-host" ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" tmclient "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" - rclient "github.com/cosmos/relayer/v2/client" + "github.com/cosmos/relayer/v2/cclient" "github.com/cosmos/relayer/v2/relayer/chains" "github.com/cosmos/relayer/v2/relayer/provider" "go.uber.org/zap" @@ -1212,7 +1212,7 @@ func (cc *CosmosProvider) QueryLatestHeight(ctx context.Context) (int64, error) } // Query current node status -func (cc *CosmosProvider) QueryStatus(ctx context.Context) (*rclient.Status, error) { +func (cc *CosmosProvider) QueryStatus(ctx context.Context) (*cclient.Status, error) { status, err := cc.ConsensusClient.GetStatus(ctx) if err != nil { return nil, fmt.Errorf("failed to query node status: %w", err) diff --git a/relayer/chains/cosmos/tx.go b/relayer/chains/cosmos/tx.go index 70f239878..06081995f 100644 --- a/relayer/chains/cosmos/tx.go +++ b/relayer/chains/cosmos/tx.go @@ -43,7 +43,7 @@ import ( ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" tmclient "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" localhost "github.com/cosmos/ibc-go/v8/modules/light-clients/09-localhost" - rclient "github.com/cosmos/relayer/v2/client" + "github.com/cosmos/relayer/v2/cclient" strideicqtypes "github.com/cosmos/relayer/v2/relayer/chains/cosmos/stride" "github.com/cosmos/relayer/v2/relayer/ethermint" "github.com/cosmos/relayer/v2/relayer/provider" @@ -266,7 +266,7 @@ func (cc *CosmosProvider) AwaitTx(txHash bytes.HexBytes, timeout time.Duration) // sent and executed successfully is returned. // // feegranterKey - key name of the address set as the feegranter, empty string will not feegrant -func (cc *CosmosProvider) SendMsgsWith(ctx context.Context, msgs []sdk.Msg, memo string, gas uint64, signingKey string, feegranterKey string) (*rclient.ResultBroadcastTx, error) { +func (cc *CosmosProvider) SendMsgsWith(ctx context.Context, msgs []sdk.Msg, memo string, gas uint64, signingKey string, feegranterKey string) (*cclient.ResultBroadcastTx, error) { sdkConfigMutex.Lock() sdkConf := sdk.GetConfig() sdkConf.SetBech32PrefixForAccount(cc.PCfg.AccountPrefix, cc.PCfg.AccountPrefix+"pub") diff --git a/relayer/chains/penumbra/penumbra_chain_processor.go b/relayer/chains/penumbra/penumbra_chain_processor.go index 2944a4570..7bea56b33 100644 --- a/relayer/chains/penumbra/penumbra_chain_processor.go +++ b/relayer/chains/penumbra/penumbra_chain_processor.go @@ -337,7 +337,7 @@ func (pcp *PenumbraChainProcessor) queryCycle(ctx context.Context, persistence * queryCtx, cancelQueryCtx := context.WithTimeout(ctx, blockResultsQueryTimeout) defer cancelQueryCtx() - blockRes, err = pcp.chainProvider.RPCClient.BlockResults(queryCtx, &i) + blockRes, err = pcp.chainProvider.ConsensusClient.BlockResults(queryCtx, &i) return err }) diff --git a/relayer/chains/penumbra/provider.go b/relayer/chains/penumbra/provider.go index cb1c4299c..c4ef95f96 100644 --- a/relayer/chains/penumbra/provider.go +++ b/relayer/chains/penumbra/provider.go @@ -22,7 +22,7 @@ import ( commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" tmclient "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" - rclient "github.com/cosmos/relayer/v2/client" + "github.com/cosmos/relayer/v2/cclient" "github.com/cosmos/relayer/v2/relayer/codecs/ethermint" "github.com/cosmos/relayer/v2/relayer/provider" "github.com/strangelove-ventures/cometbft-client/client" @@ -139,15 +139,15 @@ func (h PenumbraIBCHeader) NextValidatorsHash() []byte { type PenumbraProvider struct { log *zap.Logger - PCfg PenumbraProviderConfig - Keybase keyring.Keyring - KeyringOptions []keyring.Option - RPCClient rclient.CometRPCClient - LightProvider provtypes.Provider - Input io.Reader - Output io.Writer - Codec Codec - RPCCaller jsonrpcclient.Caller + PCfg PenumbraProviderConfig + Keybase keyring.Keyring + KeyringOptions []keyring.Option + ConsensusClient cclient.CometRPCClient + LightProvider provtypes.Provider + Input io.Reader + Output io.Writer + Codec Codec + RPCCaller jsonrpcclient.Caller } func (cc *PenumbraProvider) ProviderConfig() provider.ProviderConfig { @@ -303,7 +303,7 @@ func (cc *PenumbraProvider) startLivelinessChecks(ctx context.Context, timeout t case <-ctx.Done(): return case <-ticker.C: - _, err := cc.RPCClient.Status(ctx) + _, err := cc.ConsensusClient.Status(ctx) if err != nil { cc.log.Error("RPC client disconnected", zap.String("chain", cc.ChainName()), zap.Error(err)) @@ -354,13 +354,13 @@ func (cc *PenumbraProvider) setRpcClient(onStartup bool, rpcAddr string, timeout return err } - cc.RPCClient = rclient.NewRPCClient(c) + cc.ConsensusClient = cclient.NewCometRPCClient(c) // Only check status if not on startup, to ensure the relayer will not block on startup. // All subsequent calls will perform the status check to ensure RPC endpoints are rotated // as necessary. if !onStartup { - if _, err = cc.RPCClient.Status(context.Background()); err != nil { + if _, err = cc.ConsensusClient.Status(context.Background()); err != nil { return err } } @@ -382,7 +382,7 @@ func (cc *PenumbraProvider) setLightProvider(rpcAddr string) error { // WaitForNBlocks blocks until the next block on a given chain func (cc *PenumbraProvider) WaitForNBlocks(ctx context.Context, n int64) error { var initial int64 - h, err := cc.RPCClient.Status(ctx) + h, err := cc.ConsensusClient.Status(ctx) if err != nil { return err } @@ -391,7 +391,7 @@ func (cc *PenumbraProvider) WaitForNBlocks(ctx context.Context, n int64) error { } initial = h.SyncInfo.LatestBlockHeight for { - h, err = cc.RPCClient.Status(ctx) + h, err = cc.ConsensusClient.Status(ctx) if err != nil { return err } @@ -408,7 +408,7 @@ func (cc *PenumbraProvider) WaitForNBlocks(ctx context.Context, n int64) error { } func (cc *PenumbraProvider) BlockTime(ctx context.Context, height int64) (time.Time, error) { - resultBlock, err := cc.RPCClient.Block(ctx, &height) + resultBlock, err := cc.ConsensusClient.Block(ctx, &height) if err != nil { return time.Time{}, err } diff --git a/relayer/chains/penumbra/query.go b/relayer/chains/penumbra/query.go index 615428799..518aa0764 100644 --- a/relayer/chains/penumbra/query.go +++ b/relayer/chains/penumbra/query.go @@ -42,7 +42,7 @@ func (cc *PenumbraProvider) QueryTx(ctx context.Context, hashHex string) (*provi return nil, err } - resp, err := cc.RPCClient.Tx(ctx, hash, true) + resp, err := cc.ConsensusClient.Tx(ctx, hash, true) if err != nil { return nil, err } @@ -72,7 +72,7 @@ func (cc *PenumbraProvider) QueryTxs(ctx context.Context, page, limit int, event return nil, errors.New("limit must greater than 0") } - res, err := cc.RPCClient.TxSearch(ctx, strings.Join(events, " AND "), true, &page, &limit, "") + res, err := cc.ConsensusClient.TxSearch(ctx, strings.Join(events, " AND "), true, &page, &limit, "") if err != nil { return nil, err } @@ -380,7 +380,7 @@ func (cc *PenumbraProvider) QueryUpgradedConsState(ctx context.Context, height i // QueryConsensusState returns a consensus state for a given chain to be used as a // client in another chain, fetches latest height when passed 0 as arg func (cc *PenumbraProvider) QueryConsensusState(ctx context.Context, height int64) (ibcexported.ConsensusState, int64, error) { - commit, err := cc.RPCClient.Commit(ctx, &height) + commit, err := cc.ConsensusClient.Commit(ctx, &height) if err != nil { return &tmclient.ConsensusState{}, 0, err } @@ -389,7 +389,7 @@ func (cc *PenumbraProvider) QueryConsensusState(ctx context.Context, height int6 count := 10_000 nextHeight := height + 1 - nextVals, err := cc.RPCClient.Validators(ctx, &nextHeight, &page, &count) + nextVals, err := cc.ConsensusClient.Validators(ctx, &nextHeight, &page, &count) if err != nil { return &tmclient.ConsensusState{}, 0, err } @@ -787,7 +787,7 @@ func (cc *PenumbraProvider) QueryPacketReceipt(ctx context.Context, height int64 } func (cc *PenumbraProvider) QueryLatestHeight(ctx context.Context) (int64, error) { - stat, err := cc.RPCClient.Status(ctx) + stat, err := cc.ConsensusClient.Status(ctx) if err != nil { return -1, err } else if stat.SyncInfo.CatchingUp { @@ -806,12 +806,12 @@ func (cc *PenumbraProvider) QueryHeaderAtHeight(ctx context.Context, height int6 return nil, fmt.Errorf("must pass in valid height, %d not valid", height) } - res, err := cc.RPCClient.Commit(ctx, &height) + res, err := cc.ConsensusClient.Commit(ctx, &height) if err != nil { return nil, err } - val, err := cc.RPCClient.Validators(ctx, &height, &page, &perPage) + val, err := cc.ConsensusClient.Validators(ctx, &height, &page, &perPage) if err != nil { return nil, err } @@ -922,7 +922,7 @@ func (cc *PenumbraProvider) queryIBCMessages(ctx context.Context, log *zap.Logge return nil, errors.New("limit must greater than 0") } - res, err := cc.RPCClient.TxSearch(ctx, query, true, &page, &limit, "") + res, err := cc.ConsensusClient.TxSearch(ctx, query, true, &page, &limit, "") if err != nil { return nil, err } @@ -1004,7 +1004,7 @@ func (cc *PenumbraProvider) QueryRecvPacket( // QueryStatus queries the current node status. func (cc *PenumbraProvider) QueryStatus(ctx context.Context) (*coretypes.ResultStatus, error) { - status, err := cc.RPCClient.Status(ctx) + status, err := cc.ConsensusClient.Status(ctx) if err != nil { return nil, fmt.Errorf("failed to query node status: %w", err) } diff --git a/relayer/chains/penumbra/tx.go b/relayer/chains/penumbra/tx.go index dbf8a2547..5ce21696a 100644 --- a/relayer/chains/penumbra/tx.go +++ b/relayer/chains/penumbra/tx.go @@ -248,7 +248,7 @@ type ValidatorUpdate struct { } func (cc *PenumbraProvider) getAnchor(ctx context.Context) (*penumbracrypto.MerkleRoot, error) { - status, err := cc.RPCClient.Status(ctx) + status, err := cc.ConsensusClient.Status(ctx) if err != nil { return nil, err } @@ -345,7 +345,7 @@ func (cc *PenumbraProvider) sendMessagesInner(ctx context.Context, msgs []provid return nil, err } - return cc.RPCClient.BroadcastTxSync(ctx, txBytes) + return cc.ConsensusClient.BroadcastTxSync(ctx, txBytes) } // SendMessages attempts to sign, encode, & send a slice of RelayerMessages @@ -372,7 +372,7 @@ func (cc *PenumbraProvider) SendMessages(ctx context.Context, msgs []provider.Re ctx, cancel := context.WithTimeout(ctx, 40*time.Second) defer cancel() - res, err := cc.RPCClient.Tx(ctx, syncRes.Hash, false) + res, err := cc.ConsensusClient.Tx(ctx, syncRes.Hash, false) if err != nil { return err } @@ -2078,7 +2078,7 @@ func (cc *PenumbraProvider) QueryABCI(ctx context.Context, req abci.RequestQuery Prove: req.Prove, } - result, err := cc.RPCClient.ABCIQueryWithOptions(ctx, req.Path, req.Data, opts) + result, err := cc.ConsensusClient.ABCIQueryWithOptions(ctx, req.Path, req.Data, opts) if err != nil { return abci.ResponseQuery{}, err } @@ -2153,7 +2153,7 @@ func (cc *PenumbraProvider) broadcastTx( asyncTimeout time.Duration, // timeout for waiting for block inclusion asyncCallback func(*provider.RelayerTxResponse, error), // callback for success/fail of the wait for block inclusion ) error { - res, err := cc.RPCClient.BroadcastTxSync(ctx, tx) + res, err := cc.ConsensusClient.BroadcastTxSync(ctx, tx) isErr := err != nil isFailed := res != nil && res.Code != 0 if isErr || isFailed { @@ -2249,12 +2249,12 @@ func (cc *PenumbraProvider) waitForBlockInclusion( return nil, fmt.Errorf("timed out after: %d; %w", waitTimeout, ErrTimeoutAfterWaitingForTxBroadcast) // This fixed poll is fine because it's only for logging and updating prometheus metrics currently. case <-time.After(time.Millisecond * 100): - res, err := cc.RPCClient.Tx(ctx, txHash, false) + res, err := cc.ConsensusClient.Tx(ctx, txHash, false) if err == nil { return cc.mkTxResult(res) } if strings.Contains(err.Error(), "transaction indexing is disabled") { - return nil,errors.New("cannot determine success/failure of tx because transaction indexing is disabled on rpc url") + return nil, errors.New("cannot determine success/failure of tx because transaction indexing is disabled on rpc url") } case <-ctx.Done(): return nil, ctx.Err()