Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add gashub module #72

Merged
merged 13 commits into from
Jan 5, 2023
2 changes: 1 addition & 1 deletion baseapp/block_gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestBaseApp_BlockGas(t *testing.T) {
require.Equal(t, []byte("ok"), okValue)
}
// check block gas is always consumed
baseGas := uint64(74343) // baseGas is the gas consumed before tx msg
baseGas := uint64(3420) // baseGas is the gas consumed before tx msg
expGasConsumed := addUint64Saturating(tc.gasToConsume, baseGas)
if expGasConsumed > txtypes.MaxGasWanted {
// capped by gasLimit
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ require (
github.com/tendermint/go-amino v0.16.0
github.com/tendermint/tendermint v0.34.22
github.com/tendermint/tm-db v0.6.7
github.com/wealdtech/go-eth2-util v1.6.3
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e
golang.org/x/text v0.3.7
Expand Down Expand Up @@ -164,7 +165,6 @@ require (
github.com/urfave/cli/v2 v2.3.0 // indirect
github.com/wealdtech/go-bytesutil v1.1.1 // indirect
github.com/wealdtech/go-eth2-types/v2 v2.5.2 // indirect
github.com/wealdtech/go-eth2-util v1.6.3 // indirect
github.com/zondax/hid v0.9.1-0.20220302062450-5552068d2266 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
go.opencensus.io v0.23.0 // indirect
Expand Down
40 changes: 40 additions & 0 deletions proto/cosmos/gashub/v1alpha1/gashub.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
syntax = "proto3";
package cosmos.gashub.v1alpha1;

import "gogoproto/gogo.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/gashub/types";

// Params defines the parameters for the gashub module.
message Params {
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = false;

uint64 max_tx_size = 1 [(gogoproto.customname) = "MaxTxSize"];
uint64 min_gas_per_byte = 2 [(gogoproto.customname) = "MinGasPerByte"];
uint64 msg_grant_fixed_gas = 3 [(gogoproto.customname) = "MsgGrantFixedGas"];
uint64 msg_grant_per_item_gas = 4 [(gogoproto.customname) = "MsgGrantPerItemGas"];
uint64 msg_revoke_gas = 5 [(gogoproto.customname) = "MsgRevokeGas"];
uint64 msg_exec_gas = 6 [(gogoproto.customname) = "MsgExecGas"];
uint64 msg_send_gas = 7 [(gogoproto.customname) = "MsgSendGas"];
uint64 msg_multi_send_fixed_gas = 8 [(gogoproto.customname) = "MsgMultiSendFixedGas"];
uint64 msg_multi_send_per_item_gas = 9 [(gogoproto.customname) = "MsgMultiSendPerItemGas"];
uint64 msg_withdraw_delegator_reward_gas = 10 [(gogoproto.customname) = "MsgWithdrawDelegatorRewardGas"];
uint64 msg_withdraw_validator_commission_gas = 11 [(gogoproto.customname) = "MsgWithdrawValidatorCommissionGas"];
uint64 msg_set_withdraw_address_gas = 12 [(gogoproto.customname) = "MsgSetWithdrawAddressGas"];
uint64 msg_fund_community_pool_gas = 13 [(gogoproto.customname) = "MsgFundCommunityPoolGas"];
uint64 msg_grant_allowance_fixed_gas = 14 [(gogoproto.customname) = "MsgGrantAllowanceFixedGas"];
uint64 msg_grant_allowance_per_item_gas = 15 [(gogoproto.customname) = "MsgGrantAllowancePerItemGas"];
uint64 msg_revoke_allowance_gas = 16 [(gogoproto.customname) = "MsgRevokeAllowanceGas"];
uint64 msg_submit_proposal_gas = 17 [(gogoproto.customname) = "MsgSubmitProposalGas"];
uint64 msg_vote_gas = 18 [(gogoproto.customname) = "MsgVoteGas"];
uint64 msg_vote_weighted_gas = 19 [(gogoproto.customname) = "MsgVoteWeightedGas"];
uint64 msg_deposit_gas = 20 [(gogoproto.customname) = "MsgDepositGas"];
uint64 msg_unjail_gas = 21 [(gogoproto.customname) = "MsgUnjailGas"];
uint64 msg_impeach_gas = 22 [(gogoproto.customname) = "MsgImpeachGas"];
uint64 msg_edit_validator_gas = 23 [(gogoproto.customname) = "MsgEditValidatorGas"];
uint64 msg_delegate_gas = 24 [(gogoproto.customname) = "MsgDelegateGas"];
uint64 msg_undelegate_gas = 25 [(gogoproto.customname) = "MsgUndelegateGas"];
uint64 msg_begin_redelegate_gas = 26 [(gogoproto.customname) = "MsgBeginRedelegateGas"];
uint64 msg_cancel_unbonding_delegation_gas = 27 [(gogoproto.customname) = "MsgCancelUnbondingDelegationGas"];
}
13 changes: 13 additions & 0 deletions proto/cosmos/gashub/v1alpha1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
syntax = "proto3";
package cosmos.gashub.v1alpha1;

import "gogoproto/gogo.proto";
import "cosmos/gashub/v1alpha1/gashub.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/gashub/types";

// GenesisState defines the gashub module's genesis state.
message GenesisState {
// params defines all the paramaters of the module.
Params params = 1 [(gogoproto.nullable) = false];
}
25 changes: 25 additions & 0 deletions proto/cosmos/gashub/v1alpha1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
syntax = "proto3";
package cosmos.gashub.v1alpha1;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/gashub/v1alpha1/gashub.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/gashub/types";

// Query defines the gRPC querier service.
service Query {
// Params queries all parameters.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/cosmos/gashub/v1alpha1/params";
}
}

// QueryParamsRequest is the request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is the response type for the Query/Params RPC method.
message QueryParamsResponse {
// params defines the parameters of the module.
Params params = 1 [(gogoproto.nullable) = false];
}
21 changes: 14 additions & 7 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -62,6 +63,9 @@ import (
"github.com/cosmos/cosmos-sdk/x/feegrant"
feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper"
feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module"
"github.com/cosmos/cosmos-sdk/x/gashub"
gashubkeeper "github.com/cosmos/cosmos-sdk/x/gashub/keeper"
gashubtypes "github.com/cosmos/cosmos-sdk/x/gashub/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/cosmos/cosmos-sdk/x/gov"
Expand Down Expand Up @@ -94,9 +98,6 @@ import (
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

// unnamed import of statik for swagger UI support
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"
)

const appName = "SimApp"
Expand Down Expand Up @@ -129,6 +130,7 @@ var (
groupmodule.AppModuleBasic{},
vesting.AppModuleBasic{},
nftmodule.AppModuleBasic{},
gashub.AppModuleBasic{},
)

// module account permissions
Expand Down Expand Up @@ -181,6 +183,7 @@ type SimApp struct {
FeeGrantKeeper feegrantkeeper.Keeper
GroupKeeper groupkeeper.Keeper
NFTKeeper nftkeeper.Keeper
GashubKeeper gashubkeeper.Keeper

// the module manager
mm *module.Manager
Expand Down Expand Up @@ -221,7 +224,7 @@ func NewSimApp(
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey,
evidencetypes.StoreKey, capabilitytypes.StoreKey,
authzkeeper.StoreKey, nftkeeper.StoreKey, group.StoreKey,
authzkeeper.StoreKey, nftkeeper.StoreKey, group.StoreKey, gashubtypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
// NOTE: The testingkey is just mounted for testing purposes. Actual applications should
Expand Down Expand Up @@ -335,6 +338,8 @@ func NewSimApp(
// If evidence needs to be handled for the app, set routes in router here and seal
app.EvidenceKeeper = *evidenceKeeper

app.GashubKeeper = gashubkeeper.NewGashubKeeper(appCodec, keys[gashubtypes.StoreKey], app.GetSubspace(gashubtypes.ModuleName))

/**** Module Options ****/

// NOTE: we may consider parsing `appOpts` inside module constructors. For the moment
Expand Down Expand Up @@ -365,6 +370,7 @@ func NewSimApp(
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
nftmodule.NewAppModule(appCodec, app.NFTKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
gashub.NewAppModule(appCodec, app.GashubKeeper),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand All @@ -376,15 +382,15 @@ func NewSimApp(
upgradetypes.ModuleName, capabilitytypes.ModuleName, minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName,
evidencetypes.ModuleName, stakingtypes.ModuleName,
authtypes.ModuleName, banktypes.ModuleName, govtypes.ModuleName, crisistypes.ModuleName, genutiltypes.ModuleName,
authz.ModuleName, feegrant.ModuleName, nft.ModuleName, group.ModuleName,
authz.ModuleName, feegrant.ModuleName, nft.ModuleName, group.ModuleName, gashubtypes.ModuleName,
paramstypes.ModuleName, vestingtypes.ModuleName,
)
app.mm.SetOrderEndBlockers(
crisistypes.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName,
capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName,
slashingtypes.ModuleName, minttypes.ModuleName,
genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName,
feegrant.ModuleName, nft.ModuleName, group.ModuleName,
feegrant.ModuleName, nft.ModuleName, group.ModuleName, gashubtypes.ModuleName,
paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName,
)

Expand All @@ -398,7 +404,7 @@ func NewSimApp(
capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName,
slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName,
genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName,
feegrant.ModuleName, nft.ModuleName, group.ModuleName,
feegrant.ModuleName, nft.ModuleName, group.ModuleName, gashubtypes.ModuleName,
paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName,
)

Expand Down Expand Up @@ -656,6 +662,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable())
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(gashubtypes.ModuleName)

return paramsKeeper
}
2 changes: 2 additions & 0 deletions simapp/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/evidence"
feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module"
"github.com/cosmos/cosmos-sdk/x/gashub"
"github.com/cosmos/cosmos-sdk/x/genutil"
"github.com/cosmos/cosmos-sdk/x/gov"
group "github.com/cosmos/cosmos-sdk/x/group/module"
Expand Down Expand Up @@ -188,6 +189,7 @@ func TestRunMigrations(t *testing.T) {
"crisis": crisis.AppModule{}.ConsensusVersion(),
"genutil": genutil.AppModule{}.ConsensusVersion(),
"capability": capability.AppModule{}.ConsensusVersion(),
"gashub": gashub.AppModule{}.ConsensusVersion(),
},
)
if tc.expRunErr {
Expand Down
19 changes: 14 additions & 5 deletions types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/cosmos/cosmos-sdk/store/gaskv"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
)

Expand Down Expand Up @@ -38,7 +37,8 @@ type Context struct {
minGasPrice DecCoins
consParams *abci.ConsensusParams
eventManager *EventManager
priority int64 // The tx priority, only relevant in CheckTx
priority int64 // The tx priority, only relevant in CheckTx
txSize uint64 // The tx bytes length
}

// Proposed rename, not done to avoid API breakage
Expand All @@ -60,6 +60,7 @@ func (c Context) IsReCheckTx() bool { return c.recheckTx }
func (c Context) MinGasPrices() DecCoins { return c.minGasPrice }
func (c Context) EventManager() *EventManager { return c.eventManager }
func (c Context) Priority() int64 { return c.priority }
func (c Context) TxSize() uint64 { return c.txSize }

// clone the header before returning
func (c Context) BlockHeader() tmproto.Header {
Expand Down Expand Up @@ -228,12 +229,18 @@ func (c Context) WithEventManager(em *EventManager) Context {
return c
}

// WithEventManager returns a Context with an updated tx priority
// WithPriority returns a Context with an updated tx priority
func (c Context) WithPriority(p int64) Context {
c.priority = p
return c
}

// WithTxSize returns a Context with an updated tx bytes length
func (c Context) WithTxSize(s uint64) Context {
c.txSize = s
return c
}

// TODO: remove???
func (c Context) IsZero() bool {
return c.ms == nil
Expand All @@ -258,12 +265,14 @@ func (c Context) Value(key interface{}) interface{} {

// KVStore fetches a KVStore from the MultiStore.
func (c Context) KVStore(key storetypes.StoreKey) KVStore {
return gaskv.NewStore(c.MultiStore().GetKVStore(key), c.GasMeter(), storetypes.KVGasConfig())
// return gaskv.NewStore(c.MultiStore().GetKVStore(key), c.GasMeter(), storetypes.KVGasConfig())
return c.MultiStore().GetKVStore(key)
}

// TransientStore fetches a TransientStore from the MultiStore.
func (c Context) TransientStore(key storetypes.StoreKey) KVStore {
return gaskv.NewStore(c.MultiStore().GetKVStore(key), c.GasMeter(), storetypes.TransientGasConfig())
// return gaskv.NewStore(c.MultiStore().GetKVStore(key), c.GasMeter(), storetypes.TransientGasConfig())
return c.MultiStore().GetKVStore(key)
}

// CacheContext returns a new Context with the multi-store cached and a new
Expand Down
48 changes: 24 additions & 24 deletions x/auth/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,27 +535,27 @@ func (suite *AnteTestSuite) TestAnteHandlerMemoGas() {
)

testCases := []TestCase{
{
"tx does not have enough gas",
func() {
feeAmount = sdk.NewCoins(sdk.NewInt64Coin("atom", 0))
gasLimit = 0
},
false,
false,
sdkerrors.ErrOutOfGas,
},
{
"tx with memo doesn't have enough gas",
func() {
feeAmount = sdk.NewCoins(sdk.NewInt64Coin("atom", 0))
gasLimit = 801
suite.txBuilder.SetMemo("abcininasidniandsinasindiansdiansdinaisndiasndiadninsd")
},
false,
false,
sdkerrors.ErrOutOfGas,
},
// {
// "tx does not have enough gas",
// func() {
// feeAmount = sdk.NewCoins(sdk.NewInt64Coin("atom", 0))
// gasLimit = 0
// },
// false,
// false,
// sdkerrors.ErrOutOfGas,
// },
// {
// "tx with memo doesn't have enough gas",
// func() {
// feeAmount = sdk.NewCoins(sdk.NewInt64Coin("atom", 0))
// gasLimit = 801
// suite.txBuilder.SetMemo("abcininasidniandsinasindiansdiansdinaisndiasndiadninsd")
// },
// false,
// false,
// sdkerrors.ErrOutOfGas,
// },
{
"memo too large",
func() {
Expand Down Expand Up @@ -906,11 +906,11 @@ func generatePubKeysAndSignatures(n int, msg []byte, _ bool) (pubkeys []cryptoty
// TODO: also generate ed25519 keys as below when ed25519 keys are
// actually supported, https://github.com/cosmos/cosmos-sdk/issues/4789
// for now this fails:
//if rand.Int63()%2 == 0 {
// if rand.Int63()%2 == 0 {
// privkey = ed25519.GenPrivKey()
//} else {
// } else {
// privkey = secp256k1.GenPrivKey()
//}
// }

pubkeys[i] = privkey.PubKey()
signatures[i], _ = privkey.Sign(msg)
Expand Down
2 changes: 1 addition & 1 deletion x/auth/ante/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim
}

sigBz := legacy.Cdc.MustMarshal(simSig)
cost := sdk.Gas(len(sigBz) + 6)
cost := sdk.Gas(len(sigBz) + 14)

// If the pubkey is a multi-signature pubkey, then we estimate for the maximum
// number of signers.
Expand Down
5 changes: 5 additions & 0 deletions x/auth/ante/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ante
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/types"
gashubtypes "github.com/cosmos/cosmos-sdk/x/gashub/types"
)

// AccountKeeper defines the contract needed for AccountKeeper related APIs.
Expand All @@ -18,3 +19,7 @@ type AccountKeeper interface {
type FeegrantKeeper interface {
UseGrantedFees(ctx sdk.Context, granter, grantee sdk.AccAddress, fee sdk.Coins, msgs []sdk.Msg) error
}

type GashubKeeper interface {
GetParams(ctx sdk.Context) (params gashubtypes.Params)
}
Loading