From e31c19a5af8b4d1100ebd6e504d1ef3bab116472 Mon Sep 17 00:00:00 2001 From: likhita Date: Mon, 22 Feb 2021 16:27:30 +0530 Subject: [PATCH 01/96] adding RegisterInvariants to Configuration --- types/module/server/manager.go | 50 ++++++++++++++++++------------- types/module/server/module.go | 2 +- types/module/server/testutil.go | 7 +++-- x/data/server/server_test.go | 2 +- x/ecocredit/server/server_test.go | 2 +- x/group/server/server.go | 1 + x/group/server/server_test.go | 2 +- 7 files changed, 39 insertions(+), 27 deletions(-) diff --git a/types/module/server/manager.go b/types/module/server/manager.go index 926510ee5a..3dd141d7cb 100644 --- a/types/module/server/manager.go +++ b/types/module/server/manager.go @@ -14,19 +14,21 @@ import ( // Manager is the server module manager type Manager struct { - baseApp *baseapp.BaseApp - cdc *codec.ProtoCodec - keys map[string]ModuleKey - router *router - requiredServices map[reflect.Type]bool + baseApp *baseapp.BaseApp + cdc *codec.ProtoCodec + keys map[string]ModuleKey + router *router + requiredServices map[reflect.Type]bool + registerInvariants *sdk.InvariantRegistry } // NewManager creates a new Manager -func NewManager(baseApp *baseapp.BaseApp, cdc *codec.ProtoCodec) *Manager { +func NewManager(baseApp *baseapp.BaseApp, cdc *codec.ProtoCodec, invariant sdk.InvariantRegistry) *Manager { return &Manager{ - baseApp: baseApp, - cdc: cdc, - keys: map[string]ModuleKey{}, + baseApp: baseApp, + cdc: cdc, + keys: map[string]ModuleKey{}, + registerInvariants: &invariant, router: &router{ handlers: map[string]handler{}, providedServices: map[reflect.Type]bool{}, @@ -88,12 +90,13 @@ func (mm *Manager) RegisterModules(modules []module.Module) error { } cfg := &configurator{ - msgServer: msgRegistrar, - queryServer: queryRegistrar, - key: key, - cdc: mm.cdc, - requiredServices: map[reflect.Type]bool{}, - router: mm.baseApp.Router(), // TODO: remove once #225 addressed + msgServer: msgRegistrar, + queryServer: queryRegistrar, + key: key, + cdc: mm.cdc, + requiredServices: map[reflect.Type]bool{}, + router: mm.baseApp.Router(), // TODO: remove once #225 addressed + registerInvariants: *mm.registerInvariants, } serverMod.RegisterServices(cfg) @@ -138,12 +141,13 @@ func (mm *Manager) CompleteInitialization() error { } type configurator struct { - msgServer gogogrpc.Server - queryServer gogogrpc.Server - key *rootModuleKey - cdc codec.Marshaler - requiredServices map[reflect.Type]bool - router sdk.Router + msgServer gogogrpc.Server + queryServer gogogrpc.Server + key *rootModuleKey + cdc codec.Marshaler + requiredServices map[reflect.Type]bool + router sdk.Router + registerInvariants sdk.InvariantRegistry } var _ Configurator = &configurator{} @@ -156,6 +160,10 @@ func (c *configurator) QueryServer() gogogrpc.Server { return c.queryServer } +func (c *configurator) RegisterInvariants() sdk.InvariantRegistry { + return c.registerInvariants +} + func (c *configurator) ModuleKey() RootModuleKey { return c.key } diff --git a/types/module/server/module.go b/types/module/server/module.go index 440188893d..12826f593b 100644 --- a/types/module/server/module.go +++ b/types/module/server/module.go @@ -20,7 +20,7 @@ type Configurator interface { ModuleKey() RootModuleKey Marshaler() codec.Marshaler RequireServer(interface{}) - + RegisterInvariants() sdk.InvariantRegistry // Router() is temporarily added here to use in the group module. // TODO: remove once #225 addressed Router() sdk.Router diff --git a/types/module/server/testutil.go b/types/module/server/testutil.go index bc9b58814a..9e0a15a081 100644 --- a/types/module/server/testutil.go +++ b/types/module/server/testutil.go @@ -28,9 +28,10 @@ type FixtureFactory struct { signers []sdk.AccAddress cdc *codec.ProtoCodec baseApp *baseapp.BaseApp + invar *sdk.InvariantRegistry } -func NewFixtureFactory(t *testing.T, numSigners int) *FixtureFactory { +func NewFixtureFactory(t *testing.T, numSigners int, invariant sdk.InvariantRegistry) *FixtureFactory { signers := makeTestAddresses(numSigners) return &FixtureFactory{ t: t, @@ -39,6 +40,7 @@ func NewFixtureFactory(t *testing.T, numSigners int) *FixtureFactory { // TODO: remove once all code using this uses ADR 033 module wiring cdc: codec.NewProtoCodec(types.NewInterfaceRegistry()), baseApp: baseapp.NewBaseApp("test", log.NewNopLogger(), dbm.NewMemDB(), nil), + invar: &invariant, } } @@ -70,9 +72,10 @@ func (ff FixtureFactory) Setup() testutil.Fixture { cdc := ff.cdc registry := cdc.InterfaceRegistry() baseApp := ff.baseApp + invar := ff.invar baseApp.MsgServiceRouter().SetInterfaceRegistry(registry) baseApp.GRPCQueryRouter().SetInterfaceRegistry(registry) - mm := NewManager(baseApp, cdc) + mm := NewManager(baseApp, cdc, *invar) err := mm.RegisterModules(ff.modules) require.NoError(ff.t, err) err = mm.CompleteInitialization() diff --git a/x/data/server/server_test.go b/x/data/server/server_test.go index 284837c2c9..dc5521488e 100644 --- a/x/data/server/server_test.go +++ b/x/data/server/server_test.go @@ -13,7 +13,7 @@ import ( ) func TestServer(t *testing.T) { - ff := server.NewFixtureFactory(t, 2) + ff := server.NewFixtureFactory(t, 2, nil) ff.SetModules([]module.Module{datamodule.Module{}}) s := testsuite.NewIntegrationTestSuite(ff) suite.Run(t, s) diff --git a/x/ecocredit/server/server_test.go b/x/ecocredit/server/server_test.go index 32dab6aa0e..ec1ead8dc2 100644 --- a/x/ecocredit/server/server_test.go +++ b/x/ecocredit/server/server_test.go @@ -12,7 +12,7 @@ import ( ) func TestServer(t *testing.T) { - ff := server.NewFixtureFactory(t, 6) + ff := server.NewFixtureFactory(t, 6, nil) ff.SetModules([]module.Module{ecocreditmodule.Module{}}) s := testsuite.NewIntegrationTestSuite(ff) suite.Run(t, s) diff --git a/x/group/server/server.go b/x/group/server/server.go index 8714449c54..db855c1bd0 100644 --- a/x/group/server/server.go +++ b/x/group/server/server.go @@ -165,4 +165,5 @@ func RegisterServices(configurator servermodule.Configurator, accountKeeper Acco impl := newServer(configurator.ModuleKey(), configurator.Router(), accountKeeper, configurator.Marshaler()) group.RegisterMsgServer(configurator.MsgServer(), impl) group.RegisterQueryServer(configurator.QueryServer(), impl) + configurator.RegisterInvariants() } diff --git a/x/group/server/server_test.go b/x/group/server/server_test.go index 9c73037c14..a1f7d34a64 100644 --- a/x/group/server/server_test.go +++ b/x/group/server/server_test.go @@ -21,7 +21,7 @@ import ( ) func TestServer(t *testing.T) { - ff := server.NewFixtureFactory(t, 6) + ff := server.NewFixtureFactory(t, 6, nil) cdc := ff.Codec() // Setting up bank keeper banktypes.RegisterInterfaces(cdc.InterfaceRegistry()) From 6d2092a2a942a2e23ce2ce0ce995f73a911c38a6 Mon Sep 17 00:00:00 2001 From: likhita Date: Mon, 22 Feb 2021 18:40:15 +0530 Subject: [PATCH 02/96] fixing failed tests --- app/experimental_appconfig.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/experimental_appconfig.go b/app/experimental_appconfig.go index b69a8668c5..3d8abce027 100644 --- a/app/experimental_appconfig.go +++ b/app/experimental_appconfig.go @@ -27,7 +27,7 @@ func setCustomModuleBasics() []module.AppModuleBasic { func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry) { /* New Module Wiring START */ - newModuleManager := servermodule.NewManager(app.BaseApp, codec.NewProtoCodec(interfaceRegistry)) + newModuleManager := servermodule.NewManager(app.BaseApp, codec.NewProtoCodec(interfaceRegistry), sdk.InvariantRegistry) // BEGIN HACK: this is a total, ugly hack until x/auth supports ADR 033 or we have a suitable alternative groupModule := group.Module{AccountKeeper: app.AccountKeeper} From 9c19e8487b28ab5063b058a36e96ecb475cba3b8 Mon Sep 17 00:00:00 2001 From: likhita Date: Tue, 23 Feb 2021 15:08:39 +0530 Subject: [PATCH 03/96] fix failing tests --- app/experimental_appconfig.go | 2 +- x/group/server/testsuite/suite.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/experimental_appconfig.go b/app/experimental_appconfig.go index 3d8abce027..69e3ea9ef4 100644 --- a/app/experimental_appconfig.go +++ b/app/experimental_appconfig.go @@ -27,7 +27,7 @@ func setCustomModuleBasics() []module.AppModuleBasic { func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry) { /* New Module Wiring START */ - newModuleManager := servermodule.NewManager(app.BaseApp, codec.NewProtoCodec(interfaceRegistry), sdk.InvariantRegistry) + newModuleManager := servermodule.NewManager(app.BaseApp, codec.NewProtoCodec(interfaceRegistry), nil) // BEGIN HACK: this is a total, ugly hack until x/auth supports ADR 033 or we have a suitable alternative groupModule := group.Module{AccountKeeper: app.AccountKeeper} diff --git a/x/group/server/testsuite/suite.go b/x/group/server/testsuite/suite.go index a906027551..d5abdf6962 100644 --- a/x/group/server/testsuite/suite.go +++ b/x/group/server/testsuite/suite.go @@ -3,6 +3,7 @@ package testsuite import ( "bytes" "context" + "github.com/regen-network/regen-ledger/testutil/testdata" "sort" "strings" "time" @@ -21,7 +22,6 @@ import ( bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/regen-network/regen-ledger/testutil/testdata" "github.com/regen-network/regen-ledger/types" "github.com/regen-network/regen-ledger/x/group" groupserver "github.com/regen-network/regen-ledger/x/group/server" From 1e5170490dc4408826ded484962c43be8fafb864 Mon Sep 17 00:00:00 2001 From: likhita Date: Tue, 23 Feb 2021 16:07:26 +0530 Subject: [PATCH 04/96] fix lint issues --- go.mod | 1 + go.sum | 10 ++++ x/data/server/query_server.go | 2 +- x/data/server/testsuite/suite.go | 99 +++++++++++++++---------------- x/group/server/testsuite/suite.go | 9 ++- 5 files changed, 68 insertions(+), 53 deletions(-) diff --git a/go.mod b/go.mod index 67e2efd296..75c2eec8b4 100644 --- a/go.mod +++ b/go.mod @@ -23,6 +23,7 @@ require ( github.com/stretchr/testify v1.7.0 github.com/tendermint/tendermint v0.34.3 github.com/tendermint/tm-db v0.6.3 + golang.org/x/tools v0.1.0 // indirect google.golang.org/genproto v0.0.0-20210212180131-e7f2df4ecc2d // indirect google.golang.org/grpc v1.35.0 gopkg.in/yaml.v2 v2.4.0 diff --git a/go.sum b/go.sum index 1e27501676..2e24372521 100644 --- a/go.sum +++ b/go.sum @@ -637,6 +637,7 @@ github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijb github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/zondax/hid v0.9.0 h1:eiT3P6vNxAEVxXMw66eZUAAnU2zD33JBkfG/EnfAKl8= github.com/zondax/hid v0.9.0/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= @@ -700,6 +701,8 @@ golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKG golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -744,6 +747,7 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -789,6 +793,8 @@ golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201211090839-8ad439b19e0f h1:QdHQnPce6K4XQewki9WNbG5KOROuDzqO3NaYjI1cXJ0= golang.org/x/sys v0.0.0-20201211090839-8ad439b19e0f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E= @@ -826,9 +832,13 @@ golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200110213125-a7a6caa82ab2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa h1:5E4dL8+NgFOgjwbTKz+OOEGGhP+ectTmF842l6KjupQ= golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY= +golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= 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= diff --git a/x/data/server/query_server.go b/x/data/server/query_server.go index 5243cd2f2a..d2f319de23 100644 --- a/x/data/server/query_server.go +++ b/x/data/server/query_server.go @@ -46,7 +46,7 @@ func (s serverImpl) ByHash(ctx types.Context, request *data.QueryByHashRequest) func (s serverImpl) BySigner(ctx types.Context, request *data.QueryBySignerRequest) (*data.QueryBySignerResponse, error) { return nil, fmt.Errorf("not implemented") - //store := prefix.NewStore(ctx.KVStore(s.storeKey), SignerCIDIndexPrefix(request.Signer)) + // store := prefix.NewStore(ctx.KVStore(s.storeKey), SignerCIDIndexPrefix(request.Signer)) // //var cids [][]byte //pageRes, err := query.Paginate(store, request.Pagination, func(key []byte, value []byte) error { diff --git a/x/data/server/testsuite/suite.go b/x/data/server/testsuite/suite.go index 6b60c9eb72..f957404090 100644 --- a/x/data/server/testsuite/suite.go +++ b/x/data/server/testsuite/suite.go @@ -3,11 +3,10 @@ package testsuite import ( "context" - "github.com/regen-network/regen-ledger/testutil" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/suite" + "github.com/regen-network/regen-ledger/testutil" "github.com/regen-network/regen-ledger/x/data" ) @@ -43,66 +42,66 @@ func (s *IntegrationTestSuite) TearDownSuite() { } func (s *IntegrationTestSuite) TestScenario() { - //testContent := []byte("xyzabc123") - //mh, err := multihash.Sum(testContent, multihash.SHA2_256, -1) - //s.Require().NoError(err) - //cid := gocid.NewCidV1(gocid.Raw, mh) + // testContent := []byte("xyzabc123") + // mh, err := multihash.Sum(testContent, multihash.SHA2_256, -1) + // s.Require().NoError(err) + // cid := gocid.NewCidV1(gocid.Raw, mh) // //// anchor some data - //cidBz := cid.Bytes() - //anchorRes, err := s.msgClient.AnchorData(s.ctx, &data.MsgAnchorDataRequest{ + // cidBz := cid.Bytes() + // anchorRes, err := s.msgClient.AnchorData(s.ctx, &data.MsgAnchorDataRequest{ // Sender: s.addr1.String(), // Cid: cidBz, //}) - //s.Require().NoError(err) - //s.Require().NotNil(anchorRes) + // s.Require().NoError(err) + // s.Require().NotNil(anchorRes) // //// can't anchor same data twice //_, err = s.msgClient.AnchorData(s.ctx, &data.MsgAnchorDataRequest{ // Sender: s.addr1.String(), // Cid: cidBz, //}) - //s.Require().Error(err) + // s.Require().Error(err) // //// can query data and get timestamp - //queryRes, err := s.queryClient.ByCid(s.ctx, &data.QueryByCidRequest{Cid: cidBz}) - //s.Require().NoError(err) - //s.Require().NotNil(queryRes) - //s.Require().Equal(anchorRes.Timestamp, queryRes.Timestamp) - //s.Require().Empty(queryRes.Signers) - //s.Require().Empty(queryRes.Content) + // queryRes, err := s.queryClient.ByCid(s.ctx, &data.QueryByCidRequest{Cid: cidBz}) + // s.Require().NoError(err) + // s.Require().NotNil(queryRes) + // s.Require().Equal(anchorRes.Timestamp, queryRes.Timestamp) + // s.Require().Empty(queryRes.Signers) + // s.Require().Empty(queryRes.Content) // //// can sign data //_, err = s.msgClient.SignData(s.ctx, &data.MsgSignDataRequest{ // Signers: []string{s.addr1.String()}, // Cid: cidBz, //}) - //s.Require().NoError(err) + // s.Require().NoError(err) // //// can retrieve signature, same timestamp //// can query data and get timestamp - //queryRes, err = s.queryClient.ByCid(s.ctx, &data.QueryByCidRequest{Cid: cidBz}) - //s.Require().NoError(err) - //s.Require().NotNil(queryRes) - //s.Require().Equal(anchorRes.Timestamp, queryRes.Timestamp) - //s.Require().Equal([]string{s.addr1.String()}, queryRes.Signers) - //s.Require().Empty(queryRes.Content) + // queryRes, err = s.queryClient.ByCid(s.ctx, &data.QueryByCidRequest{Cid: cidBz}) + // s.Require().NoError(err) + // s.Require().NotNil(queryRes) + // s.Require().Equal(anchorRes.Timestamp, queryRes.Timestamp) + // s.Require().Equal([]string{s.addr1.String()}, queryRes.Signers) + // s.Require().Empty(queryRes.Content) // //// query data by signer - //bySignerRes, err := s.queryClient.BySigner(s.ctx, &data.QueryBySignerRequest{ + // bySignerRes, err := s.queryClient.BySigner(s.ctx, &data.QueryBySignerRequest{ // Signer: s.addr1.String(), //}) - //s.Require().NoError(err) - //s.Require().NotNil(bySignerRes) - //s.Require().Contains(bySignerRes.Cids, cidBz) + // s.Require().NoError(err) + // s.Require().NotNil(bySignerRes) + // s.Require().Contains(bySignerRes.Cids, cidBz) // //// can't store bad data - //_, err = s.msgClient.StoreData(s.ctx, &data.MsgStoreDataRequest{ + // _, err = s.msgClient.StoreData(s.ctx, &data.MsgStoreDataRequest{ // Sender: s.addr1.String(), // Cid: cidBz, // Content: []byte("sgkjhsgouiyh"), //}) - //s.Require().Error(err) + // s.Require().Error(err) // //// can store good data //_, err = s.msgClient.StoreData(s.ctx, &data.MsgStoreDataRequest{ @@ -110,38 +109,38 @@ func (s *IntegrationTestSuite) TestScenario() { // Cid: cidBz, // Content: testContent, //}) - //s.Require().NoError(err) + // s.Require().NoError(err) // //// can retrieve signature, same timestamp, and data - //queryRes, err = s.queryClient.ByCid(s.ctx, &data.QueryByCidRequest{Cid: cidBz}) - //s.Require().NoError(err) - //s.Require().NotNil(queryRes) - //s.Require().Equal(anchorRes.Timestamp, queryRes.Timestamp) - //s.Require().Equal([]string{s.addr1.String()}, queryRes.Signers) - //s.Require().Equal(testContent, queryRes.Content) + // queryRes, err = s.queryClient.ByCid(s.ctx, &data.QueryByCidRequest{Cid: cidBz}) + // s.Require().NoError(err) + // s.Require().NotNil(queryRes) + // s.Require().Equal(anchorRes.Timestamp, queryRes.Timestamp) + // s.Require().Equal([]string{s.addr1.String()}, queryRes.Signers) + // s.Require().Equal(testContent, queryRes.Content) // //// another signer can sign //_, err = s.msgClient.SignData(s.ctx, &data.MsgSignDataRequest{ // Signers: []string{s.addr2.String()}, // Cid: cidBz, //}) - //s.Require().NoError(err) + // s.Require().NoError(err) // //// query data by signer - //bySignerRes, err = s.queryClient.BySigner(s.ctx, &data.QueryBySignerRequest{ + // bySignerRes, err = s.queryClient.BySigner(s.ctx, &data.QueryBySignerRequest{ // Signer: s.addr2.String(), //}) - //s.Require().NoError(err) - //s.Require().NotNil(bySignerRes) - //s.Require().Contains(bySignerRes.Cids, cidBz) + // s.Require().NoError(err) + // s.Require().NotNil(bySignerRes) + // s.Require().Contains(bySignerRes.Cids, cidBz) // //// query all data and both signatures - //queryRes, err = s.queryClient.ByCid(s.ctx, &data.QueryByCidRequest{Cid: cidBz}) - //s.Require().NoError(err) - //s.Require().NotNil(queryRes) - //s.Require().Equal(anchorRes.Timestamp, queryRes.Timestamp) - //s.Require().Len(queryRes.Signers, 2) - //s.Require().Contains(queryRes.Signers, s.addr1.String()) - //s.Require().Contains(queryRes.Signers, s.addr2.String()) - //s.Require().Equal(testContent, queryRes.Content) + // queryRes, err = s.queryClient.ByCid(s.ctx, &data.QueryByCidRequest{Cid: cidBz}) + // s.Require().NoError(err) + // s.Require().NotNil(queryRes) + // s.Require().Equal(anchorRes.Timestamp, queryRes.Timestamp) + // s.Require().Len(queryRes.Signers, 2) + // s.Require().Contains(queryRes.Signers, s.addr1.String()) + // s.Require().Contains(queryRes.Signers, s.addr2.String()) + // s.Require().Equal(testContent, queryRes.Content) } diff --git a/x/group/server/testsuite/suite.go b/x/group/server/testsuite/suite.go index d5abdf6962..068cbdfef9 100644 --- a/x/group/server/testsuite/suite.go +++ b/x/group/server/testsuite/suite.go @@ -3,27 +3,32 @@ package testsuite import ( "bytes" "context" - "github.com/regen-network/regen-ledger/testutil/testdata" "sort" "strings" "time" + "github.com/regen-network/regen-ledger/testutil/testdata" + "github.com/regen-network/regen-ledger/testutil" servermodule "github.com/regen-network/regen-ledger/types/module/server" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + bank "github.com/cosmos/cosmos-sdk/x/bank" + gogotypes "github.com/gogo/protobuf/types" + "github.com/stretchr/testify/suite" "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" - bank "github.com/cosmos/cosmos-sdk/x/bank" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/regen-network/regen-ledger/types" + "github.com/regen-network/regen-ledger/x/group" + groupserver "github.com/regen-network/regen-ledger/x/group/server" ) From a5338df422a01e6690deb767a30cd6dcf274fcbe Mon Sep 17 00:00:00 2001 From: likhita Date: Fri, 26 Feb 2021 17:25:57 +0530 Subject: [PATCH 05/96] add-TallyVotesInvariant --- types/module/server/manager.go | 4 +- types/module/server/module.go | 2 +- x/group/server/invariant.go | 92 ++++ x/group/server/query_server.go | 4 + x/group/server/server.go | 1 - x/temp/config/app.toml | 152 +++++++ x/temp/config/config.toml | 393 ++++++++++++++++++ x/temp/config/node_key.json | 1 + x/temp/config/priv_validator_key.json | 11 + x/temp/data/application.db/000001.log | 0 x/temp/data/application.db/CURRENT | 1 + x/temp/data/application.db/LOCK | 0 x/temp/data/application.db/LOG | 6 + x/temp/data/application.db/MANIFEST-000000 | Bin 0 -> 54 bytes x/temp/data/blockstore.db/000001.log | 0 x/temp/data/blockstore.db/CURRENT | 1 + x/temp/data/blockstore.db/LOCK | 0 x/temp/data/blockstore.db/LOG | 6 + x/temp/data/blockstore.db/MANIFEST-000000 | Bin 0 -> 54 bytes x/temp/data/priv_validator_state.json | 5 + x/temp/data/snapshots/metadata.db/000001.log | 0 x/temp/data/snapshots/metadata.db/CURRENT | 1 + x/temp/data/snapshots/metadata.db/LOCK | 0 x/temp/data/snapshots/metadata.db/LOG | 6 + .../snapshots/metadata.db/MANIFEST-000000 | Bin 0 -> 54 bytes x/temp/data/state.db/000001.log | 0 x/temp/data/state.db/CURRENT | 1 + x/temp/data/state.db/LOCK | 0 x/temp/data/state.db/LOG | 6 + x/temp/data/state.db/MANIFEST-000000 | Bin 0 -> 54 bytes 30 files changed, 689 insertions(+), 4 deletions(-) create mode 100644 x/group/server/invariant.go create mode 100644 x/temp/config/app.toml create mode 100644 x/temp/config/config.toml create mode 100644 x/temp/config/node_key.json create mode 100644 x/temp/config/priv_validator_key.json create mode 100644 x/temp/data/application.db/000001.log create mode 100644 x/temp/data/application.db/CURRENT create mode 100644 x/temp/data/application.db/LOCK create mode 100644 x/temp/data/application.db/LOG create mode 100644 x/temp/data/application.db/MANIFEST-000000 create mode 100644 x/temp/data/blockstore.db/000001.log create mode 100644 x/temp/data/blockstore.db/CURRENT create mode 100644 x/temp/data/blockstore.db/LOCK create mode 100644 x/temp/data/blockstore.db/LOG create mode 100644 x/temp/data/blockstore.db/MANIFEST-000000 create mode 100644 x/temp/data/priv_validator_state.json create mode 100644 x/temp/data/snapshots/metadata.db/000001.log create mode 100644 x/temp/data/snapshots/metadata.db/CURRENT create mode 100644 x/temp/data/snapshots/metadata.db/LOCK create mode 100644 x/temp/data/snapshots/metadata.db/LOG create mode 100644 x/temp/data/snapshots/metadata.db/MANIFEST-000000 create mode 100644 x/temp/data/state.db/000001.log create mode 100644 x/temp/data/state.db/CURRENT create mode 100644 x/temp/data/state.db/LOCK create mode 100644 x/temp/data/state.db/LOG create mode 100644 x/temp/data/state.db/MANIFEST-000000 diff --git a/types/module/server/manager.go b/types/module/server/manager.go index 3dd141d7cb..d173b68238 100644 --- a/types/module/server/manager.go +++ b/types/module/server/manager.go @@ -160,8 +160,8 @@ func (c *configurator) QueryServer() gogogrpc.Server { return c.queryServer } -func (c *configurator) RegisterInvariants() sdk.InvariantRegistry { - return c.registerInvariants +func (c *configurator) RegisterInvariants(registry sdk.InvariantRegistry) { + c.registerInvariants = registry } func (c *configurator) ModuleKey() RootModuleKey { diff --git a/types/module/server/module.go b/types/module/server/module.go index 12826f593b..14967a3c9a 100644 --- a/types/module/server/module.go +++ b/types/module/server/module.go @@ -20,7 +20,7 @@ type Configurator interface { ModuleKey() RootModuleKey Marshaler() codec.Marshaler RequireServer(interface{}) - RegisterInvariants() sdk.InvariantRegistry + RegisterInvariants(registry sdk.InvariantRegistry) // Router() is temporarily added here to use in the group module. // TODO: remove once #225 addressed Router() sdk.Router diff --git a/x/group/server/invariant.go b/x/group/server/invariant.go new file mode 100644 index 0000000000..44b30a397c --- /dev/null +++ b/x/group/server/invariant.go @@ -0,0 +1,92 @@ +package server + +import ( + "fmt" + "strconv" + + "github.com/cosmos/cosmos-sdk/types/query" + "github.com/regen-network/regen-ledger/orm" + "github.com/regen-network/regen-ledger/types" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/regen-network/regen-ledger/x/group" +) + +type resTally struct { + YesCount int64 + NoCount int64 + AbstainCount int64 + VetoCount int64 +} + +func resultVoteState(v group.Tally) resTally { + return resTally{ + YesCount: strToInt(v.YesCount), + NoCount: strToInt(v.NoCount), + AbstainCount: strToInt(v.AbstainCount), + VetoCount: strToInt(v.VetoCount), + } +} + +func strToInt(str string) int64 { + integer, _ := strconv.ParseInt(str, 10, 64) + return integer +} + +func (s serverImpl) RegisterInvariants(ir sdk.InvariantRegistry) { + ir.RegisterRoute(group.ModuleName, "Tally-Votes", s.TallyVotesInvariant()) +} + +func (s serverImpl) AllInvariants() sdk.Invariant { + return func(ctx sdk.Context) (string, bool) { + res, stop := s.TallyVotesInvariant()(ctx) + if stop { + return res, stop + } + return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", fmt.Sprintf("\tTallyVoteSums is failed")), false + } +} + +func (s serverImpl) TallyVotesInvariant() sdk.Invariant { + return func(sdkCtx sdk.Context) (string, bool) { + ctx := types.Context{Context: sdkCtx} + var pageReq = query.PageRequest{ + Offset: 0, + Limit: 100, + CountTotal: true, + } + it, err := s.getAllProposals(ctx, &pageReq) + if err != nil { + return "No proposals found", false + } + + var Proposals2 []*group.Proposal + _, err = orm.Paginate(it, &pageReq, &Proposals2) + if err != nil { + return "", false + } + sdkCtx = sdkCtx.WithBlockHeight(ctx.BlockHeight() - 1) + it2, err := s.getAllProposals(types.Context{Context: sdkCtx}, &pageReq) + if err != nil { + return "No proposals found", false + } + + var Proposals []*group.Proposal + _, err = orm.Paginate(it2, &pageReq, &Proposals) + if err != nil { + return "", false + } + + for i := 0; i < len(Proposals) && i < len(Proposals2); i++ { + if int32(Proposals[i].Status) == 1 && int32(Proposals2[i].Status) == 1 { + var voteState1 = resultVoteState(Proposals[i].VoteState) + var voteState2 = resultVoteState(Proposals2[i].VoteState) + if (voteState2.YesCount >= voteState1.YesCount) && (voteState2.NoCount >= voteState1.NoCount) && (voteState2.AbstainCount >= voteState1.AbstainCount) && (voteState2.VetoCount >= voteState1.VetoCount) { + return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", fmt.Sprintf("\tTallyVoteSums is passed\n")), true + } + } + } + return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", fmt.Sprintf("\tTallyVoteSums is failed")), false + } +} diff --git a/x/group/server/query_server.go b/x/group/server/query_server.go index 05e7736adb..7ee8c8adbe 100644 --- a/x/group/server/query_server.go +++ b/x/group/server/query_server.go @@ -176,6 +176,10 @@ func (s serverImpl) getProposalsByGroupAccount(ctx types.Context, account sdk.Ac return s.proposalByGroupAccountIndex.GetPaginated(ctx, account.Bytes(), pageRequest) } +func (s serverImpl) getAllProposals(ctx types.Context, pageRequest *query.PageRequest) (orm.Iterator, error) { + return s.proposalTable.PrefixScan(ctx, pageRequest.Offset, pageRequest.Limit) +} + func (s serverImpl) getProposal(ctx types.Context, proposalID uint64) (group.Proposal, error) { var p group.Proposal if _, err := s.proposalTable.GetOne(ctx, proposalID, &p); err != nil { diff --git a/x/group/server/server.go b/x/group/server/server.go index db855c1bd0..8714449c54 100644 --- a/x/group/server/server.go +++ b/x/group/server/server.go @@ -165,5 +165,4 @@ func RegisterServices(configurator servermodule.Configurator, accountKeeper Acco impl := newServer(configurator.ModuleKey(), configurator.Router(), accountKeeper, configurator.Marshaler()) group.RegisterMsgServer(configurator.MsgServer(), impl) group.RegisterQueryServer(configurator.QueryServer(), impl) - configurator.RegisterInvariants() } diff --git a/x/temp/config/app.toml b/x/temp/config/app.toml new file mode 100644 index 0000000000..54de73e392 --- /dev/null +++ b/x/temp/config/app.toml @@ -0,0 +1,152 @@ +# This is a TOML config file. +# For more information, see https://github.com/toml-lang/toml + +############################################################################### +### Base Configuration ### +############################################################################### + +# The minimum gas prices a validator is willing to accept for processing a +# transaction. A transaction's fees must meet the minimum of any denomination +# specified in this config (e.g. 0.25token1;0.0001token2). +minimum-gas-prices = "" + +# default: the last 100 states are kept in addition to every 500th state; pruning at 10 block intervals +# nothing: all historic states will be saved, nothing will be deleted (i.e. archiving node) +# everything: all saved states will be deleted, storing only the current state; pruning at 10 block intervals +# custom: allow pruning options to be manually specified through 'pruning-keep-recent', 'pruning-keep-every', and 'pruning-interval' +pruning = "default" + +# These are applied if and only if the pruning strategy is custom. +pruning-keep-recent = "0" +pruning-keep-every = "0" +pruning-interval = "0" + +# HaltHeight contains a non-zero block height at which a node will gracefully +# halt and shutdown that can be used to assist upgrades and testing. +# +# Note: Commitment of state will be attempted on the corresponding block. +halt-height = 0 + +# HaltTime contains a non-zero minimum block time (in Unix seconds) at which +# a node will gracefully halt and shutdown that can be used to assist upgrades +# and testing. +# +# Note: Commitment of state will be attempted on the corresponding block. +halt-time = 0 + +# MinRetainBlocks defines the minimum block height offset from the current +# block being committed, such that all blocks past this offset are pruned +# from Tendermint. It is used as part of the process of determining the +# ResponseCommit.RetainHeight value during ABCI Commit. A value of 0 indicates +# that no blocks should be pruned. +# +# This configuration value is only responsible for pruning Tendermint blocks. +# It has no bearing on application state pruning which is determined by the +# "pruning-*" configurations. +# +# Note: Tendermint block pruning is dependant on this parameter in conunction +# with the unbonding (safety threshold) period, state pruning and state sync +# snapshot parameters to determine the correct minimum value of +# ResponseCommit.RetainHeight. +min-retain-blocks = 0 + +# InterBlockCache enables inter-block caching. +inter-block-cache = true + +# IndexEvents defines the set of events in the form {eventType}.{attributeKey}, +# which informs Tendermint what to index. If empty, all events will be indexed. +# +# Example: +# ["message.sender", "message.recipient"] +index-events = [] + +############################################################################### +### Telemetry Configuration ### +############################################################################### + +[telemetry] + +# Prefixed with keys to separate services. +service-name = "" + +# Enabled enables the application telemetry functionality. When enabled, +# an in-memory sink is also enabled by default. Operators may also enabled +# other sinks such as Prometheus. +enabled = false + +# Enable prefixing gauge values with hostname. +enable-hostname = false + +# Enable adding hostname to labels. +enable-hostname-label = false + +# Enable adding service to labels. +enable-service-label = false + +# PrometheusRetentionTime, when positive, enables a Prometheus metrics sink. +prometheus-retention-time = 0 + +# GlobalLabels defines a global set of name/value label tuples applied to all +# metrics emitted using the wrapper functions defined in telemetry package. +# +# Example: +# [["chain_id", "cosmoshub-1"]] +global-labels = [ +] + +############################################################################### +### API Configuration ### +############################################################################### + +[api] + +# Enable defines if the API server should be enabled. +enable = false + +# Swagger defines if swagger documentation should automatically be registered. +swagger = false + +# Address defines the API server to listen on. +address = "tcp://0.0.0.0:1317" + +# MaxOpenConnections defines the number of maximum open connections. +max-open-connections = 1000 + +# RPCReadTimeout defines the Tendermint RPC read timeout (in seconds). +rpc-read-timeout = 10 + +# RPCWriteTimeout defines the Tendermint RPC write timeout (in seconds). +rpc-write-timeout = 0 + +# RPCMaxBodyBytes defines the Tendermint maximum response body (in bytes). +rpc-max-body-bytes = 1000000 + +# EnableUnsafeCORS defines if CORS should be enabled (unsafe - use it at your own risk). +enabled-unsafe-cors = false + +############################################################################### +### gRPC Configuration ### +############################################################################### + +[grpc] + +# Enable defines if the gRPC server should be enabled. +enable = true + +# Address defines the gRPC server address to bind to. +address = "0.0.0.0:9090" + +############################################################################### +### State Sync Configuration ### +############################################################################### + +# State sync snapshots allow other nodes to rapidly join the network without replaying historical +# blocks, instead downloading and applying a snapshot of the application state at a given height. +[state-sync] + +# snapshot-interval specifies the block interval at which local state sync snapshots are +# taken (0 to disable). Must be a multiple of pruning-keep-every. +snapshot-interval = 0 + +# snapshot-keep-recent specifies the number of recent snapshots to keep and serve (0 to keep all). +snapshot-keep-recent = 2 diff --git a/x/temp/config/config.toml b/x/temp/config/config.toml new file mode 100644 index 0000000000..a4732ca910 --- /dev/null +++ b/x/temp/config/config.toml @@ -0,0 +1,393 @@ +# This is a TOML config file. +# For more information, see https://github.com/toml-lang/toml + +# NOTE: Any path below can be absolute (e.g. "/var/myawesomeapp/data") or +# relative to the home directory (e.g. "data"). The home directory is +# "$HOME/.tendermint" by default, but could be changed via $TMHOME env variable +# or --home cmd flag. + +####################################################################### +### Main Base Config Options ### +####################################################################### + +# TCP or UNIX socket address of the ABCI application, +# or the name of an ABCI application compiled in with the Tendermint binary +proxy_app = "tcp://127.0.0.1:26658" + +# A custom human readable name for this node +moniker = "vitwit-Vostro-15-3568" + +# If this node is many blocks behind the tip of the chain, FastSync +# allows them to catchup quickly by downloading blocks in parallel +# and verifying their commits +fast_sync = true + +# Database backend: goleveldb | cleveldb | boltdb | rocksdb | badgerdb +# * goleveldb (github.com/syndtr/goleveldb - most popular implementation) +# - pure go +# - stable +# * cleveldb (uses levigo wrapper) +# - fast +# - requires gcc +# - use cleveldb build tag (go build -tags cleveldb) +# * boltdb (uses etcd's fork of bolt - github.com/etcd-io/bbolt) +# - EXPERIMENTAL +# - may be faster is some use-cases (random reads - indexer) +# - use boltdb build tag (go build -tags boltdb) +# * rocksdb (uses github.com/tecbot/gorocksdb) +# - EXPERIMENTAL +# - requires gcc +# - use rocksdb build tag (go build -tags rocksdb) +# * badgerdb (uses github.com/dgraph-io/badger) +# - EXPERIMENTAL +# - use badgerdb build tag (go build -tags badgerdb) +db_backend = "goleveldb" + +# Database directory +db_dir = "data" + +# Output level for logging, including package level options +log_level = "main:info,state:info,statesync:info,*:error" + +# Output format: 'plain' (colored text) or 'json' +log_format = "plain" + +##### additional base config options ##### + +# Path to the JSON file containing the initial validator set and other meta data +genesis_file = "config/genesis.json" + +# Path to the JSON file containing the private key to use as a validator in the consensus protocol +priv_validator_key_file = "config/priv_validator_key.json" + +# Path to the JSON file containing the last sign state of a validator +priv_validator_state_file = "data/priv_validator_state.json" + +# TCP or UNIX socket address for Tendermint to listen on for +# connections from an external PrivValidator process +priv_validator_laddr = "" + +# Path to the JSON file containing the private key to use for node authentication in the p2p protocol +node_key_file = "config/node_key.json" + +# Mechanism to connect to the ABCI application: socket | grpc +abci = "socket" + +# If true, query the ABCI app on connecting to a new peer +# so the app can decide if we should keep the connection or not +filter_peers = false + + +####################################################################### +### Advanced Configuration Options ### +####################################################################### + +####################################################### +### RPC Server Configuration Options ### +####################################################### +[rpc] + +# TCP or UNIX socket address for the RPC server to listen on +laddr = "tcp://127.0.0.1:26657" + +# A list of origins a cross-domain request can be executed from +# Default value '[]' disables cors support +# Use '["*"]' to allow any origin +cors_allowed_origins = [] + +# A list of methods the client is allowed to use with cross-domain requests +cors_allowed_methods = ["HEAD", "GET", "POST", ] + +# A list of non simple headers the client is allowed to use with cross-domain requests +cors_allowed_headers = ["Origin", "Accept", "Content-Type", "X-Requested-With", "X-Server-Time", ] + +# TCP or UNIX socket address for the gRPC server to listen on +# NOTE: This server only supports /broadcast_tx_commit +grpc_laddr = "" + +# Maximum number of simultaneous connections. +# Does not include RPC (HTTP&WebSocket) connections. See max_open_connections +# If you want to accept a larger number than the default, make sure +# you increase your OS limits. +# 0 - unlimited. +# Should be < {ulimit -Sn} - {MaxNumInboundPeers} - {MaxNumOutboundPeers} - {N of wal, db and other open files} +# 1024 - 40 - 10 - 50 = 924 = ~900 +grpc_max_open_connections = 900 + +# Activate unsafe RPC commands like /dial_seeds and /unsafe_flush_mempool +unsafe = false + +# Maximum number of simultaneous connections (including WebSocket). +# Does not include gRPC connections. See grpc_max_open_connections +# If you want to accept a larger number than the default, make sure +# you increase your OS limits. +# 0 - unlimited. +# Should be < {ulimit -Sn} - {MaxNumInboundPeers} - {MaxNumOutboundPeers} - {N of wal, db and other open files} +# 1024 - 40 - 10 - 50 = 924 = ~900 +max_open_connections = 900 + +# Maximum number of unique clientIDs that can /subscribe +# If you're using /broadcast_tx_commit, set to the estimated maximum number +# of broadcast_tx_commit calls per block. +max_subscription_clients = 100 + +# Maximum number of unique queries a given client can /subscribe to +# If you're using GRPC (or Local RPC client) and /broadcast_tx_commit, set to +# the estimated # maximum number of broadcast_tx_commit calls per block. +max_subscriptions_per_client = 5 + +# How long to wait for a tx to be committed during /broadcast_tx_commit. +# WARNING: Using a value larger than 10s will result in increasing the +# global HTTP write timeout, which applies to all connections and endpoints. +# See https://github.com/tendermint/tendermint/issues/3435 +timeout_broadcast_tx_commit = "10s" + +# Maximum size of request body, in bytes +max_body_bytes = 1000000 + +# Maximum size of request header, in bytes +max_header_bytes = 1048576 + +# The path to a file containing certificate that is used to create the HTTPS server. +# Might be either absolute path or path related to Tendermint's config directory. +# If the certificate is signed by a certificate authority, +# the certFile should be the concatenation of the server's certificate, any intermediates, +# and the CA's certificate. +# NOTE: both tls_cert_file and tls_key_file must be present for Tendermint to create HTTPS server. +# Otherwise, HTTP server is run. +tls_cert_file = "" + +# The path to a file containing matching private key that is used to create the HTTPS server. +# Might be either absolute path or path related to Tendermint's config directory. +# NOTE: both tls-cert-file and tls-key-file must be present for Tendermint to create HTTPS server. +# Otherwise, HTTP server is run. +tls_key_file = "" + +# pprof listen address (https://golang.org/pkg/net/http/pprof) +pprof_laddr = "localhost:6060" + +####################################################### +### P2P Configuration Options ### +####################################################### +[p2p] + +# Address to listen for incoming connections +laddr = "tcp://0.0.0.0:26656" + +# Address to advertise to peers for them to dial +# If empty, will use the same port as the laddr, +# and will introspect on the listener or use UPnP +# to figure out the address. +external_address = "" + +# Comma separated list of seed nodes to connect to +seeds = "" + +# Comma separated list of nodes to keep persistent connections to +persistent_peers = "" + +# UPNP port forwarding +upnp = false + +# Path to address book +addr_book_file = "config/addrbook.json" + +# Set true for strict address routability rules +# Set false for private or local networks +addr_book_strict = true + +# Maximum number of inbound peers +max_num_inbound_peers = 40 + +# Maximum number of outbound peers to connect to, excluding persistent peers +max_num_outbound_peers = 10 + +# List of node IDs, to which a connection will be (re)established ignoring any existing limits +unconditional_peer_ids = "" + +# Maximum pause when redialing a persistent peer (if zero, exponential backoff is used) +persistent_peers_max_dial_period = "0s" + +# Time to wait before flushing messages out on the connection +flush_throttle_timeout = "100ms" + +# Maximum size of a message packet payload, in bytes +max_packet_msg_payload_size = 1024 + +# Rate at which packets can be sent, in bytes/second +send_rate = 5120000 + +# Rate at which packets can be received, in bytes/second +recv_rate = 5120000 + +# Set true to enable the peer-exchange reactor +pex = true + +# Seed mode, in which node constantly crawls the network and looks for +# peers. If another node asks it for addresses, it responds and disconnects. +# +# Does not work if the peer-exchange reactor is disabled. +seed_mode = false + +# Comma separated list of peer IDs to keep private (will not be gossiped to other peers) +private_peer_ids = "" + +# Toggle to disable guard against peers connecting from the same ip. +allow_duplicate_ip = false + +# Peer connection configuration. +handshake_timeout = "20s" +dial_timeout = "3s" + +####################################################### +### Mempool Configuration Option ### +####################################################### +[mempool] + +recheck = true +broadcast = true +wal_dir = "" + +# Maximum number of transactions in the mempool +size = 5000 + +# Limit the total size of all txs in the mempool. +# This only accounts for raw transactions (e.g. given 1MB transactions and +# max_txs_bytes=5MB, mempool will only accept 5 transactions). +max_txs_bytes = 1073741824 + +# Size of the cache (used to filter transactions we saw earlier) in transactions +cache_size = 10000 + +# Do not remove invalid transactions from the cache (default: false) +# Set to true if it's not possible for any invalid transaction to become valid +# again in the future. +keep-invalid-txs-in-cache = false + +# Maximum size of a single transaction. +# NOTE: the max size of a tx transmitted over the network is {max_tx_bytes}. +max_tx_bytes = 1048576 + +# Maximum size of a batch of transactions to send to a peer +# Including space needed by encoding (one varint per transaction). +# XXX: Unused due to https://github.com/tendermint/tendermint/issues/5796 +max_batch_bytes = 0 + +####################################################### +### State Sync Configuration Options ### +####################################################### +[statesync] +# State sync rapidly bootstraps a new node by discovering, fetching, and restoring a state machine +# snapshot from peers instead of fetching and replaying historical blocks. Requires some peers in +# the network to take and serve state machine snapshots. State sync is not attempted if the node +# has any local state (LastBlockHeight > 0). The node will have a truncated block history, +# starting from the height of the snapshot. +enable = false + +# RPC servers (comma-separated) for light client verification of the synced state machine and +# retrieval of state data for node bootstrapping. Also needs a trusted height and corresponding +# header hash obtained from a trusted source, and a period during which validators can be trusted. +# +# For Cosmos SDK-based chains, trust_period should usually be about 2/3 of the unbonding time (~2 +# weeks) during which they can be financially punished (slashed) for misbehavior. +rpc_servers = "" +trust_height = 0 +trust_hash = "" +trust_period = "168h0m0s" + +# Time to spend discovering snapshots before initiating a restore. +discovery_time = "15s" + +# Temporary directory for state sync snapshot chunks, defaults to the OS tempdir (typically /tmp). +# Will create a new, randomly named directory within, and remove it when done. +temp_dir = "" + +####################################################### +### Fast Sync Configuration Connections ### +####################################################### +[fastsync] + +# Fast Sync version to use: +# 1) "v0" (default) - the legacy fast sync implementation +# 2) "v1" - refactor of v0 version for better testability +# 2) "v2" - complete redesign of v0, optimized for testability & readability +version = "v0" + +####################################################### +### Consensus Configuration Options ### +####################################################### +[consensus] + +wal_file = "data/cs.wal/wal" + +# How long we wait for a proposal block before prevoting nil +timeout_propose = "3s" +# How much timeout_propose increases with each round +timeout_propose_delta = "500ms" +# How long we wait after receiving +2/3 prevotes for “anything” (ie. not a single block or nil) +timeout_prevote = "1s" +# How much the timeout_prevote increases with each round +timeout_prevote_delta = "500ms" +# How long we wait after receiving +2/3 precommits for “anything” (ie. not a single block or nil) +timeout_precommit = "1s" +# How much the timeout_precommit increases with each round +timeout_precommit_delta = "500ms" +# How long we wait after committing a block, before starting on the new +# height (this gives us a chance to receive some more precommits, even +# though we already have +2/3). +timeout_commit = "5s" + +# How many blocks to look back to check existence of the node's consensus votes before joining consensus +# When non-zero, the node will panic upon restart +# if the same consensus key was used to sign {double_sign_check_height} last blocks. +# So, validators should stop the state machine, wait for some blocks, and then restart the state machine to avoid panic. +double_sign_check_height = 0 + +# Make progress as soon as we have all the precommits (as if TimeoutCommit = 0) +skip_timeout_commit = false + +# EmptyBlocks mode and possible interval between empty blocks +create_empty_blocks = true +create_empty_blocks_interval = "0s" + +# Reactor sleep duration parameters +peer_gossip_sleep_duration = "100ms" +peer_query_maj23_sleep_duration = "2s" + +####################################################### +### Transaction Indexer Configuration Options ### +####################################################### +[tx_index] + +# What indexer to use for transactions +# +# The application will set which txs to index. In some cases a node operator will be able +# to decide which txs to index based on configuration set in the application. +# +# Options: +# 1) "null" +# 2) "kv" (default) - the simplest possible indexer, backed by key-value storage (defaults to levelDB; see DBBackend). +# - When "kv" is chosen "tx.height" and "tx.hash" will always be indexed. +indexer = "kv" + +####################################################### +### Instrumentation Configuration Options ### +####################################################### +[instrumentation] + +# When true, Prometheus metrics are served under /metrics on +# PrometheusListenAddr. +# Check out the documentation for the list of available metrics. +prometheus = false + +# Address to listen for Prometheus collector(s) connections +prometheus_listen_addr = ":26660" + +# Maximum number of simultaneous connections. +# If you want to accept a larger number than the default, make sure +# you increase your OS limits. +# 0 - unlimited. +max_open_connections = 3 + +# Instrumentation namespace +namespace = "tendermint" diff --git a/x/temp/config/node_key.json b/x/temp/config/node_key.json new file mode 100644 index 0000000000..3b951d7fb6 --- /dev/null +++ b/x/temp/config/node_key.json @@ -0,0 +1 @@ +{"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"OZcpDb+U9LBA+Hjbg/ZIajQ5d9j7Isto2ooNWpso7lVDWUbvZmI4XqepOoGfLBiFXnemjJ/kWI3YmHuYTnIMLw=="}} \ No newline at end of file diff --git a/x/temp/config/priv_validator_key.json b/x/temp/config/priv_validator_key.json new file mode 100644 index 0000000000..fa2bfc512e --- /dev/null +++ b/x/temp/config/priv_validator_key.json @@ -0,0 +1,11 @@ +{ + "address": "142651759302924B4083281F2F0D59F53C241C05", + "pub_key": { + "type": "tendermint/PubKeyEd25519", + "value": "1oIORIWgAhHE2h1vq3f3tMylzGr5YSBVE1VyYLeRsps=" + }, + "priv_key": { + "type": "tendermint/PrivKeyEd25519", + "value": "juLU6oVkT8DESz0UIBUAF4pi++3WfXIPv0AwTtaeHfjWgg5EhaACEcTaHW+rd/e0zKXMavlhIFUTVXJgt5Gymw==" + } +} \ No newline at end of file diff --git a/x/temp/data/application.db/000001.log b/x/temp/data/application.db/000001.log new file mode 100644 index 0000000000..e69de29bb2 diff --git a/x/temp/data/application.db/CURRENT b/x/temp/data/application.db/CURRENT new file mode 100644 index 0000000000..feda7d6b24 --- /dev/null +++ b/x/temp/data/application.db/CURRENT @@ -0,0 +1 @@ +MANIFEST-000000 diff --git a/x/temp/data/application.db/LOCK b/x/temp/data/application.db/LOCK new file mode 100644 index 0000000000..e69de29bb2 diff --git a/x/temp/data/application.db/LOG b/x/temp/data/application.db/LOG new file mode 100644 index 0000000000..1c6ce9ba0f --- /dev/null +++ b/x/temp/data/application.db/LOG @@ -0,0 +1,6 @@ +=============== Feb 24, 2021 (IST) =============== +23:22:37.633472 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed +23:22:37.723592 db@open opening +23:22:37.734837 version@stat F·[] S·0B[] Sc·[] +23:22:37.809193 db@janitor F·2 G·0 +23:22:37.809278 db@open done T·85.583746ms diff --git a/x/temp/data/application.db/MANIFEST-000000 b/x/temp/data/application.db/MANIFEST-000000 new file mode 100644 index 0000000000000000000000000000000000000000..9d54f6733b1364dc8d53dd15ca59a6ec36a1c29d GIT binary patch literal 54 zcmdmC5aOo9z{n_-lUkOVlai$8R9TW*o>`pgoS$2eSd>_jU&O?~%*ev9Y~pbaHU>r} JMrI}!1^~s!4paaD literal 0 HcmV?d00001 diff --git a/x/temp/data/blockstore.db/000001.log b/x/temp/data/blockstore.db/000001.log new file mode 100644 index 0000000000..e69de29bb2 diff --git a/x/temp/data/blockstore.db/CURRENT b/x/temp/data/blockstore.db/CURRENT new file mode 100644 index 0000000000..feda7d6b24 --- /dev/null +++ b/x/temp/data/blockstore.db/CURRENT @@ -0,0 +1 @@ +MANIFEST-000000 diff --git a/x/temp/data/blockstore.db/LOCK b/x/temp/data/blockstore.db/LOCK new file mode 100644 index 0000000000..e69de29bb2 diff --git a/x/temp/data/blockstore.db/LOG b/x/temp/data/blockstore.db/LOG new file mode 100644 index 0000000000..bec4773452 --- /dev/null +++ b/x/temp/data/blockstore.db/LOG @@ -0,0 +1,6 @@ +=============== Feb 24, 2021 (IST) =============== +23:22:38.089180 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed +23:22:38.166482 db@open opening +23:22:38.167992 version@stat F·[] S·0B[] Sc·[] +23:22:38.222937 db@janitor F·2 G·0 +23:22:38.223045 db@open done T·56.481743ms diff --git a/x/temp/data/blockstore.db/MANIFEST-000000 b/x/temp/data/blockstore.db/MANIFEST-000000 new file mode 100644 index 0000000000000000000000000000000000000000..9d54f6733b1364dc8d53dd15ca59a6ec36a1c29d GIT binary patch literal 54 zcmdmC5aOo9z{n_-lUkOVlai$8R9TW*o>`pgoS$2eSd>_jU&O?~%*ev9Y~pbaHU>r} JMrI}!1^~s!4paaD literal 0 HcmV?d00001 diff --git a/x/temp/data/priv_validator_state.json b/x/temp/data/priv_validator_state.json new file mode 100644 index 0000000000..48f3b67e3f --- /dev/null +++ b/x/temp/data/priv_validator_state.json @@ -0,0 +1,5 @@ +{ + "height": "0", + "round": 0, + "step": 0 +} \ No newline at end of file diff --git a/x/temp/data/snapshots/metadata.db/000001.log b/x/temp/data/snapshots/metadata.db/000001.log new file mode 100644 index 0000000000..e69de29bb2 diff --git a/x/temp/data/snapshots/metadata.db/CURRENT b/x/temp/data/snapshots/metadata.db/CURRENT new file mode 100644 index 0000000000..feda7d6b24 --- /dev/null +++ b/x/temp/data/snapshots/metadata.db/CURRENT @@ -0,0 +1 @@ +MANIFEST-000000 diff --git a/x/temp/data/snapshots/metadata.db/LOCK b/x/temp/data/snapshots/metadata.db/LOCK new file mode 100644 index 0000000000..e69de29bb2 diff --git a/x/temp/data/snapshots/metadata.db/LOG b/x/temp/data/snapshots/metadata.db/LOG new file mode 100644 index 0000000000..d1e86b96d2 --- /dev/null +++ b/x/temp/data/snapshots/metadata.db/LOG @@ -0,0 +1,6 @@ +=============== Feb 24, 2021 (IST) =============== +23:22:37.809883 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed +23:22:37.886896 db@open opening +23:22:37.887790 version@stat F·[] S·0B[] Sc·[] +23:22:37.943284 db@janitor F·2 G·0 +23:22:37.943388 db@open done T·56.426957ms diff --git a/x/temp/data/snapshots/metadata.db/MANIFEST-000000 b/x/temp/data/snapshots/metadata.db/MANIFEST-000000 new file mode 100644 index 0000000000000000000000000000000000000000..9d54f6733b1364dc8d53dd15ca59a6ec36a1c29d GIT binary patch literal 54 zcmdmC5aOo9z{n_-lUkOVlai$8R9TW*o>`pgoS$2eSd>_jU&O?~%*ev9Y~pbaHU>r} JMrI}!1^~s!4paaD literal 0 HcmV?d00001 diff --git a/x/temp/data/state.db/000001.log b/x/temp/data/state.db/000001.log new file mode 100644 index 0000000000..e69de29bb2 diff --git a/x/temp/data/state.db/CURRENT b/x/temp/data/state.db/CURRENT new file mode 100644 index 0000000000..feda7d6b24 --- /dev/null +++ b/x/temp/data/state.db/CURRENT @@ -0,0 +1 @@ +MANIFEST-000000 diff --git a/x/temp/data/state.db/LOCK b/x/temp/data/state.db/LOCK new file mode 100644 index 0000000000..e69de29bb2 diff --git a/x/temp/data/state.db/LOG b/x/temp/data/state.db/LOG new file mode 100644 index 0000000000..5a6490fb90 --- /dev/null +++ b/x/temp/data/state.db/LOG @@ -0,0 +1,6 @@ +=============== Feb 24, 2021 (IST) =============== +23:22:38.223661 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed +23:22:38.300675 db@open opening +23:22:38.302549 version@stat F·[] S·0B[] Sc·[] +23:22:38.368421 db@janitor F·2 G·0 +23:22:38.368570 db@open done T·67.83638ms diff --git a/x/temp/data/state.db/MANIFEST-000000 b/x/temp/data/state.db/MANIFEST-000000 new file mode 100644 index 0000000000000000000000000000000000000000..9d54f6733b1364dc8d53dd15ca59a6ec36a1c29d GIT binary patch literal 54 zcmdmC5aOo9z{n_-lUkOVlai$8R9TW*o>`pgoS$2eSd>_jU&O?~%*ev9Y~pbaHU>r} JMrI}!1^~s!4paaD literal 0 HcmV?d00001 From f353d412395ccb9f013f936f9e48aad7619d45ca Mon Sep 17 00:00:00 2001 From: likhita Date: Fri, 26 Feb 2021 17:30:27 +0530 Subject: [PATCH 06/96] remove temp --- x/temp/config/app.toml | 152 ------- x/temp/config/config.toml | 393 ------------------ x/temp/config/node_key.json | 1 - x/temp/config/priv_validator_key.json | 11 - x/temp/data/application.db/000001.log | 0 x/temp/data/application.db/CURRENT | 1 - x/temp/data/application.db/LOCK | 0 x/temp/data/application.db/LOG | 6 - x/temp/data/application.db/MANIFEST-000000 | Bin 54 -> 0 bytes x/temp/data/blockstore.db/000001.log | 0 x/temp/data/blockstore.db/CURRENT | 1 - x/temp/data/blockstore.db/LOCK | 0 x/temp/data/blockstore.db/LOG | 6 - x/temp/data/blockstore.db/MANIFEST-000000 | Bin 54 -> 0 bytes x/temp/data/priv_validator_state.json | 5 - x/temp/data/snapshots/metadata.db/000001.log | 0 x/temp/data/snapshots/metadata.db/CURRENT | 1 - x/temp/data/snapshots/metadata.db/LOCK | 0 x/temp/data/snapshots/metadata.db/LOG | 6 - .../snapshots/metadata.db/MANIFEST-000000 | Bin 54 -> 0 bytes x/temp/data/state.db/000001.log | 0 x/temp/data/state.db/CURRENT | 1 - x/temp/data/state.db/LOCK | 0 x/temp/data/state.db/LOG | 6 - x/temp/data/state.db/MANIFEST-000000 | Bin 54 -> 0 bytes 25 files changed, 590 deletions(-) delete mode 100644 x/temp/config/app.toml delete mode 100644 x/temp/config/config.toml delete mode 100644 x/temp/config/node_key.json delete mode 100644 x/temp/config/priv_validator_key.json delete mode 100644 x/temp/data/application.db/000001.log delete mode 100644 x/temp/data/application.db/CURRENT delete mode 100644 x/temp/data/application.db/LOCK delete mode 100644 x/temp/data/application.db/LOG delete mode 100644 x/temp/data/application.db/MANIFEST-000000 delete mode 100644 x/temp/data/blockstore.db/000001.log delete mode 100644 x/temp/data/blockstore.db/CURRENT delete mode 100644 x/temp/data/blockstore.db/LOCK delete mode 100644 x/temp/data/blockstore.db/LOG delete mode 100644 x/temp/data/blockstore.db/MANIFEST-000000 delete mode 100644 x/temp/data/priv_validator_state.json delete mode 100644 x/temp/data/snapshots/metadata.db/000001.log delete mode 100644 x/temp/data/snapshots/metadata.db/CURRENT delete mode 100644 x/temp/data/snapshots/metadata.db/LOCK delete mode 100644 x/temp/data/snapshots/metadata.db/LOG delete mode 100644 x/temp/data/snapshots/metadata.db/MANIFEST-000000 delete mode 100644 x/temp/data/state.db/000001.log delete mode 100644 x/temp/data/state.db/CURRENT delete mode 100644 x/temp/data/state.db/LOCK delete mode 100644 x/temp/data/state.db/LOG delete mode 100644 x/temp/data/state.db/MANIFEST-000000 diff --git a/x/temp/config/app.toml b/x/temp/config/app.toml deleted file mode 100644 index 54de73e392..0000000000 --- a/x/temp/config/app.toml +++ /dev/null @@ -1,152 +0,0 @@ -# This is a TOML config file. -# For more information, see https://github.com/toml-lang/toml - -############################################################################### -### Base Configuration ### -############################################################################### - -# The minimum gas prices a validator is willing to accept for processing a -# transaction. A transaction's fees must meet the minimum of any denomination -# specified in this config (e.g. 0.25token1;0.0001token2). -minimum-gas-prices = "" - -# default: the last 100 states are kept in addition to every 500th state; pruning at 10 block intervals -# nothing: all historic states will be saved, nothing will be deleted (i.e. archiving node) -# everything: all saved states will be deleted, storing only the current state; pruning at 10 block intervals -# custom: allow pruning options to be manually specified through 'pruning-keep-recent', 'pruning-keep-every', and 'pruning-interval' -pruning = "default" - -# These are applied if and only if the pruning strategy is custom. -pruning-keep-recent = "0" -pruning-keep-every = "0" -pruning-interval = "0" - -# HaltHeight contains a non-zero block height at which a node will gracefully -# halt and shutdown that can be used to assist upgrades and testing. -# -# Note: Commitment of state will be attempted on the corresponding block. -halt-height = 0 - -# HaltTime contains a non-zero minimum block time (in Unix seconds) at which -# a node will gracefully halt and shutdown that can be used to assist upgrades -# and testing. -# -# Note: Commitment of state will be attempted on the corresponding block. -halt-time = 0 - -# MinRetainBlocks defines the minimum block height offset from the current -# block being committed, such that all blocks past this offset are pruned -# from Tendermint. It is used as part of the process of determining the -# ResponseCommit.RetainHeight value during ABCI Commit. A value of 0 indicates -# that no blocks should be pruned. -# -# This configuration value is only responsible for pruning Tendermint blocks. -# It has no bearing on application state pruning which is determined by the -# "pruning-*" configurations. -# -# Note: Tendermint block pruning is dependant on this parameter in conunction -# with the unbonding (safety threshold) period, state pruning and state sync -# snapshot parameters to determine the correct minimum value of -# ResponseCommit.RetainHeight. -min-retain-blocks = 0 - -# InterBlockCache enables inter-block caching. -inter-block-cache = true - -# IndexEvents defines the set of events in the form {eventType}.{attributeKey}, -# which informs Tendermint what to index. If empty, all events will be indexed. -# -# Example: -# ["message.sender", "message.recipient"] -index-events = [] - -############################################################################### -### Telemetry Configuration ### -############################################################################### - -[telemetry] - -# Prefixed with keys to separate services. -service-name = "" - -# Enabled enables the application telemetry functionality. When enabled, -# an in-memory sink is also enabled by default. Operators may also enabled -# other sinks such as Prometheus. -enabled = false - -# Enable prefixing gauge values with hostname. -enable-hostname = false - -# Enable adding hostname to labels. -enable-hostname-label = false - -# Enable adding service to labels. -enable-service-label = false - -# PrometheusRetentionTime, when positive, enables a Prometheus metrics sink. -prometheus-retention-time = 0 - -# GlobalLabels defines a global set of name/value label tuples applied to all -# metrics emitted using the wrapper functions defined in telemetry package. -# -# Example: -# [["chain_id", "cosmoshub-1"]] -global-labels = [ -] - -############################################################################### -### API Configuration ### -############################################################################### - -[api] - -# Enable defines if the API server should be enabled. -enable = false - -# Swagger defines if swagger documentation should automatically be registered. -swagger = false - -# Address defines the API server to listen on. -address = "tcp://0.0.0.0:1317" - -# MaxOpenConnections defines the number of maximum open connections. -max-open-connections = 1000 - -# RPCReadTimeout defines the Tendermint RPC read timeout (in seconds). -rpc-read-timeout = 10 - -# RPCWriteTimeout defines the Tendermint RPC write timeout (in seconds). -rpc-write-timeout = 0 - -# RPCMaxBodyBytes defines the Tendermint maximum response body (in bytes). -rpc-max-body-bytes = 1000000 - -# EnableUnsafeCORS defines if CORS should be enabled (unsafe - use it at your own risk). -enabled-unsafe-cors = false - -############################################################################### -### gRPC Configuration ### -############################################################################### - -[grpc] - -# Enable defines if the gRPC server should be enabled. -enable = true - -# Address defines the gRPC server address to bind to. -address = "0.0.0.0:9090" - -############################################################################### -### State Sync Configuration ### -############################################################################### - -# State sync snapshots allow other nodes to rapidly join the network without replaying historical -# blocks, instead downloading and applying a snapshot of the application state at a given height. -[state-sync] - -# snapshot-interval specifies the block interval at which local state sync snapshots are -# taken (0 to disable). Must be a multiple of pruning-keep-every. -snapshot-interval = 0 - -# snapshot-keep-recent specifies the number of recent snapshots to keep and serve (0 to keep all). -snapshot-keep-recent = 2 diff --git a/x/temp/config/config.toml b/x/temp/config/config.toml deleted file mode 100644 index a4732ca910..0000000000 --- a/x/temp/config/config.toml +++ /dev/null @@ -1,393 +0,0 @@ -# This is a TOML config file. -# For more information, see https://github.com/toml-lang/toml - -# NOTE: Any path below can be absolute (e.g. "/var/myawesomeapp/data") or -# relative to the home directory (e.g. "data"). The home directory is -# "$HOME/.tendermint" by default, but could be changed via $TMHOME env variable -# or --home cmd flag. - -####################################################################### -### Main Base Config Options ### -####################################################################### - -# TCP or UNIX socket address of the ABCI application, -# or the name of an ABCI application compiled in with the Tendermint binary -proxy_app = "tcp://127.0.0.1:26658" - -# A custom human readable name for this node -moniker = "vitwit-Vostro-15-3568" - -# If this node is many blocks behind the tip of the chain, FastSync -# allows them to catchup quickly by downloading blocks in parallel -# and verifying their commits -fast_sync = true - -# Database backend: goleveldb | cleveldb | boltdb | rocksdb | badgerdb -# * goleveldb (github.com/syndtr/goleveldb - most popular implementation) -# - pure go -# - stable -# * cleveldb (uses levigo wrapper) -# - fast -# - requires gcc -# - use cleveldb build tag (go build -tags cleveldb) -# * boltdb (uses etcd's fork of bolt - github.com/etcd-io/bbolt) -# - EXPERIMENTAL -# - may be faster is some use-cases (random reads - indexer) -# - use boltdb build tag (go build -tags boltdb) -# * rocksdb (uses github.com/tecbot/gorocksdb) -# - EXPERIMENTAL -# - requires gcc -# - use rocksdb build tag (go build -tags rocksdb) -# * badgerdb (uses github.com/dgraph-io/badger) -# - EXPERIMENTAL -# - use badgerdb build tag (go build -tags badgerdb) -db_backend = "goleveldb" - -# Database directory -db_dir = "data" - -# Output level for logging, including package level options -log_level = "main:info,state:info,statesync:info,*:error" - -# Output format: 'plain' (colored text) or 'json' -log_format = "plain" - -##### additional base config options ##### - -# Path to the JSON file containing the initial validator set and other meta data -genesis_file = "config/genesis.json" - -# Path to the JSON file containing the private key to use as a validator in the consensus protocol -priv_validator_key_file = "config/priv_validator_key.json" - -# Path to the JSON file containing the last sign state of a validator -priv_validator_state_file = "data/priv_validator_state.json" - -# TCP or UNIX socket address for Tendermint to listen on for -# connections from an external PrivValidator process -priv_validator_laddr = "" - -# Path to the JSON file containing the private key to use for node authentication in the p2p protocol -node_key_file = "config/node_key.json" - -# Mechanism to connect to the ABCI application: socket | grpc -abci = "socket" - -# If true, query the ABCI app on connecting to a new peer -# so the app can decide if we should keep the connection or not -filter_peers = false - - -####################################################################### -### Advanced Configuration Options ### -####################################################################### - -####################################################### -### RPC Server Configuration Options ### -####################################################### -[rpc] - -# TCP or UNIX socket address for the RPC server to listen on -laddr = "tcp://127.0.0.1:26657" - -# A list of origins a cross-domain request can be executed from -# Default value '[]' disables cors support -# Use '["*"]' to allow any origin -cors_allowed_origins = [] - -# A list of methods the client is allowed to use with cross-domain requests -cors_allowed_methods = ["HEAD", "GET", "POST", ] - -# A list of non simple headers the client is allowed to use with cross-domain requests -cors_allowed_headers = ["Origin", "Accept", "Content-Type", "X-Requested-With", "X-Server-Time", ] - -# TCP or UNIX socket address for the gRPC server to listen on -# NOTE: This server only supports /broadcast_tx_commit -grpc_laddr = "" - -# Maximum number of simultaneous connections. -# Does not include RPC (HTTP&WebSocket) connections. See max_open_connections -# If you want to accept a larger number than the default, make sure -# you increase your OS limits. -# 0 - unlimited. -# Should be < {ulimit -Sn} - {MaxNumInboundPeers} - {MaxNumOutboundPeers} - {N of wal, db and other open files} -# 1024 - 40 - 10 - 50 = 924 = ~900 -grpc_max_open_connections = 900 - -# Activate unsafe RPC commands like /dial_seeds and /unsafe_flush_mempool -unsafe = false - -# Maximum number of simultaneous connections (including WebSocket). -# Does not include gRPC connections. See grpc_max_open_connections -# If you want to accept a larger number than the default, make sure -# you increase your OS limits. -# 0 - unlimited. -# Should be < {ulimit -Sn} - {MaxNumInboundPeers} - {MaxNumOutboundPeers} - {N of wal, db and other open files} -# 1024 - 40 - 10 - 50 = 924 = ~900 -max_open_connections = 900 - -# Maximum number of unique clientIDs that can /subscribe -# If you're using /broadcast_tx_commit, set to the estimated maximum number -# of broadcast_tx_commit calls per block. -max_subscription_clients = 100 - -# Maximum number of unique queries a given client can /subscribe to -# If you're using GRPC (or Local RPC client) and /broadcast_tx_commit, set to -# the estimated # maximum number of broadcast_tx_commit calls per block. -max_subscriptions_per_client = 5 - -# How long to wait for a tx to be committed during /broadcast_tx_commit. -# WARNING: Using a value larger than 10s will result in increasing the -# global HTTP write timeout, which applies to all connections and endpoints. -# See https://github.com/tendermint/tendermint/issues/3435 -timeout_broadcast_tx_commit = "10s" - -# Maximum size of request body, in bytes -max_body_bytes = 1000000 - -# Maximum size of request header, in bytes -max_header_bytes = 1048576 - -# The path to a file containing certificate that is used to create the HTTPS server. -# Might be either absolute path or path related to Tendermint's config directory. -# If the certificate is signed by a certificate authority, -# the certFile should be the concatenation of the server's certificate, any intermediates, -# and the CA's certificate. -# NOTE: both tls_cert_file and tls_key_file must be present for Tendermint to create HTTPS server. -# Otherwise, HTTP server is run. -tls_cert_file = "" - -# The path to a file containing matching private key that is used to create the HTTPS server. -# Might be either absolute path or path related to Tendermint's config directory. -# NOTE: both tls-cert-file and tls-key-file must be present for Tendermint to create HTTPS server. -# Otherwise, HTTP server is run. -tls_key_file = "" - -# pprof listen address (https://golang.org/pkg/net/http/pprof) -pprof_laddr = "localhost:6060" - -####################################################### -### P2P Configuration Options ### -####################################################### -[p2p] - -# Address to listen for incoming connections -laddr = "tcp://0.0.0.0:26656" - -# Address to advertise to peers for them to dial -# If empty, will use the same port as the laddr, -# and will introspect on the listener or use UPnP -# to figure out the address. -external_address = "" - -# Comma separated list of seed nodes to connect to -seeds = "" - -# Comma separated list of nodes to keep persistent connections to -persistent_peers = "" - -# UPNP port forwarding -upnp = false - -# Path to address book -addr_book_file = "config/addrbook.json" - -# Set true for strict address routability rules -# Set false for private or local networks -addr_book_strict = true - -# Maximum number of inbound peers -max_num_inbound_peers = 40 - -# Maximum number of outbound peers to connect to, excluding persistent peers -max_num_outbound_peers = 10 - -# List of node IDs, to which a connection will be (re)established ignoring any existing limits -unconditional_peer_ids = "" - -# Maximum pause when redialing a persistent peer (if zero, exponential backoff is used) -persistent_peers_max_dial_period = "0s" - -# Time to wait before flushing messages out on the connection -flush_throttle_timeout = "100ms" - -# Maximum size of a message packet payload, in bytes -max_packet_msg_payload_size = 1024 - -# Rate at which packets can be sent, in bytes/second -send_rate = 5120000 - -# Rate at which packets can be received, in bytes/second -recv_rate = 5120000 - -# Set true to enable the peer-exchange reactor -pex = true - -# Seed mode, in which node constantly crawls the network and looks for -# peers. If another node asks it for addresses, it responds and disconnects. -# -# Does not work if the peer-exchange reactor is disabled. -seed_mode = false - -# Comma separated list of peer IDs to keep private (will not be gossiped to other peers) -private_peer_ids = "" - -# Toggle to disable guard against peers connecting from the same ip. -allow_duplicate_ip = false - -# Peer connection configuration. -handshake_timeout = "20s" -dial_timeout = "3s" - -####################################################### -### Mempool Configuration Option ### -####################################################### -[mempool] - -recheck = true -broadcast = true -wal_dir = "" - -# Maximum number of transactions in the mempool -size = 5000 - -# Limit the total size of all txs in the mempool. -# This only accounts for raw transactions (e.g. given 1MB transactions and -# max_txs_bytes=5MB, mempool will only accept 5 transactions). -max_txs_bytes = 1073741824 - -# Size of the cache (used to filter transactions we saw earlier) in transactions -cache_size = 10000 - -# Do not remove invalid transactions from the cache (default: false) -# Set to true if it's not possible for any invalid transaction to become valid -# again in the future. -keep-invalid-txs-in-cache = false - -# Maximum size of a single transaction. -# NOTE: the max size of a tx transmitted over the network is {max_tx_bytes}. -max_tx_bytes = 1048576 - -# Maximum size of a batch of transactions to send to a peer -# Including space needed by encoding (one varint per transaction). -# XXX: Unused due to https://github.com/tendermint/tendermint/issues/5796 -max_batch_bytes = 0 - -####################################################### -### State Sync Configuration Options ### -####################################################### -[statesync] -# State sync rapidly bootstraps a new node by discovering, fetching, and restoring a state machine -# snapshot from peers instead of fetching and replaying historical blocks. Requires some peers in -# the network to take and serve state machine snapshots. State sync is not attempted if the node -# has any local state (LastBlockHeight > 0). The node will have a truncated block history, -# starting from the height of the snapshot. -enable = false - -# RPC servers (comma-separated) for light client verification of the synced state machine and -# retrieval of state data for node bootstrapping. Also needs a trusted height and corresponding -# header hash obtained from a trusted source, and a period during which validators can be trusted. -# -# For Cosmos SDK-based chains, trust_period should usually be about 2/3 of the unbonding time (~2 -# weeks) during which they can be financially punished (slashed) for misbehavior. -rpc_servers = "" -trust_height = 0 -trust_hash = "" -trust_period = "168h0m0s" - -# Time to spend discovering snapshots before initiating a restore. -discovery_time = "15s" - -# Temporary directory for state sync snapshot chunks, defaults to the OS tempdir (typically /tmp). -# Will create a new, randomly named directory within, and remove it when done. -temp_dir = "" - -####################################################### -### Fast Sync Configuration Connections ### -####################################################### -[fastsync] - -# Fast Sync version to use: -# 1) "v0" (default) - the legacy fast sync implementation -# 2) "v1" - refactor of v0 version for better testability -# 2) "v2" - complete redesign of v0, optimized for testability & readability -version = "v0" - -####################################################### -### Consensus Configuration Options ### -####################################################### -[consensus] - -wal_file = "data/cs.wal/wal" - -# How long we wait for a proposal block before prevoting nil -timeout_propose = "3s" -# How much timeout_propose increases with each round -timeout_propose_delta = "500ms" -# How long we wait after receiving +2/3 prevotes for “anything” (ie. not a single block or nil) -timeout_prevote = "1s" -# How much the timeout_prevote increases with each round -timeout_prevote_delta = "500ms" -# How long we wait after receiving +2/3 precommits for “anything” (ie. not a single block or nil) -timeout_precommit = "1s" -# How much the timeout_precommit increases with each round -timeout_precommit_delta = "500ms" -# How long we wait after committing a block, before starting on the new -# height (this gives us a chance to receive some more precommits, even -# though we already have +2/3). -timeout_commit = "5s" - -# How many blocks to look back to check existence of the node's consensus votes before joining consensus -# When non-zero, the node will panic upon restart -# if the same consensus key was used to sign {double_sign_check_height} last blocks. -# So, validators should stop the state machine, wait for some blocks, and then restart the state machine to avoid panic. -double_sign_check_height = 0 - -# Make progress as soon as we have all the precommits (as if TimeoutCommit = 0) -skip_timeout_commit = false - -# EmptyBlocks mode and possible interval between empty blocks -create_empty_blocks = true -create_empty_blocks_interval = "0s" - -# Reactor sleep duration parameters -peer_gossip_sleep_duration = "100ms" -peer_query_maj23_sleep_duration = "2s" - -####################################################### -### Transaction Indexer Configuration Options ### -####################################################### -[tx_index] - -# What indexer to use for transactions -# -# The application will set which txs to index. In some cases a node operator will be able -# to decide which txs to index based on configuration set in the application. -# -# Options: -# 1) "null" -# 2) "kv" (default) - the simplest possible indexer, backed by key-value storage (defaults to levelDB; see DBBackend). -# - When "kv" is chosen "tx.height" and "tx.hash" will always be indexed. -indexer = "kv" - -####################################################### -### Instrumentation Configuration Options ### -####################################################### -[instrumentation] - -# When true, Prometheus metrics are served under /metrics on -# PrometheusListenAddr. -# Check out the documentation for the list of available metrics. -prometheus = false - -# Address to listen for Prometheus collector(s) connections -prometheus_listen_addr = ":26660" - -# Maximum number of simultaneous connections. -# If you want to accept a larger number than the default, make sure -# you increase your OS limits. -# 0 - unlimited. -max_open_connections = 3 - -# Instrumentation namespace -namespace = "tendermint" diff --git a/x/temp/config/node_key.json b/x/temp/config/node_key.json deleted file mode 100644 index 3b951d7fb6..0000000000 --- a/x/temp/config/node_key.json +++ /dev/null @@ -1 +0,0 @@ -{"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"OZcpDb+U9LBA+Hjbg/ZIajQ5d9j7Isto2ooNWpso7lVDWUbvZmI4XqepOoGfLBiFXnemjJ/kWI3YmHuYTnIMLw=="}} \ No newline at end of file diff --git a/x/temp/config/priv_validator_key.json b/x/temp/config/priv_validator_key.json deleted file mode 100644 index fa2bfc512e..0000000000 --- a/x/temp/config/priv_validator_key.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "address": "142651759302924B4083281F2F0D59F53C241C05", - "pub_key": { - "type": "tendermint/PubKeyEd25519", - "value": "1oIORIWgAhHE2h1vq3f3tMylzGr5YSBVE1VyYLeRsps=" - }, - "priv_key": { - "type": "tendermint/PrivKeyEd25519", - "value": "juLU6oVkT8DESz0UIBUAF4pi++3WfXIPv0AwTtaeHfjWgg5EhaACEcTaHW+rd/e0zKXMavlhIFUTVXJgt5Gymw==" - } -} \ No newline at end of file diff --git a/x/temp/data/application.db/000001.log b/x/temp/data/application.db/000001.log deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/x/temp/data/application.db/CURRENT b/x/temp/data/application.db/CURRENT deleted file mode 100644 index feda7d6b24..0000000000 --- a/x/temp/data/application.db/CURRENT +++ /dev/null @@ -1 +0,0 @@ -MANIFEST-000000 diff --git a/x/temp/data/application.db/LOCK b/x/temp/data/application.db/LOCK deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/x/temp/data/application.db/LOG b/x/temp/data/application.db/LOG deleted file mode 100644 index 1c6ce9ba0f..0000000000 --- a/x/temp/data/application.db/LOG +++ /dev/null @@ -1,6 +0,0 @@ -=============== Feb 24, 2021 (IST) =============== -23:22:37.633472 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed -23:22:37.723592 db@open opening -23:22:37.734837 version@stat F·[] S·0B[] Sc·[] -23:22:37.809193 db@janitor F·2 G·0 -23:22:37.809278 db@open done T·85.583746ms diff --git a/x/temp/data/application.db/MANIFEST-000000 b/x/temp/data/application.db/MANIFEST-000000 deleted file mode 100644 index 9d54f6733b1364dc8d53dd15ca59a6ec36a1c29d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 54 zcmdmC5aOo9z{n_-lUkOVlai$8R9TW*o>`pgoS$2eSd>_jU&O?~%*ev9Y~pbaHU>r} JMrI}!1^~s!4paaD diff --git a/x/temp/data/blockstore.db/000001.log b/x/temp/data/blockstore.db/000001.log deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/x/temp/data/blockstore.db/CURRENT b/x/temp/data/blockstore.db/CURRENT deleted file mode 100644 index feda7d6b24..0000000000 --- a/x/temp/data/blockstore.db/CURRENT +++ /dev/null @@ -1 +0,0 @@ -MANIFEST-000000 diff --git a/x/temp/data/blockstore.db/LOCK b/x/temp/data/blockstore.db/LOCK deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/x/temp/data/blockstore.db/LOG b/x/temp/data/blockstore.db/LOG deleted file mode 100644 index bec4773452..0000000000 --- a/x/temp/data/blockstore.db/LOG +++ /dev/null @@ -1,6 +0,0 @@ -=============== Feb 24, 2021 (IST) =============== -23:22:38.089180 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed -23:22:38.166482 db@open opening -23:22:38.167992 version@stat F·[] S·0B[] Sc·[] -23:22:38.222937 db@janitor F·2 G·0 -23:22:38.223045 db@open done T·56.481743ms diff --git a/x/temp/data/blockstore.db/MANIFEST-000000 b/x/temp/data/blockstore.db/MANIFEST-000000 deleted file mode 100644 index 9d54f6733b1364dc8d53dd15ca59a6ec36a1c29d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 54 zcmdmC5aOo9z{n_-lUkOVlai$8R9TW*o>`pgoS$2eSd>_jU&O?~%*ev9Y~pbaHU>r} JMrI}!1^~s!4paaD diff --git a/x/temp/data/priv_validator_state.json b/x/temp/data/priv_validator_state.json deleted file mode 100644 index 48f3b67e3f..0000000000 --- a/x/temp/data/priv_validator_state.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "height": "0", - "round": 0, - "step": 0 -} \ No newline at end of file diff --git a/x/temp/data/snapshots/metadata.db/000001.log b/x/temp/data/snapshots/metadata.db/000001.log deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/x/temp/data/snapshots/metadata.db/CURRENT b/x/temp/data/snapshots/metadata.db/CURRENT deleted file mode 100644 index feda7d6b24..0000000000 --- a/x/temp/data/snapshots/metadata.db/CURRENT +++ /dev/null @@ -1 +0,0 @@ -MANIFEST-000000 diff --git a/x/temp/data/snapshots/metadata.db/LOCK b/x/temp/data/snapshots/metadata.db/LOCK deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/x/temp/data/snapshots/metadata.db/LOG b/x/temp/data/snapshots/metadata.db/LOG deleted file mode 100644 index d1e86b96d2..0000000000 --- a/x/temp/data/snapshots/metadata.db/LOG +++ /dev/null @@ -1,6 +0,0 @@ -=============== Feb 24, 2021 (IST) =============== -23:22:37.809883 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed -23:22:37.886896 db@open opening -23:22:37.887790 version@stat F·[] S·0B[] Sc·[] -23:22:37.943284 db@janitor F·2 G·0 -23:22:37.943388 db@open done T·56.426957ms diff --git a/x/temp/data/snapshots/metadata.db/MANIFEST-000000 b/x/temp/data/snapshots/metadata.db/MANIFEST-000000 deleted file mode 100644 index 9d54f6733b1364dc8d53dd15ca59a6ec36a1c29d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 54 zcmdmC5aOo9z{n_-lUkOVlai$8R9TW*o>`pgoS$2eSd>_jU&O?~%*ev9Y~pbaHU>r} JMrI}!1^~s!4paaD diff --git a/x/temp/data/state.db/000001.log b/x/temp/data/state.db/000001.log deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/x/temp/data/state.db/CURRENT b/x/temp/data/state.db/CURRENT deleted file mode 100644 index feda7d6b24..0000000000 --- a/x/temp/data/state.db/CURRENT +++ /dev/null @@ -1 +0,0 @@ -MANIFEST-000000 diff --git a/x/temp/data/state.db/LOCK b/x/temp/data/state.db/LOCK deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/x/temp/data/state.db/LOG b/x/temp/data/state.db/LOG deleted file mode 100644 index 5a6490fb90..0000000000 --- a/x/temp/data/state.db/LOG +++ /dev/null @@ -1,6 +0,0 @@ -=============== Feb 24, 2021 (IST) =============== -23:22:38.223661 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed -23:22:38.300675 db@open opening -23:22:38.302549 version@stat F·[] S·0B[] Sc·[] -23:22:38.368421 db@janitor F·2 G·0 -23:22:38.368570 db@open done T·67.83638ms diff --git a/x/temp/data/state.db/MANIFEST-000000 b/x/temp/data/state.db/MANIFEST-000000 deleted file mode 100644 index 9d54f6733b1364dc8d53dd15ca59a6ec36a1c29d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 54 zcmdmC5aOo9z{n_-lUkOVlai$8R9TW*o>`pgoS$2eSd>_jU&O?~%*ev9Y~pbaHU>r} JMrI}!1^~s!4paaD From 89a43db1abf681677a77403170e16d4c759cc455 Mon Sep 17 00:00:00 2001 From: likhita Date: Fri, 26 Feb 2021 17:35:58 +0530 Subject: [PATCH 07/96] fix lint issues --- x/group/server/invariant.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/x/group/server/invariant.go b/x/group/server/invariant.go index 44b30a397c..bf9a2607dc 100644 --- a/x/group/server/invariant.go +++ b/x/group/server/invariant.go @@ -1,7 +1,6 @@ package server import ( - "fmt" "strconv" "github.com/cosmos/cosmos-sdk/types/query" @@ -44,7 +43,7 @@ func (s serverImpl) AllInvariants() sdk.Invariant { if stop { return res, stop } - return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", fmt.Sprintf("\tTallyVoteSums is failed")), false + return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "\tTallyVoteSums is failed"), false } } @@ -83,10 +82,10 @@ func (s serverImpl) TallyVotesInvariant() sdk.Invariant { var voteState1 = resultVoteState(Proposals[i].VoteState) var voteState2 = resultVoteState(Proposals2[i].VoteState) if (voteState2.YesCount >= voteState1.YesCount) && (voteState2.NoCount >= voteState1.NoCount) && (voteState2.AbstainCount >= voteState1.AbstainCount) && (voteState2.VetoCount >= voteState1.VetoCount) { - return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", fmt.Sprintf("\tTallyVoteSums is passed\n")), true + return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "\tTallyVoteSums is passed"), true } } } - return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", fmt.Sprintf("\tTallyVoteSums is failed")), false + return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "\tTallyVoteSums is failed"), false } } From 0a64ab227a4fd19c9c57d64f36c612ffb1d74136 Mon Sep 17 00:00:00 2001 From: likhita Date: Tue, 2 Mar 2021 13:41:01 +0530 Subject: [PATCH 08/96] adding invariants --- Makefile | 2 +- app/app.go | 12 +++++++++++- app/experimental_appconfig.go | 6 ++++-- app/stable_appconfig.go | 5 ++++- types/module/server/manager.go | 33 +++++++++++++++++++++------------ types/module/server/module.go | 2 +- x/group/server/invariant.go | 2 +- x/group/server/server.go | 1 + 8 files changed, 44 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index fd75bdc2fb..88ba1ae9f6 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ DOCKER_BUF := docker run -v $(shell pwd):/workspace --workdir /workspace bufbuil export GO111MODULE = on # process build tags - +EXPERIMENTAL=true build_tags = netgo ifeq ($(EXPERIMENTAL),true) diff --git a/app/app.go b/app/app.go index f63642a925..6deab6ff55 100644 --- a/app/app.go +++ b/app/app.go @@ -7,6 +7,8 @@ import ( "os" "path/filepath" + servermodule "github.com/regen-network/regen-ledger/types/module/server" + wasmclient "github.com/CosmWasm/wasmd/x/wasm/client" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" @@ -190,6 +192,13 @@ type RegenApp struct { // simulation manager sm *module.SimulationManager + + // new module manager + // XXX We will likely want to make this new manager compatible + // with module.Manager so that we can have existing cosmos-sdk modules + // use ADR 33 approach without the need for removing their keepers + // and a larger refactoring. + nm *servermodule.Manager } // NewRegenApp returns a reference to an initialized RegenApp. @@ -344,7 +353,8 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest ) // register experimental modules here - setCustomModules(app, interfaceRegistry) + app.nm = setCustomModules(app, interfaceRegistry) + app.nm.RegisterInvariants(&app.CrisisKeeper) app.mm = module.NewManager( genutil.NewAppModule( diff --git a/app/experimental_appconfig.go b/app/experimental_appconfig.go index fc496fb72d..d6b07277ef 100644 --- a/app/experimental_appconfig.go +++ b/app/experimental_appconfig.go @@ -24,10 +24,10 @@ func setCustomModuleBasics() []module.AppModuleBasic { } } -func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry) { +func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry) *servermodule.Manager { /* New Module Wiring START */ - newModuleManager := servermodule.NewManager(app.BaseApp, codec.NewProtoCodec(interfaceRegistry), nil) + newModuleManager := servermodule.NewManager(app.BaseApp, codec.NewProtoCodec(interfaceRegistry)) // BEGIN HACK: this is a total, ugly hack until x/auth supports ADR 033 or we have a suitable alternative groupModule := group.Module{AccountKeeper: app.AccountKeeper} @@ -48,6 +48,8 @@ func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry) panic(err) } /* New Module Wiring END */ + + return newModuleManager } func (app *RegenApp) registerUpgradeHandlers() { diff --git a/app/stable_appconfig.go b/app/stable_appconfig.go index a565114c88..fd65cf3d0f 100644 --- a/app/stable_appconfig.go +++ b/app/stable_appconfig.go @@ -5,12 +5,15 @@ package app import ( "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/types/module" + servermodule "github.com/regen-network/regen-ledger/types/module/server" ) func setCustomModuleBasics() []module.AppModuleBasic { return []module.AppModuleBasic{} } -func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry) {} +func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry) *servermodule.Manager { + return &servermodule.Manager{} +} func (app *RegenApp) registerUpgradeHandlers() {} diff --git a/types/module/server/manager.go b/types/module/server/manager.go index d173b68238..89849b5f33 100644 --- a/types/module/server/manager.go +++ b/types/module/server/manager.go @@ -19,16 +19,23 @@ type Manager struct { keys map[string]ModuleKey router *router requiredServices map[reflect.Type]bool - registerInvariants *sdk.InvariantRegistry + registerInvariants map[string]RegisterInvariantsHandler +} + +// RegisterInvariants registers all module routes and module querier routes +func (m *Manager) RegisterInvariants(ir sdk.InvariantRegistry) { + for _, module := range m.registerInvariants { + module(ir) + } } // NewManager creates a new Manager -func NewManager(baseApp *baseapp.BaseApp, cdc *codec.ProtoCodec, invariant sdk.InvariantRegistry) *Manager { +func NewManager(baseApp *baseapp.BaseApp, cdc *codec.ProtoCodec) *Manager { return &Manager{ baseApp: baseApp, cdc: cdc, keys: map[string]ModuleKey{}, - registerInvariants: &invariant, + registerInvariants: map[string]RegisterInvariantsHandler{}, router: &router{ handlers: map[string]handler{}, providedServices: map[reflect.Type]bool{}, @@ -90,16 +97,16 @@ func (mm *Manager) RegisterModules(modules []module.Module) error { } cfg := &configurator{ - msgServer: msgRegistrar, - queryServer: queryRegistrar, - key: key, - cdc: mm.cdc, - requiredServices: map[reflect.Type]bool{}, - router: mm.baseApp.Router(), // TODO: remove once #225 addressed - registerInvariants: *mm.registerInvariants, + msgServer: msgRegistrar, + queryServer: queryRegistrar, + key: key, + cdc: mm.cdc, + requiredServices: map[reflect.Type]bool{}, + router: mm.baseApp.Router(), // TODO: remove once #225 addressed } serverMod.RegisterServices(cfg) + mm.registerInvariants[name] = cfg.registerInvariants // If mod implements LegacyRouteModule, register module route. // This is currently used for the group module as part of #218. @@ -140,6 +147,8 @@ func (mm *Manager) CompleteInitialization() error { return nil } +type RegisterInvariantsHandler func(ir sdk.InvariantRegistry) + type configurator struct { msgServer gogogrpc.Server queryServer gogogrpc.Server @@ -147,7 +156,7 @@ type configurator struct { cdc codec.Marshaler requiredServices map[reflect.Type]bool router sdk.Router - registerInvariants sdk.InvariantRegistry + registerInvariants RegisterInvariantsHandler } var _ Configurator = &configurator{} @@ -160,7 +169,7 @@ func (c *configurator) QueryServer() gogogrpc.Server { return c.queryServer } -func (c *configurator) RegisterInvariants(registry sdk.InvariantRegistry) { +func (c *configurator) RegisterInvariants(registry RegisterInvariantsHandler) { c.registerInvariants = registry } diff --git a/types/module/server/module.go b/types/module/server/module.go index 14967a3c9a..fc49bd3ca8 100644 --- a/types/module/server/module.go +++ b/types/module/server/module.go @@ -20,7 +20,7 @@ type Configurator interface { ModuleKey() RootModuleKey Marshaler() codec.Marshaler RequireServer(interface{}) - RegisterInvariants(registry sdk.InvariantRegistry) + RegisterInvariants(registry RegisterInvariantsHandler) // Router() is temporarily added here to use in the group module. // TODO: remove once #225 addressed Router() sdk.Router diff --git a/x/group/server/invariant.go b/x/group/server/invariant.go index bf9a2607dc..47e4c0e3c0 100644 --- a/x/group/server/invariant.go +++ b/x/group/server/invariant.go @@ -81,7 +81,7 @@ func (s serverImpl) TallyVotesInvariant() sdk.Invariant { if int32(Proposals[i].Status) == 1 && int32(Proposals2[i].Status) == 1 { var voteState1 = resultVoteState(Proposals[i].VoteState) var voteState2 = resultVoteState(Proposals2[i].VoteState) - if (voteState2.YesCount >= voteState1.YesCount) && (voteState2.NoCount >= voteState1.NoCount) && (voteState2.AbstainCount >= voteState1.AbstainCount) && (voteState2.VetoCount >= voteState1.VetoCount) { + if (voteState2.YesCount <= voteState1.YesCount) && (voteState2.NoCount <= voteState1.NoCount) && (voteState2.AbstainCount <= voteState1.AbstainCount) && (voteState2.VetoCount <= voteState1.VetoCount) { return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "\tTallyVoteSums is passed"), true } } diff --git a/x/group/server/server.go b/x/group/server/server.go index 8714449c54..dbe16239a0 100644 --- a/x/group/server/server.go +++ b/x/group/server/server.go @@ -165,4 +165,5 @@ func RegisterServices(configurator servermodule.Configurator, accountKeeper Acco impl := newServer(configurator.ModuleKey(), configurator.Router(), accountKeeper, configurator.Marshaler()) group.RegisterMsgServer(configurator.MsgServer(), impl) group.RegisterQueryServer(configurator.QueryServer(), impl) + configurator.RegisterInvariants(impl.RegisterInvariants) } From ad719bface3f1c6cf6e868683f46ef4b9fbf3f8a Mon Sep 17 00:00:00 2001 From: likhita Date: Tue, 2 Mar 2021 17:44:40 +0530 Subject: [PATCH 09/96] changes to invariant --- types/module/server/manager.go | 4 +++- types/module/server/testutil.go | 3 +-- x/group/server/invariant.go | 8 ++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/types/module/server/manager.go b/types/module/server/manager.go index 89849b5f33..c9bf4a6afd 100644 --- a/types/module/server/manager.go +++ b/types/module/server/manager.go @@ -25,7 +25,9 @@ type Manager struct { // RegisterInvariants registers all module routes and module querier routes func (m *Manager) RegisterInvariants(ir sdk.InvariantRegistry) { for _, module := range m.registerInvariants { - module(ir) + if module != nil { //TODO: Remove if condition + module(ir) + } } } diff --git a/types/module/server/testutil.go b/types/module/server/testutil.go index 9e0a15a081..c9130e3150 100644 --- a/types/module/server/testutil.go +++ b/types/module/server/testutil.go @@ -72,10 +72,9 @@ func (ff FixtureFactory) Setup() testutil.Fixture { cdc := ff.cdc registry := cdc.InterfaceRegistry() baseApp := ff.baseApp - invar := ff.invar baseApp.MsgServiceRouter().SetInterfaceRegistry(registry) baseApp.GRPCQueryRouter().SetInterfaceRegistry(registry) - mm := NewManager(baseApp, cdc, *invar) + mm := NewManager(baseApp, cdc) err := mm.RegisterModules(ff.modules) require.NoError(ff.t, err) err = mm.CompleteInitialization() diff --git a/x/group/server/invariant.go b/x/group/server/invariant.go index 47e4c0e3c0..099b65a760 100644 --- a/x/group/server/invariant.go +++ b/x/group/server/invariant.go @@ -76,16 +76,16 @@ func (s serverImpl) TallyVotesInvariant() sdk.Invariant { if err != nil { return "", false } - for i := 0; i < len(Proposals) && i < len(Proposals2); i++ { if int32(Proposals[i].Status) == 1 && int32(Proposals2[i].Status) == 1 { var voteState1 = resultVoteState(Proposals[i].VoteState) var voteState2 = resultVoteState(Proposals2[i].VoteState) - if (voteState2.YesCount <= voteState1.YesCount) && (voteState2.NoCount <= voteState1.NoCount) && (voteState2.AbstainCount <= voteState1.AbstainCount) && (voteState2.VetoCount <= voteState1.VetoCount) { - return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "\tTallyVoteSums is passed"), true + if (voteState1.YesCount > voteState2.YesCount) || (voteState1.NoCount > voteState2.NoCount) || (voteState1.AbstainCount > voteState2.AbstainCount) || (voteState1.VetoCount > voteState2.VetoCount) { + return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "\tTallyVoteSums is failed"), true } } } - return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "\tTallyVoteSums is failed"), false + return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "\tTallyVoteSums is passed"), false + } } From 0c1556ae19d961aba18257e27bd158124105a75f Mon Sep 17 00:00:00 2001 From: likhita Date: Tue, 2 Mar 2021 18:09:12 +0530 Subject: [PATCH 10/96] fix lint issues --- Makefile | 1 - types/module/server/manager.go | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 88ba1ae9f6..b14d8d8f58 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,6 @@ DOCKER_BUF := docker run -v $(shell pwd):/workspace --workdir /workspace bufbuil export GO111MODULE = on # process build tags -EXPERIMENTAL=true build_tags = netgo ifeq ($(EXPERIMENTAL),true) diff --git a/types/module/server/manager.go b/types/module/server/manager.go index c9bf4a6afd..e871103339 100644 --- a/types/module/server/manager.go +++ b/types/module/server/manager.go @@ -23,10 +23,10 @@ type Manager struct { } // RegisterInvariants registers all module routes and module querier routes -func (m *Manager) RegisterInvariants(ir sdk.InvariantRegistry) { - for _, module := range m.registerInvariants { - if module != nil { //TODO: Remove if condition - module(ir) +func (mm *Manager) RegisterInvariants(ir sdk.InvariantRegistry) { + for _, moduleName := range mm.registerInvariants { + if moduleName != nil { //TODO: Remove if condition + moduleName(ir) } } } From 822d61dcd8f9fa4edc5a00de6a13cc407a9c694b Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 4 Mar 2021 21:50:41 +0530 Subject: [PATCH 11/96] addressing requested changes --- x/group/server/invariants.go | 90 ++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 x/group/server/invariants.go diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go new file mode 100644 index 0000000000..51c77ad6e9 --- /dev/null +++ b/x/group/server/invariants.go @@ -0,0 +1,90 @@ +package server + +import ( + "fmt" + "math" + + "github.com/regen-network/regen-ledger/orm" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/regen-network/regen-ledger/types" + "github.com/regen-network/regen-ledger/x/group" +) + +func (s serverImpl) RegisterInvariants(ir sdk.InvariantRegistry) { + ir.RegisterRoute(group.ModuleName, "Tally-Votes", s.TallyVotesInvariant()) +} + +func (s serverImpl) AllInvariants() sdk.Invariant { + return func(ctx sdk.Context) (string, bool) { + res, stop := s.TallyVotesInvariant()(ctx) + if stop { + return res, stop + } + return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "\tvote tally sums must never have less than the block before"), false + } +} + +func (s serverImpl) TallyVotesInvariant() sdk.Invariant { + return func(sdkCtx sdk.Context) (string, bool) { + var proposals2 []*group.Proposal + ctx := types.Context{Context: sdkCtx} + it2, err := s.proposalTable.PrefixScan(ctx, 1, math.MaxUint64) + if err != nil { + return "start value must be less than end value in iterator", false + } + _, err = orm.ReadAll(it2, &proposals2) + var proposals1 []*group.Proposal + if ctx.BlockHeight()-1 >= 0 { + sdkCtx = sdkCtx.WithBlockHeight(ctx.BlockHeight() - 1) + } else { + return "Not enough blocks to perform TallyVotesInvariant", false + } + it1, err := s.proposalTable.PrefixScan(sdkCtx, 1, math.MaxUint64) + if err != nil { + return "start value must be less than end value in iterator", false + } + _, err = orm.ReadAll(it1, &proposals1) + + for i := 0; i < len(proposals1) && i < len(proposals2); i++ { + if int32(proposals1[i].Status) == 1 && int32(proposals2[i].Status) == 1 { + yesCount1, err := proposals1[i].VoteState.GetYesCount() + if err != nil { + return fmt.Sprint(err), false + } + yesCount2, err := proposals2[i].VoteState.GetYesCount() + if err != nil { + return fmt.Sprint(err), false + } + noCount1, err := proposals1[i].VoteState.GetNoCount() + if err != nil { + return fmt.Sprint(err), false + } + noCount2, err := proposals2[i].VoteState.GetNoCount() + if err != nil { + return fmt.Sprint(err), false + } + abstainCount1, err := proposals1[i].VoteState.GetAbstainCount() + if err != nil { + return fmt.Sprint(err), false + } + abstainCount2, err := proposals2[i].VoteState.GetAbstainCount() + if err != nil { + return fmt.Sprint(err), false + } + vetoCount1, err := proposals1[i].VoteState.GetVetoCount() + if err != nil { + return fmt.Sprint(err), false + } + vetoCount2, err := proposals2[i].VoteState.GetVetoCount() + if err != nil { + return fmt.Sprint(err), false + } + if (yesCount2.Cmp(yesCount1) == -1) || (noCount2.Cmp(noCount1) == -1) || (abstainCount2.Cmp(abstainCount1) == -1) || (vetoCount2.Cmp(vetoCount1) == -1) { + return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "\tvote tally sums must never have less than the block before"), false + } + } + } + return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "\tTallyVotesSum is passed"), false + } +} From a60f6257fe1741ba423fbb00132defeeeb9adb01 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 4 Mar 2021 21:53:47 +0530 Subject: [PATCH 12/96] "Remove getAllProposals" --- x/group/server/query_server.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/x/group/server/query_server.go b/x/group/server/query_server.go index 7ee8c8adbe..05e7736adb 100644 --- a/x/group/server/query_server.go +++ b/x/group/server/query_server.go @@ -176,10 +176,6 @@ func (s serverImpl) getProposalsByGroupAccount(ctx types.Context, account sdk.Ac return s.proposalByGroupAccountIndex.GetPaginated(ctx, account.Bytes(), pageRequest) } -func (s serverImpl) getAllProposals(ctx types.Context, pageRequest *query.PageRequest) (orm.Iterator, error) { - return s.proposalTable.PrefixScan(ctx, pageRequest.Offset, pageRequest.Limit) -} - func (s serverImpl) getProposal(ctx types.Context, proposalID uint64) (group.Proposal, error) { var p group.Proposal if _, err := s.proposalTable.GetOne(ctx, proposalID, &p); err != nil { From fd08c735c2a517c15a15d2dbaefa358b5031bc68 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 4 Mar 2021 22:00:54 +0530 Subject: [PATCH 13/96] "Remove invariant.go" --- x/group/server/invariant.go | 91 ------------------------------------- 1 file changed, 91 deletions(-) delete mode 100644 x/group/server/invariant.go diff --git a/x/group/server/invariant.go b/x/group/server/invariant.go deleted file mode 100644 index 099b65a760..0000000000 --- a/x/group/server/invariant.go +++ /dev/null @@ -1,91 +0,0 @@ -package server - -import ( - "strconv" - - "github.com/cosmos/cosmos-sdk/types/query" - "github.com/regen-network/regen-ledger/orm" - "github.com/regen-network/regen-ledger/types" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/regen-network/regen-ledger/x/group" -) - -type resTally struct { - YesCount int64 - NoCount int64 - AbstainCount int64 - VetoCount int64 -} - -func resultVoteState(v group.Tally) resTally { - return resTally{ - YesCount: strToInt(v.YesCount), - NoCount: strToInt(v.NoCount), - AbstainCount: strToInt(v.AbstainCount), - VetoCount: strToInt(v.VetoCount), - } -} - -func strToInt(str string) int64 { - integer, _ := strconv.ParseInt(str, 10, 64) - return integer -} - -func (s serverImpl) RegisterInvariants(ir sdk.InvariantRegistry) { - ir.RegisterRoute(group.ModuleName, "Tally-Votes", s.TallyVotesInvariant()) -} - -func (s serverImpl) AllInvariants() sdk.Invariant { - return func(ctx sdk.Context) (string, bool) { - res, stop := s.TallyVotesInvariant()(ctx) - if stop { - return res, stop - } - return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "\tTallyVoteSums is failed"), false - } -} - -func (s serverImpl) TallyVotesInvariant() sdk.Invariant { - return func(sdkCtx sdk.Context) (string, bool) { - ctx := types.Context{Context: sdkCtx} - var pageReq = query.PageRequest{ - Offset: 0, - Limit: 100, - CountTotal: true, - } - it, err := s.getAllProposals(ctx, &pageReq) - if err != nil { - return "No proposals found", false - } - - var Proposals2 []*group.Proposal - _, err = orm.Paginate(it, &pageReq, &Proposals2) - if err != nil { - return "", false - } - sdkCtx = sdkCtx.WithBlockHeight(ctx.BlockHeight() - 1) - it2, err := s.getAllProposals(types.Context{Context: sdkCtx}, &pageReq) - if err != nil { - return "No proposals found", false - } - - var Proposals []*group.Proposal - _, err = orm.Paginate(it2, &pageReq, &Proposals) - if err != nil { - return "", false - } - for i := 0; i < len(Proposals) && i < len(Proposals2); i++ { - if int32(Proposals[i].Status) == 1 && int32(Proposals2[i].Status) == 1 { - var voteState1 = resultVoteState(Proposals[i].VoteState) - var voteState2 = resultVoteState(Proposals2[i].VoteState) - if (voteState1.YesCount > voteState2.YesCount) || (voteState1.NoCount > voteState2.NoCount) || (voteState1.AbstainCount > voteState2.AbstainCount) || (voteState1.VetoCount > voteState2.VetoCount) { - return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "\tTallyVoteSums is failed"), true - } - } - } - return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "\tTallyVoteSums is passed"), false - - } -} From 3f6c079a1894f30daa111afd0435ea323bfddd8e Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 4 Mar 2021 23:00:44 +0530 Subject: [PATCH 14/96] "Change naming conventions" --- x/group/server/invariants.go | 46 ++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 51c77ad6e9..df1442ae91 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -17,24 +17,23 @@ func (s serverImpl) RegisterInvariants(ir sdk.InvariantRegistry) { func (s serverImpl) AllInvariants() sdk.Invariant { return func(ctx sdk.Context) (string, bool) { - res, stop := s.TallyVotesInvariant()(ctx) - if stop { - return res, stop - } - return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "\tvote tally sums must never have less than the block before"), false + return s.TallyVotesInvariant()(ctx) } } func (s serverImpl) TallyVotesInvariant() sdk.Invariant { return func(sdkCtx sdk.Context) (string, bool) { - var proposals2 []*group.Proposal + var msg string + var broken bool + var curProposal []*group.Proposal ctx := types.Context{Context: sdkCtx} it2, err := s.proposalTable.PrefixScan(ctx, 1, math.MaxUint64) if err != nil { return "start value must be less than end value in iterator", false } - _, err = orm.ReadAll(it2, &proposals2) - var proposals1 []*group.Proposal + curProposalRowID, err := orm.ReadAll(it2, &curProposal) + _ = curProposalRowID + var prevProposal []*group.Proposal if ctx.BlockHeight()-1 >= 0 { sdkCtx = sdkCtx.WithBlockHeight(ctx.BlockHeight() - 1) } else { @@ -44,47 +43,48 @@ func (s serverImpl) TallyVotesInvariant() sdk.Invariant { if err != nil { return "start value must be less than end value in iterator", false } - _, err = orm.ReadAll(it1, &proposals1) - - for i := 0; i < len(proposals1) && i < len(proposals2); i++ { - if int32(proposals1[i].Status) == 1 && int32(proposals2[i].Status) == 1 { - yesCount1, err := proposals1[i].VoteState.GetYesCount() + prevProposalRowID, err := orm.ReadAll(it1, &prevProposal) + _ = prevProposalRowID + for i := 0; i < len(prevProposal) && i < len(curProposal); i++ { + if int32(prevProposal[i].Status) == 1 && int32(curProposal[i].Status) == 1 { + prevYesCount, err := prevProposal[i].VoteState.GetYesCount() if err != nil { return fmt.Sprint(err), false } - yesCount2, err := proposals2[i].VoteState.GetYesCount() + curYesCount, err := curProposal[i].VoteState.GetYesCount() if err != nil { return fmt.Sprint(err), false } - noCount1, err := proposals1[i].VoteState.GetNoCount() + prevNoCount, err := prevProposal[i].VoteState.GetNoCount() if err != nil { return fmt.Sprint(err), false } - noCount2, err := proposals2[i].VoteState.GetNoCount() + curNoCount, err := curProposal[i].VoteState.GetNoCount() if err != nil { return fmt.Sprint(err), false } - abstainCount1, err := proposals1[i].VoteState.GetAbstainCount() + prevAbstainCount, err := prevProposal[i].VoteState.GetAbstainCount() if err != nil { return fmt.Sprint(err), false } - abstainCount2, err := proposals2[i].VoteState.GetAbstainCount() + curAbstainCount, err := curProposal[i].VoteState.GetAbstainCount() if err != nil { return fmt.Sprint(err), false } - vetoCount1, err := proposals1[i].VoteState.GetVetoCount() + prevVetoCount, err := prevProposal[i].VoteState.GetVetoCount() if err != nil { return fmt.Sprint(err), false } - vetoCount2, err := proposals2[i].VoteState.GetVetoCount() + curVetoCount, err := curProposal[i].VoteState.GetVetoCount() if err != nil { return fmt.Sprint(err), false } - if (yesCount2.Cmp(yesCount1) == -1) || (noCount2.Cmp(noCount1) == -1) || (abstainCount2.Cmp(abstainCount1) == -1) || (vetoCount2.Cmp(vetoCount1) == -1) { - return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "\tvote tally sums must never have less than the block before"), false + if (curYesCount.Cmp(prevYesCount) == -1) || (curNoCount.Cmp(prevNoCount) == -1) || (curAbstainCount.Cmp(prevAbstainCount) == -1) || (curVetoCount.Cmp(prevVetoCount) == -1) { + broken = true + msg += fmt.Sprintf("vote tally sums must never have less than the block before\n") } } } - return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "\tTallyVotesSum is passed"), false + return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", msg), broken } } From 96c61f2faa73f3acdea3c85e396798e631875157 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 4 Mar 2021 23:11:48 +0530 Subject: [PATCH 15/96] "Fix lint issues" --- x/group/server/invariants.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index df1442ae91..7412b46b6b 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -32,6 +32,9 @@ func (s serverImpl) TallyVotesInvariant() sdk.Invariant { return "start value must be less than end value in iterator", false } curProposalRowID, err := orm.ReadAll(it2, &curProposal) + if err != nil { + return "cannot read all proposals in current block", false + } _ = curProposalRowID var prevProposal []*group.Proposal if ctx.BlockHeight()-1 >= 0 { @@ -44,6 +47,9 @@ func (s serverImpl) TallyVotesInvariant() sdk.Invariant { return "start value must be less than end value in iterator", false } prevProposalRowID, err := orm.ReadAll(it1, &prevProposal) + if err != nil { + return "cannot read all proposals from previous block", false + } _ = prevProposalRowID for i := 0; i < len(prevProposal) && i < len(curProposal); i++ { if int32(prevProposal[i].Status) == 1 && int32(curProposal[i].Status) == 1 { @@ -81,7 +87,7 @@ func (s serverImpl) TallyVotesInvariant() sdk.Invariant { } if (curYesCount.Cmp(prevYesCount) == -1) || (curNoCount.Cmp(prevNoCount) == -1) || (curAbstainCount.Cmp(prevAbstainCount) == -1) || (curVetoCount.Cmp(prevVetoCount) == -1) { broken = true - msg += fmt.Sprintf("vote tally sums must never have less than the block before\n") + msg += "vote tally sums must never have less than the block before\n" } } } From 8f39c1e5cc586b5a976a791bbfe5373ec138717e Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 5 Mar 2021 12:29:08 +0530 Subject: [PATCH 16/96] change naming conventions --- x/group/server/invariants.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 7412b46b6b..16c07fe173 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -27,11 +27,11 @@ func (s serverImpl) TallyVotesInvariant() sdk.Invariant { var broken bool var curProposal []*group.Proposal ctx := types.Context{Context: sdkCtx} - it2, err := s.proposalTable.PrefixScan(ctx, 1, math.MaxUint64) + curIterator, err := s.proposalTable.PrefixScan(ctx, 1, math.MaxUint64) if err != nil { return "start value must be less than end value in iterator", false } - curProposalRowID, err := orm.ReadAll(it2, &curProposal) + curProposalRowID, err := orm.ReadAll(curIterator, &curProposal) if err != nil { return "cannot read all proposals in current block", false } @@ -42,11 +42,11 @@ func (s serverImpl) TallyVotesInvariant() sdk.Invariant { } else { return "Not enough blocks to perform TallyVotesInvariant", false } - it1, err := s.proposalTable.PrefixScan(sdkCtx, 1, math.MaxUint64) + prevIterator, err := s.proposalTable.PrefixScan(sdkCtx, 1, math.MaxUint64) if err != nil { return "start value must be less than end value in iterator", false } - prevProposalRowID, err := orm.ReadAll(it1, &prevProposal) + prevProposalRowID, err := orm.ReadAll(prevIterator, &prevProposal) if err != nil { return "cannot read all proposals from previous block", false } From d223200bddfdd30605eae156799fa2d6020ed705 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 5 Mar 2021 13:06:33 +0530 Subject: [PATCH 17/96] "Change naming conventions" --- x/group/server/invariants.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 16c07fe173..4b5e5a1fdc 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -27,11 +27,11 @@ func (s serverImpl) TallyVotesInvariant() sdk.Invariant { var broken bool var curProposal []*group.Proposal ctx := types.Context{Context: sdkCtx} - curIterator, err := s.proposalTable.PrefixScan(ctx, 1, math.MaxUint64) + it1, err := s.proposalTable.PrefixScan(ctx, 1, math.MaxUint64) if err != nil { return "start value must be less than end value in iterator", false } - curProposalRowID, err := orm.ReadAll(curIterator, &curProposal) + curProposalRowID, err := orm.ReadAll(it1, &curProposal) if err != nil { return "cannot read all proposals in current block", false } @@ -42,11 +42,11 @@ func (s serverImpl) TallyVotesInvariant() sdk.Invariant { } else { return "Not enough blocks to perform TallyVotesInvariant", false } - prevIterator, err := s.proposalTable.PrefixScan(sdkCtx, 1, math.MaxUint64) + it2, err := s.proposalTable.PrefixScan(sdkCtx, 1, math.MaxUint64) if err != nil { return "start value must be less than end value in iterator", false } - prevProposalRowID, err := orm.ReadAll(prevIterator, &prevProposal) + prevProposalRowID, err := orm.ReadAll(it2, &prevProposal) if err != nil { return "cannot read all proposals from previous block", false } From 76be926dbb32a5432d87d2db1112e0856afd99c0 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Sat, 6 Mar 2021 15:20:23 +0530 Subject: [PATCH 18/96] Merge branch 'master' into likhita/add-invariants # Conflicts: # go.mod --- go.mod | 10 ++++++---- x/data/server/query_server.go | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 67e2efd296..9789b9a512 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/CosmWasm/wasmd v0.14.0 github.com/btcsuite/btcutil v1.0.2 github.com/cockroachdb/apd/v2 v2.0.2 - github.com/cosmos/cosmos-sdk v0.41.0 + github.com/cosmos/cosmos-sdk v0.42.0-rc0 github.com/enigmampc/btcutil v1.0.3-0.20200723161021-e2fb6adb2a25 github.com/gogo/protobuf v1.3.3 github.com/gorilla/mux v1.8.0 @@ -18,14 +18,16 @@ require ( github.com/regen-network/cosmos-proto v0.3.1 github.com/rs/zerolog v1.20.0 github.com/spf13/cast v1.3.1 - github.com/spf13/cobra v1.1.1 + github.com/spf13/cobra v1.1.3 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.7.0 - github.com/tendermint/tendermint v0.34.3 - github.com/tendermint/tm-db v0.6.3 + github.com/tendermint/tendermint v0.34.8 + github.com/tendermint/tm-db v0.6.4 google.golang.org/genproto v0.0.0-20210212180131-e7f2df4ecc2d // indirect google.golang.org/grpc v1.35.0 gopkg.in/yaml.v2 v2.4.0 ) +replace google.golang.org/grpc => google.golang.org/grpc v1.33.2 + replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.2-alpha.regen.4 diff --git a/x/data/server/query_server.go b/x/data/server/query_server.go index d2f319de23..5243cd2f2a 100644 --- a/x/data/server/query_server.go +++ b/x/data/server/query_server.go @@ -46,7 +46,7 @@ func (s serverImpl) ByHash(ctx types.Context, request *data.QueryByHashRequest) func (s serverImpl) BySigner(ctx types.Context, request *data.QueryBySignerRequest) (*data.QueryBySignerResponse, error) { return nil, fmt.Errorf("not implemented") - // store := prefix.NewStore(ctx.KVStore(s.storeKey), SignerCIDIndexPrefix(request.Signer)) + //store := prefix.NewStore(ctx.KVStore(s.storeKey), SignerCIDIndexPrefix(request.Signer)) // //var cids [][]byte //pageRes, err := query.Paginate(store, request.Pagination, func(key []byte, value []byte) error { From 68a0e0f276a3640f8336c1082d89eb08fac27776 Mon Sep 17 00:00:00 2001 From: likhita-809 <78951027+likhita-809@users.noreply.github.com> Date: Tue, 9 Mar 2021 17:32:10 +0530 Subject: [PATCH 19/96] Update types/module/server/manager.go Co-authored-by: Marie Gauthier --- types/module/server/manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/module/server/manager.go b/types/module/server/manager.go index e871103339..f6f9121541 100644 --- a/types/module/server/manager.go +++ b/types/module/server/manager.go @@ -19,7 +19,7 @@ type Manager struct { keys map[string]ModuleKey router *router requiredServices map[reflect.Type]bool - registerInvariants map[string]RegisterInvariantsHandler + registerInvariantsHandlers map[string]RegisterInvariantsHandler } // RegisterInvariants registers all module routes and module querier routes From af62bac83425359a48d89ac881e7c04b20888f32 Mon Sep 17 00:00:00 2001 From: likhita-809 <78951027+likhita-809@users.noreply.github.com> Date: Tue, 9 Mar 2021 17:35:01 +0530 Subject: [PATCH 20/96] Update types/module/server/manager.go Co-authored-by: Marie Gauthier --- types/module/server/manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/module/server/manager.go b/types/module/server/manager.go index f6f9121541..909b849165 100644 --- a/types/module/server/manager.go +++ b/types/module/server/manager.go @@ -37,7 +37,7 @@ func NewManager(baseApp *baseapp.BaseApp, cdc *codec.ProtoCodec) *Manager { baseApp: baseApp, cdc: cdc, keys: map[string]ModuleKey{}, - registerInvariants: map[string]RegisterInvariantsHandler{}, + registerInvariantsHandlers: map[string]RegisterInvariantsHandler{}, router: &router{ handlers: map[string]handler{}, providedServices: map[reflect.Type]bool{}, From 95f27b3da7f2315ac23e13d8c1798f07b18c160a Mon Sep 17 00:00:00 2001 From: likhita-809 <78951027+likhita-809@users.noreply.github.com> Date: Tue, 9 Mar 2021 17:35:33 +0530 Subject: [PATCH 21/96] Update types/module/server/manager.go Co-authored-by: Marie Gauthier --- types/module/server/manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/module/server/manager.go b/types/module/server/manager.go index 909b849165..b32238912a 100644 --- a/types/module/server/manager.go +++ b/types/module/server/manager.go @@ -108,7 +108,7 @@ func (mm *Manager) RegisterModules(modules []module.Module) error { } serverMod.RegisterServices(cfg) - mm.registerInvariants[name] = cfg.registerInvariants + mm.registerInvariantsHandlers[name] = cfg.registerInvariants // If mod implements LegacyRouteModule, register module route. // This is currently used for the group module as part of #218. From 6783ecd29be27842ec35bcd911bd7e50fc04a5f7 Mon Sep 17 00:00:00 2001 From: likhita-809 <78951027+likhita-809@users.noreply.github.com> Date: Tue, 9 Mar 2021 17:35:46 +0530 Subject: [PATCH 22/96] Update types/module/server/manager.go Co-authored-by: Marie Gauthier --- types/module/server/manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/module/server/manager.go b/types/module/server/manager.go index b32238912a..6f93fe1843 100644 --- a/types/module/server/manager.go +++ b/types/module/server/manager.go @@ -158,7 +158,7 @@ type configurator struct { cdc codec.Marshaler requiredServices map[reflect.Type]bool router sdk.Router - registerInvariants RegisterInvariantsHandler + registerInvariantsHandler RegisterInvariantsHandler } var _ Configurator = &configurator{} From 94e8b931a67ce7f4b606cdf7e89ed99253861b48 Mon Sep 17 00:00:00 2001 From: likhita-809 <78951027+likhita-809@users.noreply.github.com> Date: Tue, 9 Mar 2021 17:36:38 +0530 Subject: [PATCH 23/96] Update types/module/server/manager.go Co-authored-by: Marie Gauthier --- types/module/server/manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/module/server/manager.go b/types/module/server/manager.go index 6f93fe1843..ef9b5997d8 100644 --- a/types/module/server/manager.go +++ b/types/module/server/manager.go @@ -171,7 +171,7 @@ func (c *configurator) QueryServer() gogogrpc.Server { return c.queryServer } -func (c *configurator) RegisterInvariants(registry RegisterInvariantsHandler) { +func (c *configurator) RegisterInvariantsHandler(registry RegisterInvariantsHandler) { c.registerInvariants = registry } From 3b8328e20797b880014d3b88b2e81279baa2c329 Mon Sep 17 00:00:00 2001 From: likhita-809 <78951027+likhita-809@users.noreply.github.com> Date: Tue, 9 Mar 2021 17:37:01 +0530 Subject: [PATCH 24/96] Update types/module/server/manager.go Co-authored-by: Marie Gauthier --- types/module/server/manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/module/server/manager.go b/types/module/server/manager.go index ef9b5997d8..8e06b3690a 100644 --- a/types/module/server/manager.go +++ b/types/module/server/manager.go @@ -172,7 +172,7 @@ func (c *configurator) QueryServer() gogogrpc.Server { } func (c *configurator) RegisterInvariantsHandler(registry RegisterInvariantsHandler) { - c.registerInvariants = registry + c.registerInvariantsHandler = registry } func (c *configurator) ModuleKey() RootModuleKey { From 3dd8029f7d1b4a407e286db3bbb96a2eebd8455b Mon Sep 17 00:00:00 2001 From: likhita-809 <78951027+likhita-809@users.noreply.github.com> Date: Tue, 9 Mar 2021 17:38:19 +0530 Subject: [PATCH 25/96] Update x/group/server/server.go Co-authored-by: Marie Gauthier --- x/group/server/server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/group/server/server.go b/x/group/server/server.go index dbe16239a0..815eb24bdd 100644 --- a/x/group/server/server.go +++ b/x/group/server/server.go @@ -165,5 +165,5 @@ func RegisterServices(configurator servermodule.Configurator, accountKeeper Acco impl := newServer(configurator.ModuleKey(), configurator.Router(), accountKeeper, configurator.Marshaler()) group.RegisterMsgServer(configurator.MsgServer(), impl) group.RegisterQueryServer(configurator.QueryServer(), impl) - configurator.RegisterInvariants(impl.RegisterInvariants) + configurator.RegisterInvariantsHandler(impl.RegisterInvariants) } From 7c3ebe5ad7d6a818719d2d8f2e0013f95d1f87c4 Mon Sep 17 00:00:00 2001 From: likhita-809 <78951027+likhita-809@users.noreply.github.com> Date: Tue, 9 Mar 2021 17:49:13 +0530 Subject: [PATCH 26/96] Update types/module/server/module.go Co-authored-by: Marie Gauthier --- types/module/server/module.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/module/server/module.go b/types/module/server/module.go index fc49bd3ca8..ddbe91e110 100644 --- a/types/module/server/module.go +++ b/types/module/server/module.go @@ -20,7 +20,7 @@ type Configurator interface { ModuleKey() RootModuleKey Marshaler() codec.Marshaler RequireServer(interface{}) - RegisterInvariants(registry RegisterInvariantsHandler) + RegisterInvariantsHandler(registry RegisterInvariantsHandler) // Router() is temporarily added here to use in the group module. // TODO: remove once #225 addressed Router() sdk.Router From 09c1dde0be124cdf5fea32209707de32831e0c75 Mon Sep 17 00:00:00 2001 From: likhita-809 <78951027+likhita-809@users.noreply.github.com> Date: Tue, 9 Mar 2021 17:49:50 +0530 Subject: [PATCH 27/96] Update x/group/server/invariants.go Co-authored-by: Marie Gauthier --- x/group/server/invariants.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 4b5e5a1fdc..146f7f6cdf 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -11,7 +11,7 @@ import ( "github.com/regen-network/regen-ledger/x/group" ) -func (s serverImpl) RegisterInvariants(ir sdk.InvariantRegistry) { +func (s serverImpl) RegisterInvariantsHandler(ir sdk.InvariantRegistry) { ir.RegisterRoute(group.ModuleName, "Tally-Votes", s.TallyVotesInvariant()) } From a365a4bd3a97facad3b3bd57f6d187b27157292c Mon Sep 17 00:00:00 2001 From: likhita-809 <78951027+likhita-809@users.noreply.github.com> Date: Tue, 9 Mar 2021 17:50:27 +0530 Subject: [PATCH 28/96] Update x/group/server/invariants.go Co-authored-by: Marie Gauthier --- x/group/server/invariants.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 146f7f6cdf..eb9566e9c5 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -25,7 +25,7 @@ func (s serverImpl) TallyVotesInvariant() sdk.Invariant { return func(sdkCtx sdk.Context) (string, bool) { var msg string var broken bool - var curProposal []*group.Proposal + var curProposals []*group.Proposal ctx := types.Context{Context: sdkCtx} it1, err := s.proposalTable.PrefixScan(ctx, 1, math.MaxUint64) if err != nil { From bd7b11642c9cb203ca34baabae4e4a789f739800 Mon Sep 17 00:00:00 2001 From: likhita-809 <78951027+likhita-809@users.noreply.github.com> Date: Tue, 9 Mar 2021 17:51:04 +0530 Subject: [PATCH 29/96] Update x/group/server/invariants.go Co-authored-by: Marie Gauthier --- x/group/server/invariants.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index eb9566e9c5..1d940824c4 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -36,7 +36,7 @@ func (s serverImpl) TallyVotesInvariant() sdk.Invariant { return "cannot read all proposals in current block", false } _ = curProposalRowID - var prevProposal []*group.Proposal + var prevProposals []*group.Proposal if ctx.BlockHeight()-1 >= 0 { sdkCtx = sdkCtx.WithBlockHeight(ctx.BlockHeight() - 1) } else { From bc555a9009f712a0c34609f6688ad45207f2cad8 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 9 Mar 2021 18:12:06 +0530 Subject: [PATCH 30/96] Update invariants and fix naming conventions --- types/module/server/manager.go | 46 +++++++------- types/module/server/module.go | 3 +- x/group/server/invariants.go | 112 ++++++++++++++++----------------- x/group/server/server.go | 8 +-- 4 files changed, 84 insertions(+), 85 deletions(-) diff --git a/types/module/server/manager.go b/types/module/server/manager.go index e871103339..651ca2be1a 100644 --- a/types/module/server/manager.go +++ b/types/module/server/manager.go @@ -14,30 +14,28 @@ import ( // Manager is the server module manager type Manager struct { - baseApp *baseapp.BaseApp - cdc *codec.ProtoCodec - keys map[string]ModuleKey - router *router - requiredServices map[reflect.Type]bool - registerInvariants map[string]RegisterInvariantsHandler + baseApp *baseapp.BaseApp + cdc *codec.ProtoCodec + keys map[string]ModuleKey + router *router + requiredServices map[reflect.Type]bool + registerInvariantsHandler map[string]RegisterInvariantsHandler } // RegisterInvariants registers all module routes and module querier routes func (mm *Manager) RegisterInvariants(ir sdk.InvariantRegistry) { - for _, moduleName := range mm.registerInvariants { - if moduleName != nil { //TODO: Remove if condition - moduleName(ir) - } + for _, moduleName := range mm.registerInvariantsHandler { + moduleName(ir) } } // NewManager creates a new Manager func NewManager(baseApp *baseapp.BaseApp, cdc *codec.ProtoCodec) *Manager { return &Manager{ - baseApp: baseApp, - cdc: cdc, - keys: map[string]ModuleKey{}, - registerInvariants: map[string]RegisterInvariantsHandler{}, + baseApp: baseApp, + cdc: cdc, + keys: map[string]ModuleKey{}, + registerInvariantsHandler: map[string]RegisterInvariantsHandler{}, router: &router{ handlers: map[string]handler{}, providedServices: map[reflect.Type]bool{}, @@ -108,7 +106,7 @@ func (mm *Manager) RegisterModules(modules []module.Module) error { } serverMod.RegisterServices(cfg) - mm.registerInvariants[name] = cfg.registerInvariants + mm.registerInvariantsHandler[name] = cfg.registerInvariantsHandler // If mod implements LegacyRouteModule, register module route. // This is currently used for the group module as part of #218. @@ -152,13 +150,13 @@ func (mm *Manager) CompleteInitialization() error { type RegisterInvariantsHandler func(ir sdk.InvariantRegistry) type configurator struct { - msgServer gogogrpc.Server - queryServer gogogrpc.Server - key *rootModuleKey - cdc codec.Marshaler - requiredServices map[reflect.Type]bool - router sdk.Router - registerInvariants RegisterInvariantsHandler + msgServer gogogrpc.Server + queryServer gogogrpc.Server + key *rootModuleKey + cdc codec.Marshaler + requiredServices map[reflect.Type]bool + router sdk.Router + registerInvariantsHandler RegisterInvariantsHandler } var _ Configurator = &configurator{} @@ -171,8 +169,8 @@ func (c *configurator) QueryServer() gogogrpc.Server { return c.queryServer } -func (c *configurator) RegisterInvariants(registry RegisterInvariantsHandler) { - c.registerInvariants = registry +func (c *configurator) RegisterInvariantsHandler(registry RegisterInvariantsHandler) { + c.registerInvariantsHandler = registry } func (c *configurator) ModuleKey() RootModuleKey { diff --git a/types/module/server/module.go b/types/module/server/module.go index fc49bd3ca8..0ac7745567 100644 --- a/types/module/server/module.go +++ b/types/module/server/module.go @@ -4,6 +4,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkmodule "github.com/cosmos/cosmos-sdk/types/module" + "github.com/regen-network/regen-ledger/types/module" ) @@ -20,7 +21,7 @@ type Configurator interface { ModuleKey() RootModuleKey Marshaler() codec.Marshaler RequireServer(interface{}) - RegisterInvariants(registry RegisterInvariantsHandler) + RegisterInvariantsHandler(registry RegisterInvariantsHandler) // Router() is temporarily added here to use in the group module. // TODO: remove once #225 addressed Router() sdk.Router diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 4b5e5a1fdc..14d04aa6a8 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -4,14 +4,14 @@ import ( "fmt" "math" - "github.com/regen-network/regen-ledger/orm" - sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/regen-network/regen-ledger/orm" "github.com/regen-network/regen-ledger/types" "github.com/regen-network/regen-ledger/x/group" ) -func (s serverImpl) RegisterInvariants(ir sdk.InvariantRegistry) { +func (s serverImpl) RegisterInvariantsHandler(ir sdk.InvariantRegistry) { ir.RegisterRoute(group.ModuleName, "Tally-Votes", s.TallyVotesInvariant()) } @@ -25,70 +25,70 @@ func (s serverImpl) TallyVotesInvariant() sdk.Invariant { return func(sdkCtx sdk.Context) (string, bool) { var msg string var broken bool - var curProposal []*group.Proposal ctx := types.Context{Context: sdkCtx} + if ctx.BlockHeight()-1 < 0 { + return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "Not enough blocks to perform TallyVotesInvariant"), true + } + sdkCtx = sdkCtx.WithBlockHeight(ctx.BlockHeight() - 1) it1, err := s.proposalTable.PrefixScan(ctx, 1, math.MaxUint64) if err != nil { - return "start value must be less than end value in iterator", false + panic(err) } - curProposalRowID, err := orm.ReadAll(it1, &curProposal) + it2, err := s.proposalTable.PrefixScan(sdkCtx, 1, math.MaxUint64) if err != nil { - return "cannot read all proposals in current block", false + panic(err) } - _ = curProposalRowID - var prevProposal []*group.Proposal - if ctx.BlockHeight()-1 >= 0 { - sdkCtx = sdkCtx.WithBlockHeight(ctx.BlockHeight() - 1) - } else { - return "Not enough blocks to perform TallyVotesInvariant", false - } - it2, err := s.proposalTable.PrefixScan(sdkCtx, 1, math.MaxUint64) + + var curProposals []*group.Proposal + curProposalRowID, err := orm.ReadAll(it1, &curProposals) if err != nil { - return "start value must be less than end value in iterator", false + panic(err) } - prevProposalRowID, err := orm.ReadAll(it2, &prevProposal) + _ = curProposalRowID + + var prevProposals []*group.Proposal + prevProposalRowID, err := orm.ReadAll(it2, &prevProposals) if err != nil { - return "cannot read all proposals from previous block", false + panic(err) } _ = prevProposalRowID - for i := 0; i < len(prevProposal) && i < len(curProposal); i++ { - if int32(prevProposal[i].Status) == 1 && int32(curProposal[i].Status) == 1 { - prevYesCount, err := prevProposal[i].VoteState.GetYesCount() - if err != nil { - return fmt.Sprint(err), false - } - curYesCount, err := curProposal[i].VoteState.GetYesCount() - if err != nil { - return fmt.Sprint(err), false - } - prevNoCount, err := prevProposal[i].VoteState.GetNoCount() - if err != nil { - return fmt.Sprint(err), false - } - curNoCount, err := curProposal[i].VoteState.GetNoCount() - if err != nil { - return fmt.Sprint(err), false - } - prevAbstainCount, err := prevProposal[i].VoteState.GetAbstainCount() - if err != nil { - return fmt.Sprint(err), false - } - curAbstainCount, err := curProposal[i].VoteState.GetAbstainCount() - if err != nil { - return fmt.Sprint(err), false - } - prevVetoCount, err := prevProposal[i].VoteState.GetVetoCount() - if err != nil { - return fmt.Sprint(err), false - } - curVetoCount, err := curProposal[i].VoteState.GetVetoCount() - if err != nil { - return fmt.Sprint(err), false - } - if (curYesCount.Cmp(prevYesCount) == -1) || (curNoCount.Cmp(prevNoCount) == -1) || (curAbstainCount.Cmp(prevAbstainCount) == -1) || (curVetoCount.Cmp(prevVetoCount) == -1) { - broken = true - msg += "vote tally sums must never have less than the block before\n" - } + + for i := 0; i < len(prevProposals) && i < len(curProposals); i++ { + prevYesCount, err := prevProposals[i].VoteState.GetYesCount() + if err != nil { + return fmt.Sprint(err), false + } + curYesCount, err := curProposals[i].VoteState.GetYesCount() + if err != nil { + return fmt.Sprint(err), false + } + prevNoCount, err := prevProposals[i].VoteState.GetNoCount() + if err != nil { + return fmt.Sprint(err), false + } + curNoCount, err := curProposals[i].VoteState.GetNoCount() + if err != nil { + return fmt.Sprint(err), false + } + prevAbstainCount, err := prevProposals[i].VoteState.GetAbstainCount() + if err != nil { + return fmt.Sprint(err), false + } + curAbstainCount, err := curProposals[i].VoteState.GetAbstainCount() + if err != nil { + return fmt.Sprint(err), false + } + prevVetoCount, err := prevProposals[i].VoteState.GetVetoCount() + if err != nil { + return fmt.Sprint(err), false + } + curVetoCount, err := curProposals[i].VoteState.GetVetoCount() + if err != nil { + return fmt.Sprint(err), false + } + if (curYesCount.Cmp(prevYesCount) == -1) || (curNoCount.Cmp(prevNoCount) == -1) || (curAbstainCount.Cmp(prevAbstainCount) == -1) || (curVetoCount.Cmp(prevVetoCount) == -1) { + broken = true + msg += "vote tally sums must never have less than the block before\n" } } return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", msg), broken diff --git a/x/group/server/server.go b/x/group/server/server.go index dbe16239a0..070a5727ac 100644 --- a/x/group/server/server.go +++ b/x/group/server/server.go @@ -1,12 +1,12 @@ package server import ( + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/regen-network/regen-ledger/orm" servermodule "github.com/regen-network/regen-ledger/types/module/server" "github.com/regen-network/regen-ledger/x/group" - - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" ) const ( @@ -165,5 +165,5 @@ func RegisterServices(configurator servermodule.Configurator, accountKeeper Acco impl := newServer(configurator.ModuleKey(), configurator.Router(), accountKeeper, configurator.Marshaler()) group.RegisterMsgServer(configurator.MsgServer(), impl) group.RegisterQueryServer(configurator.QueryServer(), impl) - configurator.RegisterInvariants(impl.RegisterInvariants) + configurator.RegisterInvariantsHandler(impl.RegisterInvariantsHandler) } From 30e9857b2838336c675b168f85b2bb7b00b99636 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 9 Mar 2021 18:25:40 +0530 Subject: [PATCH 31/96] update types/module/server/manager.go --- types/module/server/manager.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/types/module/server/manager.go b/types/module/server/manager.go index 07c2105c84..651ca2be1a 100644 --- a/types/module/server/manager.go +++ b/types/module/server/manager.go @@ -14,17 +14,17 @@ import ( // Manager is the server module manager type Manager struct { - baseApp *baseapp.BaseApp - cdc *codec.ProtoCodec - keys map[string]ModuleKey - router *router - requiredServices map[reflect.Type]bool - registerInvariantsHandlers map[string]RegisterInvariantsHandler + baseApp *baseapp.BaseApp + cdc *codec.ProtoCodec + keys map[string]ModuleKey + router *router + requiredServices map[reflect.Type]bool + registerInvariantsHandler map[string]RegisterInvariantsHandler } // RegisterInvariants registers all module routes and module querier routes func (mm *Manager) RegisterInvariants(ir sdk.InvariantRegistry) { - for _, moduleName := range mm.registerInvariantsHandlers { + for _, moduleName := range mm.registerInvariantsHandler { moduleName(ir) } } @@ -32,10 +32,10 @@ func (mm *Manager) RegisterInvariants(ir sdk.InvariantRegistry) { // NewManager creates a new Manager func NewManager(baseApp *baseapp.BaseApp, cdc *codec.ProtoCodec) *Manager { return &Manager{ - baseApp: baseApp, - cdc: cdc, - keys: map[string]ModuleKey{}, - registerInvariantsHandlers: map[string]RegisterInvariantsHandler{}, + baseApp: baseApp, + cdc: cdc, + keys: map[string]ModuleKey{}, + registerInvariantsHandler: map[string]RegisterInvariantsHandler{}, router: &router{ handlers: map[string]handler{}, providedServices: map[reflect.Type]bool{}, @@ -106,7 +106,7 @@ func (mm *Manager) RegisterModules(modules []module.Module) error { } serverMod.RegisterServices(cfg) - mm.registerInvariantsHandlers[name] = cfg.registerInvariantsHandler + mm.registerInvariantsHandler[name] = cfg.registerInvariantsHandler // If mod implements LegacyRouteModule, register module route. // This is currently used for the group module as part of #218. From 1a11a8724f053dd6a0aeb52020af337b7b5b737d Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 9 Mar 2021 18:35:26 +0530 Subject: [PATCH 32/96] Fix failed tests --- app/app.go | 41 +++++++++++++++++----------------- types/module/server/manager.go | 2 +- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/app/app.go b/app/app.go index 1b39652c09..a6a40528a5 100644 --- a/app/app.go +++ b/app/app.go @@ -7,8 +7,9 @@ import ( "os" "path/filepath" - servermodule "github.com/regen-network/regen-ledger/types/module/server" + // types + "github.com/CosmWasm/wasmd/x/wasm" wasmclient "github.com/CosmWasm/wasmd/x/wasm/client" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" @@ -20,6 +21,7 @@ import ( "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/auth" @@ -27,23 +29,33 @@ import ( authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" + authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/auth/vesting" "github.com/cosmos/cosmos-sdk/x/bank" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/capability" capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" "github.com/cosmos/cosmos-sdk/x/crisis" crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper" + crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" distr "github.com/cosmos/cosmos-sdk/x/distribution" distrclient "github.com/cosmos/cosmos-sdk/x/distribution/client" distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" "github.com/cosmos/cosmos-sdk/x/evidence" evidencekeeper "github.com/cosmos/cosmos-sdk/x/evidence/keeper" + evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" "github.com/cosmos/cosmos-sdk/x/genutil" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" "github.com/cosmos/cosmos-sdk/x/gov" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer" ibctransferkeeper "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/keeper" + ibctransfertypes "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/types" ibc "github.com/cosmos/cosmos-sdk/x/ibc/core" ibcclient "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client" porttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/05-port/types" @@ -52,17 +64,22 @@ import ( ibcmock "github.com/cosmos/cosmos-sdk/x/ibc/testing/mock" "github.com/cosmos/cosmos-sdk/x/mint" mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" "github.com/cosmos/cosmos-sdk/x/params" paramsclient "github.com/cosmos/cosmos-sdk/x/params/client" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal" "github.com/cosmos/cosmos-sdk/x/slashing" slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/cosmos/cosmos-sdk/x/upgrade" upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/gorilla/mux" "github.com/rakyll/statik/fs" "github.com/spf13/cast" @@ -72,25 +89,7 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" - // types - sdk "github.com/cosmos/cosmos-sdk/types" - authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" - crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" - distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" - genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - ibctransfertypes "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/types" - minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" - slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - - "github.com/CosmWasm/wasmd/x/wasm" + servermodule "github.com/regen-network/regen-ledger/types/module/server" ) const ( @@ -357,7 +356,7 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest // register experimental modules here app.nm = setCustomModules(app, interfaceRegistry) - app.nm.RegisterInvariants(&app.CrisisKeeper) + app.nm.RegisterInvariantsHandler(&app.CrisisKeeper) var skipGenesisInvariants = cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants)) diff --git a/types/module/server/manager.go b/types/module/server/manager.go index 651ca2be1a..1a088f6eed 100644 --- a/types/module/server/manager.go +++ b/types/module/server/manager.go @@ -23,7 +23,7 @@ type Manager struct { } // RegisterInvariants registers all module routes and module querier routes -func (mm *Manager) RegisterInvariants(ir sdk.InvariantRegistry) { +func (mm *Manager) RegisterInvariantsHandler(ir sdk.InvariantRegistry) { for _, moduleName := range mm.registerInvariantsHandler { moduleName(ir) } From 849a31bb6e3c0e40a9bbde8660eaf3fb608845d2 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 9 Mar 2021 19:04:38 +0530 Subject: [PATCH 33/96] fix failing tests --- app/app.go | 2 +- types/module/server/manager.go | 44 +++++++++++++++++----------------- types/module/server/module.go | 2 +- x/group/server/server.go | 2 +- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/app/app.go b/app/app.go index a6a40528a5..2ca0a944d5 100644 --- a/app/app.go +++ b/app/app.go @@ -356,7 +356,7 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest // register experimental modules here app.nm = setCustomModules(app, interfaceRegistry) - app.nm.RegisterInvariantsHandler(&app.CrisisKeeper) + app.nm.RegisterInvariants(&app.CrisisKeeper) var skipGenesisInvariants = cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants)) diff --git a/types/module/server/manager.go b/types/module/server/manager.go index 1a088f6eed..c6eff92a9a 100644 --- a/types/module/server/manager.go +++ b/types/module/server/manager.go @@ -14,17 +14,17 @@ import ( // Manager is the server module manager type Manager struct { - baseApp *baseapp.BaseApp - cdc *codec.ProtoCodec - keys map[string]ModuleKey - router *router - requiredServices map[reflect.Type]bool - registerInvariantsHandler map[string]RegisterInvariantsHandler + baseApp *baseapp.BaseApp + cdc *codec.ProtoCodec + keys map[string]ModuleKey + router *router + requiredServices map[reflect.Type]bool + registerInvariants map[string]RegisterInvariantsHandler } // RegisterInvariants registers all module routes and module querier routes -func (mm *Manager) RegisterInvariantsHandler(ir sdk.InvariantRegistry) { - for _, moduleName := range mm.registerInvariantsHandler { +func (mm *Manager) RegisterInvariants(ir sdk.InvariantRegistry) { + for _, moduleName := range mm.registerInvariants { moduleName(ir) } } @@ -32,10 +32,10 @@ func (mm *Manager) RegisterInvariantsHandler(ir sdk.InvariantRegistry) { // NewManager creates a new Manager func NewManager(baseApp *baseapp.BaseApp, cdc *codec.ProtoCodec) *Manager { return &Manager{ - baseApp: baseApp, - cdc: cdc, - keys: map[string]ModuleKey{}, - registerInvariantsHandler: map[string]RegisterInvariantsHandler{}, + baseApp: baseApp, + cdc: cdc, + keys: map[string]ModuleKey{}, + registerInvariants: map[string]RegisterInvariantsHandler{}, router: &router{ handlers: map[string]handler{}, providedServices: map[reflect.Type]bool{}, @@ -106,7 +106,7 @@ func (mm *Manager) RegisterModules(modules []module.Module) error { } serverMod.RegisterServices(cfg) - mm.registerInvariantsHandler[name] = cfg.registerInvariantsHandler + mm.registerInvariants[name] = cfg.registerInvariants // If mod implements LegacyRouteModule, register module route. // This is currently used for the group module as part of #218. @@ -150,13 +150,13 @@ func (mm *Manager) CompleteInitialization() error { type RegisterInvariantsHandler func(ir sdk.InvariantRegistry) type configurator struct { - msgServer gogogrpc.Server - queryServer gogogrpc.Server - key *rootModuleKey - cdc codec.Marshaler - requiredServices map[reflect.Type]bool - router sdk.Router - registerInvariantsHandler RegisterInvariantsHandler + msgServer gogogrpc.Server + queryServer gogogrpc.Server + key *rootModuleKey + cdc codec.Marshaler + requiredServices map[reflect.Type]bool + router sdk.Router + registerInvariants RegisterInvariantsHandler } var _ Configurator = &configurator{} @@ -169,8 +169,8 @@ func (c *configurator) QueryServer() gogogrpc.Server { return c.queryServer } -func (c *configurator) RegisterInvariantsHandler(registry RegisterInvariantsHandler) { - c.registerInvariantsHandler = registry +func (c *configurator) RegisterInvariants(registry RegisterInvariantsHandler) { + c.registerInvariants = registry } func (c *configurator) ModuleKey() RootModuleKey { diff --git a/types/module/server/module.go b/types/module/server/module.go index 0ac7745567..7f20f6ac73 100644 --- a/types/module/server/module.go +++ b/types/module/server/module.go @@ -21,7 +21,7 @@ type Configurator interface { ModuleKey() RootModuleKey Marshaler() codec.Marshaler RequireServer(interface{}) - RegisterInvariantsHandler(registry RegisterInvariantsHandler) + RegisterInvariants(registry RegisterInvariantsHandler) // Router() is temporarily added here to use in the group module. // TODO: remove once #225 addressed Router() sdk.Router diff --git a/x/group/server/server.go b/x/group/server/server.go index 070a5727ac..602ec328e9 100644 --- a/x/group/server/server.go +++ b/x/group/server/server.go @@ -165,5 +165,5 @@ func RegisterServices(configurator servermodule.Configurator, accountKeeper Acco impl := newServer(configurator.ModuleKey(), configurator.Router(), accountKeeper, configurator.Marshaler()) group.RegisterMsgServer(configurator.MsgServer(), impl) group.RegisterQueryServer(configurator.QueryServer(), impl) - configurator.RegisterInvariantsHandler(impl.RegisterInvariantsHandler) + configurator.RegisterInvariants(impl.RegisterInvariantsHandler) } From 0062f9dae70a140bde84778525f9b98490541768 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 9 Mar 2021 19:15:56 +0530 Subject: [PATCH 34/96] fix failed tests --- x/group/client/testsuite/query_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/group/client/testsuite/query_test.go b/x/group/client/testsuite/query_test.go index f3b8899865..338387914b 100644 --- a/x/group/client/testsuite/query_test.go +++ b/x/group/client/testsuite/query_test.go @@ -6,10 +6,11 @@ import ( "fmt" "strconv" + tmcli "github.com/tendermint/tendermint/libs/cli" + "github.com/regen-network/regen-ledger/testutil/cli" "github.com/regen-network/regen-ledger/x/group" "github.com/regen-network/regen-ledger/x/group/client" - tmcli "github.com/tendermint/tendermint/libs/cli" ) func (s *IntegrationTestSuite) TestQueryGroupInfo() { From 594c142b912cf1661c842cba1899cef52402d978 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 9 Mar 2021 19:23:43 +0530 Subject: [PATCH 35/96] WIP --- x/group/server/invariants.go | 2 +- x/group/server/server.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 14d04aa6a8..c9f71c0c59 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -11,7 +11,7 @@ import ( "github.com/regen-network/regen-ledger/x/group" ) -func (s serverImpl) RegisterInvariantsHandler(ir sdk.InvariantRegistry) { +func (s serverImpl) RegisterInvariants(ir sdk.InvariantRegistry) { ir.RegisterRoute(group.ModuleName, "Tally-Votes", s.TallyVotesInvariant()) } diff --git a/x/group/server/server.go b/x/group/server/server.go index 602ec328e9..5f4c5b9abe 100644 --- a/x/group/server/server.go +++ b/x/group/server/server.go @@ -165,5 +165,5 @@ func RegisterServices(configurator servermodule.Configurator, accountKeeper Acco impl := newServer(configurator.ModuleKey(), configurator.Router(), accountKeeper, configurator.Marshaler()) group.RegisterMsgServer(configurator.MsgServer(), impl) group.RegisterQueryServer(configurator.QueryServer(), impl) - configurator.RegisterInvariants(impl.RegisterInvariantsHandler) + configurator.RegisterInvariants(impl.RegisterInvariants) } From d790e96215c25a9d231c2dec36172571a4359cb9 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 9 Mar 2021 19:59:24 +0530 Subject: [PATCH 36/96] changes to manager --- types/module/server/manager.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/types/module/server/manager.go b/types/module/server/manager.go index c6eff92a9a..c04e5ce877 100644 --- a/types/module/server/manager.go +++ b/types/module/server/manager.go @@ -25,7 +25,9 @@ type Manager struct { // RegisterInvariants registers all module routes and module querier routes func (mm *Manager) RegisterInvariants(ir sdk.InvariantRegistry) { for _, moduleName := range mm.registerInvariants { - moduleName(ir) + if moduleName != nil { + moduleName(ir) + } } } From b257000dc877fa0157e75301a41617790cdb8733 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 9 Mar 2021 21:44:17 +0530 Subject: [PATCH 37/96] fix failed tests --- types/module/server/manager.go | 42 ++++++++++++++--------------- types/module/server/module.go | 2 +- x/group/client/testsuite/tx_test.go | 8 +++--- x/group/server/server.go | 2 +- 4 files changed, 26 insertions(+), 28 deletions(-) diff --git a/types/module/server/manager.go b/types/module/server/manager.go index c04e5ce877..b6c399e2ea 100644 --- a/types/module/server/manager.go +++ b/types/module/server/manager.go @@ -14,17 +14,17 @@ import ( // Manager is the server module manager type Manager struct { - baseApp *baseapp.BaseApp - cdc *codec.ProtoCodec - keys map[string]ModuleKey - router *router - requiredServices map[reflect.Type]bool - registerInvariants map[string]RegisterInvariantsHandler + baseApp *baseapp.BaseApp + cdc *codec.ProtoCodec + keys map[string]ModuleKey + router *router + requiredServices map[reflect.Type]bool + registerInvariantsHandler map[string]RegisterInvariantsHandler } // RegisterInvariants registers all module routes and module querier routes func (mm *Manager) RegisterInvariants(ir sdk.InvariantRegistry) { - for _, moduleName := range mm.registerInvariants { + for _, moduleName := range mm.registerInvariantsHandler { if moduleName != nil { moduleName(ir) } @@ -34,10 +34,10 @@ func (mm *Manager) RegisterInvariants(ir sdk.InvariantRegistry) { // NewManager creates a new Manager func NewManager(baseApp *baseapp.BaseApp, cdc *codec.ProtoCodec) *Manager { return &Manager{ - baseApp: baseApp, - cdc: cdc, - keys: map[string]ModuleKey{}, - registerInvariants: map[string]RegisterInvariantsHandler{}, + baseApp: baseApp, + cdc: cdc, + keys: map[string]ModuleKey{}, + registerInvariantsHandler: map[string]RegisterInvariantsHandler{}, router: &router{ handlers: map[string]handler{}, providedServices: map[reflect.Type]bool{}, @@ -108,7 +108,7 @@ func (mm *Manager) RegisterModules(modules []module.Module) error { } serverMod.RegisterServices(cfg) - mm.registerInvariants[name] = cfg.registerInvariants + mm.registerInvariantsHandler[name] = cfg.registerInvariantsHandler // If mod implements LegacyRouteModule, register module route. // This is currently used for the group module as part of #218. @@ -152,13 +152,13 @@ func (mm *Manager) CompleteInitialization() error { type RegisterInvariantsHandler func(ir sdk.InvariantRegistry) type configurator struct { - msgServer gogogrpc.Server - queryServer gogogrpc.Server - key *rootModuleKey - cdc codec.Marshaler - requiredServices map[reflect.Type]bool - router sdk.Router - registerInvariants RegisterInvariantsHandler + msgServer gogogrpc.Server + queryServer gogogrpc.Server + key *rootModuleKey + cdc codec.Marshaler + requiredServices map[reflect.Type]bool + router sdk.Router + registerInvariantsHandler RegisterInvariantsHandler } var _ Configurator = &configurator{} @@ -171,8 +171,8 @@ func (c *configurator) QueryServer() gogogrpc.Server { return c.queryServer } -func (c *configurator) RegisterInvariants(registry RegisterInvariantsHandler) { - c.registerInvariants = registry +func (c *configurator) RegisterInvariantsHandler(registry RegisterInvariantsHandler) { + c.registerInvariantsHandler = registry } func (c *configurator) ModuleKey() RootModuleKey { diff --git a/types/module/server/module.go b/types/module/server/module.go index 7f20f6ac73..0ac7745567 100644 --- a/types/module/server/module.go +++ b/types/module/server/module.go @@ -21,7 +21,7 @@ type Configurator interface { ModuleKey() RootModuleKey Marshaler() codec.Marshaler RequireServer(interface{}) - RegisterInvariants(registry RegisterInvariantsHandler) + RegisterInvariantsHandler(registry RegisterInvariantsHandler) // Router() is temporarily added here to use in the group module. // TODO: remove once #225 addressed Router() sdk.Router diff --git a/x/group/client/testsuite/tx_test.go b/x/group/client/testsuite/tx_test.go index 9b581aec1b..9ffcda5a3f 100644 --- a/x/group/client/testsuite/tx_test.go +++ b/x/group/client/testsuite/tx_test.go @@ -8,22 +8,20 @@ import ( "strings" "testing" - tmcli "github.com/tendermint/tendermint/libs/cli" - "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" + sdk "github.com/cosmos/cosmos-sdk/types" banktestutil "github.com/cosmos/cosmos-sdk/x/bank/client/testutil" "github.com/gogo/protobuf/proto" + "github.com/stretchr/testify/suite" + tmcli "github.com/tendermint/tendermint/libs/cli" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/regen-network/regen-ledger/testutil/cli" "github.com/regen-network/regen-ledger/testutil/network" - "github.com/regen-network/regen-ledger/x/group" "github.com/regen-network/regen-ledger/x/group/client" - "github.com/stretchr/testify/suite" ) type IntegrationTestSuite struct { diff --git a/x/group/server/server.go b/x/group/server/server.go index 5f4c5b9abe..d7b20e75d7 100644 --- a/x/group/server/server.go +++ b/x/group/server/server.go @@ -165,5 +165,5 @@ func RegisterServices(configurator servermodule.Configurator, accountKeeper Acco impl := newServer(configurator.ModuleKey(), configurator.Router(), accountKeeper, configurator.Marshaler()) group.RegisterMsgServer(configurator.MsgServer(), impl) group.RegisterQueryServer(configurator.QueryServer(), impl) - configurator.RegisterInvariants(impl.RegisterInvariants) + configurator.RegisterInvariantsHandler(impl.RegisterInvariants) } From 3bd1dcf0171748df544b4d06bd5694888db50ad8 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Wed, 10 Mar 2021 12:22:22 +0530 Subject: [PATCH 38/96] Update invariants in group module --- x/group/server/invariants.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index c9f71c0c59..46bbf1f7c5 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -5,6 +5,7 @@ import ( "math" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" "github.com/regen-network/regen-ledger/orm" "github.com/regen-network/regen-ledger/types" @@ -27,7 +28,7 @@ func (s serverImpl) TallyVotesInvariant() sdk.Invariant { var broken bool ctx := types.Context{Context: sdkCtx} if ctx.BlockHeight()-1 < 0 { - return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "Not enough blocks to perform TallyVotesInvariant"), true + return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "Not enough blocks to perform TallyVotesInvariant"), false } sdkCtx = sdkCtx.WithBlockHeight(ctx.BlockHeight() - 1) it1, err := s.proposalTable.PrefixScan(ctx, 1, math.MaxUint64) @@ -38,19 +39,16 @@ func (s serverImpl) TallyVotesInvariant() sdk.Invariant { if err != nil { panic(err) } - + var t require.TestingT var curProposals []*group.Proposal curProposalRowID, err := orm.ReadAll(it1, &curProposals) - if err != nil { - panic(err) - } - _ = curProposalRowID + require.NoError(t, err, &curProposals) + _ = curProposalRowID var prevProposals []*group.Proposal prevProposalRowID, err := orm.ReadAll(it2, &prevProposals) - if err != nil { - panic(err) - } + require.NoError(t, err, &curProposals) + _ = prevProposalRowID for i := 0; i < len(prevProposals) && i < len(curProposals); i++ { From f16a4c25df1ec755500a2d09389f912a306eef29 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Wed, 10 Mar 2021 12:29:55 +0530 Subject: [PATCH 39/96] Update x/group/server/invariants.go --- x/group/server/invariants.go | 2 +- x/group/server/server.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 46bbf1f7c5..7bc130d755 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -12,7 +12,7 @@ import ( "github.com/regen-network/regen-ledger/x/group" ) -func (s serverImpl) RegisterInvariants(ir sdk.InvariantRegistry) { +func (s serverImpl) RegisterInvariantsHandler(ir sdk.InvariantRegistry) { ir.RegisterRoute(group.ModuleName, "Tally-Votes", s.TallyVotesInvariant()) } diff --git a/x/group/server/server.go b/x/group/server/server.go index d7b20e75d7..070a5727ac 100644 --- a/x/group/server/server.go +++ b/x/group/server/server.go @@ -165,5 +165,5 @@ func RegisterServices(configurator servermodule.Configurator, accountKeeper Acco impl := newServer(configurator.ModuleKey(), configurator.Router(), accountKeeper, configurator.Marshaler()) group.RegisterMsgServer(configurator.MsgServer(), impl) group.RegisterQueryServer(configurator.QueryServer(), impl) - configurator.RegisterInvariantsHandler(impl.RegisterInvariants) + configurator.RegisterInvariantsHandler(impl.RegisterInvariantsHandler) } From cd739de47e40390c3ab239dcd2414e49dc4e5de4 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Wed, 10 Mar 2021 18:57:53 +0530 Subject: [PATCH 40/96] changes to invariants --- x/group/server/invariants.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 7bc130d755..53ec6cd748 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -31,26 +31,23 @@ func (s serverImpl) TallyVotesInvariant() sdk.Invariant { return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "Not enough blocks to perform TallyVotesInvariant"), false } sdkCtx = sdkCtx.WithBlockHeight(ctx.BlockHeight() - 1) - it1, err := s.proposalTable.PrefixScan(ctx, 1, math.MaxUint64) + curIt, err := s.proposalTable.PrefixScan(ctx, 1, math.MaxUint64) if err != nil { panic(err) } - it2, err := s.proposalTable.PrefixScan(sdkCtx, 1, math.MaxUint64) + prevIt, err := s.proposalTable.PrefixScan(sdkCtx, 1, math.MaxUint64) if err != nil { panic(err) } var t require.TestingT var curProposals []*group.Proposal - curProposalRowID, err := orm.ReadAll(it1, &curProposals) + _, err = orm.ReadAll(curIt, &curProposals) require.NoError(t, err, &curProposals) - _ = curProposalRowID var prevProposals []*group.Proposal - prevProposalRowID, err := orm.ReadAll(it2, &prevProposals) + _, err = orm.ReadAll(prevIt, &prevProposals) require.NoError(t, err, &curProposals) - _ = prevProposalRowID - for i := 0; i < len(prevProposals) && i < len(curProposals); i++ { prevYesCount, err := prevProposals[i].VoteState.GetYesCount() if err != nil { From 3a4f33c20b27883032fe6a1a4203268def66b376 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 18 Mar 2021 15:00:36 +0530 Subject: [PATCH 41/96] Change naming convention for invariants --- x/group/server/invariants.go | 2 +- x/group/server/server.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 53ec6cd748..0008af107f 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -12,7 +12,7 @@ import ( "github.com/regen-network/regen-ledger/x/group" ) -func (s serverImpl) RegisterInvariantsHandler(ir sdk.InvariantRegistry) { +func (s serverImpl) RegisterInvariants(ir sdk.InvariantRegistry) { ir.RegisterRoute(group.ModuleName, "Tally-Votes", s.TallyVotesInvariant()) } diff --git a/x/group/server/server.go b/x/group/server/server.go index 070a5727ac..d7b20e75d7 100644 --- a/x/group/server/server.go +++ b/x/group/server/server.go @@ -165,5 +165,5 @@ func RegisterServices(configurator servermodule.Configurator, accountKeeper Acco impl := newServer(configurator.ModuleKey(), configurator.Router(), accountKeeper, configurator.Marshaler()) group.RegisterMsgServer(configurator.MsgServer(), impl) group.RegisterQueryServer(configurator.QueryServer(), impl) - configurator.RegisterInvariantsHandler(impl.RegisterInvariantsHandler) + configurator.RegisterInvariantsHandler(impl.RegisterInvariants) } From 4a0f031e314acfc957cbefa77d9ff136ee98d947 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 18 Mar 2021 15:25:26 +0530 Subject: [PATCH 42/96] Remove `invariant` as param in types/module/server/testutil.go --- types/module/server/testutil.go | 6 ++---- x/data/server/server_test.go | 5 ++--- x/ecocredit/server/server_test.go | 2 +- x/group/server/server_test.go | 3 +-- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/types/module/server/testutil.go b/types/module/server/testutil.go index c9130e3150..76c5be2eab 100644 --- a/types/module/server/testutil.go +++ b/types/module/server/testutil.go @@ -5,8 +5,6 @@ import ( "fmt" "testing" - "github.com/regen-network/regen-ledger/testutil" - "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" @@ -18,6 +16,7 @@ import ( dbm "github.com/tendermint/tm-db" "google.golang.org/grpc" + "github.com/regen-network/regen-ledger/testutil" regentypes "github.com/regen-network/regen-ledger/types" "github.com/regen-network/regen-ledger/types/module" ) @@ -31,7 +30,7 @@ type FixtureFactory struct { invar *sdk.InvariantRegistry } -func NewFixtureFactory(t *testing.T, numSigners int, invariant sdk.InvariantRegistry) *FixtureFactory { +func NewFixtureFactory(t *testing.T, numSigners int) *FixtureFactory { signers := makeTestAddresses(numSigners) return &FixtureFactory{ t: t, @@ -40,7 +39,6 @@ func NewFixtureFactory(t *testing.T, numSigners int, invariant sdk.InvariantRegi // TODO: remove once all code using this uses ADR 033 module wiring cdc: codec.NewProtoCodec(types.NewInterfaceRegistry()), baseApp: baseapp.NewBaseApp("test", log.NewNopLogger(), dbm.NewMemDB(), nil), - invar: &invariant, } } diff --git a/x/data/server/server_test.go b/x/data/server/server_test.go index dc5521488e..7c34033517 100644 --- a/x/data/server/server_test.go +++ b/x/data/server/server_test.go @@ -3,17 +3,16 @@ package server_test import ( "testing" - "github.com/regen-network/regen-ledger/types/module" - "github.com/stretchr/testify/suite" + "github.com/regen-network/regen-ledger/types/module" "github.com/regen-network/regen-ledger/types/module/server" datamodule "github.com/regen-network/regen-ledger/x/data/module" "github.com/regen-network/regen-ledger/x/data/server/testsuite" ) func TestServer(t *testing.T) { - ff := server.NewFixtureFactory(t, 2, nil) + ff := server.NewFixtureFactory(t, 2) ff.SetModules([]module.Module{datamodule.Module{}}) s := testsuite.NewIntegrationTestSuite(ff) suite.Run(t, s) diff --git a/x/ecocredit/server/server_test.go b/x/ecocredit/server/server_test.go index ec1ead8dc2..32dab6aa0e 100644 --- a/x/ecocredit/server/server_test.go +++ b/x/ecocredit/server/server_test.go @@ -12,7 +12,7 @@ import ( ) func TestServer(t *testing.T) { - ff := server.NewFixtureFactory(t, 6, nil) + ff := server.NewFixtureFactory(t, 6) ff.SetModules([]module.Module{ecocreditmodule.Module{}}) s := testsuite.NewIntegrationTestSuite(ff) suite.Run(t, s) diff --git a/x/group/server/server_test.go b/x/group/server/server_test.go index a1f7d34a64..54720e7400 100644 --- a/x/group/server/server_test.go +++ b/x/group/server/server_test.go @@ -11,7 +11,6 @@ import ( bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" - "github.com/stretchr/testify/suite" "github.com/regen-network/regen-ledger/types/module" @@ -21,7 +20,7 @@ import ( ) func TestServer(t *testing.T) { - ff := server.NewFixtureFactory(t, 6, nil) + ff := server.NewFixtureFactory(t, 6) cdc := ff.Codec() // Setting up bank keeper banktypes.RegisterInterfaces(cdc.InterfaceRegistry()) From 42763c9468ec6079cc7d67948a3bf7973f832da1 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 18 Mar 2021 15:30:17 +0530 Subject: [PATCH 43/96] Remove `invar` in `FixtureFactory` --- types/module/server/testutil.go | 1 - 1 file changed, 1 deletion(-) diff --git a/types/module/server/testutil.go b/types/module/server/testutil.go index 76c5be2eab..992923d440 100644 --- a/types/module/server/testutil.go +++ b/types/module/server/testutil.go @@ -27,7 +27,6 @@ type FixtureFactory struct { signers []sdk.AccAddress cdc *codec.ProtoCodec baseApp *baseapp.BaseApp - invar *sdk.InvariantRegistry } func NewFixtureFactory(t *testing.T, numSigners int) *FixtureFactory { From 7daac2e630774f312bbb787dfa0d409e988bb0b8 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 18 Mar 2021 15:38:02 +0530 Subject: [PATCH 44/96] Code cleaning --- app/app.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/app.go b/app/app.go index 2ca0a944d5..f962dd2e61 100644 --- a/app/app.go +++ b/app/app.go @@ -7,8 +7,6 @@ import ( "os" "path/filepath" - // types - "github.com/CosmWasm/wasmd/x/wasm" wasmclient "github.com/CosmWasm/wasmd/x/wasm/client" "github.com/cosmos/cosmos-sdk/baseapp" From f5df08b102cc4064a991512dd264b16e8afd2291 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 19 Mar 2021 17:30:02 +0530 Subject: [PATCH 45/96] Implement tallyVotesInvariant without using serverImpl --- x/group/server/invariants.go | 30 ++++++++++++++++++------------ x/group/server/server.go | 2 +- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 0008af107f..692cda35a4 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -8,34 +8,39 @@ import ( "github.com/stretchr/testify/require" "github.com/regen-network/regen-ledger/orm" - "github.com/regen-network/regen-ledger/types" "github.com/regen-network/regen-ledger/x/group" ) -func (s serverImpl) RegisterInvariants(ir sdk.InvariantRegistry) { - ir.RegisterRoute(group.ModuleName, "Tally-Votes", s.TallyVotesInvariant()) +type Invar struct { + sdkCtx sdk.Context + proposalTable orm.AutoUInt64Table } -func (s serverImpl) AllInvariants() sdk.Invariant { +func RegisterInvariants(ir sdk.InvariantRegistry, invar Invar) { + ir.RegisterRoute(group.ModuleName, "Tally-Votes", tallyVotesInvariant(invar)) +} + +func (s serverImpl) AllInvariants(invar Invar) sdk.Invariant { return func(ctx sdk.Context) (string, bool) { - return s.TallyVotesInvariant()(ctx) + return tallyVotesInvariant(invar)(ctx) } } -func (s serverImpl) TallyVotesInvariant() sdk.Invariant { - return func(sdkCtx sdk.Context) (string, bool) { +func tallyVotesInvariant(invar Invar) sdk.Invariant { + return func(ctx sdk.Context) (string, bool) { var msg string var broken bool - ctx := types.Context{Context: sdkCtx} + ctx = invar.sdkCtx if ctx.BlockHeight()-1 < 0 { - return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "Not enough blocks to perform TallyVotesInvariant"), false + broken = false + return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "Not enough blocks to perform TallyVotesInvariant"), broken } - sdkCtx = sdkCtx.WithBlockHeight(ctx.BlockHeight() - 1) - curIt, err := s.proposalTable.PrefixScan(ctx, 1, math.MaxUint64) + sdkCtx := ctx.WithBlockHeight(ctx.BlockHeight() - 1) + curIt, err := invar.proposalTable.PrefixScan(ctx, 1, math.MaxUint64) if err != nil { panic(err) } - prevIt, err := s.proposalTable.PrefixScan(sdkCtx, 1, math.MaxUint64) + prevIt, err := invar.proposalTable.PrefixScan(sdkCtx, 1, math.MaxUint64) if err != nil { panic(err) } @@ -87,5 +92,6 @@ func (s serverImpl) TallyVotesInvariant() sdk.Invariant { } } return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", msg), broken + } } diff --git a/x/group/server/server.go b/x/group/server/server.go index d7b20e75d7..e849ccce06 100644 --- a/x/group/server/server.go +++ b/x/group/server/server.go @@ -165,5 +165,5 @@ func RegisterServices(configurator servermodule.Configurator, accountKeeper Acco impl := newServer(configurator.ModuleKey(), configurator.Router(), accountKeeper, configurator.Marshaler()) group.RegisterMsgServer(configurator.MsgServer(), impl) group.RegisterQueryServer(configurator.QueryServer(), impl) - configurator.RegisterInvariantsHandler(impl.RegisterInvariants) + // configurator.RegisterInvariantsHandler(impl.RegisterInvariants) } From e4327fcd2b42901a41bfb00b3a1d72348b7f2030 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Sat, 20 Mar 2021 12:41:26 +0530 Subject: [PATCH 46/96] invariant test in progress --- x/group/server/invariants_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 x/group/server/invariants_test.go diff --git a/x/group/server/invariants_test.go b/x/group/server/invariants_test.go new file mode 100644 index 0000000000..5e79ac1496 --- /dev/null +++ b/x/group/server/invariants_test.go @@ -0,0 +1,24 @@ +package server + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/regen-network/regen-ledger/orm" +) + +func TesttallyVotesInvariant(t *testing.T) { + // ff := server.NewFixtureFactory(t, 6) + var ctx sdk.Context //ff.Setup().Context() + // c := ff.Setup().Context() + blockHeight := ctx.BlockHeight() + var proposalTable orm.AutoUInt64Table + + invar := Invar{ + sdkCtx: ctx, + proposalTable: proposalTable, + } + invarRes := tallyVotesInvariant(invar) + +} From a45380dd8ea97ee06d4939abc84a5adf1599aa6d Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Sat, 20 Mar 2021 12:42:16 +0530 Subject: [PATCH 47/96] invariant test in progress --- x/group/server/invariants_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/group/server/invariants_test.go b/x/group/server/invariants_test.go index 5e79ac1496..b17b66ecae 100644 --- a/x/group/server/invariants_test.go +++ b/x/group/server/invariants_test.go @@ -8,7 +8,7 @@ import ( "github.com/regen-network/regen-ledger/orm" ) -func TesttallyVotesInvariant(t *testing.T) { +func TestTallyVotesInvariant(t *testing.T) { // ff := server.NewFixtureFactory(t, 6) var ctx sdk.Context //ff.Setup().Context() // c := ff.Setup().Context() From 30386f8aefd501077872f5b1c2b07190b871bc53 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Sat, 20 Mar 2021 12:52:07 +0530 Subject: [PATCH 48/96] Invariants test in progress --- x/group/server/invariants_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x/group/server/invariants_test.go b/x/group/server/invariants_test.go index b17b66ecae..6322e931a3 100644 --- a/x/group/server/invariants_test.go +++ b/x/group/server/invariants_test.go @@ -12,13 +12,14 @@ func TestTallyVotesInvariant(t *testing.T) { // ff := server.NewFixtureFactory(t, 6) var ctx sdk.Context //ff.Setup().Context() // c := ff.Setup().Context() - blockHeight := ctx.BlockHeight() + // blockHeight := ctx.BlockHeight() + var proposalTable orm.AutoUInt64Table invar := Invar{ sdkCtx: ctx, proposalTable: proposalTable, } - invarRes := tallyVotesInvariant(invar) + tallyVotesInvariant(invar) } From 074e9bc1b4df755c2ac17b4477d768a164c91c50 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Mon, 22 Mar 2021 16:02:46 +0530 Subject: [PATCH 49/96] Modify invariants --- x/group/server/invariants.go | 2 +- x/group/server/invariants_test.go | 174 ++++++++++++++++++++++++++++-- 2 files changed, 166 insertions(+), 10 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 692cda35a4..4a2e202cb6 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -20,7 +20,7 @@ func RegisterInvariants(ir sdk.InvariantRegistry, invar Invar) { ir.RegisterRoute(group.ModuleName, "Tally-Votes", tallyVotesInvariant(invar)) } -func (s serverImpl) AllInvariants(invar Invar) sdk.Invariant { +func AllInvariants(invar Invar) sdk.Invariant { return func(ctx sdk.Context) (string, bool) { return tallyVotesInvariant(invar)(ctx) } diff --git a/x/group/server/invariants_test.go b/x/group/server/invariants_test.go index 6322e931a3..25d497de5a 100644 --- a/x/group/server/invariants_test.go +++ b/x/group/server/invariants_test.go @@ -1,25 +1,181 @@ package server import ( + "math" "testing" - sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/testutil/testdata" + "github.com/stretchr/testify/require" "github.com/regen-network/regen-ledger/orm" + "github.com/regen-network/regen-ledger/types" + "github.com/regen-network/regen-ledger/types/module/server" + "github.com/regen-network/regen-ledger/x/group" + // "github.com/regen-network/regen-ledger/types" ) func TestTallyVotesInvariant(t *testing.T) { - // ff := server.NewFixtureFactory(t, 6) - var ctx sdk.Context //ff.Setup().Context() - // c := ff.Setup().Context() - // blockHeight := ctx.BlockHeight() + ff := server.NewFixtureFactory(t, 6) + sdkCtx, _ := ff.Setup().Context().(types.Context) + sdkCtx1, _ := sdkCtx.CacheContext() + sdkCtx1 = sdkCtx1.WithBlockHeight(10) + // var ctx sdk.Context + // ctx := ff.Setup().Context() + // blockHeight := ctx.BlockHeight() var proposalTable orm.AutoUInt64Table + // ctx1 := types.Context{Context: sdkCtx1} + proposalIterator, err := proposalTable.PrefixScan(sdkCtx1, 1, math.MaxUint64) + if err != nil { + panic(err) + } + var test require.TestingT + var curProposals *group.Proposal + _, err = orm.ReadAll(proposalIterator, &curProposals) + require.NoError(test, err, &curProposals) + // invar := Invar{ + // sdkCtx: ctx, // types.Context{Context: ctx}, + // proposalTable: proposalTable, + // } + // curYesCount, err := curProposals.VoteState.GetYesCount() + // curNoCount, err := curProposals.VoteState.GetNoCount() + // curAbstainCount, err := curProposals.VoteState.GetAbstainCount() + // curVetoCount, err := curProposals.VoteState.GetVetoCount() + + _, _, addr := testdata.KeyTestPubAddr() + groupAddr := addr.String() + + _, _, addr = testdata.KeyTestPubAddr() + memberAddr := addr.String() + + specs := map[string]struct { + src *group.MsgCreateProposalRequest + expErr bool + }{ + "all good with minimum fields set": { + src: &group.MsgCreateProposalRequest{ + GroupAccount: groupAddr, + Proposers: []string{memberAddr}, + }, + }, + "group account required": { + src: &group.MsgCreateProposalRequest{ + Proposers: []string{memberAddr}, + }, + expErr: true, + }, + "proposers required": { + src: &group.MsgCreateProposalRequest{ + GroupAccount: groupAddr, + }, + expErr: true, + }, + "valid proposer address required": { + src: &group.MsgCreateProposalRequest{ + GroupAccount: groupAddr, + Proposers: []string{"invalid-member-address"}, + }, + expErr: true, + }, + "no duplicate proposers": { + src: &group.MsgCreateProposalRequest{ + GroupAccount: groupAddr, + Proposers: []string{memberAddr, memberAddr}, + }, + expErr: true, + }, + "empty proposer address not allowed": { + src: &group.MsgCreateProposalRequest{ + GroupAccount: groupAddr, + Proposers: []string{memberAddr, ""}, + }, + expErr: true, + }, + } + for msg, spec := range specs { + t.Run(msg, func(t *testing.T) { + err := spec.src.ValidateBasic() + if spec.expErr { + require.Error(t, err) + } else { + require.NoError(t, err) + } + }) + } + + specs2 := map[string]struct { + src *group.MsgVoteRequest + expErr bool + }{ + "all good with minimum fields set": { + src: &group.MsgVoteRequest{ + ProposalId: 1, + Choice: group.Choice_CHOICE_YES, + Voter: memberAddr, + }, + }, + "proposal required": { + src: &group.MsgVoteRequest{ + Choice: group.Choice_CHOICE_YES, + Voter: memberAddr, + }, + expErr: true, + }, + "choice required": { + src: &group.MsgVoteRequest{ + ProposalId: 1, + Voter: memberAddr, + }, + expErr: true, + }, + "valid choice required": { + src: &group.MsgVoteRequest{ + ProposalId: 1, + Choice: 5, + Voter: memberAddr, + }, + expErr: true, + }, + "voter required": { + src: &group.MsgVoteRequest{ + ProposalId: 1, + Choice: group.Choice_CHOICE_YES, + }, + expErr: true, + }, + "valid voter address required": { + src: &group.MsgVoteRequest{ + ProposalId: 1, + Choice: group.Choice_CHOICE_YES, + Voter: "invalid-member-address", + }, + expErr: true, + }, + "empty voters address not allowed": { + src: &group.MsgVoteRequest{ + ProposalId: 1, + Choice: group.Choice_CHOICE_YES, + Voter: "", + }, + expErr: true, + }, + } + for msg, spec := range specs2 { + t.Run(msg, func(t *testing.T) { + err := spec.src.ValidateBasic() + if spec.expErr { + require.Error(t, err) + } else { + require.NoError(t, err) + } + // ch := spec.src.Choice + // a := group.Choice_value + //group.Choice_value(spec.src.Choice) + + // vote := spec.src.GetChoice().String() - invar := Invar{ - sdkCtx: ctx, - proposalTable: proposalTable, + }) } - tallyVotesInvariant(invar) + // tallyVotesInvariant(invar) } From 9e31ebfb72c20addd8a7d4c40ccd7448dde7e6f4 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 23 Mar 2021 17:56:16 +0530 Subject: [PATCH 50/96] change invariants --- x/group/server/invariants.go | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 4a2e202cb6..36180db4ff 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -8,39 +8,39 @@ import ( "github.com/stretchr/testify/require" "github.com/regen-network/regen-ledger/orm" + "github.com/regen-network/regen-ledger/types" "github.com/regen-network/regen-ledger/x/group" ) -type Invar struct { - sdkCtx sdk.Context - proposalTable orm.AutoUInt64Table -} +// type Invar struct { +// sdkCtx sdk.Context +// proposalTable orm.AutoUInt64Table +// } -func RegisterInvariants(ir sdk.InvariantRegistry, invar Invar) { - ir.RegisterRoute(group.ModuleName, "Tally-Votes", tallyVotesInvariant(invar)) +func (s serverImpl) RegisterInvariants(ir sdk.InvariantRegistry) { + ir.RegisterRoute(group.ModuleName, "Tally-Votes", s.tallyVotesInvariant()) } -func AllInvariants(invar Invar) sdk.Invariant { +func (s serverImpl) AllInvariants() sdk.Invariant { return func(ctx sdk.Context) (string, bool) { - return tallyVotesInvariant(invar)(ctx) + return s.tallyVotesInvariant()(ctx) } } -func tallyVotesInvariant(invar Invar) sdk.Invariant { - return func(ctx sdk.Context) (string, bool) { +func (s serverImpl) tallyVotesInvariant() sdk.Invariant { + return func(sdkCtx sdk.Context) (string, bool) { var msg string var broken bool - ctx = invar.sdkCtx + ctx := types.Context{Context: sdkCtx} if ctx.BlockHeight()-1 < 0 { - broken = false - return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "Not enough blocks to perform TallyVotesInvariant"), broken + return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "Not enough blocks to perform TallyVotesInvariant"), false } - sdkCtx := ctx.WithBlockHeight(ctx.BlockHeight() - 1) - curIt, err := invar.proposalTable.PrefixScan(ctx, 1, math.MaxUint64) + sdkCtx = sdkCtx.WithBlockHeight(ctx.BlockHeight() - 1) + curIt, err := s.proposalTable.PrefixScan(ctx, 1, math.MaxUint64) if err != nil { panic(err) } - prevIt, err := invar.proposalTable.PrefixScan(sdkCtx, 1, math.MaxUint64) + prevIt, err := s.proposalTable.PrefixScan(sdkCtx, 1, math.MaxUint64) if err != nil { panic(err) } @@ -92,6 +92,5 @@ func tallyVotesInvariant(invar Invar) sdk.Invariant { } } return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", msg), broken - } } From 7bc6181d213cc55586f6d4a66a0866fb0930ccc2 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 26 Mar 2021 13:41:16 +0530 Subject: [PATCH 51/96] invariants test in progress --- x/group/server/invariants.go | 20 ++- x/group/server/invariants_test.go | 226 ++++++++++-------------------- 2 files changed, 81 insertions(+), 165 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 36180db4ff..4b8177f7a5 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -8,15 +8,9 @@ import ( "github.com/stretchr/testify/require" "github.com/regen-network/regen-ledger/orm" - "github.com/regen-network/regen-ledger/types" "github.com/regen-network/regen-ledger/x/group" ) -// type Invar struct { -// sdkCtx sdk.Context -// proposalTable orm.AutoUInt64Table -// } - func (s serverImpl) RegisterInvariants(ir sdk.InvariantRegistry) { ir.RegisterRoute(group.ModuleName, "Tally-Votes", s.tallyVotesInvariant()) } @@ -28,19 +22,23 @@ func (s serverImpl) AllInvariants() sdk.Invariant { } func (s serverImpl) tallyVotesInvariant() sdk.Invariant { - return func(sdkCtx sdk.Context) (string, bool) { + var sdkCtx sdk.Context + return tallyVotesInvariant(sdkCtx, s.proposalTable) +} + +func tallyVotesInvariant(ctx sdk.Context, ProposalTable orm.AutoUInt64Table) sdk.Invariant { + return func(ctx sdk.Context) (string, bool) { var msg string var broken bool - ctx := types.Context{Context: sdkCtx} if ctx.BlockHeight()-1 < 0 { return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "Not enough blocks to perform TallyVotesInvariant"), false } - sdkCtx = sdkCtx.WithBlockHeight(ctx.BlockHeight() - 1) - curIt, err := s.proposalTable.PrefixScan(ctx, 1, math.MaxUint64) + prevCtx := ctx.WithBlockHeight(ctx.BlockHeight() - 1) + prevIt, err := ProposalTable.PrefixScan(ctx, 1, math.MaxUint64) if err != nil { panic(err) } - prevIt, err := s.proposalTable.PrefixScan(sdkCtx, 1, math.MaxUint64) + curIt, err := ProposalTable.PrefixScan(prevCtx, 1, math.MaxUint64) if err != nil { panic(err) } diff --git a/x/group/server/invariants_test.go b/x/group/server/invariants_test.go index 25d497de5a..700d7b220a 100644 --- a/x/group/server/invariants_test.go +++ b/x/group/server/invariants_test.go @@ -1,181 +1,99 @@ package server import ( - "math" + "fmt" "testing" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/store" "github.com/cosmos/cosmos-sdk/testutil/testdata" - "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + gogotypes "github.com/gogo/protobuf/types" + "github.com/tendermint/tendermint/libs/log" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + dbm "github.com/tendermint/tm-db" "github.com/regen-network/regen-ledger/orm" - "github.com/regen-network/regen-ledger/types" - "github.com/regen-network/regen-ledger/types/module/server" "github.com/regen-network/regen-ledger/x/group" - // "github.com/regen-network/regen-ledger/types" ) -func TestTallyVotesInvariant(t *testing.T) { - ff := server.NewFixtureFactory(t, 6) +type invar struct { + s serverImpl + cdc codec.Marshaler +} - sdkCtx, _ := ff.Setup().Context().(types.Context) - sdkCtx1, _ := sdkCtx.CacheContext() - sdkCtx1 = sdkCtx1.WithBlockHeight(10) - // var ctx sdk.Context - // ctx := ff.Setup().Context() - // blockHeight := ctx.BlockHeight() - var proposalTable orm.AutoUInt64Table - // ctx1 := types.Context{Context: sdkCtx1} - proposalIterator, err := proposalTable.PrefixScan(sdkCtx1, 1, math.MaxUint64) +func TestTallyVotesInvariant(t *testing.T) { + var in invar + key := sdk.NewKVStoreKey(group.ModuleName) + db := dbm.NewMemDB() + cms := store.NewCommitMultiStore(db) + cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db) + err := cms.LoadLatestVersion() if err != nil { panic(err) } - var test require.TestingT - var curProposals *group.Proposal - _, err = orm.ReadAll(proposalIterator, &curProposals) - require.NoError(test, err, &curProposals) - // invar := Invar{ - // sdkCtx: ctx, // types.Context{Context: ctx}, - // proposalTable: proposalTable, - // } - // curYesCount, err := curProposals.VoteState.GetYesCount() - // curNoCount, err := curProposals.VoteState.GetNoCount() - // curAbstainCount, err := curProposals.VoteState.GetAbstainCount() - // curVetoCount, err := curProposals.VoteState.GetVetoCount() + ctx := sdk.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger()) + ctx = ctx.WithBlockHeight(10) - _, _, addr := testdata.KeyTestPubAddr() - groupAddr := addr.String() + // Proposal Table + proposalTableBuilder := orm.NewAutoUInt64TableBuilder(ProposalTablePrefix, ProposalTableSeqPrefix, key, &group.Proposal{}, in.cdc) + in.s.proposalByGroupAccountIndex = orm.NewIndex(proposalTableBuilder, ProposalByGroupAccountIndexPrefix, func(value interface{}) ([]orm.RowID, error) { + account := value.(*group.Proposal).GroupAccount + addr, err := sdk.AccAddressFromBech32(account) + if err != nil { + return nil, err + } + return []orm.RowID{addr.Bytes()}, nil + }) + in.s.proposalByProposerIndex = orm.NewIndex(proposalTableBuilder, ProposalByProposerIndexPrefix, func(value interface{}) ([]orm.RowID, error) { + proposers := value.(*group.Proposal).Proposers + r := make([]orm.RowID, len(proposers)) + for i := range proposers { + addr, err := sdk.AccAddressFromBech32(proposers[i]) + if err != nil { + return nil, err + } + r[i] = addr.Bytes() + } + return r, nil + }) + in.s.proposalTable = proposalTableBuilder.Build() - _, _, addr = testdata.KeyTestPubAddr() - memberAddr := addr.String() + _, _, addr1 := testdata.KeyTestPubAddr() + // addr1 := sdk.AccAddress("foo_________________") - specs := map[string]struct { - src *group.MsgCreateProposalRequest - expErr bool - }{ - "all good with minimum fields set": { - src: &group.MsgCreateProposalRequest{ - GroupAccount: groupAddr, - Proposers: []string{memberAddr}, - }, - }, - "group account required": { - src: &group.MsgCreateProposalRequest{ - Proposers: []string{memberAddr}, - }, - expErr: true, - }, - "proposers required": { - src: &group.MsgCreateProposalRequest{ - GroupAccount: groupAddr, - }, - expErr: true, - }, - "valid proposer address required": { - src: &group.MsgCreateProposalRequest{ - GroupAccount: groupAddr, - Proposers: []string{"invalid-member-address"}, - }, - expErr: true, - }, - "no duplicate proposers": { - src: &group.MsgCreateProposalRequest{ - GroupAccount: groupAddr, - Proposers: []string{memberAddr, memberAddr}, - }, - expErr: true, - }, - "empty proposer address not allowed": { - src: &group.MsgCreateProposalRequest{ - GroupAccount: groupAddr, - Proposers: []string{memberAddr, ""}, - }, - expErr: true, - }, - } - for msg, spec := range specs { - t.Run(msg, func(t *testing.T) { - err := spec.src.ValidateBasic() - if spec.expErr { - require.Error(t, err) - } else { - require.NoError(t, err) - } - }) + blockTime, err := gogotypes.TimestampProto(ctx.BlockTime()) + if err != nil { + fmt.Println("block time conversion") + panic(err) } - specs2 := map[string]struct { - src *group.MsgVoteRequest - expErr bool - }{ - "all good with minimum fields set": { - src: &group.MsgVoteRequest{ - ProposalId: 1, - Choice: group.Choice_CHOICE_YES, - Voter: memberAddr, - }, - }, - "proposal required": { - src: &group.MsgVoteRequest{ - Choice: group.Choice_CHOICE_YES, - Voter: memberAddr, - }, - expErr: true, - }, - "choice required": { - src: &group.MsgVoteRequest{ - ProposalId: 1, - Voter: memberAddr, - }, - expErr: true, - }, - "valid choice required": { - src: &group.MsgVoteRequest{ - ProposalId: 1, - Choice: 5, - Voter: memberAddr, - }, - expErr: true, + m1 := &group.Proposal{ + GroupAccount: addr1.String(), + Proposers: []string{addr1.String()}, + SubmittedAt: *blockTime, + GroupVersion: 1, + GroupAccountVersion: 1, + Result: group.ProposalResultUnfinalized, + Status: group.ProposalStatusSubmitted, + ExecutorResult: group.ProposalExecutorResultNotRun, + Timeout: gogotypes.Timestamp{ + Seconds: 600, }, - "voter required": { - src: &group.MsgVoteRequest{ - ProposalId: 1, - Choice: group.Choice_CHOICE_YES, - }, - expErr: true, - }, - "valid voter address required": { - src: &group.MsgVoteRequest{ - ProposalId: 1, - Choice: group.Choice_CHOICE_YES, - Voter: "invalid-member-address", - }, - expErr: true, - }, - "empty voters address not allowed": { - src: &group.MsgVoteRequest{ - ProposalId: 1, - Choice: group.Choice_CHOICE_YES, - Voter: "", - }, - expErr: true, + VoteState: group.Tally{ + YesCount: "2", + NoCount: "0", + AbstainCount: "0", + VetoCount: "0", }, } - for msg, spec := range specs2 { - t.Run(msg, func(t *testing.T) { - err := spec.src.ValidateBasic() - if spec.expErr { - require.Error(t, err) - } else { - require.NoError(t, err) - } - // ch := spec.src.Choice - // a := group.Choice_value - //group.Choice_value(spec.src.Choice) - // vote := spec.src.GetChoice().String() - - }) + _, err = in.s.proposalTable.Create(ctx, m1) + if err != nil { + fmt.Println(err) + panic("create proposal") } - // tallyVotesInvariant(invar) + fmt.Println("It worked") + panic("") } From 1910ed9fdda21e0ae5291642f6bde9679f99c1d0 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 26 Mar 2021 14:02:21 +0530 Subject: [PATCH 52/96] fix invariants --- x/group/server/invariants.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 4b8177f7a5..da09f1860e 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -34,11 +34,11 @@ func tallyVotesInvariant(ctx sdk.Context, ProposalTable orm.AutoUInt64Table) sdk return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "Not enough blocks to perform TallyVotesInvariant"), false } prevCtx := ctx.WithBlockHeight(ctx.BlockHeight() - 1) - prevIt, err := ProposalTable.PrefixScan(ctx, 1, math.MaxUint64) + prevIt, err := ProposalTable.PrefixScan(prevCtx, 1, math.MaxUint64) if err != nil { panic(err) } - curIt, err := ProposalTable.PrefixScan(prevCtx, 1, math.MaxUint64) + curIt, err := ProposalTable.PrefixScan(ctx, 1, math.MaxUint64) if err != nil { panic(err) } From 308f6391ebcfb889bafb8f5cc302c923edfdecb1 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 26 Mar 2021 16:56:50 +0530 Subject: [PATCH 53/96] Invariants test added --- x/group/server/invariants.go | 92 ++++++++++++++++--------------- x/group/server/invariants_test.go | 87 ++++++++++++++++------------- 2 files changed, 98 insertions(+), 81 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index da09f1860e..925c73b2a4 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -1,7 +1,6 @@ package server import ( - "fmt" "math" sdk "github.com/cosmos/cosmos-sdk/types" @@ -22,11 +21,6 @@ func (s serverImpl) AllInvariants() sdk.Invariant { } func (s serverImpl) tallyVotesInvariant() sdk.Invariant { - var sdkCtx sdk.Context - return tallyVotesInvariant(sdkCtx, s.proposalTable) -} - -func tallyVotesInvariant(ctx sdk.Context, ProposalTable orm.AutoUInt64Table) sdk.Invariant { return func(ctx sdk.Context) (string, bool) { var msg string var broken bool @@ -34,14 +28,15 @@ func tallyVotesInvariant(ctx sdk.Context, ProposalTable orm.AutoUInt64Table) sdk return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "Not enough blocks to perform TallyVotesInvariant"), false } prevCtx := ctx.WithBlockHeight(ctx.BlockHeight() - 1) - prevIt, err := ProposalTable.PrefixScan(prevCtx, 1, math.MaxUint64) + prevIt, err := s.proposalTable.PrefixScan(prevCtx, 1, math.MaxUint64) if err != nil { panic(err) } - curIt, err := ProposalTable.PrefixScan(ctx, 1, math.MaxUint64) + curIt, err := s.proposalTable.PrefixScan(ctx, 1, math.MaxUint64) if err != nil { panic(err) } + var t require.TestingT var curProposals []*group.Proposal _, err = orm.ReadAll(curIt, &curProposals) @@ -52,43 +47,52 @@ func tallyVotesInvariant(ctx sdk.Context, ProposalTable orm.AutoUInt64Table) sdk require.NoError(t, err, &curProposals) for i := 0; i < len(prevProposals) && i < len(curProposals); i++ { - prevYesCount, err := prevProposals[i].VoteState.GetYesCount() - if err != nil { - return fmt.Sprint(err), false - } - curYesCount, err := curProposals[i].VoteState.GetYesCount() - if err != nil { - return fmt.Sprint(err), false - } - prevNoCount, err := prevProposals[i].VoteState.GetNoCount() - if err != nil { - return fmt.Sprint(err), false - } - curNoCount, err := curProposals[i].VoteState.GetNoCount() - if err != nil { - return fmt.Sprint(err), false - } - prevAbstainCount, err := prevProposals[i].VoteState.GetAbstainCount() - if err != nil { - return fmt.Sprint(err), false - } - curAbstainCount, err := curProposals[i].VoteState.GetAbstainCount() - if err != nil { - return fmt.Sprint(err), false - } - prevVetoCount, err := prevProposals[i].VoteState.GetVetoCount() - if err != nil { - return fmt.Sprint(err), false - } - curVetoCount, err := curProposals[i].VoteState.GetVetoCount() - if err != nil { - return fmt.Sprint(err), false - } - if (curYesCount.Cmp(prevYesCount) == -1) || (curNoCount.Cmp(prevNoCount) == -1) || (curAbstainCount.Cmp(prevAbstainCount) == -1) || (curVetoCount.Cmp(prevVetoCount) == -1) { - broken = true - msg += "vote tally sums must never have less than the block before\n" - } + msg, broken = tallyVotesInvariant(prevProposals[i], curProposals[i]) } return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", msg), broken } } + +func tallyVotesInvariant(prevProposal *group.Proposal, curProposal *group.Proposal) (string, bool) { + + var msg string + var broken bool + prevYesCount, err := prevProposal.VoteState.GetYesCount() + if err != nil { + panic(err) + } + curYesCount, err := curProposal.VoteState.GetYesCount() + if err != nil { + panic(err) + } + prevNoCount, err := prevProposal.VoteState.GetNoCount() + if err != nil { + panic(err) + } + curNoCount, err := curProposal.VoteState.GetNoCount() + if err != nil { + panic(err) + } + prevAbstainCount, err := prevProposal.VoteState.GetAbstainCount() + if err != nil { + panic(err) + } + curAbstainCount, err := curProposal.VoteState.GetAbstainCount() + if err != nil { + panic(err) + } + prevVetoCount, err := prevProposal.VoteState.GetVetoCount() + if err != nil { + panic(err) + } + curVetoCount, err := curProposal.VoteState.GetVetoCount() + if err != nil { + panic(err) + } + if (curYesCount.Cmp(prevYesCount) == -1) || (curNoCount.Cmp(prevNoCount) == -1) || (curAbstainCount.Cmp(prevAbstainCount) == -1) || (curVetoCount.Cmp(prevVetoCount) == -1) { + broken = true + msg += "vote tally sums must never have less than the block before\n" + + } + return msg, broken +} diff --git a/x/group/server/invariants_test.go b/x/group/server/invariants_test.go index 700d7b220a..99ff677b7f 100644 --- a/x/group/server/invariants_test.go +++ b/x/group/server/invariants_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/store" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -17,13 +18,10 @@ import ( "github.com/regen-network/regen-ledger/x/group" ) -type invar struct { - s serverImpl - cdc codec.Marshaler -} - func TestTallyVotesInvariant(t *testing.T) { - var in invar + var s serverImpl + interfaceRegistry := types.NewInterfaceRegistry() + cdc := codec.NewProtoCodec(interfaceRegistry) key := sdk.NewKVStoreKey(group.ModuleName) db := dbm.NewMemDB() cms := store.NewCommitMultiStore(db) @@ -32,46 +30,52 @@ func TestTallyVotesInvariant(t *testing.T) { if err != nil { panic(err) } - ctx := sdk.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger()) - ctx = ctx.WithBlockHeight(10) + curCtx := sdk.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger()) + curCtx = curCtx.WithBlockHeight(10) + prevCtx := curCtx.WithBlockHeight(curCtx.BlockHeight() - 1) // Proposal Table - proposalTableBuilder := orm.NewAutoUInt64TableBuilder(ProposalTablePrefix, ProposalTableSeqPrefix, key, &group.Proposal{}, in.cdc) - in.s.proposalByGroupAccountIndex = orm.NewIndex(proposalTableBuilder, ProposalByGroupAccountIndexPrefix, func(value interface{}) ([]orm.RowID, error) { - account := value.(*group.Proposal).GroupAccount - addr, err := sdk.AccAddressFromBech32(account) - if err != nil { - return nil, err - } - return []orm.RowID{addr.Bytes()}, nil - }) - in.s.proposalByProposerIndex = orm.NewIndex(proposalTableBuilder, ProposalByProposerIndexPrefix, func(value interface{}) ([]orm.RowID, error) { - proposers := value.(*group.Proposal).Proposers - r := make([]orm.RowID, len(proposers)) - for i := range proposers { - addr, err := sdk.AccAddressFromBech32(proposers[i]) - if err != nil { - return nil, err - } - r[i] = addr.Bytes() - } - return r, nil - }) - in.s.proposalTable = proposalTableBuilder.Build() + proposalTableBuilder := orm.NewAutoUInt64TableBuilder(ProposalTablePrefix, ProposalTableSeqPrefix, key, &group.Proposal{}, cdc) + s.proposalTable = proposalTableBuilder.Build() _, _, addr1 := testdata.KeyTestPubAddr() - // addr1 := sdk.AccAddress("foo_________________") + _, _, addr2 := testdata.KeyTestPubAddr() - blockTime, err := gogotypes.TimestampProto(ctx.BlockTime()) + curBlockTime, err := gogotypes.TimestampProto(curCtx.BlockTime()) + if err != nil { + fmt.Println("block time conversion") + panic(err) + } + prevBlockTime, err := gogotypes.TimestampProto(prevCtx.BlockTime()) if err != nil { fmt.Println("block time conversion") panic(err) } - m1 := &group.Proposal{ + prevProposal := &group.Proposal{ GroupAccount: addr1.String(), Proposers: []string{addr1.String()}, - SubmittedAt: *blockTime, + SubmittedAt: *prevBlockTime, + GroupVersion: 1, + GroupAccountVersion: 1, + Result: group.ProposalResultUnfinalized, + Status: group.ProposalStatusSubmitted, + ExecutorResult: group.ProposalExecutorResultNotRun, + Timeout: gogotypes.Timestamp{ + Seconds: 600, + }, + VoteState: group.Tally{ + YesCount: "1", + NoCount: "0", + AbstainCount: "0", + VetoCount: "0", + }, + } + + curProposal := &group.Proposal{ + GroupAccount: addr2.String(), + Proposers: []string{addr2.String()}, + SubmittedAt: *curBlockTime, GroupVersion: 1, GroupAccountVersion: 1, Result: group.ProposalResultUnfinalized, @@ -88,12 +92,21 @@ func TestTallyVotesInvariant(t *testing.T) { }, } - _, err = in.s.proposalTable.Create(ctx, m1) + _, err = s.proposalTable.Create(prevCtx, prevProposal) if err != nil { fmt.Println(err) panic("create proposal") } - fmt.Println("It worked") - panic("") + _, err = s.proposalTable.Create(curCtx, curProposal) + if err != nil { + fmt.Println(err) + panic("create proposal") + } + + msg, broken := tallyVotesInvariant(prevProposal, curProposal) + fmt.Println(msg, broken) + if broken == true { + panic("Invariant broken") + } } From 60ac9b2c2fc52016149e74fd7099444e59fe1662 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 26 Mar 2021 18:30:04 +0530 Subject: [PATCH 54/96] update files --- go.sum | 54 ------------------------------------------------------ 1 file changed, 54 deletions(-) diff --git a/go.sum b/go.sum index b0acee69ce..c2ab1cd3fb 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,3 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= @@ -91,10 +90,7 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag= github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I= github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= -github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= -github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cockroachdb/apd/v2 v2.0.2 h1:weh8u7Cneje73dDh+2tEVLUvyBc89iwepWCD8b8034E= github.com/cockroachdb/apd/v2 v2.0.2/go.mod h1:DDxRlzC2lo3/vSlmSoS7JkqbbrARPuFOGr0B9pvN3Gw= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= @@ -113,8 +109,6 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7 github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cosmos/cosmos-sdk v0.40.0-rc5/go.mod h1:+oR3VJg5puOc6IDdw5MIKdhjXW+HgBzd5zTfGMjDmNQ= -github.com/cosmos/cosmos-sdk v0.41.0 h1:U614TXkI/+T8HY6V9krC0/mKaDm6qSs9EMFSIKuomCo= -github.com/cosmos/cosmos-sdk v0.41.0/go.mod h1:vlgqdPpUGSxgqSbZea6fjszoLkPKwCuiqSBySLlv4ro= github.com/cosmos/cosmos-sdk v0.42.0-rc0 h1:KZiZrRGb+GfrLTX3M2/oqxJOVkEm3A1O9uE64LLtnbM= github.com/cosmos/cosmos-sdk v0.42.0-rc0/go.mod h1:xiLp1G8mumj82S5KLJGCAyeAlD+7VNomg/aRSJV12yk= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d h1:49RLWk1j44Xu4fjHb6JFYmeUnDORVwHNkDxaQ0ctCVU= @@ -165,12 +159,7 @@ github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFP github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= github.com/enigmampc/btcutil v1.0.3-0.20200723161021-e2fb6adb2a25 h1:2vLKys4RBU4pn2T/hjXMbvwTr1Cvy5THHrQkbeY9HRk= github.com/enigmampc/btcutil v1.0.3-0.20200723161021-e2fb6adb2a25/go.mod h1:hTr8+TLQmkUkgcuh3mcr5fjrT9c64ZzsBCdCEC6UppY= -github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g= -github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= -github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po= -github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/protoc-gen-validate v0.1.0 h1:EQciDnbrYxy13PgWoY8AqoxGiPrpgBZ1R8UNe3ddc+A= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51 h1:0JZ+dUmQeA8IIVUMzysrX4/AKuQwWhV2dYQuPZdvdSQ= @@ -207,12 +196,10 @@ github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 h1:ZpnhV/YsD2/4cESfV5+ github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4= github.com/gogo/gateway v1.1.0 h1:u0SuhL9+Il+UbjM9VIE3ntfRujKbvVpFvNB4HbjeVQ0= github.com/gogo/gateway v1.1.0/go.mod h1:S7rR8FRQyG3QFESeSv4l2WnsyzlCLG0CzBbUUo/mbic= -github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc= @@ -367,7 +354,6 @@ github.com/libp2p/go-buffer-pool v0.0.2 h1:QNK2iAFa8gjAe1SPz6mHSMuCcjs+X1wlHzeOS github.com/libp2p/go-buffer-pool v0.0.2/go.mod h1:MvaB6xw5vOrDl8rYZGLFdKAuk/hRoRZd1Vi32+RXyFM= github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM= github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= -github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.4 h1:8KGKTcQQGm0Kv7vEbKFErAoAOFyyacLStRtQSeYtvkY= @@ -631,8 +617,6 @@ github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoM github.com/tendermint/tendermint v0.34.0-rc4/go.mod h1:yotsojf2C1QBOw4dZrTcxbyxmPUrT4hNuOQWX9XUwB4= github.com/tendermint/tendermint v0.34.0-rc6/go.mod h1:ugzyZO5foutZImv0Iyx/gOFCX6mjJTgbLHTwi17VDVg= github.com/tendermint/tendermint v0.34.0/go.mod h1:Aj3PIipBFSNO21r+Lq3TtzQ+uKESxkbA3yo/INM4QwQ= -github.com/tendermint/tendermint v0.34.3 h1:9yEsf3WO5VAwPVwrmM+RffDMiijmNfWaBwNttHm0q5w= -github.com/tendermint/tendermint v0.34.3/go.mod h1:h57vnXeOlrdvvNFCqPBSaOrpOivl+2swWEtlUAqStYE= github.com/tendermint/tendermint v0.34.8 h1:PMWgUx47FrNTsfhxCWzoiIlVAC1SE9+WBlnsF9oQW0I= github.com/tendermint/tendermint v0.34.8/go.mod h1:JVuu3V1ZexOaZG8VJMRl8lnfrGw6hEB2TVnoUwKRbss= github.com/tendermint/tm-db v0.5.1/go.mod h1:g92zWjHpCYlEvQXvy9M168Su8V1IBEeawpXVVBaK4f4= @@ -651,7 +635,6 @@ github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijb github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= -github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/zondax/hid v0.9.0 h1:eiT3P6vNxAEVxXMw66eZUAAnU2zD33JBkfG/EnfAKl8= github.com/zondax/hid v0.9.0/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= @@ -702,7 +685,6 @@ golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= @@ -715,11 +697,8 @@ golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKG golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4= -golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -761,9 +740,7 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -807,8 +784,6 @@ golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201211090839-8ad439b19e0f h1:QdHQnPce6K4XQewki9WNbG5KOROuDzqO3NaYjI1cXJ0= golang.org/x/sys v0.0.0-20201211090839-8ad439b19e0f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k= -golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E= @@ -824,10 +799,8 @@ golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxb golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= @@ -846,13 +819,10 @@ golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200110213125-a7a6caa82ab2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa h1:5E4dL8+NgFOgjwbTKz+OOEGGhP+ectTmF842l6KjupQ= golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY= -golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= 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= @@ -864,7 +834,6 @@ google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= 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= @@ -891,30 +860,8 @@ google.golang.org/genproto v0.0.0-20201211151036-40ec1c210f7a/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20210114201628-6edceaf6022f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210212180131-e7f2df4ecc2d h1:Edhcm0CKDPLQIecHCp5Iz57Lo7MfT6zUFBAlocmOjcY= google.golang.org/genproto v0.0.0-20210212180131-e7f2df4ecc2d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM= -google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= -google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= -google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= -google.golang.org/grpc v1.22.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= -google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= -google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= -google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= -google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= -google.golang.org/grpc v1.32.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= -google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= 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 v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8= -google.golang.org/grpc v1.35.0 h1:TwIQcH3es+MojMVojxxfQ3l3OF2KzlRxML2xZq0kRo8= -google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= 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= @@ -956,7 +903,6 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From 52a0eb1bf7a819875f47673e6a5217915ed5f96e Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 26 Mar 2021 18:37:36 +0530 Subject: [PATCH 55/96] fix failed tests --- app/app.go | 2 +- app/experimental_appconfig.go | 2 +- app/stable_appconfig.go | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/app.go b/app/app.go index 36eb140280..1ce839da78 100644 --- a/app/app.go +++ b/app/app.go @@ -317,7 +317,7 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest ) // register experimental modules here - app.nm = setCustomModules(app, interfaceRegistry) + // app.nm = setCustomModules(app, interfaceRegistry) app.nm.RegisterInvariants(&app.CrisisKeeper) var skipGenesisInvariants = cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants)) diff --git a/app/experimental_appconfig.go b/app/experimental_appconfig.go index 909ee45648..11d3fe799f 100644 --- a/app/experimental_appconfig.go +++ b/app/experimental_appconfig.go @@ -97,7 +97,7 @@ func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry) } /* New Module Wiring END */ - return newModuleManager + // return newModuleManager } func (app *RegenApp) registerUpgradeHandlers() { diff --git a/app/stable_appconfig.go b/app/stable_appconfig.go index 7758d7e5c5..624072c392 100644 --- a/app/stable_appconfig.go +++ b/app/stable_appconfig.go @@ -14,8 +14,6 @@ import ( paramsclient "github.com/cosmos/cosmos-sdk/x/params/client" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" - - servermodule "github.com/regen-network/regen-ledger/types/module/server" ) func setCustomModuleBasics() []module.AppModuleBasic { @@ -27,9 +25,11 @@ func setCustomModuleBasics() []module.AppModuleBasic { } } -func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry) *servermodule.Manager { - return &servermodule.Manager{} -} +func setCustomModules(_ *RegenApp, interfaceRegistry types.InterfaceRegistry) {} + +// func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry) *servermodule.Manager { +// return &servermodule.Manager{} +// } func setCustomKVStoreKeys() []string { return []string{} From 17edac250a1326032164d188013744d79acc1476 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 26 Mar 2021 19:01:11 +0530 Subject: [PATCH 56/96] fix failed tests --- app/app.go | 2 +- app/experimental_appconfig.go | 2 +- app/stable_appconfig.go | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/app.go b/app/app.go index 1ce839da78..36eb140280 100644 --- a/app/app.go +++ b/app/app.go @@ -317,7 +317,7 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest ) // register experimental modules here - // app.nm = setCustomModules(app, interfaceRegistry) + app.nm = setCustomModules(app, interfaceRegistry) app.nm.RegisterInvariants(&app.CrisisKeeper) var skipGenesisInvariants = cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants)) diff --git a/app/experimental_appconfig.go b/app/experimental_appconfig.go index 11d3fe799f..909ee45648 100644 --- a/app/experimental_appconfig.go +++ b/app/experimental_appconfig.go @@ -97,7 +97,7 @@ func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry) } /* New Module Wiring END */ - // return newModuleManager + return newModuleManager } func (app *RegenApp) registerUpgradeHandlers() { diff --git a/app/stable_appconfig.go b/app/stable_appconfig.go index 624072c392..ef94894275 100644 --- a/app/stable_appconfig.go +++ b/app/stable_appconfig.go @@ -14,6 +14,8 @@ import ( paramsclient "github.com/cosmos/cosmos-sdk/x/params/client" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" + + servermodule "github.com/regen-network/regen-ledger/types/module/server" ) func setCustomModuleBasics() []module.AppModuleBasic { @@ -25,11 +27,11 @@ func setCustomModuleBasics() []module.AppModuleBasic { } } -func setCustomModules(_ *RegenApp, interfaceRegistry types.InterfaceRegistry) {} +// func setCustomModules(_ *RegenApp, _ types.InterfaceRegistry) {} -// func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry) *servermodule.Manager { -// return &servermodule.Manager{} -// } +func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry) *servermodule.Manager { + return &servermodule.Manager{} +} func setCustomKVStoreKeys() []string { return []string{} From c5e5e7219f5ae0f70ec00cad0f3637a04de960e6 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 26 Mar 2021 19:10:10 +0530 Subject: [PATCH 57/96] fix --- app/experimental_appconfig.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/experimental_appconfig.go b/app/experimental_appconfig.go index 909ee45648..ed0848d43a 100644 --- a/app/experimental_appconfig.go +++ b/app/experimental_appconfig.go @@ -72,7 +72,7 @@ func (app *RegenApp) setCustomKeeprs(bApp *baseapp.BaseApp, keys map[string]*sdk govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.wasmKeeper, wasm.EnableAllProposals)) } -func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry) { +func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry) *servermodule.NewManager { /* New Module Wiring START */ newModuleManager := servermodule.NewManager(app.BaseApp, codec.NewProtoCodec(interfaceRegistry)) From 9fb38fd50a285baa9a9a20b180e4c40cf4ef1aeb Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 26 Mar 2021 20:43:33 +0530 Subject: [PATCH 58/96] fix errors --- app/experimental_appconfig.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/experimental_appconfig.go b/app/experimental_appconfig.go index ed0848d43a..b9c2aa9292 100644 --- a/app/experimental_appconfig.go +++ b/app/experimental_appconfig.go @@ -72,10 +72,10 @@ func (app *RegenApp) setCustomKeeprs(bApp *baseapp.BaseApp, keys map[string]*sdk govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.wasmKeeper, wasm.EnableAllProposals)) } -func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry) *servermodule.NewManager { +func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry) { /* New Module Wiring START */ - newModuleManager := servermodule.NewManager(app.BaseApp, codec.NewProtoCodec(interfaceRegistry)) + newModuleManager := servermodule.NewManager(app.BaseApp, codec.NewProtoCodec(interfaceRegistry), sdk.InvariantRegistry) // BEGIN HACK: this is a total, ugly hack until x/auth supports ADR 033 or we have a suitable alternative groupModule := group.Module{AccountKeeper: app.AccountKeeper} From 5fd97fb2519d7eff08630c17cb2958ba7a8b7f1b Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 26 Mar 2021 21:20:11 +0530 Subject: [PATCH 59/96] fix errors --- app/experimental_appconfig.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/experimental_appconfig.go b/app/experimental_appconfig.go index b9c2aa9292..b427926272 100644 --- a/app/experimental_appconfig.go +++ b/app/experimental_appconfig.go @@ -72,10 +72,10 @@ func (app *RegenApp) setCustomKeeprs(bApp *baseapp.BaseApp, keys map[string]*sdk govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.wasmKeeper, wasm.EnableAllProposals)) } -func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry) { +func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry) *servermodule.Manager { /* New Module Wiring START */ - newModuleManager := servermodule.NewManager(app.BaseApp, codec.NewProtoCodec(interfaceRegistry), sdk.InvariantRegistry) + newModuleManager := servermodule.NewManager(app.BaseApp, codec.NewProtoCodec(interfaceRegistry)) // BEGIN HACK: this is a total, ugly hack until x/auth supports ADR 033 or we have a suitable alternative groupModule := group.Module{AccountKeeper: app.AccountKeeper} From b7ea6f3ba9ffc617b4e92a2728dab15eee9b8b0f Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 26 Mar 2021 23:56:33 +0530 Subject: [PATCH 60/96] Register Invariants in configurator --- app/stable_appconfig.go | 2 -- x/group/server/server.go | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/stable_appconfig.go b/app/stable_appconfig.go index ef94894275..7758d7e5c5 100644 --- a/app/stable_appconfig.go +++ b/app/stable_appconfig.go @@ -27,8 +27,6 @@ func setCustomModuleBasics() []module.AppModuleBasic { } } -// func setCustomModules(_ *RegenApp, _ types.InterfaceRegistry) {} - func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry) *servermodule.Manager { return &servermodule.Manager{} } diff --git a/x/group/server/server.go b/x/group/server/server.go index e849ccce06..d7b20e75d7 100644 --- a/x/group/server/server.go +++ b/x/group/server/server.go @@ -165,5 +165,5 @@ func RegisterServices(configurator servermodule.Configurator, accountKeeper Acco impl := newServer(configurator.ModuleKey(), configurator.Router(), accountKeeper, configurator.Marshaler()) group.RegisterMsgServer(configurator.MsgServer(), impl) group.RegisterQueryServer(configurator.QueryServer(), impl) - // configurator.RegisterInvariantsHandler(impl.RegisterInvariants) + configurator.RegisterInvariantsHandler(impl.RegisterInvariants) } From 58d65e5e62ce7dc6ed7417a65cd494dad0dd64f2 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 30 Mar 2021 10:02:25 +0530 Subject: [PATCH 61/96] remove serverImpl in invariants test --- x/group/server/invariants_test.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/x/group/server/invariants_test.go b/x/group/server/invariants_test.go index 99ff677b7f..9fbf4459c0 100644 --- a/x/group/server/invariants_test.go +++ b/x/group/server/invariants_test.go @@ -19,7 +19,6 @@ import ( ) func TestTallyVotesInvariant(t *testing.T) { - var s serverImpl interfaceRegistry := types.NewInterfaceRegistry() cdc := codec.NewProtoCodec(interfaceRegistry) key := sdk.NewKVStoreKey(group.ModuleName) @@ -36,7 +35,7 @@ func TestTallyVotesInvariant(t *testing.T) { // Proposal Table proposalTableBuilder := orm.NewAutoUInt64TableBuilder(ProposalTablePrefix, ProposalTableSeqPrefix, key, &group.Proposal{}, cdc) - s.proposalTable = proposalTableBuilder.Build() + proposalTable := proposalTableBuilder.Build() _, _, addr1 := testdata.KeyTestPubAddr() _, _, addr2 := testdata.KeyTestPubAddr() @@ -92,13 +91,13 @@ func TestTallyVotesInvariant(t *testing.T) { }, } - _, err = s.proposalTable.Create(prevCtx, prevProposal) + _, err = proposalTable.Create(prevCtx, prevProposal) if err != nil { fmt.Println(err) panic("create proposal") } - _, err = s.proposalTable.Create(curCtx, curProposal) + _, err = proposalTable.Create(curCtx, curProposal) if err != nil { fmt.Println(err) panic("create proposal") From 09568a6e54d68a5a5a1ab6a078a60a6aa7763c74 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 30 Mar 2021 10:58:00 +0530 Subject: [PATCH 62/96] add table tests for invariants --- x/group/server/invariants_test.go | 152 ++++++++++++++++++++---------- 1 file changed, 102 insertions(+), 50 deletions(-) diff --git a/x/group/server/invariants_test.go b/x/group/server/invariants_test.go index 9fbf4459c0..bcb704253d 100644 --- a/x/group/server/invariants_test.go +++ b/x/group/server/invariants_test.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" gogotypes "github.com/gogo/protobuf/types" + "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" @@ -51,61 +52,112 @@ func TestTallyVotesInvariant(t *testing.T) { panic(err) } - prevProposal := &group.Proposal{ - GroupAccount: addr1.String(), - Proposers: []string{addr1.String()}, - SubmittedAt: *prevBlockTime, - GroupVersion: 1, - GroupAccountVersion: 1, - Result: group.ProposalResultUnfinalized, - Status: group.ProposalStatusSubmitted, - ExecutorResult: group.ProposalExecutorResultNotRun, - Timeout: gogotypes.Timestamp{ - Seconds: 600, + specs := map[string]struct { + prevReq *group.Proposal + curReq *group.Proposal + expErr bool + }{ + "invariant not broken": { + prevReq: &group.Proposal{ + GroupAccount: addr1.String(), + Proposers: []string{addr1.String()}, + SubmittedAt: *prevBlockTime, + GroupVersion: 1, + GroupAccountVersion: 1, + Result: group.ProposalResultUnfinalized, + Status: group.ProposalStatusSubmitted, + ExecutorResult: group.ProposalExecutorResultNotRun, + Timeout: gogotypes.Timestamp{ + Seconds: 600, + }, + VoteState: group.Tally{ + YesCount: "1", + NoCount: "0", + AbstainCount: "0", + VetoCount: "0", + }, + }, + curReq: &group.Proposal{ + GroupAccount: addr2.String(), + Proposers: []string{addr2.String()}, + SubmittedAt: *curBlockTime, + GroupVersion: 1, + GroupAccountVersion: 1, + Result: group.ProposalResultUnfinalized, + Status: group.ProposalStatusSubmitted, + ExecutorResult: group.ProposalExecutorResultNotRun, + Timeout: gogotypes.Timestamp{ + Seconds: 600, + }, + VoteState: group.Tally{ + YesCount: "2", + NoCount: "0", + AbstainCount: "0", + VetoCount: "0", + }, + }, }, - VoteState: group.Tally{ - YesCount: "1", - NoCount: "0", - AbstainCount: "0", - VetoCount: "0", + "VoteState of current block must be greater than previous block": { + prevReq: &group.Proposal{ + GroupAccount: addr1.String(), + Proposers: []string{addr1.String()}, + SubmittedAt: *prevBlockTime, + GroupVersion: 1, + GroupAccountVersion: 1, + Result: group.ProposalResultUnfinalized, + Status: group.ProposalStatusSubmitted, + ExecutorResult: group.ProposalExecutorResultNotRun, + Timeout: gogotypes.Timestamp{ + Seconds: 600, + }, + VoteState: group.Tally{ + YesCount: "2", + NoCount: "0", + AbstainCount: "0", + VetoCount: "0", + }, + }, + curReq: &group.Proposal{ + GroupAccount: addr2.String(), + Proposers: []string{addr2.String()}, + SubmittedAt: *curBlockTime, + GroupVersion: 1, + GroupAccountVersion: 1, + Result: group.ProposalResultUnfinalized, + Status: group.ProposalStatusSubmitted, + ExecutorResult: group.ProposalExecutorResultNotRun, + Timeout: gogotypes.Timestamp{ + Seconds: 600, + }, + VoteState: group.Tally{ + YesCount: "1", + NoCount: "0", + AbstainCount: "0", + VetoCount: "0", + }, + }, + expErr: true, }, } + for _, spec := range specs { + spec := spec + prevProposal := spec.prevReq + curProposal := spec.curReq - curProposal := &group.Proposal{ - GroupAccount: addr2.String(), - Proposers: []string{addr2.String()}, - SubmittedAt: *curBlockTime, - GroupVersion: 1, - GroupAccountVersion: 1, - Result: group.ProposalResultUnfinalized, - Status: group.ProposalStatusSubmitted, - ExecutorResult: group.ProposalExecutorResultNotRun, - Timeout: gogotypes.Timestamp{ - Seconds: 600, - }, - VoteState: group.Tally{ - YesCount: "2", - NoCount: "0", - AbstainCount: "0", - VetoCount: "0", - }, - } - - _, err = proposalTable.Create(prevCtx, prevProposal) - if err != nil { - fmt.Println(err) - panic("create proposal") - } + _, err = proposalTable.Create(prevCtx, prevProposal) + if err != nil { + fmt.Println(err) + panic("create proposal") + } - _, err = proposalTable.Create(curCtx, curProposal) - if err != nil { - fmt.Println(err) - panic("create proposal") - } + _, err = proposalTable.Create(curCtx, curProposal) + if err != nil { + fmt.Println(err) + panic("create proposal") + } - msg, broken := tallyVotesInvariant(prevProposal, curProposal) - fmt.Println(msg, broken) - if broken == true { - panic("Invariant broken") + var test require.TestingT + _, broken := tallyVotesInvariant(prevProposal, curProposal) + require.Equal(test, spec.expErr, broken) } } From d6476517ab47acde82fd58bc29391f3ec51999d1 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 30 Mar 2021 11:03:27 +0530 Subject: [PATCH 63/96] change table test name --- x/group/server/invariants_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/group/server/invariants_test.go b/x/group/server/invariants_test.go index bcb704253d..e2ee587efa 100644 --- a/x/group/server/invariants_test.go +++ b/x/group/server/invariants_test.go @@ -97,7 +97,7 @@ func TestTallyVotesInvariant(t *testing.T) { }, }, }, - "VoteState of current block must be greater than previous block": { + "invariant broken": { prevReq: &group.Proposal{ GroupAccount: addr1.String(), Proposers: []string{addr1.String()}, From 9910747b700604bfd0d708ed4182e4861a11fadd Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 30 Mar 2021 13:59:32 +0530 Subject: [PATCH 64/96] change params in tallyVotesInvariant func --- x/group/server/invariants.go | 119 +++++++++++++++------------- x/group/server/invariants_test.go | 127 +++++++++++++++++++++++++++++- 2 files changed, 188 insertions(+), 58 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 925c73b2a4..9374467cf5 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -22,77 +22,84 @@ func (s serverImpl) AllInvariants() sdk.Invariant { func (s serverImpl) tallyVotesInvariant() sdk.Invariant { return func(ctx sdk.Context) (string, bool) { - var msg string - var broken bool - if ctx.BlockHeight()-1 < 0 { - return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "Not enough blocks to perform TallyVotesInvariant"), false - } - prevCtx := ctx.WithBlockHeight(ctx.BlockHeight() - 1) - prevIt, err := s.proposalTable.PrefixScan(prevCtx, 1, math.MaxUint64) - if err != nil { - panic(err) - } - curIt, err := s.proposalTable.PrefixScan(ctx, 1, math.MaxUint64) - if err != nil { - panic(err) - } - - var t require.TestingT - var curProposals []*group.Proposal - _, err = orm.ReadAll(curIt, &curProposals) - require.NoError(t, err, &curProposals) - - var prevProposals []*group.Proposal - _, err = orm.ReadAll(prevIt, &prevProposals) - require.NoError(t, err, &curProposals) - - for i := 0; i < len(prevProposals) && i < len(curProposals); i++ { - msg, broken = tallyVotesInvariant(prevProposals[i], curProposals[i]) - } + msg, broken := tallyVotesInvariant(ctx, s.proposalTable) return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", msg), broken } } -func tallyVotesInvariant(prevProposal *group.Proposal, curProposal *group.Proposal) (string, bool) { +func tallyVotesInvariant(ctx sdk.Context, proposalTable orm.AutoUInt64Table) (string, bool) { var msg string var broken bool - prevYesCount, err := prevProposal.VoteState.GetYesCount() - if err != nil { - panic(err) - } - curYesCount, err := curProposal.VoteState.GetYesCount() - if err != nil { - panic(err) - } - prevNoCount, err := prevProposal.VoteState.GetNoCount() - if err != nil { - panic(err) - } - curNoCount, err := curProposal.VoteState.GetNoCount() - if err != nil { - panic(err) - } - prevAbstainCount, err := prevProposal.VoteState.GetAbstainCount() - if err != nil { - panic(err) - } - curAbstainCount, err := curProposal.VoteState.GetAbstainCount() - if err != nil { - panic(err) + + if ctx.BlockHeight()-1 < 0 { + return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "Not enough blocks to perform TallyVotesInvariant"), false } - prevVetoCount, err := prevProposal.VoteState.GetVetoCount() + prevCtx := ctx.WithBlockHeight(ctx.BlockHeight() - 1) + + prevIt, err := proposalTable.PrefixScan(prevCtx, 1, math.MaxUint64) if err != nil { panic(err) } - curVetoCount, err := curProposal.VoteState.GetVetoCount() + curIt, err := proposalTable.PrefixScan(ctx, 1, math.MaxUint64) if err != nil { panic(err) } - if (curYesCount.Cmp(prevYesCount) == -1) || (curNoCount.Cmp(prevNoCount) == -1) || (curAbstainCount.Cmp(prevAbstainCount) == -1) || (curVetoCount.Cmp(prevVetoCount) == -1) { - broken = true - msg += "vote tally sums must never have less than the block before\n" + var t require.TestingT + var curProposals []*group.Proposal + _, err = orm.ReadAll(curIt, &curProposals) + require.NoError(t, err, &curProposals) + + var prevProposals []*group.Proposal + _, err = orm.ReadAll(prevIt, &prevProposals) + require.NoError(t, err, &curProposals) + + for i := 0; i < len(prevProposals) && i < len(curProposals); i++ { + prevYesCount, err := prevProposals[i].VoteState.GetYesCount() + if err != nil { + broken = true + msg = err.Error() + } + curYesCount, err := curProposals[i].VoteState.GetYesCount() + if err != nil { + broken = true + msg = err.Error() + } + prevNoCount, err := prevProposals[i].VoteState.GetNoCount() + if err != nil { + broken = true + msg = err.Error() + } + curNoCount, err := curProposals[i].VoteState.GetNoCount() + if err != nil { + broken = true + msg = err.Error() + } + prevAbstainCount, err := prevProposals[i].VoteState.GetAbstainCount() + if err != nil { + broken = true + msg = err.Error() + } + curAbstainCount, err := curProposals[i].VoteState.GetAbstainCount() + if err != nil { + broken = true + msg = err.Error() + } + prevVetoCount, err := prevProposals[i].VoteState.GetVetoCount() + if err != nil { + broken = true + msg = err.Error() + } + curVetoCount, err := curProposals[i].VoteState.GetVetoCount() + if err != nil { + broken = true + msg = err.Error() + } + if (curYesCount.Cmp(prevYesCount) == -1) || (curNoCount.Cmp(prevNoCount) == -1) || (curAbstainCount.Cmp(prevAbstainCount) == -1) || (curVetoCount.Cmp(prevVetoCount) == -1) { + broken = true + msg += "vote tally sums must never have less than the block before\n" + } } return msg, broken } diff --git a/x/group/server/invariants_test.go b/x/group/server/invariants_test.go index e2ee587efa..6adcf714f4 100644 --- a/x/group/server/invariants_test.go +++ b/x/group/server/invariants_test.go @@ -97,7 +97,7 @@ func TestTallyVotesInvariant(t *testing.T) { }, }, }, - "invariant broken": { + "current block yes vote count must be greater than previous block yes vote count": { prevReq: &group.Proposal{ GroupAccount: addr1.String(), Proposers: []string{addr1.String()}, @@ -138,6 +138,129 @@ func TestTallyVotesInvariant(t *testing.T) { }, expErr: true, }, + "current block no vote count must be greater than previous block no vote count": { + prevReq: &group.Proposal{ + GroupAccount: addr1.String(), + Proposers: []string{addr1.String()}, + SubmittedAt: *prevBlockTime, + GroupVersion: 1, + GroupAccountVersion: 1, + Result: group.ProposalResultUnfinalized, + Status: group.ProposalStatusSubmitted, + ExecutorResult: group.ProposalExecutorResultNotRun, + Timeout: gogotypes.Timestamp{ + Seconds: 600, + }, + VoteState: group.Tally{ + YesCount: "0", + NoCount: "2", + AbstainCount: "0", + VetoCount: "0", + }, + }, + curReq: &group.Proposal{ + GroupAccount: addr2.String(), + Proposers: []string{addr2.String()}, + SubmittedAt: *curBlockTime, + GroupVersion: 1, + GroupAccountVersion: 1, + Result: group.ProposalResultUnfinalized, + Status: group.ProposalStatusSubmitted, + ExecutorResult: group.ProposalExecutorResultNotRun, + Timeout: gogotypes.Timestamp{ + Seconds: 600, + }, + VoteState: group.Tally{ + YesCount: "0", + NoCount: "1", + AbstainCount: "0", + VetoCount: "0", + }, + }, + expErr: true, + }, + "current block abstain vote count must be greater than previous block abstain vote count": { + prevReq: &group.Proposal{ + GroupAccount: addr1.String(), + Proposers: []string{addr1.String()}, + SubmittedAt: *prevBlockTime, + GroupVersion: 1, + GroupAccountVersion: 1, + Result: group.ProposalResultUnfinalized, + Status: group.ProposalStatusSubmitted, + ExecutorResult: group.ProposalExecutorResultNotRun, + Timeout: gogotypes.Timestamp{ + Seconds: 600, + }, + VoteState: group.Tally{ + YesCount: "0", + NoCount: "0", + AbstainCount: "2", + VetoCount: "0", + }, + }, + curReq: &group.Proposal{ + GroupAccount: addr2.String(), + Proposers: []string{addr2.String()}, + SubmittedAt: *curBlockTime, + GroupVersion: 1, + GroupAccountVersion: 1, + Result: group.ProposalResultUnfinalized, + Status: group.ProposalStatusSubmitted, + ExecutorResult: group.ProposalExecutorResultNotRun, + Timeout: gogotypes.Timestamp{ + Seconds: 600, + }, + VoteState: group.Tally{ + YesCount: "0", + NoCount: "0", + AbstainCount: "1", + VetoCount: "0", + }, + }, + expErr: true, + }, + "current block veto vote count must be greater than previous block veto vote count": { + prevReq: &group.Proposal{ + GroupAccount: addr1.String(), + Proposers: []string{addr1.String()}, + SubmittedAt: *prevBlockTime, + GroupVersion: 1, + GroupAccountVersion: 1, + Result: group.ProposalResultUnfinalized, + Status: group.ProposalStatusSubmitted, + ExecutorResult: group.ProposalExecutorResultNotRun, + Timeout: gogotypes.Timestamp{ + Seconds: 600, + }, + VoteState: group.Tally{ + YesCount: "0", + NoCount: "0", + AbstainCount: "0", + VetoCount: "2", + }, + }, + curReq: &group.Proposal{ + GroupAccount: addr2.String(), + Proposers: []string{addr2.String()}, + SubmittedAt: *curBlockTime, + GroupVersion: 1, + GroupAccountVersion: 1, + Result: group.ProposalResultUnfinalized, + Status: group.ProposalStatusSubmitted, + ExecutorResult: group.ProposalExecutorResultNotRun, + Timeout: gogotypes.Timestamp{ + Seconds: 600, + }, + VoteState: group.Tally{ + YesCount: "0", + NoCount: "0", + AbstainCount: "0", + VetoCount: "1", + }, + }, + expErr: true, + }, } for _, spec := range specs { spec := spec @@ -157,7 +280,7 @@ func TestTallyVotesInvariant(t *testing.T) { } var test require.TestingT - _, broken := tallyVotesInvariant(prevProposal, curProposal) + _, broken := tallyVotesInvariant(curCtx, proposalTable) require.Equal(test, spec.expErr, broken) } } From adbc7e546731477d5d7dc060880bb3a0472c943f Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 30 Mar 2021 15:31:31 +0530 Subject: [PATCH 65/96] add changes to invariants_test --- x/group/server/invariants_test.go | 391 ++++++++++++++++-------------- 1 file changed, 207 insertions(+), 184 deletions(-) diff --git a/x/group/server/invariants_test.go b/x/group/server/invariants_test.go index 6adcf714f4..2585c53120 100644 --- a/x/group/server/invariants_test.go +++ b/x/group/server/invariants_test.go @@ -53,230 +53,253 @@ func TestTallyVotesInvariant(t *testing.T) { } specs := map[string]struct { - prevReq *group.Proposal - curReq *group.Proposal + prevReq []*group.Proposal + curReq []*group.Proposal expErr bool }{ "invariant not broken": { - prevReq: &group.Proposal{ - GroupAccount: addr1.String(), - Proposers: []string{addr1.String()}, - SubmittedAt: *prevBlockTime, - GroupVersion: 1, - GroupAccountVersion: 1, - Result: group.ProposalResultUnfinalized, - Status: group.ProposalStatusSubmitted, - ExecutorResult: group.ProposalExecutorResultNotRun, - Timeout: gogotypes.Timestamp{ - Seconds: 600, - }, - VoteState: group.Tally{ - YesCount: "1", - NoCount: "0", - AbstainCount: "0", - VetoCount: "0", + prevReq: []*group.Proposal{ + { + GroupAccount: addr1.String(), + Proposers: []string{addr1.String()}, + SubmittedAt: *prevBlockTime, + GroupVersion: 1, + GroupAccountVersion: 1, + Result: group.ProposalResultUnfinalized, + Status: group.ProposalStatusSubmitted, + ExecutorResult: group.ProposalExecutorResultNotRun, + Timeout: gogotypes.Timestamp{ + Seconds: 600, + }, + VoteState: group.Tally{ + YesCount: "1", + NoCount: "0", + AbstainCount: "0", + VetoCount: "0", + }, }, }, - curReq: &group.Proposal{ - GroupAccount: addr2.String(), - Proposers: []string{addr2.String()}, - SubmittedAt: *curBlockTime, - GroupVersion: 1, - GroupAccountVersion: 1, - Result: group.ProposalResultUnfinalized, - Status: group.ProposalStatusSubmitted, - ExecutorResult: group.ProposalExecutorResultNotRun, - Timeout: gogotypes.Timestamp{ - Seconds: 600, - }, - VoteState: group.Tally{ - YesCount: "2", - NoCount: "0", - AbstainCount: "0", - VetoCount: "0", + + curReq: []*group.Proposal{ + { + GroupAccount: addr2.String(), + Proposers: []string{addr2.String()}, + SubmittedAt: *curBlockTime, + GroupVersion: 1, + GroupAccountVersion: 1, + Result: group.ProposalResultUnfinalized, + Status: group.ProposalStatusSubmitted, + ExecutorResult: group.ProposalExecutorResultNotRun, + Timeout: gogotypes.Timestamp{ + Seconds: 600, + }, + VoteState: group.Tally{ + YesCount: "2", + NoCount: "0", + AbstainCount: "0", + VetoCount: "0", + }, }, }, }, "current block yes vote count must be greater than previous block yes vote count": { - prevReq: &group.Proposal{ - GroupAccount: addr1.String(), - Proposers: []string{addr1.String()}, - SubmittedAt: *prevBlockTime, - GroupVersion: 1, - GroupAccountVersion: 1, - Result: group.ProposalResultUnfinalized, - Status: group.ProposalStatusSubmitted, - ExecutorResult: group.ProposalExecutorResultNotRun, - Timeout: gogotypes.Timestamp{ - Seconds: 600, - }, - VoteState: group.Tally{ - YesCount: "2", - NoCount: "0", - AbstainCount: "0", - VetoCount: "0", + prevReq: []*group.Proposal{ + { + GroupAccount: addr1.String(), + Proposers: []string{addr1.String()}, + SubmittedAt: *prevBlockTime, + GroupVersion: 1, + GroupAccountVersion: 1, + Result: group.ProposalResultUnfinalized, + Status: group.ProposalStatusSubmitted, + ExecutorResult: group.ProposalExecutorResultNotRun, + Timeout: gogotypes.Timestamp{ + Seconds: 600, + }, + VoteState: group.Tally{ + YesCount: "2", + NoCount: "0", + AbstainCount: "0", + VetoCount: "0", + }, }, }, - curReq: &group.Proposal{ - GroupAccount: addr2.String(), - Proposers: []string{addr2.String()}, - SubmittedAt: *curBlockTime, - GroupVersion: 1, - GroupAccountVersion: 1, - Result: group.ProposalResultUnfinalized, - Status: group.ProposalStatusSubmitted, - ExecutorResult: group.ProposalExecutorResultNotRun, - Timeout: gogotypes.Timestamp{ - Seconds: 600, - }, - VoteState: group.Tally{ - YesCount: "1", - NoCount: "0", - AbstainCount: "0", - VetoCount: "0", + curReq: []*group.Proposal{ + { + GroupAccount: addr2.String(), + Proposers: []string{addr2.String()}, + SubmittedAt: *curBlockTime, + GroupVersion: 1, + GroupAccountVersion: 1, + Result: group.ProposalResultUnfinalized, + Status: group.ProposalStatusSubmitted, + ExecutorResult: group.ProposalExecutorResultNotRun, + Timeout: gogotypes.Timestamp{ + Seconds: 600, + }, + VoteState: group.Tally{ + YesCount: "1", + NoCount: "0", + AbstainCount: "0", + VetoCount: "0", + }, }, }, expErr: true, }, "current block no vote count must be greater than previous block no vote count": { - prevReq: &group.Proposal{ - GroupAccount: addr1.String(), - Proposers: []string{addr1.String()}, - SubmittedAt: *prevBlockTime, - GroupVersion: 1, - GroupAccountVersion: 1, - Result: group.ProposalResultUnfinalized, - Status: group.ProposalStatusSubmitted, - ExecutorResult: group.ProposalExecutorResultNotRun, - Timeout: gogotypes.Timestamp{ - Seconds: 600, - }, - VoteState: group.Tally{ - YesCount: "0", - NoCount: "2", - AbstainCount: "0", - VetoCount: "0", + prevReq: []*group.Proposal{ + { + GroupAccount: addr1.String(), + Proposers: []string{addr1.String()}, + SubmittedAt: *prevBlockTime, + GroupVersion: 1, + GroupAccountVersion: 1, + Result: group.ProposalResultUnfinalized, + Status: group.ProposalStatusSubmitted, + ExecutorResult: group.ProposalExecutorResultNotRun, + Timeout: gogotypes.Timestamp{ + Seconds: 600, + }, + VoteState: group.Tally{ + YesCount: "0", + NoCount: "2", + AbstainCount: "0", + VetoCount: "0", + }, }, }, - curReq: &group.Proposal{ - GroupAccount: addr2.String(), - Proposers: []string{addr2.String()}, - SubmittedAt: *curBlockTime, - GroupVersion: 1, - GroupAccountVersion: 1, - Result: group.ProposalResultUnfinalized, - Status: group.ProposalStatusSubmitted, - ExecutorResult: group.ProposalExecutorResultNotRun, - Timeout: gogotypes.Timestamp{ - Seconds: 600, - }, - VoteState: group.Tally{ - YesCount: "0", - NoCount: "1", - AbstainCount: "0", - VetoCount: "0", + curReq: []*group.Proposal{ + { + GroupAccount: addr2.String(), + Proposers: []string{addr2.String()}, + SubmittedAt: *curBlockTime, + GroupVersion: 1, + GroupAccountVersion: 1, + Result: group.ProposalResultUnfinalized, + Status: group.ProposalStatusSubmitted, + ExecutorResult: group.ProposalExecutorResultNotRun, + Timeout: gogotypes.Timestamp{ + Seconds: 600, + }, + VoteState: group.Tally{ + YesCount: "0", + NoCount: "1", + AbstainCount: "0", + VetoCount: "0", + }, }, }, expErr: true, }, "current block abstain vote count must be greater than previous block abstain vote count": { - prevReq: &group.Proposal{ - GroupAccount: addr1.String(), - Proposers: []string{addr1.String()}, - SubmittedAt: *prevBlockTime, - GroupVersion: 1, - GroupAccountVersion: 1, - Result: group.ProposalResultUnfinalized, - Status: group.ProposalStatusSubmitted, - ExecutorResult: group.ProposalExecutorResultNotRun, - Timeout: gogotypes.Timestamp{ - Seconds: 600, - }, - VoteState: group.Tally{ - YesCount: "0", - NoCount: "0", - AbstainCount: "2", - VetoCount: "0", + prevReq: []*group.Proposal{ + { + GroupAccount: addr1.String(), + Proposers: []string{addr1.String()}, + SubmittedAt: *prevBlockTime, + GroupVersion: 1, + GroupAccountVersion: 1, + Result: group.ProposalResultUnfinalized, + Status: group.ProposalStatusSubmitted, + ExecutorResult: group.ProposalExecutorResultNotRun, + Timeout: gogotypes.Timestamp{ + Seconds: 600, + }, + VoteState: group.Tally{ + YesCount: "0", + NoCount: "0", + AbstainCount: "2", + VetoCount: "0", + }, }, }, - curReq: &group.Proposal{ - GroupAccount: addr2.String(), - Proposers: []string{addr2.String()}, - SubmittedAt: *curBlockTime, - GroupVersion: 1, - GroupAccountVersion: 1, - Result: group.ProposalResultUnfinalized, - Status: group.ProposalStatusSubmitted, - ExecutorResult: group.ProposalExecutorResultNotRun, - Timeout: gogotypes.Timestamp{ - Seconds: 600, - }, - VoteState: group.Tally{ - YesCount: "0", - NoCount: "0", - AbstainCount: "1", - VetoCount: "0", + curReq: []*group.Proposal{ + { + GroupAccount: addr2.String(), + Proposers: []string{addr2.String()}, + SubmittedAt: *curBlockTime, + GroupVersion: 1, + GroupAccountVersion: 1, + Result: group.ProposalResultUnfinalized, + Status: group.ProposalStatusSubmitted, + ExecutorResult: group.ProposalExecutorResultNotRun, + Timeout: gogotypes.Timestamp{ + Seconds: 600, + }, + VoteState: group.Tally{ + YesCount: "0", + NoCount: "0", + AbstainCount: "1", + VetoCount: "0", + }, }, }, expErr: true, }, "current block veto vote count must be greater than previous block veto vote count": { - prevReq: &group.Proposal{ - GroupAccount: addr1.String(), - Proposers: []string{addr1.String()}, - SubmittedAt: *prevBlockTime, - GroupVersion: 1, - GroupAccountVersion: 1, - Result: group.ProposalResultUnfinalized, - Status: group.ProposalStatusSubmitted, - ExecutorResult: group.ProposalExecutorResultNotRun, - Timeout: gogotypes.Timestamp{ - Seconds: 600, - }, - VoteState: group.Tally{ - YesCount: "0", - NoCount: "0", - AbstainCount: "0", - VetoCount: "2", + prevReq: []*group.Proposal{ + { + GroupAccount: addr1.String(), + Proposers: []string{addr1.String()}, + SubmittedAt: *prevBlockTime, + GroupVersion: 1, + GroupAccountVersion: 1, + Result: group.ProposalResultUnfinalized, + Status: group.ProposalStatusSubmitted, + ExecutorResult: group.ProposalExecutorResultNotRun, + Timeout: gogotypes.Timestamp{ + Seconds: 600, + }, + VoteState: group.Tally{ + YesCount: "0", + NoCount: "0", + AbstainCount: "0", + VetoCount: "2", + }, }, }, - curReq: &group.Proposal{ - GroupAccount: addr2.String(), - Proposers: []string{addr2.String()}, - SubmittedAt: *curBlockTime, - GroupVersion: 1, - GroupAccountVersion: 1, - Result: group.ProposalResultUnfinalized, - Status: group.ProposalStatusSubmitted, - ExecutorResult: group.ProposalExecutorResultNotRun, - Timeout: gogotypes.Timestamp{ - Seconds: 600, - }, - VoteState: group.Tally{ - YesCount: "0", - NoCount: "0", - AbstainCount: "0", - VetoCount: "1", + curReq: []*group.Proposal{ + { + GroupAccount: addr2.String(), + Proposers: []string{addr2.String()}, + SubmittedAt: *curBlockTime, + GroupVersion: 1, + GroupAccountVersion: 1, + Result: group.ProposalResultUnfinalized, + Status: group.ProposalStatusSubmitted, + ExecutorResult: group.ProposalExecutorResultNotRun, + Timeout: gogotypes.Timestamp{ + Seconds: 600, + }, + VoteState: group.Tally{ + YesCount: "0", + NoCount: "0", + AbstainCount: "0", + VetoCount: "1", + }, }, }, expErr: true, }, } + for _, spec := range specs { - spec := spec - prevProposal := spec.prevReq - curProposal := spec.curReq - _, err = proposalTable.Create(prevCtx, prevProposal) - if err != nil { - fmt.Println(err) - panic("create proposal") - } + prevProposals := spec.prevReq + curProposals := spec.curReq - _, err = proposalTable.Create(curCtx, curProposal) - if err != nil { - fmt.Println(err) - panic("create proposal") + for i := 0; i < len(prevProposals) && i < len(curProposals); i++ { + _, err = proposalTable.Create(prevCtx, prevProposals[i]) + if err != nil { + fmt.Println(err) + panic("create proposal") + } + _, err = proposalTable.Create(curCtx, curProposals[i]) + if err != nil { + fmt.Println(err) + panic("create proposal") + } } var test require.TestingT From 5e4754e481de196abc4b5057bd6c8cbcb23fabfd Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 30 Mar 2021 16:18:44 +0530 Subject: [PATCH 66/96] update stable_appconfig --- app/stable_appconfig.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/stable_appconfig.go b/app/stable_appconfig.go index 22f3dc260e..34ab3d3c95 100644 --- a/app/stable_appconfig.go +++ b/app/stable_appconfig.go @@ -3,10 +3,6 @@ package app import ( -<<<<<<< HEAD -======= ->>>>>>> a38ebdb2463e1f76953727deb5c38ec44adf6660 - "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" @@ -19,7 +15,6 @@ import ( paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" - servermodule "github.com/regen-network/regen-ledger/types/module/server" "github.com/regen-network/regen-ledger/types/module/server" ) From 89227a09815f1f6de373b21b030f7e422843e00d Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 30 Mar 2021 16:47:02 +0530 Subject: [PATCH 67/96] change GroupAccount filed to Address --- x/group/server/invariants_test.go | 160 ++++++++++-------------------- 1 file changed, 50 insertions(+), 110 deletions(-) diff --git a/x/group/server/invariants_test.go b/x/group/server/invariants_test.go index 2585c53120..2a850cb71a 100644 --- a/x/group/server/invariants_test.go +++ b/x/group/server/invariants_test.go @@ -60,89 +60,65 @@ func TestTallyVotesInvariant(t *testing.T) { "invariant not broken": { prevReq: []*group.Proposal{ { - GroupAccount: addr1.String(), + ProposalId: 0, + Address: addr1.String(), Proposers: []string{addr1.String()}, SubmittedAt: *prevBlockTime, GroupVersion: 1, GroupAccountVersion: 1, - Result: group.ProposalResultUnfinalized, Status: group.ProposalStatusSubmitted, + Result: group.ProposalResultUnfinalized, + VoteState: group.Tally{YesCount: "1", NoCount: "0", AbstainCount: "0", VetoCount: "0"}, + Timeout: gogotypes.Timestamp{Seconds: 600}, ExecutorResult: group.ProposalExecutorResultNotRun, - Timeout: gogotypes.Timestamp{ - Seconds: 600, - }, - VoteState: group.Tally{ - YesCount: "1", - NoCount: "0", - AbstainCount: "0", - VetoCount: "0", - }, }, }, curReq: []*group.Proposal{ { - GroupAccount: addr2.String(), + ProposalId: 0, + Address: addr2.String(), Proposers: []string{addr2.String()}, SubmittedAt: *curBlockTime, GroupVersion: 1, GroupAccountVersion: 1, - Result: group.ProposalResultUnfinalized, Status: group.ProposalStatusSubmitted, + Result: group.ProposalResultUnfinalized, + VoteState: group.Tally{YesCount: "2", NoCount: "0", AbstainCount: "0", VetoCount: "0"}, + Timeout: gogotypes.Timestamp{Seconds: 600}, ExecutorResult: group.ProposalExecutorResultNotRun, - Timeout: gogotypes.Timestamp{ - Seconds: 600, - }, - VoteState: group.Tally{ - YesCount: "2", - NoCount: "0", - AbstainCount: "0", - VetoCount: "0", - }, }, }, }, "current block yes vote count must be greater than previous block yes vote count": { prevReq: []*group.Proposal{ { - GroupAccount: addr1.String(), + ProposalId: 0, + Address: addr1.String(), Proposers: []string{addr1.String()}, SubmittedAt: *prevBlockTime, GroupVersion: 1, GroupAccountVersion: 1, - Result: group.ProposalResultUnfinalized, Status: group.ProposalStatusSubmitted, + Result: group.ProposalResultUnfinalized, + VoteState: group.Tally{YesCount: "2", NoCount: "0", AbstainCount: "0", VetoCount: "0"}, + Timeout: gogotypes.Timestamp{Seconds: 600}, ExecutorResult: group.ProposalExecutorResultNotRun, - Timeout: gogotypes.Timestamp{ - Seconds: 600, - }, - VoteState: group.Tally{ - YesCount: "2", - NoCount: "0", - AbstainCount: "0", - VetoCount: "0", - }, }, }, curReq: []*group.Proposal{ { - GroupAccount: addr2.String(), + ProposalId: 0, + Address: addr2.String(), Proposers: []string{addr2.String()}, SubmittedAt: *curBlockTime, GroupVersion: 1, GroupAccountVersion: 1, - Result: group.ProposalResultUnfinalized, Status: group.ProposalStatusSubmitted, + Result: group.ProposalResultUnfinalized, + VoteState: group.Tally{YesCount: "1", NoCount: "0", AbstainCount: "0", VetoCount: "0"}, + Timeout: gogotypes.Timestamp{Seconds: 600}, ExecutorResult: group.ProposalExecutorResultNotRun, - Timeout: gogotypes.Timestamp{ - Seconds: 600, - }, - VoteState: group.Tally{ - YesCount: "1", - NoCount: "0", - AbstainCount: "0", - VetoCount: "0", - }, }, }, expErr: true, @@ -150,44 +126,32 @@ func TestTallyVotesInvariant(t *testing.T) { "current block no vote count must be greater than previous block no vote count": { prevReq: []*group.Proposal{ { - GroupAccount: addr1.String(), + ProposalId: 0, + Address: addr1.String(), Proposers: []string{addr1.String()}, SubmittedAt: *prevBlockTime, GroupVersion: 1, GroupAccountVersion: 1, - Result: group.ProposalResultUnfinalized, Status: group.ProposalStatusSubmitted, + Result: group.ProposalResultUnfinalized, + VoteState: group.Tally{YesCount: "0", NoCount: "2", AbstainCount: "0", VetoCount: "0"}, + Timeout: gogotypes.Timestamp{Seconds: 600}, ExecutorResult: group.ProposalExecutorResultNotRun, - Timeout: gogotypes.Timestamp{ - Seconds: 600, - }, - VoteState: group.Tally{ - YesCount: "0", - NoCount: "2", - AbstainCount: "0", - VetoCount: "0", - }, }, }, curReq: []*group.Proposal{ { - GroupAccount: addr2.String(), + ProposalId: 0, + Address: addr2.String(), Proposers: []string{addr2.String()}, SubmittedAt: *curBlockTime, GroupVersion: 1, GroupAccountVersion: 1, - Result: group.ProposalResultUnfinalized, Status: group.ProposalStatusSubmitted, + Result: group.ProposalResultUnfinalized, + VoteState: group.Tally{YesCount: "0", NoCount: "1", AbstainCount: "0", VetoCount: "0"}, + Timeout: gogotypes.Timestamp{Seconds: 600}, ExecutorResult: group.ProposalExecutorResultNotRun, - Timeout: gogotypes.Timestamp{ - Seconds: 600, - }, - VoteState: group.Tally{ - YesCount: "0", - NoCount: "1", - AbstainCount: "0", - VetoCount: "0", - }, }, }, expErr: true, @@ -195,44 +159,32 @@ func TestTallyVotesInvariant(t *testing.T) { "current block abstain vote count must be greater than previous block abstain vote count": { prevReq: []*group.Proposal{ { - GroupAccount: addr1.String(), + ProposalId: 0, + Address: addr1.String(), Proposers: []string{addr1.String()}, SubmittedAt: *prevBlockTime, GroupVersion: 1, GroupAccountVersion: 1, - Result: group.ProposalResultUnfinalized, Status: group.ProposalStatusSubmitted, + Result: group.ProposalResultUnfinalized, + VoteState: group.Tally{YesCount: "0", NoCount: "0", AbstainCount: "2", VetoCount: "0"}, + Timeout: gogotypes.Timestamp{Seconds: 600}, ExecutorResult: group.ProposalExecutorResultNotRun, - Timeout: gogotypes.Timestamp{ - Seconds: 600, - }, - VoteState: group.Tally{ - YesCount: "0", - NoCount: "0", - AbstainCount: "2", - VetoCount: "0", - }, }, }, curReq: []*group.Proposal{ { - GroupAccount: addr2.String(), + ProposalId: 0, + Address: addr2.String(), Proposers: []string{addr2.String()}, SubmittedAt: *curBlockTime, GroupVersion: 1, GroupAccountVersion: 1, - Result: group.ProposalResultUnfinalized, Status: group.ProposalStatusSubmitted, + Result: group.ProposalResultUnfinalized, + VoteState: group.Tally{YesCount: "0", NoCount: "0", AbstainCount: "1", VetoCount: "0"}, + Timeout: gogotypes.Timestamp{Seconds: 600}, ExecutorResult: group.ProposalExecutorResultNotRun, - Timeout: gogotypes.Timestamp{ - Seconds: 600, - }, - VoteState: group.Tally{ - YesCount: "0", - NoCount: "0", - AbstainCount: "1", - VetoCount: "0", - }, }, }, expErr: true, @@ -240,44 +192,32 @@ func TestTallyVotesInvariant(t *testing.T) { "current block veto vote count must be greater than previous block veto vote count": { prevReq: []*group.Proposal{ { - GroupAccount: addr1.String(), + ProposalId: 0, + Address: addr1.String(), Proposers: []string{addr1.String()}, SubmittedAt: *prevBlockTime, GroupVersion: 1, GroupAccountVersion: 1, - Result: group.ProposalResultUnfinalized, Status: group.ProposalStatusSubmitted, + Result: group.ProposalResultUnfinalized, + VoteState: group.Tally{YesCount: "0", NoCount: "0", AbstainCount: "0", VetoCount: "2"}, + Timeout: gogotypes.Timestamp{Seconds: 600}, ExecutorResult: group.ProposalExecutorResultNotRun, - Timeout: gogotypes.Timestamp{ - Seconds: 600, - }, - VoteState: group.Tally{ - YesCount: "0", - NoCount: "0", - AbstainCount: "0", - VetoCount: "2", - }, }, }, curReq: []*group.Proposal{ { - GroupAccount: addr2.String(), + ProposalId: 0, + Address: addr2.String(), Proposers: []string{addr2.String()}, SubmittedAt: *curBlockTime, GroupVersion: 1, GroupAccountVersion: 1, - Result: group.ProposalResultUnfinalized, Status: group.ProposalStatusSubmitted, + Result: group.ProposalResultUnfinalized, + VoteState: group.Tally{YesCount: "0", NoCount: "0", AbstainCount: "0", VetoCount: "1"}, + Timeout: gogotypes.Timestamp{Seconds: 600}, ExecutorResult: group.ProposalExecutorResultNotRun, - Timeout: gogotypes.Timestamp{ - Seconds: 600, - }, - VoteState: group.Tally{ - YesCount: "0", - NoCount: "0", - AbstainCount: "0", - VetoCount: "1", - }, }, }, expErr: true, From 42dcecf791cefcee081ffae33fb0cb435f939abe Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 30 Mar 2021 17:31:14 +0530 Subject: [PATCH 68/96] address changes --- x/group/server/invariants.go | 38 +++++++++++++------------------ x/group/server/invariants_test.go | 29 +++++------------------ 2 files changed, 22 insertions(+), 45 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 9374467cf5..b9f3ad74d3 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -4,7 +4,6 @@ import ( "math" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" "github.com/regen-network/regen-ledger/orm" "github.com/regen-network/regen-ledger/x/group" @@ -39,62 +38,57 @@ func tallyVotesInvariant(ctx sdk.Context, proposalTable orm.AutoUInt64Table) (st prevIt, err := proposalTable.PrefixScan(prevCtx, 1, math.MaxUint64) if err != nil { - panic(err) + return err.Error(), true } curIt, err := proposalTable.PrefixScan(ctx, 1, math.MaxUint64) if err != nil { - panic(err) + return err.Error(), true } - var t require.TestingT var curProposals []*group.Proposal _, err = orm.ReadAll(curIt, &curProposals) - require.NoError(t, err, &curProposals) + if err != nil { + return err.Error(), true + } var prevProposals []*group.Proposal _, err = orm.ReadAll(prevIt, &prevProposals) - require.NoError(t, err, &curProposals) + if err != nil { + return err.Error(), true + } for i := 0; i < len(prevProposals) && i < len(curProposals); i++ { prevYesCount, err := prevProposals[i].VoteState.GetYesCount() if err != nil { - broken = true - msg = err.Error() + return err.Error(), true } curYesCount, err := curProposals[i].VoteState.GetYesCount() if err != nil { - broken = true - msg = err.Error() + return err.Error(), true } prevNoCount, err := prevProposals[i].VoteState.GetNoCount() if err != nil { - broken = true - msg = err.Error() + return err.Error(), true } curNoCount, err := curProposals[i].VoteState.GetNoCount() if err != nil { - broken = true - msg = err.Error() + return err.Error(), true } prevAbstainCount, err := prevProposals[i].VoteState.GetAbstainCount() if err != nil { - broken = true - msg = err.Error() + return err.Error(), true } curAbstainCount, err := curProposals[i].VoteState.GetAbstainCount() if err != nil { - broken = true - msg = err.Error() + return err.Error(), true } prevVetoCount, err := prevProposals[i].VoteState.GetVetoCount() if err != nil { - broken = true - msg = err.Error() + return err.Error(), true } curVetoCount, err := curProposals[i].VoteState.GetVetoCount() if err != nil { - broken = true - msg = err.Error() + return err.Error(), true } if (curYesCount.Cmp(prevYesCount) == -1) || (curNoCount.Cmp(prevNoCount) == -1) || (curAbstainCount.Cmp(prevAbstainCount) == -1) || (curVetoCount.Cmp(prevVetoCount) == -1) { broken = true diff --git a/x/group/server/invariants_test.go b/x/group/server/invariants_test.go index 2a850cb71a..670dae1341 100644 --- a/x/group/server/invariants_test.go +++ b/x/group/server/invariants_test.go @@ -1,7 +1,6 @@ package server import ( - "fmt" "testing" "github.com/cosmos/cosmos-sdk/codec" @@ -27,9 +26,7 @@ func TestTallyVotesInvariant(t *testing.T) { cms := store.NewCommitMultiStore(db) cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db) err := cms.LoadLatestVersion() - if err != nil { - panic(err) - } + require.NoError(t, err) curCtx := sdk.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger()) curCtx = curCtx.WithBlockHeight(10) prevCtx := curCtx.WithBlockHeight(curCtx.BlockHeight() - 1) @@ -42,15 +39,9 @@ func TestTallyVotesInvariant(t *testing.T) { _, _, addr2 := testdata.KeyTestPubAddr() curBlockTime, err := gogotypes.TimestampProto(curCtx.BlockTime()) - if err != nil { - fmt.Println("block time conversion") - panic(err) - } + require.NoError(t, err) prevBlockTime, err := gogotypes.TimestampProto(prevCtx.BlockTime()) - if err != nil { - fmt.Println("block time conversion") - panic(err) - } + require.NoError(t, err) specs := map[string]struct { prevReq []*group.Proposal @@ -231,19 +222,11 @@ func TestTallyVotesInvariant(t *testing.T) { for i := 0; i < len(prevProposals) && i < len(curProposals); i++ { _, err = proposalTable.Create(prevCtx, prevProposals[i]) - if err != nil { - fmt.Println(err) - panic("create proposal") - } + require.NoError(t, err) _, err = proposalTable.Create(curCtx, curProposals[i]) - if err != nil { - fmt.Println(err) - panic("create proposal") - } + require.NoError(t, err) } - - var test require.TestingT _, broken := tallyVotesInvariant(curCtx, proposalTable) - require.Equal(test, spec.expErr, broken) + require.Equal(t, spec.expErr, broken) } } From d7806b16d00e224b488cd693db5dbb7f26ffe380 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 30 Mar 2021 18:08:13 +0530 Subject: [PATCH 69/96] Update with CacheContext --- x/group/server/invariants.go | 14 +++++++------- x/group/server/invariants_test.go | 13 ++++++++----- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index b9f3ad74d3..c53eec4e9a 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -21,21 +21,21 @@ func (s serverImpl) AllInvariants() sdk.Invariant { func (s serverImpl) tallyVotesInvariant() sdk.Invariant { return func(ctx sdk.Context) (string, bool) { - msg, broken := tallyVotesInvariant(ctx, s.proposalTable) + if ctx.BlockHeight()-1 < 0 { + return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "Not enough blocks to perform TallyVotesInvariant"), false + } + prevCtx, _ := ctx.CacheContext() + prevCtx = prevCtx.WithBlockHeight(ctx.BlockHeight() - 1) + msg, broken := tallyVotesInvariant(ctx, prevCtx, s.proposalTable) return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", msg), broken } } -func tallyVotesInvariant(ctx sdk.Context, proposalTable orm.AutoUInt64Table) (string, bool) { +func tallyVotesInvariant(ctx sdk.Context, prevCtx sdk.Context, proposalTable orm.AutoUInt64Table) (string, bool) { var msg string var broken bool - if ctx.BlockHeight()-1 < 0 { - return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "Not enough blocks to perform TallyVotesInvariant"), false - } - prevCtx := ctx.WithBlockHeight(ctx.BlockHeight() - 1) - prevIt, err := proposalTable.PrefixScan(prevCtx, 1, math.MaxUint64) if err != nil { return err.Error(), true diff --git a/x/group/server/invariants_test.go b/x/group/server/invariants_test.go index 670dae1341..1789168bba 100644 --- a/x/group/server/invariants_test.go +++ b/x/group/server/invariants_test.go @@ -29,8 +29,8 @@ func TestTallyVotesInvariant(t *testing.T) { require.NoError(t, err) curCtx := sdk.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger()) curCtx = curCtx.WithBlockHeight(10) - prevCtx := curCtx.WithBlockHeight(curCtx.BlockHeight() - 1) - + prevCtx, _ := curCtx.CacheContext() + prevCtx = prevCtx.WithBlockHeight(curCtx.BlockHeight() - 1) // Proposal Table proposalTableBuilder := orm.NewAutoUInt64TableBuilder(ProposalTablePrefix, ProposalTableSeqPrefix, key, &group.Proposal{}, cdc) proposalTable := proposalTableBuilder.Build() @@ -220,13 +220,16 @@ func TestTallyVotesInvariant(t *testing.T) { prevProposals := spec.prevReq curProposals := spec.curReq + cachePrevCtx, _ := prevCtx.CacheContext() + cacheCurCtx, _ := curCtx.CacheContext() + for i := 0; i < len(prevProposals) && i < len(curProposals); i++ { - _, err = proposalTable.Create(prevCtx, prevProposals[i]) + _, err = proposalTable.Create(cachePrevCtx, prevProposals[i]) require.NoError(t, err) - _, err = proposalTable.Create(curCtx, curProposals[i]) + _, err = proposalTable.Create(cacheCurCtx, curProposals[i]) require.NoError(t, err) } - _, broken := tallyVotesInvariant(curCtx, proposalTable) + _, broken := tallyVotesInvariant(cacheCurCtx, cachePrevCtx, proposalTable) require.Equal(t, spec.expErr, broken) } } From 9ba140482df8d92a1cda5667d992326bb875e854 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Wed, 31 Mar 2021 12:26:23 +0530 Subject: [PATCH 70/96] remove unnecessary code --- app/stable_appconfig.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/stable_appconfig.go b/app/stable_appconfig.go index 34ab3d3c95..7c042ce8a1 100644 --- a/app/stable_appconfig.go +++ b/app/stable_appconfig.go @@ -27,10 +27,6 @@ func setCustomModuleBasics() []module.AppModuleBasic { } } -// func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry) *servermodule.Manager { -// return &servermodule.Manager{} -// } - // setCustomModules registers new modules with the server module manager. // It does nothing here and returns an empty manager since we're not using experimental mode. func setCustomModules(_ *RegenApp, _ types.InterfaceRegistry) *server.Manager { From c8c69be732da408110045465cc4011b5374493c1 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Wed, 31 Mar 2021 14:25:32 +0530 Subject: [PATCH 71/96] resolve requested changes --- app/experimental_appconfig.go | 1 - types/module/server/manager.go | 1 + x/group/server/invariants.go | 60 +++++++++++++++++++++++-------- x/group/server/invariants_test.go | 2 +- 4 files changed, 47 insertions(+), 17 deletions(-) diff --git a/app/experimental_appconfig.go b/app/experimental_appconfig.go index fd90d025ac..6a8b622810 100644 --- a/app/experimental_appconfig.go +++ b/app/experimental_appconfig.go @@ -72,7 +72,6 @@ func (app *RegenApp) setCustomKeeprs(bApp *baseapp.BaseApp, keys map[string]*sdk govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.wasmKeeper, wasm.EnableAllProposals)) } -// func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry) *servermodule.Manager { // setCustomModules registers new modules with the server module manager. func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry) *server.Manager { diff --git a/types/module/server/manager.go b/types/module/server/manager.go index 53c3013f5e..c384be6c62 100644 --- a/types/module/server/manager.go +++ b/types/module/server/manager.go @@ -250,6 +250,7 @@ func (c *configurator) QueryServer() gogogrpc.Server { func (c *configurator) RegisterInvariantsHandler(registry RegisterInvariantsHandler) { c.registerInvariantsHandler = registry } + func (c *configurator) RegisterGenesisHandlers(initGenesisHandler module.InitGenesisHandler, exportGenesisHandler module.ExportGenesisHandler) { c.initGenesisHandler = initGenesisHandler c.exportGenesisHandler = exportGenesisHandler diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index c53eec4e9a..394aba3f1b 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -1,6 +1,7 @@ package server import ( + "fmt" "math" sdk "github.com/cosmos/cosmos-sdk/types" @@ -26,74 +27,103 @@ func (s serverImpl) tallyVotesInvariant() sdk.Invariant { } prevCtx, _ := ctx.CacheContext() prevCtx = prevCtx.WithBlockHeight(ctx.BlockHeight() - 1) - msg, broken := tallyVotesInvariant(ctx, prevCtx, s.proposalTable) + msg, broken, err := tallyVotesInvariant(ctx, prevCtx, s.proposalTable) + if err != nil { + panic(err) + } return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", msg), broken } } -func tallyVotesInvariant(ctx sdk.Context, prevCtx sdk.Context, proposalTable orm.AutoUInt64Table) (string, bool) { +func tallyVotesInvariant(ctx sdk.Context, prevCtx sdk.Context, proposalTable orm.AutoUInt64Table) (string, bool, error) { var msg string var broken bool prevIt, err := proposalTable.PrefixScan(prevCtx, 1, math.MaxUint64) if err != nil { - return err.Error(), true + msg = err.Error() + broken = true + return msg, broken, err } curIt, err := proposalTable.PrefixScan(ctx, 1, math.MaxUint64) if err != nil { - return err.Error(), true + msg = err.Error() + broken = true + return msg, broken, err } var curProposals []*group.Proposal _, err = orm.ReadAll(curIt, &curProposals) if err != nil { - return err.Error(), true + msg = err.Error() + broken = true + return msg, broken, err } var prevProposals []*group.Proposal _, err = orm.ReadAll(prevIt, &prevProposals) if err != nil { - return err.Error(), true + msg = err.Error() + broken = true + return msg, broken, err } for i := 0; i < len(prevProposals) && i < len(curProposals); i++ { prevYesCount, err := prevProposals[i].VoteState.GetYesCount() if err != nil { - return err.Error(), true + msg = err.Error() + broken = true + return msg, broken, err } curYesCount, err := curProposals[i].VoteState.GetYesCount() if err != nil { - return err.Error(), true + msg = err.Error() + broken = true + return msg, broken, err } prevNoCount, err := prevProposals[i].VoteState.GetNoCount() if err != nil { - return err.Error(), true + msg = err.Error() + broken = true + return msg, broken, err } curNoCount, err := curProposals[i].VoteState.GetNoCount() if err != nil { - return err.Error(), true + msg = err.Error() + broken = true + return msg, broken, err } prevAbstainCount, err := prevProposals[i].VoteState.GetAbstainCount() if err != nil { - return err.Error(), true + msg = err.Error() + broken = true + return msg, broken, err } curAbstainCount, err := curProposals[i].VoteState.GetAbstainCount() if err != nil { - return err.Error(), true + msg = err.Error() + broken = true + return msg, broken, err } prevVetoCount, err := prevProposals[i].VoteState.GetVetoCount() if err != nil { - return err.Error(), true + msg = err.Error() + broken = true + return msg, broken, err } curVetoCount, err := curProposals[i].VoteState.GetVetoCount() if err != nil { - return err.Error(), true + msg = err.Error() + broken = true + return msg, broken, err } if (curYesCount.Cmp(prevYesCount) == -1) || (curNoCount.Cmp(prevNoCount) == -1) || (curAbstainCount.Cmp(prevAbstainCount) == -1) || (curVetoCount.Cmp(prevVetoCount) == -1) { broken = true msg += "vote tally sums must never have less than the block before\n" + err = fmt.Errorf(msg) + return msg, broken, err } } - return msg, broken + return msg, broken, err } diff --git a/x/group/server/invariants_test.go b/x/group/server/invariants_test.go index 1789168bba..ac250b959a 100644 --- a/x/group/server/invariants_test.go +++ b/x/group/server/invariants_test.go @@ -229,7 +229,7 @@ func TestTallyVotesInvariant(t *testing.T) { _, err = proposalTable.Create(cacheCurCtx, curProposals[i]) require.NoError(t, err) } - _, broken := tallyVotesInvariant(cacheCurCtx, cachePrevCtx, proposalTable) + _, broken, _ := tallyVotesInvariant(cacheCurCtx, cachePrevCtx, proposalTable) require.Equal(t, spec.expErr, broken) } } From 71b1d8936b9c24a863e408d835d980980a7ec512 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Wed, 31 Mar 2021 22:09:57 +0530 Subject: [PATCH 72/96] remove redundant return in experimental_appconfig --- app/experimental_appconfig.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/experimental_appconfig.go b/app/experimental_appconfig.go index 6a8b622810..e5958336a6 100644 --- a/app/experimental_appconfig.go +++ b/app/experimental_appconfig.go @@ -99,8 +99,6 @@ func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry) return newModuleManager /* New Module Wiring END */ - - return newModuleManager } func (app *RegenApp) registerUpgradeHandlers() { From df3e7f47c99ae29bf957163231b28e7dd601bb9b Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 1 Apr 2021 16:33:39 +0530 Subject: [PATCH 73/96] address requested changes --- app/app.go | 7 ------- types/module/server/manager.go | 6 +++--- x/group/server/invariants.go | 26 -------------------------- 3 files changed, 3 insertions(+), 36 deletions(-) diff --git a/app/app.go b/app/app.go index 206e7d397d..b7c3f5fccd 100644 --- a/app/app.go +++ b/app/app.go @@ -178,12 +178,6 @@ type RegenApp struct { // simulation manager sm *module.SimulationManager - // new module manager - // XXX We will likely want to make this new manager compatible - // with module.Manager so that we can have existing cosmos-sdk modules - // use ADR 33 approach without the need for removing their keepers - // and a larger refactoring. - // nm *servermodule.Manager // server module manager // NOTE: We will likely want to make this new manager compatible // with module.Manager so that we can have existing cosmos-sdk modules @@ -325,7 +319,6 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest // register experimental modules here app.smm = setCustomModules(app, interfaceRegistry) app.smm.RegisterInvariants(&app.CrisisKeeper) - // app.smm = setCustomModules(app, interfaceRegistry) var skipGenesisInvariants = cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants)) diff --git a/types/module/server/manager.go b/types/module/server/manager.go index c384be6c62..d01dab3e47 100644 --- a/types/module/server/manager.go +++ b/types/module/server/manager.go @@ -30,9 +30,9 @@ type Manager struct { // RegisterInvariants registers all module routes and module querier routes func (mm *Manager) RegisterInvariants(ir sdk.InvariantRegistry) { - for _, moduleName := range mm.registerInvariantsHandler { - if moduleName != nil { - moduleName(ir) + for _, invariant := range mm.registerInvariantsHandler { + if invariant != nil { + invariant(ir) } } } diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 394aba3f1b..15cca04ea3 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -1,7 +1,6 @@ package server import ( - "fmt" "math" sdk "github.com/cosmos/cosmos-sdk/types" @@ -42,86 +41,61 @@ func tallyVotesInvariant(ctx sdk.Context, prevCtx sdk.Context, proposalTable orm prevIt, err := proposalTable.PrefixScan(prevCtx, 1, math.MaxUint64) if err != nil { - msg = err.Error() - broken = true return msg, broken, err } curIt, err := proposalTable.PrefixScan(ctx, 1, math.MaxUint64) if err != nil { - msg = err.Error() - broken = true return msg, broken, err } var curProposals []*group.Proposal _, err = orm.ReadAll(curIt, &curProposals) if err != nil { - msg = err.Error() - broken = true return msg, broken, err } var prevProposals []*group.Proposal _, err = orm.ReadAll(prevIt, &prevProposals) if err != nil { - msg = err.Error() - broken = true return msg, broken, err } for i := 0; i < len(prevProposals) && i < len(curProposals); i++ { prevYesCount, err := prevProposals[i].VoteState.GetYesCount() if err != nil { - msg = err.Error() - broken = true return msg, broken, err } curYesCount, err := curProposals[i].VoteState.GetYesCount() if err != nil { - msg = err.Error() - broken = true return msg, broken, err } prevNoCount, err := prevProposals[i].VoteState.GetNoCount() if err != nil { - msg = err.Error() - broken = true return msg, broken, err } curNoCount, err := curProposals[i].VoteState.GetNoCount() if err != nil { - msg = err.Error() - broken = true return msg, broken, err } prevAbstainCount, err := prevProposals[i].VoteState.GetAbstainCount() if err != nil { - msg = err.Error() - broken = true return msg, broken, err } curAbstainCount, err := curProposals[i].VoteState.GetAbstainCount() if err != nil { - msg = err.Error() - broken = true return msg, broken, err } prevVetoCount, err := prevProposals[i].VoteState.GetVetoCount() if err != nil { - msg = err.Error() - broken = true return msg, broken, err } curVetoCount, err := curProposals[i].VoteState.GetVetoCount() if err != nil { - msg = err.Error() - broken = true return msg, broken, err } if (curYesCount.Cmp(prevYesCount) == -1) || (curNoCount.Cmp(prevNoCount) == -1) || (curAbstainCount.Cmp(prevAbstainCount) == -1) || (curVetoCount.Cmp(prevVetoCount) == -1) { broken = true msg += "vote tally sums must never have less than the block before\n" - err = fmt.Errorf(msg) return msg, broken, err } } From be7952c8c1d39c13076e2373880aa2898646fa5e Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 1 Apr 2021 16:47:20 +0530 Subject: [PATCH 74/96] remove AllInvariants function --- x/group/server/invariants.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 15cca04ea3..56a69fae5e 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -13,12 +13,6 @@ func (s serverImpl) RegisterInvariants(ir sdk.InvariantRegistry) { ir.RegisterRoute(group.ModuleName, "Tally-Votes", s.tallyVotesInvariant()) } -func (s serverImpl) AllInvariants() sdk.Invariant { - return func(ctx sdk.Context) (string, bool) { - return s.tallyVotesInvariant()(ctx) - } -} - func (s serverImpl) tallyVotesInvariant() sdk.Invariant { return func(ctx sdk.Context) (string, bool) { if ctx.BlockHeight()-1 < 0 { From 7ef6cb57dafb484447aebe0cbe4d28ccb52c0399 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 2 Apr 2021 12:13:23 +0530 Subject: [PATCH 75/96] changes to invariant --- x/group/server/invariants.go | 80 +++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 56a69fae5e..4f4f0ed183 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -9,8 +9,10 @@ import ( "github.com/regen-network/regen-ledger/x/group" ) +const votesInvariant = "Tally-Votes" + func (s serverImpl) RegisterInvariants(ir sdk.InvariantRegistry) { - ir.RegisterRoute(group.ModuleName, "Tally-Votes", s.tallyVotesInvariant()) + ir.RegisterRoute(group.ModuleName, votesInvariant, s.tallyVotesInvariant()) } func (s serverImpl) tallyVotesInvariant() sdk.Invariant { @@ -54,43 +56,45 @@ func tallyVotesInvariant(ctx sdk.Context, prevCtx sdk.Context, proposalTable orm return msg, broken, err } - for i := 0; i < len(prevProposals) && i < len(curProposals); i++ { - prevYesCount, err := prevProposals[i].VoteState.GetYesCount() - if err != nil { - return msg, broken, err - } - curYesCount, err := curProposals[i].VoteState.GetYesCount() - if err != nil { - return msg, broken, err - } - prevNoCount, err := prevProposals[i].VoteState.GetNoCount() - if err != nil { - return msg, broken, err - } - curNoCount, err := curProposals[i].VoteState.GetNoCount() - if err != nil { - return msg, broken, err - } - prevAbstainCount, err := prevProposals[i].VoteState.GetAbstainCount() - if err != nil { - return msg, broken, err - } - curAbstainCount, err := curProposals[i].VoteState.GetAbstainCount() - if err != nil { - return msg, broken, err - } - prevVetoCount, err := prevProposals[i].VoteState.GetVetoCount() - if err != nil { - return msg, broken, err - } - curVetoCount, err := curProposals[i].VoteState.GetVetoCount() - if err != nil { - return msg, broken, err - } - if (curYesCount.Cmp(prevYesCount) == -1) || (curNoCount.Cmp(prevNoCount) == -1) || (curAbstainCount.Cmp(prevAbstainCount) == -1) || (curVetoCount.Cmp(prevVetoCount) == -1) { - broken = true - msg += "vote tally sums must never have less than the block before\n" - return msg, broken, err + for i := 0; i < len(prevProposals); i++ { + if prevProposals[i].ProposalId == curProposals[i].ProposalId { + prevYesCount, err := prevProposals[i].VoteState.GetYesCount() + if err != nil { + return msg, broken, err + } + curYesCount, err := curProposals[i].VoteState.GetYesCount() + if err != nil { + return msg, broken, err + } + prevNoCount, err := prevProposals[i].VoteState.GetNoCount() + if err != nil { + return msg, broken, err + } + curNoCount, err := curProposals[i].VoteState.GetNoCount() + if err != nil { + return msg, broken, err + } + prevAbstainCount, err := prevProposals[i].VoteState.GetAbstainCount() + if err != nil { + return msg, broken, err + } + curAbstainCount, err := curProposals[i].VoteState.GetAbstainCount() + if err != nil { + return msg, broken, err + } + prevVetoCount, err := prevProposals[i].VoteState.GetVetoCount() + if err != nil { + return msg, broken, err + } + curVetoCount, err := curProposals[i].VoteState.GetVetoCount() + if err != nil { + return msg, broken, err + } + if (curYesCount.Cmp(prevYesCount) == -1) || (curNoCount.Cmp(prevNoCount) == -1) || (curAbstainCount.Cmp(prevAbstainCount) == -1) || (curVetoCount.Cmp(prevVetoCount) == -1) { + broken = true + msg += "vote tally sums must never have less than the block before\n" + return msg, broken, err + } } } return msg, broken, err From 97c8c7c67b4dcaf9bf6cf4b5b62965632b9ef9a2 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 2 Apr 2021 12:24:14 +0530 Subject: [PATCH 76/96] remove unncessary changes --- Makefile | 1 + x/data/server/testsuite/suite.go | 96 ++++++++++++++++---------------- 2 files changed, 49 insertions(+), 48 deletions(-) diff --git a/Makefile b/Makefile index b14d8d8f58..fd75bdc2fb 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ DOCKER_BUF := docker run -v $(shell pwd):/workspace --workdir /workspace bufbuil export GO111MODULE = on # process build tags + build_tags = netgo ifeq ($(EXPERIMENTAL),true) diff --git a/x/data/server/testsuite/suite.go b/x/data/server/testsuite/suite.go index f957404090..8f2bfad70d 100644 --- a/x/data/server/testsuite/suite.go +++ b/x/data/server/testsuite/suite.go @@ -42,66 +42,66 @@ func (s *IntegrationTestSuite) TearDownSuite() { } func (s *IntegrationTestSuite) TestScenario() { - // testContent := []byte("xyzabc123") - // mh, err := multihash.Sum(testContent, multihash.SHA2_256, -1) - // s.Require().NoError(err) - // cid := gocid.NewCidV1(gocid.Raw, mh) + //testContent := []byte("xyzabc123") + //mh, err := multihash.Sum(testContent, multihash.SHA2_256, -1) + //s.Require().NoError(err) + //cid := gocid.NewCidV1(gocid.Raw, mh) // //// anchor some data - // cidBz := cid.Bytes() - // anchorRes, err := s.msgClient.AnchorData(s.ctx, &data.MsgAnchorDataRequest{ + //cidBz := cid.Bytes() + //anchorRes, err := s.msgClient.AnchorData(s.ctx, &data.MsgAnchorDataRequest{ // Sender: s.addr1.String(), // Cid: cidBz, //}) - // s.Require().NoError(err) - // s.Require().NotNil(anchorRes) + //s.Require().NoError(err) + //s.Require().NotNil(anchorRes) // //// can't anchor same data twice //_, err = s.msgClient.AnchorData(s.ctx, &data.MsgAnchorDataRequest{ // Sender: s.addr1.String(), // Cid: cidBz, //}) - // s.Require().Error(err) + //s.Require().Error(err) // //// can query data and get timestamp - // queryRes, err := s.queryClient.ByCid(s.ctx, &data.QueryByCidRequest{Cid: cidBz}) - // s.Require().NoError(err) - // s.Require().NotNil(queryRes) - // s.Require().Equal(anchorRes.Timestamp, queryRes.Timestamp) - // s.Require().Empty(queryRes.Signers) - // s.Require().Empty(queryRes.Content) + //queryRes, err := s.queryClient.ByCid(s.ctx, &data.QueryByCidRequest{Cid: cidBz}) + //s.Require().NoError(err) + //s.Require().NotNil(queryRes) + //s.Require().Equal(anchorRes.Timestamp, queryRes.Timestamp) + //s.Require().Empty(queryRes.Signers) + //s.Require().Empty(queryRes.Content) // //// can sign data //_, err = s.msgClient.SignData(s.ctx, &data.MsgSignDataRequest{ // Signers: []string{s.addr1.String()}, // Cid: cidBz, //}) - // s.Require().NoError(err) + //s.Require().NoError(err) // //// can retrieve signature, same timestamp //// can query data and get timestamp - // queryRes, err = s.queryClient.ByCid(s.ctx, &data.QueryByCidRequest{Cid: cidBz}) - // s.Require().NoError(err) - // s.Require().NotNil(queryRes) - // s.Require().Equal(anchorRes.Timestamp, queryRes.Timestamp) - // s.Require().Equal([]string{s.addr1.String()}, queryRes.Signers) - // s.Require().Empty(queryRes.Content) + //queryRes, err = s.queryClient.ByCid(s.ctx, &data.QueryByCidRequest{Cid: cidBz}) + //s.Require().NoError(err) + //s.Require().NotNil(queryRes) + //s.Require().Equal(anchorRes.Timestamp, queryRes.Timestamp) + //s.Require().Equal([]string{s.addr1.String()}, queryRes.Signers) + //s.Require().Empty(queryRes.Content) // //// query data by signer - // bySignerRes, err := s.queryClient.BySigner(s.ctx, &data.QueryBySignerRequest{ + //bySignerRes, err := s.queryClient.BySigner(s.ctx, &data.QueryBySignerRequest{ // Signer: s.addr1.String(), //}) - // s.Require().NoError(err) - // s.Require().NotNil(bySignerRes) - // s.Require().Contains(bySignerRes.Cids, cidBz) + //s.Require().NoError(err) + //s.Require().NotNil(bySignerRes) + //s.Require().Contains(bySignerRes.Cids, cidBz) // //// can't store bad data - // _, err = s.msgClient.StoreData(s.ctx, &data.MsgStoreDataRequest{ + //_, err = s.msgClient.StoreData(s.ctx, &data.MsgStoreDataRequest{ // Sender: s.addr1.String(), // Cid: cidBz, // Content: []byte("sgkjhsgouiyh"), //}) - // s.Require().Error(err) + //s.Require().Error(err) // //// can store good data //_, err = s.msgClient.StoreData(s.ctx, &data.MsgStoreDataRequest{ @@ -109,38 +109,38 @@ func (s *IntegrationTestSuite) TestScenario() { // Cid: cidBz, // Content: testContent, //}) - // s.Require().NoError(err) + //s.Require().NoError(err) // //// can retrieve signature, same timestamp, and data - // queryRes, err = s.queryClient.ByCid(s.ctx, &data.QueryByCidRequest{Cid: cidBz}) - // s.Require().NoError(err) - // s.Require().NotNil(queryRes) - // s.Require().Equal(anchorRes.Timestamp, queryRes.Timestamp) - // s.Require().Equal([]string{s.addr1.String()}, queryRes.Signers) - // s.Require().Equal(testContent, queryRes.Content) + //queryRes, err = s.queryClient.ByCid(s.ctx, &data.QueryByCidRequest{Cid: cidBz}) + //s.Require().NoError(err) + //s.Require().NotNil(queryRes) + //s.Require().Equal(anchorRes.Timestamp, queryRes.Timestamp) + //s.Require().Equal([]string{s.addr1.String()}, queryRes.Signers) + //s.Require().Equal(testContent, queryRes.Content) // //// another signer can sign //_, err = s.msgClient.SignData(s.ctx, &data.MsgSignDataRequest{ // Signers: []string{s.addr2.String()}, // Cid: cidBz, //}) - // s.Require().NoError(err) + //s.Require().NoError(err) // //// query data by signer - // bySignerRes, err = s.queryClient.BySigner(s.ctx, &data.QueryBySignerRequest{ + //bySignerRes, err = s.queryClient.BySigner(s.ctx, &data.QueryBySignerRequest{ // Signer: s.addr2.String(), //}) - // s.Require().NoError(err) - // s.Require().NotNil(bySignerRes) - // s.Require().Contains(bySignerRes.Cids, cidBz) + //s.Require().NoError(err) + //s.Require().NotNil(bySignerRes) + //s.Require().Contains(bySignerRes.Cids, cidBz) // //// query all data and both signatures - // queryRes, err = s.queryClient.ByCid(s.ctx, &data.QueryByCidRequest{Cid: cidBz}) - // s.Require().NoError(err) - // s.Require().NotNil(queryRes) - // s.Require().Equal(anchorRes.Timestamp, queryRes.Timestamp) - // s.Require().Len(queryRes.Signers, 2) - // s.Require().Contains(queryRes.Signers, s.addr1.String()) - // s.Require().Contains(queryRes.Signers, s.addr2.String()) - // s.Require().Equal(testContent, queryRes.Content) + //queryRes, err = s.queryClient.ByCid(s.ctx, &data.QueryByCidRequest{Cid: cidBz}) + //s.Require().NoError(err) + //s.Require().NotNil(queryRes) + //s.Require().Equal(anchorRes.Timestamp, queryRes.Timestamp) + //s.Require().Len(queryRes.Signers, 2) + //s.Require().Contains(queryRes.Signers, s.addr1.String()) + //s.Require().Contains(queryRes.Signers, s.addr2.String()) + //s.Require().Equal(testContent, queryRes.Content) } From 15ce9a99c75e8567ebb35d1c3a20d0a8f928d5bd Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 2 Apr 2021 12:44:46 +0530 Subject: [PATCH 77/96] add votesInvariant const --- x/group/server/invariants.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 4f4f0ed183..36c22341bd 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -9,7 +9,9 @@ import ( "github.com/regen-network/regen-ledger/x/group" ) -const votesInvariant = "Tally-Votes" +const ( + votesInvariant = "Tally-Votes" +) func (s serverImpl) RegisterInvariants(ir sdk.InvariantRegistry) { ir.RegisterRoute(group.ModuleName, votesInvariant, s.tallyVotesInvariant()) @@ -18,7 +20,7 @@ func (s serverImpl) RegisterInvariants(ir sdk.InvariantRegistry) { func (s serverImpl) tallyVotesInvariant() sdk.Invariant { return func(ctx sdk.Context) (string, bool) { if ctx.BlockHeight()-1 < 0 { - return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", "Not enough blocks to perform TallyVotesInvariant"), false + return sdk.FormatInvariant(group.ModuleName, votesInvariant, "Not enough blocks to perform TallyVotesInvariant"), false } prevCtx, _ := ctx.CacheContext() prevCtx = prevCtx.WithBlockHeight(ctx.BlockHeight() - 1) @@ -26,7 +28,7 @@ func (s serverImpl) tallyVotesInvariant() sdk.Invariant { if err != nil { panic(err) } - return sdk.FormatInvariant(group.ModuleName, "Tally-Votes", msg), broken + return sdk.FormatInvariant(group.ModuleName, votesInvariant, msg), broken } } From 084c33bbb531dfa99af7d040b6ef9c743b79fb16 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Sat, 3 Apr 2021 11:03:59 +0530 Subject: [PATCH 78/96] add tallyTotalWeightInvariant --- x/group/server/invariants.go | 75 ++++++++++++++++++++- x/group/server/invariants_test.go | 104 ++++++++++++++++++++++++++++++ 2 files changed, 178 insertions(+), 1 deletion(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 36c22341bd..04f080ccd7 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -2,19 +2,24 @@ package server import ( "math" + "strconv" + "github.com/cockroachdb/apd/v2" sdk "github.com/cosmos/cosmos-sdk/types" + regenMath "github.com/regen-network/regen-ledger/math" "github.com/regen-network/regen-ledger/orm" "github.com/regen-network/regen-ledger/x/group" ) const ( - votesInvariant = "Tally-Votes" + votesInvariant = "Tally-Votes" + weightInvariant = "Tally-TotalWeight" ) func (s serverImpl) RegisterInvariants(ir sdk.InvariantRegistry) { ir.RegisterRoute(group.ModuleName, votesInvariant, s.tallyVotesInvariant()) + ir.RegisterRoute(group.ModuleName, weightInvariant, s.tallyTotalWeightInvariant()) } func (s serverImpl) tallyVotesInvariant() sdk.Invariant { @@ -32,6 +37,19 @@ func (s serverImpl) tallyVotesInvariant() sdk.Invariant { } } +func (s serverImpl) tallyTotalWeightInvariant() sdk.Invariant { + return func(ctx sdk.Context) (string, bool) { + if ctx.BlockHeight() < 0 { + return sdk.FormatInvariant(group.ModuleName, weightInvariant, "Not enough blocks to perform TallyVotesInvariant"), false + } + msg, broken, err := tallyTotalWeightInvariant(ctx, s.groupTable, s.groupMemberTable) + if err != nil { + panic(err) + } + return sdk.FormatInvariant(group.ModuleName, weightInvariant, msg), broken + } +} + func tallyVotesInvariant(ctx sdk.Context, prevCtx sdk.Context, proposalTable orm.AutoUInt64Table) (string, bool, error) { var msg string @@ -101,3 +119,58 @@ func tallyVotesInvariant(ctx sdk.Context, prevCtx sdk.Context, proposalTable orm } return msg, broken, err } + +func tallyTotalWeightInvariant(ctx sdk.Context, groupTable orm.Table, groupMemberTable orm.PrimaryKeyTable) (string, bool, error) { + + var msg string + var broken bool + + var groupInfo []*group.GroupInfo + + groupIt, err := groupTable.PrefixScan(ctx, nil, nil) + if err != nil { + return msg, broken, err + } + _, err = orm.ReadAll(groupIt, &groupInfo) + if err != nil { + return msg, broken, err + } + + var members []*group.GroupMember + + memberIt, err := groupMemberTable.PrefixScan(ctx, nil, nil) + if err != nil { + return msg, broken, err + } + _, err = orm.ReadAll(memberIt, &members) + if err != nil { + return msg, broken, err + } + + var sum int64 + + for i := 0; i < len(groupInfo); i++ { + + sum = 0 + for j := 0; j < len(members); j++ { + if groupInfo[i].GroupId == members[j].GroupId { + MemWeight, err := strconv.ParseInt(members[j].GetMember().Weight, 10, 64) + if err != nil { + return msg, broken, err + } + sum = sum + MemWeight + } + } + totalWeight, err := regenMath.ParsePositiveDecimal(groupInfo[i].GetTotalWeight()) + if err != nil { + return msg, broken, err + } + memSum := apd.New(sum, 0) + if (totalWeight.Cmp(memSum) == 1) || (totalWeight.Cmp(memSum) == -1) { + broken = true + msg += "group's TotalWeight must be equal to the sum of its members' weights\n" + break + } + } + return msg, broken, err +} diff --git a/x/group/server/invariants_test.go b/x/group/server/invariants_test.go index ac250b959a..e697de12f9 100644 --- a/x/group/server/invariants_test.go +++ b/x/group/server/invariants_test.go @@ -233,3 +233,107 @@ func TestTallyVotesInvariant(t *testing.T) { require.Equal(t, spec.expErr, broken) } } + +func TestTallyTotalWeightInvariant(t *testing.T) { + interfaceRegistry := types.NewInterfaceRegistry() + cdc := codec.NewProtoCodec(interfaceRegistry) + key := sdk.NewKVStoreKey(group.ModuleName) + db := dbm.NewMemDB() + cms := store.NewCommitMultiStore(db) + cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db) + err := cms.LoadLatestVersion() + require.NoError(t, err) + curCtx := sdk.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger()) + curCtx = curCtx.WithBlockHeight(10) + // Group Table + groupTableBuilder := orm.NewTableBuilder(GroupTablePrefix, key, &group.GroupInfo{}, orm.FixLengthIndexKeys(orm.EncodedSeqLength), cdc) + groupTable := groupTableBuilder.Build() + + // Members Table + groupMemberTableBuilder := orm.NewPrimaryKeyTableBuilder(GroupMemberTablePrefix, key, &group.GroupMember{}, orm.Max255DynamicLengthIndexKeyCodec{}, cdc) + groupMemberTable := groupMemberTableBuilder.Build() + + _, _, addr1 := testdata.KeyTestPubAddr() + _, _, addr2 := testdata.KeyTestPubAddr() + + specs := map[string]struct { + groupReq []*group.GroupInfo + membersReq []*group.GroupMember + expErr bool + }{ + "invariant not broken": { + groupReq: []*group.GroupInfo{ + { + GroupId: 1, + Admin: addr1.String(), + Version: 1, + TotalWeight: "3", + }, + }, + membersReq: []*group.GroupMember{ + { + GroupId: 1, + Member: &group.Member{ + Address: addr1.String(), + Weight: "1", + }, + }, + { + GroupId: 1, + Member: &group.Member{ + Address: addr2.String(), + Weight: "2", + }, + }, + }, + expErr: false, + }, + + "group's TotalWeight must be equal to sum of its members weight ": { + groupReq: []*group.GroupInfo{ + { + GroupId: 1, + Admin: addr1.String(), + Version: 1, + TotalWeight: "3", + }, + }, + membersReq: []*group.GroupMember{ + { + GroupId: 1, + Member: &group.Member{ + Address: addr1.String(), + Weight: "2", + }, + }, + { + GroupId: 1, + Member: &group.Member{ + Address: addr2.String(), + Weight: "2", + }, + }, + }, + expErr: true, + }, + } + + for _, spec := range specs { + cacheCurCtx, _ := curCtx.CacheContext() + groupReq := spec.groupReq + members := spec.membersReq + + for i := 0; i < len(groupReq); i++ { + err := groupTable.Create(cacheCurCtx, group.ID(groupReq[i].GroupId).Bytes(), groupReq[i]) + require.NoError(t, err) + } + + for i := 0; i < len(members); i++ { + err := groupMemberTable.Create(cacheCurCtx, members[i]) + require.NoError(t, err) + } + + _, broken, _ := tallyTotalWeightInvariant(cacheCurCtx, groupTable, groupMemberTable) + require.Equal(t, spec.expErr, broken) + } +} From b340653533d30f40ec7a58f65263fe2c36048bf4 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Sat, 3 Apr 2021 11:15:02 +0530 Subject: [PATCH 79/96] change naming conventions in tallyTotalWeightInvariant --- x/group/server/invariants.go | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 04f080ccd7..a2013609a9 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -136,37 +136,35 @@ func tallyTotalWeightInvariant(ctx sdk.Context, groupTable orm.Table, groupMembe return msg, broken, err } - var members []*group.GroupMember + var groupMembers []*group.GroupMember memberIt, err := groupMemberTable.PrefixScan(ctx, nil, nil) if err != nil { return msg, broken, err } - _, err = orm.ReadAll(memberIt, &members) + _, err = orm.ReadAll(memberIt, &groupMembers) if err != nil { return msg, broken, err } - var sum int64 - + var membersWeight int64 for i := 0; i < len(groupInfo); i++ { - - sum = 0 - for j := 0; j < len(members); j++ { - if groupInfo[i].GroupId == members[j].GroupId { - MemWeight, err := strconv.ParseInt(members[j].GetMember().Weight, 10, 64) + membersWeight = 0 + for j := 0; j < len(groupMembers); j++ { + if groupInfo[i].GroupId == groupMembers[j].GroupId { + curMemWeight, err := strconv.ParseInt(groupMembers[j].GetMember().Weight, 10, 64) if err != nil { return msg, broken, err } - sum = sum + MemWeight + membersWeight = membersWeight + curMemWeight } } - totalWeight, err := regenMath.ParsePositiveDecimal(groupInfo[i].GetTotalWeight()) + groupWeight, err := regenMath.ParsePositiveDecimal(groupInfo[i].GetTotalWeight()) if err != nil { return msg, broken, err } - memSum := apd.New(sum, 0) - if (totalWeight.Cmp(memSum) == 1) || (totalWeight.Cmp(memSum) == -1) { + totalMembersWeight := apd.New(membersWeight, 0) + if (groupWeight.Cmp(totalMembersWeight) == 1) || (groupWeight.Cmp(totalMembersWeight) == -1) { broken = true msg += "group's TotalWeight must be equal to the sum of its members' weights\n" break From a2df03e125a27f3ef8e29ecc16a7b0bf6c62de9c Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Sat, 3 Apr 2021 11:18:17 +0530 Subject: [PATCH 80/96] fix lint issues --- x/group/server/invariants.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index a2013609a9..8887c30728 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -156,7 +156,7 @@ func tallyTotalWeightInvariant(ctx sdk.Context, groupTable orm.Table, groupMembe if err != nil { return msg, broken, err } - membersWeight = membersWeight + curMemWeight + membersWeight += curMemWeight } } groupWeight, err := regenMath.ParsePositiveDecimal(groupInfo[i].GetTotalWeight()) From 8bbd8e4f082962226fcb59148b4c40c04dff43ae Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Mon, 5 Apr 2021 13:28:32 +0530 Subject: [PATCH 81/96] fix something --- x/group/server/invariants.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 8887c30728..32a47895c8 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -159,7 +159,7 @@ func tallyTotalWeightInvariant(ctx sdk.Context, groupTable orm.Table, groupMembe membersWeight += curMemWeight } } - groupWeight, err := regenMath.ParsePositiveDecimal(groupInfo[i].GetTotalWeight()) + groupWeight, err := regenMath.ParseNonNegativeDecimal(groupInfo[i].GetTotalWeight()) if err != nil { return msg, broken, err } From 622565da7109f4c3f195a8b6298410d1ad4f6f1e Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 8 Apr 2021 15:57:30 +0530 Subject: [PATCH 82/96] change naming conventions and add improvements to invariants --- x/group/server/invariants.go | 36 +++++++++++++------------------ x/group/server/invariants_test.go | 8 +++++-- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 32a47895c8..42a6784eb9 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -2,7 +2,6 @@ package server import ( "math" - "strconv" "github.com/cockroachdb/apd/v2" sdk "github.com/cosmos/cosmos-sdk/types" @@ -14,12 +13,12 @@ import ( const ( votesInvariant = "Tally-Votes" - weightInvariant = "Tally-TotalWeight" + weightInvariant = "Group-TotalWeight" ) func (s serverImpl) RegisterInvariants(ir sdk.InvariantRegistry) { ir.RegisterRoute(group.ModuleName, votesInvariant, s.tallyVotesInvariant()) - ir.RegisterRoute(group.ModuleName, weightInvariant, s.tallyTotalWeightInvariant()) + ir.RegisterRoute(group.ModuleName, weightInvariant, s.groupTotalWeightInvariant()) } func (s serverImpl) tallyVotesInvariant() sdk.Invariant { @@ -37,12 +36,9 @@ func (s serverImpl) tallyVotesInvariant() sdk.Invariant { } } -func (s serverImpl) tallyTotalWeightInvariant() sdk.Invariant { +func (s serverImpl) groupTotalWeightInvariant() sdk.Invariant { return func(ctx sdk.Context) (string, bool) { - if ctx.BlockHeight() < 0 { - return sdk.FormatInvariant(group.ModuleName, weightInvariant, "Not enough blocks to perform TallyVotesInvariant"), false - } - msg, broken, err := tallyTotalWeightInvariant(ctx, s.groupTable, s.groupMemberTable) + msg, broken, err := groupTotalWeightInvariant(ctx, s.groupTable, s.groupMemberByGroupIndex) if err != nil { panic(err) } @@ -120,7 +116,7 @@ func tallyVotesInvariant(ctx sdk.Context, prevCtx sdk.Context, proposalTable orm return msg, broken, err } -func tallyTotalWeightInvariant(ctx sdk.Context, groupTable orm.Table, groupMemberTable orm.PrimaryKeyTable) (string, bool, error) { +func groupTotalWeightInvariant(ctx sdk.Context, groupTable orm.Table, groupMemberByGroupIndex orm.UInt64Index) (string, bool, error) { var msg string var broken bool @@ -136,35 +132,33 @@ func tallyTotalWeightInvariant(ctx sdk.Context, groupTable orm.Table, groupMembe return msg, broken, err } - var groupMembers []*group.GroupMember - - memberIt, err := groupMemberTable.PrefixScan(ctx, nil, nil) + var curGroupMembers []*group.GroupMember + memIt, err := groupMemberByGroupIndex.PrefixScan(ctx, 1, math.MaxUint64) if err != nil { return msg, broken, err } - _, err = orm.ReadAll(memberIt, &groupMembers) + _, err = orm.ReadAll(memIt, &curGroupMembers) if err != nil { return msg, broken, err } - var membersWeight int64 + var membersWeight *apd.Decimal + membersWeight = apd.New(0, 0) for i := 0; i < len(groupInfo); i++ { - membersWeight = 0 - for j := 0; j < len(groupMembers); j++ { - if groupInfo[i].GroupId == groupMembers[j].GroupId { - curMemWeight, err := strconv.ParseInt(groupMembers[j].GetMember().Weight, 10, 64) + for j := 0; j < len(curGroupMembers); j++ { + if groupInfo[i].GroupId == curGroupMembers[j].GroupId { + curMemWeight, err := regenMath.ParseNonNegativeDecimal(curGroupMembers[j].GetMember().GetWeight()) if err != nil { return msg, broken, err } - membersWeight += curMemWeight + regenMath.Add(membersWeight, membersWeight, curMemWeight) } } groupWeight, err := regenMath.ParseNonNegativeDecimal(groupInfo[i].GetTotalWeight()) if err != nil { return msg, broken, err } - totalMembersWeight := apd.New(membersWeight, 0) - if (groupWeight.Cmp(totalMembersWeight) == 1) || (groupWeight.Cmp(totalMembersWeight) == -1) { + if groupWeight.Cmp(membersWeight) != 0 { broken = true msg += "group's TotalWeight must be equal to the sum of its members' weights\n" break diff --git a/x/group/server/invariants_test.go b/x/group/server/invariants_test.go index e697de12f9..44a0f6054e 100644 --- a/x/group/server/invariants_test.go +++ b/x/group/server/invariants_test.go @@ -234,7 +234,7 @@ func TestTallyVotesInvariant(t *testing.T) { } } -func TestTallyTotalWeightInvariant(t *testing.T) { +func TestGroupTotalWeightInvariant(t *testing.T) { interfaceRegistry := types.NewInterfaceRegistry() cdc := codec.NewProtoCodec(interfaceRegistry) key := sdk.NewKVStoreKey(group.ModuleName) @@ -251,6 +251,10 @@ func TestTallyTotalWeightInvariant(t *testing.T) { // Members Table groupMemberTableBuilder := orm.NewPrimaryKeyTableBuilder(GroupMemberTablePrefix, key, &group.GroupMember{}, orm.Max255DynamicLengthIndexKeyCodec{}, cdc) + groupMemberByGroupIndex := orm.NewUInt64Index(groupMemberTableBuilder, GroupMemberByGroupIndexPrefix, func(val interface{}) ([]uint64, error) { + group := val.(*group.GroupMember).GroupId + return []uint64{group}, nil + }) groupMemberTable := groupMemberTableBuilder.Build() _, _, addr1 := testdata.KeyTestPubAddr() @@ -333,7 +337,7 @@ func TestTallyTotalWeightInvariant(t *testing.T) { require.NoError(t, err) } - _, broken, _ := tallyTotalWeightInvariant(cacheCurCtx, groupTable, groupMemberTable) + _, broken, _ := groupTotalWeightInvariant(cacheCurCtx, groupTable, groupMemberByGroupIndex) require.Equal(t, spec.expErr, broken) } } From c520fd6ef84f29e7f53a147b84b5cdf9d16eceea Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 8 Apr 2021 16:25:06 +0530 Subject: [PATCH 83/96] fix lint issue --- x/group/server/invariants.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 42a6784eb9..9dbdf3941a 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -151,7 +151,10 @@ func groupTotalWeightInvariant(ctx sdk.Context, groupTable orm.Table, groupMembe if err != nil { return msg, broken, err } - regenMath.Add(membersWeight, membersWeight, curMemWeight) + err = regenMath.Add(membersWeight, membersWeight, curMemWeight) + if err != nil { + return msg, broken, err + } } } groupWeight, err := regenMath.ParseNonNegativeDecimal(groupInfo[i].GetTotalWeight()) From 2da53554d1afd73cab0f951a53a51dca0614d97a Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 8 Apr 2021 16:35:32 +0530 Subject: [PATCH 84/96] fix lint issues --- x/group/server/invariants.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 9dbdf3941a..e42a21540a 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -142,8 +142,7 @@ func groupTotalWeightInvariant(ctx sdk.Context, groupTable orm.Table, groupMembe return msg, broken, err } - var membersWeight *apd.Decimal - membersWeight = apd.New(0, 0) + membersWeight := apd.New(0, 0) for i := 0; i < len(groupInfo); i++ { for j := 0; j < len(curGroupMembers); j++ { if groupInfo[i].GroupId == curGroupMembers[j].GroupId { From c29b9d1fe36fb5887f0c7c64e1ae421801a20f11 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 9 Apr 2021 01:43:18 +0530 Subject: [PATCH 85/96] changes in groupTotalWeightInvariant --- x/group/server/invariants.go | 35 ++++++++++++++++--------------- x/group/server/invariants_test.go | 4 +++- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index e42a21540a..4622871767 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -133,29 +133,30 @@ func groupTotalWeightInvariant(ctx sdk.Context, groupTable orm.Table, groupMembe } var curGroupMembers []*group.GroupMember - memIt, err := groupMemberByGroupIndex.PrefixScan(ctx, 1, math.MaxUint64) - if err != nil { - return msg, broken, err - } - _, err = orm.ReadAll(memIt, &curGroupMembers) - if err != nil { - return msg, broken, err - } membersWeight := apd.New(0, 0) + for i := 0; i < len(groupInfo); i++ { + memIt, err := groupMemberByGroupIndex.Get(ctx, groupInfo[i].GroupId) + if err != nil { + return msg, broken, err + } + _, err = orm.ReadAll(memIt, &curGroupMembers) + if err != nil { + return msg, broken, err + } + for j := 0; j < len(curGroupMembers); j++ { - if groupInfo[i].GroupId == curGroupMembers[j].GroupId { - curMemWeight, err := regenMath.ParseNonNegativeDecimal(curGroupMembers[j].GetMember().GetWeight()) - if err != nil { - return msg, broken, err - } - err = regenMath.Add(membersWeight, membersWeight, curMemWeight) - if err != nil { - return msg, broken, err - } + curMemWeight, err := regenMath.ParseNonNegativeDecimal(curGroupMembers[j].GetMember().GetWeight()) + if err != nil { + return msg, broken, err + } + err = regenMath.Add(membersWeight, membersWeight, curMemWeight) + if err != nil { + return msg, broken, err } } + groupWeight, err := regenMath.ParseNonNegativeDecimal(groupInfo[i].GetTotalWeight()) if err != nil { return msg, broken, err diff --git a/x/group/server/invariants_test.go b/x/group/server/invariants_test.go index 44a0f6054e..7cc7e7c229 100644 --- a/x/group/server/invariants_test.go +++ b/x/group/server/invariants_test.go @@ -31,6 +31,7 @@ func TestTallyVotesInvariant(t *testing.T) { curCtx = curCtx.WithBlockHeight(10) prevCtx, _ := curCtx.CacheContext() prevCtx = prevCtx.WithBlockHeight(curCtx.BlockHeight() - 1) + // Proposal Table proposalTableBuilder := orm.NewAutoUInt64TableBuilder(ProposalTablePrefix, ProposalTableSeqPrefix, key, &group.Proposal{}, cdc) proposalTable := proposalTableBuilder.Build() @@ -245,11 +246,12 @@ func TestGroupTotalWeightInvariant(t *testing.T) { require.NoError(t, err) curCtx := sdk.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger()) curCtx = curCtx.WithBlockHeight(10) + // Group Table groupTableBuilder := orm.NewTableBuilder(GroupTablePrefix, key, &group.GroupInfo{}, orm.FixLengthIndexKeys(orm.EncodedSeqLength), cdc) groupTable := groupTableBuilder.Build() - // Members Table + // Group Member Table groupMemberTableBuilder := orm.NewPrimaryKeyTableBuilder(GroupMemberTablePrefix, key, &group.GroupMember{}, orm.Max255DynamicLengthIndexKeyCodec{}, cdc) groupMemberByGroupIndex := orm.NewUInt64Index(groupMemberTableBuilder, GroupMemberByGroupIndexPrefix, func(val interface{}) ([]uint64, error) { group := val.(*group.GroupMember).GroupId From ead73124c29dd1a0515926572dec8c39334ef8de Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 9 Apr 2021 11:16:13 +0530 Subject: [PATCH 86/96] code refactoring in invariants_Test --- x/group/server/invariants_test.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/x/group/server/invariants_test.go b/x/group/server/invariants_test.go index 7cc7e7c229..a6ac9c4d96 100644 --- a/x/group/server/invariants_test.go +++ b/x/group/server/invariants_test.go @@ -18,7 +18,7 @@ import ( "github.com/regen-network/regen-ledger/x/group" ) -func TestTallyVotesInvariant(t *testing.T) { +func GetCtxCodecKey(t *testing.T) (sdk.Context, *codec.ProtoCodec, *sdk.KVStoreKey) { interfaceRegistry := types.NewInterfaceRegistry() cdc := codec.NewProtoCodec(interfaceRegistry) key := sdk.NewKVStoreKey(group.ModuleName) @@ -29,6 +29,11 @@ func TestTallyVotesInvariant(t *testing.T) { require.NoError(t, err) curCtx := sdk.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger()) curCtx = curCtx.WithBlockHeight(10) + return curCtx, cdc, key +} + +func TestTallyVotesInvariant(t *testing.T) { + curCtx, cdc, key := GetCtxCodecKey(t) prevCtx, _ := curCtx.CacheContext() prevCtx = prevCtx.WithBlockHeight(curCtx.BlockHeight() - 1) @@ -236,16 +241,7 @@ func TestTallyVotesInvariant(t *testing.T) { } func TestGroupTotalWeightInvariant(t *testing.T) { - interfaceRegistry := types.NewInterfaceRegistry() - cdc := codec.NewProtoCodec(interfaceRegistry) - key := sdk.NewKVStoreKey(group.ModuleName) - db := dbm.NewMemDB() - cms := store.NewCommitMultiStore(db) - cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db) - err := cms.LoadLatestVersion() - require.NoError(t, err) - curCtx := sdk.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger()) - curCtx = curCtx.WithBlockHeight(10) + curCtx, cdc, key := GetCtxCodecKey(t) // Group Table groupTableBuilder := orm.NewTableBuilder(GroupTablePrefix, key, &group.GroupInfo{}, orm.FixLengthIndexKeys(orm.EncodedSeqLength), cdc) From 4f1b50d39933b2cf9f0275d9785347011d9f0089 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 9 Apr 2021 11:31:29 +0530 Subject: [PATCH 87/96] changes in invariants_test --- x/group/server/invariants_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x/group/server/invariants_test.go b/x/group/server/invariants_test.go index a6ac9c4d96..bd573a8188 100644 --- a/x/group/server/invariants_test.go +++ b/x/group/server/invariants_test.go @@ -18,7 +18,7 @@ import ( "github.com/regen-network/regen-ledger/x/group" ) -func GetCtxCodecKey(t *testing.T) (sdk.Context, *codec.ProtoCodec, *sdk.KVStoreKey) { +func getCtxCodecKey(t *testing.T) (sdk.Context, *codec.ProtoCodec, *sdk.KVStoreKey) { interfaceRegistry := types.NewInterfaceRegistry() cdc := codec.NewProtoCodec(interfaceRegistry) key := sdk.NewKVStoreKey(group.ModuleName) @@ -33,7 +33,7 @@ func GetCtxCodecKey(t *testing.T) (sdk.Context, *codec.ProtoCodec, *sdk.KVStoreK } func TestTallyVotesInvariant(t *testing.T) { - curCtx, cdc, key := GetCtxCodecKey(t) + curCtx, cdc, key := getCtxCodecKey(t) prevCtx, _ := curCtx.CacheContext() prevCtx = prevCtx.WithBlockHeight(curCtx.BlockHeight() - 1) @@ -241,7 +241,7 @@ func TestTallyVotesInvariant(t *testing.T) { } func TestGroupTotalWeightInvariant(t *testing.T) { - curCtx, cdc, key := GetCtxCodecKey(t) + curCtx, cdc, key := getCtxCodecKey(t) // Group Table groupTableBuilder := orm.NewTableBuilder(GroupTablePrefix, key, &group.GroupInfo{}, orm.FixLengthIndexKeys(orm.EncodedSeqLength), cdc) From 55039180a1ef92de2b346fe02f9c23e2c2028a94 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Mon, 12 Apr 2021 13:07:19 +0530 Subject: [PATCH 88/96] remove ReadAll and add LoadNext in invariants --- x/group/server/invariants.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 4622871767..142ab5c098 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -132,22 +132,20 @@ func groupTotalWeightInvariant(ctx sdk.Context, groupTable orm.Table, groupMembe return msg, broken, err } - var curGroupMembers []*group.GroupMember + var groupMember group.GroupMember membersWeight := apd.New(0, 0) - for i := 0; i < len(groupInfo); i++ { memIt, err := groupMemberByGroupIndex.Get(ctx, groupInfo[i].GroupId) if err != nil { return msg, broken, err } - _, err = orm.ReadAll(memIt, &curGroupMembers) - if err != nil { - return msg, broken, err - } - - for j := 0; j < len(curGroupMembers); j++ { - curMemWeight, err := regenMath.ParseNonNegativeDecimal(curGroupMembers[j].GetMember().GetWeight()) + for { + _, err = memIt.LoadNext(&groupMember) + if err != nil { + break + } + curMemWeight, err := regenMath.ParseNonNegativeDecimal(groupMember.GetMember().GetWeight()) if err != nil { return msg, broken, err } @@ -156,7 +154,6 @@ func groupTotalWeightInvariant(ctx sdk.Context, groupTable orm.Table, groupMembe return msg, broken, err } } - groupWeight, err := regenMath.ParseNonNegativeDecimal(groupInfo[i].GetTotalWeight()) if err != nil { return msg, broken, err From d8316dfb71d6739575fff4e182f5f715376767a7 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Mon, 12 Apr 2021 13:14:28 +0530 Subject: [PATCH 89/96] close iterator --- x/group/server/invariants.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 142ab5c098..3bac0d5bc1 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -137,6 +137,7 @@ func groupTotalWeightInvariant(ctx sdk.Context, groupTable orm.Table, groupMembe membersWeight := apd.New(0, 0) for i := 0; i < len(groupInfo); i++ { memIt, err := groupMemberByGroupIndex.Get(ctx, groupInfo[i].GroupId) + defer memIt.Close() if err != nil { return msg, broken, err } From 6d4af8201515a64284f98831c2cc6d4f5d7ad953 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Mon, 12 Apr 2021 13:17:26 +0530 Subject: [PATCH 90/96] fix lint issues --- x/group/server/invariants.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 3bac0d5bc1..853e9ad11f 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -137,10 +137,10 @@ func groupTotalWeightInvariant(ctx sdk.Context, groupTable orm.Table, groupMembe membersWeight := apd.New(0, 0) for i := 0; i < len(groupInfo); i++ { memIt, err := groupMemberByGroupIndex.Get(ctx, groupInfo[i].GroupId) - defer memIt.Close() if err != nil { return msg, broken, err } + defer memIt.Close() for { _, err = memIt.LoadNext(&groupMember) if err != nil { From 51c239d0cbff6d883e2c15ced7abf4cad618709b Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Wed, 14 Apr 2021 09:52:43 +0530 Subject: [PATCH 91/96] changes to invariants --- x/group/server/invariants.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 853e9ad11f..9515e3b19e 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -143,16 +143,17 @@ func groupTotalWeightInvariant(ctx sdk.Context, groupTable orm.Table, groupMembe defer memIt.Close() for { _, err = memIt.LoadNext(&groupMember) - if err != nil { + if orm.ErrIteratorDone.Is(err) { break - } - curMemWeight, err := regenMath.ParseNonNegativeDecimal(groupMember.GetMember().GetWeight()) - if err != nil { - return msg, broken, err - } - err = regenMath.Add(membersWeight, membersWeight, curMemWeight) - if err != nil { - return msg, broken, err + } else { + curMemWeight, err := regenMath.ParseNonNegativeDecimal(groupMember.GetMember().GetWeight()) + if err != nil { + return msg, broken, err + } + err = regenMath.Add(membersWeight, membersWeight, curMemWeight) + if err != nil { + return msg, broken, err + } } } groupWeight, err := regenMath.ParseNonNegativeDecimal(groupInfo[i].GetTotalWeight()) From ee43a7040dc15e95bc6617be0d1e0c4eea4adab6 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Wed, 14 Apr 2021 14:47:12 +0530 Subject: [PATCH 92/96] use groupIt with LoadNext --- x/group/server/invariants.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 9515e3b19e..e11c3676cb 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -121,22 +121,23 @@ func groupTotalWeightInvariant(ctx sdk.Context, groupTable orm.Table, groupMembe var msg string var broken bool - var groupInfo []*group.GroupInfo + var groupInfo group.GroupInfo groupIt, err := groupTable.PrefixScan(ctx, nil, nil) if err != nil { return msg, broken, err } - _, err = orm.ReadAll(groupIt, &groupInfo) - if err != nil { - return msg, broken, err - } var groupMember group.GroupMember membersWeight := apd.New(0, 0) - for i := 0; i < len(groupInfo); i++ { - memIt, err := groupMemberByGroupIndex.Get(ctx, groupInfo[i].GroupId) + + for { + _, err := groupIt.LoadNext(&groupInfo) + if orm.ErrIteratorDone.Is(err) { + break + } + memIt, err := groupMemberByGroupIndex.Get(ctx, groupInfo.GroupId) if err != nil { return msg, broken, err } @@ -156,7 +157,7 @@ func groupTotalWeightInvariant(ctx sdk.Context, groupTable orm.Table, groupMembe } } } - groupWeight, err := regenMath.ParseNonNegativeDecimal(groupInfo[i].GetTotalWeight()) + groupWeight, err := regenMath.ParseNonNegativeDecimal(groupInfo.GetTotalWeight()) if err != nil { return msg, broken, err } From 9f009950104e8009e6de105f9bd7ec449755ef0a Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Wed, 14 Apr 2021 14:54:53 +0530 Subject: [PATCH 93/96] remove unecessary lines --- x/group/server/invariants.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index e11c3676cb..83bffb16f3 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -146,15 +146,14 @@ func groupTotalWeightInvariant(ctx sdk.Context, groupTable orm.Table, groupMembe _, err = memIt.LoadNext(&groupMember) if orm.ErrIteratorDone.Is(err) { break - } else { - curMemWeight, err := regenMath.ParseNonNegativeDecimal(groupMember.GetMember().GetWeight()) - if err != nil { - return msg, broken, err - } - err = regenMath.Add(membersWeight, membersWeight, curMemWeight) - if err != nil { - return msg, broken, err - } + } + curMemWeight, err := regenMath.ParseNonNegativeDecimal(groupMember.GetMember().GetWeight()) + if err != nil { + return msg, broken, err + } + err = regenMath.Add(membersWeight, membersWeight, curMemWeight) + if err != nil { + return msg, broken, err } } groupWeight, err := regenMath.ParseNonNegativeDecimal(groupInfo.GetTotalWeight()) From 51dcff57c28c952a607bf2587611a84dacdea8a5 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 15 Apr 2021 15:24:26 +0530 Subject: [PATCH 94/96] refactoring code --- x/group/server/invariants.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 83bffb16f3..9a3b4c1165 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -122,13 +122,13 @@ func groupTotalWeightInvariant(ctx sdk.Context, groupTable orm.Table, groupMembe var broken bool var groupInfo group.GroupInfo + var groupMember group.GroupMember groupIt, err := groupTable.PrefixScan(ctx, nil, nil) if err != nil { return msg, broken, err } - - var groupMember group.GroupMember + defer groupIt.Close() membersWeight := apd.New(0, 0) From 32bd9e454dc363000ae912bb253db3edc2c8380b Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 15 Apr 2021 22:08:54 +0530 Subject: [PATCH 95/96] refactor code --- x/group/server/invariants.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index 9a3b4c1165..e7182f7725 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -125,10 +125,10 @@ func groupTotalWeightInvariant(ctx sdk.Context, groupTable orm.Table, groupMembe var groupMember group.GroupMember groupIt, err := groupTable.PrefixScan(ctx, nil, nil) + defer groupIt.Close() if err != nil { return msg, broken, err } - defer groupIt.Close() membersWeight := apd.New(0, 0) @@ -138,10 +138,11 @@ func groupTotalWeightInvariant(ctx sdk.Context, groupTable orm.Table, groupMembe break } memIt, err := groupMemberByGroupIndex.Get(ctx, groupInfo.GroupId) + defer memIt.Close() if err != nil { return msg, broken, err } - defer memIt.Close() + for { _, err = memIt.LoadNext(&groupMember) if orm.ErrIteratorDone.Is(err) { From 5878b585a09dfd1a4e98089121f8aee9a7511574 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 15 Apr 2021 22:17:44 +0530 Subject: [PATCH 96/96] fix lint issues --- x/group/server/invariants.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/group/server/invariants.go b/x/group/server/invariants.go index e7182f7725..53c3019f64 100644 --- a/x/group/server/invariants.go +++ b/x/group/server/invariants.go @@ -125,10 +125,10 @@ func groupTotalWeightInvariant(ctx sdk.Context, groupTable orm.Table, groupMembe var groupMember group.GroupMember groupIt, err := groupTable.PrefixScan(ctx, nil, nil) - defer groupIt.Close() if err != nil { return msg, broken, err } + defer groupIt.Close() membersWeight := apd.New(0, 0) @@ -138,10 +138,10 @@ func groupTotalWeightInvariant(ctx sdk.Context, groupTable orm.Table, groupMembe break } memIt, err := groupMemberByGroupIndex.Get(ctx, groupInfo.GroupId) - defer memIt.Close() if err != nil { return msg, broken, err } + defer memIt.Close() for { _, err = memIt.LoadNext(&groupMember)