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

Start global chain fee module #45

Merged
merged 4 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
14 changes: 9 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app
import (
"github.com/CosmWasm/wasmd/x/wasm"
wasmclient "github.com/CosmWasm/wasmd/x/wasm/client"
"github.com/confio/tgrade/x/globalfee"
"github.com/confio/tgrade/x/twasm"
twasmkeeper "github.com/confio/tgrade/x/twasm/keeper"
"github.com/cosmos/cosmos-sdk/baseapp"
Expand All @@ -19,7 +20,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
Expand Down Expand Up @@ -144,6 +145,7 @@ var (
evidence.AppModuleBasic{},
transfer.AppModuleBasic{},
vesting.AppModuleBasic{},
globalfee.AppModuleBasic{},
)

// module account permissions
Expand Down Expand Up @@ -396,6 +398,7 @@ func NewTgradeApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
ibc.NewAppModule(app.ibcKeeper),
params.NewAppModule(app.paramsKeeper),
transferModule,
globalfee.NewAppModule(app.getSubspace(globalfee.ModuleName)),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand All @@ -421,7 +424,7 @@ func NewTgradeApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName,
ibchost.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, ibctransfertypes.ModuleName,
// wasm after ibc transfer
twasm.ModuleName,
twasm.ModuleName, globalfee.ModuleName,
)

app.mm.RegisterInvariants(&app.crisisKeeper)
Expand Down Expand Up @@ -462,9 +465,9 @@ func NewTgradeApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)

anteHandler := ante.NewAnteHandler(
app.accountKeeper, app.bankKeeper, ante.DefaultSigVerificationGasConsumer,
encodingConfig.TxConfig.SignModeHandler(),
anteHandler := globalfee.NewAnteHandler(
alpe marked this conversation as resolved.
Show resolved Hide resolved
app.accountKeeper, app.bankKeeper, authante.DefaultSigVerificationGasConsumer,
encodingConfig.TxConfig.SignModeHandler(), app.getSubspace(globalfee.ModuleName),
)
app.SetAnteHandler(anteHandler)
app.SetEndBlocker(app.EndBlocker)
Expand Down Expand Up @@ -625,6 +628,7 @@ func initParamsKeeper(appCodec codec.BinaryMarshaler, legacyAmino *codec.LegacyA
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibchost.ModuleName)
paramsKeeper.Subspace(twasm.ModuleName)
paramsKeeper.Subspace(globalfee.ModuleName)
alpe marked this conversation as resolved.
Show resolved Hide resolved

return paramsKeeper
}
2 changes: 1 addition & 1 deletion app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

var emptyWasmOpts []wasm.Option = nil

func TestWasmdExport(t *testing.T) {
func TestTgradeExport(t *testing.T) {
db := db.NewMemDB()
gapp := NewTgradeApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, EmptyBaseAppOptions{}, emptyWasmOpts)

Expand Down
2 changes: 1 addition & 1 deletion app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
)

// The genesis state of the blockchain is represented here as a map of raw json
// GenesisState The genesis state of the blockchain is represented here as a map of raw json
// messages key'd by a identifier string.
// The identifier is used to determine which module genesis information belongs
// to so it may be appropriately routed during init chain.
Expand Down
50 changes: 50 additions & 0 deletions docs/proto/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

## Table of Contents

- [confio/globalfee/v1beta1/genesis.proto](#confio/globalfee/v1beta1/genesis.proto)
- [GenesisState](#confio.globalfee.v1beta1.GenesisState)
- [Params](#confio.globalfee.v1beta1.Params)

- [confio/twasm/v1beta1/contract_extension.proto](#confio/twasm/v1beta1/contract_extension.proto)
- [RegisteredCallback](#confio.twasm.v1beta1.RegisteredCallback)
- [TgradeContractDetails](#confio.twasm.v1beta1.TgradeContractDetails)
Expand All @@ -27,6 +31,52 @@



<a name="confio/globalfee/v1beta1/genesis.proto"></a>
<p align="right"><a href="#top">Top</a></p>

## confio/globalfee/v1beta1/genesis.proto



<a name="confio.globalfee.v1beta1.GenesisState"></a>

### GenesisState
GenesisState - initial state of module


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `params` | [Params](#confio.globalfee.v1beta1.Params) | | Params of this module |






<a name="confio.globalfee.v1beta1.Params"></a>

### Params
Params defines the set of module parameters.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `minimum_gas_prices` | [cosmos.base.v1beta1.DecCoin](#cosmos.base.v1beta1.DecCoin) | repeated | Minimum stores the minimum gas price(s) for all TX on the chain. When multiple coins are defined then they are accepted alternatively. The list must be sorted by denoms asc. No duplicate denoms or zero amount values allowed. For more information see https://docs.cosmos.network/master/modules/auth/01_concepts.html |
alpe marked this conversation as resolved.
Show resolved Hide resolved





<!-- end messages -->

<!-- end enums -->

<!-- end HasExtensions -->

<!-- end services -->



<a name="confio/twasm/v1beta1/contract_extension.proto"></a>
<p align="right"><a href="#top">Top</a></p>

Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ require (
github.com/stretchr/testify v1.7.0
github.com/tendermint/tendermint v0.34.10
github.com/tendermint/tm-db v0.6.4
github.com/tidwall/gjson v1.7.3
github.com/tidwall/gjson v1.7.4
github.com/tidwall/sjson v1.1.6
alpe marked this conversation as resolved.
Show resolved Hide resolved
google.golang.org/genproto v0.0.0-20210114201628-6edceaf6022f
google.golang.org/grpc v1.37.0
gopkg.in/yaml.v2 v2.4.0
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -584,12 +584,14 @@ github.com/tendermint/tm-db v0.6.2/go.mod h1:GYtQ67SUvATOcoY8/+x6ylk8Qo02BQyLrAs
github.com/tendermint/tm-db v0.6.3/go.mod h1:lfA1dL9/Y/Y8wwyPp2NMLyn5P5Ptr/gvDFNWtrCWSf8=
github.com/tendermint/tm-db v0.6.4 h1:3N2jlnYQkXNQclQwd/eKV/NzlqPlfK21cpRRIx80XXQ=
github.com/tendermint/tm-db v0.6.4/go.mod h1:dptYhIpJ2M5kUuenLr+Yyf3zQOv1SgBZcl8/BmWlMBw=
github.com/tidwall/gjson v1.7.3 h1:9dOulDrkCJf1mwljVMhXNQr9ZL2NvajRX7A1R8c6Qxw=
github.com/tidwall/gjson v1.7.3/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk=
github.com/tidwall/gjson v1.7.4 h1:19cchw8FOxkG5mdLRkGf9jqIqEyqdZhPqW60XfyFxk8=
github.com/tidwall/gjson v1.7.4/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk=
github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.1.0 h1:K3hMW5epkdAVwibsQEfR/7Zj0Qgt4DxtNumTq/VloO8=
github.com/tidwall/pretty v1.1.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tidwall/sjson v1.1.6 h1:8fDdlahON04OZBlTQCIatW8FstSFJz8oxidj5h0rmSQ=
github.com/tidwall/sjson v1.1.6/go.mod h1:KN3FZ7odvXIHPbJdhNorK/M9lWweVUbXsXXhrJ/kGOA=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
Expand Down
32 changes: 32 additions & 0 deletions proto/confio/globalfee/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
syntax = "proto3";
package confio.globalfee.v1beta1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmwasm/wasm/v1beta1/genesis.proto";

option go_package = "github.com/confio/tgrade/x/globalfee";

// GenesisState - initial state of module
message GenesisState {
// Params of this module
Params params = 1 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "params,omitempty"
];
}

// Params defines the set of module parameters.
message Params {
// Minimum stores the minimum gas price(s) for all TX on the chain.
// When multiple coins are defined then they are accepted alternatively.
// The list must be sorted by denoms asc. No duplicate denoms or zero amount
// values allowed. For more information see
// https://docs.cosmos.network/master/modules/auth/01_concepts.html
repeated cosmos.base.v1beta1.DecCoin minimum_gas_prices = 1 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "minimum,omitempty",
alpe marked this conversation as resolved.
Show resolved Hide resolved
(gogoproto.moretags) = "yaml:\"minimum_gas_pricess\"",
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins"
];
}
15 changes: 14 additions & 1 deletion testing/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,29 @@ func (c TgradeCli) AddKey(name string) string {

const defaultSrcAddr = "node0"

// FundAddress sends the token amount to the destination address
func (c TgradeCli) FundAddress(t *testing.T, destAddr, amount string) string {
require.NotEmpty(t, destAddr)
require.NotEmpty(t, amount)
cmd := []string{"tx", "send", defaultSrcAddr, destAddr, amount}
return c.run(c.withTXFlags(cmd...))
}

// RequireTxSuccess require the received response to contain the success code
func RequireTxSuccess(t *testing.T, got string) {
t.Helper()
code := gjson.Get(got, "code")
rawLog := gjson.Get(got, "raw_log")
rawLog := gjson.Get(got, "raw_log").String()
require.Equal(t, int64(0), code.Int(), rawLog)
}

// RequireTxFailure require the received response to contain any failure code and the passed msgsgs
func RequireTxFailure(t *testing.T, got string, containsMsgs ...string) {
t.Helper()
code := gjson.Get(got, "code")
rawLog := gjson.Get(got, "raw_log").String()
require.NotEqual(t, int64(0), code.Int(), rawLog)
for _, msg := range containsMsgs {
require.Contains(t, rawLog, msg)
}
}
42 changes: 42 additions & 0 deletions testing/global_fee_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// +build system_test

package testing

import (
"encoding/json"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
"github.com/tidwall/sjson"
"testing"
)

func TestGlobalFee(t *testing.T) {
sut.ResetChain(t)
sut.ModifyGenesisJson(t, SetGlobalMinFee(t, sdk.NewDecCoinFromDec("utgd", sdk.NewDecWithPrec(1, 3))))
alpe marked this conversation as resolved.
Show resolved Hide resolved
sut.StartChain(t)

cli := NewTgradeCli(t, sut, verbose)

const anyContract = "testing/contracts/tg4_group.wasm"
t.Log("Any transaction without enough fees should fail")
txResult := cli.CustomCommand("tx", "wasm", "store", anyContract, "--from=node0", "--gas=1500000", "--fees=1utg")
RequireTxFailure(t, txResult, "insufficient fee")

t.Log("Any transaction with enough fees should pass")
txResult = cli.CustomCommand("tx", "wasm", "store", anyContract, "--from=node0", "--gas=1500000", "--fees=1500utgd")
RequireTxSuccess(t, txResult)
}

// SetGlobalMinFee set the passed coins to the global minimum fee
func SetGlobalMinFee(t *testing.T, fees ...sdk.DecCoin) GenesisMutator {
return func(genesis []byte) []byte {
t.Helper()
coins := sdk.NewDecCoins(fees...)
require.NoError(t, coins.Validate())
val, err := json.Marshal(coins)
require.NoError(t, err)
state, err := sjson.SetRawBytes(genesis, "app_state.globalfee.params.minimum_gas_prices", val)
alpe marked this conversation as resolved.
Show resolved Hide resolved
require.NoError(t, err)
return state
}
}
2 changes: 1 addition & 1 deletion testing/poa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestProofOfAuthoritySetup(t *testing.T) {
valsetContractAddr,
},
}
sut.ModifyGenesis(t, commands...)
sut.ModifyGenesisCLI(t, commands...)
sut.StartChain(t)

// and then should be in list of privileged contracts
Expand Down
27 changes: 25 additions & 2 deletions testing/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,25 @@ func (s SystemUnderTest) ResetChain(t *testing.T) {
})
}

// ModifyGenesis executes the commands to modify the genesis
func (s SystemUnderTest) ModifyGenesis(t *testing.T, cmds ...[]string) {
// ModifyGenesisCLI executes the CLI commands to modify the genesis
func (s SystemUnderTest) ModifyGenesisCLI(t *testing.T, cmds ...[]string) {
s.ForEachNodeExecAndWait(t, cmds...)
}

type GenesisMutator func([]byte) []byte

// ModifyGenesisJson executes the callbacks to update the json representation
func (s SystemUnderTest) ModifyGenesisJson(t *testing.T, mutators ...GenesisMutator) {
current, err := ioutil.ReadFile(filepath.Join(workDir, s.nodePath(0), "config", "genesis.json"))
require.NoError(t, err)
for _, m := range mutators {
current = m(current)
}
out := storeTempFile(t, current)
defer os.Remove(out.Name())
s.SetGenesis(t, out.Name())
}

// SetGenesis copy genesis file to all nodes
func (s SystemUnderTest) SetGenesis(t *testing.T, srcPath string) {
in, err := os.Open(srcPath)
Expand Down Expand Up @@ -539,3 +553,12 @@ func copyFilesInDir(src, dest string) error {
}
return nil
}

func storeTempFile(t *testing.T, content []byte) *os.File {
out, err := ioutil.TempFile(t.TempDir(), "genesis")
require.NoError(t, err)
_, err = io.Copy(out, bytes.NewReader(content))
require.NoError(t, err)
require.NoError(t, out.Close())
return out
}
Loading