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 27 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"
"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

// 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
// use ADR 33 approach without the need for removing their keepers
// and a larger refactoring.
smm *server.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.smm = 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.smm.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
16 changes: 15 additions & 1 deletion app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app

import (
"encoding/json"
"fmt"
"log"

tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
Expand Down Expand Up @@ -31,7 +32,20 @@ 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)
// if they are not already part of genState
for name, v := range app.smm.ExportGenesis(ctx) {
if _, ok := genState[name]; ok {
return servertypes.ExportedApp{}, fmt.Errorf("genesis state already exported for %s module", name)
}
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() {}
94 changes: 53 additions & 41 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 @@ -115,7 +115,7 @@ EventCreateGroupAccount is an event emitted when a group account is created.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| group_account | [string](#string) | | group_account is the address of the group account. |
| address | [string](#string) | | address is the address of the group account. |



Expand Down Expand Up @@ -145,34 +145,7 @@ EventUpdateGroupAccount is an event emitted when a group account is updated.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| group_account | [string](#string) | | group_account is the address of the group account. |





<!-- 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.
| address | [string](#string) | | address is the address of the group account. |



Expand Down Expand Up @@ -203,7 +176,7 @@ GroupAccountInfo represents the high-level on-chain information for a group acco

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| group_account | [string](#string) | | group_account is the group account address. |
| address | [string](#string) | | address is the group account address. |
| group_id | [uint64](#uint64) | | group_id is the unique ID of the group. |
| admin | [string](#string) | | admin is the account address of the group admin. |
| metadata | [bytes](#bytes) | | metadata is any arbitrary metadata to attached to the group account. |
Expand Down Expand Up @@ -294,12 +267,13 @@ 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. |
| submitted_at | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | submitted_at is a timestamp specifying when a proposal was submitted. |
| group_version | [uint64](#uint64) | | group_version tracks the version of the group that this proposal corresponds to. When group membership is changed, existing proposals for prior group versions will become invalid. |
| group_account_version | [uint64](#uint64) | | group_account_version tracks the version of the group account that this proposal corresponds to. When a decision policy is changed, an existing proposals for prior policy versions will become invalid. |
| group_version | [uint64](#uint64) | | group_version tracks the version of the group that this proposal corresponds to. When group membership is changed, existing proposals from previous group versions will become invalid. |
| group_account_version | [uint64](#uint64) | | group_account_version tracks the version of the group account that this proposal corresponds to. When a decision policy is changed, existing proposals from previous policy versions will become invalid. |
| status | [Proposal.Status](#regen.group.v1alpha1.Proposal.Status) | | Status represents the high level position in the life cycle of the proposal. Initial value is Submitted. |
| result | [Proposal.Result](#regen.group.v1alpha1.Proposal.Result) | | result is the final result based on the votes and election rule. Initial value is Undefined. The result is persisted so that clients can always rely on this state and not have to replicate the logic. |
| vote_state | [Tally](#regen.group.v1alpha1.Tally) | | vote_state contains the sums of all weighted votes for this proposal. |
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, it is used to get the next group ID. |
| 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, it is used to generate the next group account address. |
| 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, it is used to get the next proposal ID. |
| 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 All @@ -446,7 +458,7 @@ QueryGroupAccountInfoRequest is the Query/GroupAccountInfo request type.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| group_account | [string](#string) | | group_account is the account address of the group account. |
| address | [string](#string) | | address is the account address of the group account. |



Expand Down Expand Up @@ -664,7 +676,7 @@ QueryProposalsByGroupAccountRequest is the Query/ProposalByGroupAccount request

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| group_account | [string](#string) | | group_account is the group account address related to proposals. |
| address | [string](#string) | | address is the group account address related to proposals. |
| pagination | [cosmos.base.query.v1beta1.PageRequest](#cosmos.base.query.v1beta1.PageRequest) | | pagination defines an optional pagination for the request. |


Expand Down Expand Up @@ -845,7 +857,7 @@ MsgCreateGroupAccountResponse is the Msg/CreateGroupAccount response type.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| group_account | [string](#string) | | group_account is the account address of the newly created group account. |
| address | [string](#string) | | address is the account address of the newly created group account. |



Expand Down Expand Up @@ -952,7 +964,7 @@ MsgUpdateGroupAccountAdminRequest is the Msg/UpdateGroupAccountAdmin request typ
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| admin | [string](#string) | | admin is the account address of the group admin. |
| group_account | [string](#string) | | group_account is the group account address. |
| address | [string](#string) | | address is the group account address. |
| new_admin | [string](#string) | | new_admin is the new group account admin. |


Expand All @@ -979,7 +991,7 @@ MsgUpdateGroupAccountDecisionPolicyRequest is the Msg/UpdateGroupAccountDecision
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| admin | [string](#string) | | admin is the account address of the group admin. |
| group_account | [string](#string) | | group_account is the group account address. |
| address | [string](#string) | | address is the group account address. |
| decision_policy | [google.protobuf.Any](#google.protobuf.Any) | | decision_policy is the updated group account decision policy. |


Expand All @@ -1006,7 +1018,7 @@ MsgUpdateGroupAccountMetadataRequest is the Msg/UpdateGroupAccountMetadata reque
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| admin | [string](#string) | | admin is the account address of the group admin. |
| group_account | [string](#string) | | group_account is the group account address. |
| address | [string](#string) | | address is the group account address. |
| metadata | [bytes](#bytes) | | metadata is the updated group account metadata. |


Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ require (
github.com/stretchr/testify v1.7.0
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
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect
google.golang.org/genproto v0.0.0-20210323160006-e668133fea6a // indirect
google.golang.org/grpc v1.36.0
gopkg.in/yaml.v2 v2.4.0
)

Expand Down
Loading