Skip to content

Commit

Permalink
Package Godocs improvements and additions (osmosis-labs#2064)
Browse files Browse the repository at this point in the history
* ante, app, cmd, osmomath package doc additions

* wasmbindings, epochs, and gamm doc additions

* modules, proto godocs additions

* proto godocs additions

* make proto-gen

* godocs in all module.go; package godocs

* sync w main

* godocs naming conventions followed

* Update ante/sendblock.go

Co-authored-by: Roman <[email protected]>

* Update app/apptesting/gamm.go

Co-authored-by: Roman <[email protected]>

* Update app/apptesting/gamm.go

Co-authored-by: Roman <[email protected]>

* Update app/apptesting/gamm.go

Co-authored-by: Roman <[email protected]>

* Update app/keepers/keys.go

Co-authored-by: Roman <[email protected]>

* Update app/keepers/keys.go

Co-authored-by: Roman <[email protected]>

* Update app/modules.go

Co-authored-by: Roman <[email protected]>

* Update app/params/config.go

Co-authored-by: Roman <[email protected]>

* Update cmd/osmosisd/cmd/init.go

Co-authored-by: Roman <[email protected]>

* Update app/apptesting/test_suite.go

Co-authored-by: Matt, Park <[email protected]>

* Update app/apptesting/test_suite.go

Co-authored-by: Matt, Park <[email protected]>

* Update app/forks.go

Co-authored-by: Matt, Park <[email protected]>

* Update cmd/osmosisd/cmd/genesis.go

Co-authored-by: Matt, Park <[email protected]>

* Update cmd/osmosisd/cmd/testnet.go

Co-authored-by: Matt, Park <[email protected]>

* Update proto/osmosis/gamm/pool-models/balancer/tx/tx.proto

Co-authored-by: Matt, Park <[email protected]>

* Update app/keepers/keys.go

Co-authored-by: Roman <[email protected]>

* Update osmomath/decimal.go

Co-authored-by: Matt, Park <[email protected]>

* Update proto/osmosis/pool-incentives/v1beta1/query.proto

Co-authored-by: Matt, Park <[email protected]>

* Update wasmbinding/message_plugin.go

Co-authored-by: Matt, Park <[email protected]>

* Update wasmbinding/message_plugin.go

Co-authored-by: Matt, Park <[email protected]>

* Update osmomath/decimal.go

Co-authored-by: Matt, Park <[email protected]>

* docs clarifications

* make all

* indirect fix

Co-authored-by: Roman <[email protected]>
Co-authored-by: Matt, Park <[email protected]>
  • Loading branch information
3 people authored Jul 19, 2022
1 parent 69126dd commit ce51825
Show file tree
Hide file tree
Showing 51 changed files with 241 additions and 21 deletions.
4 changes: 4 additions & 0 deletions ante/sendblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ type SendBlockOptions struct {
PermittedOnlySendTo map[string]string
}

// NewSendBlockOptions returns options for sending new blocks.
func NewSendBlockOptions(appOpts servertypes.AppOptions) SendBlockOptions {
return SendBlockOptions{
PermittedOnlySendTo: parsePermittedOnlySendTo(appOpts),
}
}

// parsePermittedOnlySendTo parses the mapping PermittedOnlySendTo.
func parsePermittedOnlySendTo(opts servertypes.AppOptions) map[string]string {
valueInterface := opts.Get("permitted-only-send-to")
if valueInterface == nil {
Expand All @@ -32,12 +34,14 @@ type SendBlockDecorator struct {
Options SendBlockOptions
}

// NewSendBlockDecorator are a part of auth module AnteDecorators that are recursively chained together into a single AntiHandler.
func NewSendBlockDecorator(options SendBlockOptions) *SendBlockDecorator {
return &SendBlockDecorator{
Options: options, // TODO: hydrate from configuration
}
}

// AnteHandle is used for performing basic validity checks on a transaction such that it can be thrown out of the mempool.
func (decorator *SendBlockDecorator) AnteHandle(
ctx sdk.Context,
tx sdk.Tx,
Expand Down
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ type OsmosisApp struct {
configurator module.Configurator
}

// init sets DefaultNodeHome to default osmosisd install location.
func init() {
userHomeDir, err := os.UserHomeDir()
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion app/apptesting/gamm.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var DefaultAcctFunds sdk.Coins = sdk.NewCoins(
sdk.NewCoin("baz", sdk.NewInt(10000000)),
)

// Returns a Univ2 pool with the initial liquidity being the provided balances
// PrepareUni2PoolWithAssets returns a Univ2 pool with the initial liquidity being the provided balances.
func (s *KeeperTestHelper) PrepareUni2PoolWithAssets(asset1, asset2 sdk.Coin) uint64 {
return s.PrepareBalancerPoolWithPoolAsset(
[]balancer.PoolAsset{
Expand All @@ -30,6 +30,7 @@ func (s *KeeperTestHelper) PrepareUni2PoolWithAssets(asset1, asset2 sdk.Coin) ui
)
}

// PrepareBalancerPool returns a Balancer pool's pool-ID with pool params set in PrepareBalancerPoolWithPoolParams.
func (s *KeeperTestHelper) PrepareBalancerPool() uint64 {
poolId := s.PrepareBalancerPoolWithPoolParams(balancer.PoolParams{
SwapFee: sdk.NewDec(0),
Expand All @@ -51,6 +52,7 @@ func (s *KeeperTestHelper) PrepareBalancerPool() uint64 {
return poolId
}

// PrepareBalancerPoolWithPoolParams sets up a Balancer pool with poolParams.
func (s *KeeperTestHelper) PrepareBalancerPoolWithPoolParams(poolParams balancer.PoolParams) uint64 {
// Mint some assets to the account.
s.FundAcc(s.TestAccs[0], DefaultAcctFunds)
Expand All @@ -75,6 +77,7 @@ func (s *KeeperTestHelper) PrepareBalancerPoolWithPoolParams(poolParams balancer
return poolId
}

// PrepareBalancerPoolWithPoolAsset sets up a Balancer pool with an array of assets.
func (s *KeeperTestHelper) PrepareBalancerPoolWithPoolAsset(assets []balancer.PoolAsset) uint64 {
s.Require().Len(assets, 2)

Expand Down
11 changes: 11 additions & 0 deletions app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type KeeperTestHelper struct {
TestAccs []sdk.AccAddress
}

// Setup sets up basic environment for suite (App, Ctx, and test accounts)
func (s *KeeperTestHelper) Setup() {
s.App = app.Setup(false)
s.Ctx = s.App.BaseApp.NewContext(false, tmtypes.Header{Height: 1, ChainID: "osmosis-1", Time: time.Now().UTC()})
Expand All @@ -50,6 +51,7 @@ func (s *KeeperTestHelper) Setup() {
s.TestAccs = CreateRandomAccounts(3)
}

// CreateTestContext creates a test context.
func (s *KeeperTestHelper) CreateTestContext() sdk.Context {
db := dbm.NewMemDB()
logger := log.NewNopLogger()
Expand All @@ -59,11 +61,13 @@ func (s *KeeperTestHelper) CreateTestContext() sdk.Context {
return sdk.NewContext(ms, tmtypes.Header{}, false, logger)
}

// FundAcc funds target address with specified amount.
func (s *KeeperTestHelper) FundAcc(acc sdk.AccAddress, amounts sdk.Coins) {
err := simapp.FundAccount(s.App.BankKeeper, s.Ctx, acc, amounts)
s.Require().NoError(err)
}

// SetupValidator sets up a validator and returns the ValAddress.
func (s *KeeperTestHelper) SetupValidator(bondStatus stakingtypes.BondStatus) sdk.ValAddress {
valPub := secp256k1.GenPrivKey().PubKey()
valAddr := sdk.ValAddress(valPub.Address())
Expand Down Expand Up @@ -98,10 +102,12 @@ func (s *KeeperTestHelper) SetupValidator(bondStatus stakingtypes.BondStatus) sd
return valAddr
}

// SetupTokenFactory sets up a token module account for the TokenFactoryKeeper.
func (s *KeeperTestHelper) SetupTokenFactory() {
s.App.TokenFactoryKeeper.CreateModuleAccount(s.Ctx)
}

// BeginNewBlock starts a new block.
func (s *KeeperTestHelper) BeginNewBlock(executeNextEpoch bool) {
var valAddr []byte

Expand All @@ -120,6 +126,7 @@ func (s *KeeperTestHelper) BeginNewBlock(executeNextEpoch bool) {
s.BeginNewBlockWithProposer(executeNextEpoch, valAddr)
}

// BeginNewBlockWithProposer begins a new block with a proposer.
func (s *KeeperTestHelper) BeginNewBlockWithProposer(executeNextEpoch bool, proposer sdk.ValAddress) {
validator, found := s.App.StakingKeeper.GetValidator(s.Ctx, proposer)
s.Assert().True(found)
Expand Down Expand Up @@ -152,11 +159,13 @@ func (s *KeeperTestHelper) BeginNewBlockWithProposer(executeNextEpoch bool, prop
s.App.BeginBlocker(s.Ctx, reqBeginBlock)
}

// EndBlock ends the block.
func (s *KeeperTestHelper) EndBlock() {
reqEndBlock := abci.RequestEndBlock{Height: s.Ctx.BlockHeight()}
s.App.EndBlocker(s.Ctx, reqEndBlock)
}

// AllocateRewardsToValidator allocates reward tokens to a distribution module then allocates rewards to the validator address.
func (s *KeeperTestHelper) AllocateRewardsToValidator(valAddr sdk.ValAddress, rewardAmt sdk.Int) {
validator, found := s.App.StakingKeeper.GetValidator(s.Ctx, valAddr)
s.Require().True(found)
Expand Down Expand Up @@ -250,6 +259,7 @@ func (s *KeeperTestHelper) SwapAndSetSpotPrice(poolId uint64, fromAsset sdk.Coin
return spotPrice
}

// LockTokens funds an account, locks tokens and returns a lockID.
func (s *KeeperTestHelper) LockTokens(addr sdk.AccAddress, coins sdk.Coins, duration time.Duration) (lockID uint64) {
msgServer := lockupkeeper.NewMsgServerImpl(s.App.LockupKeeper)
s.FundAcc(addr, coins)
Expand All @@ -260,6 +270,7 @@ func (s *KeeperTestHelper) LockTokens(addr sdk.AccAddress, coins sdk.Coins, dura
return msgResponse.ID
}

// BuildTx builds a transaction.
func (s *KeeperTestHelper) BuildTx(
txBuilder client.TxBuilder,
msgs []sdk.Msg,
Expand Down
1 change: 1 addition & 0 deletions app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func DefaultConfig() network.Config {
}
}

// NewAppConstructor returns a new Osmosis app given encoding type configs.
func NewAppConstructor(encodingCfg params.EncodingConfig) network.AppConstructor {
return func(val network.Validator) servertypes.Application {
return NewOsmosisApp(
Expand Down
2 changes: 1 addition & 1 deletion app/forks.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// BeginBlockForks is intended to be ran in.
// BeginBlockForks is intended to be ran in a chain upgrade.
func BeginBlockForks(ctx sdk.Context, app *OsmosisApp) {
for _, fork := range Forks {
if ctx.BlockHeight() == fork.UpgradeHeight {
Expand Down
3 changes: 3 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ type AppKeepers struct {
memKeys map[string]*sdk.MemoryStoreKey
}

// InitNormalKeepers initializes all 'normal' keepers (account, app, bank, auth, staking, distribution, slashing, transfer, gamm, IBC router, pool incentives, governance, mint, txfees keepers).
func (appKeepers *AppKeepers) InitNormalKeepers(
appCodec codec.Codec,
bApp *baseapp.BaseApp,
Expand Down Expand Up @@ -367,6 +368,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
appKeepers.GovKeeper = &govKeeper
}

// InitSpecialKeepers initiates special keepers (crisis appkeeper, upgradekeeper, params keeper)
func (appKeepers *AppKeepers) InitSpecialKeepers(
appCodec codec.Codec,
bApp *baseapp.BaseApp,
Expand Down Expand Up @@ -433,6 +435,7 @@ func (appKeepers *AppKeepers) initParamsKeeper(appCodec codec.BinaryCodec, legac
return paramsKeeper
}

// SetupHooks sets up hooks for modules.
func (appKeepers *AppKeepers) SetupHooks() {
// For every module that has hooks set on it,
// you must check InitNormalKeepers to ensure that its not passed by de-reference
Expand Down
5 changes: 5 additions & 0 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

// GenerateKeys generates new keys (KV Store, Transient store, and memory store).
func (appKeepers *AppKeepers) GenerateKeys() {
// Define what keys will be used in the cosmos-sdk key/value store.
// Cosmos-SDK modules each have a "key" that allows the application to reference what they've stored on the chain.
Expand All @@ -18,19 +19,23 @@ func (appKeepers *AppKeepers) GenerateKeys() {
appKeepers.memKeys = sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
}

// GetSubspace gets existing substore from keeper.
func (appKeepers *AppKeepers) GetSubspace(moduleName string) paramstypes.Subspace {
subspace, _ := appKeepers.ParamsKeeper.GetSubspace(moduleName)
return subspace
}

// GetKVStoreKey gets KV Store keys.
func (appKeepers *AppKeepers) GetKVStoreKey() map[string]*sdk.KVStoreKey {
return appKeepers.keys
}

// GetTransientStoreKey gets Transient Store keys.
func (appKeepers *AppKeepers) GetTransientStoreKey() map[string]*sdk.TransientStoreKey {
return appKeepers.tkeys
}

// GetMemoryStoreKey get memory Store keys.
func (appKeepers *AppKeepers) GetMemoryStoreKey() map[string]*sdk.MemoryStoreKey {
return appKeepers.memKeys
}
Expand Down
1 change: 1 addition & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func orderBeginBlockers(allModuleNames []string) []string {
return ord.TotalOrdering()
}

// OrderEndBlockers returns EndBlockers (crisis, govtypes, staking) with no relative order.
func OrderEndBlockers(allModuleNames []string) []string {
ord := partialord.NewPartialOrdering(allModuleNames)
// only Osmosis modules with endblock code are: crisis, govtypes, staking
Expand Down
2 changes: 2 additions & 0 deletions app/params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func init() {
RegisterDenoms()
}

// RegisterDenoms registers token denoms.
func RegisterDenoms() {
err := sdk.RegisterDenom(HumanCoinUnit, sdk.OneDec())
if err != nil {
Expand All @@ -47,6 +48,7 @@ func RegisterDenoms() {
}
}

// SetAddressPrefixes builds the Config with Bech32 addressPrefix and publKeyPrefix for accounts, validators, and consensus nodes and verifies that addreeses have correct format.
func SetAddressPrefixes() {
config := sdk.GetConfig()
config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub)
Expand Down
3 changes: 3 additions & 0 deletions cmd/osmosisd/cmd/balances_from_state_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type DerivedAccount struct {
TotalBalances sdk.Coins `json:"total_balances"`
}

// newDerivedAccount returns a new derived account.
func newDerivedAccount(address string) DerivedAccount {
return DerivedAccount{
Address: address,
Expand All @@ -53,6 +54,7 @@ func newDerivedAccount(address string) DerivedAccount {
}
}

// underlyingCoins returns liquidity pool's underlying coin balances.
func underlyingCoins(originCoins sdk.Coins, pools map[string]gammtypes.PoolI) sdk.Coins {
balances := sdk.Coins{}
convertAgain := false
Expand Down Expand Up @@ -115,6 +117,7 @@ func underlyingCoinsForSelectPools(
return balancesByPool
}

// getGenStateFromPath returns a JSON genState message from inputted path.
func getGenStateFromPath(genesisFilePath string) (map[string]json.RawMessage, error) {
genState := make(map[string]json.RawMessage)

Expand Down
5 changes: 4 additions & 1 deletion cmd/osmosisd/cmd/forceprune.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
defaultMinHeight = "1000"
)

// get cmd to convert any bech32 address to an osmo prefix.
// forceprune gets cmd to convert any bech32 address to an osmo prefix.
func forceprune() *cobra.Command {
cmd := &cobra.Command{
Use: "forceprune",
Expand Down Expand Up @@ -94,6 +94,7 @@ func forceprune() *cobra.Command {
return cmd
}

// pruneBlockStoreAndGetHeights prunes blockstore and returns the startHeight and currentHeight.
func pruneBlockStoreAndGetHeights(dbPath string, fullHeight int64) (
startHeight int64, currentHeight int64, err error,
) {
Expand Down Expand Up @@ -131,6 +132,7 @@ func pruneBlockStoreAndGetHeights(dbPath string, fullHeight int64) (
return startHeight, currentHeight, nil
}

// compactBlockStore compacts block storage.
func compactBlockStore(dbPath string) (err error) {
compactOpts := opt.Options{
DisableSeeksCompaction: true,
Expand All @@ -151,6 +153,7 @@ func compactBlockStore(dbPath string) (err error) {
return nil
}

// forcepruneStateStore prunes and compacts state storage.
func forcepruneStateStore(dbPath string, startHeight, currentHeight, minHeight, fullHeight int64) error {
opts := opt.Options{
DisableSeeksCompaction: true,
Expand Down
1 change: 1 addition & 0 deletions cmd/osmosisd/cmd/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
)

//nolint:ineffassign
// PrepareGenesisCmd returns prepare-genesis cobra Command.
func PrepareGenesisCmd(defaultNodeHome string, mbm module.BasicManager) *cobra.Command {
cmd := &cobra.Command{
Use: "prepare-genesis",
Expand Down
2 changes: 2 additions & 0 deletions cmd/osmosisd/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type printInfo struct {
AppMessage json.RawMessage `json:"app_message" yaml:"app_message"`
}

// newPrintInfo initializes a printInfo struct.
func newPrintInfo(moniker, chainID, nodeID, genTxsDir string, appMessage json.RawMessage) printInfo {
return printInfo{
Moniker: moniker,
Expand All @@ -54,6 +55,7 @@ func newPrintInfo(moniker, chainID, nodeID, genTxsDir string, appMessage json.Ra
}
}

// displayInfo displays printInfo in JSON format.
func displayInfo(info printInfo) error {
out, err := json.MarshalIndent(info, "", " ")
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions cmd/osmosisd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ min-gas-price-for-high-gas-tx = ".0025"
return OsmosisAppTemplate, OsmosisAppCfg
}

// initRootCmd initializes root commands when creating a new root command for simd.
func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
cfg := sdk.GetConfig()
cfg.Seal()
Expand Down Expand Up @@ -179,6 +180,7 @@ func addModuleInitFlags(startCmd *cobra.Command) {
wasm.AddModuleInitFlags(startCmd)
}

// queryCommand adds transaction and account querying commands.
func queryCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "query",
Expand All @@ -203,6 +205,7 @@ func queryCommand() *cobra.Command {
return cmd
}

// txCommand adds transaction signing, encoding / decoding, and broadcasting commands.
func txCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "tx",
Expand All @@ -229,6 +232,7 @@ func txCommand() *cobra.Command {
return cmd
}

// newApp initializes and returns a new Osmosis app.
func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts servertypes.AppOptions) servertypes.Application {
var cache sdk.MultiStorePersistentCache

Expand Down Expand Up @@ -282,6 +286,7 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts serverty
)
}

// createOsmosisAppAndExport creates and exports the new Osmosis app, returns the state of the new Osmosis app for a genesis file.
func createOsmosisAppAndExport(
logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailWhiteList []string,
appOpts servertypes.AppOptions,
Expand Down
5 changes: 3 additions & 2 deletions cmd/osmosisd/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var (
emptyMnemonic = ""
)

// get cmd to initialize all files for tendermint testnet and application.
// testnetCmd gets the cmd to initialize all files for tendermint testnet and application.
func testnetCmd(mbm module.BasicManager, genBalIterator banktypes.GenesisBalancesIterator) *cobra.Command {
cmd := &cobra.Command{
Use: "testnet",
Expand Down Expand Up @@ -105,7 +105,7 @@ Example:

const nodeDirPerm = 0o755

// Initialize the testnet.
// InitTestnet initializes the testnet.
func InitTestnet(
clientCtx client.Context,
cmd *cobra.Command,
Expand Down Expand Up @@ -270,6 +270,7 @@ func InitTestnet(
return nil
}

// initGenFiles initializes genesis files for testnet.
func initGenFiles(
clientCtx client.Context, mbm module.BasicManager, genesisParams GenesisParams, chainID string,
genAccounts []authtypes.GenesisAccount, genBalances []banktypes.Balance,
Expand Down
Loading

0 comments on commit ce51825

Please sign in to comment.