Skip to content

Commit

Permalink
feat: update min gas price in GasInfo (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonberg1997 authored Feb 23, 2023
1 parent 7a7df77 commit 14f91ec
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 89 deletions.
6 changes: 3 additions & 3 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re

ctx := app.getContextForTx(mode, txBytes)
ms := ctx.MultiStore()
gInfo.MinGasPrices = ctx.MinGasPrices().String()
gInfo.MinGasPrice = app.minGasPrices.String()

// only run the tx if there is block gas remaining
if mode == runTxModeDeliver && ctx.BlockGasMeter().IsOutOfGas() {
Expand All @@ -658,12 +658,12 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re
err, result = processRecovery(r, recoveryMW), nil
}

gInfo = sdk.GasInfo{GasWanted: gasWanted, GasUsed: ctx.GasMeter().GasConsumed(), MinGasPrices: app.minGasPrices.String()}
gInfo = sdk.GasInfo{GasWanted: gasWanted, GasUsed: ctx.GasMeter().GasConsumed(), MinGasPrice: gInfo.MinGasPrice}
}()

blockGasConsumed := false
// consumeBlockGas makes sure block gas is consumed at most once. It must happen after
// tx processing, and must be execute even if tx processing fails. Hence we use trick with `defer`
// tx processing, and must be executed even if tx processing fails. Hence we use trick with `defer`
consumeBlockGas := func() {
if !blockGasConsumed {
blockGasConsumed = true
Expand Down
17 changes: 6 additions & 11 deletions client/tx/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,17 @@ func BroadcastTx(clientCtx client.Context, txf Factory, msgs ...sdk.Msg) error {
txf = txf.WithGas(adjusted)
_, _ = fmt.Fprintf(os.Stderr, "%s\n", GasEstimateResponse{GasEstimate: txf.Gas()})

parsedGasPrices, err := sdk.ParseCoinsNormalized(gInfo.GasInfo.MinGasPrices)
parsedGasPrice, err := sdk.ParseCoinNormalized(gInfo.GasInfo.MinGasPrice)
if err != nil {
return err
}
if parsedGasPrices == nil {
return fmt.Errorf("empty gas prices")
}

// we only accept one type coin
gasPrice := parsedGasPrices[0]
fees := make(sdk.Coins, 1)
gasLimit := sdk.NewInt(int64(adjusted))
fee := gasPrice.Amount.Mul(gasLimit)
fees[0] = sdk.NewCoin(gasPrice.Denom, fee)
if !parsedGasPrice.IsNil() && !parsedGasPrice.IsZero() {
fees := make(sdk.Coins, 1)
fees[0] = sdk.NewCoin(parsedGasPrice.Denom, parsedGasPrice.Amount.Mul(sdk.NewInt(int64(adjusted))))

txf = txf.WithFees(fees.String())
txf = txf.WithFees(fees.String())
}
}

if clientCtx.Simulate {
Expand Down
4 changes: 2 additions & 2 deletions proto/cosmos/base/abci/v1beta1/abci.proto
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ message GasInfo {
// GasUsed is the amount of gas actually consumed.
uint64 gas_used = 2;

// MinGasPrices are the min gas prices.
string min_gas_prices = 3;
// MinGasPrice are the min gas price.
string min_gas_price = 3;
}

// Result is the union of ResponseFormat and ResponseCheckTx.
Expand Down
4 changes: 2 additions & 2 deletions proto/cosmos/tx/v1beta1/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ message GetTxsEventRequest {
// pagination defines a pagination for the request.
// Deprecated post v0.46.x: use page and limit instead.
cosmos.base.query.v1beta1.PageRequest pagination = 2 [deprecated = true];
;

OrderBy order_by = 3;
// page is the page number to query, starts at 1. If not provided, will default to first page.
uint64 page = 4;
Expand Down Expand Up @@ -170,4 +170,4 @@ message GetBlockWithTxsResponse {
.tendermint.types.Block block = 3;
// pagination defines a pagination for the response.
cosmos.base.query.v1beta1.PageResponse pagination = 4;
}
}
142 changes: 71 additions & 71 deletions types/abci.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions x/auth/tx/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ func (s txServer) Simulate(ctx context.Context, req *txtypes.SimulateRequest) (*
return nil, status.Errorf(codes.Unknown, "%v With gas wanted: '%d' and gas used: '%d' ", err, gasInfo.GasWanted, gasInfo.GasUsed)
}

// we only adopt the first gas price in the list
gasPrices, err := sdk.ParseCoinsNormalized(gasInfo.MinGasPrice)
if err != nil {
return nil, status.Errorf(codes.Unknown, "%v With min gas price: '%s' ", err, gasInfo.MinGasPrice)
}

if !gasPrices.Empty() {
gasInfo.MinGasPrice = gasPrices[0].String()
}

return &txtypes.SimulateResponse{
GasInfo: &gasInfo,
Result: result,
Expand Down

0 comments on commit 14f91ec

Please sign in to comment.