Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add genesis support for new modules and group genesis #270

Merged
merged 31 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1186a40
Add basic support for genesis with new modules wip
blushi Feb 18, 2021
e9545d5
cleanup
blushi Feb 18, 2021
62a608e
Add genesis proto definition
blushi Feb 18, 2021
9d8c24f
Update manager
blushi Feb 19, 2021
f5235e3
Wire up in/export genesis at app level
blushi Feb 19, 2021
2a57c87
Add init/export group genesis
blushi Mar 3, 2021
51d4e8f
Fix seqs
blushi Mar 3, 2021
16b28c4
Merge branch 'master' into marie/214-group-genesis
blushi Mar 3, 2021
fdc91ae
Fix typo
blushi Mar 3, 2021
28331ee
Use testdata with auto uint64 table in orm test
blushi Mar 3, 2021
0b3edc3
Lint
blushi Mar 3, 2021
0e2168b
Rename cfg RegisterGenesisHandlers
blushi Mar 4, 2021
d8e71e3
Merge branch 'master' into marie/214-group-genesis
blushi Mar 11, 2021
cbd6d5b
Only keep relevant code in NotPanics
blushi Mar 17, 2021
ba57e0c
Clean up
blushi Mar 17, 2021
5a07f0e
Return error as part of init/export genesis handlers
blushi Mar 18, 2021
235e8f6
Merge branch 'master' into marie/214-group-genesis
blushi Mar 19, 2021
e53314e
Add doc about sequence
blushi Mar 24, 2021
672938a
Merge branch 'marie/214-group-genesis' of github.com:regen-network/re…
blushi Mar 24, 2021
59c54ea
Address some review comments
blushi Mar 24, 2021
8ba8fc9
Lint
blushi Mar 24, 2021
6f13740
Improve error msg and doc
blushi Mar 24, 2021
36d401f
Group account renaming
blushi Mar 25, 2021
c0c7aae
Use require var in genesis tests
blushi Mar 25, 2021
858bc24
Lint
blushi Mar 25, 2021
789f363
Use primary key instead of natural key
blushi Mar 25, 2021
2b36281
Use Init/ExportGenesis in Fixture
blushi Mar 25, 2021
821d7c2
Add docs to setCustomModules
blushi Mar 25, 2021
1551d00
Use address for group account address on proposal
blushi Mar 25, 2021
a3a3666
Merge branch 'master' into marie/214-group-genesis
blushi Mar 26, 2021
2f24c89
Merge branch 'master' into marie/214-group-genesis
blushi Mar 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import (
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
servermodule "github.com/regen-network/regen-ledger/types/module/server"
"github.com/spf13/cast"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
Expand Down Expand Up @@ -187,6 +188,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.
Expand Down Expand Up @@ -342,7 +350,7 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
)

// register experimental modules here
setCustomModules(app, interfaceRegistry)
app.nm = setCustomModules(app, interfaceRegistry)

var skipGenesisInvariants = cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants))

Expand Down Expand Up @@ -484,7 +492,8 @@ func (app *RegenApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.
func (app *RegenApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
var genesisState GenesisState
app.cdc.MustUnmarshalJSON(req.AppStateBytes, &genesisState)
return app.mm.InitGenesis(ctx, app.appCodec, genesisState)
res := app.mm.InitGenesis(ctx, app.appCodec, genesisState)
return app.nm.InitGenesis(ctx, genesisState, res.Validators)
}

// LoadHeight loads a particular height
Expand Down
4 changes: 3 additions & 1 deletion app/experimental_appconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ 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))
Expand All @@ -47,6 +47,8 @@ func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry)
if err != nil {
panic(err)
}

return newModuleManager
/* New Module Wiring END */
}

Expand Down
9 changes: 8 additions & 1 deletion app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ func (app *RegenApp) ExportAppStateAndValidators(
app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs)
}

genState := app.mm.ExportGenesis(ctx, app.appCodec)
genState := map[string]json.RawMessage{}
for name, v := range app.mm.ExportGenesis(ctx, app.appCodec) {
genState[name] = v
}
// Export genesis state from new modules (that use ADR 33 approach)
for name, v := range app.nm.ExportGenesis(ctx) {
genState[name] = v
}
appState, err := json.MarshalIndent(genState, "", " ")
if err != nil {
return servertypes.ExportedApp{}, err
Expand Down
5 changes: 4 additions & 1 deletion app/stable_appconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
72 changes: 42 additions & 30 deletions docs/modules/group/protobuf.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
- [EventUpdateGroup](#regen.group.v1alpha1.EventUpdateGroup)
- [EventUpdateGroupAccount](#regen.group.v1alpha1.EventUpdateGroupAccount)

- [regen/group/v1alpha1/genesis.proto](#regen/group/v1alpha1/genesis.proto)
- [GenesisState](#regen.group.v1alpha1.GenesisState)

- [regen/group/v1alpha1/types.proto](#regen/group/v1alpha1/types.proto)
- [GroupAccountInfo](#regen.group.v1alpha1.GroupAccountInfo)
- [GroupInfo](#regen.group.v1alpha1.GroupInfo)
Expand All @@ -29,6 +26,9 @@
- [Proposal.Result](#regen.group.v1alpha1.Proposal.Result)
- [Proposal.Status](#regen.group.v1alpha1.Proposal.Status)

- [regen/group/v1alpha1/genesis.proto](#regen/group/v1alpha1/genesis.proto)
- [GenesisState](#regen.group.v1alpha1.GenesisState)

- [regen/group/v1alpha1/query.proto](#regen/group/v1alpha1/query.proto)
- [QueryGroupAccountInfoRequest](#regen.group.v1alpha1.QueryGroupAccountInfoRequest)
- [QueryGroupAccountInfoResponse](#regen.group.v1alpha1.QueryGroupAccountInfoResponse)
Expand Down Expand Up @@ -151,33 +151,6 @@ EventUpdateGroupAccount is an event emitted when a group account is updated.



<!-- end messages -->

<!-- end enums -->

<!-- end HasExtensions -->

<!-- end services -->



<a name="regen/group/v1alpha1/genesis.proto"></a>
<p align="right"><a href="#top">Top</a></p>

## regen/group/v1alpha1/genesis.proto



<a name="regen.group.v1alpha1.GenesisState"></a>

### GenesisState
TODO: #214
GenesisState defines the group module's genesis state.





<!-- end messages -->

<!-- end enums -->
Expand Down Expand Up @@ -294,6 +267,7 @@ passes as well as some optional metadata associated with the proposal.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| proposal_id | [uint64](#uint64) | | proposal_id is the unique id of the proposal. |
| group_account | [string](#string) | | group_account is the group account address. |
| metadata | [bytes](#bytes) | | metadata is any arbitrary metadata to attached to the proposal. |
| proposers | [string](#string) | repeated | proposers are the account addresses of the proposers. |
Expand Down Expand Up @@ -431,6 +405,44 @@ Status defines proposal statuses.



<a name="regen/group/v1alpha1/genesis.proto"></a>
<p align="right"><a href="#top">Top</a></p>

## regen/group/v1alpha1/genesis.proto



<a name="regen.group.v1alpha1.GenesisState"></a>

### GenesisState
GenesisState defines the group module's genesis state.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| group_seq | [uint64](#uint64) | | group_seq is the group table orm.Sequence. |
| groups | [GroupInfo](#regen.group.v1alpha1.GroupInfo) | repeated | groups is the list of groups info. |
| group_members | [GroupMember](#regen.group.v1alpha1.GroupMember) | repeated | group_members is the list of groups members. |
| group_account_seq | [uint64](#uint64) | | group_account_seq is the group account table orm.Sequence. |
| group_accounts | [GroupAccountInfo](#regen.group.v1alpha1.GroupAccountInfo) | repeated | group_accounts is the list of group accounts info. |
| proposal_seq | [uint64](#uint64) | | proposal_seq is the proposal table orm.Sequence. |
| proposals | [Proposal](#regen.group.v1alpha1.Proposal) | repeated | proposals is the list of proposals. |
| votes | [Vote](#regen.group.v1alpha1.Vote) | repeated | votes is the list of votes. |





<!-- end messages -->

<!-- end enums -->

<!-- end HasExtensions -->

<!-- end services -->



<a name="regen/group/v1alpha1/query.proto"></a>
<p align="right"><a href="#top">Top</a></p>

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,8 @@ golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 h1:/ZScEX8SfEmUGRHs0gxpqteO5nfNW6axyZbBdw9A12g=
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down
41 changes: 21 additions & 20 deletions orm/auto_uint64_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package orm
package orm_test

import (
"math"
Expand All @@ -11,6 +11,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/regen-network/regen-ledger/orm"
"github.com/regen-network/regen-ledger/testutil/testdata"
)

Expand All @@ -23,8 +24,8 @@ func TestAutoUInt64PrefixScan(t *testing.T) {
testTablePrefix = iota
testTableSeqPrefix
)
tb := NewAutoUInt64TableBuilder(testTablePrefix, testTableSeqPrefix, storeKey, &testdata.GroupInfo{}, cdc).Build()
ctx := NewMockContext()
tb := orm.NewAutoUInt64TableBuilder(testTablePrefix, testTableSeqPrefix, storeKey, &testdata.GroupInfo{}, cdc).Build()
ctx := orm.NewMockContext()

g1 := testdata.GroupInfo{
Description: "my test 1",
Expand All @@ -46,103 +47,103 @@ func TestAutoUInt64PrefixScan(t *testing.T) {
specs := map[string]struct {
start, end uint64
expResult []testdata.GroupInfo
expRowIDs []RowID
expRowIDs []orm.RowID
expError *errors.Error
method func(ctx HasKVStore, start uint64, end uint64) (Iterator, error)
method func(ctx orm.HasKVStore, start uint64, end uint64) (orm.Iterator, error)
}{
"first element": {
start: 1,
end: 2,
method: tb.PrefixScan,
expResult: []testdata.GroupInfo{g1},
expRowIDs: []RowID{EncodeSequence(1)},
expRowIDs: []orm.RowID{orm.EncodeSequence(1)},
},
"first 2 elements": {
start: 1,
end: 3,
method: tb.PrefixScan,
expResult: []testdata.GroupInfo{g1, g2},
expRowIDs: []RowID{EncodeSequence(1), EncodeSequence(2)},
expRowIDs: []orm.RowID{orm.EncodeSequence(1), orm.EncodeSequence(2)},
},
"first 3 elements": {
start: 1,
end: 4,
method: tb.PrefixScan,
expResult: []testdata.GroupInfo{g1, g2, g3},
expRowIDs: []RowID{EncodeSequence(1), EncodeSequence(2), EncodeSequence(3)},
expRowIDs: []orm.RowID{orm.EncodeSequence(1), orm.EncodeSequence(2), orm.EncodeSequence(3)},
},
"search with max end": {
start: 1,
end: math.MaxUint64,
method: tb.PrefixScan,
expResult: []testdata.GroupInfo{g1, g2, g3},
expRowIDs: []RowID{EncodeSequence(1), EncodeSequence(2), EncodeSequence(3)},
expRowIDs: []orm.RowID{orm.EncodeSequence(1), orm.EncodeSequence(2), orm.EncodeSequence(3)},
},
"2 to end": {
start: 2,
end: 5,
method: tb.PrefixScan,
expResult: []testdata.GroupInfo{g2, g3},
expRowIDs: []RowID{EncodeSequence(2), EncodeSequence(3)},
expRowIDs: []orm.RowID{orm.EncodeSequence(2), orm.EncodeSequence(3)},
},
"start before end should fail": {
start: 2,
end: 1,
method: tb.PrefixScan,
expError: ErrArgument,
expError: orm.ErrArgument,
},
"start equals end should fail": {
start: 1,
end: 1,
method: tb.PrefixScan,
expError: ErrArgument,
expError: orm.ErrArgument,
},
"reverse first element": {
start: 1,
end: 2,
method: tb.ReversePrefixScan,
expResult: []testdata.GroupInfo{g1},
expRowIDs: []RowID{EncodeSequence(1)},
expRowIDs: []orm.RowID{orm.EncodeSequence(1)},
},
"reverse first 2 elements": {
start: 1,
end: 3,
method: tb.ReversePrefixScan,
expResult: []testdata.GroupInfo{g2, g1},
expRowIDs: []RowID{EncodeSequence(2), EncodeSequence(1)},
expRowIDs: []orm.RowID{orm.EncodeSequence(2), orm.EncodeSequence(1)},
},
"reverse first 3 elements": {
start: 1,
end: 4,
method: tb.ReversePrefixScan,
expResult: []testdata.GroupInfo{g3, g2, g1},
expRowIDs: []RowID{EncodeSequence(3), EncodeSequence(2), EncodeSequence(1)},
expRowIDs: []orm.RowID{orm.EncodeSequence(3), orm.EncodeSequence(2), orm.EncodeSequence(1)},
},
"reverse search with max end": {
start: 1,
end: math.MaxUint64,
method: tb.ReversePrefixScan,
expResult: []testdata.GroupInfo{g3, g2, g1},
expRowIDs: []RowID{EncodeSequence(3), EncodeSequence(2), EncodeSequence(1)},
expRowIDs: []orm.RowID{orm.EncodeSequence(3), orm.EncodeSequence(2), orm.EncodeSequence(1)},
},
"reverse 2 to end": {
start: 2,
end: 5,
method: tb.ReversePrefixScan,
expResult: []testdata.GroupInfo{g3, g2},
expRowIDs: []RowID{EncodeSequence(3), EncodeSequence(2)},
expRowIDs: []orm.RowID{orm.EncodeSequence(3), orm.EncodeSequence(2)},
},
"reverse start before end should fail": {
start: 2,
end: 1,
method: tb.ReversePrefixScan,
expError: ErrArgument,
expError: orm.ErrArgument,
},
"reverse start equals end should fail": {
start: 1,
end: 1,
method: tb.ReversePrefixScan,
expError: ErrArgument,
expError: orm.ErrArgument,
},
}
for msg, spec := range specs {
Expand All @@ -153,7 +154,7 @@ func TestAutoUInt64PrefixScan(t *testing.T) {
return
}
var loaded []testdata.GroupInfo
rowIDs, err := ReadAll(it, &loaded)
rowIDs, err := orm.ReadAll(it, &loaded)
require.NoError(t, err)
assert.Equal(t, spec.expResult, loaded)
assert.Equal(t, spec.expRowIDs, rowIDs)
Expand Down
Loading