Skip to content

Commit

Permalink
refactor: rename rclient -> cclient (consensus client)
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Sep 3, 2024
1 parent 7e8f012 commit 5f7a8b3
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rclient
package cclient

import (
"context"
Expand Down Expand Up @@ -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}
}

Expand Down Expand Up @@ -388,8 +388,7 @@ func (r CometRPCClient) BlockSearch(
}

return &coretypes.ResultBlockSearch{
Blocks: blocks,
TotalCount: res.TotalCount,
Blocks: blocks,
}, nil
}

Expand Down
5 changes: 2 additions & 3 deletions client/cmbft_consensus.go → cclient/cmbft_consensus.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rclient
package cclient

import (
"context"
Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 2 additions & 3 deletions client/consensus.go → cclient/consensus.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rclient
package cclient

import (
"context"
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions interchaintest/feegrant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions relayer/chains/cosmos/cosmos_chain_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
)

Expand Down
6 changes: 3 additions & 3 deletions relayer/chains/cosmos/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions relayer/chains/cosmos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions relayer/chains/cosmos/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion relayer/chains/penumbra/penumbra_chain_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand Down
32 changes: 16 additions & 16 deletions relayer/chains/penumbra/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
18 changes: 9 additions & 9 deletions relayer/chains/penumbra/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down
14 changes: 7 additions & 7 deletions relayer/chains/penumbra/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 5f7a8b3

Please sign in to comment.