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: consensus module #12905

Merged
merged 75 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
2528498
add consensus-param module
tac0turtle Aug 8, 2022
75fd065
remove exrtas
tac0turtle Aug 9, 2022
f88a482
comment out tests
tac0turtle Aug 11, 2022
99a1476
setup legacy app
tac0turtle Aug 11, 2022
bd70956
feat: minor improvements to pr (#13031)
JeancarloBarrios Aug 29, 2022
f6cac85
add migrations
JeancarloBarrios Aug 30, 2022
94390b3
empty struct
JeancarloBarrios Aug 31, 2022
fffd4db
commented depinject code
JeancarloBarrios Sep 2, 2022
6f55f8b
change proto to not recieve version and finish migration and migratio…
JeancarloBarrios Sep 3, 2022
97d19f1
add keeper base test
JeancarloBarrios Sep 3, 2022
dada35d
add keeper and update msg test
JeancarloBarrios Sep 4, 2022
fdc9922
add query test
JeancarloBarrios Sep 4, 2022
e58a116
Merge branch 'main' into marko/consensus_param
tac0turtle Sep 5, 2022
95a89e5
Merge branch 'main' into marko/consensus_param
tac0turtle Sep 5, 2022
269f664
lint
tac0turtle Sep 5, 2022
8f2a66a
set param store
tac0turtle Sep 5, 2022
67e9291
Merge branch 'main' into marko/consensus_param
tac0turtle Sep 6, 2022
09e0ab8
fix issues
tac0turtle Sep 6, 2022
09a72c6
fix somethings and get blocked by depinject
tac0turtle Sep 6, 2022
163c7f5
rename module to consensus
tac0turtle Sep 6, 2022
76d7f87
rename module to consensus++
tac0turtle Sep 6, 2022
7969d86
fix imports
tac0turtle Sep 6, 2022
26ee3f8
re-generate protos and update `app.go`
julienrbrt Sep 6, 2022
ccc6cfc
`make lint-fix`
julienrbrt Sep 6, 2022
6ff7c3f
wire x/consensus
julienrbrt Sep 6, 2022
5251ed4
wire consesnsus param
tac0turtle Sep 6, 2022
a51e73c
wire in baseapp
tac0turtle Sep 6, 2022
65b27ec
minor fix
tac0turtle Sep 6, 2022
5870cd7
remove unnecessary uses of reflection in NewAnteHandler
aaronc Sep 6, 2022
ab5b29d
setup tests
tac0turtle Sep 6, 2022
a9e3e2b
fix tests
tac0turtle Sep 6, 2022
9cf54fd
Merge branch 'main' into marko/consensus_param
tac0turtle Sep 6, 2022
3a109bb
fix tests++
tac0turtle Sep 6, 2022
00b2f91
tests+++
tac0turtle Sep 6, 2022
3e0611d
tests+++
tac0turtle Sep 6, 2022
3ee0252
fix migration tests
tac0turtle Sep 6, 2022
547b328
lint++
tac0turtle Sep 6, 2022
5d50a04
Merge branch 'main' into marko/consensus_param
tac0turtle Sep 8, 2022
8817805
fix simapp
tac0turtle Sep 8, 2022
c17cdf6
fix simapp
tac0turtle Sep 8, 2022
2269345
Merge branch 'main' into marko/consensus_param
tac0turtle Sep 12, 2022
a3754b7
fix
tac0turtle Sep 12, 2022
27b3988
Merge branch 'main' into marko/consensus_param
tac0turtle Sep 20, 2022
0c5212b
Merge branch 'main' into marko/consensus_param
tac0turtle Sep 20, 2022
9700322
Merge branch 'main' into marko/consensus_param
tac0turtle Sep 23, 2022
6ef2f75
fix some tests
tac0turtle Sep 23, 2022
e65c714
remove staking and return error
tac0turtle Sep 23, 2022
5a5088e
revert order change
tac0turtle Sep 23, 2022
d378fb0
Update baseapp/baseapp.go
tac0turtle Sep 23, 2022
1d3ccca
Merge branch 'main' into marko/consensus_param
tac0turtle Oct 2, 2022
394ff49
lint
alexanderbez Oct 4, 2022
027eccb
Merge branch 'main' into marko/consensus_param
alexanderbez Oct 4, 2022
abd7a03
lint
alexanderbez Oct 4, 2022
182c56c
Merge branch 'marko/consensus_param' of github.com:cosmos/cosmos-sdk …
alexanderbez Oct 4, 2022
571163f
updates
alexanderbez Oct 4, 2022
664c917
updates
alexanderbez Oct 4, 2022
4fc6898
updates
alexanderbez Oct 4, 2022
dc46fbe
updates
alexanderbez Oct 4, 2022
c56e743
updates
alexanderbez Oct 4, 2022
6dba3fa
updates
alexanderbez Oct 4, 2022
8465b82
updates
alexanderbez Oct 4, 2022
32c9cc1
updates
alexanderbez Oct 4, 2022
9303a65
updates
alexanderbez Oct 4, 2022
6f0d36c
updates
alexanderbez Oct 4, 2022
9a84137
updates
alexanderbez Oct 4, 2022
1fd6d1d
updates
alexanderbez Oct 4, 2022
eb982d6
updates
alexanderbez Oct 4, 2022
49abe6d
updates
alexanderbez Oct 4, 2022
c3ff0bd
fix make rosetta-data + run
facundomedica Oct 4, 2022
1bec6a0
Merge branch 'marko/consensus_param' of https://github.com/cosmos/cos…
facundomedica Oct 4, 2022
0afe8fc
Merge branch 'main' into marko/consensus_param
alexanderbez Oct 5, 2022
cbd7078
Merge branch 'main' into marko/consensus_param
tac0turtle Oct 5, 2022
f236fc2
add upgrade and changelog entry
tac0turtle Oct 5, 2022
ecf490f
updates
alexanderbez Oct 5, 2022
a339f8f
updates
alexanderbez Oct 5, 2022
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
25 changes: 16 additions & 9 deletions baseapp/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package baseapp

import (
"encoding/json"
"errors"
"os"
"testing"

Expand Down Expand Up @@ -177,35 +178,41 @@ type paramStore struct {
db *dbm.MemDB
}

func (ps *paramStore) Set(_ sdk.Context, key []byte, value interface{}) {
var ParamstoreKey = []byte("paramstore")

func (ps *paramStore) Set(_ sdk.Context, value *tmproto.ConsensusParams) {
bz, err := json.Marshal(value)
if err != nil {
panic(err)
}

ps.db.Set(key, bz)
ps.db.Set(ParamstoreKey, bz)
}

func (ps *paramStore) Has(_ sdk.Context, key []byte) bool {
ok, err := ps.db.Has(key)
func (ps *paramStore) Has(_ sdk.Context) bool {
ok, err := ps.db.Has(ParamstoreKey)
if err != nil {
panic(err)
}

return ok
}

func (ps *paramStore) Get(_ sdk.Context, key []byte, ptr interface{}) {
bz, err := ps.db.Get(key)
func (ps paramStore) Get(_ sdk.Context) (*tmproto.ConsensusParams, error) {
bz, err := ps.db.Get(ParamstoreKey)
if err != nil {
panic(err)
return nil, err
}

if len(bz) == 0 {
return
return nil, errors.New("no consensus params")
}

if err := json.Unmarshal(bz, ptr); err != nil {
var params tmproto.ConsensusParams

if err := json.Unmarshal(bz, &params); err != nil {
panic(err)
}

return &params, nil
}
45 changes: 12 additions & 33 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import (
"sort"
"strings"

"github.com/cosmos/gogoproto/proto"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/tmhash"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"
"golang.org/x/exp/maps"

"github.com/cosmos/gogoproto/proto"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/snapshots"
"github.com/cosmos/cosmos-sdk/store"
Expand Down Expand Up @@ -407,39 +406,14 @@ func (app *BaseApp) GetConsensusParams(ctx sdk.Context) *tmproto.ConsensusParams
return nil
}

cp := new(tmproto.ConsensusParams)

if app.paramStore.Has(ctx, ParamStoreKeyBlockParams) {
var bp tmproto.BlockParams

app.paramStore.Get(ctx, ParamStoreKeyBlockParams, &bp)
cp.Block = &bp
}

if app.paramStore.Has(ctx, ParamStoreKeyEvidenceParams) {
var ep tmproto.EvidenceParams

app.paramStore.Get(ctx, ParamStoreKeyEvidenceParams, &ep)
cp.Evidence = &ep
}

if app.paramStore.Has(ctx, ParamStoreKeyValidatorParams) {
var vp tmproto.ValidatorParams

app.paramStore.Get(ctx, ParamStoreKeyValidatorParams, &vp)
cp.Validator = &vp
cp, err := app.paramStore.Get(ctx)
if err != nil {
panic(err)
}

return cp
}

// AddRunTxRecoveryHandler adds custom app.runTx method panic handlers.
func (app *BaseApp) AddRunTxRecoveryHandler(handlers ...RecoveryHandler) {
for _, h := range handlers {
app.runTxRecoveryMiddleware = newRecoveryMiddleware(h, app.runTxRecoveryMiddleware)
}
}

// StoreConsensusParams sets the consensus parameters to the baseapp's param store.
func (app *BaseApp) StoreConsensusParams(ctx sdk.Context, cp *tmproto.ConsensusParams) {
if app.paramStore == nil {
Expand All @@ -450,13 +424,18 @@ func (app *BaseApp) StoreConsensusParams(ctx sdk.Context, cp *tmproto.ConsensusP
return
}

app.paramStore.Set(ctx, ParamStoreKeyBlockParams, cp.Block)
app.paramStore.Set(ctx, ParamStoreKeyEvidenceParams, cp.Evidence)
app.paramStore.Set(ctx, ParamStoreKeyValidatorParams, cp.Validator)
app.paramStore.Set(ctx, cp)
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
// We're explicitly not storing the Tendermint app_version in the param store. It's
// stored instead in the x/upgrade store, with its own bump logic.
}

// AddRunTxRecoveryHandler adds custom app.runTx method panic handlers.
func (app *BaseApp) AddRunTxRecoveryHandler(handlers ...RecoveryHandler) {
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
for _, h := range handlers {
app.runTxRecoveryMiddleware = newRecoveryMiddleware(h, app.runTxRecoveryMiddleware)
}
}

// getMaximumBlockGas gets the maximum gas from the consensus params. It panics
// if maximum block gas is less than negative one and returns zero if negative
// one.
Expand Down
6 changes: 0 additions & 6 deletions baseapp/block_gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ import (
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
)

var blockMaxGas = uint64(simtestutil.DefaultConsensusParams.Block.MaxGas)
Expand Down Expand Up @@ -73,8 +71,6 @@ func TestBaseApp_BlockGas(t *testing.T) {
var (
bankKeeper bankkeeper.Keeper
accountKeeper authkeeper.AccountKeeper
paramsKeeper paramskeeper.Keeper
stakingKeeper *stakingkeeper.Keeper
appBuilder *runtime.AppBuilder
txConfig client.TxConfig
cdc codec.Codec
Expand All @@ -88,8 +84,6 @@ func TestBaseApp_BlockGas(t *testing.T) {
err = depinject.Inject(appConfig,
&bankKeeper,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please perhaps provide a comment as to why the ordering of this modules changes, is it just alphabetic ordering?

&accountKeeper,
&paramsKeeper,
&stakingKeeper,
&interfaceRegistry,
&txConfig,
&cdc,
Expand Down
23 changes: 15 additions & 8 deletions baseapp/deliver_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/binary"
"encoding/json"
"errors"
"fmt"
"math/rand"
"net/url"
Expand Down Expand Up @@ -2152,35 +2153,41 @@ type paramStore struct {
db *dbm.MemDB
}

func (ps *paramStore) Set(_ sdk.Context, key []byte, value interface{}) {
var ParamstoreKey = []byte("paramstore")

func (ps *paramStore) Set(_ sdk.Context, value *tmproto.ConsensusParams) {
bz, err := json.Marshal(value)
if err != nil {
panic(err)
}

ps.db.Set(key, bz)
ps.db.Set(ParamstoreKey, bz)
}

func (ps *paramStore) Has(_ sdk.Context, key []byte) bool {
ok, err := ps.db.Has(key)
func (ps *paramStore) Has(_ sdk.Context) bool {
ok, err := ps.db.Has(ParamstoreKey)
if err != nil {
panic(err)
}

return ok
}

func (ps *paramStore) Get(_ sdk.Context, key []byte, ptr interface{}) {
bz, err := ps.db.Get(key)
func (ps paramStore) Get(ctx sdk.Context) (*tmproto.ConsensusParams, error) {
bz, err := ps.db.Get(ParamstoreKey)
if err != nil {
panic(err)
}

if len(bz) == 0 {
return
return nil, errors.New("params not found")
}

if err := json.Unmarshal(bz, ptr); err != nil {
var params tmproto.ConsensusParams

if err := json.Unmarshal(bz, &params); err != nil {
panic(err)
}

return &params, nil
}
5 changes: 1 addition & 4 deletions baseapp/grpcrouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,5 @@ func (qrt *GRPCQueryRouter) SetInterfaceRegistry(interfaceRegistry codectypes.In
qrt.cdc = codec.NewProtoCodec(interfaceRegistry).GRPCCodec()
// Once we have an interface registry, we can register the interface
// registry reflection gRPC service.
reflection.RegisterReflectionServiceServer(
qrt,
reflection.NewReflectionServiceServer(interfaceRegistry),
)
reflection.RegisterReflectionServiceServer(qrt, reflection.NewReflectionServiceServer(interfaceRegistry))
}
76 changes: 3 additions & 73 deletions baseapp/params.go
Original file line number Diff line number Diff line change
@@ -1,85 +1,15 @@
package baseapp

import (
"errors"
"fmt"

tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

sdk "github.com/cosmos/cosmos-sdk/types"
)

// Paramspace defines the parameter subspace to be used for the paramstore.
const Paramspace = "baseapp"

// Parameter store keys for all the consensus parameter types.
var (
ParamStoreKeyBlockParams = []byte("BlockParams")
ParamStoreKeyEvidenceParams = []byte("EvidenceParams")
ParamStoreKeyValidatorParams = []byte("ValidatorParams")
)

// ParamStore defines the interface the parameter store used by the BaseApp must
// fulfill.
type ParamStore interface {
Get(ctx sdk.Context, key []byte, ptr interface{})
Has(ctx sdk.Context, key []byte) bool
Set(ctx sdk.Context, key []byte, param interface{})
}

// ValidateBlockParams defines a stateless validation on BlockParams. This function
// is called whenever the parameters are updated or stored.
func ValidateBlockParams(i interface{}) error {
v, ok := i.(tmproto.BlockParams)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v.MaxBytes <= 0 {
return fmt.Errorf("block maximum bytes must be positive: %d", v.MaxBytes)
}

if v.MaxGas < -1 {
return fmt.Errorf("block maximum gas must be greater than or equal to -1: %d", v.MaxGas)
}

return nil
}

// ValidateEvidenceParams defines a stateless validation on EvidenceParams. This
// function is called whenever the parameters are updated or stored.
func ValidateEvidenceParams(i interface{}) error {
v, ok := i.(tmproto.EvidenceParams)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v.MaxAgeNumBlocks <= 0 {
return fmt.Errorf("evidence maximum age in blocks must be positive: %d", v.MaxAgeNumBlocks)
}

if v.MaxAgeDuration <= 0 {
return fmt.Errorf("evidence maximum age time duration must be positive: %v", v.MaxAgeDuration)
}

if v.MaxBytes < 0 {
return fmt.Errorf("maximum evidence bytes must be non-negative: %v", v.MaxBytes)
}

return nil
}

// ValidateValidatorParams defines a stateless validation on ValidatorParams. This
// function is called whenever the parameters are updated or stored.
func ValidateValidatorParams(i interface{}) error {
v, ok := i.(tmproto.ValidatorParams)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

if len(v.PubKeyTypes) == 0 {
return errors.New("validator allowed pubkey types must not be empty")
}

return nil
Get(ctx sdk.Context) (*tmproto.ConsensusParams, error)
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
Has(ctx sdk.Context) bool
Set(ctx sdk.Context, cp *tmproto.ConsensusParams)
}
65 changes: 0 additions & 65 deletions baseapp/params_test.go

This file was deleted.

Loading