Skip to content

Commit

Permalink
fix: arch updates (#221)
Browse files Browse the repository at this point in the history
* fee grant support

* feegranter config to unsigned tx

---------

Co-authored-by: Aniket Dixit <dixitaniket199@gmail.com>
  • Loading branch information
adamewozniak and dixitaniket authored Mar 29, 2024
1 parent 71fa322 commit d0a1b49
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
1 change: 1 addition & 0 deletions cw-relayer/cmd/cw-relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func cwRelayerCmdHandler(cmd *cobra.Command, args []string) error {
cfg.Account.AccPrefix,
cfg.GasAdjustment,
cfg.GasPrices,
cfg.FeeGrant.Granter,
)
if err != nil {
return err
Expand Down
15 changes: 11 additions & 4 deletions cw-relayer/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ var (
type (
// Config defines all necessary cw-relayer configuration parameters.
Config struct {
Account Account `mapstructure:"account" validate:"required,gt=0,dive,required"`
Keyring Keyring `mapstructure:"keyring" validate:"required,gt=0,dive,required"`
RPC RPC `mapstructure:"rpc" validate:"required,gt=0,dive,required"`
Restart RestartConfig `mapstructure:"restart" validate:"required"`
Account Account `mapstructure:"account" validate:"required,gt=0,dive,required"`
Keyring Keyring `mapstructure:"keyring" validate:"required,gt=0,dive,required"`
RPC RPC `mapstructure:"rpc" validate:"required,gt=0,dive,required"`
Restart RestartConfig `mapstructure:"restart" validate:"required"`
FeeGrant FeeGrantConfig `mapstructure:"fee_grant" validate:"dive"`

ProviderTimeout string `mapstructure:"provider_timeout"`
ContractAddress string `mapstructure:"contract_address"`
Expand Down Expand Up @@ -87,6 +88,10 @@ type (
SkipError bool `mapstructure:"skip_error"`
}

FeeGrantConfig struct {
Granter string `mapstructure:"granter" validate:"omitempty,required"`
}

// RPC defines RPC configuration of both the wasmd chain and Tendermint nodes.
RPC struct {
TMRPCEndpoint string `mapstructure:"tmrpc_endpoint" validate:"required"`
Expand Down Expand Up @@ -160,5 +165,7 @@ func ParseConfig(configPath string) (Config, error) {
cfg.MaxRetries = defaultRetries
}

fmt.Println()

return cfg, cfg.Validate()
}
18 changes: 16 additions & 2 deletions cw-relayer/relayer/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type (
GasAdjustment float64
KeyringPassphrase string
ChainHeight *ChainHeight
feeGranter sdk.AccAddress
}

passReader struct {
Expand Down Expand Up @@ -80,6 +81,7 @@ func NewRelayerClient(
accPrefix string,
gasAdjustment float64,
GasPrices string,
granter string,
) (RelayerClient, error) {
config := sdk.GetConfig()
config.SetBech32PrefixForAccount(accPrefix, accPrefix+sdk.PrefixPublic)
Expand Down Expand Up @@ -111,6 +113,17 @@ func NewRelayerClient(
return RelayerClient{}, err
}

if len(granter) > 0 {
feeGranterAddr, err := sdk.AccAddressFromBech32(granter)
if err != nil {
return RelayerClient{}, err
}

relayerClient.feeGranter = feeGranterAddr
} else {
relayerClient.feeGranter = clientCtx.GetFeeGranterAddress()
}

blockHeight, err := rpc.GetChainHeight(clientCtx)
if err != nil {
return RelayerClient{}, err
Expand Down Expand Up @@ -189,7 +202,7 @@ func (oc RelayerClient) BroadcastTx(timeoutDuration time.Duration, nextBlockHeig
// set last check height to latest block height
lastCheckHeight = latestBlockHeight

resp, err := BroadcastTx(clientCtx, factory, msgs...)
resp, err := BroadcastTx(oc.feeGranter, clientCtx, factory, msgs...)
if resp != nil && resp.Code != 0 {
telemetry.IncrCounter(1, "failure", "tx", "code")
oc.logger.Error().Msg(resp.String())
Expand Down Expand Up @@ -348,7 +361,8 @@ func (oc RelayerClient) CreateTxFactory() (tx.Factory, error) {
WithGasPrices(oc.GasPrices).
WithKeybase(clientCtx.Keyring).
WithSignMode(signing.SignMode_SIGN_MODE_DIRECT).
WithSimulateAndExecute(true)
WithSimulateAndExecute(true).
WithFeeGranter(oc.feeGranter)

return txFactory, nil
}
Expand Down
4 changes: 2 additions & 2 deletions cw-relayer/relayer/client/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// Note, BroadcastTx is copied from the SDK except it removes a few unnecessary
// things like prompting for confirmation and printing the response. Instead,
// we return the TxResponse.
func BroadcastTx(clientCtx client.Context, txf tx.Factory, msgs ...sdk.Msg) (*sdk.TxResponse, error) {
func BroadcastTx(feeGranter sdk.AccAddress, clientCtx client.Context, txf tx.Factory, msgs ...sdk.Msg) (*sdk.TxResponse, error) {
txf, err := prepareFactory(clientCtx, txf)
if err != nil {
return nil, err
Expand All @@ -31,7 +31,7 @@ func BroadcastTx(clientCtx client.Context, txf tx.Factory, msgs ...sdk.Msg) (*sd
return nil, err
}

unsignedTx.SetFeeGranter(clientCtx.GetFeeGranterAddress())
unsignedTx.SetFeeGranter(feeGranter)

if err = tx.Sign(txf, clientCtx.GetFromName(), unsignedTx, true); err != nil {
return nil, err
Expand Down

0 comments on commit d0a1b49

Please sign in to comment.