-
Notifications
You must be signed in to change notification settings - Fork 586
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 app v2 scaffolding and app config #6216
Draft
damiannolan
wants to merge
17
commits into
feat/depinject
Choose a base branch
from
damian/app-v2-config
base: feat/depinject
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 4 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d08c69c
feat: add app v2 scaffolding, app config and satisfy compiler
damiannolan 2ed28d6
chore: exclude pulsar files from make format
damiannolan b923865
lint: make lint-fix
damiannolan 6033360
chore: linter and invert build tags
damiannolan 62c06d7
feat: add invokers and refactor ibc core depinject inputs/outputs
damiannolan d4fe40a
chore: add capability, ibc and lightclient modules to app config
damiannolan b8b156b
lint: make lint-fix
damiannolan 5a72470
fix: add wrapper struct for light client modules DI
damiannolan ed70ae2
chore: linting, godocs, cleanup
damiannolan fc30a95
chore: add depinject to mock module
damiannolan fce3a30
lint: make lint-fix
damiannolan 2c3cb04
chore: add type alias for scoped keeper and set port router in invoker
damiannolan a8403f7
chore: update mock app with type alias and add mock module to app config
damiannolan e7c2eae
feat: add transfer to app config and wire up, fix tests
damiannolan 1a232c0
lint: make lint-fix
damiannolan 54bc954
refactor: ica depinject configuration
damiannolan f8614c6
chore: push ica depinject changes and todos
damiannolan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package simapp | ||
|
||
import ( | ||
"bytes" | ||
"crypto/rand" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
abci "github.com/cometbft/cometbft/abci/types" | ||
) | ||
|
||
type ( | ||
// VoteExtensionHandler defines a dummy vote extension handler for SimApp. | ||
// | ||
// NOTE: This implementation is solely used for testing purposes. DO NOT use | ||
// in a production application! | ||
VoteExtensionHandler struct{} | ||
|
||
// VoteExtension defines the structure used to create a dummy vote extension. | ||
VoteExtension struct { | ||
Hash []byte | ||
Height int64 | ||
Data []byte | ||
} | ||
) | ||
|
||
func NewVoteExtensionHandler() *VoteExtensionHandler { | ||
return &VoteExtensionHandler{} | ||
} | ||
|
||
func (h *VoteExtensionHandler) SetHandlers(bApp *baseapp.BaseApp) { | ||
bApp.SetExtendVoteHandler(h.ExtendVote()) | ||
bApp.SetVerifyVoteExtensionHandler(h.VerifyVoteExtension()) | ||
} | ||
|
||
func (*VoteExtensionHandler) ExtendVote() sdk.ExtendVoteHandler { | ||
return func(_ sdk.Context, req *abci.RequestExtendVote) (*abci.ResponseExtendVote, error) { | ||
buf := make([]byte, 1024) | ||
|
||
_, err := rand.Read(buf) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to generate random vote extension data: %w", err) | ||
} | ||
|
||
ve := VoteExtension{ | ||
Hash: req.Hash, | ||
Height: req.Height, | ||
Data: buf, | ||
} | ||
|
||
bz, err := json.Marshal(ve) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to encode vote extension: %w", err) | ||
} | ||
|
||
return &abci.ResponseExtendVote{VoteExtension: bz}, nil | ||
} | ||
} | ||
|
||
func (*VoteExtensionHandler) VerifyVoteExtension() sdk.VerifyVoteExtensionHandler { | ||
return func(ctx sdk.Context, req *abci.RequestVerifyVoteExtension) (*abci.ResponseVerifyVoteExtension, error) { | ||
var ve VoteExtension | ||
|
||
if err := json.Unmarshal(req.VoteExtension, &ve); err != nil { | ||
return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, nil | ||
} | ||
|
||
switch { | ||
case req.Height != ve.Height: | ||
return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, nil | ||
|
||
case !bytes.Equal(req.Hash, ve.Hash): | ||
return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, nil | ||
|
||
case len(ve.Data) != 1024: | ||
return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, nil | ||
} | ||
|
||
return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_ACCEPT}, nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
//go:build !app_v2 | ||
|
||
package simapp | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,267 @@ | ||
package simapp | ||
|
||
import ( | ||
"time" | ||
|
||
"google.golang.org/protobuf/types/known/durationpb" | ||
|
||
_ "cosmossdk.io/x/circuit" // import for side-effects | ||
_ "cosmossdk.io/x/evidence" // import for side-effects | ||
_ "cosmossdk.io/x/feegrant/module" // import for side-effects | ||
_ "cosmossdk.io/x/upgrade" // import for side-effects | ||
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import for side-effects | ||
_ "github.com/cosmos/cosmos-sdk/x/auth/vesting" // import for side-effects | ||
_ "github.com/cosmos/cosmos-sdk/x/authz/module" // import for side-effects | ||
_ "github.com/cosmos/cosmos-sdk/x/bank" // import for side-effects | ||
_ "github.com/cosmos/cosmos-sdk/x/consensus" // import for side-effects | ||
_ "github.com/cosmos/cosmos-sdk/x/crisis" // import for side-effects | ||
_ "github.com/cosmos/cosmos-sdk/x/distribution" // import for side-effects | ||
_ "github.com/cosmos/cosmos-sdk/x/group/module" // import for side-effects | ||
_ "github.com/cosmos/cosmos-sdk/x/mint" // import for side-effects | ||
_ "github.com/cosmos/cosmos-sdk/x/params" // import for side-effects | ||
_ "github.com/cosmos/cosmos-sdk/x/slashing" // import for side-effects | ||
_ "github.com/cosmos/cosmos-sdk/x/staking" // import for side-effects | ||
|
||
runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" | ||
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" | ||
authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1" | ||
authzmodulev1 "cosmossdk.io/api/cosmos/authz/module/v1" | ||
bankmodulev1 "cosmossdk.io/api/cosmos/bank/module/v1" | ||
circuitmodulev1 "cosmossdk.io/api/cosmos/circuit/module/v1" | ||
consensusmodulev1 "cosmossdk.io/api/cosmos/consensus/module/v1" | ||
crisismodulev1 "cosmossdk.io/api/cosmos/crisis/module/v1" | ||
distrmodulev1 "cosmossdk.io/api/cosmos/distribution/module/v1" | ||
evidencemodulev1 "cosmossdk.io/api/cosmos/evidence/module/v1" | ||
feegrantmodulev1 "cosmossdk.io/api/cosmos/feegrant/module/v1" | ||
genutilmodulev1 "cosmossdk.io/api/cosmos/genutil/module/v1" | ||
govmodulev1 "cosmossdk.io/api/cosmos/gov/module/v1" | ||
groupmodulev1 "cosmossdk.io/api/cosmos/group/module/v1" | ||
mintmodulev1 "cosmossdk.io/api/cosmos/mint/module/v1" | ||
paramsmodulev1 "cosmossdk.io/api/cosmos/params/module/v1" | ||
slashingmodulev1 "cosmossdk.io/api/cosmos/slashing/module/v1" | ||
stakingmodulev1 "cosmossdk.io/api/cosmos/staking/module/v1" | ||
txconfigv1 "cosmossdk.io/api/cosmos/tx/config/v1" | ||
upgrademodulev1 "cosmossdk.io/api/cosmos/upgrade/module/v1" | ||
vestingmodulev1 "cosmossdk.io/api/cosmos/vesting/module/v1" | ||
"cosmossdk.io/core/appconfig" | ||
"cosmossdk.io/depinject" | ||
circuittypes "cosmossdk.io/x/circuit/types" | ||
evidencetypes "cosmossdk.io/x/evidence/types" | ||
"cosmossdk.io/x/feegrant" | ||
upgradetypes "cosmossdk.io/x/upgrade/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/runtime" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" | ||
"github.com/cosmos/cosmos-sdk/x/authz" | ||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" | ||
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" | ||
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" | ||
"github.com/cosmos/cosmos-sdk/x/genutil" | ||
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" | ||
"github.com/cosmos/cosmos-sdk/x/gov" | ||
govclient "github.com/cosmos/cosmos-sdk/x/gov/client" | ||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" | ||
"github.com/cosmos/cosmos-sdk/x/group" | ||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" | ||
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client" | ||
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" | ||
) | ||
|
||
var ( | ||
// module account permissions | ||
moduleAccPerms = []*authmodulev1.ModuleAccountPermission{ | ||
{Account: authtypes.FeeCollectorName}, | ||
{Account: distrtypes.ModuleName}, | ||
{Account: minttypes.ModuleName, Permissions: []string{authtypes.Minter}}, | ||
{Account: stakingtypes.BondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}}, | ||
{Account: stakingtypes.NotBondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}}, | ||
{Account: govtypes.ModuleName, Permissions: []string{authtypes.Burner}}, | ||
} | ||
|
||
// blocked account addresses | ||
blockAccAddrs = []string{ | ||
authtypes.FeeCollectorName, | ||
distrtypes.ModuleName, | ||
minttypes.ModuleName, | ||
stakingtypes.BondedPoolName, | ||
stakingtypes.NotBondedPoolName, | ||
// We allow the following module accounts to receive funds: | ||
// govtypes.ModuleName | ||
} | ||
|
||
// application configuration (used by depinject) | ||
AppConfig = depinject.Configs(appconfig.Compose(&appv1alpha1.Config{ | ||
Modules: []*appv1alpha1.ModuleConfig{ | ||
{ | ||
Name: runtime.ModuleName, | ||
Config: appconfig.WrapAny(&runtimev1alpha1.Module{ | ||
AppName: "SimApp", | ||
// NOTE: upgrade module is required to be prioritized | ||
PreBlockers: []string{ | ||
upgradetypes.ModuleName, | ||
}, | ||
// During begin block slashing happens after distr.BeginBlocker so that | ||
// there is nothing left over in the validator fee pool, so as to keep the | ||
// CanWithdrawInvariant invariant. | ||
// NOTE: staking module is required if HistoricalEntries param > 0 | ||
BeginBlockers: []string{ | ||
minttypes.ModuleName, | ||
distrtypes.ModuleName, | ||
slashingtypes.ModuleName, | ||
evidencetypes.ModuleName, | ||
stakingtypes.ModuleName, | ||
authz.ModuleName, | ||
}, | ||
EndBlockers: []string{ | ||
crisistypes.ModuleName, | ||
govtypes.ModuleName, | ||
stakingtypes.ModuleName, | ||
feegrant.ModuleName, | ||
group.ModuleName, | ||
}, | ||
OverrideStoreKeys: []*runtimev1alpha1.StoreKeyConfig{ | ||
{ | ||
ModuleName: authtypes.ModuleName, | ||
KvStoreKey: "acc", | ||
}, | ||
}, | ||
// NOTE: The genutils module must occur after staking so that pools are | ||
// properly initialized with tokens from genesis accounts. | ||
// NOTE: The genutils module must also occur after auth so that it can access the params from auth. | ||
InitGenesis: []string{ | ||
authtypes.ModuleName, | ||
banktypes.ModuleName, | ||
distrtypes.ModuleName, | ||
stakingtypes.ModuleName, | ||
slashingtypes.ModuleName, | ||
govtypes.ModuleName, | ||
minttypes.ModuleName, | ||
crisistypes.ModuleName, | ||
genutiltypes.ModuleName, | ||
evidencetypes.ModuleName, | ||
authz.ModuleName, | ||
feegrant.ModuleName, | ||
group.ModuleName, | ||
paramstypes.ModuleName, | ||
upgradetypes.ModuleName, | ||
vestingtypes.ModuleName, | ||
circuittypes.ModuleName, | ||
}, | ||
// When ExportGenesis is not specified, the export genesis module order | ||
// is equal to the init genesis order | ||
// ExportGenesis: []string{}, | ||
// Uncomment if you want to set a custom migration order here. | ||
// OrderMigrations: []string{}, | ||
}), | ||
}, | ||
{ | ||
Name: authtypes.ModuleName, | ||
Config: appconfig.WrapAny(&authmodulev1.Module{ | ||
Bech32Prefix: "cosmos", | ||
ModuleAccountPermissions: moduleAccPerms, | ||
// By default modules authority is the governance module. This is configurable with the following: | ||
// Authority: "group", // A custom module authority can be set using a module name | ||
// Authority: "cosmos1cwwv22j5ca08ggdv9c2uky355k908694z577tv", // or a specific address | ||
}), | ||
}, | ||
{ | ||
Name: vestingtypes.ModuleName, | ||
Config: appconfig.WrapAny(&vestingmodulev1.Module{}), | ||
}, | ||
{ | ||
Name: banktypes.ModuleName, | ||
Config: appconfig.WrapAny(&bankmodulev1.Module{ | ||
BlockedModuleAccountsOverride: blockAccAddrs, | ||
}), | ||
}, | ||
{ | ||
Name: stakingtypes.ModuleName, | ||
Config: appconfig.WrapAny(&stakingmodulev1.Module{ | ||
// NOTE: specifying a prefix is only necessary when using bech32 addresses | ||
// If not specfied, the auth Bech32Prefix appended with "valoper" and "valcons" is used by default | ||
Bech32PrefixValidator: "cosmosvaloper", | ||
Bech32PrefixConsensus: "cosmosvalcons", | ||
}), | ||
}, | ||
{ | ||
Name: slashingtypes.ModuleName, | ||
Config: appconfig.WrapAny(&slashingmodulev1.Module{}), | ||
}, | ||
{ | ||
Name: paramstypes.ModuleName, | ||
Config: appconfig.WrapAny(¶msmodulev1.Module{}), | ||
}, | ||
{ | ||
Name: "tx", | ||
Config: appconfig.WrapAny(&txconfigv1.Config{}), | ||
}, | ||
{ | ||
Name: genutiltypes.ModuleName, | ||
Config: appconfig.WrapAny(&genutilmodulev1.Module{}), | ||
}, | ||
{ | ||
Name: authz.ModuleName, | ||
Config: appconfig.WrapAny(&authzmodulev1.Module{}), | ||
}, | ||
{ | ||
Name: upgradetypes.ModuleName, | ||
Config: appconfig.WrapAny(&upgrademodulev1.Module{}), | ||
}, | ||
{ | ||
Name: distrtypes.ModuleName, | ||
Config: appconfig.WrapAny(&distrmodulev1.Module{}), | ||
}, | ||
{ | ||
Name: evidencetypes.ModuleName, | ||
Config: appconfig.WrapAny(&evidencemodulev1.Module{}), | ||
}, | ||
{ | ||
Name: minttypes.ModuleName, | ||
Config: appconfig.WrapAny(&mintmodulev1.Module{}), | ||
}, | ||
{ | ||
Name: group.ModuleName, | ||
Config: appconfig.WrapAny(&groupmodulev1.Module{ | ||
MaxExecutionPeriod: durationpb.New(time.Second * 1209600), | ||
MaxMetadataLen: 255, | ||
}), | ||
}, | ||
{ | ||
Name: feegrant.ModuleName, | ||
Config: appconfig.WrapAny(&feegrantmodulev1.Module{}), | ||
}, | ||
{ | ||
Name: govtypes.ModuleName, | ||
Config: appconfig.WrapAny(&govmodulev1.Module{}), | ||
}, | ||
{ | ||
Name: crisistypes.ModuleName, | ||
Config: appconfig.WrapAny(&crisismodulev1.Module{}), | ||
}, | ||
{ | ||
Name: consensustypes.ModuleName, | ||
Config: appconfig.WrapAny(&consensusmodulev1.Module{}), | ||
}, | ||
{ | ||
Name: circuittypes.ModuleName, | ||
Config: appconfig.WrapAny(&circuitmodulev1.Module{}), | ||
}, | ||
}, | ||
}), | ||
depinject.Supply( | ||
// supply custom module basics | ||
map[string]module.AppModuleBasic{ | ||
genutiltypes.ModuleName: genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator), | ||
govtypes.ModuleName: gov.NewAppModuleBasic( | ||
[]govclient.ProposalHandler{ | ||
paramsclient.ProposalHandler, | ||
}, | ||
), | ||
}, | ||
)) | ||
) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copied from sdk simapp. I don't think this is really needed, its just a mock vote extension handler. We can remove it if needs be