diff --git a/PENDING.md b/PENDING.md index 1c17731e2b7c..a0985593e838 100644 --- a/PENDING.md +++ b/PENDING.md @@ -62,7 +62,8 @@ IMPROVEMENTS * SDK - [x/mock/simulation] [\#2720] major cleanup, introduction of helper objects, reorganization - - \#2821 Codespaces are now strings + - #2815 Gas unit fields changed from `int64` to `uint64`. + - #2821 Codespaces are now strings * Tendermint - #2796 Update to go-amino 0.14.1 diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 0d557102414b..34f9d817dec8 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -451,8 +451,8 @@ func (app *BaseApp) CheckTx(txBytes []byte) (res abci.ResponseCheckTx) { Code: uint32(result.Code), Data: result.Data, Log: result.Log, - GasWanted: result.GasWanted, - GasUsed: result.GasUsed, + GasWanted: int64(result.GasWanted), // TODO: Should type accept unsigned ints? + GasUsed: int64(result.GasUsed), // TODO: Should type accept unsigned ints? Tags: result.Tags, } } @@ -477,8 +477,8 @@ func (app *BaseApp) DeliverTx(txBytes []byte) (res abci.ResponseDeliverTx) { Codespace: string(result.Codespace), Data: result.Data, Log: result.Log, - GasWanted: result.GasWanted, - GasUsed: result.GasUsed, + GasWanted: int64(result.GasWanted), // TODO: Should type accept unsigned ints? + GasUsed: int64(result.GasUsed), // TODO: Should type accept unsigned ints? Tags: result.Tags, } } @@ -614,7 +614,7 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte, tx sdk.Tx) (result sdk // NOTE: GasWanted should be returned by the AnteHandler. GasUsed is // determined by the GasMeter. We need access to the context to get the gas // meter so we initialize upfront. - var gasWanted int64 + var gasWanted uint64 ctx := app.getContextForAnte(mode, txBytes) ctx = app.initializeContext(ctx, mode) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 9c2e7e1a0da7..ba3830e920ad 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -618,7 +618,7 @@ func TestConcurrentCheckDeliver(t *testing.T) { // Simulate() and Query("/app/simulate", txBytes) should give // the same results. func TestSimulateTx(t *testing.T) { - gasConsumed := int64(5) + gasConsumed := uint64(5) anteOpt := func(bapp *BaseApp) { bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, res sdk.Result, abort bool) { @@ -765,7 +765,7 @@ func TestRunInvalidTransaction(t *testing.T) { // Test that transactions exceeding gas limits fail func TestTxGasLimits(t *testing.T) { - gasGranted := int64(10) + gasGranted := uint64(10) anteOpt := func(bapp *BaseApp) { bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, res sdk.Result, abort bool) { newCtx = ctx.WithGasMeter(sdk.NewGasMeter(gasGranted)) @@ -790,7 +790,7 @@ func TestTxGasLimits(t *testing.T) { }() count := tx.(*txTest).Counter - newCtx.GasMeter().ConsumeGas(count, "counter-ante") + newCtx.GasMeter().ConsumeGas(uint64(count), "counter-ante") res = sdk.Result{ GasWanted: gasGranted, } @@ -802,7 +802,7 @@ func TestTxGasLimits(t *testing.T) { routerOpt := func(bapp *BaseApp) { bapp.Router().AddRoute(routeMsgCounter, func(ctx sdk.Context, msg sdk.Msg) sdk.Result { count := msg.(msgCounter).Counter - ctx.GasMeter().ConsumeGas(count, "counter-handler") + ctx.GasMeter().ConsumeGas(uint64(count), "counter-handler") return sdk.Result{} }) } @@ -813,7 +813,7 @@ func TestTxGasLimits(t *testing.T) { testCases := []struct { tx *txTest - gasUsed int64 + gasUsed uint64 fail bool }{ {newTxCounter(0, 0), 0, false}, diff --git a/client/flags.go b/client/flags.go index dfadab07e43f..ffb2a0c2f04f 100644 --- a/client/flags.go +++ b/client/flags.go @@ -124,7 +124,7 @@ func RegisterRestServerFlags(cmd *cobra.Command) *cobra.Command { // GasSetting encapsulates the possible values passed through the --gas flag. type GasSetting struct { Simulate bool - Gas int64 + Gas uint64 } // Type returns the flag's value type. @@ -140,18 +140,18 @@ func (v *GasSetting) String() string { if v.Simulate { return GasFlagSimulate } - return strconv.FormatInt(v.Gas, 10) + return strconv.FormatUint(v.Gas, 10) } // ParseGasFlag parses the value of the --gas flag. -func ReadGasFlag(s string) (simulate bool, gas int64, err error) { +func ReadGasFlag(s string) (simulate bool, gas uint64, err error) { switch s { case "": gas = DefaultGasLimit case GasFlagSimulate: simulate = true default: - gas, err = strconv.ParseInt(s, 10, 64) + gas, err = strconv.ParseUint(s, 10, 64) if err != nil { err = fmt.Errorf("gas must be either integer or %q", GasFlagSimulate) return diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index 1be908e98bdb..885e4b914f7c 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -283,7 +283,7 @@ func TestCoinSend(t *testing.T) { // test failure with negative gas res, body, _ = doSendWithGas(t, port, seed, name, password, addr, "-200", 0, "") - require.Equal(t, http.StatusInternalServerError, res.StatusCode, body) + require.Equal(t, http.StatusBadRequest, res.StatusCode, body) // test failure with 0 gas res, body, _ = doSendWithGas(t, port, seed, name, password, addr, "0", 0, "") @@ -389,8 +389,8 @@ func TestCoinSendGenerateSignAndBroadcast(t *testing.T) { require.Nil(t, cdc.UnmarshalJSON([]byte(body), &resultTx)) require.Equal(t, uint32(0), resultTx.CheckTx.Code) require.Equal(t, uint32(0), resultTx.DeliverTx.Code) - require.Equal(t, gasEstimate, resultTx.DeliverTx.GasWanted) - require.Equal(t, gasEstimate, resultTx.DeliverTx.GasUsed) + require.Equal(t, gasEstimate, uint64(resultTx.DeliverTx.GasWanted)) + require.Equal(t, gasEstimate, uint64(resultTx.DeliverTx.GasUsed)) } func TestTxs(t *testing.T) { diff --git a/client/utils/rest.go b/client/utils/rest.go index 53c6186921db..13347098b39e 100644 --- a/client/utils/rest.go +++ b/client/utils/rest.go @@ -34,7 +34,7 @@ func WriteErrorResponse(w http.ResponseWriter, status int, err string) { // WriteSimulationResponse prepares and writes an HTTP // response for transactions simulations. -func WriteSimulationResponse(w http.ResponseWriter, gas int64) { +func WriteSimulationResponse(w http.ResponseWriter, gas uint64) { w.WriteHeader(http.StatusOK) w.Write([]byte(fmt.Sprintf(`{"gas_estimate":%v}`, gas))) } diff --git a/client/utils/utils.go b/client/utils/utils.go index fee7c7fe2557..46bb9799c1c2 100644 --- a/client/utils/utils.go +++ b/client/utils/utils.go @@ -71,7 +71,7 @@ func EnrichCtxWithGas(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, name // CalculateGas simulates the execution of a transaction and returns // both the estimate obtained by the query and the adjusted amount. -func CalculateGas(queryFunc func(string, common.HexBytes) ([]byte, error), cdc *amino.Codec, txBytes []byte, adjustment float64) (estimate, adjusted int64, err error) { +func CalculateGas(queryFunc func(string, common.HexBytes) ([]byte, error), cdc *amino.Codec, txBytes []byte, adjustment float64) (estimate, adjusted uint64, err error) { // run a simulation (via /app/simulate query) to // estimate gas and update TxBuilder accordingly rawRes, err := queryFunc("/app/simulate", txBytes) @@ -152,7 +152,7 @@ func SignStdTx(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, name string, // nolint // SimulateMsgs simulates the transaction and returns the gas estimate and the adjusted value. -func simulateMsgs(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, name string, msgs []sdk.Msg) (estimated, adjusted int64, err error) { +func simulateMsgs(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, name string, msgs []sdk.Msg) (estimated, adjusted uint64, err error) { txBytes, err := txBldr.BuildWithPubKey(name, msgs) if err != nil { return @@ -161,11 +161,11 @@ func simulateMsgs(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, name stri return } -func adjustGasEstimate(estimate int64, adjustment float64) int64 { - return int64(adjustment * float64(estimate)) +func adjustGasEstimate(estimate uint64, adjustment float64) uint64 { + return uint64(adjustment * float64(estimate)) } -func parseQueryResponse(cdc *amino.Codec, rawRes []byte) (int64, error) { +func parseQueryResponse(cdc *amino.Codec, rawRes []byte) (uint64, error) { var simulationResult sdk.Result if err := cdc.UnmarshalBinaryLengthPrefixed(rawRes, &simulationResult); err != nil { return 0, err diff --git a/client/utils/utils_test.go b/client/utils/utils_test.go index c3bf315699ac..b22a50806cc8 100644 --- a/client/utils/utils_test.go +++ b/client/utils/utils_test.go @@ -14,16 +14,16 @@ func TestParseQueryResponse(t *testing.T) { cdc := app.MakeCodec() sdkResBytes := cdc.MustMarshalBinaryLengthPrefixed(sdk.Result{GasUsed: 10}) gas, err := parseQueryResponse(cdc, sdkResBytes) - assert.Equal(t, gas, int64(10)) + assert.Equal(t, gas, uint64(10)) assert.Nil(t, err) gas, err = parseQueryResponse(cdc, []byte("fuzzy")) - assert.Equal(t, gas, int64(0)) + assert.Equal(t, gas, uint64(0)) assert.NotNil(t, err) } func TestCalculateGas(t *testing.T) { cdc := app.MakeCodec() - makeQueryFunc := func(gasUsed int64, wantErr bool) func(string, common.HexBytes) ([]byte, error) { + makeQueryFunc := func(gasUsed uint64, wantErr bool) func(string, common.HexBytes) ([]byte, error) { return func(string, common.HexBytes) ([]byte, error) { if wantErr { return nil, errors.New("") @@ -32,15 +32,15 @@ func TestCalculateGas(t *testing.T) { } } type args struct { - queryFuncGasUsed int64 + queryFuncGasUsed uint64 queryFuncWantErr bool adjustment float64 } tests := []struct { name string args args - wantEstimate int64 - wantAdjusted int64 + wantEstimate uint64 + wantAdjusted uint64 wantErr bool }{ {"error", args{0, true, 1.2}, 0, 0, true}, diff --git a/cmd/gaia/app/genesis.go b/cmd/gaia/app/genesis.go index 7d95bbfa7d51..5ce9ab8b95e0 100644 --- a/cmd/gaia/app/genesis.go +++ b/cmd/gaia/app/genesis.go @@ -91,7 +91,6 @@ func (ga *GenesisAccount) ToAccount() (acc *auth.BaseAccount) { } } - // Create the core parameters for genesis initialization for gaia // note that the pubkey input is this machines pubkey func GaiaAppGenState(cdc *codec.Codec, genDoc tmtypes.GenesisDoc, appGenTxs []json.RawMessage) ( @@ -279,7 +278,7 @@ func CollectStdTxs(cdc *codec.Codec, moniker string, genTxsDir string, genDoc tm func NewDefaultGenesisAccount(addr sdk.AccAddress) GenesisAccount { accAuth := auth.NewBaseAccountWithAddress(addr) - coins :=sdk.Coins{ + coins := sdk.Coins{ {"fooToken", sdk.NewInt(1000)}, {bondDenom, freeFermionsAcc}, } diff --git a/cmd/gaia/cli_test/cli_test.go b/cmd/gaia/cli_test/cli_test.go index 62f4d0d64f04..26e6fcaa3673 100644 --- a/cmd/gaia/cli_test/cli_test.go +++ b/cmd/gaia/cli_test/cli_test.go @@ -475,7 +475,7 @@ func TestGaiaCLISendGenerateSignAndBroadcast(t *testing.T) { require.True(t, success) require.Empty(t, stderr) msg := unmarshalStdTx(t, stdout) - require.Equal(t, msg.Fee.Gas, int64(client.DefaultGasLimit)) + require.Equal(t, msg.Fee.Gas, uint64(client.DefaultGasLimit)) require.Equal(t, len(msg.Msgs), 1) require.Equal(t, 0, len(msg.GetSignatures())) @@ -486,7 +486,7 @@ func TestGaiaCLISendGenerateSignAndBroadcast(t *testing.T) { require.True(t, success) require.Empty(t, stderr) msg = unmarshalStdTx(t, stdout) - require.Equal(t, msg.Fee.Gas, int64(100)) + require.Equal(t, msg.Fee.Gas, uint64(100)) require.Equal(t, len(msg.Msgs), 1) require.Equal(t, 0, len(msg.GetSignatures())) @@ -543,9 +543,8 @@ func TestGaiaCLISendGenerateSignAndBroadcast(t *testing.T) { } require.Nil(t, app.MakeCodec().UnmarshalJSON([]byte(stdout), &result)) - require.Equal(t, msg.Fee.Gas, result.Response.GasUsed) - require.Equal(t, msg.Fee.Gas, result.Response.GasWanted) - + require.Equal(t, msg.Fee.Gas, uint64(result.Response.GasUsed)) + require.Equal(t, msg.Fee.Gas, uint64(result.Response.GasWanted)) tests.WaitForNextNBlocksTM(2, port) barAcc := executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", barAddr, flags)) diff --git a/cmd/gaia/init/genesis_accts_test.go b/cmd/gaia/init/genesis_accts_test.go index 8825a8cd3483..49634a90c4c4 100644 --- a/cmd/gaia/init/genesis_accts_test.go +++ b/cmd/gaia/init/genesis_accts_test.go @@ -25,14 +25,14 @@ func TestAddGenesisAccount(t *testing.T) { }{ { "valid account", - args{ - app.GenesisState{}, - addr1, - sdk.Coins{}, - }, - false}, + args{ + app.GenesisState{}, + addr1, + sdk.Coins{}, + }, + false}, {"dup account", args{ - app.GenesisState{Accounts: []app.GenesisAccount{app.GenesisAccount{Address:addr1}}}, + app.GenesisState{Accounts: []app.GenesisAccount{{Address: addr1}}}, addr1, sdk.Coins{}}, true}, } diff --git a/docs/examples/democoin/cmd/democoind/main.go b/docs/examples/democoin/cmd/democoind/main.go index 29e2640fde31..730109798c16 100644 --- a/docs/examples/democoin/cmd/democoind/main.go +++ b/docs/examples/democoin/cmd/democoind/main.go @@ -30,7 +30,6 @@ const ( flagClientHome = "home-client" ) - // coolGenAppParams sets up the app_state and appends the cool app state func CoolAppGenState(cdc *codec.Codec, genDoc tmtypes.GenesisDoc, appGenTxs []json.RawMessage) ( appState json.RawMessage, err error) { diff --git a/server/init.go b/server/init.go index 3a6c6adae599..e1655c27ea68 100644 --- a/server/init.go +++ b/server/init.go @@ -15,7 +15,6 @@ import ( tmtypes "github.com/tendermint/tendermint/types" ) - // SimpleGenTx is a simple genesis tx type SimpleGenTx struct { Addr sdk.AccAddress `json:"addr"` @@ -23,7 +22,6 @@ type SimpleGenTx struct { //_____________________________________________________________________ - // Generate a genesis transaction func SimpleAppGenTx(cdc *codec.Codec, pk crypto.PubKey) ( appGenTx, cliPrint json.RawMessage, validator types.GenesisValidator, err error) { diff --git a/store/gaskvstore_test.go b/store/gaskvstore_test.go index ba77bae1f889..69f4ae204e4d 100644 --- a/store/gaskvstore_test.go +++ b/store/gaskvstore_test.go @@ -73,15 +73,15 @@ func testGasKVStoreWrap(t *testing.T, store KVStore) { meter := sdk.NewGasMeter(10000) store = store.Gas(meter, sdk.GasConfig{HasCost: 10}) - require.Equal(t, int64(0), meter.GasConsumed()) + require.Equal(t, uint64(0), meter.GasConsumed()) store.Has([]byte("key")) - require.Equal(t, int64(10), meter.GasConsumed()) + require.Equal(t, uint64(10), meter.GasConsumed()) store = store.Gas(meter, sdk.GasConfig{HasCost: 20}) store.Has([]byte("key")) - require.Equal(t, int64(40), meter.GasConsumed()) + require.Equal(t, uint64(40), meter.GasConsumed()) } func TestGasKVStoreWrap(t *testing.T) { diff --git a/types/context.go b/types/context.go index bfb4c58fed10..267e66681528 100644 --- a/types/context.go +++ b/types/context.go @@ -203,8 +203,10 @@ func (c Context) WithConsensusParams(params *abci.ConsensusParams) Context { if params == nil { return c } + + // TODO: Do we need to handle invalid MaxGas values? return c.withValue(contextKeyConsensusParams, params). - WithGasMeter(NewGasMeter(params.BlockSize.MaxGas)) + WithGasMeter(NewGasMeter(uint64(params.BlockSize.MaxGas))) } func (c Context) WithChainID(chainID string) Context { return c.withValue(contextKeyChainID, chainID) } diff --git a/types/gas.go b/types/gas.go index 7b034746703b..656bd1d04c97 100644 --- a/types/gas.go +++ b/types/gas.go @@ -18,13 +18,19 @@ var ( ) // Gas measured by the SDK -type Gas = int64 +type Gas = uint64 // ErrorOutOfGas defines an error thrown when an action results in out of gas. type ErrorOutOfGas struct { Descriptor string } +// ErrorGasOverflow defines an error thrown when an action results gas consumption +// unsigned integer overflow. +type ErrorGasOverflow struct { + Descriptor string +} + // GasMeter interface to track gas consumption type GasMeter interface { GasConsumed() Gas @@ -49,7 +55,14 @@ func (g *basicGasMeter) GasConsumed() Gas { } func (g *basicGasMeter) ConsumeGas(amount Gas, descriptor string) { - g.consumed += amount + var overflow bool + + // TODO: Should we set the consumed field after overflow checking? + g.consumed, overflow = AddUint64Overflow(g.consumed, amount) + if overflow { + panic(ErrorGasOverflow{descriptor}) + } + if g.consumed > g.limit { panic(ErrorOutOfGas{descriptor}) } @@ -71,7 +84,13 @@ func (g *infiniteGasMeter) GasConsumed() Gas { } func (g *infiniteGasMeter) ConsumeGas(amount Gas, descriptor string) { - g.consumed += amount + var overflow bool + + // TODO: Should we set the consumed field after overflow checking? + g.consumed, overflow = AddUint64Overflow(g.consumed, amount) + if overflow { + panic(ErrorGasOverflow{descriptor}) + } } // GasConfig defines gas cost for each operation on KVStores diff --git a/types/gas_test.go b/types/gas_test.go index cd2384d12d39..f4452053fbd0 100644 --- a/types/gas_test.go +++ b/types/gas_test.go @@ -21,7 +21,7 @@ func TestGasMeter(t *testing.T) { for tcnum, tc := range cases { meter := NewGasMeter(tc.limit) - used := int64(0) + used := uint64(0) for unum, usage := range tc.usage { used += usage diff --git a/types/int.go b/types/int.go index c2bef7a64fcb..2083168e9cfd 100644 --- a/types/int.go +++ b/types/int.go @@ -2,6 +2,7 @@ package types import ( "encoding/json" + "math" "testing" "math/big" @@ -529,6 +530,16 @@ func (i *Uint) UnmarshalJSON(bz []byte) error { //__________________________________________________________________________ +// AddUint64Overflow performs the addition operation on two uint64 integers and +// returns a boolean on whether or not the result overflows. +func AddUint64Overflow(a, b uint64) (uint64, bool) { + if math.MaxUint64-a < b { + return 0, true + } + + return a + b, false +} + // intended to be used with require/assert: require.True(IntEq(...)) func IntEq(t *testing.T, exp, got Int) (*testing.T, bool, string, string, string) { return t, exp.Equal(got), "expected:\t%v\ngot:\t\t%v", exp.String(), got.String() diff --git a/types/int_test.go b/types/int_test.go index cd357c4f77ac..78bee66bfaa0 100644 --- a/types/int_test.go +++ b/types/int_test.go @@ -590,3 +590,28 @@ func TestEncodingTableUint(t *testing.T) { require.Equal(t, tc.i, i, "Unmarshaled value is different from expected. tc #%d", tcnum) } } + +func TestAddUint64Overflow(t *testing.T) { + testCases := []struct { + a, b uint64 + result uint64 + overflow bool + }{ + {0, 0, 0, false}, + {100, 100, 200, false}, + {math.MaxUint64 / 2, math.MaxUint64/2 + 1, math.MaxUint64, false}, + {math.MaxUint64 / 2, math.MaxUint64/2 + 2, 0, true}, + } + + for i, tc := range testCases { + res, overflow := AddUint64Overflow(tc.a, tc.b) + require.Equal( + t, tc.overflow, overflow, + "invalid overflow result; tc: #%d, a: %d, b: %d", i, tc.a, tc.b, + ) + require.Equal( + t, tc.result, res, + "invalid uint64 result; tc: #%d, a: %d, b: %d", i, tc.a, tc.b, + ) + } +} diff --git a/types/result.go b/types/result.go index 20893a076fe3..924b73b49fbb 100644 --- a/types/result.go +++ b/types/result.go @@ -16,10 +16,10 @@ type Result struct { Log string // GasWanted is the maximum units of work we allow this tx to perform. - GasWanted int64 + GasWanted uint64 // GasUsed is the amount of gas actually consumed. NOTE: unimplemented - GasUsed int64 + GasUsed uint64 // Tx fee amount and denom. FeeAmount int64 diff --git a/x/auth/ante.go b/x/auth/ante.go index 8539be06a42f..7beb643c562c 100644 --- a/x/auth/ante.go +++ b/x/auth/ante.go @@ -71,6 +71,7 @@ func NewAnteHandler(am AccountKeeper, fck FeeCollectionKeeper) sdk.AnteHandler { if err != nil { return newCtx, err.Result(), true } + // charge gas for the memo newCtx.GasMeter().ConsumeGas(memoCostPerByte*sdk.Gas(len(stdTx.GetMemo())), "memo") @@ -260,13 +261,16 @@ func consumeSignatureVerificationGas(meter sdk.GasMeter, pubkey crypto.PubKey) { } } -func adjustFeesByGas(fees sdk.Coins, gas int64) sdk.Coins { +func adjustFeesByGas(fees sdk.Coins, gas uint64) sdk.Coins { gasCost := gas / gasPerUnitCost gasFees := make(sdk.Coins, len(fees)) + // TODO: Make this not price all coins in the same way + // TODO: Undo int64 casting once unsigned integers are supported for coins for i := 0; i < len(fees); i++ { - gasFees[i] = sdk.NewInt64Coin(fees[i].Denom, gasCost) + gasFees[i] = sdk.NewInt64Coin(fees[i].Denom, int64(gasCost)) } + return fees.Plus(gasFees) } @@ -306,10 +310,12 @@ func ensureSufficientMempoolFees(ctx sdk.Context, stdTx StdTx) sdk.Result { } func setGasMeter(simulate bool, ctx sdk.Context, stdTx StdTx) sdk.Context { - // set the gas meter + // In various cases such as simulation and during the genesis block, we do not + // meter any gas utilization. if simulate || ctx.BlockHeight() == 0 { return ctx.WithGasMeter(sdk.NewInfiniteGasMeter()) } + return ctx.WithGasMeter(sdk.NewGasMeter(stdTx.Fee.Gas)) } diff --git a/x/auth/ante_test.go b/x/auth/ante_test.go index c376d29961d4..0e8d13957a4f 100644 --- a/x/auth/ante_test.go +++ b/x/auth/ante_test.go @@ -677,7 +677,7 @@ func TestConsumeSignatureVerificationGas(t *testing.T) { tests := []struct { name string args args - gasConsumed int64 + gasConsumed uint64 wantPanic bool }{ {"PubKeyEd25519", args{sdk.NewInfiniteGasMeter(), ed25519.GenPrivKey().PubKey()}, ed25519VerifyCost, false}, @@ -699,7 +699,7 @@ func TestConsumeSignatureVerificationGas(t *testing.T) { func TestAdjustFeesByGas(t *testing.T) { type args struct { fee sdk.Coins - gas int64 + gas uint64 } tests := []struct { name string diff --git a/x/auth/client/txbuilder/txbuilder.go b/x/auth/client/txbuilder/txbuilder.go index f516de4513d5..593d745abfeb 100644 --- a/x/auth/client/txbuilder/txbuilder.go +++ b/x/auth/client/txbuilder/txbuilder.go @@ -16,7 +16,7 @@ type TxBuilder struct { Codec *codec.Codec AccountNumber int64 Sequence int64 - Gas int64 // TODO: should this turn into uint64? requires further discussion - see #2173 + Gas uint64 GasAdjustment float64 SimulateGas bool ChainID string @@ -61,7 +61,7 @@ func (bldr TxBuilder) WithChainID(chainID string) TxBuilder { } // WithGas returns a copy of the context with an updated gas. -func (bldr TxBuilder) WithGas(gas int64) TxBuilder { +func (bldr TxBuilder) WithGas(gas uint64) TxBuilder { bldr.Gas = gas return bldr } diff --git a/x/auth/client/txbuilder/txbuilder_test.go b/x/auth/client/txbuilder/txbuilder_test.go index 3ad2ad4123d8..f4f9163a0303 100644 --- a/x/auth/client/txbuilder/txbuilder_test.go +++ b/x/auth/client/txbuilder/txbuilder_test.go @@ -9,8 +9,8 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/tendermint/tendermint/crypto/ed25519" stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types" + "github.com/tendermint/tendermint/crypto/ed25519" ) var ( @@ -23,7 +23,7 @@ func TestTxBuilderBuild(t *testing.T) { Codec *codec.Codec AccountNumber int64 Sequence int64 - Gas int64 + Gas uint64 GasAdjustment float64 SimulateGas bool ChainID string diff --git a/x/auth/stdtx.go b/x/auth/stdtx.go index 84bf88a4b7e5..ba1c65b84593 100644 --- a/x/auth/stdtx.go +++ b/x/auth/stdtx.go @@ -70,10 +70,10 @@ func (tx StdTx) GetSignatures() []StdSignature { return tx.Signatures } // which must be above some miminum to be accepted into the mempool. type StdFee struct { Amount sdk.Coins `json:"amount"` - Gas int64 `json:"gas"` + Gas uint64 `json:"gas"` } -func NewStdFee(gas int64, amount ...sdk.Coin) StdFee { +func NewStdFee(gas uint64, amount ...sdk.Coin) StdFee { return StdFee{ Amount: amount, Gas: gas,