Skip to content

Commit

Permalink
Merge branch 'main' into testing/cosmos-db
Browse files Browse the repository at this point in the history
  • Loading branch information
cool-develope committed Sep 3, 2024
2 parents 411f7ac + 8431dbd commit 334739f
Show file tree
Hide file tree
Showing 26 changed files with 1,752 additions and 330 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/sims-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
go-version: "1.23"
check-latest: true
- name: test-sim-multi-seed-long
env:
GOMEMLIMIT: 14GiB # reserve 2 GiB as buffer for GC to avoid OOM
run: |
make test-sim-multi-seed-long
Expand Down
1,326 changes: 1,123 additions & 203 deletions api/cosmos/accounts/defaults/base/v1/base.pulsar.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const (
QueryPathBroadcastTx = "/cosmos.tx.v1beta1.Service/BroadcastTx"
)

// InitChain implements the ABCI interface. It initializes the application's state
// and sets up the initial validator set.
func (app *BaseApp) InitChain(req *abci.InitChainRequest) (*abci.InitChainResponse, error) {
if req.ChainId != app.chainID {
return nil, fmt.Errorf("invalid chain-id on InitChain; expected: %s, got: %s", app.chainID, req.ChainId)
Expand Down Expand Up @@ -135,6 +137,7 @@ func (app *BaseApp) InitChain(req *abci.InitChainRequest) (*abci.InitChainRespon
}, nil
}

// Info implements the ABCI interface. It returns information about the application.
func (app *BaseApp) Info(_ *abci.InfoRequest) (*abci.InfoResponse, error) {
lastCommitID := app.cms.LastCommitID()
appVersion := InitialAppVersion
Expand Down
4 changes: 2 additions & 2 deletions baseapp/abci_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

type (
// ValidatorStore defines the interface contract require for verifying vote
// ValidatorStore defines the interface contract required for verifying vote
// extension signatures. Typically, this will be implemented by the x/staking
// module, which has knowledge of the CometBFT public key.
ValidatorStore interface {
Expand Down Expand Up @@ -84,7 +84,7 @@ func ValidateVoteExtensions(
totalVP += vote.Validator.Power

// Only check + include power if the vote is a commit vote. There must be super-majority, otherwise the
// previous block (the block vote is for) could not have been committed.
// previous block (the block the vote is for) could not have been committed.
if vote.BlockIdFlag != cmtproto.BlockIDFlagCommit {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion baseapp/abci_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func (s *ABCIUtilsTestSuite) TestValidateVoteExtensionsIncorrectVotingPower() {
s.Require().Error(baseapp.ValidateVoteExtensions(s.ctx, s.valStore, llc))
}

func (s *ABCIUtilsTestSuite) TestValidateVoteExtensionsIncorrecOrder() {
func (s *ABCIUtilsTestSuite) TestValidateVoteExtensionsIncorrectOrder() {
ext := []byte("vote-extension")
cve := cmtproto.CanonicalVoteExtension{
Extension: ext,
Expand Down
6 changes: 3 additions & 3 deletions baseapp/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"github.com/cometbft/cometbft/abci/types"
)

// ExecuteGenesis implements a genesis TxHandler used to execute a genTxs (from genutil).
func (ba *BaseApp) ExecuteGenesisTx(tx []byte) error {
res := ba.deliverTx(tx)
// ExecuteGenesisTx implements a genesis TxHandler used to execute a genTxs (from genutil).
func (app *BaseApp) ExecuteGenesisTx(tx []byte) error {
res := app.deliverTx(tx)

if res.Code != types.CodeTypeOK {
return errors.New(res.Log)
Expand Down
3 changes: 1 addition & 2 deletions baseapp/internal/protocompat/protocompat.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ func MakeHybridHandler(cdc codec.BinaryCodec, sd *grpc.ServiceDesc, method grpc.
}
if isProtov2Handler {
return makeProtoV2HybridHandler(methodDesc, cdc, method, handler)
} else {
return makeGogoHybridHandler(methodDesc, cdc, method, handler)
}
return makeGogoHybridHandler(methodDesc, cdc, method, handler)
}

// makeProtoV2HybridHandler returns a handler that can handle both gogo and protov2 messages.
Expand Down
1 change: 0 additions & 1 deletion baseapp/msg_service_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func NewMsgServiceRouter() *MsgServiceRouter {
routes: map[string]MsgServiceHandler{},
hybridHandlers: map[string]func(ctx context.Context, req, resp protoiface.MessageV1) error{},
responseByMsgName: map[string]string{},
circuitBreaker: nil,
}
}

Expand Down
3 changes: 2 additions & 1 deletion baseapp/streaming.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
abci "github.com/cometbft/cometbft/api/cometbft/abci/v1"
"github.com/spf13/cast"

"cosmossdk.io/log"
"cosmossdk.io/schema"
"cosmossdk.io/schema/appdata"
"cosmossdk.io/schema/decoding"
Expand Down Expand Up @@ -36,7 +37,7 @@ func (app *BaseApp) EnableIndexer(indexerOpts interface{}, keys map[string]*stor
Config: indexerOpts,
Resolver: decoding.ModuleSetDecoderResolver(appModules),
SyncSource: nil,
Logger: app.logger.With("module", "indexer"),
Logger: app.logger.With(log.ModuleKey, "indexer"),
})
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion baseapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (app *BaseApp) SimDeliver(txEncoder sdk.TxEncoder, tx sdk.Tx) (sdk.GasInfo,
}

// SimWriteState is an entrypoint for simulations only. They are not executed during the normal ABCI finalize
// block step but later. Therefore an extra call to the root multi-store (app.cms) is required to write the changes.
// block step but later. Therefore, an extra call to the root multi-store (app.cms) is required to write the changes.
func (app *BaseApp) SimWriteState() {
app.finalizeBlockState.ms.Write()
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/simulations.mk
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test-sim-custom-genesis-multi-seed:

test-sim-multi-seed-long:
@echo "Running long multi-seed application simulation. This may take awhile!"
@cd ${CURRENT_DIR}/simapp && go test -mod=readonly -timeout=1h -tags='sims' -run TestFullAppSimulation \
@cd ${CURRENT_DIR}/simapp && go test -mod=readonly -timeout=2h -tags='sims' -run TestFullAppSimulation \
-NumBlocks=150 -Period=50

test-sim-multi-seed-short:
Expand Down
2 changes: 1 addition & 1 deletion scripts/protocgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ for dir in $proto_dirs; do

# check if buf.gen.gogo.yaml exists in the proto directory
if [ -f "buf.gen.gogo.yaml" ]; then
for file in $(find . -maxdepth 5 -name '*.proto'); do
for file in $(find . -maxdepth 8 -name '*.proto'); do
# this regex checks if a proto file has its go_package set to cosmossdk.io/api/...
# gogo proto files SHOULD ONLY be generated if this is false
# we don't want gogo proto to run for proto files which are natively built for google.golang.org/protobuf
Expand Down
2 changes: 1 addition & 1 deletion simapp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Always refer to the [UPGRADING.md](https://github.com/cosmos/cosmos-sdk/blob/mai
* [#20771](https://github.com/cosmos/cosmos-sdk/pull/20771) Use client/v2 `GetNodeHomeDirectory` helper in `app.go` and use the `DefaultNodeHome` constant everywhere in the app.
* [#20490](https://github.com/cosmos/cosmos-sdk/pull/20490) Refactor simulations to make use of `testutil/sims` instead of `runsims`.
* [#19726](https://github.com/cosmos/cosmos-sdk/pull/19726) Update APIs to match CometBFT v1.

* [#21466](https://github.com/cosmos/cosmos-sdk/pull/21466) Allow chains to plug in their own public key types in `base.Account`
<!-- TODO: move changelog.md elements to here -->

## v0.47 to v0.50
Expand Down
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func NewSimApp(
accountstd.AddAccount(lockup.DELAYED_LOCKING_ACCOUNT, lockup.NewDelayedLockingAccount),
accountstd.AddAccount(lockup.PERMANENT_LOCKING_ACCOUNT, lockup.NewPermanentLockingAccount),
// PRODUCTION: add
baseaccount.NewAccount("base", txConfig.SignModeHandler()),
baseaccount.NewAccount("base", txConfig.SignModeHandler(), baseaccount.WithSecp256K1PubKey()),
)
if err != nil {
panic(err)
Expand Down
28 changes: 19 additions & 9 deletions store/internal/kv/kv.pb.go

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

2 changes: 1 addition & 1 deletion tests/integration/auth/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func initFixture(t *testing.T) *fixture {
queryRouter := baseapp.NewGRPCQueryRouter()

handler := directHandler{}
account := baseaccount.NewAccount("base", signing.NewHandlerMap(handler))
account := baseaccount.NewAccount("base", signing.NewHandlerMap(handler), baseaccount.WithSecp256K1PubKey())
accountsKeeper, err := accounts.NewKeeper(
cdc,
runtime.NewEnvironment(runtime.NewKVStoreService(keys[accounts.StoreKey]), log.NewNopLogger(), runtime.EnvWithQueryRouterService(queryRouter), runtime.EnvWithMsgRouterService(router)),
Expand Down
12 changes: 8 additions & 4 deletions testutils/sims/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sims
import (
"fmt"
"io"
"os"
"path/filepath"
"testing"

Expand Down Expand Up @@ -51,6 +52,7 @@ type SimulationApp interface {
SetNotSigverifyTx()
GetBaseApp() *baseapp.BaseApp
TxConfig() client.TxConfig
Close() error
}

// Run is a helper function that runs a simulation test with the given parameters.
Expand Down Expand Up @@ -115,7 +117,6 @@ func RunWithSeeds[T SimulationApp](
runLogger = log.NewTestLoggerInfo(t)
}
runLogger = runLogger.With("seed", tCfg.Seed)

app := testInstance.App
stateFactory := setupStateFactory(app)
simParams, err := simulation.SimulateFromSeedX(
Expand All @@ -125,7 +126,7 @@ func RunWithSeeds[T SimulationApp](
app.GetBaseApp(),
stateFactory.AppStateFn,
simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
simtestutil.SimulationOperations(app, stateFactory.Codec, tCfg, testInstance.App.TxConfig()),
simtestutil.SimulationOperations(app, stateFactory.Codec, tCfg, app.TxConfig()),
stateFactory.BlockedAddr,
tCfg,
stateFactory.Codec,
Expand All @@ -135,12 +136,13 @@ func RunWithSeeds[T SimulationApp](
require.NoError(t, err)
err = simtestutil.CheckExportSimulation(app, tCfg, simParams)
require.NoError(t, err)
if tCfg.Commit {
if tCfg.Commit && tCfg.DBBackend == "goleveldb" {
simtestutil.PrintStats(testInstance.DB.(*coretesting.GoLevelDB))
}
for _, step := range postRunActions {
step(t, testInstance)
}
require.NoError(t, app.Close())
})
}
}
Expand Down Expand Up @@ -174,6 +176,8 @@ func NewSimulationAppInstance[T SimulationApp](
) TestInstance[T] {
t.Helper()
workDir := t.TempDir()
require.NoError(t, os.Mkdir(filepath.Join(workDir, "data"), 0o755))

dbDir := filepath.Join(workDir, "leveldb-app-sim")
var logger log.Logger
if cli.FlagVerboseValue {
Expand All @@ -186,7 +190,7 @@ func NewSimulationAppInstance[T SimulationApp](
db, err := dbm.NewDB("Simulation", dbm.BackendType(tCfg.DBBackend), dbDir)
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, db.Close())
_ = db.Close() // ensure db is closed
})
appOptions := make(simtestutil.AppOptionsMap)
appOptions[flags.FlagHome] = workDir
Expand Down
2 changes: 1 addition & 1 deletion types/mempool/priority_nonce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (a signerExtractionAdapter) GetSigners(tx sdk.Tx) ([]mempool.SignerData, er
if err != nil {
return nil, err
}
signerData := make([]mempool.SignerData, len(sigs))
signerData := make([]mempool.SignerData, 0, len(sigs))
for _, sig := range sigs {
signerData = append(signerData, mempool.SignerData{
Signer: sig.PubKey.Address().Bytes(),
Expand Down
16 changes: 14 additions & 2 deletions types/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import (
storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
Expand Down Expand Up @@ -293,7 +295,11 @@ func (m *Manager) SetOrderMigrations(moduleNames ...string) {

// RegisterLegacyAminoCodec registers all module codecs
func (m *Manager) RegisterLegacyAminoCodec(cdc legacy.Amino) {
for _, b := range m.Modules {
for name, b := range m.Modules {
if _, ok := b.(interface{ RegisterLegacyAminoCodec(*codec.LegacyAmino) }); ok {
panic(fmt.Sprintf("%s uses a deprecated amino registration api, implement HasAminoCodec instead if necessary", name))
}

if mod, ok := b.(HasAminoCodec); ok {
mod.RegisterLegacyAminoCodec(cdc)
}
Expand All @@ -302,7 +308,13 @@ func (m *Manager) RegisterLegacyAminoCodec(cdc legacy.Amino) {

// RegisterInterfaces registers all module interface types
func (m *Manager) RegisterInterfaces(registrar registry.InterfaceRegistrar) {
for _, b := range m.Modules {
for name, b := range m.Modules {
if _, ok := b.(interface {
RegisterInterfaces(cdctypes.InterfaceRegistry)
}); ok {
panic(fmt.Sprintf("%s uses a deprecated interface registration api, implement appmodule.HasRegisterInterfaces instead", name))
}

if mod, ok := b.(appmodule.HasRegisterInterfaces); ok {
mod.RegisterInterfaces(registrar)
}
Expand Down
Loading

0 comments on commit 334739f

Please sign in to comment.