Skip to content

Commit

Permalink
code consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat committed Aug 30, 2023
1 parent 1fc7775 commit eec57ba
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 53 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ linters-settings:
# Do NOT whine about the following, full explanation found in:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#description-of-available-rules
rules:
- name: exported
disabled: true
- name: use-any
disabled: true
- name: if-return
Expand Down
6 changes: 3 additions & 3 deletions cmd/feegrant.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func feegrantConfigureBaseCmd(a *appState) *cobra.Command {
func feegrantConfigureBasicCmd(a *appState) *cobra.Command {
var numGrantees int
var update bool
var delete bool
var deleteChain bool
var updateGrantees bool
var grantees []string

Expand Down Expand Up @@ -63,7 +63,7 @@ func feegrantConfigureBasicCmd(a *appState) *cobra.Command {
return fmt.Errorf("could not get granter key from '%s'", granterKeyOrAddr)
}

if delete {
if deleteChain {
fmt.Printf("Deleting %s feegrant configuration\n", chain)

cfgErr := a.performConfigLockingOperation(cmd.Context(), func() error {
Expand Down Expand Up @@ -140,7 +140,7 @@ func feegrantConfigureBasicCmd(a *appState) *cobra.Command {
},
}

cmd.Flags().BoolVar(&delete, "delete", false, "delete the feegrant configuration")
cmd.Flags().BoolVar(&deleteChain, "delete", false, "delete the feegrant configuration")
cmd.Flags().BoolVar(&update, "overwrite-granter", false, "allow overwriting the existing granter")
cmd.Flags().BoolVar(&updateGrantees, "overwrite-grantees", false, "allow overwriting existing grantees")
cmd.Flags().IntVar(&numGrantees, "num-grantees", 10, "number of grantees that will be feegranted with basic allowances")
Expand Down
8 changes: 4 additions & 4 deletions relayer/chains/cosmos/event_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ type clientInfo struct {
header []byte
}

func (c clientInfo) ClientState(trustingPeriod time.Duration) provider.ClientState {
func (res clientInfo) ClientState(trustingPeriod time.Duration) provider.ClientState {
return provider.ClientState{
ClientID: c.clientID,
ConsensusHeight: c.consensusHeight,
ClientID: res.clientID,
ConsensusHeight: res.consensusHeight,
TrustingPeriod: trustingPeriod,
Header: c.header,
Header: res.header,
}
}

Expand Down
4 changes: 2 additions & 2 deletions relayer/chains/cosmos/feegrant.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (cc *CosmosProvider) GetTxFeeGrant() (txSignerKey string, feeGranterKey str

if lastGranteeIdx >= 0 && lastGranteeIdx <= len(cc.PCfg.FeeGrants.ManagedGrantees)-1 {
txSignerKey = cc.PCfg.FeeGrants.ManagedGrantees[lastGranteeIdx]
cc.PCfg.FeeGrants.GranteeLastSignerIndex = cc.PCfg.FeeGrants.GranteeLastSignerIndex + 1
cc.PCfg.FeeGrants.GranteeLastSignerIndex++

if cc.PCfg.FeeGrants.GranteeLastSignerIndex == len(cc.PCfg.FeeGrants.ManagedGrantees) {
cc.PCfg.FeeGrants.GranteeLastSignerIndex = 0
Expand Down Expand Up @@ -271,7 +271,7 @@ func (cc *CosmosProvider) EnsureBasicGrants(ctx context.Context, memo string) (*
}

if !hasGrant {
grantsNeeded += 1
grantsNeeded++
fmt.Printf("Grant will be created on chain for granter %s and grantee %s\n", granterAddr, granteeAddr)
grantMsg, err := cc.getMsgGrantBasicAllowance(granterAcc, granteeAcc)
if err != nil {
Expand Down
9 changes: 4 additions & 5 deletions relayer/chains/cosmos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
"github.com/cosmos/cosmos-sdk/types/query"
bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types"
Expand Down Expand Up @@ -420,7 +419,7 @@ func (cc *CosmosProvider) QueryClientStateResponse(ctx context.Context, height i

// check if client exists
if len(value) == 0 {
return nil, sdkerrors.Wrap(clienttypes.ErrClientNotFound, srcClientId)
return nil, errorsmod.Wrap(clienttypes.ErrClientNotFound, srcClientId)
}

cdc := codec.NewProtoCodec(cc.Cdc.InterfaceRegistry)
Expand Down Expand Up @@ -469,7 +468,7 @@ func (cc *CosmosProvider) QueryClientConsensusState(ctx context.Context, chainHe

// check if consensus state exists
if len(value) == 0 {
return nil, sdkerrors.Wrap(clienttypes.ErrConsensusStateNotFound, clientid)
return nil, errorsmod.Wrap(clienttypes.ErrConsensusStateNotFound, clientid)
}

cdc := codec.NewProtoCodec(cc.Cdc.InterfaceRegistry)
Expand Down Expand Up @@ -666,7 +665,7 @@ func (cc *CosmosProvider) queryConnectionABCI(ctx context.Context, height int64,

// check if connection exists
if len(value) == 0 {
return nil, sdkerrors.Wrap(conntypes.ErrConnectionNotFound, connectionID)
return nil, errorsmod.Wrap(conntypes.ErrConnectionNotFound, connectionID)
}

cdc := codec.NewProtoCodec(cc.Cdc.InterfaceRegistry)
Expand Down Expand Up @@ -1264,7 +1263,7 @@ func (cc *CosmosProvider) QueryConsensusStateABCI(ctx context.Context, clientID

// check if consensus state exists
if len(value) == 0 {
return nil, sdkerrors.Wrap(clienttypes.ErrConsensusStateNotFound, clientID)
return nil, errorsmod.Wrap(clienttypes.ErrConsensusStateNotFound, clientID)
}

// TODO do we really want to create a new codec? ChainClient exposes proto.Marshaler
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 @@ -495,8 +495,8 @@ func (cc *CosmosProvider) mkTxResult(resTx *coretypes.ResultTx) (*sdk.TxResponse
if !ok {
return nil, fmt.Errorf("expecting a type implementing intoAny, got: %T", txbz)
}
any := p.AsAny()
return sdk.NewResponseResultTx(resTx, any, ""), nil
anyResult := p.AsAny()
return sdk.NewResponseResultTx(resTx, anyResult, ""), nil
}

func parseEventsFromTxResponse(resp *sdk.TxResponse) []provider.RelayerEvent {
Expand Down
8 changes: 4 additions & 4 deletions relayer/chains/penumbra/event_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ type ibcMessageInfo interface {
MarshalLogObject(enc zapcore.ObjectEncoder) error
}

func (ccp *PenumbraChainProcessor) ibcMessagesFromBlockEvents(
func (pcp *PenumbraChainProcessor) ibcMessagesFromBlockEvents(
beginBlockEvents, endBlockEvents []abci.Event,
height uint64, base64Encoded bool,
) (res []ibcMessage) {
chainID := ccp.chainProvider.ChainId()
res = append(res, ibcMessagesFromEvents(ccp.log, beginBlockEvents, chainID, height, base64Encoded)...)
res = append(res, ibcMessagesFromEvents(ccp.log, endBlockEvents, chainID, height, base64Encoded)...)
chainID := pcp.chainProvider.ChainId()
res = append(res, ibcMessagesFromEvents(pcp.log, beginBlockEvents, chainID, height, base64Encoded)...)
res = append(res, ibcMessagesFromEvents(pcp.log, endBlockEvents, chainID, height, base64Encoded)...)
return res
}

Expand Down
2 changes: 1 addition & 1 deletion relayer/chains/penumbra/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (cc *PenumbraProvider) Invoke(ctx context.Context, method string, req, repl

// In both cases, we don't allow empty request req (it will panic unexpectedly).
if reflect.ValueOf(req).IsNil() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "request cannot be nil")
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "request cannot be nil")
}

// Case 1. Broadcasting a Tx.
Expand Down
6 changes: 3 additions & 3 deletions relayer/chains/penumbra/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ func PenumbraMsg(rm provider.RelayerMessage) sdk.Msg {
func PenumbraMsgs(rm ...provider.RelayerMessage) []sdk.Msg {
sdkMsgs := make([]sdk.Msg, 0)
for _, rMsg := range rm {
switch rMsg.(type) {
switch msg := rMsg.(type) {
case PenumbraMessage:
sdkMsgs = append(sdkMsgs, rMsg.(PenumbraMessage).Msg)
sdkMsgs = append(sdkMsgs, msg.Msg)
case cosmos.CosmosMessage:
sdkMsgs = append(sdkMsgs, rMsg.(cosmos.CosmosMessage).Msg)
sdkMsgs = append(sdkMsgs, msg.Msg)
default:
fmt.Printf("got data of type %T but wanted PenumbraMessage \n", rMsg)
return nil
Expand Down
17 changes: 8 additions & 9 deletions relayer/packet-tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,14 @@ func (c *Chain) SendTransferMsg(ctx context.Context, log *zap.Logger, dst *Chain
)
}
return err
} else {
if result.SuccessfullySent() {
c.log.Info(
"Successfully sent a transfer",
zap.String("src_chain_id", c.ChainID()),
zap.String("dst_chain_id", dst.ChainID()),
zap.Object("send_result", result),
)
}
} else if result.SuccessfullySent() {
c.log.Info(
"Successfully sent a transfer",
zap.String("src_chain_id", c.ChainID()),
zap.String("dst_chain_id", dst.ChainID()),
zap.Object("send_result", result),
)
}

return nil
}
10 changes: 5 additions & 5 deletions relayer/processor/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,11 @@ func (connectionKey ConnectionKey) PreInitKey() ConnectionKey {
}
}

func (k ConnectionKey) MarshalLogObject(enc zapcore.ObjectEncoder) error {
enc.AddString("connection_id", k.ConnectionID)
enc.AddString("client_id", k.ClientID)
enc.AddString("counterparty_connection_id", k.CounterpartyConnID)
enc.AddString("counterparty_client_id", k.CounterpartyClientID)
func (connectionKey ConnectionKey) MarshalLogObject(enc zapcore.ObjectEncoder) error {
enc.AddString("connection_id", connectionKey.ConnectionID)
enc.AddString("client_id", connectionKey.ClientID)
enc.AddString("counterparty_connection_id", connectionKey.CounterpartyConnID)
enc.AddString("counterparty_client_id", connectionKey.CounterpartyClientID)
return nil
}

Expand Down
29 changes: 17 additions & 12 deletions relayer/provider/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ func ClientsMatch(ctx context.Context, src, dst ChainProvider, existingClient cl
return "", nil
}

switch ec := existingClientState.(type) {
case *tmclient.ClientState:
nc := newClient.(*tmclient.ClientState)
if ec, ok := existingClientState.(*tmclient.ClientState); ok {
nc, ok := newClient.(*tmclient.ClientState)
if !ok {
return "", fmt.Errorf("got type(%T) expected type(*tmclient.ClientState)", newClient)
}

return cometMatcher(ctx, src, dst, existingClient.ClientId, ec, nc)
}

Expand All @@ -64,15 +67,17 @@ func CheckForMisbehaviour(
return nil, err
}

switch header := clientMsg.(type) {
case *tmclient.Header:
misbehavior, err = checkTendermintMisbehaviour(ctx, clientID, header, cachedHeader, counterparty)
if err != nil {
return nil, err
}
if misbehavior == nil && err == nil {
return nil, nil
}
header, ok := clientMsg.(*tmclient.Header)
if !ok {
return nil, nil
}

misbehavior, err = checkTendermintMisbehaviour(ctx, clientID, header, cachedHeader, counterparty)
if err != nil {
return nil, err
}
if misbehavior == nil && err == nil {
return nil, nil
}

return misbehavior, nil
Expand Down
6 changes: 3 additions & 3 deletions relayer/strategies.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ type path struct {
}

// chainProcessor returns the corresponding ChainProcessor implementation instance for a pathChain.
func (chain *Chain) chainProcessor(log *zap.Logger, metrics *processor.PrometheusMetrics) processor.ChainProcessor {
func (c *Chain) chainProcessor(log *zap.Logger, metrics *processor.PrometheusMetrics) processor.ChainProcessor {
// Handle new ChainProcessor implementations as cases here
switch p := chain.ChainProvider.(type) {
switch p := c.ChainProvider.(type) {
case *penumbraprocessor.PenumbraProvider:
return penumbraprocessor.NewPenumbraChainProcessor(log, p)
case *cosmos.CosmosProvider:
return cosmos.NewCosmosChainProcessor(log, p, metrics)
default:
panic(fmt.Errorf("unsupported chain provider type: %T", chain.ChainProvider))
panic(fmt.Errorf("unsupported chain provider type: %T", c.ChainProvider))
}
}

Expand Down

0 comments on commit eec57ba

Please sign in to comment.