From b926886b77f1331bb3fbe2e3ac4abfbdbf44b24d Mon Sep 17 00:00:00 2001 From: nghuyenthevinh2000 Date: Thu, 25 Jan 2024 15:59:44 +0700 Subject: [PATCH 1/2] feat: modifications for terra classic --- server/config/config.go | 8 +++++++- server/config/toml.go | 11 ++++++++++- server/start.go | 5 +++++ store/cache/cache.go | 13 ++++++++++--- store/iavl/store.go | 5 ++++- store/types/store.go | 3 +++ x/staking/keeper/delegation.go | 26 ++++++++++++++++++++++++++ 7 files changed, 65 insertions(+), 6 deletions(-) diff --git a/server/config/config.go b/server/config/config.go index f4ac30a30dd9..714796f5d335 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -7,6 +7,8 @@ import ( "github.com/spf13/viper" clientflags "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/store/cache" + "github.com/cosmos/cosmos-sdk/store/iavl" pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" @@ -80,6 +82,9 @@ type BaseConfig struct { // InterBlockCache enables inter-block caching. InterBlockCache bool `mapstructure:"inter-block-cache"` + // InterBlockCacheSize set the size of the inter-block cache. + InterBlockCacheSize uint `mapstructure:"inter-block-cache-size"` + // IndexEvents defines the set of events in the form {eventType}.{attributeKey}, // which informs Tendermint what to index. If empty, all events will be indexed. IndexEvents []string `mapstructure:"index-events"` @@ -283,12 +288,13 @@ func DefaultConfig() *Config { BaseConfig: BaseConfig{ MinGasPrices: defaultMinGasPrices, InterBlockCache: true, + InterBlockCacheSize: cache.DefaultCommitKVStoreCacheSize, Pruning: pruningtypes.PruningOptionDefault, PruningKeepRecent: "0", PruningInterval: "0", MinRetainBlocks: 0, IndexEvents: make([]string, 0), - IAVLCacheSize: 781250, + IAVLCacheSize: iavl.DefaultIAVLCacheSize, IAVLDisableFastNode: false, IAVLLazyLoading: false, AppDBBackend: "", diff --git a/server/config/toml.go b/server/config/toml.go index 40fa0ed239a8..ffc446077f9f 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -63,6 +63,12 @@ min-retain-blocks = {{ .BaseConfig.MinRetainBlocks }} # InterBlockCache enables inter-block caching. inter-block-cache = {{ .BaseConfig.InterBlockCache }} +# InterBlockCacheSize set the size (the number of cache items) of interblock cache item +# Each item consumes 128 bytes, so the value should be dividend by 128 +# Default cache size is 10mb. +# Ex) 100mb = 10,000,000 / 128 = 78,125 +inter-block-cache-size = {{ .BaseConfig.InterBlockCacheSize }} + # IndexEvents defines the set of events in the form {eventType}.{attributeKey}, # which informs Tendermint what to index. If empty, all events will be indexed. # @@ -70,7 +76,10 @@ inter-block-cache = {{ .BaseConfig.InterBlockCache }} # ["message.sender", "message.recipient"] index-events = [{{ range .BaseConfig.IndexEvents }}{{ printf "%q, " . }}{{end}}] -# IavlCacheSize set the size of the iavl tree cache (in number of nodes). +# IAVLCacheSize set the cache size (the number of cache items) of the iavl tree. +# Each item size consumes 128 bytes, so the value should be dividend by 128 +# Default cache size is 100mb. +# Ex) 100mb = 100,000,000 / 128 = 781,250 iavl-cache-size = {{ .BaseConfig.IAVLCacheSize }} # IAVLDisableFastNode enables or disables the fast node feature of IAVL. diff --git a/server/start.go b/server/start.go index 9827f0a4c293..a1051dae719e 100644 --- a/server/start.go +++ b/server/start.go @@ -31,6 +31,8 @@ import ( serverconfig "github.com/cosmos/cosmos-sdk/server/config" servergrpc "github.com/cosmos/cosmos-sdk/server/grpc" "github.com/cosmos/cosmos-sdk/server/types" + "github.com/cosmos/cosmos-sdk/store/cache" + "github.com/cosmos/cosmos-sdk/store/iavl" pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" @@ -60,6 +62,7 @@ const ( FlagIndexEvents = "index-events" FlagMinRetainBlocks = "min-retain-blocks" FlagIAVLCacheSize = "iavl-cache-size" + FlagInterBlockCacheSize = "inter-block-cache-size" FlagDisableIAVLFastNode = "iavl-disable-fastnode" FlagIAVLLazyLoading = "iavl-lazy-loading" @@ -172,6 +175,8 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. cmd.Flags().Uint64(FlagHaltHeight, 0, "Block height at which to gracefully halt the chain and shutdown the node") cmd.Flags().Uint64(FlagHaltTime, 0, "Minimum block time (in Unix seconds) at which to gracefully halt the chain and shutdown the node") cmd.Flags().Bool(FlagInterBlockCache, true, "Enable inter-block caching") + cmd.Flags().Uint(FlagInterBlockCacheSize, cache.DefaultCommitKVStoreCacheSize, "The size of inter-block caching store") + cmd.Flags().Uint64(FlagIAVLCacheSize, iavl.DefaultIAVLCacheSize, "The size of iavl caching store") cmd.Flags().String(flagCPUProfile, "", "Enable CPU profiling and write to the provided file") cmd.Flags().Bool(FlagTrace, false, "Provide full stack traces for errors in ABCI Log") cmd.Flags().String(FlagPruning, pruningtypes.PruningOptionDefault, "Pruning strategy (default|nothing|everything|custom)") diff --git a/store/cache/cache.go b/store/cache/cache.go index 62bed91d978e..c7dbb89d3ec3 100644 --- a/store/cache/cache.go +++ b/store/cache/cache.go @@ -13,9 +13,11 @@ var ( _ types.CommitKVStore = (*CommitKVStoreCache)(nil) _ types.MultiStorePersistentCache = (*CommitKVStoreCacheManager)(nil) - // DefaultCommitKVStoreCacheSize defines the persistent ARC cache size for a - // CommitKVStoreCache. - DefaultCommitKVStoreCacheSize uint = 1000 + // DefaultCommitKVStoreCacheSize defines the number of persistent ARC cache item for a + // CommitKVStoreCache, which is supposed to be 10MB size. + // Each cache item consumes 128 bytes, 64 bytes for the left sibling, and 64 bytes for the right sibling. + // The number of cache item is calculated as 10 MB = 10,000,000 / 128 = 78_125 + DefaultCommitKVStoreCacheSize uint = 78_125 ) type ( @@ -59,6 +61,11 @@ func NewCommitKVStoreCacheManager(size uint) *CommitKVStoreCacheManager { } } +// SetCacheSize sets the cache size of the CommitKVStore. +func (cmgr *CommitKVStoreCacheManager) SetCacheSize(size uint) { + cmgr.cacheSize = size +} + // GetStoreCache returns a Cache from the CommitStoreCacheManager for a given // StoreKey. If no Cache exists for the StoreKey, then one is created and set. // The returned Cache is meant to be used in a persistent manner. diff --git a/store/iavl/store.go b/store/iavl/store.go index 28e7f68df7d1..a52f1d6c6eb2 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -23,7 +23,10 @@ import ( ) const ( - DefaultIAVLCacheSize = 500000 + // DefaultIAVLCacheSize defines the number of iavl cache item, which is supposed to be 100MB size. + // Each cache item consumes 128 bytes, 64 bytes for the left sibling, and 64 bytes for the right sibling. + // The number of cache item is calculated as 100 MB = 10,000,000 / 128 = 781_250 + DefaultIAVLCacheSize = 781_250 ) var ( diff --git a/store/types/store.go b/store/types/store.go index 992173195661..fb1414aed4a8 100644 --- a/store/types/store.go +++ b/store/types/store.go @@ -458,6 +458,9 @@ type MultiStorePersistentCache interface { // cache. GetStoreCache(key StoreKey, store CommitKVStore) CommitKVStore + // Sets the cache size of the provided CommitKVStore + SetCacheSize(size uint) + // Return the underlying CommitKVStore for a StoreKey. Unwrap(key StoreKey) CommitKVStore diff --git a/x/staking/keeper/delegation.go b/x/staking/keeper/delegation.go index 23cb929099e8..171ffce5b15b 100644 --- a/x/staking/keeper/delegation.go +++ b/x/staking/keeper/delegation.go @@ -11,6 +11,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking/types" ) +const ColumbusChainID = "columbus-5" + // GetDelegation returns a specific delegation. func (k Keeper) GetDelegation(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (delegation types.Delegation, found bool) { store := ctx.KVStore(k.storeKey) @@ -657,6 +659,30 @@ func (k Keeper) Delegate( delegatorAddress := sdk.MustAccAddressFromBech32(delegation.DelegatorAddress) + // If Delegations are allowed again, limit validator power to 20% + if ctx.ChainID() == ColumbusChainID { + // Get the last Total Power of the validator set + lastPower := k.GetLastTotalPower(ctx) + + // Get the power of the current validator power + validatorLastPower := sdk.TokensToConsensusPower(validator.Tokens, k.PowerReduction(ctx)) + + // Get the new power of the validator if delegated the bond amount + validatorNewPower := validatorLastPower + sdk.TokensToConsensusPower(bondAmt, k.PowerReduction(ctx)) + + // Compute what the Total Consensus Power would be if this Delegation goes through + newTotalPower := lastPower.Int64() + sdk.TokensToConsensusPower(bondAmt, k.PowerReduction(ctx)) + + // Compute what the new Validator voting power would be in relation to the new total power + // validatorIncreasedDelegationPercent := float32(validatorNewPower) / float32(newTotalPower) + validatorIncreasedDelegationPercent := sdk.NewDec(validatorNewPower).QuoInt64(newTotalPower) + + // If Delegations are allowed, and the Delegation would have increased the Validator to over 20% of the staking power, do not allow the Delegation to proceed + if validatorIncreasedDelegationPercent.GT(sdk.NewDecWithPrec(20, 2)) { + panic("validator power is over the allowed limit") + } + } + // if subtractAccount is true then we are // performing a delegation and not a redelegation, thus the source tokens are // all non bonded From 1040442714996910822d7e7e7530a18fa09df088 Mon Sep 17 00:00:00 2001 From: Till Ziegler Date: Fri, 8 Mar 2024 16:50:23 +0100 Subject: [PATCH 2/2] fix: apply further terra classic specifics --- baseapp/abci.go | 30 ++++++++++++++++++++++-------- baseapp/baseapp.go | 26 +++++++++++++------------- baseapp/test_helpers.go | 6 +++--- client/pruning/main.go | 19 ++++++++++++++++++- go.mod | 17 ++--------------- go.sum | 4 ++-- server/api/server.go | 30 ++++++++++++++++++++++++++++-- server/start.go | 3 ++- simapp/go.mod | 3 ++- simapp/go.sum | 4 ++-- store/rootmulti/store.go | 4 +++- store/store.go | 4 ++++ 12 files changed, 101 insertions(+), 49 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 08dbe8d367b9..3afa20333d20 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -351,6 +351,19 @@ func (app *BaseApp) ProcessProposal(req abci.RequestProcessProposal) (resp abci. return resp } +func isOracleTx(msgs []sdk.Msg) bool { + for _, msg := range msgs { + if sdk.MsgTypeURL(msg) == "/terra.oracle.v1beta1.MsgAggregateExchangeRatePrevote" || + sdk.MsgTypeURL(msg) == "/terra.oracle.v1beta1.MsgAggregateExchangeRateVote" { + continue + } else { + return false + } + } + + return true +} + // CheckTx implements the ABCI interface and executes a tx in CheckTx mode. In // CheckTx mode, messages are not executed. This means messages are only validated // and only the AnteHandler is executed. State is persisted to the BaseApp's @@ -371,18 +384,19 @@ func (app *BaseApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx { panic(fmt.Sprintf("unknown RequestCheckTx type: %s", req.Type)) } - gInfo, result, anteEvents, priority, err := app.runTx(mode, req.Tx) + gInfo, result, anteEvents, priority, tx, err := app.runTx(mode, req.Tx) if err != nil { return sdkerrors.ResponseCheckTxWithEvents(err, gInfo.GasWanted, gInfo.GasUsed, anteEvents, app.trace) } return abci.ResponseCheckTx{ - GasWanted: int64(gInfo.GasWanted), // TODO: Should type accept unsigned ints? - GasUsed: int64(gInfo.GasUsed), // TODO: Should type accept unsigned ints? - Log: result.Log, - Data: result.Data, - Events: sdk.MarkEventsToIndex(result.Events, app.indexEvents), - Priority: priority, + GasWanted: int64(gInfo.GasWanted), // TODO: Should type accept unsigned ints? + GasUsed: int64(gInfo.GasUsed), // TODO: Should type accept unsigned ints? + Log: result.Log, + Data: result.Data, + Events: sdk.MarkEventsToIndex(result.Events, app.indexEvents), + Priority: priority, + IsOracleTx: isOracleTx(tx.GetMsgs()), } } @@ -410,7 +424,7 @@ func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) (res abci.ResponseDeliv telemetry.SetGauge(float32(gInfo.GasWanted), "tx", "gas", "wanted") }() - gInfo, result, anteEvents, _, err := app.runTx(runTxModeDeliver, req.Tx) + gInfo, result, anteEvents, _, _, err := app.runTx(runTxModeDeliver, req.Tx) if err != nil { resultStr = "failed" return sdkerrors.ResponseDeliverTxWithEvents(err, gInfo.GasWanted, gInfo.GasUsed, sdk.MarkEventsToIndex(anteEvents, app.indexEvents), app.trace) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index c2ce465ca9ca..7dc62450c11f 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -158,7 +158,7 @@ func NewBaseApp( logger: logger, name: name, db: db, - cms: store.NewCommitMultiStore(db), + cms: store.NewCommitMultiStoreWithLogger(db, logger), storeLoader: DefaultStoreLoader, grpcQueryRouter: NewGRPCQueryRouter(), msgServiceRouter: NewMsgServiceRouter(), @@ -626,7 +626,7 @@ func (app *BaseApp) cacheTxContext(ctx sdk.Context, txBytes []byte) (sdk.Context // Note, gas execution info is always returned. A reference to a Result is // returned if the tx does not run out of gas and if all the messages are valid // and execute successfully. An error is returned otherwise. -func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, result *sdk.Result, anteEvents []abci.Event, priority int64, err error) { +func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, result *sdk.Result, anteEvents []abci.Event, priority int64, tx sdk.Tx, err error) { // 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. @@ -637,7 +637,7 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re // only run the tx if there is block gas remaining if mode == runTxModeDeliver && ctx.BlockGasMeter().IsOutOfGas() { - return gInfo, nil, nil, 0, sdkerrors.Wrap(sdkerrors.ErrOutOfGas, "no block gas left to run tx") + return gInfo, nil, nil, 0, nil, sdkerrors.Wrap(sdkerrors.ErrOutOfGas, "no block gas left to run tx") } defer func() { @@ -674,14 +674,14 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re defer consumeBlockGas() } - tx, err := app.txDecoder(txBytes) + tx, err = app.txDecoder(txBytes) if err != nil { - return sdk.GasInfo{}, nil, nil, 0, err + return sdk.GasInfo{}, nil, nil, 0, nil, err } msgs := tx.GetMsgs() if err := validateBasicTxMsgs(msgs); err != nil { - return sdk.GasInfo{}, nil, nil, 0, err + return sdk.GasInfo{}, nil, nil, 0, nil, err } if app.anteHandler != nil { @@ -717,7 +717,7 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re gasWanted = ctx.GasMeter().Limit() if err != nil { - return gInfo, nil, nil, 0, err + return gInfo, nil, nil, 0, nil, err } priority = ctx.Priority() @@ -728,12 +728,12 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re if mode == runTxModeCheck { err = app.mempool.Insert(ctx, tx) if err != nil { - return gInfo, nil, anteEvents, priority, err + return gInfo, nil, anteEvents, priority, nil, err } } else if mode == runTxModeDeliver { err = app.mempool.Remove(tx) if err != nil && !errors.Is(err, mempool.ErrTxNotFound) { - return gInfo, nil, anteEvents, priority, + return gInfo, nil, anteEvents, priority, nil, fmt.Errorf("failed to remove tx from mempool: %w", err) } } @@ -759,7 +759,7 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re newCtx, err := app.postHandler(postCtx, tx, mode == runTxModeSimulate, err == nil) if err != nil { - return gInfo, nil, anteEvents, priority, err + return gInfo, nil, anteEvents, priority, nil, err } result.Events = append(result.Events, newCtx.EventManager().ABCIEvents()...) @@ -778,7 +778,7 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re } } - return gInfo, result, anteEvents, priority, err + return gInfo, result, anteEvents, priority, tx, err } // runMsgs iterates through a list of messages and executes them with the provided @@ -884,7 +884,7 @@ func (app *BaseApp) PrepareProposalVerifyTx(tx sdk.Tx) ([]byte, error) { return nil, err } - _, _, _, _, err = app.runTx(runTxPrepareProposal, bz) //nolint:dogsled + _, _, _, _, _, err = app.runTx(runTxPrepareProposal, bz) //nolint:dogsled if err != nil { return nil, err } @@ -903,7 +903,7 @@ func (app *BaseApp) ProcessProposalVerifyTx(txBz []byte) (sdk.Tx, error) { return nil, err } - _, _, _, _, err = app.runTx(runTxProcessProposal, txBz) //nolint:dogsled + _, _, _, _, _, err = app.runTx(runTxProcessProposal, txBz) //nolint:dogsled if err != nil { return nil, err } diff --git a/baseapp/test_helpers.go b/baseapp/test_helpers.go index a8ecee084d5c..a4ef492587c6 100644 --- a/baseapp/test_helpers.go +++ b/baseapp/test_helpers.go @@ -16,13 +16,13 @@ func (app *BaseApp) SimCheck(txEncoder sdk.TxEncoder, tx sdk.Tx) (sdk.GasInfo, * if err != nil { return sdk.GasInfo{}, nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "%s", err) } - gasInfo, result, _, _, err := app.runTx(runTxModeCheck, bz) + gasInfo, result, _, _, _, err := app.runTx(runTxModeCheck, bz) return gasInfo, result, err } // Simulate executes a tx in simulate mode to get result and gas info. func (app *BaseApp) Simulate(txBytes []byte) (sdk.GasInfo, *sdk.Result, error) { - gasInfo, result, _, _, err := app.runTx(runTxModeSimulate, txBytes) + gasInfo, result, _, _, _, err := app.runTx(runTxModeSimulate, txBytes) return gasInfo, result, err } @@ -32,7 +32,7 @@ func (app *BaseApp) SimDeliver(txEncoder sdk.TxEncoder, tx sdk.Tx) (sdk.GasInfo, if err != nil { return sdk.GasInfo{}, nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "%s", err) } - gasInfo, result, _, _, err := app.runTx(runTxModeDeliver, bz) + gasInfo, result, _, _, _, err := app.runTx(runTxModeDeliver, bz) return gasInfo, result, err } diff --git a/client/pruning/main.go b/client/pruning/main.go index 247cd2c360c9..7d5d4d094a30 100644 --- a/client/pruning/main.go +++ b/client/pruning/main.go @@ -4,11 +4,14 @@ import ( "fmt" "os" "path/filepath" + "strconv" "github.com/spf13/cobra" "github.com/spf13/viper" dbm "github.com/cometbft/cometbft-db" + cfg "github.com/cometbft/cometbft/config" + bftflags "github.com/cometbft/cometbft/libs/cli/flags" "github.com/cometbft/cometbft/libs/log" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" @@ -81,6 +84,11 @@ Supported app-db-backend types include 'goleveldb', 'rocksdb', 'pebbledb'.`, } logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) + logger, err = bftflags.ParseLogLevel(vp.GetString(flags.FlagLogLevel), logger, cfg.DefaultLogLevel) + if err != nil { + return err + } + app := appCreator(logger, db, nil, vp) cms := app.CommitMultiStore() @@ -94,8 +102,16 @@ Supported app-db-backend types include 'goleveldb', 'rocksdb', 'pebbledb'.`, return fmt.Errorf("the database has no valid heights to prune, the latest height: %v", latestHeight) } + startHeight := 1 + + if str := vp.GetString(flags.FlagHeight); str != "" { + if startHeight, err = strconv.Atoi(str); err != nil { + return fmt.Errorf("invalid height flag %v", str) + } + } + var pruningHeights []int64 - for height := int64(1); height < latestHeight; height++ { + for height := int64(startHeight); height < latestHeight; height++ { if height < latestHeight-int64(pruningOptions.KeepRecent) { pruningHeights = append(pruningHeights, height) } @@ -111,6 +127,7 @@ Supported app-db-backend types include 'goleveldb', 'rocksdb', 'pebbledb'.`, } cmd.Println("successfully pruned the application root multi stores") + cmd.Flags().Uint64(server.FlagHeight, 1, `the height to begin with`) return nil }, } diff --git a/go.mod b/go.mod index b68b95763b57..2469f7467bf4 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -go 1.19 +go 1.20 module github.com/cosmos/cosmos-sdk @@ -186,6 +186,7 @@ require ( replace ( // use cosmos fork of keyring github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 + github.com/cometbft/cometbft => github.com/classic-terra/cometbft v0.37.3-0.20240308104225-9f5ce8b85c1b // dgrijalva/jwt-go is deprecated and doesn't receive security updates. // TODO: remove it: https://github.com/cosmos/cosmos-sdk/issues/13134 github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2 @@ -199,17 +200,3 @@ replace ( // stick with compatible version of rapid in v0.47.x line pgregory.net/rapid => pgregory.net/rapid v0.5.5 ) - -retract ( - // revert fix https://github.com/cosmos/cosmos-sdk/pull/16331 - v0.46.12 - // subject to a bug in the group module and gov module migration - [v0.46.5, v0.46.6] - // subject to the dragonberry vulnerability - // and/or the bank coin metadata migration issue - [v0.46.0, v0.46.4] - // subject to the dragonberry vulnerability - [v0.45.0, v0.45.8] - // do not use - v0.43.0 -) diff --git a/go.sum b/go.sum index 177270521bd8..b46ee4d303b4 100644 --- a/go.sum +++ b/go.sum @@ -287,6 +287,8 @@ github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04= github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8= github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag= github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I= +github.com/classic-terra/cometbft v0.37.3-0.20240308104225-9f5ce8b85c1b h1:x0holP0dCb0W6GnUzVAsAaHPp6pirupf0Po/f7uJ0QE= +github.com/classic-terra/cometbft v0.37.3-0.20240308104225-9f5ce8b85c1b/go.mod h1:Cmg5Hp4sNpapm7j+x0xRyt2g0juQfmB752ous+pA0G8= github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= @@ -310,8 +312,6 @@ github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZ github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= github.com/coinbase/rosetta-sdk-go/types v1.0.0 h1:jpVIwLcPoOeCR6o1tU+Xv7r5bMONNbHU7MuEHboiFuA= github.com/coinbase/rosetta-sdk-go/types v1.0.0/go.mod h1:eq7W2TMRH22GTW0N0beDnN931DW0/WOI1R2sdHNHG4c= -github.com/cometbft/cometbft v0.37.4 h1:xyvvEqlyfK8MgNIIKVJaMsuIp03wxOcFmVkT26+Ikpg= -github.com/cometbft/cometbft v0.37.4/go.mod h1:Cmg5Hp4sNpapm7j+x0xRyt2g0juQfmB752ous+pA0G8= github.com/cometbft/cometbft-db v0.7.0 h1:uBjbrBx4QzU0zOEnU8KxoDl18dMNgDh+zZRUE0ucsbo= github.com/cometbft/cometbft-db v0.7.0/go.mod h1:yiKJIm2WKrt6x8Cyxtq9YTEcIMPcEe4XPxhgX59Fzf0= github.com/confio/ics23/go v0.9.0 h1:cWs+wdbS2KRPZezoaaj+qBleXgUk5WOQFMP3CQFGTr4= diff --git a/server/api/server.go b/server/api/server.go index 917554857b31..befa327de648 100644 --- a/server/api/server.go +++ b/server/api/server.go @@ -4,6 +4,7 @@ import ( "fmt" "net" "net/http" + "strconv" "strings" "sync" "time" @@ -81,6 +82,31 @@ func New(clientCtx client.Context, logger log.Logger) *Server { } } +// blockHeightMiddleware parses height query parameter and sets GRPCBlockHeightHeader +func blockHeightMiddleware(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + heightStr := r.FormValue("height") + if heightStr != "" { + height, err := strconv.ParseInt(heightStr, 10, 64) + if err != nil { + writeErrorResponse(w, http.StatusBadRequest, "syntax error") + return + } + + if height < 0 { + writeErrorResponse(w, http.StatusBadRequest, "height must be equal or greater than zero") + return + } + + if height > 0 { + r.Header.Set(grpctypes.GRPCBlockHeightHeader, heightStr) + } + } + + next.ServeHTTP(w, r) + }) +} + // Start starts the API server. Internally, the API server leverages Tendermint's // JSON RPC server. Configuration options are provided via config.APIConfig // and are delegated to the Tendermint JSON RPC server. The process is @@ -102,7 +128,7 @@ func (s *Server) Start(cfg config.Config) error { s.registerGRPCGatewayRoutes() s.listener = listener - var h http.Handler = s.Router + var h http.Handler = blockHeightMiddleware(s.Router) s.mtx.Unlock() @@ -112,7 +138,7 @@ func (s *Server) Start(cfg config.Config) error { } s.logger.Info("starting API server...") - return tmrpcserver.Serve(s.listener, s.Router, s.logger, tmCfg) + return tmrpcserver.Serve(s.listener, h, s.logger, tmCfg) } // Close closes the API server. diff --git a/server/start.go b/server/start.go index a1051dae719e..107396287fc6 100644 --- a/server/start.go +++ b/server/start.go @@ -204,7 +204,8 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. cmd.Flags().Uint64(FlagStateSyncSnapshotInterval, 0, "State sync snapshot interval") cmd.Flags().Uint32(FlagStateSyncSnapshotKeepRecent, 2, "State sync snapshot to keep") - cmd.Flags().Bool(FlagDisableIAVLFastNode, false, "Disable fast node for IAVL tree") + // TODO: Should we disable by default? + cmd.Flags().Bool(FlagDisableIAVLFastNode, true, "Disable fast node for IAVL tree") cmd.Flags().Int(FlagMempoolMaxTxs, mempool.DefaultMaxTx, "Sets MaxTx value for the app-side mempool") diff --git a/simapp/go.mod b/simapp/go.mod index abd5cef6a776..3141a00119a8 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -1,6 +1,6 @@ module cosmossdk.io/simapp -go 1.19 +go 1.20 require ( cosmossdk.io/api v0.3.1 @@ -180,6 +180,7 @@ require ( replace ( // use cosmos fork of keyring github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 + github.com/cometbft/cometbft => github.com/classic-terra/cometbft v0.37.3-0.20240308104225-9f5ce8b85c1b // Simapp always use the latest version of the cosmos-sdk github.com/cosmos/cosmos-sdk => ../. // Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities. diff --git a/simapp/go.sum b/simapp/go.sum index 14693c0f9177..cf827fd7ae9b 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -286,6 +286,8 @@ github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04= github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8= github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag= github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I= +github.com/classic-terra/cometbft v0.37.3-0.20240308104225-9f5ce8b85c1b h1:x0holP0dCb0W6GnUzVAsAaHPp6pirupf0Po/f7uJ0QE= +github.com/classic-terra/cometbft v0.37.3-0.20240308104225-9f5ce8b85c1b/go.mod h1:Cmg5Hp4sNpapm7j+x0xRyt2g0juQfmB752ous+pA0G8= github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= @@ -309,8 +311,6 @@ github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZ github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= github.com/coinbase/rosetta-sdk-go/types v1.0.0 h1:jpVIwLcPoOeCR6o1tU+Xv7r5bMONNbHU7MuEHboiFuA= github.com/coinbase/rosetta-sdk-go/types v1.0.0/go.mod h1:eq7W2TMRH22GTW0N0beDnN931DW0/WOI1R2sdHNHG4c= -github.com/cometbft/cometbft v0.37.4 h1:xyvvEqlyfK8MgNIIKVJaMsuIp03wxOcFmVkT26+Ikpg= -github.com/cometbft/cometbft v0.37.4/go.mod h1:Cmg5Hp4sNpapm7j+x0xRyt2g0juQfmB752ous+pA0G8= github.com/cometbft/cometbft-db v0.8.0 h1:vUMDaH3ApkX8m0KZvOFFy9b5DZHBAjsnEuo9AKVZpjo= github.com/cometbft/cometbft-db v0.8.0/go.mod h1:6ASCP4pfhmrCBpfk01/9E1SI29nD3HfVHrY4PG8x5c0= github.com/confio/ics23/go v0.9.0 h1:cWs+wdbS2KRPZezoaaj+qBleXgUk5WOQFMP3CQFGTr4= diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index bebd6cd1af9a..83514c86e561 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -36,7 +36,8 @@ const ( commitInfoKeyFmt = "s/%d" // s/ ) -const iavlDisablefastNodeDefault = false +// TODO: really true? +const iavlDisablefastNodeDefault = true // keysForStoreKeyMap returns a slice of keys for the provided map lexically sorted by StoreKey.Name() func keysForStoreKeyMap[V any](m map[types.StoreKey]V) []types.StoreKey { @@ -636,6 +637,7 @@ func (rs *Store) PruneStores(clearPruningManager bool, pruningHeights []int64) ( continue } + rs.logger.Debug("pruning store", "store", key) store = rs.GetCommitKVStore(key) err := store.(*iavl.Store).DeleteVersions(pruningHeights...) diff --git a/store/store.go b/store/store.go index d70ad54ee4d6..0b090ae3add6 100644 --- a/store/store.go +++ b/store/store.go @@ -13,6 +13,10 @@ func NewCommitMultiStore(db dbm.DB) types.CommitMultiStore { return rootmulti.NewStore(db, log.NewNopLogger()) } +func NewCommitMultiStoreWithLogger(db dbm.DB, logger log.Logger) types.CommitMultiStore { + return rootmulti.NewStore(db, logger) +} + func NewCommitKVStoreCacheManager() types.MultiStorePersistentCache { return cache.NewCommitKVStoreCacheManager(cache.DefaultCommitKVStoreCacheSize) }