Skip to content

Commit

Permalink
Merge branch 'main' into store/pruning_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
cool-develope authored May 28, 2024
2 parents 364942c + dac569c commit 8bf3749
Show file tree
Hide file tree
Showing 68 changed files with 380 additions and 225 deletions.
4 changes: 2 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ please add links to any relevant follow up issues.*
I have...

* [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title, you can find examples of the prefixes below:
* `feat`: A new feature
<!-- * `feat`: A new feature
* `fix`: A bug fix
* `docs`: Documentation only changes
* `style`: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
Expand All @@ -25,7 +25,7 @@ I have...
* `build`: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
* `ci`: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
* `chore`: Other changes that don't modify src or test files
* `revert`: Reverts a previous commit
* `revert`: Reverts a previous commit -->
* [ ] confirmed `!` in the type prefix if API or client breaking change
* [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
* [ ] provided a link to the relevant issue or specification
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i

### API Breaking Changes

* (server) [#20422](https://github.com/cosmos/cosmos-sdk/pull/20422) Deprecated `ServerContext`. To get `cmtcfg.Config` from cmd, use `client.GetCometConfigFromCmd(cmd)` instead of `server.GetServerContextFromCmd(cmd).Config`
* (types)[#20369](https://github.com/cosmos/cosmos-sdk/pull/20369) The signature of `HasAminoCodec` has changed to accept a `core/legacy.Amino` interface instead of `codec.LegacyAmino`.
* (x/simulation)[#20056](https://github.com/cosmos/cosmos-sdk/pull/20056) `SimulateFromSeed` now takes an address codec as argument.
* (x/crisis) [#20043](https://github.com/cosmos/cosmos-sdk/pull/20043) Changed `NewMsgVerifyInvariant` to accept a string as argument instead of an `AccAddress`.
Expand Down
41 changes: 41 additions & 0 deletions client/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ import (
"slices"
"strings"

cmtcfg "github.com/cometbft/cometbft/config"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"

signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1"
corectx "cosmossdk.io/core/context"
"cosmossdk.io/log"

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
Expand Down Expand Up @@ -373,3 +377,40 @@ func SetCmdClientContext(cmd *cobra.Command, clientCtx Context) error {

return nil
}

func GetViperFromCmd(cmd *cobra.Command) *viper.Viper {
value := cmd.Context().Value(corectx.ViperContextKey{})
v, ok := value.(*viper.Viper)
if !ok {
return viper.New()
}
return v
}

func GetConfigFromCmd(cmd *cobra.Command) *cmtcfg.Config {
v := cmd.Context().Value(corectx.ViperContextKey{})
viper, ok := v.(*viper.Viper)
if !ok {
return cmtcfg.DefaultConfig()
}
return GetConfigFromViper(viper)
}

func GetLoggerFromCmd(cmd *cobra.Command) log.Logger {
v := cmd.Context().Value(corectx.LoggerContextKey{})
logger, ok := v.(log.Logger)
if !ok {
return log.NewLogger(cmd.OutOrStdout())
}
return logger
}

func GetConfigFromViper(v *viper.Viper) *cmtcfg.Config {
conf := cmtcfg.DefaultConfig()
err := v.Unmarshal(conf)
rootDir := v.GetString(flags.FlagHome)
if err != nil {
return cmtcfg.DefaultConfig().SetRoot(rootDir)
}
return conf.SetRoot(rootDir)
}
5 changes: 3 additions & 2 deletions client/snapshot/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/server"
)

Expand All @@ -14,7 +15,7 @@ func DeleteSnapshotCmd() *cobra.Command {
Short: "Delete a local snapshot",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := server.GetServerContextFromCmd(cmd)
viper := client.GetViperFromCmd(cmd)

height, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
Expand All @@ -25,7 +26,7 @@ func DeleteSnapshotCmd() *cobra.Command {
return err
}

snapshotStore, err := server.GetSnapshotStore(ctx.Viper)
snapshotStore, err := server.GetSnapshotStore(viper)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions client/snapshot/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/server"
)

Expand All @@ -21,8 +22,8 @@ func DumpArchiveCmd() *cobra.Command {
Short: "Dump the snapshot as portable archive format",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := server.GetServerContextFromCmd(cmd)
snapshotStore, err := server.GetSnapshotStore(ctx.Viper)
viper := client.GetViperFromCmd(cmd)
snapshotStore, err := server.GetSnapshotStore(viper)
if err != nil {
return err
}
Expand Down
10 changes: 6 additions & 4 deletions client/snapshot/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"cosmossdk.io/log"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/server"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
)
Expand All @@ -16,20 +17,21 @@ func ExportSnapshotCmd[T servertypes.Application](appCreator servertypes.AppCrea
Short: "Export app state to snapshot store",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := server.GetServerContextFromCmd(cmd)
cfg := client.GetConfigFromCmd(cmd)
viper := client.GetViperFromCmd(cmd)

height, err := cmd.Flags().GetInt64("height")
if err != nil {
return err
}

home := ctx.Config.RootDir
db, err := openDB(home, server.GetAppDBBackend(ctx.Viper))
home := cfg.RootDir
db, err := openDB(home, server.GetAppDBBackend(viper))
if err != nil {
return err
}
logger := log.NewLogger(cmd.OutOrStdout())
app := appCreator(logger, db, nil, ctx.Viper)
app := appCreator(logger, db, nil, viper)

if height == 0 {
height = app.CommitMultiStore().LastCommitID().Version
Expand Down
5 changes: 3 additions & 2 deletions client/snapshot/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/server"
)

Expand All @@ -13,8 +14,8 @@ var ListSnapshotsCmd = &cobra.Command{
Use: "list",
Short: "List local snapshots",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := server.GetServerContextFromCmd(cmd)
snapshotStore, err := server.GetSnapshotStore(ctx.Viper)
viper := client.GetViperFromCmd(cmd)
snapshotStore, err := server.GetSnapshotStore(viper)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions client/snapshot/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

snapshottypes "cosmossdk.io/store/snapshots/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/server"
)

Expand All @@ -27,8 +28,8 @@ func LoadArchiveCmd() *cobra.Command {
Short: "Load a snapshot archive file (.tar.gz) into snapshot store",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := server.GetServerContextFromCmd(cmd)
snapshotStore, err := server.GetSnapshotStore(ctx.Viper)
viper := client.GetViperFromCmd(cmd)
snapshotStore, err := server.GetSnapshotStore(viper)
if err != nil {
return err
}
Expand Down
10 changes: 6 additions & 4 deletions client/snapshot/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"cosmossdk.io/log"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/server"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
)
Expand All @@ -21,7 +22,8 @@ func RestoreSnapshotCmd[T servertypes.Application](appCreator servertypes.AppCre
Long: "Restore app state from local snapshot",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := server.GetServerContextFromCmd(cmd)
cfg := client.GetConfigFromCmd(cmd)
viper := client.GetViperFromCmd(cmd)

height, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
Expand All @@ -32,13 +34,13 @@ func RestoreSnapshotCmd[T servertypes.Application](appCreator servertypes.AppCre
return err
}

home := ctx.Config.RootDir
db, err := openDB(home, server.GetAppDBBackend(ctx.Viper))
home := cfg.RootDir
db, err := openDB(home, server.GetAppDBBackend(viper))
if err != nil {
return err
}
logger := log.NewLogger(cmd.OutOrStdout())
app := appCreator(logger, db, nil, ctx.Viper)
app := appCreator(logger, db, nil, viper)

sm := app.SnapshotManager()
return sm.RestoreLocalSnapshot(height, uint32(format))
Expand Down
5 changes: 3 additions & 2 deletions client/v2/sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ sonar.projectName=Cosmos SDK - Client V2
sonar.project.monorepo.enabled=true

sonar.sources=.
sonar.exclusions=**/*_test.go,**/*.pb.go,**/*.pulsar.go
sonar.exclusions=**/*_test.go,**/*.pb.go,**/*.pulsar.go,**/*.pb.gw.go
sonar.coverage.exclusions=**/*_test.go,**/testutil/**,**/*.pb.go,**/*.pb.gw.go,**/*.pulsar.go,test_helpers.go,docs/**
sonar.tests=.
sonar.test.inclusions=**/*_test.go
sonar.go.coverage.reportPaths=coverage.out

sonar.sourceEncoding=UTF-8
sonar.scm.provider=git
sonar.scm.provider=git
4 changes: 2 additions & 2 deletions collections/sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ sonar.projectName=Cosmos SDK - Collections
sonar.project.monorepo.enabled=true

sonar.sources=.
sonar.exclusions=**/*_test.go
sonar.exclusions=**/*_test.go,**/*.pb.go,**/*.pulsar.go,**/*.pb.gateway.go
sonar.tests=.
sonar.test.inclusions=**/*_test.go
sonar.go.coverage.reportPaths=coverage.out

sonar.sourceEncoding=UTF-8
sonar.scm.provider=git
sonar.scm.provider=git
6 changes: 6 additions & 0 deletions core/context/server_context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package context

type (
LoggerContextKey struct{}
ViperContextKey struct{}
)
6 changes: 0 additions & 6 deletions core/gas/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,11 @@ type Service interface {
// will be returned.
GasMeter(context.Context) Meter

// WithGasMeter returns a new context with the provided transaction-level gas meter.
WithGasMeter(ctx context.Context, meter Meter) context.Context

// BlockGasMeter returns the current block-level gas meter. A non-nil meter
// is always returned. When one is unavailable in the context an infinite gas meter
// will be returned.
BlockGasMeter(context.Context) Meter

// WithBlockGasMeter returns a new context with the provided block-level gas meter.
WithBlockGasMeter(ctx context.Context, meter Meter) context.Context

// GasConfig returns the gas costs.
GasConfig(ctx context.Context) GasConfig
}
Expand Down
2 changes: 1 addition & 1 deletion core/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions core/go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
github.com/cosmos/gogoproto v1.4.12 h1:vB6Lbe/rtnYGjQuFxkPiPYiCybqFT8QvLipDZP8JpFE=
github.com/cosmos/gogoproto v1.4.12/go.mod h1:LnZob1bXRdUoqMMtwYlcR3wjiElmlC+FkjaZRv1/eLY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
Expand Down
5 changes: 3 additions & 2 deletions core/sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ sonar.projectName=Cosmos SDK - Core
sonar.project.monorepo.enabled=true

sonar.sources=.
sonar.exclusions=**/*_test.go,**/*.pulsar.go
sonar.exclusions=**/*_test.go,**/*.pb.go,**/*.pulsar.go,**/*.pb.gw.go
sonar.coverage.exclusions=**/*_test.go,**/testutil/**,**/*.pb.go,**/*.pb.gw.go,**/*.pulsar.go,test_helpers.go,docs/**
sonar.tests=.
sonar.test.inclusions=**/*_test.go
sonar.go.coverage.reportPaths=coverage.out

sonar.sourceEncoding=UTF-8
sonar.scm.provider=git
sonar.scm.provider=git
5 changes: 3 additions & 2 deletions depinject/sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ sonar.projectName=Cosmos SDK Depinject
sonar.project.monorepo.enabled=true

sonar.sources=.
sonar.exclusions=**/*_test.go,**/*.pulsar.go
sonar.exclusions=**/*_test.go,**/*.pb.go,**/*.pulsar.go,**/*.pb.gw.go
sonar.coverage.exclusions=**/*_test.go,**/testutil/**,**/*.pb.go,**/*.pb.gw.go,**/*.pulsar.go,test_helpers.go,docs/**
sonar.tests=.
sonar.test.inclusions=**/*_test.go
sonar.go.coverage.reportPaths=coverage.out

sonar.sourceEncoding=UTF-8
sonar.scm.provider=git
sonar.scm.provider=git
3 changes: 2 additions & 1 deletion log/sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ sonar.projectName=Cosmos SDK - Log
sonar.project.monorepo.enabled=true

sonar.sources=.
sonar.exclusions=**/*_test.go
sonar.exclusions=**/*_test.go,**/*.pb.go,**/*.pulsar.go,**/*.pb.gw.go
sonar.coverage.exclusions=**/*_test.go,**/testutil/**,**/*.pb.go,**/*.pb.gw.go,**/*.pulsar.go,test_helpers.go,docs/**
sonar.tests=.
sonar.test.inclusions=**/*_test.go
sonar.go.coverage.reportPaths=coverage.out
Expand Down
5 changes: 3 additions & 2 deletions math/sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ sonar.projectName=Cosmos SDK - Math
sonar.project.monorepo.enabled=true

sonar.sources=.
sonar.exclusions=**/*_test.go
sonar.exclusions=**/*_test.go,**/*.pb.go,**/*.pulsar.go,**/*.pb.gw.go
sonar.coverage.exclusions=**/*_test.go,**/testutil/**,**/*.pb.go,**/*.pb.gw.go,**/*.pulsar.go,test_helpers.go,docs/**
sonar.tests=.
sonar.test.inclusions=**/*_test.go
sonar.go.coverage.reportPaths=coverage.out

sonar.sourceEncoding=UTF-8
sonar.scm.provider=git
sonar.scm.provider=git
5 changes: 3 additions & 2 deletions orm/sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ sonar.projectName=Cosmos SDK - ORM
sonar.project.monorepo.enabled=true

sonar.sources=.
sonar.exclusions=**/*_test.go
sonar.exclusions=**/*_test.go,**/*.pb.go,**/*.pulsar.go,**/*.pb.gw.go
sonar.coverage.exclusions=**/*_test.go,**/testutil/**,**/*.pb.go,**/*.pb.gw.go,**/*.pulsar.go,test_helpers.go,docs/**
sonar.tests=.
sonar.test.inclusions=**/*_test.go
sonar.go.coverage.reportPaths=coverage.out

sonar.sourceEncoding=UTF-8
sonar.scm.provider=git
sonar.scm.provider=git
Loading

0 comments on commit 8bf3749

Please sign in to comment.