Skip to content

Commit

Permalink
fee grant support
Browse files Browse the repository at this point in the history
  • Loading branch information
dixitaniket committed Oct 13, 2023
1 parent 8c0831c commit 596b201
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 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
13 changes: 9 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 Cometbft nodes.
RPC struct {
TMRPCEndpoint string `mapstructure:"tmrpc_endpoint" validate:"required"`
Expand Down
20 changes: 17 additions & 3 deletions cw-relayer/relayer/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type (
GasAdjustment float64
KeyringPassphrase string
ChainHeight *ChainHeight
feeGranter sdk.AccAddress
}

passReader struct {
Expand Down Expand Up @@ -79,6 +80,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 @@ -110,6 +112,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 @@ -179,7 +192,7 @@ func (oc RelayerClient) BroadcastTx(timeoutDuration time.Duration, nextBlockHeig

if latestBlockHeight <= lastCheckHeight {
if time.Since(start).Seconds() >= timeoutDuration.Seconds() {
return fmt.Errorf("timeout duration exceeded")
return fmt.Errorf("timeout duration exceeded, last check height = %v", lastCheckHeight)
}

continue
Expand All @@ -188,7 +201,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 @@ -347,7 +360,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 596b201

Please sign in to comment.