Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions reporter/client/broadcast_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (c *Client) GenerateAndBroadcastSpotPriceReport(ctx context.Context, qd []b
}

func (c *Client) HandleBridgeDepositTxInChannel(ctx context.Context, data TxChannelInfo) {
resp, err := c.sendTx(ctx, 0, data.Msg) // 0 = no queryMeta tracking for bridge transactions
resp, err := c.sendTx(ctx, 0, true, data.Msg) // 0 = no queryMeta tracking for bridge transactions
if err != nil {
c.logger.Error("submitting deposit report transaction",
"error", err,
Expand Down Expand Up @@ -200,7 +200,7 @@ func (c *Client) BroadcastTxMsgToChain() {
defer cancel()

if !txInfo.isBridge {
_, err := c.sendTx(ctx, txInfo.QueryMetaId, txInfo.Msg)
_, err := c.sendTx(ctx, txInfo.QueryMetaId, false, txInfo.Msg)
if err != nil {
c.logger.Error(fmt.Sprintf("Error sending tx: %v", err))
}
Expand Down
6 changes: 2 additions & 4 deletions reporter/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)

const defaultGas = uint64(300000)
const defaultGas = uint64(240000)

var (
commitedIds = make(map[uint64]bool)
Expand Down Expand Up @@ -175,9 +175,7 @@ func (c *Client) Start(
if !viper.IsSet("price-guard-update-on-blocked") {
return fmt.Errorf("price-guard-enabled is true but price-guard-update-on-blocked is not set")
}
} else
// If price guard is disabled, error if any other price guard flags are set
if viper.IsSet("price-guard-threshold") || viper.IsSet("price-guard-max-age") || viper.IsSet("price-guard-update-on-blocked") {
} else if !priceGuardEnabled && (viper.IsSet("price-guard-threshold") || viper.IsSet("price-guard-max-age") || viper.IsSet("price-guard-update-on-blocked")) {
return fmt.Errorf("price-guard flags are set but price-guard-enabled is false")
}

Expand Down
42 changes: 39 additions & 3 deletions reporter/client/tx_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/hex"
"fmt"
"reflect"
"strings"
"time"

Expand All @@ -21,11 +22,16 @@ import (
"github.com/cosmos/cosmos-sdk/types/tx/signing"
)

var (
gasEstimateMap = make(map[reflect.Type]uint64)
BRIDGE_REPORT_TYPE = reflect.TypeOf("bridge_deposit_report")
)

func newFactory(clientCtx client.Context) tx.Factory {
return tx.Factory{}.
WithChainID(clientCtx.ChainID).
WithKeybase(clientCtx.Keyring).
WithGasAdjustment(1.1).
WithGasAdjustment(1.25).
WithGas(defaultGas).
WithSignMode(signing.SignMode_SIGN_MODE_DIRECT).
WithAccountRetriever(clientCtx.AccountRetriever).
Expand Down Expand Up @@ -120,7 +126,34 @@ func (c *Client) WaitForBlockHeight(ctx context.Context, h int64) error {
}
}

func (c *Client) sendTx(ctx context.Context, queryMetaId uint64, msg ...sdk.Msg) (*cmttypes.ResultTx, error) {
func (c *Client) EstimateGas(ctx context.Context, isBridge bool, txf tx.Factory, msg ...sdk.Msg) (uint64, error) {
if isBridge {
if gasEstimate, ok := gasEstimateMap[BRIDGE_REPORT_TYPE]; ok {
return gasEstimate, nil
}
} else {
msgType := reflect.TypeOf(msg[0])
if gasEstimate, ok := gasEstimateMap[msgType]; ok {
return gasEstimate, nil
}
}
if isBridge {
txf = txf.WithGasAdjustment(1.75)
}
_, gasEstimate, err := tx.CalculateGas(c.cosmosCtx, txf, msg...)
if err != nil {
return 0, fmt.Errorf("error calculating gas: %w", err)
}
if isBridge {
gasEstimateMap[BRIDGE_REPORT_TYPE] = gasEstimate
} else {
msgType := reflect.TypeOf(msg[0])
gasEstimateMap[msgType] = gasEstimate
}
return gasEstimate, nil
}

func (c *Client) sendTx(ctx context.Context, queryMetaId uint64, isBridge bool, msg ...sdk.Msg) (*cmttypes.ResultTx, error) {
telemetry.IncrCounter(1, "daemon_sending_txs", "called")

// Track success status for defer cleanup
Expand Down Expand Up @@ -153,7 +186,10 @@ func (c *Client) sendTx(ctx context.Context, queryMetaId uint64, msg ...sdk.Msg)
if err != nil {
return nil, fmt.Errorf("error preparing transaction factory: %w", err)
}

gasEstimate, err := c.EstimateGas(ctx, isBridge, txf, msg...)
if err == nil {
txf = txf.WithGas(gasEstimate)
}
txn, err := txf.BuildUnsignedTx(msg...)
if err != nil {
return nil, fmt.Errorf("error building unsigned transaction: %w", err)
Expand Down
Loading