diff --git a/CHANGELOG.md b/CHANGELOG.md index bb72e4ad902d..4dd5611d6f63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes +* [\#10295](https://github.com/cosmos/cosmos-sdk/pull/10295) Remove store type aliases from /types * [\#9695](https://github.com/cosmos/cosmos-sdk/pull/9695) Migrate keys from `Info` -> `Record` * Add new `codec.Codec` argument in: * `keyring.NewInMemory` @@ -121,6 +122,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (types) [\#10021](https://github.com/cosmos/cosmos-sdk/pull/10021) Speedup coins.AmountOf(), by removing many intermittent regex calls. * (rosetta) [\#10001](https://github.com/cosmos/cosmos-sdk/issues/10001) Add documentation for rosetta-cli dockerfile and rename folder for the rosetta-ci dockerfile * [\#9699](https://github.com/cosmos/cosmos-sdk/pull/9699) Add `:`, `.`, `-`, and `_` as allowed characters in the default denom regular expression. +* (genesis) [\#9697](https://github.com/cosmos/cosmos-sdk/pull/9697) Ensure `InitGenesis` returns with non-empty validator set. * [\#10262](https://github.com/cosmos/cosmos-sdk/pull/10262) Remove unnecessary logging in `x/feegrant` simulation. ### Bug Fixes diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 6044b9518d18..32073cc88278 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -15,6 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/snapshots" "github.com/cosmos/cosmos-sdk/store" "github.com/cosmos/cosmos-sdk/store/rootmulti" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx" ) @@ -185,20 +186,20 @@ func (app *BaseApp) Trace() bool { // MountStores mounts all IAVL or DB stores to the provided keys in the BaseApp // multistore. -func (app *BaseApp) MountStores(keys ...sdk.StoreKey) { +func (app *BaseApp) MountStores(keys ...storetypes.StoreKey) { for _, key := range keys { switch key.(type) { - case *sdk.KVStoreKey: + case *storetypes.KVStoreKey: if !app.fauxMerkleMode { - app.MountStore(key, sdk.StoreTypeIAVL) + app.MountStore(key, storetypes.StoreTypeIAVL) } else { // StoreTypeDB doesn't do anything upon commit, and it doesn't // retain history, but it's useful for faster simulation. - app.MountStore(key, sdk.StoreTypeDB) + app.MountStore(key, storetypes.StoreTypeDB) } - case *sdk.TransientStoreKey: - app.MountStore(key, sdk.StoreTypeTransient) + case *storetypes.TransientStoreKey: + app.MountStore(key, storetypes.StoreTypeTransient) default: panic("Unrecognized store key type " + reflect.TypeOf(key).Name()) @@ -208,37 +209,37 @@ func (app *BaseApp) MountStores(keys ...sdk.StoreKey) { // MountKVStores mounts all IAVL or DB stores to the provided keys in the // BaseApp multistore. -func (app *BaseApp) MountKVStores(keys map[string]*sdk.KVStoreKey) { +func (app *BaseApp) MountKVStores(keys map[string]*storetypes.KVStoreKey) { for _, key := range keys { if !app.fauxMerkleMode { - app.MountStore(key, sdk.StoreTypeIAVL) + app.MountStore(key, storetypes.StoreTypeIAVL) } else { // StoreTypeDB doesn't do anything upon commit, and it doesn't // retain history, but it's useful for faster simulation. - app.MountStore(key, sdk.StoreTypeDB) + app.MountStore(key, storetypes.StoreTypeDB) } } } // MountTransientStores mounts all transient stores to the provided keys in // the BaseApp multistore. -func (app *BaseApp) MountTransientStores(keys map[string]*sdk.TransientStoreKey) { +func (app *BaseApp) MountTransientStores(keys map[string]*storetypes.TransientStoreKey) { for _, key := range keys { - app.MountStore(key, sdk.StoreTypeTransient) + app.MountStore(key, storetypes.StoreTypeTransient) } } // MountMemoryStores mounts all in-memory KVStores with the BaseApp's internal // commit multi-store. -func (app *BaseApp) MountMemoryStores(keys map[string]*sdk.MemoryStoreKey) { +func (app *BaseApp) MountMemoryStores(keys map[string]*storetypes.MemoryStoreKey) { for _, memKey := range keys { - app.MountStore(memKey, sdk.StoreTypeMemory) + app.MountStore(memKey, storetypes.StoreTypeMemory) } } // MountStore mounts a store to the provided key in the BaseApp multistore, // using the default DB. -func (app *BaseApp) MountStore(key sdk.StoreKey, typ sdk.StoreType) { +func (app *BaseApp) MountStore(key storetypes.StoreKey, typ storetypes.StoreType) { app.cms.MountStoreWithDB(key, typ, nil) } @@ -270,7 +271,7 @@ func (app *BaseApp) LoadVersion(version int64) error { } // LastCommitID returns the last CommitID of the multistore. -func (app *BaseApp) LastCommitID() sdk.CommitID { +func (app *BaseApp) LastCommitID() storetypes.CommitID { return app.cms.LastCommitID() } diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 63abd71b5633..5d77a16469ce 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -27,7 +27,7 @@ import ( "github.com/cosmos/cosmos-sdk/snapshots" snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types" "github.com/cosmos/cosmos-sdk/store/rootmulti" - store "github.com/cosmos/cosmos-sdk/store/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -234,7 +234,7 @@ func TestMountStores(t *testing.T) { // Test that LoadLatestVersion actually does. func TestLoadVersion(t *testing.T) { logger := defaultLogger() - pruningOpt := baseapp.SetPruning(store.PruneNothing) + pruningOpt := baseapp.SetPruning(storetypes.PruneNothing) db := dbm.NewMemDB() name := t.Name() app := baseapp.NewBaseApp(name, logger, db, nil, pruningOpt) @@ -243,7 +243,7 @@ func TestLoadVersion(t *testing.T) { err := app.LoadLatestVersion() // needed to make stores non-nil require.Nil(t, err) - emptyCommitID := sdk.CommitID{} + emptyCommitID := storetypes.CommitID{} // fresh store has zero/empty last commit lastHeight := app.LastBlockHeight() @@ -255,13 +255,13 @@ func TestLoadVersion(t *testing.T) { header := tmproto.Header{Height: 1} app.BeginBlock(abci.RequestBeginBlock{Header: header}) res := app.Commit() - commitID1 := sdk.CommitID{Version: 1, Hash: res.Data} + commitID1 := storetypes.CommitID{Version: 1, Hash: res.Data} // execute a block, collect commit ID header = tmproto.Header{Height: 2} app.BeginBlock(abci.RequestBeginBlock{Header: header}) res = app.Commit() - commitID2 := sdk.CommitID{Version: 2, Hash: res.Data} + commitID2 := storetypes.CommitID{Version: 2, Hash: res.Data} // reload with LoadLatestVersion app = baseapp.NewBaseApp(name, logger, db, nil, pruningOpt) @@ -287,15 +287,15 @@ func useDefaultLoader(app *baseapp.BaseApp) { func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { rs := rootmulti.NewStore(db) - rs.SetPruning(store.PruneNothing) + rs.SetPruning(storetypes.PruneNothing) key := sdk.NewKVStoreKey(storeKey) - rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil) + rs.MountStoreWithDB(key, storetypes.StoreTypeIAVL, nil) err := rs.LoadLatestVersion() require.Nil(t, err) require.Equal(t, int64(0), rs.LastCommitID().Version) // write some data in substore - kv, _ := rs.GetStore(key).(store.KVStore) + kv, _ := rs.GetStore(key).(storetypes.KVStore) require.NotNil(t, kv) kv.Set(k, v) commitID := rs.Commit() @@ -304,15 +304,15 @@ func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { func checkStore(t *testing.T, db dbm.DB, ver int64, storeKey string, k, v []byte) { rs := rootmulti.NewStore(db) - rs.SetPruning(store.PruneDefault) + rs.SetPruning(storetypes.PruneDefault) key := sdk.NewKVStoreKey(storeKey) - rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil) + rs.MountStoreWithDB(key, storetypes.StoreTypeIAVL, nil) err := rs.LoadLatestVersion() require.Nil(t, err) require.Equal(t, ver, rs.LastCommitID().Version) // query data in substore - kv, _ := rs.GetStore(key).(store.KVStore) + kv, _ := rs.GetStore(key).(storetypes.KVStore) require.NotNil(t, kv) require.Equal(t, v, kv.Get(k)) } @@ -347,7 +347,7 @@ func TestSetLoader(t *testing.T) { initStore(t, db, tc.origStoreKey, k, v) // load the app with the existing db - opts := []func(*baseapp.BaseApp){baseapp.SetPruning(store.PruneNothing)} + opts := []func(*baseapp.BaseApp){baseapp.SetPruning(storetypes.PruneNothing)} if tc.setLoader != nil { opts = append(opts, tc.setLoader) } @@ -370,7 +370,7 @@ func TestSetLoader(t *testing.T) { func TestVersionSetterGetter(t *testing.T) { logger := defaultLogger() - pruningOpt := baseapp.SetPruning(store.PruneDefault) + pruningOpt := baseapp.SetPruning(storetypes.PruneDefault) db := dbm.NewMemDB() name := t.Name() app := baseapp.NewBaseApp(name, logger, db, nil, pruningOpt) @@ -390,7 +390,7 @@ func TestVersionSetterGetter(t *testing.T) { func TestLoadVersionInvalid(t *testing.T) { logger := log.NewNopLogger() - pruningOpt := baseapp.SetPruning(store.PruneNothing) + pruningOpt := baseapp.SetPruning(storetypes.PruneNothing) db := dbm.NewMemDB() name := t.Name() app := baseapp.NewBaseApp(name, logger, db, nil, pruningOpt) @@ -405,7 +405,7 @@ func TestLoadVersionInvalid(t *testing.T) { header := tmproto.Header{Height: 1} app.BeginBlock(abci.RequestBeginBlock{Header: header}) res := app.Commit() - commitID1 := sdk.CommitID{Version: 1, Hash: res.Data} + commitID1 := storetypes.CommitID{Version: 1, Hash: res.Data} // create a new app with the stores mounted under the same cap key app = baseapp.NewBaseApp(name, logger, db, nil, pruningOpt) @@ -422,7 +422,7 @@ func TestLoadVersionInvalid(t *testing.T) { func TestLoadVersionPruning(t *testing.T) { logger := log.NewNopLogger() - pruningOptions := store.PruningOptions{ + pruningOptions := storetypes.PruningOptions{ KeepRecent: 2, KeepEvery: 3, Interval: 1, @@ -439,7 +439,7 @@ func TestLoadVersionPruning(t *testing.T) { err := app.LoadLatestVersion() // needed to make stores non-nil require.Nil(t, err) - emptyCommitID := sdk.CommitID{} + emptyCommitID := storetypes.CommitID{} // fresh store has zero/empty last commit lastHeight := app.LastBlockHeight() @@ -447,14 +447,14 @@ func TestLoadVersionPruning(t *testing.T) { require.Equal(t, int64(0), lastHeight) require.Equal(t, emptyCommitID, lastID) - var lastCommitID sdk.CommitID + var lastCommitID storetypes.CommitID // Commit seven blocks, of which 7 (latest) is kept in addition to 6, 5 // (keep recent) and 3 (keep every). for i := int64(1); i <= 7; i++ { app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: i}}) res := app.Commit() - lastCommitID = sdk.CommitID{Version: i, Hash: res.Data} + lastCommitID = storetypes.CommitID{Version: i, Hash: res.Data} } for _, v := range []int64{1, 2, 4} { @@ -476,7 +476,7 @@ func TestLoadVersionPruning(t *testing.T) { testLoadVersionHelper(t, app, int64(7), lastCommitID) } -func testLoadVersionHelper(t *testing.T, app *baseapp.BaseApp, expectedHeight int64, expectedID sdk.CommitID) { +func testLoadVersionHelper(t *testing.T, app *baseapp.BaseApp, expectedHeight int64, expectedID storetypes.CommitID) { lastHeight := app.LastBlockHeight() lastID := app.LastCommitID() require.Equal(t, expectedHeight, lastHeight) @@ -845,7 +845,7 @@ func testTxDecoder(cdc *codec.LegacyAmino) sdk.TxDecoder { } } -func customHandlerTxTest(t *testing.T, capKey sdk.StoreKey, storeKey []byte) handlerFun { +func customHandlerTxTest(t *testing.T, capKey storetypes.StoreKey, storeKey []byte) handlerFun { return func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) { store := ctx.KVStore(capKey) txTest := tx.(txTest) @@ -876,7 +876,7 @@ func counterEvent(evType string, msgCount int64) sdk.Events { } } -func handlerMsgCounter(t *testing.T, capKey sdk.StoreKey, deliverKey []byte) sdk.Handler { +func handlerMsgCounter(t *testing.T, capKey storetypes.StoreKey, deliverKey []byte) sdk.Handler { return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { ctx = ctx.WithEventManager(sdk.NewEventManager()) store := ctx.KVStore(capKey) diff --git a/container/config.go b/container/config.go new file mode 100644 index 000000000000..12437d7c009f --- /dev/null +++ b/container/config.go @@ -0,0 +1,173 @@ +package container + +import ( + "bytes" + "fmt" + "path/filepath" + "reflect" + + "github.com/pkg/errors" + + "github.com/goccy/go-graphviz" + "github.com/goccy/go-graphviz/cgraph" +) + +type config struct { + // logging + loggers []func(string) + indentStr string + + // graphing + graphviz *graphviz.Graphviz + graph *cgraph.Graph + visualizers []func(string) + logVisualizer bool +} + +func newConfig() (*config, error) { + g := graphviz.New() + graph, err := g.Graph() + if err != nil { + return nil, errors.Wrap(err, "error initializing graph") + } + + return &config{ + graphviz: g, + graph: graph, + }, nil +} + +func (c *config) indentLogger() { + c.indentStr = c.indentStr + " " +} + +func (c *config) dedentLogger() { + if len(c.indentStr) > 0 { + c.indentStr = c.indentStr[1:] + } +} + +func (c config) logf(format string, args ...interface{}) { + s := fmt.Sprintf(c.indentStr+format, args...) + for _, logger := range c.loggers { + logger(s) + } +} + +func (c *config) generateGraph() { + buf := &bytes.Buffer{} + err := c.graphviz.Render(c.graph, graphviz.XDOT, buf) + if err != nil { + c.logf("Error rendering DOT graph: %+v", err) + return + } + + dot := buf.String() + if c.logVisualizer { + c.logf("DOT Graph: %s", dot) + } + + for _, v := range c.visualizers { + v(dot) + } + + err = c.graph.Close() + if err != nil { + c.logf("Error closing graph: %+v", err) + return + } + + err = c.graphviz.Close() + if err != nil { + c.logf("Error closing graphviz: %+v", err) + } +} + +func (c *config) addFuncVisualizer(f func(string)) { + c.visualizers = append(c.visualizers, func(dot string) { + f(dot) + }) +} + +func (c *config) enableLogVisualizer() { + c.logVisualizer = true +} + +func (c *config) addFileVisualizer(filename string, format string) { + c.visualizers = append(c.visualizers, func(_ string) { + err := c.graphviz.RenderFilename(c.graph, graphviz.Format(format), filename) + if err != nil { + c.logf("Error saving graphviz file %s with format %s: %+v", filename, format, err) + } else { + path, err := filepath.Abs(filename) + if err == nil { + c.logf("Saved graph of container to %s", path) + } + } + }) +} + +func (c *config) locationGraphNode(location Location, scope Scope) (*cgraph.Node, error) { + graph := c.scopeSubGraph(scope) + node, found, err := c.findOrCreateGraphNode(graph, location.Name()) + if err != nil { + return nil, err + } + + if found { + return node, nil + } + + node.SetShape(cgraph.BoxShape) + node.SetColor("lightgrey") + return node, nil +} + +func (c *config) typeGraphNode(typ reflect.Type) (*cgraph.Node, error) { + node, found, err := c.findOrCreateGraphNode(c.graph, typ.String()) + if err != nil { + return nil, err + } + + if found { + return node, nil + } + + node.SetColor("lightgrey") + return node, err +} + +func (c *config) findOrCreateGraphNode(subGraph *cgraph.Graph, name string) (node *cgraph.Node, found bool, err error) { + node, err = c.graph.Node(name) + if err != nil { + return nil, false, errors.Wrapf(err, "error finding graph node %s", name) + } + + if node != nil { + return node, true, nil + } + + node, err = subGraph.CreateNode(name) + if err != nil { + return nil, false, errors.Wrapf(err, "error creating graph node %s", name) + } + + return node, false, nil +} + +func (c *config) scopeSubGraph(scope Scope) *cgraph.Graph { + graph := c.graph + if scope != nil { + gname := fmt.Sprintf("cluster_%s", scope.Name()) + graph = c.graph.SubGraph(gname, 1) + graph.SetLabel(fmt.Sprintf("Scope: %s", scope.Name())) + } + return graph +} + +func (c *config) addGraphEdge(from *cgraph.Node, to *cgraph.Node) { + _, err := c.graph.CreateEdge("", from, to) + if err != nil { + c.logf("error creating graph edge") + } +} diff --git a/container/constructor_info.go b/container/constructor_info.go deleted file mode 100644 index b3b5e7b50025..000000000000 --- a/container/constructor_info.go +++ /dev/null @@ -1,22 +0,0 @@ -package container - -import "reflect" - -// ConstructorInfo defines a special constructor type that is defined by -// reflection. It should be passed as a value to the Provide function. -// Ex: -// option.Provide(ConstructorInfo{ ... }) -type ConstructorInfo struct { - // In defines the in parameter types to Fn. - In []reflect.Type - - // Out defines the out parameter types to Fn. - Out []reflect.Type - - // Fn defines the constructor function. - Fn func([]reflect.Value) []reflect.Value - - // Location defines the source code location to be used for this constructor - // in error messages. - Location Location -} diff --git a/container/container.go b/container/container.go new file mode 100644 index 000000000000..e528726d60c2 --- /dev/null +++ b/container/container.go @@ -0,0 +1,406 @@ +package container + +import ( + "bytes" + "fmt" + "reflect" + + "github.com/goccy/go-graphviz/cgraph" + "github.com/pkg/errors" +) + +type container struct { + *config + + resolvers map[reflect.Type]resolver + + scopes map[string]Scope + + resolveStack []resolveFrame + callerStack []Location + callerMap map[Location]bool +} + +type resolveFrame struct { + loc Location + typ reflect.Type +} + +func newContainer(cfg *config) *container { + return &container{ + config: cfg, + resolvers: map[reflect.Type]resolver{}, + scopes: map[string]Scope{}, + callerStack: nil, + callerMap: map[Location]bool{}, + } +} + +func (c *container) call(constructor *ProviderDescriptor, scope Scope) ([]reflect.Value, error) { + loc := constructor.Location + graphNode, err := c.locationGraphNode(loc, scope) + if err != nil { + return nil, err + } + markGraphNodeAsFailed(graphNode) + + if c.callerMap[loc] { + return nil, errors.Errorf("cyclic dependency: %s -> %s", loc.Name(), loc.Name()) + } + + c.callerMap[loc] = true + c.callerStack = append(c.callerStack, loc) + + c.logf("Resolving dependencies for %s", loc) + c.indentLogger() + inVals := make([]reflect.Value, len(constructor.Inputs)) + for i, in := range constructor.Inputs { + val, err := c.resolve(in, scope, loc) + if err != nil { + return nil, err + } + inVals[i] = val + } + c.dedentLogger() + c.logf("Calling %s", loc) + + delete(c.callerMap, loc) + c.callerStack = c.callerStack[0 : len(c.callerStack)-1] + + out, err := constructor.Fn(inVals) + if err != nil { + return nil, errors.Wrapf(err, "error calling constructor %s", loc) + } + + markGraphNodeAsUsed(graphNode) + + return out, nil +} + +func (c *container) getResolver(typ reflect.Type) (resolver, error) { + if vr, ok := c.resolvers[typ]; ok { + return vr, nil + } + + elemType := typ + if isAutoGroupSliceType(elemType) || isOnePerScopeMapType(elemType) { + elemType = elemType.Elem() + } + + var typeGraphNode *cgraph.Node + var err error + + if isAutoGroupType(elemType) { + c.logf("Registering resolver for auto-group type %v", elemType) + sliceType := reflect.SliceOf(elemType) + + typeGraphNode, err = c.typeGraphNode(sliceType) + if err != nil { + return nil, err + } + typeGraphNode.SetComment("auto-group") + + r := &groupResolver{ + typ: elemType, + sliceType: sliceType, + graphNode: typeGraphNode, + } + + c.resolvers[elemType] = r + c.resolvers[sliceType] = &sliceGroupResolver{r} + } else if isOnePerScopeType(elemType) { + c.logf("Registering resolver for one-per-scope type %v", elemType) + mapType := reflect.MapOf(stringType, elemType) + + typeGraphNode, err = c.typeGraphNode(mapType) + if err != nil { + return nil, err + } + typeGraphNode.SetComment("one-per-scope") + + r := &onePerScopeResolver{ + typ: elemType, + mapType: mapType, + providers: map[Scope]*simpleProvider{}, + idxMap: map[Scope]int{}, + graphNode: typeGraphNode, + } + + c.resolvers[elemType] = r + c.resolvers[mapType] = &mapOfOnePerScopeResolver{r} + } + + return c.resolvers[typ], nil +} + +func (c *container) addNode(constructor *ProviderDescriptor, scope Scope) (interface{}, error) { + constructorGraphNode, err := c.locationGraphNode(constructor.Location, scope) + if err != nil { + return nil, err + } + + hasScopeParam := false + for _, in := range constructor.Inputs { + typ := in.Type + if typ == scopeType { + hasScopeParam = true + } + + if isAutoGroupType(typ) { + return nil, fmt.Errorf("auto-group type %v can't be used as an input parameter", typ) + } else if isOnePerScopeType(typ) { + return nil, fmt.Errorf("one-per-scope type %v can't be used as an input parameter", typ) + } + + vr, err := c.getResolver(typ) + if err != nil { + return nil, err + } + + var typeGraphNode *cgraph.Node + if vr != nil { + typeGraphNode = vr.typeGraphNode() + } else { + typeGraphNode, err = c.typeGraphNode(typ) + if err != nil { + return nil, err + } + } + + c.addGraphEdge(typeGraphNode, constructorGraphNode) + } + + if scope != nil || !hasScopeParam { + c.logf("Registering %s", constructor.Location.String()) + c.indentLogger() + defer c.dedentLogger() + + sp := &simpleProvider{ + provider: constructor, + scope: scope, + } + + for i, out := range constructor.Outputs { + typ := out.Type + + // one-per-scope maps can't be used as a return type + if isOnePerScopeMapType(typ) { + return nil, fmt.Errorf("%v cannot be used as a return type because %v is a one-per-scope type", + typ, typ.Elem()) + } + + // auto-group slices of auto-group types + if isAutoGroupSliceType(typ) { + typ = typ.Elem() + } + + vr, err := c.getResolver(typ) + if err != nil { + return nil, err + } + + if vr != nil { + c.logf("Found resolver for %v: %T", typ, vr) + err := vr.addNode(sp, i) + if err != nil { + return nil, err + } + } else { + c.logf("Registering resolver for simple type %v", typ) + + typeGraphNode, err := c.typeGraphNode(typ) + if err != nil { + return nil, err + } + + vr = &simpleResolver{ + node: sp, + typ: typ, + graphNode: typeGraphNode, + } + c.resolvers[typ] = vr + } + + c.addGraphEdge(constructorGraphNode, vr.typeGraphNode()) + } + + return sp, nil + } else { + c.logf("Registering scope provider: %s", constructor.Location.String()) + c.indentLogger() + defer c.dedentLogger() + + node := &scopeDepProvider{ + provider: constructor, + calledForScope: map[Scope]bool{}, + valueMap: map[Scope][]reflect.Value{}, + } + + for i, out := range constructor.Outputs { + typ := out.Type + + c.logf("Registering resolver for scoped type %v", typ) + + existing, ok := c.resolvers[typ] + if ok { + return nil, errors.Errorf("duplicate provision of type %v by scoped provider %s\n\talready provided by %s", + typ, constructor.Location, existing.describeLocation()) + } + + typeGraphNode, err := c.typeGraphNode(typ) + if err != nil { + return reflect.Value{}, err + } + + c.resolvers[typ] = &scopeDepResolver{ + typ: typ, + idxInValues: i, + node: node, + valueMap: map[Scope]reflect.Value{}, + graphNode: typeGraphNode, + } + + c.addGraphEdge(constructorGraphNode, typeGraphNode) + } + + return node, nil + } +} + +func (c *container) supply(value reflect.Value, location Location) error { + typ := value.Type() + locGrapNode, err := c.locationGraphNode(location, nil) + if err != nil { + return err + } + markGraphNodeAsUsed(locGrapNode) + + typeGraphNode, err := c.typeGraphNode(typ) + if err != nil { + return err + } + + c.addGraphEdge(locGrapNode, typeGraphNode) + + if existing, ok := c.resolvers[typ]; ok { + return duplicateDefinitionError(typ, location, existing.describeLocation()) + } + + c.resolvers[typ] = &supplyResolver{ + typ: typ, + value: value, + loc: location, + graphNode: typeGraphNode, + } + + return nil +} + +func (c *container) resolve(in ProviderInput, scope Scope, caller Location) (reflect.Value, error) { + c.resolveStack = append(c.resolveStack, resolveFrame{loc: caller, typ: in.Type}) + + typeGraphNode, err := c.typeGraphNode(in.Type) + if err != nil { + return reflect.Value{}, err + } + + if in.Type == scopeType { + if scope == nil { + return reflect.Value{}, errors.Errorf("trying to resolve %T for %s but not inside of any scope", scope, caller) + } + c.logf("Providing Scope %s", scope.Name()) + markGraphNodeAsUsed(typeGraphNode) + return reflect.ValueOf(scope), nil + } + + vr, err := c.getResolver(in.Type) + if err != nil { + return reflect.Value{}, err + } + + if vr == nil { + if in.Optional { + c.logf("Providing zero value for optional dependency %v", in.Type) + return reflect.Zero(in.Type), nil + } + + markGraphNodeAsFailed(typeGraphNode) + return reflect.Value{}, errors.Errorf("can't resolve type %v for %s:\n%s", + in.Type, caller, c.formatResolveStack()) + } + + res, err := vr.resolve(c, scope, caller) + if err != nil { + markGraphNodeAsFailed(typeGraphNode) + return reflect.Value{}, err + } + + markGraphNodeAsUsed(typeGraphNode) + + c.resolveStack = c.resolveStack[:len(c.resolveStack)-1] + + return res, nil +} + +func (c *container) run(invoker interface{}) error { + rctr, err := ExtractProviderDescriptor(invoker) + if err != nil { + return err + } + + if len(rctr.Outputs) > 0 { + return errors.Errorf("invoker function cannot have return values other than error: %s", rctr.Location) + } + + c.logf("Registering invoker") + c.indentLogger() + + node, err := c.addNode(&rctr, nil) + if err != nil { + return err + } + + c.dedentLogger() + + sn, ok := node.(*simpleProvider) + if !ok { + return errors.Errorf("cannot run scoped provider as an invoker") + } + + c.logf("Building container") + _, err = sn.resolveValues(c) + if err != nil { + return err + } + c.logf("Done building container") + + return nil +} + +func (c container) createOrGetScope(name string) Scope { + if s, ok := c.scopes[name]; ok { + return s + } + s := newScope(name) + c.scopes[name] = s + return s +} + +func (c container) formatResolveStack() string { + buf := &bytes.Buffer{} + _, _ = fmt.Fprintf(buf, "\twhile resolving:\n") + n := len(c.resolveStack) + for i := n - 1; i >= 0; i-- { + rk := c.resolveStack[i] + _, _ = fmt.Fprintf(buf, "\t\t%v for %s\n", rk.typ, rk.loc) + } + return buf.String() +} + +func markGraphNodeAsUsed(node *cgraph.Node) { + node.SetColor("black") +} + +func markGraphNodeAsFailed(node *cgraph.Node) { + node.SetColor("red") +} diff --git a/container/container_test.go b/container/container_test.go index 091ab3ab2987..9bb072c9cd39 100644 --- a/container/container_test.go +++ b/container/container_test.go @@ -1,6 +1,9 @@ package container_test import ( + "fmt" + "io/ioutil" + "os" "reflect" "testing" @@ -32,16 +35,20 @@ type Handler struct { Handle func() } +func (Handler) IsOnePerScopeType() {} + type Command struct { Run func() } +func (Command) IsAutoGroupType() {} + func ProvideKVStoreKey(scope container.Scope) KVStoreKey { return KVStoreKey{name: scope.Name()} } -func ProvideModuleKey(scope container.Scope) ModuleKey { - return ModuleKey(scope.Name()) +func ProvideModuleKey(scope container.Scope) (ModuleKey, error) { + return ModuleKey(scope.Name()), nil } func ProvideMsgClientA(_ container.Scope, key ModuleKey) MsgClientA { @@ -57,72 +64,480 @@ func (ModuleA) Provide(key KVStoreKey) (KeeperA, Handler, Command) { type ModuleB struct{} type BDependencies struct { - container.StructArgs + container.In Key KVStoreKey A MsgClientA } type BProvides struct { + container.Out + KeeperB KeeperB - Handler Handler Commands []Command } -func (ModuleB) Provide(dependencies BDependencies) BProvides { +func (ModuleB) Provide(dependencies BDependencies, _ container.Scope) (BProvides, Handler, error) { return BProvides{ KeeperB: KeeperB{ key: dependencies.Key, msgClientA: dependencies.A, }, - Handler: Handler{}, Commands: []Command{{}, {}}, + }, Handler{}, nil +} + +func TestScenario(t *testing.T) { + require.NoError(t, + container.Run( + func(handlers map[string]Handler, commands []Command, a KeeperA, b KeeperB) { + require.Len(t, handlers, 2) + require.Equal(t, Handler{}, handlers["a"]) + require.Equal(t, Handler{}, handlers["b"]) + require.Len(t, commands, 3) + require.Equal(t, KeeperA{ + key: KVStoreKey{name: "a"}, + }, a) + require.Equal(t, KeeperB{ + key: KVStoreKey{name: "b"}, + msgClientA: MsgClientA{ + key: "b", + }, + }, b) + }, + container.Provide( + ProvideKVStoreKey, + ProvideModuleKey, + ProvideMsgClientA, + ), + container.ProvideWithScope("a", wrapMethod0(ModuleA{})), + container.ProvideWithScope("b", wrapMethod0(ModuleB{})), + )) +} + +func wrapMethod0(module interface{}) interface{} { + methodFn := reflect.TypeOf(module).Method(0).Func.Interface() + ctrInfo, err := container.ExtractProviderDescriptor(methodFn) + if err != nil { + panic(err) } + + ctrInfo.Inputs = ctrInfo.Inputs[1:] + fn := ctrInfo.Fn + ctrInfo.Fn = func(values []reflect.Value) ([]reflect.Value, error) { + return fn(append([]reflect.Value{reflect.ValueOf(module)}, values...)) + } + return ctrInfo +} + +func TestResolveError(t *testing.T) { + require.Error(t, container.Run( + func(x string) {}, + container.Provide( + func(x float64) string { return fmt.Sprintf("%f", x) }, + func(x int) float64 { return float64(x) }, + func(x float32) int { return int(x) }, + ), + )) +} + +func TestCyclic(t *testing.T) { + require.Error(t, container.Run( + func(x string) {}, + container.Provide( + func(x int) float64 { return float64(x) }, + func(x float64) (int, string) { return int(x), "hi" }, + ), + )) +} + +func TestErrorOption(t *testing.T) { + err := container.Run(func() {}, container.Error(fmt.Errorf("an error"))) + require.Error(t, err) +} + +func TestBadCtr(t *testing.T) { + _, err := container.ExtractProviderDescriptor(KeeperA{}) + require.Error(t, err) +} + +func TestInvoker(t *testing.T) { + require.NoError(t, container.Run(func() {})) + require.NoError(t, container.Run(func() error { return nil })) + require.Error(t, container.Run(func() error { return fmt.Errorf("error") })) + require.Error(t, container.Run(func() int { return 0 })) +} + +func TestErrorFunc(t *testing.T) { + _, err := container.ExtractProviderDescriptor( + func() (error, int) { return nil, 0 }, + ) + require.Error(t, err) + + _, err = container.ExtractProviderDescriptor( + func() (int, error) { return 0, nil }, + ) + require.NoError(t, err) + + require.Error(t, + container.Run( + func(x int) { + }, + container.Provide(func() (int, error) { + return 0, fmt.Errorf("the error") + }), + )) + + require.Error(t, + container.Run(func() error { + return fmt.Errorf("the error") + }), "the error") +} + +func TestSimple(t *testing.T) { + require.NoError(t, + container.Run( + func(x int) { + require.Equal(t, 1, x) + }, + container.Provide( + func() int { return 1 }, + ), + ), + ) + + require.Error(t, + container.Run(func(int) {}, + container.Provide( + func() int { return 0 }, + func() int { return 1 }, + ), + ), + ) +} + +func TestScoped(t *testing.T) { + require.Error(t, + container.Run(func(int) {}, + container.Provide( + func(container.Scope) int { return 0 }, + ), + ), + ) + + require.Error(t, + container.Run(func(float64) {}, + container.Provide( + func(container.Scope) int { return 0 }, + func() int { return 1 }, + ), + container.ProvideWithScope("a", + func(x int) float64 { return float64(x) }, + ), + ), + ) + + require.Error(t, + container.Run(func(float64) {}, + container.Provide( + func() int { return 0 }, + func(container.Scope) int { return 1 }, + ), + container.ProvideWithScope("a", + func(x int) float64 { return float64(x) }, + ), + ), + ) + + require.Error(t, + container.Run(func(float64) {}, + container.Provide( + func(container.Scope) int { return 0 }, + func(container.Scope) int { return 1 }, + ), + container.ProvideWithScope("a", + func(x int) float64 { return float64(x) }, + ), + ), + ) + + require.NoError(t, + container.Run(func(float64) {}, + container.Provide( + func(container.Scope) int { return 0 }, + ), + container.ProvideWithScope("a", + func(x int) float64 { return float64(x) }, + ), + ), + ) + + require.Error(t, + container.Run(func(float64) {}, + container.Provide( + func(container.Scope) int { return 0 }, + ), + container.ProvideWithScope("", + func(x int) float64 { return float64(x) }, + ), + ), + ) + + require.NoError(t, + container.Run(func(float64, float32) {}, + container.Provide( + func(container.Scope) int { return 0 }, + ), + container.ProvideWithScope("a", + func(x int) float64 { return float64(x) }, + func(x int) float32 { return float32(x) }, + ), + ), + "use scope dep twice", + ) } -func TestRun(t *testing.T) { - t.Skip("Expecting this test to fail for now") +type OnePerScopeInt int + +func (OnePerScopeInt) IsOnePerScopeType() {} + +func TestOnePerScope(t *testing.T) { + require.Error(t, + container.Run( + func(OnePerScopeInt) {}, + ), + "bad input type", + ) + require.NoError(t, container.Run( - func(handlers map[container.Scope]Handler, commands []Command, a KeeperA, b KeeperB) { - // TODO: - // require one Handler for module a and a scopes - // require 3 commands - // require KeeperA have store key a - // require KeeperB have store key b and MsgClientA + func(x map[string]OnePerScopeInt, y string) { + require.Equal(t, map[string]OnePerScopeInt{ + "a": 3, + "b": 4, + }, x) + require.Equal(t, "7", y) + }, + container.ProvideWithScope("a", + func() OnePerScopeInt { return 3 }, + ), + container.ProvideWithScope("b", + func() OnePerScopeInt { return 4 }, + ), + container.Provide(func(x map[string]OnePerScopeInt) string { + sum := 0 + for _, v := range x { + sum += int(v) + } + return fmt.Sprintf("%d", sum) }), - container.AutoGroupTypes(reflect.TypeOf(Command{})), - container.OnePerScopeTypes(reflect.TypeOf(Handler{})), - container.Provide( - ProvideKVStoreKey, - ProvideModuleKey, - ProvideMsgClientA, ), - container.ProvideWithScope(container.NewScope("a"), wrapProvideMethod(ModuleA{})), - container.ProvideWithScope(container.NewScope("b"), wrapProvideMethod(ModuleB{})), + ) + + require.Error(t, + container.Run( + func(map[string]OnePerScopeInt) {}, + container.ProvideWithScope("a", + func() OnePerScopeInt { return 0 }, + func() OnePerScopeInt { return 0 }, + ), + ), + "duplicate", + ) + + require.Error(t, + container.Run( + func(map[string]OnePerScopeInt) {}, + container.Provide( + func() OnePerScopeInt { return 0 }, + ), + ), + "out of scope", + ) + + require.Error(t, + container.Run( + func(map[string]OnePerScopeInt) {}, + container.Provide( + func() map[string]OnePerScopeInt { return nil }, + ), + ), + "bad return type", + ) + + require.NoError(t, + container.Run( + func(map[string]OnePerScopeInt) {}, + ), + "no providers", ) } -func wrapProvideMethod(module interface{}) container.ConstructorInfo { - method := reflect.TypeOf(module).Method(0) - methodTy := method.Type - var in []reflect.Type - var out []reflect.Type +type AutoGroupInt int - for i := 1; i < methodTy.NumIn(); i++ { - in = append(in, methodTy.In(i)) - } - for i := 0; i < methodTy.NumOut(); i++ { - out = append(out, methodTy.Out(i)) - } +func (AutoGroupInt) IsAutoGroupType() {} + +func TestAutoGroup(t *testing.T) { + require.NoError(t, + container.Run( + func(xs []AutoGroupInt, sum string) { + require.Len(t, xs, 2) + require.Contains(t, xs, AutoGroupInt(4)) + require.Contains(t, xs, AutoGroupInt(9)) + require.Equal(t, "13", sum) + }, + container.Provide( + func() AutoGroupInt { return 4 }, + func() AutoGroupInt { return 9 }, + func(xs []AutoGroupInt) string { + sum := 0 + for _, x := range xs { + sum += int(x) + } + return fmt.Sprintf("%d", sum) + }, + ), + ), + ) + + require.Error(t, + container.Run( + func(AutoGroupInt) {}, + container.Provide( + func() AutoGroupInt { return 0 }, + ), + ), + "bad input type", + ) + + require.NoError(t, + container.Run( + func([]AutoGroupInt) {}, + ), + "no providers", + ) +} - return container.ConstructorInfo{ - In: in, - Out: out, - Fn: func(values []reflect.Value) []reflect.Value { - values = append([]reflect.Value{reflect.ValueOf(module)}, values...) - return method.Func.Call(values) +func TestSupply(t *testing.T) { + require.NoError(t, + container.Run(func(x int) { + require.Equal(t, 3, x) }, - Location: container.LocationFromPC(method.Func.Pointer()), - } + container.Supply(3), + ), + ) + + require.Error(t, + container.Run(func(x int) {}, + container.Supply(3), + container.Provide(func() int { return 4 }), + ), + "can't supply then provide", + ) + + require.Error(t, + container.Run(func(x int) {}, + container.Supply(3), + container.Provide(func() int { return 4 }), + ), + "can't provide then supply", + ) + + require.Error(t, + container.Run(func(x int) {}, + container.Supply(3, 4), + ), + "can't supply twice", + ) +} + +type TestInput struct { + container.In + + X int `optional:"true"` + Y float64 +} + +type TestOutput struct { + container.Out + + X string +} + +func TestStructArgs(t *testing.T) { + require.Error(t, container.Run( + func(input TestInput) {}, + )) + + require.NoError(t, container.Run( + func(input TestInput) { + require.Equal(t, 0, input.X) + require.Equal(t, 1.3, input.Y) + }, + container.Supply(1.3), + )) + + require.NoError(t, container.Run( + func(input TestInput) { + require.Equal(t, 1, input.X) + require.Equal(t, 1.3, input.Y) + }, + container.Supply(1.3, 1), + )) + + require.NoError(t, container.Run( + func(x string) { + require.Equal(t, "A", x) + }, + container.Provide(func() (TestOutput, error) { + return TestOutput{X: "A"}, nil + }), + )) + + require.Error(t, container.Run( + func(x string) {}, + container.Provide(func() (TestOutput, error) { + return TestOutput{}, fmt.Errorf("error") + }), + )) +} + +func TestLogging(t *testing.T) { + var logOut string + var dotGraph string + + outfile, err := ioutil.TempFile("", "out") + require.NoError(t, err) + stdout := os.Stdout + os.Stdout = outfile + defer func() { os.Stdout = stdout }() + defer os.Remove(outfile.Name()) + + graphfile, err := ioutil.TempFile("", "graph") + require.NoError(t, err) + defer os.Remove(graphfile.Name()) + + require.NoError(t, container.Run( + func() {}, + container.Logger(func(s string) { + logOut += s + }), + container.Visualizer(func(g string) { + dotGraph = g + }), + container.LogVisualizer(), + container.FileVisualizer(graphfile.Name(), "svg"), + container.StdoutLogger(), + )) + + require.Contains(t, logOut, "digraph") + require.Contains(t, dotGraph, "digraph") + + outfileContents, err := ioutil.ReadFile(outfile.Name()) + require.NoError(t, err) + require.Contains(t, string(outfileContents), "digraph") + + graphfileContents, err := ioutil.ReadFile(graphfile.Name()) + require.NoError(t, err) + require.Contains(t, string(graphfileContents), "= 0 { + idx = i + } + if i := strings.Index(function[idx:], "."); i >= 0 { + idx += i + } + pname, fname = function[:idx], function[idx+1:] + + // The package may be vendored. + if i := strings.Index(pname, _vendor); i > 0 { + pname = pname[i+len(_vendor):] + } + + // Package names are URL-encoded to avoid ambiguity in the case where the + // package name contains ".git". Otherwise, "foo/bar.git.MyFunction" would + // mean that "git" is the top-level function and "MyFunction" is embedded + // inside it. + if unescaped, err := url.QueryUnescape(pname); err == nil { + pname = unescaped + } + + return } diff --git a/container/one_per_scope.go b/container/one_per_scope.go new file mode 100644 index 000000000000..e153884dce1d --- /dev/null +++ b/container/one_per_scope.go @@ -0,0 +1,106 @@ +package container + +import ( + "fmt" + "reflect" + + "github.com/goccy/go-graphviz/cgraph" + + "github.com/pkg/errors" +) + +// OnePerScopeType marks a type which +// can have up to one value per scope. All of the values for a one-per-scope type T +// and their respective scopes, can be retrieved by declaring an input parameter map[string]T. +type OnePerScopeType interface { + // IsOnePerScopeType is a marker function just indicates that this is a one-per-scope type. + IsOnePerScopeType() +} + +var onePerScopeTypeType = reflect.TypeOf((*OnePerScopeType)(nil)).Elem() + +func isOnePerScopeType(t reflect.Type) bool { + return t.Implements(onePerScopeTypeType) +} + +func isOnePerScopeMapType(typ reflect.Type) bool { + return typ.Kind() == reflect.Map && isOnePerScopeType(typ.Elem()) && typ.Key().Kind() == reflect.String +} + +type onePerScopeResolver struct { + typ reflect.Type + mapType reflect.Type + providers map[Scope]*simpleProvider + idxMap map[Scope]int + resolved bool + values reflect.Value + graphNode *cgraph.Node +} + +type mapOfOnePerScopeResolver struct { + *onePerScopeResolver +} + +func (o *onePerScopeResolver) resolve(_ *container, _ Scope, _ Location) (reflect.Value, error) { + return reflect.Value{}, errors.Errorf("%v is a one-per-scope type and thus can't be used as an input parameter, instead use %v", o.typ, o.mapType) +} + +func (o *onePerScopeResolver) describeLocation() string { + return fmt.Sprintf("one-per-scope type %v", o.typ) +} + +func (o *mapOfOnePerScopeResolver) resolve(c *container, _ Scope, caller Location) (reflect.Value, error) { + // Log + c.logf("Providing one-per-scope type map %v to %s from:", o.mapType, caller.Name()) + c.indentLogger() + for scope, node := range o.providers { + c.logf("%s: %s", scope.Name(), node.provider.Location) + } + c.dedentLogger() + + // Resolve + if !o.resolved { + res := reflect.MakeMap(o.mapType) + for scope, node := range o.providers { + values, err := node.resolveValues(c) + if err != nil { + return reflect.Value{}, err + } + idx := o.idxMap[scope] + if len(values) < idx { + return reflect.Value{}, errors.Errorf("expected value of type %T at index %d", o.typ, idx) + } + value := values[idx] + res.SetMapIndex(reflect.ValueOf(scope.Name()), value) + } + + o.values = res + o.resolved = true + } + + return o.values, nil +} + +func (o *onePerScopeResolver) addNode(n *simpleProvider, i int) error { + if n.scope == nil { + return errors.Errorf("cannot define a constructor with one-per-scope dependency %v which isn't provided in a scope", o.typ) + } + + if existing, ok := o.providers[n.scope]; ok { + return errors.Errorf("duplicate provision for one-per-scope type %v in scope %s: %s\n\talready provided by %s", + o.typ, n.scope.Name(), n.provider.Location, existing.provider.Location) + } + + o.providers[n.scope] = n + o.idxMap[n.scope] = i + + return nil +} + +func (o *mapOfOnePerScopeResolver) addNode(s *simpleProvider, _ int) error { + return errors.Errorf("%v is a one-per-scope type and thus %v can't be used as an output parameter in %s", o.typ, o.mapType, s.provider.Location) +} + +func (o onePerScopeResolver) typeGraphNode() *cgraph.Node { + return o.graphNode +} diff --git a/container/option.go b/container/option.go index e13887286436..9388ab6f64a9 100644 --- a/container/option.go +++ b/container/option.go @@ -1,10 +1,17 @@ package container -import "reflect" +import ( + "fmt" + "os" + "reflect" + + "github.com/pkg/errors" +) // Option is a functional option for a container. type Option interface { - isOption() + applyConfig(*config) error + applyContainer(*container) error } // Provide creates a container option which registers the provided dependency @@ -12,39 +19,163 @@ type Option interface { // exception of scoped constructors which are called at most once per scope // (see Scope). func Provide(constructors ...interface{}) Option { - panic("TODO") + return containerOption(func(ctr *container) error { + return provide(ctr, nil, constructors) + }) } // ProvideWithScope creates a container option which registers the provided dependency // injection constructors that are to be run in the provided scope. Each constructor // will be called at most once. -func ProvideWithScope(scope Scope, constructors ...interface{}) Option { - panic("TODO") +func ProvideWithScope(scopeName string, constructors ...interface{}) Option { + return containerOption(func(ctr *container) error { + if scopeName == "" { + return errors.Errorf("expected non-empty scope name") + } + + return provide(ctr, ctr.createOrGetScope(scopeName), constructors) + }) +} + +func provide(ctr *container, scope Scope, constructors []interface{}) error { + for _, c := range constructors { + rc, err := ExtractProviderDescriptor(c) + if err != nil { + return errors.WithStack(err) + } + _, err = ctr.addNode(&rc, scope) + if err != nil { + return errors.WithStack(err) + } + } + return nil +} + +func Supply(values ...interface{}) Option { + loc := LocationFromCaller(1) + return containerOption(func(ctr *container) error { + for _, v := range values { + err := ctr.supply(reflect.ValueOf(v), loc) + if err != nil { + return errors.WithStack(err) + } + } + return nil + }) +} + +// Logger creates an option which provides a logger function which will +// receive all log messages from the container. +func Logger(logger func(string)) Option { + return configOption(func(c *config) error { + logger("Initializing logger") + c.loggers = append(c.loggers, logger) + return nil + }) } -// AutoGroupTypes creates an option which registers the provided types as types which -// will automatically get grouped together. For a given type T, T and []T can -// be declared as output parameters for constructors as many times within the container -// as desired. All of the provided values for T can be retrieved by declaring an -// []T input parameter. -func AutoGroupTypes(types ...reflect.Type) Option { - panic("TODO") +func StdoutLogger() Option { + return Logger(func(s string) { + _, _ = fmt.Fprintln(os.Stdout, s) + }) } -// OnePerScopeTypes creates an option which registers the provided types as types which -// can have up to one value per scope. All of the values for a one-per-scope type T -// and their respective scopes, can be retrieved by declaring an input parameter map[Scope]T. -func OnePerScopeTypes(types ...reflect.Type) Option { - panic("TODO") +// Visualizer creates an option which provides a visualizer function which +// will receive a rendering of the container in the Graphiz DOT format +// whenever the container finishes building or fails due to an error. The +// graph is color-coded to aid debugging. +func Visualizer(visualizer func(dotGraph string)) Option { + return configOption(func(c *config) error { + c.addFuncVisualizer(visualizer) + return nil + }) +} + +func LogVisualizer() Option { + return configOption(func(c *config) error { + c.enableLogVisualizer() + return nil + }) +} + +func FileVisualizer(filename, format string) Option { + return configOption(func(c *config) error { + c.addFileVisualizer(filename, format) + return nil + }) +} + +func Debug() Option { + return Options( + StdoutLogger(), + LogVisualizer(), + FileVisualizer("container_dump.svg", "svg"), + ) } // Error creates an option which causes the dependency injection container to // fail immediately. func Error(err error) Option { - panic("TODO") + return configOption(func(*config) error { + return errors.WithStack(err) + }) } // Options creates an option which bundles together other options. func Options(opts ...Option) Option { - panic("TODO") + return option{ + configOption: func(cfg *config) error { + for _, opt := range opts { + err := opt.applyConfig(cfg) + if err != nil { + return errors.WithStack(err) + } + } + return nil + }, + containerOption: func(ctr *container) error { + for _, opt := range opts { + err := opt.applyContainer(ctr) + if err != nil { + return errors.WithStack(err) + } + } + return nil + }, + } } + +type configOption func(*config) error + +func (c configOption) applyConfig(cfg *config) error { + return c(cfg) +} + +func (c configOption) applyContainer(*container) error { + return nil +} + +type containerOption func(*container) error + +func (c containerOption) applyConfig(*config) error { + return nil +} + +func (c containerOption) applyContainer(ctr *container) error { + return c(ctr) +} + +type option struct { + configOption + containerOption +} + +func (o option) applyConfig(c *config) error { + return o.configOption(c) +} + +func (o option) applyContainer(c *container) error { + return o.containerOption(c) +} + +var _, _, _ Option = (*configOption)(nil), (*containerOption)(nil), option{} diff --git a/container/provider_desc.go b/container/provider_desc.go new file mode 100644 index 000000000000..76e1cd2ca830 --- /dev/null +++ b/container/provider_desc.go @@ -0,0 +1,104 @@ +package container + +import ( + "reflect" + + "github.com/pkg/errors" +) + +// ProviderDescriptor defines a special constructor type that is defined by +// reflection. It should be passed as a value to the Provide function. +// Ex: +// option.Provide(ProviderDescriptor{ ... }) +type ProviderDescriptor struct { + // Inputs defines the in parameter types to Fn. + Inputs []ProviderInput + + // Outputs defines the out parameter types to Fn. + Outputs []ProviderOutput + + // Fn defines the constructor function. + Fn func([]reflect.Value) ([]reflect.Value, error) + + // Location defines the source code location to be used for this constructor + // in error messages. + Location Location +} + +type ProviderInput struct { + Type reflect.Type + Optional bool +} + +type ProviderOutput struct { + Type reflect.Type +} + +func ExtractProviderDescriptor(provider interface{}) (ProviderDescriptor, error) { + rctr, ok := provider.(ProviderDescriptor) + if !ok { + var err error + rctr, err = doExtractProviderDescriptor(provider) + if err != nil { + return ProviderDescriptor{}, err + } + } + + return expandStructArgsConstructor(rctr) +} + +func doExtractProviderDescriptor(ctr interface{}) (ProviderDescriptor, error) { + val := reflect.ValueOf(ctr) + typ := val.Type() + if typ.Kind() != reflect.Func { + return ProviderDescriptor{}, errors.Errorf("expected a Func type, got %v", typ) + } + + loc := LocationFromPC(val.Pointer()) + + if typ.IsVariadic() { + return ProviderDescriptor{}, errors.Errorf("variadic function can't be used as a constructor: %s", loc) + } + + numIn := typ.NumIn() + in := make([]ProviderInput, numIn) + for i := 0; i < numIn; i++ { + in[i] = ProviderInput{ + Type: typ.In(i), + } + } + + errIdx := -1 + numOut := typ.NumOut() + var out []ProviderOutput + for i := 0; i < numOut; i++ { + t := typ.Out(i) + if t == errType { + if i != numOut-1 { + return ProviderDescriptor{}, errors.Errorf("output error parameter is not last parameter in function %s", loc) + } + errIdx = i + } else { + out = append(out, ProviderOutput{Type: t}) + } + } + + return ProviderDescriptor{ + Inputs: in, + Outputs: out, + Fn: func(values []reflect.Value) ([]reflect.Value, error) { + res := val.Call(values) + if errIdx >= 0 { + err := res[errIdx] + if !err.IsZero() { + return nil, err.Interface().(error) + } + return res[0:errIdx], nil + } + return res, nil + }, + Location: loc, + }, nil +} + +var errType = reflect.TypeOf((*error)(nil)).Elem() diff --git a/container/provider_desc_test.go b/container/provider_desc_test.go new file mode 100644 index 000000000000..b7dcae896421 --- /dev/null +++ b/container/provider_desc_test.go @@ -0,0 +1,106 @@ +package container_test + +import ( + "reflect" + "testing" + + "github.com/cosmos/cosmos-sdk/container" +) + +type StructIn struct { + container.In + X int + Y float64 `optional:"true"` +} + +type BadOptional struct { + container.In + X int `optional:"foo"` +} + +type StructOut struct { + container.Out + X string + Y []byte +} + +func TestExtractConstructorInfo(t *testing.T) { + var ( + intType = reflect.TypeOf(0) + int16Type = reflect.TypeOf(int16(0)) + int32Type = reflect.TypeOf(int32(0)) + float32Type = reflect.TypeOf(float32(0.0)) + float64Type = reflect.TypeOf(0.0) + stringType = reflect.TypeOf("") + byteTyp = reflect.TypeOf(byte(0)) + bytesTyp = reflect.TypeOf([]byte{}) + ) + + tests := []struct { + name string + ctr interface{} + wantIn []container.ProviderInput + wantOut []container.ProviderOutput + wantErr bool + }{ + { + "simple args", + func(x int, y float64) (string, []byte) { return "", nil }, + []container.ProviderInput{{Type: intType}, {Type: float64Type}}, + []container.ProviderOutput{{Type: stringType}, {Type: bytesTyp}}, + false, + }, + { + "simple args with error", + func(x int, y float64) (string, []byte, error) { return "", nil, nil }, + []container.ProviderInput{{Type: intType}, {Type: float64Type}}, + []container.ProviderOutput{{Type: stringType}, {Type: bytesTyp}}, + false, + }, + { + "struct in and out", + func(_ float32, _ StructIn, _ byte) (int16, StructOut, int32, error) { + return int16(0), StructOut{}, int32(0), nil + }, + []container.ProviderInput{{Type: float32Type}, {Type: intType}, {Type: float64Type, Optional: true}, {Type: byteTyp}}, + []container.ProviderOutput{{Type: int16Type}, {Type: stringType}, {Type: bytesTyp}, {Type: int32Type}}, + false, + }, + { + "error bad position", + func() (error, int) { return nil, 0 }, + nil, + nil, + true, + }, + { + "bad optional", + func(_ BadOptional) int { return 0 }, + nil, + nil, + true, + }, + { + "variadic", + func(...float64) int { return 0 }, + nil, + nil, + true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := container.ExtractProviderDescriptor(tt.ctr) + if (err != nil) != tt.wantErr { + t.Errorf("ExtractProviderDescriptor() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got.Inputs, tt.wantIn) { + t.Errorf("ExtractProviderDescriptor() got = %v, want %v", got.Inputs, tt.wantIn) + } + if !reflect.DeepEqual(got.Outputs, tt.wantOut) { + t.Errorf("ExtractProviderDescriptor() got = %v, want %v", got.Outputs, tt.wantOut) + } + }) + } +} diff --git a/container/resolver.go b/container/resolver.go new file mode 100644 index 000000000000..4549f6ba3ee6 --- /dev/null +++ b/container/resolver.go @@ -0,0 +1,14 @@ +package container + +import ( + "reflect" + + "github.com/goccy/go-graphviz/cgraph" +) + +type resolver interface { + addNode(*simpleProvider, int) error + resolve(*container, Scope, Location) (reflect.Value, error) + describeLocation() string + typeGraphNode() *cgraph.Node +} diff --git a/container/run.go b/container/run.go index 9c410b76a242..0e680d45fbee 100644 --- a/container/run.go +++ b/container/run.go @@ -1,7 +1,5 @@ package container -import "fmt" - // Run runs the provided invoker function with values provided by the provided // options. It is the single entry point for building and running a dependency // injection container. Invoker should be a function taking one or more @@ -10,5 +8,29 @@ import "fmt" // Ex: // Run(func (x int) error { println(x) }, Provide(func() int { return 1 })) func Run(invoker interface{}, opts ...Option) error { - return fmt.Errorf("not implemented") + opt := Options(opts...) + + cfg, err := newConfig() + if err != nil { + return err + } + + defer cfg.generateGraph() // always generate graph on exit + + err = opt.applyConfig(cfg) + if err != nil { + return err + } + + cfg.logf("Registering providers") + cfg.indentLogger() + ctr := newContainer(cfg) + err = opt.applyContainer(ctr) + if err != nil { + cfg.logf("Failed registering providers because of: %+v", err) + return err + } + cfg.dedentLogger() + + return ctr.run(invoker) } diff --git a/container/scope.go b/container/scope.go index f854201ef61f..52a087e50717 100644 --- a/container/scope.go +++ b/container/scope.go @@ -1,14 +1,18 @@ package container +import ( + "reflect" +) + // Scope is a special type used to define a provider scope. // // Special scoped constructors can be used with Provide by declaring a -// constructor with its first input parameter of type Scope. These constructors +// constructor with an input parameter of type Scope. These constructors // should construct an unique value for each dependency based on scope and will // be called at most once per scope. // // Constructors passed to ProvideWithScope can also declare an input parameter -// of type Scope to retrieve their scope. +// of type Scope to retrieve their scope but these constructors will be called at most once. type Scope interface { isScope() @@ -18,7 +22,7 @@ type Scope interface { // NewScope creates a new scope with the provided name. Only one scope with a // given name can be created per container. -func NewScope(name string) Scope { +func newScope(name string) Scope { return &scope{name: name} } @@ -26,8 +30,12 @@ type scope struct { name string } -func (s *scope) isScope() {} - func (s *scope) Name() string { return s.name } + +func (s *scope) isScope() {} + +var scopeType = reflect.TypeOf((*Scope)(nil)).Elem() + +var stringType = reflect.TypeOf("") diff --git a/container/scope_dep.go b/container/scope_dep.go new file mode 100644 index 000000000000..e13658140351 --- /dev/null +++ b/container/scope_dep.go @@ -0,0 +1,57 @@ +package container + +import ( + "reflect" + + "github.com/goccy/go-graphviz/cgraph" +) + +type scopeDepProvider struct { + provider *ProviderDescriptor + calledForScope map[Scope]bool + valueMap map[Scope][]reflect.Value +} + +type scopeDepResolver struct { + typ reflect.Type + idxInValues int + node *scopeDepProvider + valueMap map[Scope]reflect.Value + graphNode *cgraph.Node +} + +func (s scopeDepResolver) describeLocation() string { + return s.node.provider.Location.String() +} + +func (s scopeDepResolver) resolve(ctr *container, scope Scope, caller Location) (reflect.Value, error) { + // Log + ctr.logf("Providing %v from %s to %s", s.typ, s.node.provider.Location, caller.Name()) + + // Resolve + if val, ok := s.valueMap[scope]; ok { + return val, nil + } + + if !s.node.calledForScope[scope] { + values, err := ctr.call(s.node.provider, scope) + if err != nil { + return reflect.Value{}, err + } + + s.node.valueMap[scope] = values + s.node.calledForScope[scope] = true + } + + value := s.node.valueMap[scope][s.idxInValues] + s.valueMap[scope] = value + return value, nil +} + +func (s scopeDepResolver) addNode(p *simpleProvider, _ int) error { + return duplicateDefinitionError(s.typ, p.provider.Location, s.node.provider.Location.String()) +} + +func (s scopeDepResolver) typeGraphNode() *cgraph.Node { + return s.graphNode +} diff --git a/container/simple.go b/container/simple.go new file mode 100644 index 000000000000..61bc3780a832 --- /dev/null +++ b/container/simple.go @@ -0,0 +1,67 @@ +package container + +import ( + "reflect" + + "github.com/goccy/go-graphviz/cgraph" +) + +type simpleProvider struct { + provider *ProviderDescriptor + called bool + values []reflect.Value + scope Scope +} + +type simpleResolver struct { + node *simpleProvider + idxInValues int + resolved bool + typ reflect.Type + value reflect.Value + graphNode *cgraph.Node +} + +func (s *simpleResolver) describeLocation() string { + return s.node.provider.Location.String() +} + +func (s *simpleProvider) resolveValues(ctr *container) ([]reflect.Value, error) { + if !s.called { + values, err := ctr.call(s.provider, s.scope) + if err != nil { + return nil, err + } + s.values = values + s.called = true + } + + return s.values, nil +} + +func (s *simpleResolver) resolve(c *container, _ Scope, caller Location) (reflect.Value, error) { + // Log + c.logf("Providing %v from %s to %s", s.typ, s.node.provider.Location, caller.Name()) + + // Resolve + if !s.resolved { + values, err := s.node.resolveValues(c) + if err != nil { + return reflect.Value{}, err + } + + value := values[s.idxInValues] + s.value = value + s.resolved = true + } + + return s.value, nil +} + +func (s simpleResolver) addNode(p *simpleProvider, _ int) error { + return duplicateDefinitionError(s.typ, p.provider.Location, s.node.provider.Location.String()) +} + +func (s simpleResolver) typeGraphNode() *cgraph.Node { + return s.graphNode +} diff --git a/container/struct_args.go b/container/struct_args.go index 8c1ae72e8270..49df400c4066 100644 --- a/container/struct_args.go +++ b/container/struct_args.go @@ -1,11 +1,184 @@ package container -// StructArgs is a type which can be embedded in another struct to alert the -// container that the fields of the struct are dependency inputs/outputs. That -// is, the container will not look to resolve a value with StructArgs embedded -// directly, but will instead use the struct's fields to resolve or populate -// dependencies. Types with embedded StructArgs can be used in both the input -// and output parameter positions. -type StructArgs struct{} - -func (StructArgs) isStructArgs() {} +import ( + "reflect" + + "github.com/pkg/errors" +) + +// In can be embedded in another struct to inform the container that the +// fields of the struct should be treated as dependency inputs. +// This allows a struct to be used to specify dependencies rather than +// positional parameters. +// +// Fields of the struct may support the following tags: +// optional if set to true, the dependency is optional and will +// be set to its default value if not found, rather than causing +// an error +type In struct{} + +func (In) isIn() {} + +type isIn interface{ isIn() } + +var isInType = reflect.TypeOf((*isIn)(nil)).Elem() + +// Out can be embedded in another struct to inform the container that the +// fields of the struct should be treated as dependency outputs. +// This allows a struct to be used to specify outputs rather than +// positional return values. +type Out struct{} + +func (Out) isOut() {} + +type isOut interface{ isOut() } + +var isOutType = reflect.TypeOf((*isOut)(nil)).Elem() + +func expandStructArgsConstructor(constructor ProviderDescriptor) (ProviderDescriptor, error) { + var foundStructArgs bool + var newIn []ProviderInput + + for _, in := range constructor.Inputs { + if in.Type.AssignableTo(isInType) { + foundStructArgs = true + inTypes, err := structArgsInTypes(in.Type) + if err != nil { + return ProviderDescriptor{}, err + } + newIn = append(newIn, inTypes...) + } else { + newIn = append(newIn, in) + } + } + + var newOut []ProviderOutput + for _, out := range constructor.Outputs { + if out.Type.AssignableTo(isOutType) { + foundStructArgs = true + newOut = append(newOut, structArgsOutTypes(out.Type)...) + } else { + newOut = append(newOut, out) + } + } + + if foundStructArgs { + return ProviderDescriptor{ + Inputs: newIn, + Outputs: newOut, + Fn: expandStructArgsFn(constructor), + Location: constructor.Location, + }, nil + } + + return constructor, nil +} + +func expandStructArgsFn(constructor ProviderDescriptor) func(inputs []reflect.Value) ([]reflect.Value, error) { + fn := constructor.Fn + inParams := constructor.Inputs + outParams := constructor.Outputs + return func(inputs []reflect.Value) ([]reflect.Value, error) { + j := 0 + inputs1 := make([]reflect.Value, len(inParams)) + for i, in := range inParams { + if in.Type.AssignableTo(isInType) { + v, n := buildIn(in.Type, inputs[j:]) + inputs1[i] = v + j += n + } else { + inputs1[i] = inputs[j] + j++ + } + } + + outputs, err := fn(inputs1) + if err != nil { + return nil, err + } + + var outputs1 []reflect.Value + for i, out := range outParams { + if out.Type.AssignableTo(isOutType) { + outputs1 = append(outputs1, extractFromOut(out.Type, outputs[i])...) + } else { + outputs1 = append(outputs1, outputs[i]) + } + } + + return outputs1, nil + } +} + +func structArgsInTypes(typ reflect.Type) ([]ProviderInput, error) { + n := typ.NumField() + var res []ProviderInput + for i := 0; i < n; i++ { + f := typ.Field(i) + if f.Type.AssignableTo(isInType) { + continue + } + + var optional bool + optTag, found := f.Tag.Lookup("optional") + if found { + if optTag == "true" { + optional = true + } else { + return nil, errors.Errorf("bad optional tag %q (should be \"true\") in %v", optTag, typ) + } + } + + res = append(res, ProviderInput{ + Type: f.Type, + Optional: optional, + }) + } + return res, nil +} + +func structArgsOutTypes(typ reflect.Type) []ProviderOutput { + n := typ.NumField() + var res []ProviderOutput + for i := 0; i < n; i++ { + f := typ.Field(i) + if f.Type.AssignableTo(isOutType) { + continue + } + + res = append(res, ProviderOutput{ + Type: f.Type, + }) + } + return res +} + +func buildIn(typ reflect.Type, values []reflect.Value) (reflect.Value, int) { + numFields := typ.NumField() + j := 0 + res := reflect.New(typ) + for i := 0; i < numFields; i++ { + f := typ.Field(i) + if f.Type.AssignableTo(isInType) { + continue + } + + res.Elem().Field(i).Set(values[j]) + j++ + } + return res.Elem(), j +} + +func extractFromOut(typ reflect.Type, value reflect.Value) []reflect.Value { + numFields := typ.NumField() + var res []reflect.Value + for i := 0; i < numFields; i++ { + f := typ.Field(i) + if f.Type.AssignableTo(isOutType) { + continue + } + + res = append(res, value.Field(i)) + } + return res +} diff --git a/container/supply.go b/container/supply.go new file mode 100644 index 000000000000..eec99f0c9957 --- /dev/null +++ b/container/supply.go @@ -0,0 +1,31 @@ +package container + +import ( + "reflect" + + "github.com/goccy/go-graphviz/cgraph" +) + +type supplyResolver struct { + typ reflect.Type + value reflect.Value + loc Location + graphNode *cgraph.Node +} + +func (s supplyResolver) describeLocation() string { + return s.loc.String() +} + +func (s supplyResolver) addNode(provider *simpleProvider, _ int) error { + return duplicateDefinitionError(s.typ, provider.provider.Location, s.loc.String()) +} + +func (s supplyResolver) resolve(c *container, _ Scope, caller Location) (reflect.Value, error) { + c.logf("Supplying %v from %s to %s", s.typ, s.loc, caller.Name()) + return s.value, nil +} + +func (s supplyResolver) typeGraphNode() *cgraph.Node { + return s.graphNode +} diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 00aad2bd00b7..312c5d2d7740 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -665,7 +665,6 @@ - [ModeInfo.Single](#cosmos.tx.v1beta1.ModeInfo.Single) - [SignDoc](#cosmos.tx.v1beta1.SignDoc) - [SignDocDirectAux](#cosmos.tx.v1beta1.SignDocDirectAux) - - [SignDocJSON](#cosmos.tx.v1beta1.SignDocJSON) - [SignerInfo](#cosmos.tx.v1beta1.SignerInfo) - [Tip](#cosmos.tx.v1beta1.Tip) - [Tx](#cosmos.tx.v1beta1.Tx) @@ -9365,9 +9364,8 @@ SignMode represents a signing mode with its own security guarantees. | SIGN_MODE_UNSPECIFIED | 0 | SIGN_MODE_UNSPECIFIED specifies an unknown signing mode and will be rejected. | | SIGN_MODE_DIRECT | 1 | SIGN_MODE_DIRECT specifies a signing mode which uses SignDoc and is verified with raw bytes from Tx. | | SIGN_MODE_TEXTUAL | 2 | SIGN_MODE_TEXTUAL is a future signing mode that will verify some human-readable textual representation on top of the binary representation from SIGN_MODE_DIRECT. It is currently not supported. | -| SIGN_MODE_DIRECT_JSON | 3 | SIGN_MODE_DIRECT_JSON specifies a signing mode which uses SignDocJSON. It is verified using a canonical JSON representation of the bytes used in SIGN_MODE_DIRECT. It is currently not supported. | -| SIGN_MODE_DIRECT_AUX | 4 | SIGN_MODE_DIRECT_AUX specifies a signing mode which uses SignDocDirectAux. As opposed to SIGN_MODE_DIRECT, this sign mode does not require signers signing over other signers' `signer_info`. It also allows for adding Tips in transactions. | -| SIGN_MODE_AMINO_AUX | 5 | SIGN_MODE_AMINO_AUX specifies a signing mode which uses SignDocAminoAux. | +| SIGN_MODE_DIRECT_AUX | 3 | SIGN_MODE_DIRECT_AUX specifies a signing mode which uses SignDocDirectAux. As opposed to SIGN_MODE_DIRECT, this sign mode does not require signers signing over other signers' `signer_info`. It also allows for adding Tips in transactions. | +| SIGN_MODE_AMINO_AUX | 4 | SIGN_MODE_AMINO_AUX specifies a signing mode which uses SignDocAminoAux. | | SIGN_MODE_LEGACY_AMINO_JSON | 127 | SIGN_MODE_LEGACY_AMINO_JSON is a backwards compatibility mode which uses Amino JSON and will be removed in the future. | @@ -9512,28 +9510,6 @@ SIGN_MODE_DIRECT_AUX. - - -### SignDocJSON -SignDocJSON is the type used for generating sign bytes for -SIGN_MODE_DIRECT_JSON. It is designed to be serialized as proto3 JSON -following the rules defined here: -https://github.com/regen-network/canonical-proto3/blob/master/README.md#json. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `body` | [TxBody](#cosmos.tx.v1beta1.TxBody) | | body is the processable content of the transaction | -| `auth_info` | [AuthInfo](#cosmos.tx.v1beta1.AuthInfo) | | auth_info is the authorization related content of the transaction, specifically signers, signer modes and fee | -| `chain_id` | [string](#string) | | chain_id is the identifier of the chain this transaction targets. It prevents signed transactions from being used on another chain by an attacker | -| `account_number` | [uint64](#uint64) | | account_number is the account number of the signing account in state | -| `sign_doc_sha256_hash` | [bytes](#bytes) | | sign_doc_sha256_hash is the SHA-256 hash of SignDoc. It is included here to reduce the malleability attack surface of SIGN_MODE_DIRECT_JSON vs SIGN_MODE_DIRECT to zero. Basically this means that any discrepancy between protobuf bytes over the wire and protobuf bytes that are signed cannot be exploited. This information is obviously redundant with information already in SignDocJSON, but is included as a security check for scenarios where this information may have inadvertently been excluded. We include the hash of SignDoc rather than the full SignDoc bytes to reduce the size of SignDocJSON for scenarios where large payloads could cause problems for hardware wallets. | - - - - - - ### SignerInfo diff --git a/proto/cosmos/tx/signing/v1beta1/signing.proto b/proto/cosmos/tx/signing/v1beta1/signing.proto index fd494dfffeb9..0a13282ac0b3 100644 --- a/proto/cosmos/tx/signing/v1beta1/signing.proto +++ b/proto/cosmos/tx/signing/v1beta1/signing.proto @@ -21,20 +21,15 @@ enum SignMode { // from SIGN_MODE_DIRECT. It is currently not supported. SIGN_MODE_TEXTUAL = 2; - // SIGN_MODE_DIRECT_JSON specifies a signing mode which uses SignDocJSON. It - // is verified using a canonical JSON representation of the bytes used in - // SIGN_MODE_DIRECT. It is currently not supported. - SIGN_MODE_DIRECT_JSON = 3; - // SIGN_MODE_DIRECT_AUX specifies a signing mode which uses // SignDocDirectAux. As opposed to SIGN_MODE_DIRECT, this sign mode does not // require signers signing over other signers' `signer_info`. It also allows // for adding Tips in transactions. - SIGN_MODE_DIRECT_AUX = 4; + SIGN_MODE_DIRECT_AUX = 3; // SIGN_MODE_AMINO_AUX specifies a signing mode which uses // SignDocAminoAux. - SIGN_MODE_AMINO_AUX = 5; + SIGN_MODE_AMINO_AUX = 4; // SIGN_MODE_LEGACY_AMINO_JSON is a backwards compatibility mode which uses // Amino JSON and will be removed in the future. diff --git a/proto/cosmos/tx/v1beta1/tx.proto b/proto/cosmos/tx/v1beta1/tx.proto index d2588c62467a..f26c02051ff6 100644 --- a/proto/cosmos/tx/v1beta1/tx.proto +++ b/proto/cosmos/tx/v1beta1/tx.proto @@ -64,39 +64,6 @@ message SignDoc { uint64 account_number = 4; } -// SignDocJSON is the type used for generating sign bytes for -// SIGN_MODE_DIRECT_JSON. It is designed to be serialized as proto3 JSON -// following the rules defined here: -// https://github.com/regen-network/canonical-proto3/blob/master/README.md#json. -message SignDocJSON { - // body is the processable content of the transaction - TxBody body = 1; - - // auth_info is the authorization related content of the transaction, - // specifically signers, signer modes and fee - AuthInfo auth_info = 2; - - // chain_id is the identifier of the chain this transaction targets. - // It prevents signed transactions from being used on another chain by an - // attacker - string chain_id = 3; - - // account_number is the account number of the signing account in state - uint64 account_number = 4; - - // sign_doc_sha256_hash is the SHA-256 hash of SignDoc. It is included here to - // reduce the malleability attack surface of SIGN_MODE_DIRECT_JSON vs - // SIGN_MODE_DIRECT to zero. Basically this means that any discrepancy between - // protobuf bytes over the wire and protobuf bytes that are signed cannot be - // exploited. This information is obviously redundant with information already - // in SignDocJSON, but is included as a security check for scenarios where - // this information may have inadvertently been excluded. We include the hash - // of SignDoc rather than the full SignDoc bytes to reduce the size of - // SignDocJSON for scenarios where large payloads could cause problems for - // hardware wallets. - bytes sign_doc_sha256_hash = 5; -} - // SignDocDirectAux is the type used for generating sign bytes for // SIGN_MODE_DIRECT_AUX. message SignDocDirectAux { diff --git a/server/export_test.go b/server/export_test.go index c41d60f027e8..32410a82426d 100644 --- a/server/export_test.go +++ b/server/export_test.go @@ -3,7 +3,6 @@ package server_test import ( "bytes" "context" - "encoding/json" "fmt" "io" "os" @@ -22,7 +21,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/simapp" @@ -123,6 +121,8 @@ func TestExportCmd_Height(t *testing.T) { } func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *tmtypes.GenesisDoc, *cobra.Command) { + t.Helper() + if err := createConfigFolder(tempDir); err != nil { t.Fatalf("error creating config folder: %s", err) } @@ -132,11 +132,18 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *t encCfg := simapp.MakeTestEncodingConfig() app := simapp.NewSimApp(logger, db, nil, true, map[int64]bool{}, tempDir, 0, encCfg, simapp.EmptyAppOptions{}) + genesisState := simapp.GenesisStateWithSingleValidator(t, app) + stateBytes, err := tmjson.MarshalIndent(genesisState, "", " ") + require.NoError(t, err) + serverCtx := server.NewDefaultContext() serverCtx.Config.RootDir = tempDir clientCtx := client.Context{}.WithCodec(app.AppCodec()) - genDoc := newDefaultGenesisDoc(encCfg.Codec) + genDoc := &tmtypes.GenesisDoc{} + genDoc.ChainID = "theChainId" + genDoc.Validators = nil + genDoc.AppState = stateBytes require.NoError(t, saveGenesisFile(genDoc, serverCtx.Config.GenesisFile())) app.InitChain( @@ -177,22 +184,6 @@ func createConfigFolder(dir string) error { return os.Mkdir(path.Join(dir, "config"), 0700) } -func newDefaultGenesisDoc(cdc codec.Codec) *tmtypes.GenesisDoc { - genesisState := simapp.NewDefaultGenesisState(cdc) - - stateBytes, err := json.MarshalIndent(genesisState, "", " ") - if err != nil { - panic(err) - } - - genDoc := &tmtypes.GenesisDoc{} - genDoc.ChainID = "theChainId" - genDoc.Validators = nil - genDoc.AppState = stateBytes - - return genDoc -} - func saveGenesisFile(genDoc *tmtypes.GenesisDoc, dir string) error { err := genutil.ExportGenesisFile(genDoc, dir) if err != nil { diff --git a/server/mock/app.go b/server/mock/app.go index d5f7c911c252..779b9c5c320c 100644 --- a/server/mock/app.go +++ b/server/mock/app.go @@ -6,14 +6,14 @@ import ( "fmt" "path/filepath" - "github.com/tendermint/tendermint/types" - abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" + "github.com/tendermint/tendermint/types" bam "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/simapp" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx" "github.com/cosmos/cosmos-sdk/x/auth/middleware" @@ -72,7 +72,7 @@ func NewApp(rootDir string, logger log.Logger) (abci.Application, error) { // KVStoreHandler is a simple handler that takes kvstoreTx and writes // them to the db -func KVStoreHandler(storeKey sdk.StoreKey) sdk.Handler { +func KVStoreHandler(storeKey storetypes.StoreKey) sdk.Handler { return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { dTx, ok := msg.(kvstoreTx) if !ok { @@ -105,7 +105,7 @@ type GenesisJSON struct { // InitChainer returns a function that can initialize the chain // with key/value pairs -func InitChainer(key sdk.StoreKey) func(sdk.Context, abci.RequestInitChain) abci.ResponseInitChain { +func InitChainer(key storetypes.StoreKey) func(sdk.Context, abci.RequestInitChain) abci.ResponseInitChain { return func(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { stateJSON := req.AppStateBytes diff --git a/server/mock/store.go b/server/mock/store.go index 33f573518c19..91596337f964 100644 --- a/server/mock/store.go +++ b/server/mock/store.go @@ -5,14 +5,14 @@ import ( dbm "github.com/tendermint/tm-db" - store "github.com/cosmos/cosmos-sdk/store/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" ) var _ sdk.MultiStore = multiStore{} type multiStore struct { - kv map[sdk.StoreKey]kvStore + kv map[storetypes.StoreKey]kvStore } func (ms multiStore) CacheMultiStore() sdk.CacheMultiStore { @@ -23,15 +23,15 @@ func (ms multiStore) CacheMultiStoreWithVersion(_ int64) (sdk.CacheMultiStore, e panic("not implemented") } -func (ms multiStore) CacheWrap() sdk.CacheWrap { +func (ms multiStore) CacheWrap() storetypes.CacheWrap { panic("not implemented") } -func (ms multiStore) CacheWrapWithTrace(_ io.Writer, _ sdk.TraceContext) sdk.CacheWrap { +func (ms multiStore) CacheWrapWithTrace(_ io.Writer, _ sdk.TraceContext) storetypes.CacheWrap { panic("not implemented") } -func (ms multiStore) CacheWrapWithListeners(_ store.StoreKey, _ []store.WriteListener) store.CacheWrap { +func (ms multiStore) CacheWrapWithListeners(_ storetypes.StoreKey, _ []storetypes.WriteListener) storetypes.CacheWrap { panic("not implemented") } @@ -47,19 +47,19 @@ func (ms multiStore) SetTracer(w io.Writer) sdk.MultiStore { panic("not implemented") } -func (ms multiStore) AddListeners(key store.StoreKey, listeners []store.WriteListener) { +func (ms multiStore) AddListeners(key storetypes.StoreKey, listeners []storetypes.WriteListener) { panic("not implemented") } -func (ms multiStore) ListeningEnabled(key store.StoreKey) bool { +func (ms multiStore) ListeningEnabled(key storetypes.StoreKey) bool { panic("not implemented") } -func (ms multiStore) Commit() sdk.CommitID { +func (ms multiStore) Commit() storetypes.CommitID { panic("not implemented") } -func (ms multiStore) LastCommitID() sdk.CommitID { +func (ms multiStore) LastCommitID() storetypes.CommitID { panic("not implemented") } @@ -71,15 +71,15 @@ func (ms multiStore) GetPruning() sdk.PruningOptions { panic("not implemented") } -func (ms multiStore) GetCommitKVStore(key sdk.StoreKey) sdk.CommitKVStore { +func (ms multiStore) GetCommitKVStore(key storetypes.StoreKey) storetypes.CommitKVStore { panic("not implemented") } -func (ms multiStore) GetCommitStore(key sdk.StoreKey) sdk.CommitStore { +func (ms multiStore) GetCommitStore(key storetypes.StoreKey) storetypes.CommitStore { panic("not implemented") } -func (ms multiStore) MountStoreWithDB(key sdk.StoreKey, typ sdk.StoreType, db dbm.DB) { +func (ms multiStore) MountStoreWithDB(key storetypes.StoreKey, typ storetypes.StoreType, db dbm.DB) { ms.kv[key] = kvStore{store: make(map[string][]byte)} } @@ -87,11 +87,11 @@ func (ms multiStore) LoadLatestVersion() error { return nil } -func (ms multiStore) LoadLatestVersionAndUpgrade(upgrades *store.StoreUpgrades) error { +func (ms multiStore) LoadLatestVersionAndUpgrade(upgrades *storetypes.StoreUpgrades) error { return nil } -func (ms multiStore) LoadVersionAndUpgrade(ver int64, upgrades *store.StoreUpgrades) error { +func (ms multiStore) LoadVersionAndUpgrade(ver int64, upgrades *storetypes.StoreUpgrades) error { panic("not implemented") } @@ -99,15 +99,15 @@ func (ms multiStore) LoadVersion(ver int64) error { panic("not implemented") } -func (ms multiStore) GetKVStore(key sdk.StoreKey) sdk.KVStore { +func (ms multiStore) GetKVStore(key storetypes.StoreKey) sdk.KVStore { return ms.kv[key] } -func (ms multiStore) GetStore(key sdk.StoreKey) sdk.Store { +func (ms multiStore) GetStore(key storetypes.StoreKey) sdk.Store { panic("not implemented") } -func (ms multiStore) GetStoreType() sdk.StoreType { +func (ms multiStore) GetStoreType() storetypes.StoreType { panic("not implemented") } @@ -135,19 +135,19 @@ type kvStore struct { store map[string][]byte } -func (kv kvStore) CacheWrap() sdk.CacheWrap { +func (kv kvStore) CacheWrap() storetypes.CacheWrap { panic("not implemented") } -func (kv kvStore) CacheWrapWithTrace(w io.Writer, tc sdk.TraceContext) sdk.CacheWrap { +func (kv kvStore) CacheWrapWithTrace(w io.Writer, tc sdk.TraceContext) storetypes.CacheWrap { panic("not implemented") } -func (kv kvStore) CacheWrapWithListeners(_ store.StoreKey, _ []store.WriteListener) store.CacheWrap { +func (kv kvStore) CacheWrapWithListeners(_ storetypes.StoreKey, _ []storetypes.WriteListener) storetypes.CacheWrap { panic("not implemented") } -func (kv kvStore) GetStoreType() sdk.StoreType { +func (kv kvStore) GetStoreType() storetypes.StoreType { panic("not implemented") } @@ -165,7 +165,7 @@ func (kv kvStore) Has(key []byte) bool { } func (kv kvStore) Set(key, value []byte) { - store.AssertValidKey(key) + storetypes.AssertValidKey(key) kv.store[string(key)] = value } @@ -198,5 +198,5 @@ func (kv kvStore) ReverseSubspaceIterator(prefix []byte) sdk.Iterator { } func NewCommitMultiStore() sdk.CommitMultiStore { - return multiStore{kv: make(map[sdk.StoreKey]kvStore)} + return multiStore{kv: make(map[storetypes.StoreKey]kvStore)} } diff --git a/server/mock/store_test.go b/server/mock/store_test.go index b945cd30599f..fc5cd12e097e 100644 --- a/server/mock/store_test.go +++ b/server/mock/store_test.go @@ -4,9 +4,9 @@ import ( "testing" "github.com/stretchr/testify/require" - dbm "github.com/tendermint/tm-db" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -15,7 +15,7 @@ func TestStore(t *testing.T) { cms := NewCommitMultiStore() key := sdk.NewKVStoreKey("test") - cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db) + cms.MountStoreWithDB(key, storetypes.StoreTypeIAVL, db) err := cms.LoadLatestVersion() require.Nil(t, err) diff --git a/simapp/app.go b/simapp/app.go index b3323ec076f4..ebddd0b62046 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -42,6 +42,7 @@ import ( capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" authmiddleware "github.com/cosmos/cosmos-sdk/x/auth/middleware" "github.com/cosmos/cosmos-sdk/x/authz" authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" @@ -147,9 +148,9 @@ type SimApp struct { invCheckPeriod uint // keys to access the substores - keys map[string]*sdk.KVStoreKey - tkeys map[string]*sdk.TransientStoreKey - memKeys map[string]*sdk.MemoryStoreKey + keys map[string]*storetypes.KVStoreKey + tkeys map[string]*storetypes.TransientStoreKey + memKeys map[string]*storetypes.MemoryStoreKey // keepers AccountKeeper authkeeper.AccountKeeper @@ -484,21 +485,21 @@ func (app *SimApp) InterfaceRegistry() types.InterfaceRegistry { // GetKey returns the KVStoreKey for the provided store key. // // NOTE: This is solely to be used for testing purposes. -func (app *SimApp) GetKey(storeKey string) *sdk.KVStoreKey { +func (app *SimApp) GetKey(storeKey string) *storetypes.KVStoreKey { return app.keys[storeKey] } // GetTKey returns the TransientStoreKey for the provided store key. // // NOTE: This is solely to be used for testing purposes. -func (app *SimApp) GetTKey(storeKey string) *sdk.TransientStoreKey { +func (app *SimApp) GetTKey(storeKey string) *storetypes.TransientStoreKey { return app.tkeys[storeKey] } // GetMemKey returns the MemStoreKey for the provided mem key. // // NOTE: This is solely used for testing purposes. -func (app *SimApp) GetMemKey(storeKey string) *sdk.MemoryStoreKey { +func (app *SimApp) GetMemKey(storeKey string) *storetypes.MemoryStoreKey { return app.memKeys[storeKey] } @@ -565,7 +566,7 @@ func GetMaccPerms() map[string][]string { } // initParamsKeeper init params keeper and its subspaces -func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey sdk.StoreKey) paramskeeper.Keeper { +func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey storetypes.StoreKey) paramskeeper.Keeper { paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey) paramsKeeper.Subspace(authtypes.ModuleName) diff --git a/simapp/sim_test.go b/simapp/sim_test.go index b31efd8aa53c..26b1252086aa 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -5,8 +5,11 @@ import ( "fmt" "math/rand" "os" + "runtime/debug" + "strings" "testing" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" @@ -38,8 +41,8 @@ func init() { } type StoreKeysPrefixes struct { - A sdk.StoreKey - B sdk.StoreKey + A storetypes.StoreKey + B storetypes.StoreKey Prefixes [][]byte } @@ -152,6 +155,17 @@ func TestAppImportExport(t *testing.T) { err = json.Unmarshal(exported.AppState, &genesisState) require.NoError(t, err) + defer func() { + if r := recover(); r != nil { + err := fmt.Sprintf("%v", r) + if !strings.Contains(err, "validator set is empty after InitGenesis") { + panic(r) + } + logger.Info("Skipping simulation as all validators have been unbonded") + logger.Info("err", err, "stacktrace", string(debug.Stack())) + } + }() + ctxA := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) ctxB := newApp.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) newApp.mm.InitGenesis(ctxB, app.AppCodec(), genesisState) diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 58e365aed655..bf6476676d32 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -121,22 +121,24 @@ func NewSimappWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOptio func Setup(t *testing.T, isCheckTx bool) *SimApp { t.Helper() - app, genesisState := setup(!isCheckTx, 5) - if !isCheckTx { - // init chain must be called to stop deliverState from being nil - stateBytes, err := json.MarshalIndent(genesisState, "", " ") - require.NoError(t, err) + privVal := mock.NewPV() + pubKey, err := privVal.GetPubKey() + require.NoError(t, err) - // Initialize the chain - app.InitChain( - abci.RequestInitChain{ - Validators: []abci.ValidatorUpdate{}, - ConsensusParams: DefaultConsensusParams, - AppStateBytes: stateBytes, - }, - ) + // create validator set with single validator + validator := tmtypes.NewValidator(pubKey, 1) + valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator}) + + // generate genesis account + senderPrivKey := secp256k1.GenPrivKey() + acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0) + balance := banktypes.Balance{ + Address: acc.GetAddress().String(), + Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))), } + app := SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, balance) + return app } @@ -181,8 +183,13 @@ func genesisStateWithValSet(t *testing.T, totalSupply := sdk.NewCoins() for _, b := range balances { - // add genesis acc tokens and delegated tokens to total supply - totalSupply = totalSupply.Add(b.Coins.Add(sdk.NewCoin(sdk.DefaultBondDenom, bondAmt))...) + // add genesis acc tokens to total supply + totalSupply = totalSupply.Add(b.Coins...) + } + + for range delegations { + // add delegated tokens to total supply + totalSupply = totalSupply.Add(sdk.NewCoin(sdk.DefaultBondDenom, bondAmt)) } // add bonded amount to bonded pool module account @@ -237,33 +244,44 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs func SetupWithGenesisAccounts(t *testing.T, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *SimApp { t.Helper() - app, genesisState := setup(true, 0) - authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs) - genesisState[authtypes.ModuleName] = app.AppCodec().MustMarshalJSON(authGenesis) + privVal := mock.NewPV() + pubKey, err := privVal.GetPubKey() + require.NoError(t, err) - totalSupply := sdk.NewCoins() - for _, b := range balances { - totalSupply = totalSupply.Add(b.Coins...) - } + // create validator set with single validator + validator := tmtypes.NewValidator(pubKey, 1) + valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator}) - bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{}) - genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenesis) + return SetupWithGenesisValSet(t, valSet, genAccs, balances...) +} - stateBytes, err := json.MarshalIndent(genesisState, "", " ") +// SetupWithGenesisValSet initializes GenesisState with a single validator and genesis accounts +// that also act as delegators. +func GenesisStateWithSingleValidator(t *testing.T, app *SimApp) GenesisState { + t.Helper() + + privVal := mock.NewPV() + pubKey, err := privVal.GetPubKey() require.NoError(t, err) - app.InitChain( - abci.RequestInitChain{ - Validators: []abci.ValidatorUpdate{}, - ConsensusParams: DefaultConsensusParams, - AppStateBytes: stateBytes, + // create validator set with single validator + validator := tmtypes.NewValidator(pubKey, 1) + valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator}) + + // generate genesis account + senderPrivKey := secp256k1.GenPrivKey() + acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0) + balances := []banktypes.Balance{ + { + Address: acc.GetAddress().String(), + Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))), }, - ) + } - app.Commit() - app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1}}) + genesisState := NewDefaultGenesisState(app.appCodec) + genesisState = genesisStateWithValSet(t, app, genesisState, valSet, []authtypes.GenesisAccount{acc}, balances...) - return app + return genesisState } type GenerateAccountStrategy func(int) []sdk.AccAddress diff --git a/testutil/context.go b/testutil/context.go index 2fb9865a2696..1addf17c287a 100644 --- a/testutil/context.go +++ b/testutil/context.go @@ -6,15 +6,16 @@ import ( dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/store" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" ) // DefaultContext creates a sdk.Context with a fresh MemDB that can be used in tests. -func DefaultContext(key sdk.StoreKey, tkey sdk.StoreKey) sdk.Context { +func DefaultContext(key storetypes.StoreKey, tkey storetypes.StoreKey) sdk.Context { db := dbm.NewMemDB() cms := store.NewCommitMultiStore(db) - cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db) - cms.MountStoreWithDB(tkey, sdk.StoreTypeTransient, db) + cms.MountStoreWithDB(key, storetypes.StoreTypeIAVL, db) + cms.MountStoreWithDB(tkey, storetypes.StoreTypeTransient, db) err := cms.LoadLatestVersion() if err != nil { panic(err) diff --git a/types/context.go b/types/context.go index 35030dad9a96..b802070a3b82 100644 --- a/types/context.go +++ b/types/context.go @@ -11,7 +11,7 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/store/gaskv" - stypes "github.com/cosmos/cosmos-sdk/store/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" ) /* @@ -87,7 +87,7 @@ func NewContext(ms MultiStore, header tmproto.Header, isCheckTx bool, logger log chainID: header.ChainID, checkTx: isCheckTx, logger: logger, - gasMeter: stypes.NewInfiniteGasMeter(), + gasMeter: storetypes.NewInfiniteGasMeter(), minGasPrice: DecCoins{}, eventManager: NewEventManager(), } @@ -243,13 +243,13 @@ func (c Context) Value(key interface{}) interface{} { // ---------------------------------------------------------------------------- // KVStore fetches a KVStore from the MultiStore. -func (c Context) KVStore(key StoreKey) KVStore { - return gaskv.NewStore(c.MultiStore().GetKVStore(key), c.GasMeter(), stypes.KVGasConfig()) +func (c Context) KVStore(key storetypes.StoreKey) KVStore { + return gaskv.NewStore(c.MultiStore().GetKVStore(key), c.GasMeter(), storetypes.KVGasConfig()) } // TransientStore fetches a TransientStore from the MultiStore. -func (c Context) TransientStore(key StoreKey) KVStore { - return gaskv.NewStore(c.MultiStore().GetKVStore(key), c.GasMeter(), stypes.TransientGasConfig()) +func (c Context) TransientStore(key storetypes.StoreKey) KVStore { + return gaskv.NewStore(c.MultiStore().GetKVStore(key), c.GasMeter(), storetypes.TransientGasConfig()) } // CacheContext returns a new Context with the multi-store cached and a new diff --git a/types/module/module.go b/types/module/module.go index 7341edf8e816..685a6dcd601b 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -30,6 +30,7 @@ package module import ( "encoding/json" + "fmt" "sort" "github.com/gorilla/mux" @@ -296,7 +297,9 @@ func (m *Manager) RegisterServices(cfg Configurator) { } } -// InitGenesis performs init genesis functionality for modules +// InitGenesis performs init genesis functionality for modules. Exactly one +// module must return a non-empty validator set update to correctly initialize +// the chain. func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, genesisData map[string]json.RawMessage) abci.ResponseInitChain { var validatorUpdates []abci.ValidatorUpdate ctx.Logger().Info("initializing blockchain state from genesis.json") @@ -318,6 +321,11 @@ func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, genesisData } } + // a chain must initialize with a non-empty validator set + if len(validatorUpdates) == 0 { + panic(fmt.Sprintf("validator set is empty after InitGenesis, please ensure at least one validator is initialized with a delegation greater than or equal to the DefaultPowerReduction (%d)", sdk.DefaultPowerReduction)) + } + return abci.ResponseInitChain{ Validators: validatorUpdates, } diff --git a/types/module/module_test.go b/types/module/module_test.go index 49f6bf0ad03e..4dbb4a73c5b6 100644 --- a/types/module/module_test.go +++ b/types/module/module_test.go @@ -206,8 +206,9 @@ func TestManager_InitGenesis(t *testing.T) { cdc := codec.NewProtoCodec(interfaceRegistry) genesisData := map[string]json.RawMessage{"module1": json.RawMessage(`{"key": "value"}`)} + // this should panic since the validator set is empty even after init genesis mockAppModule1.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(cdc), gomock.Eq(genesisData["module1"])).Times(1).Return(nil) - require.Equal(t, abci.ResponseInitChain{Validators: []abci.ValidatorUpdate(nil)}, mm.InitGenesis(ctx, cdc, genesisData)) + require.Panics(t, func() { mm.InitGenesis(ctx, cdc, genesisData) }) // test panic genesisData = map[string]json.RawMessage{ diff --git a/types/store.go b/types/store.go index 5fb34b5fae5d..b50f95d02a7a 100644 --- a/types/store.go +++ b/types/store.go @@ -58,32 +58,6 @@ func DiffKVStores(a KVStore, b KVStore, prefixesToSkip [][]byte) (kvAs, kvBs []k return types.DiffKVStores(a, b, prefixesToSkip) } -type ( - CacheKVStore = types.CacheKVStore - CommitKVStore = types.CommitKVStore - CacheWrap = types.CacheWrap - CacheWrapper = types.CacheWrapper - CommitID = types.CommitID -) - -type StoreType = types.StoreType - -const ( - StoreTypeMulti = types.StoreTypeMulti - StoreTypeDB = types.StoreTypeDB - StoreTypeIAVL = types.StoreTypeIAVL - StoreTypeTransient = types.StoreTypeTransient - StoreTypeMemory = types.StoreTypeMemory -) - -type ( - StoreKey = types.StoreKey - CapabilityKey = types.CapabilityKey - KVStoreKey = types.KVStoreKey - TransientStoreKey = types.TransientStoreKey - MemoryStoreKey = types.MemoryStoreKey -) - // assertNoCommonPrefix will panic if there are two keys: k1 and k2 in keys, such that // k1 is a prefix of k2 func assertNoPrefix(keys []string) { @@ -98,16 +72,16 @@ func assertNoPrefix(keys []string) { } // NewKVStoreKey returns a new pointer to a KVStoreKey. -func NewKVStoreKey(name string) *KVStoreKey { +func NewKVStoreKey(name string) *types.KVStoreKey { return types.NewKVStoreKey(name) } // NewKVStoreKeys returns a map of new pointers to KVStoreKey's. // The function will panic if there is a potential conflict in names (see `assertNoPrefix` // function for more details). -func NewKVStoreKeys(names ...string) map[string]*KVStoreKey { +func NewKVStoreKeys(names ...string) map[string]*types.KVStoreKey { assertNoPrefix(names) - keys := make(map[string]*KVStoreKey, len(names)) + keys := make(map[string]*types.KVStoreKey, len(names)) for _, n := range names { keys[n] = NewKVStoreKey(n) } @@ -117,7 +91,7 @@ func NewKVStoreKeys(names ...string) map[string]*KVStoreKey { // Constructs new TransientStoreKey // Must return a pointer according to the ocap principle -func NewTransientStoreKey(name string) *TransientStoreKey { +func NewTransientStoreKey(name string) *types.TransientStoreKey { return types.NewTransientStoreKey(name) } @@ -125,9 +99,9 @@ func NewTransientStoreKey(name string) *TransientStoreKey { // Must return pointers according to the ocap principle // The function will panic if there is a potential conflict in names (see `assertNoPrefix` // function for more details). -func NewTransientStoreKeys(names ...string) map[string]*TransientStoreKey { +func NewTransientStoreKeys(names ...string) map[string]*types.TransientStoreKey { assertNoPrefix(names) - keys := make(map[string]*TransientStoreKey) + keys := make(map[string]*types.TransientStoreKey) for _, n := range names { keys[n] = NewTransientStoreKey(n) } @@ -139,9 +113,9 @@ func NewTransientStoreKeys(names ...string) map[string]*TransientStoreKey { // respective MemoryStoreKey references. // The function will panic if there is a potential conflict in names (see `assertNoPrefix` // function for more details). -func NewMemoryStoreKeys(names ...string) map[string]*MemoryStoreKey { +func NewMemoryStoreKeys(names ...string) map[string]*types.MemoryStoreKey { assertNoPrefix(names) - keys := make(map[string]*MemoryStoreKey) + keys := make(map[string]*types.MemoryStoreKey) for _, n := range names { keys[n] = types.NewMemoryStoreKey(n) } diff --git a/types/store_internal_test.go b/types/store_internal_test.go index 0ed4db3ae48b..e55ae175dbdc 100644 --- a/types/store_internal_test.go +++ b/types/store_internal_test.go @@ -3,6 +3,7 @@ package types import ( "testing" + "github.com/cosmos/cosmos-sdk/store/types" "github.com/stretchr/testify/suite" ) @@ -47,7 +48,7 @@ func (s *storeIntSuite) TestNewKVStoreKeys() { require := s.Require() require.Panics(func() { NewKVStoreKeys("a1", "a") }, "should fail one key is a prefix of another one") - require.Equal(map[string]*KVStoreKey{}, NewKVStoreKeys()) + require.Equal(map[string]*types.KVStoreKey{}, NewKVStoreKeys()) require.Equal(1, len(NewKVStoreKeys("one"))) key := "baca" diff --git a/types/store_test.go b/types/store_test.go index 9c3ef2f79dd6..d2039f8cb896 100644 --- a/types/store_test.go +++ b/types/store_test.go @@ -44,10 +44,10 @@ func (s *storeTestSuite) TestPrefixEndBytes() { } func (s *storeTestSuite) TestCommitID() { - var empty sdk.CommitID + var empty types.CommitID s.Require().True(empty.IsZero()) - var nonempty = sdk.CommitID{ + var nonempty = types.CommitID{ Version: 1, Hash: []byte("testhash"), } @@ -55,7 +55,7 @@ func (s *storeTestSuite) TestCommitID() { } func (s *storeTestSuite) TestNewTransientStoreKeys() { - s.Require().Equal(map[string]*sdk.TransientStoreKey{}, sdk.NewTransientStoreKeys()) + s.Require().Equal(map[string]*types.TransientStoreKey{}, sdk.NewTransientStoreKeys()) s.Require().Equal(1, len(sdk.NewTransientStoreKeys("one"))) } diff --git a/types/tx/signing/signing.pb.go b/types/tx/signing/signing.pb.go index 7ef0489bf027..e5e1ec4770ea 100644 --- a/types/tx/signing/signing.pb.go +++ b/types/tx/signing/signing.pb.go @@ -38,18 +38,14 @@ const ( // human-readable textual representation on top of the binary representation // from SIGN_MODE_DIRECT. It is currently not supported. SignMode_SIGN_MODE_TEXTUAL SignMode = 2 - // SIGN_MODE_DIRECT_JSON specifies a signing mode which uses SignDocJSON. It - // is verified using a canonical JSON representation of the bytes used in - // SIGN_MODE_DIRECT. It is currently not supported. - SignMode_SIGN_MODE_DIRECT_JSON SignMode = 3 // SIGN_MODE_DIRECT_AUX specifies a signing mode which uses // SignDocDirectAux. As opposed to SIGN_MODE_DIRECT, this sign mode does not // require signers signing over other signers' `signer_info`. It also allows // for adding Tips in transactions. - SignMode_SIGN_MODE_DIRECT_AUX SignMode = 4 + SignMode_SIGN_MODE_DIRECT_AUX SignMode = 3 // SIGN_MODE_AMINO_AUX specifies a signing mode which uses // SignDocAminoAux. - SignMode_SIGN_MODE_AMINO_AUX SignMode = 5 + SignMode_SIGN_MODE_AMINO_AUX SignMode = 4 // SIGN_MODE_LEGACY_AMINO_JSON is a backwards compatibility mode which uses // Amino JSON and will be removed in the future. SignMode_SIGN_MODE_LEGACY_AMINO_JSON SignMode = 127 @@ -59,9 +55,8 @@ var SignMode_name = map[int32]string{ 0: "SIGN_MODE_UNSPECIFIED", 1: "SIGN_MODE_DIRECT", 2: "SIGN_MODE_TEXTUAL", - 3: "SIGN_MODE_DIRECT_JSON", - 4: "SIGN_MODE_DIRECT_AUX", - 5: "SIGN_MODE_AMINO_AUX", + 3: "SIGN_MODE_DIRECT_AUX", + 4: "SIGN_MODE_AMINO_AUX", 127: "SIGN_MODE_LEGACY_AMINO_JSON", } @@ -69,9 +64,8 @@ var SignMode_value = map[string]int32{ "SIGN_MODE_UNSPECIFIED": 0, "SIGN_MODE_DIRECT": 1, "SIGN_MODE_TEXTUAL": 2, - "SIGN_MODE_DIRECT_JSON": 3, - "SIGN_MODE_DIRECT_AUX": 4, - "SIGN_MODE_AMINO_AUX": 5, + "SIGN_MODE_DIRECT_AUX": 3, + "SIGN_MODE_AMINO_AUX": 4, "SIGN_MODE_LEGACY_AMINO_JSON": 127, } @@ -409,43 +403,43 @@ func init() { } var fileDescriptor_9a54958ff3d0b1b9 = []byte{ - // 571 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0x41, 0x4f, 0xd4, 0x40, - 0x14, 0xc7, 0xb7, 0x6c, 0x97, 0xc0, 0xc3, 0x98, 0x3a, 0x2c, 0x71, 0xa9, 0xa6, 0x12, 0x3c, 0x48, - 0x4c, 0x98, 0x06, 0x38, 0x18, 0xbd, 0x95, 0xdd, 0xba, 0xac, 0xb0, 0x8b, 0xb6, 0x4b, 0x82, 0x5e, - 0x36, 0x6d, 0x77, 0xa8, 0x0d, 0xdb, 0x4e, 0xed, 0x4c, 0x0d, 0x3d, 0xf9, 0x15, 0xfc, 0x1a, 0x7e, - 0x0c, 0xe3, 0xc5, 0x23, 0x47, 0x8f, 0x06, 0x3e, 0x83, 0x77, 0xc3, 0xb4, 0xdd, 0x42, 0xc4, 0x18, - 0xf7, 0xb4, 0x99, 0xf7, 0xff, 0xf7, 0xf7, 0xfe, 0x93, 0xf7, 0x76, 0xe0, 0x89, 0x47, 0x59, 0x48, - 0x99, 0xce, 0xcf, 0x74, 0x16, 0xf8, 0x51, 0x10, 0xf9, 0xfa, 0xc7, 0x2d, 0x97, 0x70, 0x67, 0xab, - 0x3c, 0xe3, 0x38, 0xa1, 0x9c, 0xa2, 0xd5, 0xdc, 0x88, 0xf9, 0x19, 0x2e, 0x85, 0xc2, 0xa8, 0x6e, - 0x16, 0x0c, 0x2f, 0xc9, 0x62, 0x4e, 0xf5, 0x30, 0x9d, 0xf0, 0x80, 0x05, 0x15, 0xa8, 0x2c, 0xe4, - 0x24, 0x75, 0xd5, 0xa7, 0xd4, 0x9f, 0x10, 0x5d, 0x9c, 0xdc, 0xf4, 0x44, 0x77, 0xa2, 0x2c, 0x97, - 0xd6, 0x4f, 0xa0, 0x69, 0x07, 0x7e, 0xe4, 0xf0, 0x34, 0x21, 0x1d, 0xc2, 0xbc, 0x24, 0x88, 0x39, - 0x4d, 0x18, 0x1a, 0x00, 0xb0, 0xb2, 0xce, 0x5a, 0xd2, 0x5a, 0x7d, 0x63, 0x69, 0x1b, 0xe3, 0xbf, - 0x26, 0xc2, 0xb7, 0x40, 0xac, 0x6b, 0x84, 0xf5, 0x5f, 0x32, 0x2c, 0xdf, 0xe2, 0x41, 0x3b, 0x00, - 0x71, 0xea, 0x4e, 0x02, 0x6f, 0x74, 0x4a, 0xb2, 0x96, 0xb4, 0x26, 0x6d, 0x2c, 0x6d, 0x37, 0x71, - 0x9e, 0x17, 0x97, 0x79, 0xb1, 0x11, 0x65, 0xd6, 0x62, 0xee, 0xdb, 0x27, 0x19, 0xea, 0x82, 0x3c, - 0x76, 0xb8, 0xd3, 0x9a, 0x13, 0xf6, 0x9d, 0xff, 0x8b, 0x85, 0x3b, 0x0e, 0x77, 0x2c, 0x01, 0x40, - 0x2a, 0x2c, 0x30, 0xf2, 0x21, 0x25, 0x91, 0x47, 0x5a, 0xf5, 0x35, 0x69, 0x43, 0xb6, 0xa6, 0x67, - 0xf5, 0x5b, 0x1d, 0xe4, 0x2b, 0x2b, 0x1a, 0xc2, 0x3c, 0x0b, 0x22, 0x7f, 0x42, 0x8a, 0x78, 0x2f, - 0x66, 0xe8, 0x87, 0x6d, 0x41, 0xd8, 0xab, 0x59, 0x05, 0x0b, 0xbd, 0x81, 0x86, 0x98, 0x52, 0x71, - 0x89, 0xe7, 0xb3, 0x40, 0xfb, 0x57, 0x80, 0xbd, 0x9a, 0x95, 0x93, 0xd4, 0x11, 0xcc, 0xe7, 0x6d, - 0xd0, 0x33, 0x90, 0x43, 0x3a, 0xce, 0x03, 0xdf, 0xdd, 0x7e, 0xfc, 0x0f, 0x76, 0x9f, 0x8e, 0x89, - 0x25, 0x3e, 0x40, 0x0f, 0x61, 0x71, 0x3a, 0x34, 0x91, 0xec, 0x8e, 0x55, 0x15, 0xd4, 0x2f, 0x12, - 0x34, 0x44, 0x4f, 0xb4, 0x0f, 0x0b, 0x6e, 0xc0, 0x9d, 0x24, 0x71, 0xca, 0xa1, 0xe9, 0x65, 0x93, - 0x7c, 0x27, 0xf1, 0x74, 0x05, 0xcb, 0x4e, 0x6d, 0x1a, 0xc6, 0x8e, 0xc7, 0x77, 0x03, 0x6e, 0x5c, - 0x7d, 0x66, 0x4d, 0x01, 0xc8, 0xbe, 0xb1, 0x6b, 0x73, 0x62, 0xd7, 0x66, 0x1a, 0xea, 0x35, 0xcc, - 0x6e, 0x03, 0xea, 0x2c, 0x0d, 0x9f, 0x7e, 0x95, 0x60, 0xa1, 0xbc, 0x23, 0x5a, 0x85, 0x15, 0xbb, - 0xd7, 0x1d, 0x8c, 0xfa, 0x87, 0x1d, 0x73, 0x74, 0x34, 0xb0, 0x5f, 0x9b, 0xed, 0xde, 0xcb, 0x9e, - 0xd9, 0x51, 0x6a, 0xa8, 0x09, 0x4a, 0x25, 0x75, 0x7a, 0x96, 0xd9, 0x1e, 0x2a, 0x12, 0x5a, 0x81, - 0x7b, 0x55, 0x75, 0x68, 0x1e, 0x0f, 0x8f, 0x8c, 0x03, 0x65, 0xee, 0x26, 0x27, 0x37, 0x8f, 0x5e, - 0xd9, 0x87, 0x03, 0xa5, 0x8e, 0x5a, 0xd0, 0xfc, 0x43, 0x32, 0x8e, 0x8e, 0x15, 0x19, 0xdd, 0x87, - 0xe5, 0x4a, 0x31, 0xfa, 0xbd, 0xc1, 0xa1, 0x10, 0x1a, 0xe8, 0x11, 0x3c, 0xa8, 0x84, 0x03, 0xb3, - 0x6b, 0xb4, 0xdf, 0x16, 0xba, 0x60, 0x7e, 0xda, 0xed, 0x7e, 0xbf, 0xd0, 0xa4, 0xf3, 0x0b, 0x4d, - 0xfa, 0x79, 0xa1, 0x49, 0x9f, 0x2f, 0xb5, 0xda, 0xf9, 0xa5, 0x56, 0xfb, 0x71, 0xa9, 0xd5, 0xde, - 0x6d, 0xfa, 0x01, 0x7f, 0x9f, 0xba, 0xd8, 0xa3, 0xa1, 0x5e, 0x3e, 0x09, 0xe2, 0x67, 0x93, 0x8d, - 0x4f, 0x75, 0x9e, 0xc5, 0xe4, 0xfa, 0x3b, 0xe3, 0xce, 0x8b, 0x3f, 0xd4, 0xce, 0xef, 0x00, 0x00, - 0x00, 0xff, 0xff, 0x67, 0xe0, 0x5a, 0xe2, 0x83, 0x04, 0x00, 0x00, + // 566 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0x41, 0x4f, 0xd4, 0x4e, + 0x18, 0xc6, 0x5b, 0xb6, 0x10, 0x78, 0xf9, 0xe7, 0x9f, 0x3a, 0x2c, 0x71, 0xa9, 0xa6, 0x12, 0x3c, + 0x48, 0x4c, 0x98, 0x06, 0x38, 0x18, 0xbd, 0x95, 0xdd, 0xba, 0xac, 0xb0, 0x8b, 0xb6, 0x4b, 0x82, + 0x5e, 0x36, 0x6d, 0x77, 0xa8, 0x0d, 0xdb, 0x4e, 0xed, 0x4c, 0x0d, 0x3d, 0xf9, 0x15, 0xfc, 0x14, + 0x26, 0x7e, 0x0e, 0x2f, 0x1e, 0x39, 0x7a, 0x34, 0xf0, 0x19, 0xbc, 0x1b, 0xa6, 0xed, 0x16, 0x0d, + 0xc6, 0xb8, 0xa7, 0xcd, 0xbc, 0xcf, 0xd3, 0xdf, 0xfb, 0x4c, 0xde, 0x77, 0x16, 0x1e, 0xf9, 0x94, + 0x45, 0x94, 0x19, 0xfc, 0xdc, 0x60, 0x61, 0x10, 0x87, 0x71, 0x60, 0xbc, 0xdf, 0xf6, 0x08, 0x77, + 0xb7, 0xab, 0x33, 0x4e, 0x52, 0xca, 0x29, 0x5a, 0x2b, 0x8c, 0x98, 0x9f, 0xe3, 0x4a, 0x28, 0x8d, + 0xda, 0x56, 0xc9, 0xf0, 0xd3, 0x3c, 0xe1, 0xd4, 0x88, 0xb2, 0x09, 0x0f, 0x59, 0x58, 0x83, 0xaa, + 0x42, 0x41, 0xd2, 0xd6, 0x02, 0x4a, 0x83, 0x09, 0x31, 0xc4, 0xc9, 0xcb, 0x4e, 0x0d, 0x37, 0xce, + 0x0b, 0x69, 0xe3, 0x14, 0x9a, 0x4e, 0x18, 0xc4, 0x2e, 0xcf, 0x52, 0xd2, 0x21, 0xcc, 0x4f, 0xc3, + 0x84, 0xd3, 0x94, 0xa1, 0x01, 0x00, 0xab, 0xea, 0xac, 0x25, 0xaf, 0x37, 0x36, 0x97, 0x77, 0x30, + 0xfe, 0x63, 0x22, 0x7c, 0x0b, 0xc4, 0xbe, 0x41, 0xd8, 0xf8, 0xa1, 0xc0, 0xca, 0x2d, 0x1e, 0xb4, + 0x0b, 0x90, 0x64, 0xde, 0x24, 0xf4, 0x47, 0x67, 0x24, 0x6f, 0xc9, 0xeb, 0xf2, 0xe6, 0xf2, 0x4e, + 0x13, 0x17, 0x79, 0x71, 0x95, 0x17, 0x9b, 0x71, 0x6e, 0x2f, 0x15, 0xbe, 0x03, 0x92, 0xa3, 0x2e, + 0x28, 0x63, 0x97, 0xbb, 0xad, 0x39, 0x61, 0xdf, 0xfd, 0xb7, 0x58, 0xb8, 0xe3, 0x72, 0xd7, 0x16, + 0x00, 0xa4, 0xc1, 0x22, 0x23, 0xef, 0x32, 0x12, 0xfb, 0xa4, 0xd5, 0x58, 0x97, 0x37, 0x15, 0x7b, + 0x7a, 0xd6, 0xbe, 0x34, 0x40, 0xb9, 0xb6, 0xa2, 0x21, 0x2c, 0xb0, 0x30, 0x0e, 0x26, 0xa4, 0x8c, + 0xf7, 0x6c, 0x86, 0x7e, 0xd8, 0x11, 0x84, 0x7d, 0xc9, 0x2e, 0x59, 0xe8, 0x15, 0xcc, 0x8b, 0x29, + 0x95, 0x97, 0x78, 0x3a, 0x0b, 0xb4, 0x7f, 0x0d, 0xd8, 0x97, 0xec, 0x82, 0xa4, 0x8d, 0x60, 0xa1, + 0x68, 0x83, 0x9e, 0x80, 0x12, 0xd1, 0x71, 0x11, 0xf8, 0xff, 0x9d, 0x87, 0x7f, 0x61, 0xf7, 0xe9, + 0x98, 0xd8, 0xe2, 0x03, 0x74, 0x1f, 0x96, 0xa6, 0x43, 0x13, 0xc9, 0xfe, 0xb3, 0xeb, 0x82, 0xf6, + 0x59, 0x86, 0x79, 0xd1, 0x13, 0x1d, 0xc0, 0xa2, 0x17, 0x72, 0x37, 0x4d, 0xdd, 0x6a, 0x68, 0x46, + 0xd5, 0xa4, 0xd8, 0x49, 0x3c, 0x5d, 0xc1, 0xaa, 0x53, 0x9b, 0x46, 0x89, 0xeb, 0xf3, 0xbd, 0x90, + 0x9b, 0xd7, 0x9f, 0xd9, 0x53, 0x00, 0x72, 0x7e, 0xd9, 0xb5, 0x39, 0xb1, 0x6b, 0x33, 0x0d, 0xf5, + 0x06, 0x66, 0x6f, 0x1e, 0x1a, 0x2c, 0x8b, 0x1e, 0x7f, 0x92, 0x61, 0xb1, 0xba, 0x23, 0x5a, 0x83, + 0x55, 0xa7, 0xd7, 0x1d, 0x8c, 0xfa, 0x47, 0x1d, 0x6b, 0x74, 0x3c, 0x70, 0x5e, 0x5a, 0xed, 0xde, + 0xf3, 0x9e, 0xd5, 0x51, 0x25, 0xd4, 0x04, 0xb5, 0x96, 0x3a, 0x3d, 0xdb, 0x6a, 0x0f, 0x55, 0x19, + 0xad, 0xc2, 0x9d, 0xba, 0x3a, 0xb4, 0x4e, 0x86, 0xc7, 0xe6, 0xa1, 0x3a, 0x87, 0x5a, 0xd0, 0xfc, + 0xdd, 0x3c, 0x32, 0x8f, 0x4f, 0xd4, 0x06, 0xba, 0x0b, 0x2b, 0xb5, 0x62, 0xf6, 0x7b, 0x83, 0x23, + 0x21, 0x28, 0xe8, 0x01, 0xdc, 0xab, 0x85, 0x43, 0xab, 0x6b, 0xb6, 0x5f, 0x97, 0xfa, 0x0b, 0xe7, + 0x68, 0xa0, 0x7e, 0xd8, 0xeb, 0x7e, 0xbd, 0xd4, 0xe5, 0x8b, 0x4b, 0x5d, 0xfe, 0x7e, 0xa9, 0xcb, + 0x1f, 0xaf, 0x74, 0xe9, 0xe2, 0x4a, 0x97, 0xbe, 0x5d, 0xe9, 0xd2, 0x9b, 0xad, 0x20, 0xe4, 0x6f, + 0x33, 0x0f, 0xfb, 0x34, 0x32, 0xaa, 0x77, 0x2f, 0x7e, 0xb6, 0xd8, 0xf8, 0xcc, 0xe0, 0x79, 0x42, + 0x6e, 0xfe, 0x99, 0x78, 0x0b, 0xe2, 0xd5, 0xec, 0xfe, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x54, 0x1d, + 0xa5, 0xb2, 0x68, 0x04, 0x00, 0x00, } func (m *SignatureDescriptors) Marshal() (dAtA []byte, err error) { diff --git a/types/tx/tx.pb.go b/types/tx/tx.pb.go index 83b8d5840aaf..cb9f6bb6de5e 100644 --- a/types/tx/tx.pb.go +++ b/types/tx/tx.pb.go @@ -245,103 +245,6 @@ func (m *SignDoc) GetAccountNumber() uint64 { return 0 } -// SignDocJSON is the type used for generating sign bytes for -// SIGN_MODE_DIRECT_JSON. It is designed to be serialized as proto3 JSON -// following the rules defined here: -// https://github.com/regen-network/canonical-proto3/blob/master/README.md#json. -type SignDocJSON struct { - // body is the processable content of the transaction - Body *TxBody `protobuf:"bytes,1,opt,name=body,proto3" json:"body,omitempty"` - // auth_info is the authorization related content of the transaction, - // specifically signers, signer modes and fee - AuthInfo *AuthInfo `protobuf:"bytes,2,opt,name=auth_info,json=authInfo,proto3" json:"auth_info,omitempty"` - // chain_id is the identifier of the chain this transaction targets. - // It prevents signed transactions from being used on another chain by an - // attacker - ChainId string `protobuf:"bytes,3,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` - // account_number is the account number of the signing account in state - AccountNumber uint64 `protobuf:"varint,4,opt,name=account_number,json=accountNumber,proto3" json:"account_number,omitempty"` - // sign_doc_sha256_hash is the SHA-256 hash of SignDoc. It is included here to - // reduce the malleability attack surface of SIGN_MODE_DIRECT_JSON vs - // SIGN_MODE_DIRECT to zero. Basically this means that any discrepancy between - // protobuf bytes over the wire and protobuf bytes that are signed cannot be - // exploited. This information is obviously redundant with information already - // in SignDocJSON, but is included as a security check for scenarios where - // this information may have inadvertently been excluded. We include the hash - // of SignDoc rather than the full SignDoc bytes to reduce the size of - // SignDocJSON for scenarios where large payloads could cause problems for - // hardware wallets. - SignDocSha256Hash []byte `protobuf:"bytes,5,opt,name=sign_doc_sha256_hash,json=signDocSha256Hash,proto3" json:"sign_doc_sha256_hash,omitempty"` -} - -func (m *SignDocJSON) Reset() { *m = SignDocJSON{} } -func (m *SignDocJSON) String() string { return proto.CompactTextString(m) } -func (*SignDocJSON) ProtoMessage() {} -func (*SignDocJSON) Descriptor() ([]byte, []int) { - return fileDescriptor_96d1575ffde80842, []int{3} -} -func (m *SignDocJSON) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *SignDocJSON) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_SignDocJSON.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *SignDocJSON) XXX_Merge(src proto.Message) { - xxx_messageInfo_SignDocJSON.Merge(m, src) -} -func (m *SignDocJSON) XXX_Size() int { - return m.Size() -} -func (m *SignDocJSON) XXX_DiscardUnknown() { - xxx_messageInfo_SignDocJSON.DiscardUnknown(m) -} - -var xxx_messageInfo_SignDocJSON proto.InternalMessageInfo - -func (m *SignDocJSON) GetBody() *TxBody { - if m != nil { - return m.Body - } - return nil -} - -func (m *SignDocJSON) GetAuthInfo() *AuthInfo { - if m != nil { - return m.AuthInfo - } - return nil -} - -func (m *SignDocJSON) GetChainId() string { - if m != nil { - return m.ChainId - } - return "" -} - -func (m *SignDocJSON) GetAccountNumber() uint64 { - if m != nil { - return m.AccountNumber - } - return 0 -} - -func (m *SignDocJSON) GetSignDocSha256Hash() []byte { - if m != nil { - return m.SignDocSha256Hash - } - return nil -} - // SignDocDirectAux is the type used for generating sign bytes for // SIGN_MODE_DIRECT_AUX. type SignDocDirectAux struct { @@ -367,7 +270,7 @@ func (m *SignDocDirectAux) Reset() { *m = SignDocDirectAux{} } func (m *SignDocDirectAux) String() string { return proto.CompactTextString(m) } func (*SignDocDirectAux) ProtoMessage() {} func (*SignDocDirectAux) Descriptor() ([]byte, []int) { - return fileDescriptor_96d1575ffde80842, []int{4} + return fileDescriptor_96d1575ffde80842, []int{3} } func (m *SignDocDirectAux) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -469,7 +372,7 @@ func (m *TxBody) Reset() { *m = TxBody{} } func (m *TxBody) String() string { return proto.CompactTextString(m) } func (*TxBody) ProtoMessage() {} func (*TxBody) Descriptor() ([]byte, []int) { - return fileDescriptor_96d1575ffde80842, []int{5} + return fileDescriptor_96d1575ffde80842, []int{4} } func (m *TxBody) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -554,7 +457,7 @@ func (m *AuthInfo) Reset() { *m = AuthInfo{} } func (m *AuthInfo) String() string { return proto.CompactTextString(m) } func (*AuthInfo) ProtoMessage() {} func (*AuthInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_96d1575ffde80842, []int{6} + return fileDescriptor_96d1575ffde80842, []int{5} } func (m *AuthInfo) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -624,7 +527,7 @@ func (m *SignerInfo) Reset() { *m = SignerInfo{} } func (m *SignerInfo) String() string { return proto.CompactTextString(m) } func (*SignerInfo) ProtoMessage() {} func (*SignerInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_96d1575ffde80842, []int{7} + return fileDescriptor_96d1575ffde80842, []int{6} } func (m *SignerInfo) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -689,7 +592,7 @@ func (m *ModeInfo) Reset() { *m = ModeInfo{} } func (m *ModeInfo) String() string { return proto.CompactTextString(m) } func (*ModeInfo) ProtoMessage() {} func (*ModeInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_96d1575ffde80842, []int{8} + return fileDescriptor_96d1575ffde80842, []int{7} } func (m *ModeInfo) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -775,7 +678,7 @@ func (m *ModeInfo_Single) Reset() { *m = ModeInfo_Single{} } func (m *ModeInfo_Single) String() string { return proto.CompactTextString(m) } func (*ModeInfo_Single) ProtoMessage() {} func (*ModeInfo_Single) Descriptor() ([]byte, []int) { - return fileDescriptor_96d1575ffde80842, []int{8, 0} + return fileDescriptor_96d1575ffde80842, []int{7, 0} } func (m *ModeInfo_Single) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -824,7 +727,7 @@ func (m *ModeInfo_Multi) Reset() { *m = ModeInfo_Multi{} } func (m *ModeInfo_Multi) String() string { return proto.CompactTextString(m) } func (*ModeInfo_Multi) ProtoMessage() {} func (*ModeInfo_Multi) Descriptor() ([]byte, []int) { - return fileDescriptor_96d1575ffde80842, []int{8, 1} + return fileDescriptor_96d1575ffde80842, []int{7, 1} } func (m *ModeInfo_Multi) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -890,7 +793,7 @@ func (m *Fee) Reset() { *m = Fee{} } func (m *Fee) String() string { return proto.CompactTextString(m) } func (*Fee) ProtoMessage() {} func (*Fee) Descriptor() ([]byte, []int) { - return fileDescriptor_96d1575ffde80842, []int{9} + return fileDescriptor_96d1575ffde80842, []int{8} } func (m *Fee) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -959,7 +862,7 @@ func (m *Tip) Reset() { *m = Tip{} } func (m *Tip) String() string { return proto.CompactTextString(m) } func (*Tip) ProtoMessage() {} func (*Tip) Descriptor() ([]byte, []int) { - return fileDescriptor_96d1575ffde80842, []int{10} + return fileDescriptor_96d1575ffde80842, []int{9} } func (m *Tip) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1006,7 +909,6 @@ func init() { proto.RegisterType((*Tx)(nil), "cosmos.tx.v1beta1.Tx") proto.RegisterType((*TxRaw)(nil), "cosmos.tx.v1beta1.TxRaw") proto.RegisterType((*SignDoc)(nil), "cosmos.tx.v1beta1.SignDoc") - proto.RegisterType((*SignDocJSON)(nil), "cosmos.tx.v1beta1.SignDocJSON") proto.RegisterType((*SignDocDirectAux)(nil), "cosmos.tx.v1beta1.SignDocDirectAux") proto.RegisterType((*TxBody)(nil), "cosmos.tx.v1beta1.TxBody") proto.RegisterType((*AuthInfo)(nil), "cosmos.tx.v1beta1.AuthInfo") @@ -1021,70 +923,67 @@ func init() { func init() { proto.RegisterFile("cosmos/tx/v1beta1/tx.proto", fileDescriptor_96d1575ffde80842) } var fileDescriptor_96d1575ffde80842 = []byte{ - // 1007 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x56, 0x4f, 0x6f, 0x1b, 0x45, - 0x14, 0xf7, 0x66, 0x6d, 0xc7, 0x7e, 0x4d, 0xda, 0x66, 0x14, 0x21, 0xc7, 0x51, 0xdd, 0x60, 0x54, - 0xf0, 0x25, 0xbb, 0x69, 0x2a, 0x68, 0x41, 0x48, 0x60, 0xb7, 0x54, 0x29, 0xa5, 0xad, 0x34, 0xce, - 0xa9, 0x97, 0xd5, 0x78, 0x3d, 0x59, 0x8f, 0xea, 0x9d, 0x59, 0x76, 0x66, 0xc1, 0xfe, 0x10, 0x48, - 0x15, 0x12, 0xe2, 0xca, 0x99, 0x33, 0x1f, 0xa2, 0xc7, 0x8a, 0x13, 0x27, 0xa8, 0x92, 0x13, 0x42, - 0xe2, 0x2b, 0x80, 0x66, 0x76, 0x76, 0x93, 0x96, 0x60, 0x57, 0xa2, 0xe2, 0xe4, 0x99, 0x37, 0xbf, - 0xf7, 0x7b, 0xbf, 0xf7, 0x67, 0x67, 0x0c, 0xed, 0x50, 0xc8, 0x58, 0x48, 0x5f, 0xcd, 0xfc, 0xaf, - 0xae, 0x8f, 0xa8, 0x22, 0xd7, 0x7d, 0x35, 0xf3, 0x92, 0x54, 0x28, 0x81, 0x36, 0xf2, 0x33, 0x4f, - 0xcd, 0x3c, 0x7b, 0xd6, 0xde, 0x8c, 0x44, 0x24, 0xcc, 0xa9, 0xaf, 0x57, 0x39, 0xb0, 0xbd, 0x6b, - 0x49, 0xc2, 0x74, 0x9e, 0x28, 0xe1, 0xc7, 0xd9, 0x54, 0x31, 0xc9, 0xa2, 0x92, 0xb1, 0x30, 0x58, - 0x78, 0xc7, 0xc2, 0x47, 0x44, 0xd2, 0x12, 0x13, 0x0a, 0xc6, 0xed, 0xf9, 0x7b, 0xa7, 0x9a, 0x24, - 0x8b, 0x38, 0xe3, 0xa7, 0x4c, 0x76, 0x6f, 0x81, 0x5b, 0x91, 0x10, 0xd1, 0x94, 0xfa, 0x66, 0x37, - 0xca, 0x8e, 0x7c, 0xc2, 0xe7, 0xc5, 0x51, 0xce, 0x11, 0xe4, 0x5a, 0x6d, 0x22, 0x66, 0xd3, 0xfd, - 0xc6, 0x81, 0x95, 0xc3, 0x19, 0xda, 0x85, 0xea, 0x48, 0x8c, 0xe7, 0x2d, 0x67, 0xc7, 0xe9, 0x5d, - 0xd8, 0xdf, 0xf2, 0xfe, 0x91, 0xac, 0x77, 0x38, 0x1b, 0x88, 0xf1, 0x1c, 0x1b, 0x18, 0xba, 0x05, - 0x4d, 0x92, 0xa9, 0x49, 0xc0, 0xf8, 0x91, 0x68, 0xad, 0x18, 0x9f, 0xed, 0x73, 0x7c, 0xfa, 0x99, - 0x9a, 0xdc, 0xe3, 0x47, 0x02, 0x37, 0x88, 0x5d, 0xa1, 0x0e, 0x80, 0x96, 0x4d, 0x54, 0x96, 0x52, - 0xd9, 0x72, 0x77, 0xdc, 0xde, 0x1a, 0x3e, 0x63, 0xe9, 0x72, 0xa8, 0x1d, 0xce, 0x30, 0xf9, 0x1a, - 0x5d, 0x01, 0xd0, 0xa1, 0x82, 0xd1, 0x5c, 0x51, 0x69, 0x74, 0xad, 0xe1, 0xa6, 0xb6, 0x0c, 0xb4, - 0x01, 0xbd, 0x0b, 0x97, 0x4a, 0x05, 0x16, 0xb3, 0x62, 0x30, 0xeb, 0x45, 0xa8, 0x1c, 0xb7, 0x2c, - 0xde, 0xb7, 0x0e, 0xac, 0x0e, 0x59, 0xc4, 0xef, 0x88, 0xf0, 0x4d, 0x85, 0xdc, 0x82, 0x46, 0x38, - 0x21, 0x8c, 0x07, 0x6c, 0xdc, 0x72, 0x77, 0x9c, 0x5e, 0x13, 0xaf, 0x9a, 0xfd, 0xbd, 0x31, 0xba, - 0x06, 0x17, 0x49, 0x18, 0x8a, 0x8c, 0xab, 0x80, 0x67, 0xf1, 0x88, 0xa6, 0xad, 0xea, 0x8e, 0xd3, - 0xab, 0xe2, 0x75, 0x6b, 0x7d, 0x68, 0x8c, 0xdd, 0xdf, 0x1d, 0xb8, 0x60, 0x45, 0x7d, 0x3e, 0x7c, - 0xf4, 0xf0, 0xff, 0xeb, 0xce, 0x7f, 0x96, 0x8e, 0x7c, 0xd8, 0xd4, 0xd5, 0x0d, 0xc6, 0x22, 0x0c, - 0xe4, 0x84, 0xec, 0xbf, 0xff, 0x41, 0x30, 0x21, 0x72, 0xd2, 0xaa, 0x99, 0x4a, 0x6d, 0xc8, 0x3c, - 0xab, 0xa1, 0x39, 0x39, 0x20, 0x72, 0xd2, 0xfd, 0xd3, 0x81, 0xcb, 0x36, 0xd7, 0x3b, 0x2c, 0xa5, - 0xa1, 0xea, 0x67, 0xb3, 0x65, 0x9d, 0xb8, 0x01, 0x90, 0x64, 0xa3, 0x29, 0x0b, 0x83, 0x27, 0x74, - 0x6e, 0x33, 0xdc, 0xf4, 0xf2, 0xf9, 0xf7, 0x8a, 0xf9, 0xf7, 0xfa, 0x7c, 0x8e, 0x9b, 0x39, 0xee, - 0x3e, 0x9d, 0xbf, 0x81, 0xdc, 0xda, 0xd0, 0x90, 0xf4, 0xcb, 0x8c, 0xf2, 0x90, 0x9a, 0x7c, 0xaa, - 0xb8, 0xdc, 0xa3, 0x1e, 0xb8, 0x8a, 0x25, 0xad, 0xba, 0xd1, 0xf2, 0xd6, 0x79, 0x1d, 0x62, 0x09, - 0xd6, 0x90, 0xee, 0x77, 0x2b, 0x50, 0xcf, 0xdb, 0x85, 0xf6, 0xa0, 0x11, 0x53, 0x29, 0x49, 0x64, - 0x92, 0x74, 0xff, 0x35, 0x8b, 0x12, 0x85, 0x10, 0x54, 0x63, 0x1a, 0xe7, 0x5d, 0x6d, 0x62, 0xb3, - 0xd6, 0xea, 0x15, 0x8b, 0xa9, 0xc8, 0x54, 0x30, 0xa1, 0x2c, 0x9a, 0x28, 0x93, 0x5e, 0x15, 0xaf, - 0x5b, 0xeb, 0x81, 0x31, 0xa2, 0x01, 0x6c, 0xd0, 0x99, 0xa2, 0x5c, 0x32, 0xc1, 0x03, 0x91, 0x28, - 0x26, 0xb8, 0x6c, 0xfd, 0xb5, 0xba, 0x20, 0xec, 0xe5, 0x12, 0xff, 0x28, 0x87, 0xa3, 0xc7, 0xd0, - 0xe1, 0x82, 0x07, 0x61, 0xca, 0x14, 0x0b, 0xc9, 0x34, 0x38, 0x87, 0xf0, 0xd2, 0x02, 0xc2, 0x6d, - 0x2e, 0xf8, 0x6d, 0xeb, 0xfb, 0xd9, 0x2b, 0xdc, 0xdd, 0x1f, 0x1c, 0x68, 0x14, 0x23, 0x89, 0x3e, - 0x85, 0x35, 0x3d, 0x2a, 0x34, 0x35, 0x43, 0x5c, 0x54, 0xe7, 0xca, 0x39, 0x75, 0x1d, 0x1a, 0x98, - 0x99, 0xe3, 0x0b, 0xb2, 0x5c, 0x4b, 0xdd, 0x90, 0x23, 0x4a, 0xed, 0x70, 0x9c, 0xd7, 0x90, 0xbb, - 0x94, 0x62, 0x0d, 0x29, 0x5a, 0xe7, 0x2e, 0x6f, 0xdd, 0xf7, 0x0e, 0xc0, 0x69, 0xbc, 0x57, 0xc6, - 0xd0, 0x79, 0xbd, 0x31, 0xbc, 0x05, 0xcd, 0x58, 0x8c, 0xe9, 0xb2, 0x8f, 0xf3, 0x81, 0x18, 0xd3, - 0xfc, 0xe3, 0x8c, 0xed, 0xea, 0xa5, 0xf1, 0x73, 0x5f, 0x1e, 0xbf, 0xee, 0x8b, 0x15, 0x68, 0x14, - 0x2e, 0xe8, 0x63, 0xa8, 0x4b, 0xc6, 0xa3, 0x29, 0xb5, 0x9a, 0xba, 0x0b, 0xf8, 0xbd, 0xa1, 0x41, - 0x1e, 0x54, 0xb0, 0xf5, 0x41, 0x1f, 0x42, 0xcd, 0x3c, 0x51, 0x56, 0xdc, 0xdb, 0x8b, 0x9c, 0x1f, - 0x68, 0xe0, 0x41, 0x05, 0xe7, 0x1e, 0xed, 0x3e, 0xd4, 0x73, 0x3a, 0x74, 0x13, 0xaa, 0x5a, 0xb7, - 0x11, 0x70, 0x71, 0xff, 0x9d, 0x33, 0x1c, 0xc5, 0xa3, 0x75, 0xb6, 0x7f, 0x9a, 0x0f, 0x1b, 0x87, - 0xf6, 0x53, 0x07, 0x6a, 0x86, 0x15, 0xdd, 0x87, 0xc6, 0x88, 0x29, 0x92, 0xa6, 0xa4, 0xa8, 0xad, - 0x5f, 0xd0, 0xe4, 0x4f, 0xab, 0x57, 0xbe, 0xa4, 0x05, 0xd7, 0x6d, 0x11, 0x27, 0x24, 0x54, 0x03, - 0xa6, 0xfa, 0xda, 0x0d, 0x97, 0x04, 0xe8, 0x23, 0x80, 0xb2, 0xea, 0xfa, 0xda, 0x76, 0x97, 0x95, - 0xbd, 0x59, 0x94, 0x5d, 0x0e, 0x6a, 0xe0, 0xca, 0x2c, 0xee, 0xfe, 0xe1, 0x80, 0x7b, 0x97, 0x52, - 0x14, 0x42, 0x9d, 0xc4, 0xfa, 0x56, 0xb0, 0x43, 0x59, 0x5e, 0xc7, 0xfa, 0x05, 0x3f, 0x23, 0x85, - 0xf1, 0xc1, 0xde, 0xb3, 0x5f, 0xaf, 0x56, 0x7e, 0xfc, 0xed, 0x6a, 0x2f, 0x62, 0x6a, 0x92, 0x8d, - 0xbc, 0x50, 0xc4, 0x7e, 0xf1, 0xef, 0xc0, 0xfc, 0xec, 0xca, 0xf1, 0x13, 0x5f, 0xcd, 0x13, 0x2a, - 0x8d, 0x83, 0xc4, 0x96, 0x1a, 0x6d, 0x43, 0x33, 0x22, 0x32, 0x98, 0xb2, 0x98, 0x29, 0xd3, 0x88, - 0x2a, 0x6e, 0x44, 0x44, 0x7e, 0xa1, 0xf7, 0xc8, 0x83, 0x5a, 0x42, 0xe6, 0x34, 0xcd, 0xaf, 0xb1, - 0x41, 0xeb, 0xe7, 0x9f, 0x76, 0x37, 0xad, 0x86, 0xfe, 0x78, 0x9c, 0x52, 0x29, 0x87, 0x2a, 0x65, - 0x3c, 0xc2, 0x39, 0x0c, 0xed, 0xc3, 0x6a, 0x94, 0x12, 0xae, 0xec, 0xbd, 0xb6, 0xc8, 0xa3, 0x00, - 0x76, 0x13, 0x70, 0x0f, 0x59, 0x82, 0x6e, 0xbe, 0x7e, 0xb2, 0x55, 0x9d, 0x6c, 0x99, 0xc0, 0x1e, - 0xd4, 0x15, 0x4b, 0x12, 0x9a, 0xe6, 0x57, 0xd5, 0x82, 0x90, 0x16, 0x37, 0xf8, 0xe4, 0xd9, 0x71, - 0xc7, 0x79, 0x7e, 0xdc, 0x71, 0x5e, 0x1c, 0x77, 0x9c, 0xa7, 0x27, 0x9d, 0xca, 0xf3, 0x93, 0x4e, - 0xe5, 0x97, 0x93, 0x4e, 0xe5, 0xf1, 0xb5, 0xe5, 0xe5, 0xf3, 0xd5, 0x6c, 0x54, 0x37, 0x9f, 0xdc, - 0x8d, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x17, 0x43, 0x65, 0x00, 0xc6, 0x09, 0x00, 0x00, + // 957 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0x4f, 0x6f, 0x1b, 0x45, + 0x14, 0xf7, 0x66, 0x6d, 0xc7, 0x7e, 0x6d, 0xfa, 0x67, 0x14, 0x21, 0xc7, 0x51, 0xdd, 0x60, 0x54, + 0xf0, 0x25, 0xbb, 0x69, 0x7a, 0x68, 0x41, 0x48, 0x60, 0xb7, 0x54, 0xa9, 0x4a, 0x41, 0x9a, 0xe4, + 0xd4, 0xcb, 0x6a, 0x76, 0x3d, 0x59, 0x8f, 0xea, 0x9d, 0x59, 0x76, 0x66, 0xc1, 0xfb, 0x21, 0x90, + 0x2a, 0x24, 0xc4, 0x95, 0x33, 0x67, 0x3e, 0x44, 0x8f, 0x15, 0x27, 0x4e, 0x50, 0x25, 0x47, 0x24, + 0xbe, 0x02, 0x68, 0x66, 0x67, 0x37, 0x69, 0x09, 0x76, 0x25, 0x38, 0xed, 0xcc, 0x9b, 0xdf, 0xfb, + 0xcd, 0xef, 0xfd, 0xd9, 0x37, 0xd0, 0x8f, 0x84, 0x4c, 0x84, 0xf4, 0xd5, 0xc2, 0xff, 0xfa, 0x76, + 0x48, 0x15, 0xb9, 0xed, 0xab, 0x85, 0x97, 0x66, 0x42, 0x09, 0x74, 0xbd, 0x3c, 0xf3, 0xd4, 0xc2, + 0xb3, 0x67, 0xfd, 0xcd, 0x58, 0xc4, 0xc2, 0x9c, 0xfa, 0x7a, 0x55, 0x02, 0xfb, 0xbb, 0x96, 0x24, + 0xca, 0x8a, 0x54, 0x09, 0x3f, 0xc9, 0xe7, 0x8a, 0x49, 0x16, 0xd7, 0x8c, 0x95, 0xc1, 0xc2, 0x07, + 0x16, 0x1e, 0x12, 0x49, 0x6b, 0x4c, 0x24, 0x18, 0xb7, 0xe7, 0x1f, 0x9c, 0x69, 0x92, 0x2c, 0xe6, + 0x8c, 0x9f, 0x31, 0xd9, 0xbd, 0x05, 0x6e, 0xc5, 0x42, 0xc4, 0x73, 0xea, 0x9b, 0x5d, 0x98, 0x1f, + 0xfb, 0x84, 0x17, 0xd5, 0x51, 0xc9, 0x11, 0x94, 0x5a, 0x6d, 0x20, 0x66, 0x33, 0xfc, 0xd6, 0x81, + 0xb5, 0xa3, 0x05, 0xda, 0x85, 0x66, 0x28, 0xa6, 0x45, 0xcf, 0xd9, 0x71, 0x46, 0x97, 0xf6, 0xb7, + 0xbc, 0x7f, 0x04, 0xeb, 0x1d, 0x2d, 0x26, 0x62, 0x5a, 0x60, 0x03, 0x43, 0xf7, 0xa0, 0x4b, 0x72, + 0x35, 0x0b, 0x18, 0x3f, 0x16, 0xbd, 0x35, 0xe3, 0xb3, 0x7d, 0x81, 0xcf, 0x38, 0x57, 0xb3, 0x47, + 0xfc, 0x58, 0xe0, 0x0e, 0xb1, 0x2b, 0x34, 0x00, 0xd0, 0xb2, 0x89, 0xca, 0x33, 0x2a, 0x7b, 0xee, + 0x8e, 0x3b, 0xba, 0x8c, 0xcf, 0x59, 0x86, 0x1c, 0x5a, 0x47, 0x0b, 0x4c, 0xbe, 0x41, 0x37, 0x00, + 0xf4, 0x55, 0x41, 0x58, 0x28, 0x2a, 0x8d, 0xae, 0xcb, 0xb8, 0xab, 0x2d, 0x13, 0x6d, 0x40, 0xef, + 0xc3, 0xd5, 0x5a, 0x81, 0xc5, 0xac, 0x19, 0xcc, 0x46, 0x75, 0x55, 0x89, 0x5b, 0x75, 0xdf, 0x77, + 0x0e, 0xac, 0x1f, 0xb2, 0x98, 0x3f, 0x10, 0xd1, 0xff, 0x75, 0xe5, 0x16, 0x74, 0xa2, 0x19, 0x61, + 0x3c, 0x60, 0xd3, 0x9e, 0xbb, 0xe3, 0x8c, 0xba, 0x78, 0xdd, 0xec, 0x1f, 0x4d, 0xd1, 0x2d, 0xb8, + 0x42, 0xa2, 0x48, 0xe4, 0x5c, 0x05, 0x3c, 0x4f, 0x42, 0x9a, 0xf5, 0x9a, 0x3b, 0xce, 0xa8, 0x89, + 0x37, 0xac, 0xf5, 0x0b, 0x63, 0x1c, 0xfe, 0xe9, 0xc0, 0x35, 0x2b, 0xea, 0x01, 0xcb, 0x68, 0xa4, + 0xc6, 0xf9, 0x62, 0x95, 0xba, 0x3b, 0x00, 0x69, 0x1e, 0xce, 0x59, 0x14, 0x3c, 0xa3, 0x85, 0xad, + 0xc9, 0xa6, 0x57, 0xf6, 0x84, 0x57, 0xf5, 0x84, 0x37, 0xe6, 0x05, 0xee, 0x96, 0xb8, 0xc7, 0xb4, + 0xf8, 0xef, 0x52, 0x51, 0x1f, 0x3a, 0x92, 0x7e, 0x95, 0x53, 0x1e, 0xd1, 0x5e, 0xcb, 0x00, 0xea, + 0x3d, 0x1a, 0x81, 0xab, 0x58, 0xda, 0x6b, 0x1b, 0x2d, 0xef, 0x5c, 0xd4, 0x53, 0x2c, 0xc5, 0x1a, + 0x32, 0xfc, 0x7e, 0x0d, 0xda, 0x65, 0x83, 0xa1, 0x3d, 0xe8, 0x24, 0x54, 0x4a, 0x12, 0x9b, 0x20, + 0xdd, 0x7f, 0x8d, 0xa2, 0x46, 0x21, 0x04, 0xcd, 0x84, 0x26, 0x65, 0x1f, 0x76, 0xb1, 0x59, 0x6b, + 0xf5, 0x8a, 0x25, 0x54, 0xe4, 0x2a, 0x98, 0x51, 0x16, 0xcf, 0x94, 0x09, 0xaf, 0x89, 0x37, 0xac, + 0xf5, 0xc0, 0x18, 0xd1, 0x04, 0xae, 0xd3, 0x85, 0xa2, 0x5c, 0x32, 0xc1, 0x03, 0x91, 0x2a, 0x26, + 0xb8, 0xec, 0xfd, 0xb5, 0xbe, 0xe4, 0xda, 0x6b, 0x35, 0xfe, 0xcb, 0x12, 0x8e, 0x9e, 0xc2, 0x80, + 0x0b, 0x1e, 0x44, 0x19, 0x53, 0x2c, 0x22, 0xf3, 0xe0, 0x02, 0xc2, 0xab, 0x4b, 0x08, 0xb7, 0xb9, + 0xe0, 0xf7, 0xad, 0xef, 0x67, 0x6f, 0x70, 0x0f, 0x7f, 0x74, 0xa0, 0x53, 0xfd, 0x44, 0xe8, 0x53, + 0xb8, 0xac, 0x1b, 0x97, 0x66, 0xa6, 0x03, 0xab, 0xec, 0xdc, 0xb8, 0x20, 0xaf, 0x87, 0x06, 0x66, + 0xfe, 0xbc, 0x4b, 0xb2, 0x5e, 0x4b, 0x5d, 0x90, 0x63, 0x4a, 0x6d, 0x73, 0x5c, 0x54, 0x90, 0x87, + 0x94, 0x62, 0x0d, 0xa9, 0x4a, 0xe7, 0xae, 0x2e, 0xdd, 0x0f, 0x0e, 0xc0, 0xd9, 0x7d, 0x6f, 0xb4, + 0xa1, 0xf3, 0x76, 0x6d, 0x78, 0x0f, 0xba, 0x89, 0x98, 0xd2, 0x55, 0xe3, 0xe4, 0x89, 0x98, 0xd2, + 0x72, 0x9c, 0x24, 0x76, 0xf5, 0x5a, 0xfb, 0xb9, 0xaf, 0xb7, 0xdf, 0xf0, 0xd5, 0x1a, 0x74, 0x2a, + 0x17, 0xf4, 0x31, 0xb4, 0x25, 0xe3, 0xf1, 0x9c, 0x5a, 0x4d, 0xc3, 0x25, 0xfc, 0xde, 0xa1, 0x41, + 0x1e, 0x34, 0xb0, 0xf5, 0x41, 0x1f, 0x42, 0xcb, 0x8c, 0x6d, 0x2b, 0xee, 0xdd, 0x65, 0xce, 0x4f, + 0x34, 0xf0, 0xa0, 0x81, 0x4b, 0x8f, 0xfe, 0x18, 0xda, 0x25, 0x1d, 0xba, 0x0b, 0x4d, 0xad, 0xdb, + 0x08, 0xb8, 0xb2, 0xff, 0xde, 0x39, 0x8e, 0x6a, 0x90, 0x9f, 0xaf, 0x9f, 0xe6, 0xc3, 0xc6, 0xa1, + 0xff, 0xdc, 0x81, 0x96, 0x61, 0x45, 0x8f, 0xa1, 0x13, 0x32, 0x45, 0xb2, 0x8c, 0x54, 0xb9, 0xf5, + 0x2b, 0x9a, 0xf2, 0xb9, 0xf1, 0xea, 0xd7, 0xa5, 0xe2, 0xba, 0x2f, 0x92, 0x94, 0x44, 0x6a, 0xc2, + 0xd4, 0x58, 0xbb, 0xe1, 0x9a, 0x00, 0x7d, 0x04, 0x50, 0x67, 0x5d, 0x8f, 0x32, 0x77, 0x55, 0xda, + 0xbb, 0x55, 0xda, 0xe5, 0xa4, 0x05, 0xae, 0xcc, 0x93, 0xe1, 0x1f, 0x0e, 0xb8, 0x0f, 0x29, 0x45, + 0x11, 0xb4, 0x49, 0xa2, 0xa7, 0x82, 0x6d, 0xca, 0xfa, 0x01, 0xd1, 0xaf, 0xda, 0x39, 0x29, 0x8c, + 0x4f, 0xf6, 0x5e, 0xfc, 0x76, 0xb3, 0xf1, 0xd3, 0xef, 0x37, 0x47, 0x31, 0x53, 0xb3, 0x3c, 0xf4, + 0x22, 0x91, 0xf8, 0xd5, 0x8b, 0x69, 0x3e, 0xbb, 0x72, 0xfa, 0xcc, 0x57, 0x45, 0x4a, 0xa5, 0x71, + 0x90, 0xd8, 0x52, 0xa3, 0x6d, 0xe8, 0xc6, 0x44, 0x06, 0x73, 0x96, 0x30, 0x65, 0x0a, 0xd1, 0xc4, + 0x9d, 0x98, 0xc8, 0xcf, 0xf5, 0x1e, 0x79, 0xd0, 0x4a, 0x49, 0x41, 0xb3, 0x72, 0x8c, 0x4d, 0x7a, + 0xbf, 0xfc, 0xbc, 0xbb, 0x69, 0x35, 0x8c, 0xa7, 0xd3, 0x8c, 0x4a, 0x79, 0xa8, 0x32, 0xc6, 0x63, + 0x5c, 0xc2, 0xd0, 0x3e, 0xac, 0xc7, 0x19, 0xe1, 0xca, 0xce, 0xb5, 0x65, 0x1e, 0x15, 0x70, 0x98, + 0x82, 0x7b, 0xc4, 0x52, 0x74, 0xf7, 0xed, 0x83, 0x6d, 0xea, 0x60, 0xeb, 0x00, 0xf6, 0xa0, 0xad, + 0x58, 0x9a, 0xd2, 0xac, 0x1c, 0x55, 0x4b, 0xae, 0xb4, 0xb8, 0xc9, 0x27, 0x2f, 0x4e, 0x06, 0xce, + 0xcb, 0x93, 0x81, 0xf3, 0xea, 0x64, 0xe0, 0x3c, 0x3f, 0x1d, 0x34, 0x5e, 0x9e, 0x0e, 0x1a, 0xbf, + 0x9e, 0x0e, 0x1a, 0x4f, 0x6f, 0xad, 0x4e, 0x9f, 0xaf, 0x16, 0x61, 0xdb, 0xfc, 0x72, 0x77, 0xfe, + 0x0e, 0x00, 0x00, 0xff, 0xff, 0x82, 0x38, 0x16, 0x01, 0xda, 0x08, 0x00, 0x00, } func (m *Tx) Marshal() (dAtA []byte, err error) { @@ -1238,72 +1137,6 @@ func (m *SignDoc) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *SignDocJSON) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *SignDocJSON) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *SignDocJSON) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.SignDocSha256Hash) > 0 { - i -= len(m.SignDocSha256Hash) - copy(dAtA[i:], m.SignDocSha256Hash) - i = encodeVarintTx(dAtA, i, uint64(len(m.SignDocSha256Hash))) - i-- - dAtA[i] = 0x2a - } - if m.AccountNumber != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.AccountNumber)) - i-- - dAtA[i] = 0x20 - } - if len(m.ChainId) > 0 { - i -= len(m.ChainId) - copy(dAtA[i:], m.ChainId) - i = encodeVarintTx(dAtA, i, uint64(len(m.ChainId))) - i-- - dAtA[i] = 0x1a - } - if m.AuthInfo != nil { - { - size, err := m.AuthInfo.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - if m.Body != nil { - { - size, err := m.Body.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - func (m *SignDocDirectAux) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -1901,34 +1734,6 @@ func (m *SignDoc) Size() (n int) { return n } -func (m *SignDocJSON) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Body != nil { - l = m.Body.Size() - n += 1 + l + sovTx(uint64(l)) - } - if m.AuthInfo != nil { - l = m.AuthInfo.Size() - n += 1 + l + sovTx(uint64(l)) - } - l = len(m.ChainId) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - if m.AccountNumber != 0 { - n += 1 + sovTx(uint64(m.AccountNumber)) - } - l = len(m.SignDocSha256Hash) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - return n -} - func (m *SignDocDirectAux) Size() (n int) { if m == nil { return 0 @@ -2628,213 +2433,6 @@ func (m *SignDoc) Unmarshal(dAtA []byte) error { } return nil } -func (m *SignDocJSON) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: SignDocJSON: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: SignDocJSON: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Body", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Body == nil { - m.Body = &TxBody{} - } - if err := m.Body.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AuthInfo", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.AuthInfo == nil { - m.AuthInfo = &AuthInfo{} - } - if err := m.AuthInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ChainId = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field AccountNumber", wireType) - } - m.AccountNumber = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.AccountNumber |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SignDocSha256Hash", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.SignDocSha256Hash = append(m.SignDocSha256Hash[:0], dAtA[iNdEx:postIndex]...) - if m.SignDocSha256Hash == nil { - m.SignDocSha256Hash = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func (m *SignDocDirectAux) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/x/auth/keeper/grpc_query_test.go b/x/auth/keeper/grpc_query_test.go index 07d45e527379..9052873d94ae 100644 --- a/x/auth/keeper/grpc_query_test.go +++ b/x/auth/keeper/grpc_query_test.go @@ -37,14 +37,14 @@ func (suite *KeeperTestSuite) TestGRPCQueryAccounts() { }, true, func(res *types.QueryAccountsResponse) { - for _, acc := range res.Accounts { + addresses := make([]sdk.AccAddress, len(res.Accounts)) + for i, acc := range res.Accounts { var account types.AccountI err := suite.app.InterfaceRegistry().UnpackAny(acc, &account) suite.Require().NoError(err) - - suite.Require().True( - first.Equals(account.GetAddress()) || second.Equals(account.GetAddress())) + addresses[i] = account.GetAddress() } + suite.Subset(addresses, []sdk.AccAddress{first, second}) }, }, } diff --git a/x/auth/keeper/keeper.go b/x/auth/keeper/keeper.go index 10ce4f0be2aa..25592115a3e9 100644 --- a/x/auth/keeper/keeper.go +++ b/x/auth/keeper/keeper.go @@ -12,6 +12,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" @@ -53,7 +54,7 @@ type AccountKeeperI interface { // AccountKeeper encodes/decodes accounts using the go-amino (binary) // encoding/decoding library. type AccountKeeper struct { - key sdk.StoreKey + key storetypes.StoreKey cdc codec.BinaryCodec paramSubspace paramtypes.Subspace permAddrs map[string]types.PermissionsForAddress @@ -72,7 +73,7 @@ var _ AccountKeeperI = &AccountKeeper{} // and don't have to fit into any predefined structure. This auth module does not use account permissions internally, though other modules // may use auth.Keeper to access the accounts permissions map. func NewAccountKeeper( - cdc codec.BinaryCodec, key sdk.StoreKey, paramstore paramtypes.Subspace, proto func() types.AccountI, + cdc codec.BinaryCodec, key storetypes.StoreKey, paramstore paramtypes.Subspace, proto func() types.AccountI, maccPerms map[string][]string, bech32Prefix string, ) AccountKeeper { diff --git a/x/auth/module_test.go b/x/auth/module_test.go index 8e4c270d5755..6f527c587e49 100644 --- a/x/auth/module_test.go +++ b/x/auth/module_test.go @@ -5,23 +5,32 @@ import ( "github.com/stretchr/testify/require" abcitypes "github.com/tendermint/tendermint/abci/types" + tmjson "github.com/tendermint/tendermint/libs/json" + "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/x/auth/types" ) func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { - app := simapp.Setup(t, false) - ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + db := dbm.NewMemDB() + encCdc := simapp.MakeTestEncodingConfig() + app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encCdc, simapp.EmptyAppOptions{}) + + genesisState := simapp.GenesisStateWithSingleValidator(t, app) + stateBytes, err := tmjson.Marshal(genesisState) + require.NoError(t, err) app.InitChain( abcitypes.RequestInitChain{ - AppStateBytes: []byte("{}"), + AppStateBytes: stateBytes, ChainId: "test-chain-id", }, ) + ctx := app.BaseApp.NewContext(false, tmproto.Header{}) acc := app.AccountKeeper.GetAccount(ctx, types.NewModuleAddress(types.FeeCollectorName)) require.NotNil(t, acc) } diff --git a/x/auth/tx/amino_aux_test.go b/x/auth/tx/amino_aux_test.go index d7fced93870f..8f008ff84644 100644 --- a/x/auth/tx/amino_aux_test.go +++ b/x/auth/tx/amino_aux_test.go @@ -113,7 +113,6 @@ func TestAminoAuxHandler_DefaultMode(t *testing.T) { func TestAminoAuxModeHandler_nonDIRECT_MODE(t *testing.T) { invalidModes := []signingtypes.SignMode{ signingtypes.SignMode_SIGN_MODE_DIRECT, - signingtypes.SignMode_SIGN_MODE_DIRECT_JSON, signingtypes.SignMode_SIGN_MODE_TEXTUAL, signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signingtypes.SignMode_SIGN_MODE_UNSPECIFIED, diff --git a/x/auth/tx/direct_aux_test.go b/x/auth/tx/direct_aux_test.go index 777d97accb89..5930dd520213 100644 --- a/x/auth/tx/direct_aux_test.go +++ b/x/auth/tx/direct_aux_test.go @@ -4,6 +4,8 @@ import ( "fmt" "testing" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" @@ -11,7 +13,6 @@ import ( txtypes "github.com/cosmos/cosmos-sdk/types/tx" signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth/signing" - "github.com/stretchr/testify/require" ) func TestDirectAuxHandler(t *testing.T) { @@ -112,7 +113,6 @@ func TestDirectAuxHandler_DefaultMode(t *testing.T) { func TestDirectAuxModeHandler_nonDIRECT_MODE(t *testing.T) { invalidModes := []signingtypes.SignMode{ signingtypes.SignMode_SIGN_MODE_DIRECT, - signingtypes.SignMode_SIGN_MODE_DIRECT_JSON, signingtypes.SignMode_SIGN_MODE_TEXTUAL, signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signingtypes.SignMode_SIGN_MODE_UNSPECIFIED, diff --git a/x/auth/tx/direct_test.go b/x/auth/tx/direct_test.go index fd1e343229b6..bef1e81ed974 100644 --- a/x/auth/tx/direct_test.go +++ b/x/auth/tx/direct_test.go @@ -131,7 +131,6 @@ func TestDirectModeHandler(t *testing.T) { func TestDirectModeHandler_nonDIRECT_MODE(t *testing.T) { invalidModes := []signingtypes.SignMode{ - signingtypes.SignMode_SIGN_MODE_DIRECT_JSON, signingtypes.SignMode_SIGN_MODE_TEXTUAL, signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, signingtypes.SignMode_SIGN_MODE_UNSPECIFIED, diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index b884d41bc4fe..43c3ccc15d4d 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/middleware" @@ -17,13 +18,13 @@ import ( ) type Keeper struct { - storeKey sdk.StoreKey + storeKey storetypes.StoreKey cdc codec.BinaryCodec router *middleware.MsgServiceRouter } // NewKeeper constructs a message authorization Keeper -func NewKeeper(storeKey sdk.StoreKey, cdc codec.BinaryCodec, router *middleware.MsgServiceRouter) Keeper { +func NewKeeper(storeKey storetypes.StoreKey, cdc codec.BinaryCodec, router *middleware.MsgServiceRouter) Keeper { return Keeper{ storeKey: storeKey, cdc: cdc, diff --git a/x/bank/keeper/genesis_test.go b/x/bank/keeper/genesis_test.go index 70d53b9f0430..d8fd84d2e290 100644 --- a/x/bank/keeper/genesis_test.go +++ b/x/bank/keeper/genesis_test.go @@ -11,7 +11,13 @@ func (suite *IntegrationTestSuite) TestExportGenesis() { app, ctx := suite.app, suite.ctx expectedMetadata := suite.getTestMetadata() - expectedBalances, totalSupply := suite.getTestBalancesAndSupply() + expectedBalances, expTotalSupply := suite.getTestBalancesAndSupply() + + // Adding genesis supply to the expTotalSupply + genesisSupply, _, err := suite.app.BankKeeper.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{Limit: query.MaxLimit}) + suite.Require().NoError(err) + expTotalSupply = expTotalSupply.Add(genesisSupply...) + for i := range []int{1, 2} { app.BankKeeper.SetDenomMetaData(ctx, expectedMetadata[i]) accAddr, err1 := sdk.AccAddressFromBech32(expectedBalances[i].Address) @@ -32,8 +38,8 @@ func (suite *IntegrationTestSuite) TestExportGenesis() { suite.Require().Len(exportGenesis.Params.SendEnabled, 0) suite.Require().Equal(types.DefaultParams().DefaultSendEnabled, exportGenesis.Params.DefaultSendEnabled) - suite.Require().Equal(totalSupply, exportGenesis.Supply) - suite.Require().Equal(expectedBalances, exportGenesis.Balances) + suite.Require().Equal(expTotalSupply, exportGenesis.Supply) + suite.Require().Subset(exportGenesis.Balances, expectedBalances) suite.Require().Equal(expectedMetadata, exportGenesis.DenomMetadata) } @@ -74,6 +80,9 @@ func (suite *IntegrationTestSuite) TestTotalSupply() { } totalSupply := sdk.NewCoins(sdk.NewCoin("foocoin", sdk.NewInt(11)), sdk.NewCoin("barcoin", sdk.NewInt(21))) + genesisSupply, _, err := suite.app.BankKeeper.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{Limit: query.MaxLimit}) + suite.Require().NoError(err) + testcases := []struct { name string genesis *types.GenesisState @@ -107,7 +116,10 @@ func (suite *IntegrationTestSuite) TestTotalSupply() { suite.app.BankKeeper.InitGenesis(suite.ctx, tc.genesis) totalSupply, _, err := suite.app.BankKeeper.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{Limit: query.MaxLimit}) suite.Require().NoError(err) - suite.Require().Equal(tc.expSupply, totalSupply) + + // adding genesis supply to expected supply + expected := tc.expSupply.Add(genesisSupply...) + suite.Require().Equal(expected, totalSupply) } }) } diff --git a/x/bank/keeper/grpc_query_test.go b/x/bank/keeper/grpc_query_test.go index 50be8cea940e..1f8a1de5efc4 100644 --- a/x/bank/keeper/grpc_query_test.go +++ b/x/bank/keeper/grpc_query_test.go @@ -81,22 +81,29 @@ func (suite *IntegrationTestSuite) TestQueryAllBalances() { } req = types.NewQueryAllBalancesRequest(addr, pageReq) res, err = queryClient.AllBalances(gocontext.Background(), req) + suite.Require().NoError(err) suite.Equal(res.Balances.Len(), 1) suite.Nil(res.Pagination.NextKey) } func (suite *IntegrationTestSuite) TestQueryTotalSupply() { app, ctx, queryClient := suite.app, suite.ctx, suite.queryClient - expectedTotalSupply := sdk.NewCoins(sdk.NewInt64Coin("test", 400000000)) + res, err := queryClient.TotalSupply(gocontext.Background(), &types.QueryTotalSupplyRequest{}) + suite.Require().NoError(err) + genesisSupply := res.Supply + + testCoins := sdk.NewCoins(sdk.NewInt64Coin("test", 400000000)) suite. Require(). - NoError(app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, expectedTotalSupply)) + NoError(app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, testCoins)) - res, err := queryClient.TotalSupply(gocontext.Background(), &types.QueryTotalSupplyRequest{}) + res, err = queryClient.TotalSupply(gocontext.Background(), &types.QueryTotalSupplyRequest{}) suite.Require().NoError(err) suite.Require().NotNil(res) - suite.Require().Equal(expectedTotalSupply, res.Supply) + expectedTotalSupply := genesisSupply.Add(testCoins...) + suite.Require().Equal(2, len(res.Supply)) + suite.Require().Equal(res.Supply, expectedTotalSupply) } func (suite *IntegrationTestSuite) TestQueryTotalSupplyOf() { @@ -353,7 +360,7 @@ func (suite *IntegrationTestSuite) TestGRPCDenomOwners() { expPass: true, numAddrs: 6, hasNext: true, - total: 10, + total: 13, }, "valid request - page 2": { req: &types.QueryDenomOwnersRequest{ @@ -365,9 +372,9 @@ func (suite *IntegrationTestSuite) TestGRPCDenomOwners() { }, }, expPass: true, - numAddrs: 4, + numAddrs: 7, hasNext: false, - total: 10, + total: 13, }, } diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index ca014d4eca08..50aec230dda1 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -5,6 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" @@ -52,7 +53,7 @@ type BaseKeeper struct { ak types.AccountKeeper cdc codec.BinaryCodec - storeKey sdk.StoreKey + storeKey storetypes.StoreKey paramSpace paramtypes.Subspace } @@ -89,7 +90,7 @@ func (k BaseKeeper) GetPaginatedTotalSupply(ctx sdk.Context, pagination *query.P // by using a SendCoinsFromModuleToAccount execution. func NewBaseKeeper( cdc codec.BinaryCodec, - storeKey sdk.StoreKey, + storeKey storetypes.StoreKey, ak types.AccountKeeper, paramSpace paramtypes.Subspace, blockedAddrs map[string]bool, diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index 93de432cfd3e..52d0dc1338e3 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -117,26 +117,31 @@ func (suite *IntegrationTestSuite) TestSupply() { // add module accounts to supply keeper authKeeper, keeper := suite.initKeepersWithmAccPerms(make(map[string]bool)) + genesisSupply, _, err := keeper.GetPaginatedTotalSupply(ctx, &query.PageRequest{}) + require.NoError(err) + initialPower := int64(100) initTokens := suite.app.StakingKeeper.TokensFromConsensusPower(ctx, initialPower) - totalSupply := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens)) + initCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens)) // set burnerAcc balance authKeeper.SetModuleAccount(ctx, burnerAcc) - require.NoError(keeper.MintCoins(ctx, authtypes.Minter, totalSupply)) - require.NoError(keeper.SendCoinsFromModuleToAccount(ctx, authtypes.Minter, burnerAcc.GetAddress(), totalSupply)) + require.NoError(keeper.MintCoins(ctx, authtypes.Minter, initCoins)) + require.NoError(keeper.SendCoinsFromModuleToAccount(ctx, authtypes.Minter, burnerAcc.GetAddress(), initCoins)) total, _, err := keeper.GetPaginatedTotalSupply(ctx, &query.PageRequest{}) require.NoError(err) - require.Equal(totalSupply, total) + + expTotalSupply := initCoins.Add(genesisSupply...) + require.Equal(expTotalSupply, total) // burning all supplied tokens - err = keeper.BurnCoins(ctx, authtypes.Burner, totalSupply) + err = keeper.BurnCoins(ctx, authtypes.Burner, initCoins) require.NoError(err) total, _, err = keeper.GetPaginatedTotalSupply(ctx, &query.PageRequest{}) require.NoError(err) - require.Equal(total.String(), "") + require.Equal(total, genesisSupply) } func (suite *IntegrationTestSuite) TestSendCoinsFromModuleToAccount_Blocklist() { diff --git a/x/bank/keeper/querier_test.go b/x/bank/keeper/querier_test.go index 8404ed360f2f..7eba1f608a2b 100644 --- a/x/bank/keeper/querier_test.go +++ b/x/bank/keeper/querier_test.go @@ -90,10 +90,14 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryAllBalances() { func (suite *IntegrationTestSuite) TestQuerier_QueryTotalSupply() { app, ctx := suite.app, suite.ctx legacyAmino := app.LegacyAmino() - expectedTotalSupply := sdk.NewCoins(sdk.NewInt64Coin("test", 400000000)) + + genesisSupply, _, err := suite.app.BankKeeper.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{Limit: query.MaxLimit}) + suite.Require().NoError(err) + + testCoins := sdk.NewCoins(sdk.NewInt64Coin("test", 400000000)) suite. Require(). - NoError(app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, expectedTotalSupply)) + NoError(app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, testCoins)) req := abci.RequestQuery{ Path: fmt.Sprintf("custom/%s/%s", types.ModuleName, types.QueryTotalSupply), @@ -115,6 +119,8 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryTotalSupply() { var resp types.QueryTotalSupplyResponse suite.Require().NoError(legacyAmino.UnmarshalJSON(res, &resp)) + + expectedTotalSupply := genesisSupply.Add(testCoins...) suite.Require().Equal(expectedTotalSupply, resp.Supply) } diff --git a/x/bank/keeper/send.go b/x/bank/keeper/send.go index b0c38a320e0f..fa77baa5e696 100644 --- a/x/bank/keeper/send.go +++ b/x/bank/keeper/send.go @@ -3,6 +3,7 @@ package keeper import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" @@ -37,7 +38,7 @@ type BaseSendKeeper struct { cdc codec.BinaryCodec ak types.AccountKeeper - storeKey sdk.StoreKey + storeKey storetypes.StoreKey paramSpace paramtypes.Subspace // list of addresses that are restricted from receiving transactions @@ -45,7 +46,7 @@ type BaseSendKeeper struct { } func NewBaseSendKeeper( - cdc codec.BinaryCodec, storeKey sdk.StoreKey, ak types.AccountKeeper, paramSpace paramtypes.Subspace, blockedAddrs map[string]bool, + cdc codec.BinaryCodec, storeKey storetypes.StoreKey, ak types.AccountKeeper, paramSpace paramtypes.Subspace, blockedAddrs map[string]bool, ) BaseSendKeeper { return BaseSendKeeper{ diff --git a/x/bank/keeper/view.go b/x/bank/keeper/view.go index 62fed93c8747..6f178bb7f7e4 100644 --- a/x/bank/keeper/view.go +++ b/x/bank/keeper/view.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" vestexported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported" @@ -34,12 +35,12 @@ type ViewKeeper interface { // BaseViewKeeper implements a read only keeper implementation of ViewKeeper. type BaseViewKeeper struct { cdc codec.BinaryCodec - storeKey sdk.StoreKey + storeKey storetypes.StoreKey ak types.AccountKeeper } // NewBaseViewKeeper returns a new BaseViewKeeper. -func NewBaseViewKeeper(cdc codec.BinaryCodec, storeKey sdk.StoreKey, ak types.AccountKeeper) BaseViewKeeper { +func NewBaseViewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, ak types.AccountKeeper) BaseViewKeeper { return BaseViewKeeper{ cdc: cdc, storeKey: storeKey, diff --git a/x/bank/migrations/v043/store.go b/x/bank/migrations/v043/store.go index 2b3a084d0bf9..4c6b56e2b3ee 100644 --- a/x/bank/migrations/v043/store.go +++ b/x/bank/migrations/v043/store.go @@ -3,6 +3,7 @@ package v043 import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" v040auth "github.com/cosmos/cosmos-sdk/x/auth/migrations/v040" v040bank "github.com/cosmos/cosmos-sdk/x/bank/migrations/v040" @@ -76,7 +77,7 @@ func migrateBalanceKeys(store sdk.KVStore) { // - Change balances prefix to 1 byte // - Change supply to be indexed by denom // - Prune balances & supply with zero coins (ref: https://github.com/cosmos/cosmos-sdk/pull/9229) -func MigrateStore(ctx sdk.Context, storeKey sdk.StoreKey, cdc codec.BinaryCodec) error { +func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) error { store := ctx.KVStore(storeKey) migrateBalanceKeys(store) diff --git a/x/bank/migrations/v045/store.go b/x/bank/migrations/v045/store.go index 35a3545b1141..6a6ee8aa0347 100644 --- a/x/bank/migrations/v045/store.go +++ b/x/bank/migrations/v045/store.go @@ -3,6 +3,7 @@ package v045 import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" v043 "github.com/cosmos/cosmos-sdk/x/bank/migrations/v043" @@ -15,7 +16,7 @@ import ( // - Migrate coin storage to save only amount. // - Add an additional reverse index from denomination to address. // - Remove duplicate denom from denom metadata store key. -func MigrateStore(ctx sdk.Context, storeKey sdk.StoreKey, cdc codec.BinaryCodec) error { +func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) error { store := ctx.KVStore(storeKey) err := addDenomReverseIndex(store, cdc) if err != nil { diff --git a/x/capability/keeper/keeper.go b/x/capability/keeper/keeper.go index 61df229af9f2..cea524563491 100644 --- a/x/capability/keeper/keeper.go +++ b/x/capability/keeper/keeper.go @@ -8,6 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/capability/types" @@ -28,8 +29,8 @@ type ( // a single specific module. Keeper struct { cdc codec.BinaryCodec - storeKey sdk.StoreKey - memKey sdk.StoreKey + storeKey storetypes.StoreKey + memKey storetypes.StoreKey capMap map[uint64]*types.Capability scopedModules map[string]struct{} sealed bool @@ -43,8 +44,8 @@ type ( // passed by other modules. ScopedKeeper struct { cdc codec.BinaryCodec - storeKey sdk.StoreKey - memKey sdk.StoreKey + storeKey storetypes.StoreKey + memKey storetypes.StoreKey capMap map[uint64]*types.Capability module string } @@ -52,7 +53,7 @@ type ( // NewKeeper constructs a new CapabilityKeeper instance and initializes maps // for capability map and scopedModules map. -func NewKeeper(cdc codec.BinaryCodec, storeKey, memKey sdk.StoreKey) *Keeper { +func NewKeeper(cdc codec.BinaryCodec, storeKey, memKey storetypes.StoreKey) *Keeper { return &Keeper{ cdc: cdc, storeKey: storeKey, @@ -108,8 +109,8 @@ func (k *Keeper) InitMemStore(ctx sdk.Context) { memStore := ctx.KVStore(k.memKey) memStoreType := memStore.GetStoreType() - if memStoreType != sdk.StoreTypeMemory { - panic(fmt.Sprintf("invalid memory store type; got %s, expected: %s", memStoreType, sdk.StoreTypeMemory)) + if memStoreType != storetypes.StoreTypeMemory { + panic(fmt.Sprintf("invalid memory store type; got %s, expected: %s", memStoreType, storetypes.StoreTypeMemory)) } // create context with no block gas meter to ensure we do not consume gas during local initialization logic. diff --git a/x/distribution/keeper/allocation_test.go b/x/distribution/keeper/allocation_test.go index 2a4494198dcf..d32b43690cac 100644 --- a/x/distribution/keeper/allocation_test.go +++ b/x/distribution/keeper/allocation_test.go @@ -11,6 +11,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/bank/testutil" + disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types" "github.com/cosmos/cosmos-sdk/x/staking/teststaking" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -48,6 +49,9 @@ func TestAllocateTokensToManyValidators(t *testing.T) { app := simapp.Setup(t, false) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + // reset fee pool + app.DistrKeeper.SetFeePool(ctx, disttypes.InitialFeePool()) + addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.NewInt(1234)) valAddrs := simapp.ConvertAddrsToValAddrs(addrs) tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper) @@ -119,6 +123,9 @@ func TestAllocateTokensTruncation(t *testing.T) { app := simapp.Setup(t, false) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + // reset fee pool + app.DistrKeeper.SetFeePool(ctx, disttypes.InitialFeePool()) + addrs := simapp.AddTestAddrs(app, ctx, 3, sdk.NewInt(1234)) valAddrs := simapp.ConvertAddrsToValAddrs(addrs) tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper) diff --git a/x/distribution/keeper/delegation_test.go b/x/distribution/keeper/delegation_test.go index aefe60c20b01..a1916913c424 100644 --- a/x/distribution/keeper/delegation_test.go +++ b/x/distribution/keeper/delegation_test.go @@ -17,6 +17,9 @@ import ( func TestCalculateRewardsBasic(t *testing.T) { app := simapp.Setup(t, false) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + + app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx) + tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper) addr := simapp.AddTestAddrs(app, ctx, 2, sdk.NewInt(1000)) @@ -273,6 +276,8 @@ func TestWithdrawDelegationRewardsBasic(t *testing.T) { app := simapp.Setup(t, false) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx) + balancePower := int64(1000) balanceTokens := app.StakingKeeper.TokensFromConsensusPower(ctx, balancePower) addr := simapp.AddTestAddrs(app, ctx, 1, sdk.NewInt(1000000000)) @@ -486,6 +491,8 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) { app := simapp.Setup(t, false) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx) + tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper) addr := simapp.AddTestAddrs(app, ctx, 2, sdk.NewInt(1000000000)) valAddrs := simapp.ConvertAddrsToValAddrs(addr) diff --git a/x/distribution/keeper/grpc_query_test.go b/x/distribution/keeper/grpc_query_test.go index 1d80491fdb7d..d51f4a28a0ba 100644 --- a/x/distribution/keeper/grpc_query_test.go +++ b/x/distribution/keeper/grpc_query_test.go @@ -601,6 +601,8 @@ func (suite *KeeperTestSuite) TestGRPCDelegatorWithdrawAddress() { func (suite *KeeperTestSuite) TestGRPCCommunityPool() { app, ctx, queryClient, addrs := suite.app, suite.ctx, suite.queryClient, suite.addrs + // reset fee pool + app.DistrKeeper.SetFeePool(ctx, types.InitialFeePool()) var ( req *types.QueryCommunityPoolRequest diff --git a/x/distribution/keeper/keeper.go b/x/distribution/keeper/keeper.go index 97669cae23a0..9bd8285c31e2 100644 --- a/x/distribution/keeper/keeper.go +++ b/x/distribution/keeper/keeper.go @@ -6,6 +6,7 @@ import ( "github.com/tendermint/tendermint/libs/log" "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/distribution/types" @@ -14,7 +15,7 @@ import ( // Keeper of the distribution store type Keeper struct { - storeKey sdk.StoreKey + storeKey storetypes.StoreKey cdc codec.BinaryCodec paramSpace paramtypes.Subspace authKeeper types.AccountKeeper @@ -28,7 +29,7 @@ type Keeper struct { // NewKeeper creates a new distribution Keeper instance func NewKeeper( - cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramtypes.Subspace, + cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace, ak types.AccountKeeper, bk types.BankKeeper, sk types.StakingKeeper, feeCollectorName string, blockedAddrs map[string]bool, ) Keeper { diff --git a/x/distribution/keeper/keeper_test.go b/x/distribution/keeper/keeper_test.go index 1f9639838bba..9895e420bf80 100644 --- a/x/distribution/keeper/keeper_test.go +++ b/x/distribution/keeper/keeper_test.go @@ -112,6 +112,9 @@ func TestFundCommunityPool(t *testing.T) { app := simapp.Setup(t, false) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + // reset fee pool + app.DistrKeeper.SetFeePool(ctx, types.InitialFeePool()) + addr := simapp.AddTestAddrs(app, ctx, 2, sdk.ZeroInt()) amount := sdk.NewCoins(sdk.NewInt64Coin("stake", 100)) diff --git a/x/distribution/keeper/querier_test.go b/x/distribution/keeper/querier_test.go index 0ffb14bfb6c6..9e1fe7cccce5 100644 --- a/x/distribution/keeper/querier_test.go +++ b/x/distribution/keeper/querier_test.go @@ -119,6 +119,9 @@ func TestQueries(t *testing.T) { app := simapp.Setup(t, false) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + // reset fee pool + app.DistrKeeper.SetFeePool(ctx, types.InitialFeePool()) + addr := simapp.AddTestAddrs(app, ctx, 1, sdk.NewInt(1000000000)) valAddrs := simapp.ConvertAddrsToValAddrs(addr) valOpAddr1 := valAddrs[0] diff --git a/x/distribution/migrations/v043/store.go b/x/distribution/migrations/v043/store.go index 3ec85d3a42e8..b757c7f2ac10 100644 --- a/x/distribution/migrations/v043/store.go +++ b/x/distribution/migrations/v043/store.go @@ -1,6 +1,7 @@ package v043 import ( + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" v040distribution "github.com/cosmos/cosmos-sdk/x/distribution/migrations/v040" ) @@ -9,7 +10,7 @@ import ( // migration includes: // // - Change addresses to be length-prefixed. -func MigrateStore(ctx sdk.Context, storeKey sdk.StoreKey) error { +func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey) error { store := ctx.KVStore(storeKey) MigratePrefixAddress(store, v040distribution.ValidatorOutstandingRewardsPrefix) MigratePrefixAddress(store, v040distribution.DelegatorWithdrawAddrPrefix) diff --git a/x/distribution/module_test.go b/x/distribution/module_test.go index 562621d00f37..70e2e50ea8b0 100644 --- a/x/distribution/module_test.go +++ b/x/distribution/module_test.go @@ -5,7 +5,10 @@ import ( "github.com/stretchr/testify/require" abcitypes "github.com/tendermint/tendermint/abci/types" + tmjson "github.com/tendermint/tendermint/libs/json" + "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/simapp" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -13,16 +16,22 @@ import ( ) func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { - app := simapp.Setup(t, false) - ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + db := dbm.NewMemDB() + encCdc := simapp.MakeTestEncodingConfig() + app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encCdc, simapp.EmptyAppOptions{}) + + genesisState := simapp.GenesisStateWithSingleValidator(t, app) + stateBytes, err := tmjson.Marshal(genesisState) + require.NoError(t, err) app.InitChain( abcitypes.RequestInitChain{ - AppStateBytes: []byte("{}"), + AppStateBytes: stateBytes, ChainId: "test-chain-id", }, ) + ctx := app.BaseApp.NewContext(false, tmproto.Header{}) acc := app.AccountKeeper.GetAccount(ctx, authtypes.NewModuleAddress(types.ModuleName)) require.NotNil(t, acc) } diff --git a/x/distribution/proposal_handler_test.go b/x/distribution/proposal_handler_test.go index 5e109f5e95a6..24be6c98e5ae 100644 --- a/x/distribution/proposal_handler_test.go +++ b/x/distribution/proposal_handler_test.go @@ -58,6 +58,9 @@ func TestProposalHandlerFailed(t *testing.T) { app := simapp.Setup(t, false) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + // reset fee pool + app.DistrKeeper.SetFeePool(ctx, types.InitialFeePool()) + recipient := delAddr1 account := app.AccountKeeper.NewAccountWithAddress(ctx, recipient) diff --git a/x/distribution/simulation/operations_test.go b/x/distribution/simulation/operations_test.go index 1ef25858cd3d..4d70aab2eacf 100644 --- a/x/distribution/simulation/operations_test.go +++ b/x/distribution/simulation/operations_test.go @@ -157,9 +157,11 @@ func (suite *SimTestSuite) testSimulateMsgWithdrawValidatorCommission(tokenName ) suite.app.DistrKeeper.SetValidatorOutstandingRewards(suite.ctx, validator0.GetOperator(), types.ValidatorOutstandingRewards{Rewards: valCommission}) + suite.app.DistrKeeper.SetValidatorOutstandingRewards(suite.ctx, suite.genesisVals[0].GetOperator(), types.ValidatorOutstandingRewards{Rewards: valCommission}) // setup validator accumulated commission suite.app.DistrKeeper.SetValidatorAccumulatedCommission(suite.ctx, validator0.GetOperator(), types.ValidatorAccumulatedCommission{Commission: valCommission}) + suite.app.DistrKeeper.SetValidatorAccumulatedCommission(suite.ctx, suite.genesisVals[0].GetOperator(), types.ValidatorAccumulatedCommission{Commission: valCommission}) // begin a new block suite.app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: suite.app.LastBlockHeight() + 1, AppHash: suite.app.LastCommitID().Hash}}) @@ -167,16 +169,20 @@ func (suite *SimTestSuite) testSimulateMsgWithdrawValidatorCommission(tokenName // execute operation op := simulation.SimulateMsgWithdrawValidatorCommission(suite.app.AccountKeeper, suite.app.BankKeeper, suite.app.DistrKeeper, suite.app.StakingKeeper) operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") - suite.Require().NoError(err) - - var msg types.MsgWithdrawValidatorCommission - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) - - suite.Require().True(operationMsg.OK) - suite.Require().Equal("cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", msg.ValidatorAddress) - suite.Require().Equal(types.TypeMsgWithdrawValidatorCommission, msg.Type()) - suite.Require().Equal(types.ModuleName, msg.Route()) - suite.Require().Len(futureOperations, 0) + if !operationMsg.OK { + suite.Require().Equal("could not find account", operationMsg.Comment) + } else { + suite.Require().NoError(err) + + var msg types.MsgWithdrawValidatorCommission + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + + suite.Require().True(operationMsg.OK) + suite.Require().Equal("cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", msg.ValidatorAddress) + suite.Require().Equal(types.TypeMsgWithdrawValidatorCommission, msg.Type()) + suite.Require().Equal(types.ModuleName, msg.Route()) + suite.Require().Len(futureOperations, 0) + } } // TestSimulateMsgFundCommunityPool tests the normal scenario of a valid message of type TypeMsgFundCommunityPool. @@ -209,8 +215,9 @@ func (suite *SimTestSuite) TestSimulateMsgFundCommunityPool() { type SimTestSuite struct { suite.Suite - ctx sdk.Context - app *simapp.SimApp + ctx sdk.Context + app *simapp.SimApp + genesisVals []stakingtypes.Validator } func (suite *SimTestSuite) SetupTest() { @@ -218,6 +225,9 @@ func (suite *SimTestSuite) SetupTest() { app := simapp.Setup(suite.T(), checkTx) suite.app = app suite.ctx = app.BaseApp.NewContext(checkTx, tmproto.Header{}) + genesisVals := app.StakingKeeper.GetAllValidators(suite.ctx) + suite.Require().Len(genesisVals, 1) + suite.genesisVals = genesisVals } func (suite *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Account { diff --git a/x/epoching/keeper/keeper.go b/x/epoching/keeper/keeper.go index 3047375233b4..f39d324bdf0a 100644 --- a/x/epoching/keeper/keeper.go +++ b/x/epoching/keeper/keeper.go @@ -5,6 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" db "github.com/tendermint/tm-db" ) @@ -22,7 +23,7 @@ var ( // Keeper of the store type Keeper struct { - storeKey sdk.StoreKey + storeKey storetypes.StoreKey cdc codec.BinaryCodec // Used to calculate the estimated next epoch time. // This is local to every node @@ -31,7 +32,7 @@ type Keeper struct { } // NewKeeper creates a epoch queue manager -func NewKeeper(cdc codec.BinaryCodec, key sdk.StoreKey, commitTimeout time.Duration) Keeper { +func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, commitTimeout time.Duration) Keeper { return Keeper{ storeKey: key, cdc: cdc, diff --git a/x/evidence/keeper/keeper.go b/x/evidence/keeper/keeper.go index e913e7ab55ee..366f46b83182 100644 --- a/x/evidence/keeper/keeper.go +++ b/x/evidence/keeper/keeper.go @@ -3,6 +3,7 @@ package keeper import ( "fmt" + storetypes "github.com/cosmos/cosmos-sdk/store/types" tmbytes "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/libs/log" @@ -19,14 +20,14 @@ import ( // module. type Keeper struct { cdc codec.BinaryCodec - storeKey sdk.StoreKey + storeKey storetypes.StoreKey router types.Router stakingKeeper types.StakingKeeper slashingKeeper types.SlashingKeeper } func NewKeeper( - cdc codec.BinaryCodec, storeKey sdk.StoreKey, stakingKeeper types.StakingKeeper, + cdc codec.BinaryCodec, storeKey storetypes.StoreKey, stakingKeeper types.StakingKeeper, slashingKeeper types.SlashingKeeper, ) *Keeper { diff --git a/x/feegrant/keeper/keeper.go b/x/feegrant/keeper/keeper.go index 8e6750463217..5d4d79fabc40 100644 --- a/x/feegrant/keeper/keeper.go +++ b/x/feegrant/keeper/keeper.go @@ -3,6 +3,7 @@ package keeper import ( "fmt" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/tendermint/tendermint/libs/log" "github.com/cosmos/cosmos-sdk/codec" @@ -16,14 +17,14 @@ import ( // It must have a codec with all available allowances registered. type Keeper struct { cdc codec.BinaryCodec - storeKey sdk.StoreKey + storeKey storetypes.StoreKey authKeeper feegrant.AccountKeeper } var _ middleware.FeegrantKeeper = &Keeper{} // NewKeeper creates a fee grant Keeper -func NewKeeper(cdc codec.BinaryCodec, storeKey sdk.StoreKey, ak feegrant.AccountKeeper) Keeper { +func NewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, ak feegrant.AccountKeeper) Keeper { return Keeper{ cdc: cdc, storeKey: storeKey, diff --git a/x/feegrant/simulation/operations_test.go b/x/feegrant/simulation/operations_test.go index 1d6135e72eb7..59554125a0aa 100644 --- a/x/feegrant/simulation/operations_test.go +++ b/x/feegrant/simulation/operations_test.go @@ -75,12 +75,12 @@ func (suite *SimTestSuite) TestWeightedOperations() { }{ { simappparams.DefaultWeightGrantAllowance, - feegrant.ModuleName, + feegrant.MsgGrantAllowance{}.Route(), simulation.TypeMsgGrantAllowance, }, { simappparams.DefaultWeightRevokeAllowance, - feegrant.ModuleName, + feegrant.MsgRevokeAllowance{}.Route(), simulation.TypeMsgRevokeAllowance, }, } diff --git a/x/genutil/gentx_test.go b/x/genutil/gentx_test.go index 55891a0b98b8..5d8289810a09 100644 --- a/x/genutil/gentx_test.go +++ b/x/genutil/gentx_test.go @@ -240,7 +240,7 @@ func (suite *GenTxTestSuite) TestDeliverGenTxs() { sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 10)}, helpers.DefaultGenTxGas, suite.ctx.ChainID(), - []uint64{0}, + []uint64{7}, []uint64{0}, priv1, ) diff --git a/x/gov/genesis_test.go b/x/gov/genesis_test.go index d289af470c80..38750d7ed3cd 100644 --- a/x/gov/genesis_test.go +++ b/x/gov/genesis_test.go @@ -15,8 +15,11 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" "github.com/cosmos/cosmos-sdk/x/gov" "github.com/cosmos/cosmos-sdk/x/gov/types" + "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) func TestImportExportQueues(t *testing.T) { @@ -54,6 +57,8 @@ func TestImportExportQueues(t *testing.T) { authGenState := auth.ExportGenesis(ctx, app.AccountKeeper) bankGenState := app.BankKeeper.ExportGenesis(ctx) + stakingGenState := staking.ExportGenesis(ctx, app.StakingKeeper) + distributionGenState := app.DistrKeeper.ExportGenesis(ctx) // export the state and import it into a new app govGenState := gov.ExportGenesis(ctx, app.GovKeeper) @@ -62,6 +67,8 @@ func TestImportExportQueues(t *testing.T) { genesisState[authtypes.ModuleName] = app.AppCodec().MustMarshalJSON(authGenState) genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenState) genesisState[types.ModuleName] = app.AppCodec().MustMarshalJSON(govGenState) + genesisState[stakingtypes.ModuleName] = app.AppCodec().MustMarshalJSON(stakingGenState) + genesisState[distributiontypes.ModuleName] = app.AppCodec().MustMarshalJSON(distributionGenState) stateBytes, err := json.MarshalIndent(genesisState, "", " ") if err != nil { diff --git a/x/gov/keeper/keeper.go b/x/gov/keeper/keeper.go index 9e639fe5d0fc..dc2a2e6bfa25 100644 --- a/x/gov/keeper/keeper.go +++ b/x/gov/keeper/keeper.go @@ -7,6 +7,7 @@ import ( "github.com/tendermint/tendermint/libs/log" "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -27,7 +28,7 @@ type Keeper struct { hooks types.GovHooks // The (unexposed) keys used to access the stores from the Context. - storeKey sdk.StoreKey + storeKey storetypes.StoreKey // The codec codec for binary encoding/decoding. cdc codec.BinaryCodec @@ -44,7 +45,7 @@ type Keeper struct { // // CONTRACT: the parameter Subspace must have the param key table already initialized func NewKeeper( - cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace types.ParamSubspace, + cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace types.ParamSubspace, authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, sk types.StakingKeeper, rtr types.Router, ) Keeper { diff --git a/x/gov/keeper/msg_server.go b/x/gov/keeper/msg_server.go index 89876271336e..a3b42b9b3a39 100644 --- a/x/gov/keeper/msg_server.go +++ b/x/gov/keeper/msg_server.go @@ -7,7 +7,7 @@ import ( "github.com/armon/go-metrics" - store "github.com/cosmos/cosmos-sdk/store/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -39,7 +39,7 @@ func (k msgServer) SubmitProposal(goCtx context.Context, msg *types.MsgSubmitPro // ref: https://github.com/cosmos/cosmos-sdk/issues/9683 ctx.GasMeter().ConsumeGas( - 3*store.KVGasConfig().WriteCostPerByte*uint64(len(bytes)), + 3*storetypes.KVGasConfig().WriteCostPerByte*uint64(len(bytes)), "submit proposal", ) diff --git a/x/gov/migrations/v043/store.go b/x/gov/migrations/v043/store.go index 2de980dbab37..b71c6b8d7430 100644 --- a/x/gov/migrations/v043/store.go +++ b/x/gov/migrations/v043/store.go @@ -5,6 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -73,7 +74,7 @@ func migrateStoreWeightedVotes(store sdk.KVStore, cdc codec.BinaryCodec) error { // migration includes: // // - Change addresses to be length-prefixed. -func MigrateStore(ctx sdk.Context, storeKey sdk.StoreKey, cdc codec.BinaryCodec) error { +func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) error { store := ctx.KVStore(storeKey) migratePrefixProposalAddress(store, types.DepositsKeyPrefix) migratePrefixProposalAddress(store, types.VotesKeyPrefix) diff --git a/x/gov/module_test.go b/x/gov/module_test.go index fa07f9e30154..c43f570dbac5 100644 --- a/x/gov/module_test.go +++ b/x/gov/module_test.go @@ -5,7 +5,10 @@ import ( "github.com/stretchr/testify/require" abcitypes "github.com/tendermint/tendermint/abci/types" + tmjson "github.com/tendermint/tendermint/libs/json" + "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/simapp" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -13,16 +16,22 @@ import ( ) func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { - app := simapp.Setup(t, false) - ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + db := dbm.NewMemDB() + encCdc := simapp.MakeTestEncodingConfig() + app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encCdc, simapp.EmptyAppOptions{}) + + genesisState := simapp.GenesisStateWithSingleValidator(t, app) + stateBytes, err := tmjson.Marshal(genesisState) + require.NoError(t, err) app.InitChain( abcitypes.RequestInitChain{ - AppStateBytes: []byte("{}"), + AppStateBytes: stateBytes, ChainId: "test-chain-id", }, ) + ctx := app.BaseApp.NewContext(false, tmproto.Header{}) acc := app.AccountKeeper.GetAccount(ctx, authtypes.NewModuleAddress(types.ModuleName)) require.NotNil(t, acc) } diff --git a/x/group/go.mod b/x/group/go.mod index b8311f6d68df..9763835d44eb 100644 --- a/x/group/go.mod +++ b/x/group/go.mod @@ -4,11 +4,11 @@ module github.com/cosmos/cosmos-sdk/x/group require ( github.com/cockroachdb/apd/v2 v2.0.2 + github.com/cosmos/cosmos-proto v0.0.0-20210914142853-23ed61ac79ce github.com/cosmos/cosmos-sdk v0.44.0 github.com/gogo/protobuf v1.3.3 - github.com/regen-network/cosmos-proto v0.3.1 github.com/stretchr/testify v1.7.0 - google.golang.org/grpc v1.40.0 + google.golang.org/grpc v1.41.0 google.golang.org/protobuf v1.27.1 pgregory.net/rapid v0.4.7 ) @@ -27,11 +27,11 @@ require ( github.com/dgraph-io/ristretto v0.0.3 // indirect github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect github.com/dustin/go-humanize v1.0.0 // indirect - github.com/fsnotify/fsnotify v1.4.9 // indirect + github.com/fsnotify/fsnotify v1.5.1 // indirect github.com/go-kit/kit v0.10.0 // indirect github.com/go-logfmt/logfmt v0.5.0 // indirect github.com/golang/protobuf v1.5.2 // indirect - github.com/golang/snappy v0.0.3-0.20201103224600-674baa8c7fc3 // indirect + github.com/golang/snappy v0.0.3 // indirect github.com/google/btree v1.0.0 // indirect github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect github.com/gtank/merlin v0.1.1 // indirect @@ -44,14 +44,14 @@ require ( github.com/magiconair/properties v1.8.5 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643 // indirect - github.com/mitchellh/mapstructure v1.4.1 // indirect - github.com/pelletier/go-toml v1.9.3 // indirect + github.com/mitchellh/mapstructure v1.4.2 // indirect + github.com/pelletier/go-toml v1.9.4 // indirect github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_golang v1.11.0 // indirect github.com/prometheus/client_model v0.2.0 // indirect - github.com/prometheus/common v0.30.0 // indirect + github.com/prometheus/common v0.31.1 // indirect github.com/prometheus/procfs v0.6.0 // indirect github.com/sasha-s/go-deadlock v0.2.1-0.20190427202633-1595213edefa // indirect github.com/spf13/afero v1.6.0 // indirect @@ -59,7 +59,7 @@ require ( github.com/spf13/cobra v1.2.1 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - github.com/spf13/viper v1.8.1 // indirect + github.com/spf13/viper v1.9.0 // indirect github.com/subosito/gotenv v1.2.0 // indirect github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca // indirect github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect @@ -67,14 +67,15 @@ require ( github.com/tendermint/tendermint v0.34.13 // indirect github.com/tendermint/tm-db v0.6.4 // indirect go.etcd.io/bbolt v1.3.5 // indirect - golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect + golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f // indirect golang.org/x/sys v0.0.0-20210903071746-97244b99971b // indirect golang.org/x/text v0.3.6 // indirect - google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect - gopkg.in/ini.v1 v1.62.0 // indirect + google.golang.org/genproto v0.0.0-20210828152312-66f60bf46e71 // indirect + gopkg.in/ini.v1 v1.63.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect + sigs.k8s.io/yaml v1.3.0 // indirect ) replace google.golang.org/grpc => google.golang.org/grpc v1.33.2 diff --git a/x/group/go.sum b/x/group/go.sum index a5954f1d69a6..d7eb661be9ac 100644 --- a/x/group/go.sum +++ b/x/group/go.sum @@ -18,6 +18,11 @@ cloud.google.com/go v0.74.0/go.mod h1:VV1xSbzvo+9QJOxLDaJfTjx5e+MePCpCWwvftOeQmW cloud.google.com/go v0.78.0/go.mod h1:QjdrLG0uq+YwhjoVOLsS1t7TW8fs36kLs4XO5R5ECHg= cloud.google.com/go v0.79.0/go.mod h1:3bzgcEeQlzbuEAYu4mrWhKqWjmpprinYgKJLgKHnbb8= cloud.google.com/go v0.81.0/go.mod h1:mk/AM35KwGk/Nm2YSeZbxXdrNK3KZOYHmLkOqC2V6E0= +cloud.google.com/go v0.83.0/go.mod h1:Z7MJUsANfY0pYPdw0lbnivPx4/vhy/e2FEkSkF7vAVY= +cloud.google.com/go v0.84.0/go.mod h1:RazrYuxIK6Kb7YrzzhPoLmCVzl7Sup4NrbKPg8KHSUM= +cloud.google.com/go v0.87.0/go.mod h1:TpDYlFy7vuLzZMMZ+B6iRiELaY7z/gJPaqbMx6mlWcY= +cloud.google.com/go v0.90.0/go.mod h1:kRX0mNRHe0e2rC6oNakvwQqzyDmg57xJ+SZU1eT2aDQ= +cloud.google.com/go v0.93.3/go.mod h1:8utlLll2EF5XMAV15woO4lSbWQlk8rer9aLOfLh7+YI= cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= @@ -27,6 +32,7 @@ cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM7 cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= +cloud.google.com/go/firestore v1.6.0/go.mod h1:afJwI0vaXwAG54kI7A//lP/lSPDkQORQuMkv56TxEPU= cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= @@ -78,6 +84,7 @@ github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmV github.com/armon/go-metrics v0.3.9 h1:O2sNqxBdvq8Eq5xmzljcYzAORli6RWCvEym4cJf9m18= github.com/armon/go-metrics v0.3.9/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A= github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU= github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= @@ -148,6 +155,8 @@ github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfc github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cosmos/btcutil v1.0.4 h1:n7C2ngKXo7UC9gNyMNLbzqz7Asuf+7Qv4gnX/rOdQ44= github.com/cosmos/btcutil v1.0.4/go.mod h1:Ffqc8Hn6TJUdDgHBwIZLtrLQC1KdJ9jGJl/TvgUaxbU= +github.com/cosmos/cosmos-proto v0.0.0-20210914142853-23ed61ac79ce h1:nin7WtIMETZ8LezEYa5e9/iqyEgQka1x0cQYqgUeTGM= +github.com/cosmos/cosmos-proto v0.0.0-20210914142853-23ed61ac79ce/go.mod h1:g2Q3cd94kOBVRAv7ahdtO27yUc4cpNuHGnI40qanl1k= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/iavl v0.15.0-rc3.0.20201009144442-230e9bdf52cd/go.mod h1:3xOIaNNX19p0QrX0VqWa6voPRoJRGGYtny+DH8NEPvE= @@ -198,6 +207,7 @@ github.com/facebookgo/stack v0.0.0-20160209184415-751773369052/go.mod h1:UbMTZqL github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870 h1:E2s37DuLxFhQDg5gKsWoLBOB0n+ZW8s599zru8FJ2/Y= github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870/go.mod h1:5tD+neXqOorC30/tWg0LCSkrqj/AR6gu8yY8/fpw1q0= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= @@ -205,8 +215,9 @@ github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVB github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20= github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI= +github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -241,6 +252,7 @@ github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8= github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= +github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -262,8 +274,8 @@ github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/golang/snappy v0.0.3-0.20201103224600-674baa8c7fc3 h1:ur2rms48b3Ep1dxh7aUV2FZEQ8jEVO2F6ILKx8ofkAg= -github.com/golang/snappy v0.0.3-0.20201103224600-674baa8c7fc3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA= +github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= @@ -277,14 +289,16 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/martian/v3 v3.2.1/go.mod h1:oBOf6HBosgwRXnUGWUB05QECsc6uvmMiJ3+6W4l/CUk= github.com/google/orderedcode v0.0.1 h1:UzfcAexk9Vhv8+9pNOgRu41f16lHq725vPwnSeiG/Us= github.com/google/orderedcode v0.0.1/go.mod h1:iVyU4/qPKHY5h/wSd6rZZCDcLJNxiWO6dvsYES2Sb20= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= @@ -298,12 +312,15 @@ github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= +github.com/googleapis/gax-go/v2 v2.1.0/go.mod h1:Q3nei7sK6ybPYH7twZdmQpAd1MKb7pfu6SK+H1/DsU0= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4= @@ -335,17 +352,22 @@ github.com/gtank/ristretto255 v0.1.2 h1:JEqUCPA1NvLq5DwYtuzigd7ss8fwbYay9fi4/5uM github.com/gtank/ristretto255 v0.1.2/go.mod h1:Ph5OpO6c7xKUGROZfWVLiJf9icMDwUeIvY4OmlYW69o= github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE= +github.com/hashicorp/consul/api v1.10.1/go.mod h1:XjsvQN+RJGWI2TWy1/kqaE16HrR2J/FWgkYjdZQsX9M= github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= +github.com/hashicorp/consul/sdk v0.8.0/go.mod h1:GBvyrGALthsZObzUGsfgHZQDXjg4lOjagTIwIR1vPms= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-hclog v0.12.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= github.com/hashicorp/go-immutable-radix v1.0.0 h1:AKDB1HM5PWEA7i4nhcpwOrO2byshxBjXVn/J/3+z5/0= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA= github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= +github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8= github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= @@ -361,8 +383,11 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= +github.com/hashicorp/mdns v1.0.1/go.mod h1:4gW7WsVCke5TE7EPeYliwHlRUyBtfCwuFwuMg2DmyNY= github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= +github.com/hashicorp/memberlist v0.2.2/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= +github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk= github.com/hdevalence/ed25519consensus v0.0.0-20210204194344-59a8610d2b87 h1:uUjLpLt6bVvZ72SQc/B4dXcPBw4Vgd7soowdRl52qEM= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg= @@ -388,7 +413,6 @@ github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/ github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= -github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= @@ -396,13 +420,13 @@ github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d h1:Z+RDyXzjKE0 github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= -github.com/kkdai/bstream v1.0.0/go.mod h1:FDnDOHt5Yx4p3FaHcioFT0QjDOtgUpvjeZqAs+NVZZA= github.com/klauspost/compress v1.11.7 h1:0hzRabrMN4tSTvMfnL3SCv1ZGeAP23ynzodBgaHeMeg= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= @@ -418,18 +442,26 @@ github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czP github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls= github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= +github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= +github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643 h1:hLDRPB66XQT/8+wG9WsDpiCvZf1yKO7sz7scAjSlBa0= github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643/go.mod h1:43+3pMjjKimDBf5Kr4ZFNGbLql1zKkbImw+fZbw3geM= github.com/minio/highwayhash v1.0.1 h1:dZ6IIu8Z14VlC0VpfKofAhCy74wu/Qb5gcn52yWoz/0= github.com/minio/highwayhash v1.0.1/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= +github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= @@ -438,8 +470,9 @@ github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS4 github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag= github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/mapstructure v1.4.2 h1:6h7AQ0yhTcIsmFmnAwQls75jp2Gzs4iB8W7pjMO+rqo= +github.com/mitchellh/mapstructure v1.4.2/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/moby/sys/mountinfo v0.4.1/go.mod h1:rEr8tzG/lsIZHBtN/JjGG+LMYx9eXgW2JI+6q0qou+A= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -497,8 +530,9 @@ github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0Mw github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= -github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ= github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= +github.com/pelletier/go-toml v1.9.4 h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhECwM= +github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac= github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp0hoxKjt1H5pDo6utceo3dQVK3I5XQ= github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o= @@ -513,6 +547,7 @@ github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= +github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= @@ -539,8 +574,8 @@ github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8b github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= github.com/prometheus/common v0.14.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc= -github.com/prometheus/common v0.30.0 h1:JEkYlQnpzrzQFxi6gnukFPdQ+ac82oRhzMcIduJu/Ug= -github.com/prometheus/common v0.30.0/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls= +github.com/prometheus/common v0.31.1 h1:d18hG4PkHnNAKNMOmFuXFaiY8Us0nird/2m60uS1AMs= +github.com/prometheus/common v0.31.1/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= @@ -556,7 +591,6 @@ github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqn github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 h1:MkV+77GLUNo5oJ0jf870itWm3D0Sjh7+Za9gazKc5LQ= github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/regen-network/cosmos-proto v0.3.1 h1:rV7iM4SSFAagvy8RiyhiACbWEGotmqzywPxOvwMdxcg= -github.com/regen-network/cosmos-proto v0.3.1/go.mod h1:jO0sVX6a1B36nmE8C9xBFXpNwWejXC7QqCOnH3O0+YM= github.com/regen-network/protobuf v1.3.3-alpha.regen.1 h1:OHEc+q5iIAXpqiqFKeLpu5NwTIkVXUs48vFMwzqpqY4= github.com/regen-network/protobuf v1.3.3-alpha.regen.1/go.mod h1:2DjTFR1HhMQhiWC5sZ4OhQ3+NtdbZ6oBDKQwq5Ou+FI= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= @@ -568,6 +602,7 @@ github.com/rs/zerolog v1.25.0 h1:Rj7XygbUHKUlDPcVdoLyR91fJBsduXj5fRxyqIQj/II= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= +github.com/sagikazarmark/crypt v0.1.0/go.mod h1:B/mN0msZuINBtQ1zZLEQcegFJJf9vnYIR88KRMEuODE= github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= github.com/sasha-s/go-deadlock v0.2.0/go.mod h1:StQn567HiB1fF2yJ44N9au7wOhrPS3iZqiDbRupzT10= github.com/sasha-s/go-deadlock v0.2.1-0.20190427202633-1595213edefa h1:0U2s5loxrTy6/VgfVoLuVLFJcURKLH49ie0zSch7gh4= @@ -581,9 +616,7 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/snikch/goodman v0.0.0-20171125024755-10e37e294daa/go.mod h1:oJyF+mSPHbB5mVY2iO9KV3pTt/QbIkGaO8gQ2WrDbP4= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= @@ -615,8 +648,9 @@ github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= -github.com/spf13/viper v1.8.1 h1:Kq1fyeebqsBfbjZj4EL7gj2IO0mMaiyjYUWcUsl2O44= github.com/spf13/viper v1.8.1/go.mod h1:o0Pch8wJ9BVSWGQMbra6iw0oQ5oktSIBaujf1rJH9Ns= +github.com/spf13/viper v1.9.0 h1:yR6EXjTp0y0cLN8OZg1CRZmOBdI88UcGkhgyJhu6nZk= +github.com/spf13/viper v1.9.0/go.mod h1:+i6ajR7OX2XaiBkrcZJFK21htRk7eDeLg7+O6bhUPP4= github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI= @@ -702,17 +736,17 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= -golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a h1:kr2P4QFmQr29mSLA43kwrOcgcReGTfbE9N577tCTuBc= -golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= +golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ= +golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -797,6 +831,7 @@ golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f h1:w6wWR0H+nyVpbSAQbzVEIACVyr/h8l/BEkY6Sokc7Eg= golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= @@ -813,6 +848,9 @@ golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210402161424-2e8d93401602/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210805134026-6f1e6394065a/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -834,6 +872,7 @@ golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -846,9 +885,11 @@ golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191115151921-52ab43148777/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -857,7 +898,9 @@ golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -892,8 +935,14 @@ golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210426230700-d19ff857e887/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210903071746-97244b99971b h1:3Dq0eVHn0uaQJmPO+/aYPI/fRMqdrVDbu7MQcku54gg= golang.org/x/sys v0.0.0-20210903071746-97244b99971b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= @@ -925,6 +974,7 @@ golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgw golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -964,7 +1014,11 @@ golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -993,6 +1047,12 @@ google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjR google.golang.org/api v0.41.0/go.mod h1:RkxM5lITDfTzmyKFPt+wGrCJbVfniCr2ool8kTBzRTU= google.golang.org/api v0.43.0/go.mod h1:nQsDGjRXMo4lvh5hP0TKqF244gqhGcr/YSIykhUk/94= google.golang.org/api v0.44.0/go.mod h1:EBOGZqzyhtvMDoxwS97ctnh0zUmYY6CxqXsc1AvkYD8= +google.golang.org/api v0.47.0/go.mod h1:Wbvgpq1HddcWVtzsVLyfLp8lDg6AA241LmgIL59tHXo= +google.golang.org/api v0.48.0/go.mod h1:71Pr1vy+TAZRPkPs/xlCf5SsU8WjuAWv1Pfjbtukyy4= +google.golang.org/api v0.50.0/go.mod h1:4bNT5pAuq5ji4SRZm+5QIkjny9JAyVD/3gaSihNefaw= +google.golang.org/api v0.51.0/go.mod h1:t4HdrdoNgyN5cbEfm7Lum0lcLDLiise1F8qDKX00sOU= +google.golang.org/api v0.54.0/go.mod h1:7C4bFFOvVDGXjfDTAsgGwDgAxRDeQ4X8NvUedIt6z3k= +google.golang.org/api v0.56.0/go.mod h1:38yMfeP1kfjsl8isn0tliTjIb1rJXcQi4UXlbqivdVE= google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -1046,10 +1106,22 @@ google.golang.org/genproto v0.0.0-20210303154014-9728d6b83eeb/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20210310155132-4ce2db91004e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210319143718-93e7006c17a6/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210402141018-6c239bbf2bb1/go.mod h1:9lPAdzaEmUacj36I+k7YKbEc5CXzPIeORRgDAUOu28A= -google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c h1:wtujag7C+4D6KMoulW9YauvK2lgdvCMS260jsqqBXr0= +google.golang.org/genproto v0.0.0-20210513213006-bf773b8c8384/go.mod h1:P3QM42oQyzQSnHPnZ/vqoCdDmzH28fzWByN9asMeM8A= google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= +google.golang.org/genproto v0.0.0-20210604141403-392c879c8b08/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= +google.golang.org/genproto v0.0.0-20210608205507-b6d2f5bf0d7d/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= +google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= +google.golang.org/genproto v0.0.0-20210713002101-d411969a0d9a/go.mod h1:AxrInvYm1dci+enl5hChSFPOmmUF1+uAa/UsgNRWd7k= +google.golang.org/genproto v0.0.0-20210716133855-ce7ef5c701ea/go.mod h1:AxrInvYm1dci+enl5hChSFPOmmUF1+uAa/UsgNRWd7k= +google.golang.org/genproto v0.0.0-20210728212813-7823e685a01f/go.mod h1:ob2IJxKrgPT52GcgX759i1sleT07tiKowYBGbczaW48= +google.golang.org/genproto v0.0.0-20210805201207-89edb61ffb67/go.mod h1:ob2IJxKrgPT52GcgX759i1sleT07tiKowYBGbczaW48= +google.golang.org/genproto v0.0.0-20210813162853-db860fec028c/go.mod h1:cFeNkxwySK631ADgubI+/XFU/xp8FD5KIVV4rj8UC5w= +google.golang.org/genproto v0.0.0-20210821163610-241b8fcbd6c8/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= +google.golang.org/genproto v0.0.0-20210828152312-66f60bf46e71 h1:z+ErRPu0+KS02Td3fOAgdX+lnPDh/VyaABEJPD4JRQs= +google.golang.org/genproto v0.0.0-20210828152312-66f60bf46e71/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o= google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= +google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -1062,6 +1134,7 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= @@ -1076,8 +1149,9 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o= gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/ini.v1 v1.62.0 h1:duBzk771uxoUuOlyRLkHsygud9+5lrlGjdFBb4mSKDU= gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/ini.v1 v1.63.2 h1:tGK/CyBg7SMzb60vP1M03vNZ3VDu3wGQJwn7Sxi9r3c= +gopkg.in/ini.v1 v1.63.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= @@ -1110,4 +1184,6 @@ rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8 rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= +sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= +sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU= diff --git a/x/mint/keeper/keeper.go b/x/mint/keeper/keeper.go index b010204e8a18..fd064ff7b4d6 100644 --- a/x/mint/keeper/keeper.go +++ b/x/mint/keeper/keeper.go @@ -4,6 +4,7 @@ import ( "github.com/tendermint/tendermint/libs/log" "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/mint/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" @@ -12,7 +13,7 @@ import ( // Keeper of the mint store type Keeper struct { cdc codec.BinaryCodec - storeKey sdk.StoreKey + storeKey storetypes.StoreKey paramSpace paramtypes.Subspace stakingKeeper types.StakingKeeper bankKeeper types.BankKeeper @@ -21,7 +22,7 @@ type Keeper struct { // NewKeeper creates a new mint Keeper instance func NewKeeper( - cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramtypes.Subspace, + cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace, sk types.StakingKeeper, ak types.AccountKeeper, bk types.BankKeeper, feeCollectorName string, ) Keeper { diff --git a/x/mint/module_test.go b/x/mint/module_test.go index d35f2f8244d1..ecf0a1511ba1 100644 --- a/x/mint/module_test.go +++ b/x/mint/module_test.go @@ -5,7 +5,10 @@ import ( "github.com/stretchr/testify/require" abcitypes "github.com/tendermint/tendermint/abci/types" + tmjson "github.com/tendermint/tendermint/libs/json" + "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/simapp" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -13,16 +16,22 @@ import ( ) func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { - app := simapp.Setup(t, false) - ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + db := dbm.NewMemDB() + encCdc := simapp.MakeTestEncodingConfig() + app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encCdc, simapp.EmptyAppOptions{}) + + genesisState := simapp.GenesisStateWithSingleValidator(t, app) + stateBytes, err := tmjson.Marshal(genesisState) + require.NoError(t, err) app.InitChain( abcitypes.RequestInitChain{ - AppStateBytes: []byte("{}"), + AppStateBytes: stateBytes, ChainId: "test-chain-id", }, ) + ctx := app.BaseApp.NewContext(false, tmproto.Header{}) acc := app.AccountKeeper.GetAccount(ctx, authtypes.NewModuleAddress(types.ModuleName)) require.NotNil(t, acc) } diff --git a/x/params/keeper/common_test.go b/x/params/keeper/common_test.go index e5bebaf09b06..20bba1944d64 100644 --- a/x/params/keeper/common_test.go +++ b/x/params/keeper/common_test.go @@ -3,12 +3,13 @@ package keeper_test import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/simapp" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" ) -func testComponents() (*codec.LegacyAmino, sdk.Context, sdk.StoreKey, sdk.StoreKey, paramskeeper.Keeper) { +func testComponents() (*codec.LegacyAmino, sdk.Context, storetypes.StoreKey, storetypes.StoreKey, paramskeeper.Keeper) { marshaler := simapp.MakeTestEncodingConfig().Codec legacyAmino := createTestCodec() mkey := sdk.NewKVStoreKey("test") diff --git a/x/params/keeper/keeper.go b/x/params/keeper/keeper.go index 8a0e708aeb3d..362231a56ad5 100644 --- a/x/params/keeper/keeper.go +++ b/x/params/keeper/keeper.go @@ -1,25 +1,25 @@ package keeper import ( - "github.com/tendermint/tendermint/libs/log" - "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cosmos/cosmos-sdk/x/params/types/proposal" + "github.com/tendermint/tendermint/libs/log" ) // Keeper of the global paramstore type Keeper struct { cdc codec.BinaryCodec legacyAmino *codec.LegacyAmino - key sdk.StoreKey - tkey sdk.StoreKey + key storetypes.StoreKey + tkey storetypes.StoreKey spaces map[string]*types.Subspace } // NewKeeper constructs a params keeper -func NewKeeper(cdc codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey sdk.StoreKey) Keeper { +func NewKeeper(cdc codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey storetypes.StoreKey) Keeper { return Keeper{ cdc: cdc, legacyAmino: legacyAmino, diff --git a/x/params/keeper/keeper_test.go b/x/params/keeper/keeper_test.go index 043e715ca2c4..92e2afb9185e 100644 --- a/x/params/keeper/keeper_test.go +++ b/x/params/keeper/keeper_test.go @@ -26,10 +26,9 @@ type KeeperTestSuite struct { } func (suite *KeeperTestSuite) SetupTest() { - app := simapp.Setup(suite.T(), true) - ctx := app.BaseApp.NewContext(true, tmproto.Header{}) + suite.app = simapp.Setup(suite.T(), false) + suite.ctx = suite.app.BaseApp.NewContext(false, tmproto.Header{}) - suite.app, suite.ctx = app, ctx queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.app.InterfaceRegistry()) proposal.RegisterQueryServer(queryHelper, suite.app.ParamsKeeper) suite.queryClient = proposal.NewQueryClient(queryHelper) diff --git a/x/params/types/subspace.go b/x/params/types/subspace.go index 541277dcf612..dd316cbd42ef 100644 --- a/x/params/types/subspace.go +++ b/x/params/types/subspace.go @@ -6,6 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -23,14 +24,14 @@ const ( type Subspace struct { cdc codec.BinaryCodec legacyAmino *codec.LegacyAmino - key sdk.StoreKey // []byte -> []byte, stores parameter - tkey sdk.StoreKey // []byte -> bool, stores parameter change + key storetypes.StoreKey // []byte -> []byte, stores parameter + tkey storetypes.StoreKey // []byte -> bool, stores parameter change name []byte table KeyTable } // NewSubspace constructs a store with namestore -func NewSubspace(cdc codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key sdk.StoreKey, tkey sdk.StoreKey, name string) Subspace { +func NewSubspace(cdc codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key storetypes.StoreKey, tkey storetypes.StoreKey, name string) Subspace { return Subspace{ cdc: cdc, legacyAmino: legacyAmino, diff --git a/x/params/types/subspace_test.go b/x/params/types/subspace_test.go index d09e9c26b532..fa1d1a36ecb4 100644 --- a/x/params/types/subspace_test.go +++ b/x/params/types/subspace_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/stretchr/testify/suite" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -31,8 +32,8 @@ func (suite *SubspaceTestSuite) SetupTest() { db := dbm.NewMemDB() ms := store.NewCommitMultiStore(db) - ms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db) - ms.MountStoreWithDB(tkey, sdk.StoreTypeTransient, db) + ms.MountStoreWithDB(key, storetypes.StoreTypeIAVL, db) + ms.MountStoreWithDB(tkey, storetypes.StoreTypeTransient, db) suite.NoError(ms.LoadLatestVersion()) encCfg := simapp.MakeTestEncodingConfig() diff --git a/x/slashing/keeper/keeper.go b/x/slashing/keeper/keeper.go index 179bc860dd19..dbec306bfda1 100644 --- a/x/slashing/keeper/keeper.go +++ b/x/slashing/keeper/keeper.go @@ -3,6 +3,7 @@ package keeper import ( "fmt" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/tendermint/tendermint/libs/log" "github.com/cosmos/cosmos-sdk/codec" @@ -13,14 +14,14 @@ import ( // Keeper of the slashing store type Keeper struct { - storeKey sdk.StoreKey + storeKey storetypes.StoreKey cdc codec.BinaryCodec sk types.StakingKeeper paramspace types.ParamSubspace } // NewKeeper creates a slashing keeper -func NewKeeper(cdc codec.BinaryCodec, key sdk.StoreKey, sk types.StakingKeeper, paramspace types.ParamSubspace) Keeper { +func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, sk types.StakingKeeper, paramspace types.ParamSubspace) Keeper { // set KeyTable if it has not already been set if !paramspace.HasKeyTable() { paramspace = paramspace.WithKeyTable(types.ParamKeyTable()) diff --git a/x/slashing/keeper/keeper_test.go b/x/slashing/keeper/keeper_test.go index a5bdd4e0aac2..7385c1f4d7e2 100644 --- a/x/slashing/keeper/keeper_test.go +++ b/x/slashing/keeper/keeper_test.go @@ -119,6 +119,8 @@ func TestHandleNewValidator(t *testing.T) { require.Equal(t, stakingtypes.Bonded, validator.GetStatus()) bondPool := app.StakingKeeper.GetBondedPool(ctx) expTokens := app.StakingKeeper.TokensFromConsensusPower(ctx, 100) + // adding genesis validator tokens + expTokens = expTokens.Add(app.StakingKeeper.TokensFromConsensusPower(ctx, 1)) require.True(t, expTokens.Equal(app.BankKeeper.GetBalance(ctx, bondPool.GetAddress(), app.StakingKeeper.BondDenom(ctx)).Amount)) } diff --git a/x/slashing/migrations/v043/store.go b/x/slashing/migrations/v043/store.go index 20878352a69f..15da0982e27c 100644 --- a/x/slashing/migrations/v043/store.go +++ b/x/slashing/migrations/v043/store.go @@ -1,6 +1,7 @@ package v043 import ( + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" v043distribution "github.com/cosmos/cosmos-sdk/x/distribution/migrations/v043" v040slashing "github.com/cosmos/cosmos-sdk/x/slashing/migrations/v040" @@ -10,7 +11,7 @@ import ( // migration includes: // // - Change addresses to be length-prefixed. -func MigrateStore(ctx sdk.Context, storeKey sdk.StoreKey) error { +func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey) error { store := ctx.KVStore(storeKey) v043distribution.MigratePrefixAddress(store, v040slashing.ValidatorSigningInfoKeyPrefix) v043distribution.MigratePrefixAddressBytes(store, v040slashing.ValidatorMissedBlockBitArrayKeyPrefix) diff --git a/x/slashing/simulation/operations_test.go b/x/slashing/simulation/operations_test.go index fa7a6edf3ec4..a0dbffb1f360 100644 --- a/x/slashing/simulation/operations_test.go +++ b/x/slashing/simulation/operations_test.go @@ -8,12 +8,17 @@ import ( "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + tmtypes "github.com/tendermint/tendermint/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/simapp" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/bank/testutil" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" "github.com/cosmos/cosmos-sdk/x/slashing/simulation" @@ -23,16 +28,14 @@ import ( // TestWeightedOperations tests the weights of the operations. func TestWeightedOperations(t *testing.T) { - app, ctx := createTestApp(t, false) + s := rand.NewSource(1) + r := rand.New(s) + app, ctx, accs := createTestApp(t, false, r, 3) ctx.WithChainID("test-chain") cdc := app.AppCodec() appParams := make(simtypes.AppParams) - s := rand.NewSource(1) - r := rand.New(s) - accs := simtypes.RandomAccounts(r, 3) - expected := []struct { weight int opMsgRoute string @@ -54,14 +57,15 @@ func TestWeightedOperations(t *testing.T) { // TestSimulateMsgUnjail tests the normal scenario of a valid message of type types.MsgUnjail. // Abonormal scenarios, where the message is created by an errors, are not tested here. func TestSimulateMsgUnjail(t *testing.T) { - app, ctx := createTestApp(t, false) + // setup 3 accounts + s := rand.NewSource(5) + r := rand.New(s) + app, ctx, accounts := createTestApp(t, false, r, 3) blockTime := time.Now().UTC() ctx = ctx.WithBlockTime(blockTime) - // setup 3 accounts - s := rand.NewSource(1) - r := rand.New(s) - accounts := getTestingAccounts(t, r, app, ctx, 3) + // remove genesis validator account + accounts = accounts[1:] // setup accounts[0] as validator0 validator0 := getTestingValidator0(t, app, ctx, accounts) @@ -99,35 +103,49 @@ func TestSimulateMsgUnjail(t *testing.T) { require.True(t, operationMsg.OK) require.Equal(t, types.TypeMsgUnjail, msg.Type()) - require.Equal(t, "cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", msg.ValidatorAddr) + require.Equal(t, "cosmosvaloper17s94pzwhsn4ah25tec27w70n65h5t2scgxzkv2", msg.ValidatorAddr) require.Len(t, futureOperations, 0) } // returns context and an app with updated mint keeper -func createTestApp(t *testing.T, isCheckTx bool) (*simapp.SimApp, sdk.Context) { - app := simapp.Setup(t, isCheckTx) +func createTestApp(t *testing.T, isCheckTx bool, r *rand.Rand, n int) (*simapp.SimApp, sdk.Context, []simtypes.Account) { + accounts := simtypes.RandomAccounts(r, n) + // create validator set with single validator + account := accounts[0] + tmPk, err := cryptocodec.ToTmPubKeyInterface(account.PubKey) + require.NoError(t, err) + validator := tmtypes.NewValidator(tmPk, 1) - ctx := app.BaseApp.NewContext(isCheckTx, tmproto.Header{}) - app.MintKeeper.SetParams(ctx, minttypes.DefaultParams()) - app.MintKeeper.SetMinter(ctx, minttypes.DefaultInitialMinter()) + valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator}) - return app, ctx -} + // generate genesis account + senderPrivKey := secp256k1.GenPrivKey() + acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0) + balance := banktypes.Balance{ + Address: acc.GetAddress().String(), + Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))), + } -func getTestingAccounts(t *testing.T, r *rand.Rand, app *simapp.SimApp, ctx sdk.Context, n int) []simtypes.Account { - accounts := simtypes.RandomAccounts(r, n) + app := simapp.SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, balance) + ctx := app.BaseApp.NewContext(isCheckTx, tmproto.Header{}) initAmt := app.StakingKeeper.TokensFromConsensusPower(ctx, 200) initCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initAmt)) + // remove genesis validator account + accs := accounts[1:] + // add coins to the accounts - for _, account := range accounts { + for _, account := range accs { acc := app.AccountKeeper.NewAccountWithAddress(ctx, account.Address) app.AccountKeeper.SetAccount(ctx, acc) require.NoError(t, testutil.FundAccount(app.BankKeeper, ctx, account.Address, initCoins)) } - return accounts + app.MintKeeper.SetParams(ctx, minttypes.DefaultParams()) + app.MintKeeper.SetMinter(ctx, minttypes.DefaultInitialMinter()) + + return app, ctx, accounts } func getTestingValidator0(t *testing.T, app *simapp.SimApp, ctx sdk.Context, accounts []simtypes.Account) stakingtypes.Validator { diff --git a/x/staking/genesis_test.go b/x/staking/genesis_test.go index 587986870bbd..df6120b04361 100644 --- a/x/staking/genesis_test.go +++ b/x/staking/genesis_test.go @@ -34,6 +34,7 @@ func TestInitGenesis(t *testing.T) { params := app.StakingKeeper.GetParams(ctx) validators := app.StakingKeeper.GetAllValidators(ctx) + require.Len(t, validators, 1) var delegations []types.Delegation pk0, err := codectypes.NewAnyWithValue(PKs[0]) @@ -64,16 +65,20 @@ func TestInitGenesis(t *testing.T) { validators = append(validators, bondedVal1, bondedVal2) log.Printf("%#v", len(validators)) // mint coins in the bonded pool representing the validators coins + i2 := len(validators) - 1 // -1 to exclude genesis validator require.NoError(t, testutil.FundModuleAccount( app.BankKeeper, ctx, types.BondedPoolName, sdk.NewCoins( - sdk.NewCoin(params.BondDenom, valTokens.MulRaw((int64)(len(validators)))), + sdk.NewCoin(params.BondDenom, valTokens.MulRaw((int64)(i2))), ), ), ) + genesisDelegations := app.StakingKeeper.GetAllDelegations(ctx) + delegations = append(delegations, genesisDelegations...) + genesisState := types.NewGenesisState(params, validators, delegations) vals := staking.InitGenesis(ctx, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, genesisState) @@ -99,6 +104,8 @@ func TestInitGenesis(t *testing.T) { require.Equal(t, types.Bonded, resVal.Status) abcivals := make([]abci.ValidatorUpdate, len(vals)) + + validators = validators[1:] // remove genesis validator for i, val := range validators { abcivals[i] = val.ABCIValidatorUpdate(app.StakingKeeper.PowerReduction(ctx)) } @@ -156,6 +163,7 @@ func TestInitGenesisLargeValidatorSet(t *testing.T) { require.True(t, size > 100) app, ctx, addrs := bootstrapGenesisTest(t, 200) + genesisValidators := app.StakingKeeper.GetAllValidators(ctx) params := app.StakingKeeper.GetParams(ctx) delegations := []types.Delegation{} @@ -179,6 +187,8 @@ func TestInitGenesisLargeValidatorSet(t *testing.T) { bondedPoolAmt = bondedPoolAmt.Add(tokens) } + validators = append(validators, genesisValidators...) + genesisState := types.NewGenesisState(params, validators, delegations) // mint coins in the bonded pool representing the validators coins @@ -198,6 +208,8 @@ func TestInitGenesisLargeValidatorSet(t *testing.T) { abcivals[i] = val.ABCIValidatorUpdate(app.StakingKeeper.PowerReduction(ctx)) } + // remove genesis validator + vals = vals[:100] require.Equal(t, abcivals, vals) } diff --git a/x/staking/keeper/delegation_test.go b/x/staking/keeper/delegation_test.go index 395a32e61d30..2246345c2e78 100644 --- a/x/staking/keeper/delegation_test.go +++ b/x/staking/keeper/delegation_test.go @@ -19,6 +19,15 @@ import ( func TestDelegation(t *testing.T) { _, app, ctx := createTestInput(t) + // remove genesis validator delegations + delegations := app.StakingKeeper.GetAllDelegations(ctx) + require.Len(t, delegations, 1) + + app.StakingKeeper.RemoveDelegation(ctx, types.Delegation{ + ValidatorAddress: delegations[0].ValidatorAddress, + DelegatorAddress: delegations[0].DelegatorAddress, + }) + addrDels := simapp.AddTestAddrsIncremental(app, ctx, 3, sdk.NewInt(10000)) valAddrs := simapp.ConvertAddrsToValAddrs(addrDels) diff --git a/x/staking/keeper/grpc_query_test.go b/x/staking/keeper/grpc_query_test.go index 1b06f8588641..8bb355571cd2 100644 --- a/x/staking/keeper/grpc_query_test.go +++ b/x/staking/keeper/grpc_query_test.go @@ -32,7 +32,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryValidators() { }, true, - len(vals), + len(vals) + 1, // +1 validator from genesis state false, }, { @@ -41,7 +41,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryValidators() { req = &types.QueryValidatorsRequest{Status: ""} }, true, - len(vals), + len(vals) + 1, // +1 validator from genesis state false, }, { @@ -72,7 +72,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryValidators() { suite.NoError(err) suite.NotNil(valsResp) suite.Equal(tc.numVals, len(valsResp.Validators)) - suite.Equal(uint64(len(vals)), valsResp.Pagination.Total) + suite.Equal(uint64(len(vals))+1, valsResp.Pagination.Total) // +1 validator from genesis state if tc.hasNext { suite.NotNil(valsResp.Pagination.NextKey) diff --git a/x/staking/keeper/historical_info_test.go b/x/staking/keeper/historical_info_test.go index 6e7063a77c04..437269956936 100644 --- a/x/staking/keeper/historical_info_test.go +++ b/x/staking/keeper/historical_info_test.go @@ -86,6 +86,10 @@ func TestTrackHistoricalInfo(t *testing.T) { require.True(t, found) require.Equal(t, hi5, recv) + // genesis validator + genesisVals := app.StakingKeeper.GetAllValidators(ctx) + require.Len(t, genesisVals, 1) + // Set bonded validators in keeper val1 := teststaking.NewValidator(t, addrVals[2], PKs[2]) val1.Status = types.Bonded // when not bonded, consensus power is Zero @@ -98,8 +102,8 @@ func TestTrackHistoricalInfo(t *testing.T) { app.StakingKeeper.SetValidator(ctx, val2) app.StakingKeeper.SetLastValidatorPower(ctx, val2.GetOperator(), 80) - vals := []types.Validator{val1, val2} - IsValSetSorted(vals, app.StakingKeeper.PowerReduction(ctx)) + vals := []types.Validator{val1, genesisVals[0], val2} + require.True(t, IsValSetSorted(vals, app.StakingKeeper.PowerReduction(ctx))) // Set Header for BeginBlock context header := tmproto.Header{ @@ -130,6 +134,10 @@ func TestTrackHistoricalInfo(t *testing.T) { func TestGetAllHistoricalInfo(t *testing.T) { _, app, ctx := createTestInput(t) + // clear historical info + infos := app.StakingKeeper.GetAllHistoricalInfo(ctx) + require.Len(t, infos, 1) + app.StakingKeeper.DeleteHistoricalInfo(ctx, infos[0].Header.Height) addrDels := simapp.AddTestAddrsIncremental(app, ctx, 50, sdk.NewInt(0)) addrVals := simapp.ConvertAddrsToValAddrs(addrDels) @@ -153,6 +161,6 @@ func TestGetAllHistoricalInfo(t *testing.T) { app.StakingKeeper.SetHistoricalInfo(ctx, int64(10+i), &hi) } - infos := app.StakingKeeper.GetAllHistoricalInfo(ctx) + infos = app.StakingKeeper.GetAllHistoricalInfo(ctx) require.Equal(t, expHistInfos, infos) } diff --git a/x/staking/keeper/keeper.go b/x/staking/keeper/keeper.go index 6211dcf6ad94..5dde8f1bb92a 100644 --- a/x/staking/keeper/keeper.go +++ b/x/staking/keeper/keeper.go @@ -3,6 +3,7 @@ package keeper import ( "fmt" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/tendermint/tendermint/libs/log" "github.com/cosmos/cosmos-sdk/codec" @@ -19,7 +20,7 @@ var _ types.DelegationSet = Keeper{} // keeper of the staking store type Keeper struct { - storeKey sdk.StoreKey + storeKey storetypes.StoreKey cdc codec.BinaryCodec authKeeper types.AccountKeeper bankKeeper types.BankKeeper @@ -29,7 +30,7 @@ type Keeper struct { // NewKeeper creates a new staking Keeper instance func NewKeeper( - cdc codec.BinaryCodec, key sdk.StoreKey, ak types.AccountKeeper, bk types.BankKeeper, + cdc codec.BinaryCodec, key storetypes.StoreKey, ak types.AccountKeeper, bk types.BankKeeper, ps paramtypes.Subspace, ) Keeper { // set KeyTable if it has not already been set diff --git a/x/staking/keeper/querier_test.go b/x/staking/keeper/querier_test.go index 16755d5e13f2..f50e95a1833e 100644 --- a/x/staking/keeper/querier_test.go +++ b/x/staking/keeper/querier_test.go @@ -143,9 +143,9 @@ func TestQueryValidators(t *testing.T) { addrs := simapp.AddTestAddrs(app, ctx, 500, app.StakingKeeper.TokensFromConsensusPower(ctx, 10000)) // Create Validators - amts := []sdk.Int{sdk.NewInt(9), sdk.NewInt(8), sdk.NewInt(7)} - status := []types.BondStatus{types.Bonded, types.Unbonded, types.Unbonding} - var validators [3]types.Validator + amts := []sdk.Int{sdk.NewInt(8), sdk.NewInt(7)} + status := []types.BondStatus{types.Unbonded, types.Unbonding} + var validators [2]types.Validator for i, amt := range amts { validators[i] = teststaking.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i]) validators[i], _ = validators[i].AddTokensFromDel(amt) @@ -154,7 +154,6 @@ func TestQueryValidators(t *testing.T) { app.StakingKeeper.SetValidator(ctx, validators[0]) app.StakingKeeper.SetValidator(ctx, validators[1]) - app.StakingKeeper.SetValidator(ctx, validators[2]) // Query Validators queriedValidators := app.StakingKeeper.GetValidators(ctx, params.MaxValidators) @@ -305,6 +304,9 @@ func TestQueryDelegation(t *testing.T) { require.Equal(t, sdk.NewCoin(sdk.DefaultBondDenom, delegation.Shares.TruncateInt()), delegationRes.Balance) // Query Delegator Delegations + bz, errRes = cdc.MarshalJSON(queryParams) + require.NoError(t, errRes) + query = abci.RequestQuery{ Path: "/custom/staking/delegatorDelegations", Data: bz, diff --git a/x/staking/keeper/validator_test.go b/x/staking/keeper/validator_test.go index 74aa03b49766..282f64467449 100644 --- a/x/staking/keeper/validator_test.go +++ b/x/staking/keeper/validator_test.go @@ -14,6 +14,7 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/bank/testutil" + "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/cosmos/cosmos-sdk/x/staking/teststaking" "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -39,6 +40,17 @@ func bootstrapValidatorTest(t testing.TB, power int64, numAddrs int) (*simapp.Si require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), totalSupply)) + // unbond genesis validator delegations + delegations := app.StakingKeeper.GetAllDelegations(ctx) + require.Len(t, delegations, 1) + delegation := delegations[0] + + _, err := app.StakingKeeper.Undelegate(ctx, delegation.GetDelegatorAddr(), delegation.GetValidatorAddr(), delegation.Shares) + require.NoError(t, err) + + // end block to unbond genesis validator + staking.EndBlocker(ctx, app.StakingKeeper) + return app, ctx, addrDels, addrVals } @@ -97,14 +109,12 @@ func TestSetValidator(t *testing.T) { resVals = app.StakingKeeper.GetValidators(ctx, 1) require.Equal(t, 1, len(resVals)) - require.True(ValEq(t, validator, resVals[0])) resVals = app.StakingKeeper.GetValidators(ctx, 10) - require.Equal(t, 1, len(resVals)) - require.True(ValEq(t, validator, resVals[0])) + require.Equal(t, 2, len(resVals)) allVals := app.StakingKeeper.GetAllValidators(ctx) - require.Equal(t, 1, len(allVals)) + require.Equal(t, 2, len(allVals)) } func TestUpdateValidatorByPowerIndex(t *testing.T) { @@ -264,7 +274,7 @@ func TestValidatorBasics(t *testing.T) { require.Zero(t, len(resVals)) resVals = app.StakingKeeper.GetValidators(ctx, 2) - require.Zero(t, len(resVals)) + require.Len(t, resVals, 1) // set and retrieve a record validators[0] = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validators[0], true) diff --git a/x/staking/migrations/v043/store.go b/x/staking/migrations/v043/store.go index 4ebba9b600fd..2ebcbb8686de 100644 --- a/x/staking/migrations/v043/store.go +++ b/x/staking/migrations/v043/store.go @@ -2,6 +2,7 @@ package v043 import ( "github.com/cosmos/cosmos-sdk/store/prefix" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" v040auth "github.com/cosmos/cosmos-sdk/x/auth/migrations/v040" @@ -58,7 +59,7 @@ func migrateValidatorsByPowerIndexKey(store sdk.KVStore) { // migration includes: // // - Setting the Power Reduction param in the paramstore -func MigrateStore(ctx sdk.Context, storeKey sdk.StoreKey) error { +func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey) error { store := ctx.KVStore(storeKey) v043distribution.MigratePrefixAddress(store, v040staking.LastValidatorPowerKey) diff --git a/x/staking/module_test.go b/x/staking/module_test.go index a9ebb6d9a105..8784893634b6 100644 --- a/x/staking/module_test.go +++ b/x/staking/module_test.go @@ -5,7 +5,10 @@ import ( "github.com/stretchr/testify/require" abcitypes "github.com/tendermint/tendermint/abci/types" + tmjson "github.com/tendermint/tendermint/libs/json" + "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/simapp" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -13,16 +16,22 @@ import ( ) func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { - app := simapp.Setup(t, false) - ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + db := dbm.NewMemDB() + encCdc := simapp.MakeTestEncodingConfig() + app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, encCdc, simapp.EmptyAppOptions{}) + genesisState := simapp.GenesisStateWithSingleValidator(t, app) + stateBytes, err := tmjson.Marshal(genesisState) + require.NoError(t, err) + app.InitChain( abcitypes.RequestInitChain{ - AppStateBytes: []byte("{}"), + AppStateBytes: stateBytes, ChainId: "test-chain-id", }, ) + ctx := app.BaseApp.NewContext(false, tmproto.Header{}) acc := app.AccountKeeper.GetAccount(ctx, authtypes.NewModuleAddress(types.BondedPoolName)) require.NotNil(t, acc) diff --git a/x/staking/simulation/operations.go b/x/staking/simulation/operations.go index ce5ef3dc38ac..7b0b3411ec62 100644 --- a/x/staking/simulation/operations.go +++ b/x/staking/simulation/operations.go @@ -101,7 +101,7 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k k // ensure the validator doesn't exist already _, found := k.GetValidator(ctx, address) if found { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCreateValidator, "unable to find validator"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCreateValidator, "validator already exists"), nil, nil } denom := k.GetParams(ctx).BondDenom diff --git a/x/staking/simulation/operations_test.go b/x/staking/simulation/operations_test.go index 0f3f2c730d95..8c1ee9ec152e 100644 --- a/x/staking/simulation/operations_test.go +++ b/x/staking/simulation/operations_test.go @@ -1,19 +1,25 @@ package simulation_test import ( + "math/big" "math/rand" "testing" "time" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + tmtypes "github.com/tendermint/tendermint/types" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/simapp" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/bank/testutil" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" "github.com/cosmos/cosmos-sdk/x/staking/simulation" @@ -23,8 +29,9 @@ import ( // TestWeightedOperations tests the weights of the operations. func TestWeightedOperations(t *testing.T) { - - app, ctx := createTestApp(t, false) + s := rand.NewSource(1) + r := rand.New(s) + app, ctx, accs := createTestApp(t, false, r, 3) ctx.WithChainID("test-chain") @@ -35,10 +42,6 @@ func TestWeightedOperations(t *testing.T) { app.BankKeeper, app.StakingKeeper, ) - s := rand.NewSource(1) - r := rand.New(s) - accs := simtypes.RandomAccounts(r, 3) - expected := []struct { weight int opMsgRoute string @@ -64,12 +67,9 @@ func TestWeightedOperations(t *testing.T) { // TestSimulateMsgCreateValidator tests the normal scenario of a valid message of type TypeMsgCreateValidator. // Abonormal scenarios, where the message are created by an errors are not tested here. func TestSimulateMsgCreateValidator(t *testing.T) { - app, ctx := createTestApp(t, false) - - // setup 3 accounts s := rand.NewSource(1) r := rand.New(s) - accounts := getTestingAccounts(t, r, app, ctx, 3) + app, ctx, accounts := createTestApp(t, false, r, 3) // begin a new block app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1, AppHash: app.LastCommitID().Hash}}) @@ -96,14 +96,14 @@ func TestSimulateMsgCreateValidator(t *testing.T) { // TestSimulateMsgEditValidator tests the normal scenario of a valid message of type TypeMsgEditValidator. // Abonormal scenarios, where the message is created by an errors are not tested here. func TestSimulateMsgEditValidator(t *testing.T) { - app, ctx := createTestApp(t, false) + s := rand.NewSource(1) + r := rand.New(s) + app, ctx, accounts := createTestApp(t, false, r, 3) blockTime := time.Now().UTC() ctx = ctx.WithBlockTime(blockTime) - // setup 3 accounts - s := rand.NewSource(1) - r := rand.New(s) - accounts := getTestingAccounts(t, r, app, ctx, 3) + // remove genesis validator account + accounts = accounts[1:] // setup accounts[0] as validator _ = getTestingValidator0(t, app, ctx, accounts) @@ -126,28 +126,19 @@ func TestSimulateMsgEditValidator(t *testing.T) { require.Equal(t, "WeLrQKjLxz", msg.Description.Website) require.Equal(t, "rBqDOTtGTO", msg.Description.SecurityContact) require.Equal(t, types.TypeMsgEditValidator, msg.Type()) - require.Equal(t, "cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", msg.ValidatorAddress) + require.Equal(t, "cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorAddress) require.Len(t, futureOperations, 0) } // TestSimulateMsgDelegate tests the normal scenario of a valid message of type TypeMsgDelegate. // Abonormal scenarios, where the message is created by an errors are not tested here. func TestSimulateMsgDelegate(t *testing.T) { - app, ctx := createTestApp(t, false) - blockTime := time.Now().UTC() - ctx = ctx.WithBlockTime(blockTime) - - // setup 3 accounts s := rand.NewSource(1) r := rand.New(s) - accounts := getTestingAccounts(t, r, app, ctx, 3) - - // setup accounts[0] as validator - validator0 := getTestingValidator0(t, app, ctx, accounts) - setupValidatorRewards(app, ctx, validator0.GetOperator()) + app, ctx, accounts := createTestApp(t, false, r, 3) - // begin a new block - app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1, AppHash: app.LastCommitID().Hash, Time: blockTime}}) + blockTime := time.Now().UTC() + ctx = ctx.WithBlockTime(blockTime) // execute operation op := simulation.SimulateMsgDelegate(app.AccountKeeper, app.BankKeeper, app.StakingKeeper) @@ -169,14 +160,15 @@ func TestSimulateMsgDelegate(t *testing.T) { // TestSimulateMsgUndelegate tests the normal scenario of a valid message of type TypeMsgUndelegate. // Abonormal scenarios, where the message is created by an errors are not tested here. func TestSimulateMsgUndelegate(t *testing.T) { - app, ctx := createTestApp(t, false) + s := rand.NewSource(1) + r := rand.New(s) + app, ctx, accounts := createTestApp(t, false, r, 3) + blockTime := time.Now().UTC() ctx = ctx.WithBlockTime(blockTime) - // setup 3 accounts - s := rand.NewSource(1) - r := rand.New(s) - accounts := getTestingAccounts(t, r, app, ctx, 3) + // remove genesis validator account + accounts = accounts[1:] // setup accounts[0] as validator validator0 := getTestingValidator0(t, app, ctx, accounts) @@ -203,26 +195,26 @@ func TestSimulateMsgUndelegate(t *testing.T) { types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(t, operationMsg.OK) - require.Equal(t, "cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.DelegatorAddress) + require.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.DelegatorAddress) require.Equal(t, "280623462081924937", msg.Amount.Amount.String()) require.Equal(t, "stake", msg.Amount.Denom) require.Equal(t, types.TypeMsgUndelegate, msg.Type()) - require.Equal(t, "cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", msg.ValidatorAddress) + require.Equal(t, "cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorAddress) require.Len(t, futureOperations, 0) - } // TestSimulateMsgBeginRedelegate tests the normal scenario of a valid message of type TypeMsgBeginRedelegate. // Abonormal scenarios, where the message is created by an errors, are not tested here. func TestSimulateMsgBeginRedelegate(t *testing.T) { - app, ctx := createTestApp(t, false) + s := rand.NewSource(12) + r := rand.New(s) + app, ctx, accounts := createTestApp(t, false, r, 4) + blockTime := time.Now().UTC() ctx = ctx.WithBlockTime(blockTime) - // setup 3 accounts - s := rand.NewSource(5) - r := rand.New(s) - accounts := getTestingAccounts(t, r, app, ctx, 3) + // remove genesis validator account + accounts = accounts[1:] // setup accounts[0] as validator0 and accounts[1] as validator1 validator0 := getTestingValidator0(t, app, ctx, accounts) @@ -252,42 +244,56 @@ func TestSimulateMsgBeginRedelegate(t *testing.T) { types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(t, operationMsg.OK) - require.Equal(t, "cosmos12gwd9jchc69wck8dhstxgwz3z8qs8yv67ps8mu", msg.DelegatorAddress) - require.Equal(t, "489348507626016866", msg.Amount.Amount.String()) + require.Equal(t, "cosmos1092v0qgulpejj8y8hs6dmlw82x9gv8f7jfc7jl", msg.DelegatorAddress) + require.Equal(t, "1883752832348281252", msg.Amount.Amount.String()) require.Equal(t, "stake", msg.Amount.Denom) require.Equal(t, types.TypeMsgBeginRedelegate, msg.Type()) - require.Equal(t, "cosmosvaloper1h6a7shta7jyc72hyznkys683z98z36e0zdk8g9", msg.ValidatorDstAddress) - require.Equal(t, "cosmosvaloper17s94pzwhsn4ah25tec27w70n65h5t2scgxzkv2", msg.ValidatorSrcAddress) + require.Equal(t, "cosmosvaloper1gnkw3uqzflagcqn6ekjwpjanlne928qhruemah", msg.ValidatorDstAddress) + require.Equal(t, "cosmosvaloper1kk653svg7ksj9fmu85x9ygj4jzwlyrgs89nnn2", msg.ValidatorSrcAddress) require.Len(t, futureOperations, 0) - } // returns context and an app with updated mint keeper -func createTestApp(t *testing.T, isCheckTx bool) (*simapp.SimApp, sdk.Context) { - // sdk.PowerReduction = sdk.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil)) - app := simapp.Setup(t, isCheckTx) +func createTestApp(t *testing.T, isCheckTx bool, r *rand.Rand, n int) (*simapp.SimApp, sdk.Context, []simtypes.Account) { + sdk.DefaultPowerReduction = sdk.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil)) + + accounts := simtypes.RandomAccounts(r, n) + // create validator set with single validator + account := accounts[0] + tmPk, err := cryptocodec.ToTmPubKeyInterface(account.PubKey) + require.NoError(t, err) + validator := tmtypes.NewValidator(tmPk, 1) + + valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator}) + + // generate genesis account + senderPrivKey := secp256k1.GenPrivKey() + acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0) + balance := banktypes.Balance{ + Address: acc.GetAddress().String(), + Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))), + } + + app := simapp.SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, balance) ctx := app.BaseApp.NewContext(isCheckTx, tmproto.Header{}) app.MintKeeper.SetParams(ctx, minttypes.DefaultParams()) app.MintKeeper.SetMinter(ctx, minttypes.DefaultInitialMinter()) - return app, ctx -} - -func getTestingAccounts(t *testing.T, r *rand.Rand, app *simapp.SimApp, ctx sdk.Context, n int) []simtypes.Account { - accounts := simtypes.RandomAccounts(r, n) - initAmt := app.StakingKeeper.TokensFromConsensusPower(ctx, 200) initCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initAmt)) + // remove genesis validator account + accs := accounts[1:] + // add coins to the accounts - for _, account := range accounts { + for _, account := range accs { acc := app.AccountKeeper.NewAccountWithAddress(ctx, account.Address) app.AccountKeeper.SetAccount(ctx, acc) require.NoError(t, testutil.FundAccount(app.BankKeeper, ctx, account.Address, initCoins)) } - return accounts + return app, ctx, accounts } func getTestingValidator0(t *testing.T, app *simapp.SimApp, ctx sdk.Context, accounts []simtypes.Account) types.Validator { diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index a6a5ee9552e2..21ab2b2a517e 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -9,6 +9,7 @@ import ( "path/filepath" "sort" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/tendermint/tendermint/libs/log" tmos "github.com/tendermint/tendermint/libs/os" @@ -28,7 +29,7 @@ const UpgradeInfoFileName string = "upgrade-info.json" type Keeper struct { homePath string // root directory of app config skipUpgradeHeights map[int64]bool // map of heights to skip for an upgrade - storeKey sdk.StoreKey // key to access x/upgrade store + storeKey storetypes.StoreKey // key to access x/upgrade store cdc codec.BinaryCodec // App-wide binary codec upgradeHandlers map[string]types.UpgradeHandler // map of plan name to upgrade handler versionSetter xp.ProtocolVersionSetter // implements setting the protocol version field on BaseApp @@ -40,7 +41,7 @@ type Keeper struct { // cdc - the app-wide binary codec // homePath - root directory of the application's config // vs - the interface implemented by baseapp which allows setting baseapp's protocol version field -func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey sdk.StoreKey, cdc codec.BinaryCodec, homePath string, vs xp.ProtocolVersionSetter) Keeper { +func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey storetypes.StoreKey, cdc codec.BinaryCodec, homePath string, vs xp.ProtocolVersionSetter) Keeper { return Keeper{ homePath: homePath, skipUpgradeHeights: skipUpgradeHeights, diff --git a/x/upgrade/types/storeloader.go b/x/upgrade/types/storeloader.go index 00538e07152a..3911effbed30 100644 --- a/x/upgrade/types/storeloader.go +++ b/x/upgrade/types/storeloader.go @@ -2,13 +2,13 @@ package types import ( "github.com/cosmos/cosmos-sdk/baseapp" - store "github.com/cosmos/cosmos-sdk/store/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" ) // UpgradeStoreLoader is used to prepare baseapp with a fixed StoreLoader // pattern. This is useful for custom upgrade loading logic. -func UpgradeStoreLoader(upgradeHeight int64, storeUpgrades *store.StoreUpgrades) baseapp.StoreLoader { +func UpgradeStoreLoader(upgradeHeight int64, storeUpgrades *storetypes.StoreUpgrades) baseapp.StoreLoader { return func(ms sdk.CommitMultiStore) error { if upgradeHeight == ms.LastCommitID().Version+1 { // Check if the current commit version and upgrade height matches diff --git a/x/upgrade/types/storeloader_test.go b/x/upgrade/types/storeloader_test.go index b06678fc2a56..20e28888ed33 100644 --- a/x/upgrade/types/storeloader_test.go +++ b/x/upgrade/types/storeloader_test.go @@ -15,11 +15,11 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/store/rootmulti" - store "github.com/cosmos/cosmos-sdk/store/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" ) -func useUpgradeLoader(height int64, upgrades *store.StoreUpgrades) func(*baseapp.BaseApp) { +func useUpgradeLoader(height int64, upgrades *storetypes.StoreUpgrades) func(*baseapp.BaseApp) { return func(app *baseapp.BaseApp) { app.SetStoreLoader(UpgradeStoreLoader(height, upgrades)) } @@ -31,15 +31,15 @@ func defaultLogger() log.Logger { func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { rs := rootmulti.NewStore(db) - rs.SetPruning(store.PruneNothing) + rs.SetPruning(storetypes.PruneNothing) key := sdk.NewKVStoreKey(storeKey) - rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil) + rs.MountStoreWithDB(key, storetypes.StoreTypeIAVL, nil) err := rs.LoadLatestVersion() require.Nil(t, err) require.Equal(t, int64(0), rs.LastCommitID().Version) // write some data in substore - kv, _ := rs.GetStore(key).(store.KVStore) + kv, _ := rs.GetStore(key).(storetypes.KVStore) require.NotNil(t, kv) kv.Set(k, v) commitID := rs.Commit() @@ -48,15 +48,15 @@ func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { func checkStore(t *testing.T, db dbm.DB, ver int64, storeKey string, k, v []byte) { rs := rootmulti.NewStore(db) - rs.SetPruning(store.PruneNothing) + rs.SetPruning(storetypes.PruneNothing) key := sdk.NewKVStoreKey(storeKey) - rs.MountStoreWithDB(key, store.StoreTypeIAVL, nil) + rs.MountStoreWithDB(key, storetypes.StoreTypeIAVL, nil) err := rs.LoadLatestVersion() require.Nil(t, err) require.Equal(t, ver, rs.LastCommitID().Version) // query data in substore - kv, _ := rs.GetStore(key).(store.KVStore) + kv, _ := rs.GetStore(key).(storetypes.KVStore) require.NotNil(t, kv) require.Equal(t, v, kv.Get(k)) @@ -95,8 +95,8 @@ func TestSetLoader(t *testing.T) { loadStoreKey: "foo", }, "rename with inline opts": { - setLoader: useUpgradeLoader(upgradeHeight, &store.StoreUpgrades{ - Renamed: []store.StoreRename{{ + setLoader: useUpgradeLoader(upgradeHeight, &storetypes.StoreUpgrades{ + Renamed: []storetypes.StoreRename{{ OldKey: "foo", NewKey: "bar", }}, @@ -118,7 +118,7 @@ func TestSetLoader(t *testing.T) { initStore(t, db, tc.origStoreKey, k, v) // load the app with the existing db - opts := []func(*baseapp.BaseApp){baseapp.SetPruning(store.PruneNothing)} + opts := []func(*baseapp.BaseApp){baseapp.SetPruning(storetypes.PruneNothing)} origapp := baseapp.NewBaseApp(t.Name(), defaultLogger(), db, nil, opts...) origapp.MountStores(sdk.NewKVStoreKey(tc.origStoreKey))