Skip to content

Commit

Permalink
Mainnet Genesis (osmosis-labs#203)
Browse files Browse the repository at this point in the history
* in progress

* update app.toml and config.toml

* Update app/params/genesis.go

* remove finished TODO comments
  • Loading branch information
sunnya97 authored May 29, 2021
1 parent b194f95 commit 9ea50ad
Show file tree
Hide file tree
Showing 7 changed files with 276 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

const (
HumanCoinUnit = "osmo"
BaseCoinUnit = "ion"
BaseCoinUnit = "uosmo"
OsmoExponent = 6

// Bech32PrefixAccAddr defines the Bech32 prefix of an account's address
Expand Down
97 changes: 97 additions & 0 deletions app/params/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"fmt"
"time"

tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmtypes "github.com/tendermint/tendermint/types"

sdk "github.com/cosmos/cosmos-sdk/types"

banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
Expand All @@ -20,6 +23,8 @@ import (
type GenesisParams struct {
AirdropSupply sdk.Int

ConsensusParams *tmproto.ConsensusParams

ChainID string
GenesisTime time.Time
NativeCoinMetadata banktypes.Metadata
Expand All @@ -41,6 +46,98 @@ type GenesisParams struct {
ClaimDurationOfDecay time.Duration
}

func MainnetGenesisParams() GenesisParams {
genParams := GenesisParams{}

genParams.AirdropSupply = sdk.NewIntWithDecimal(1, 14) // 10^15 uosmo, 10^8 (100 million) osmo
genParams.ChainID = "osmosis-1"
// genParams.GenesisTime = time.Now() // TODO: Finalize date

genParams.NativeCoinMetadata = banktypes.Metadata{
Description: fmt.Sprintf("The native token of Osmosis"),
DenomUnits: []*banktypes.DenomUnit{
{
Denom: BaseCoinUnit,
Exponent: 0,
Aliases: nil,
},
{
Denom: HumanCoinUnit,
Exponent: OsmoExponent,
Aliases: nil,
},
},
Base: BaseCoinUnit,
Display: HumanCoinUnit,
}

genParams.StakingParams = stakingtypes.DefaultParams()
genParams.StakingParams.UnbondingTime = time.Hour * 24 * 7 * 2 // 2 weeks
genParams.StakingParams.MaxValidators = 100
genParams.StakingParams.BondDenom = genParams.NativeCoinMetadata.Base
genParams.StakingParams.MinCommissionRate = sdk.MustNewDecFromStr("0.05")

genParams.MintParams = minttypes.DefaultParams()
genParams.MintParams.EpochIdentifier = "daily" // 1 week
genParams.MintParams.GenesisEpochProvisions = sdk.NewDec(300_000_000).QuoInt64(365) // 300M / 365 = ~821917.8082191781
genParams.MintParams.MintDenom = genParams.NativeCoinMetadata.Base
genParams.MintParams.ReductionFactor = sdk.NewDec(2).QuoInt64(3) // 2/3
genParams.MintParams.ReductionPeriodInEpochs = 365 // 1 year (screw leap years)
genParams.MintParams.DistributionProportions = minttypes.DistributionProportions{
Staking: sdk.MustNewDecFromStr("0.25"), // 25%
DeveloperRewards: sdk.MustNewDecFromStr("0.25"), // 25%
PoolIncentives: sdk.MustNewDecFromStr("0.5"), // 50% TODO: Reduce to 45% once Community Pool Allocation exists
}
genParams.MintParams.MintingRewardsDistributionStartTime = genParams.GenesisTime.Add(24 * time.Hour) // TODO: Finalize
// genParams.MintParams.DeveloperRewardsReceiver

genParams.DistributionParams = distributiontypes.DefaultParams()
genParams.DistributionParams.BaseProposerReward = sdk.MustNewDecFromStr("0.01")
genParams.DistributionParams.BonusProposerReward = sdk.MustNewDecFromStr("0.04")
genParams.DistributionParams.CommunityTax = sdk.MustNewDecFromStr("0")
genParams.DistributionParams.WithdrawAddrEnabled = true

genParams.GovParams = govtypes.DefaultParams()
genParams.GovParams.DepositParams.MaxDepositPeriod = time.Hour * 24 * 14 // 2 weeks
genParams.GovParams.DepositParams.MinDeposit = sdk.NewCoins(sdk.NewCoin(
genParams.NativeCoinMetadata.Base,
genParams.AirdropSupply.QuoRaw(100_000), // 1000 OSMO
))
genParams.GovParams.TallyParams.Quorum = sdk.MustNewDecFromStr("0.25") // 25%
genParams.GovParams.VotingParams.VotingPeriod = time.Hour * 96 // 5 days TODO: Finalize

genParams.CrisisConstantFee = sdk.NewCoin(
genParams.NativeCoinMetadata.Base,
genParams.AirdropSupply.QuoRaw(1_000), // 1/1,000 of airdrop supply TODO: See how crisis invariant fee
)

genParams.SlashingParams = slashingtypes.DefaultParams()
genParams.SlashingParams.SignedBlocksWindow = int64(30000) // 30000 blocks (~25 hr at 3 second blocks)
genParams.SlashingParams.MinSignedPerWindow = sdk.MustNewDecFromStr("0.05") // 5% minimum liveness
genParams.SlashingParams.DowntimeJailDuration = time.Second // 1 second jail period
genParams.SlashingParams.SlashFractionDoubleSign = sdk.MustNewDecFromStr("0.05") // 5% double sign slashing
genParams.SlashingParams.SlashFractionDowntime = sdk.ZeroDec() // 0% liveness slashing

genParams.Epochs = epochstypes.DefaultGenesis().Epochs
for _, epoch := range genParams.Epochs {
epoch.StartTime = genParams.GenesisTime
}

genParams.IncentivesParams = incentivestypes.DefaultParams()
genParams.IncentivesParams.DistrEpochIdentifier = "daily"

genParams.ClaimAirdropStartTime = genParams.GenesisTime
genParams.ClaimDurationUntilDecay = time.Hour * 24 * 60 // 60 days = ~2 months
genParams.ClaimDurationOfDecay = time.Hour * 24 * 120 // 120 days = ~4 months

genParams.ConsensusParams = tmtypes.DefaultConsensusParams()
genParams.ConsensusParams.Evidence.MaxAgeDuration = genParams.StakingParams.UnbondingTime
genParams.ConsensusParams.Evidence.MaxAgeNumBlocks = int64(genParams.StakingParams.UnbondingTime.Seconds()) / 3
genParams.ConsensusParams.Version.AppVersion = 1

return genParams
}

func TestnetGenesisParams() GenesisParams {
testnetGenesisParams := GenesisParams{}

Expand Down
6 changes: 4 additions & 2 deletions cmd/osmosisd/cmd/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import (
"encoding/json"
"fmt"

"github.com/spf13/cobra"

tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/genutil"
"github.com/spf13/cobra"
tmtypes "github.com/tendermint/tendermint/types"

appparams "github.com/osmosis-labs/osmosis/app/params"

Expand Down
169 changes: 169 additions & 0 deletions cmd/osmosisd/cmd/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
package cmd

import (
"bufio"
"encoding/json"
"fmt"
"os"
"path/filepath"
"time"

"github.com/cosmos/go-bip39"
"github.com/pkg/errors"
"github.com/spf13/cobra"

tmcfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/libs/cli"
tmos "github.com/tendermint/tendermint/libs/os"
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/input"
"github.com/cosmos/cosmos-sdk/server"
appcfg "github.com/cosmos/cosmos-sdk/server/config"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/genutil"
)

const (
// FlagOverwrite defines a flag to overwrite an existing genesis JSON file.
FlagOverwrite = "overwrite"

// FlagSeed defines a flag to initialize the private validator key from a specific seed.
FlagRecover = "recover"
)

type printInfo struct {
Moniker string `json:"moniker" yaml:"moniker"`
ChainID string `json:"chain_id" yaml:"chain_id"`
NodeID string `json:"node_id" yaml:"node_id"`
GenTxsDir string `json:"gentxs_dir" yaml:"gentxs_dir"`
AppMessage json.RawMessage `json:"app_message" yaml:"app_message"`
}

func newPrintInfo(moniker, chainID, nodeID, genTxsDir string, appMessage json.RawMessage) printInfo {
return printInfo{
Moniker: moniker,
ChainID: chainID,
NodeID: nodeID,
GenTxsDir: genTxsDir,
AppMessage: appMessage,
}
}

func displayInfo(info printInfo) error {
out, err := json.MarshalIndent(info, "", " ")
if err != nil {
return err
}

_, err = fmt.Fprintf(os.Stderr, "%s\n", string(sdk.MustSortJSON(out)))

return err
}

// InitCmd returns a command that initializes all files needed for Tendermint
// and the respective application.
func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command {
cmd := &cobra.Command{
Use: "init [moniker]",
Short: "Initialize private validator, p2p, genesis, and application configuration files",
Long: `Initialize validators's and node's configuration files.`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
cdc := clientCtx.JSONMarshaler

serverCtx := server.GetServerContextFromCmd(cmd)
config := serverCtx.Config

config.P2P.MaxNumOutboundPeers = 40
config.Mempool.Size = 10000
config.StateSync.TrustPeriod = 112 * time.Hour
config.FastSync.Version = "v2"

config.SetRoot(clientCtx.HomeDir)

appConfig := appcfg.DefaultConfig()
appConfig.API.Enable = true
appConfig.StateSync.SnapshotInterval = 1500
appConfig.StateSync.SnapshotKeepRecent = 2

chainID, _ := cmd.Flags().GetString(flags.FlagChainID)
if chainID == "" {
chainID = fmt.Sprintf("test-chain-%v", tmrand.Str(6))
}

fmt.Println("help")

// Get bip39 mnemonic
var mnemonic string
recover, _ := cmd.Flags().GetBool(FlagRecover)
if recover {
inBuf := bufio.NewReader(cmd.InOrStdin())
mnemonic, err := input.GetString("Enter your bip39 mnemonic", inBuf)
if err != nil {
return err
}

if !bip39.IsMnemonicValid(mnemonic) {
return errors.New("invalid mnemonic")
}
}

nodeID, _, err := genutil.InitializeNodeValidatorFilesFromMnemonic(config, mnemonic)
if err != nil {
return err
}

config.Moniker = args[0]

genFile := config.GenesisFile()
overwrite, _ := cmd.Flags().GetBool(FlagOverwrite)

if !overwrite && tmos.FileExists(genFile) {
return fmt.Errorf("genesis.json file already exists: %v", genFile)
}
appState, err := json.MarshalIndent(mbm.DefaultGenesis(cdc), "", " ")
if err != nil {
return errors.Wrap(err, "Failed to marshall default genesis state")
}

genDoc := &types.GenesisDoc{}
if _, err := os.Stat(genFile); err != nil {
if !os.IsNotExist(err) {
return err
}
} else {
genDoc, err = types.GenesisDocFromFile(genFile)
if err != nil {
return errors.Wrap(err, "Failed to read genesis doc from file")
}
}

genDoc.ChainID = chainID
genDoc.Validators = nil
genDoc.AppState = appState
if err = genutil.ExportGenesisFile(genDoc, genFile); err != nil {
return errors.Wrap(err, "Failed to export gensis file")
}

toPrint := newPrintInfo(config.Moniker, chainID, nodeID, "", appState)

tmcfg.WriteConfigFile(filepath.Join(config.RootDir, "config", "config.toml"), config)
appcfg.WriteConfigFile(filepath.Join(config.RootDir, "config", "app.toml"), appConfig)

return displayInfo(toPrint)
},
}

cmd.Flags().String(cli.HomeFlag, defaultNodeHome, "node's home directory")
cmd.Flags().BoolP(FlagOverwrite, "o", false, "overwrite the genesis.json file")
cmd.Flags().Bool(FlagRecover, false, "provide seed phrase to recover existing key instead of creating")
cmd.Flags().String(flags.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created")

return cmd
}
3 changes: 2 additions & 1 deletion cmd/osmosisd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
authclient.Codec = encodingConfig.Marshaler

rootCmd.AddCommand(
genutilcli.InitCmd(osmosis.ModuleBasics, osmosis.DefaultNodeHome),
// genutilcli.InitCmd(osmosis.ModuleBasics, osmosis.DefaultNodeHome),
InitCmd(osmosis.ModuleBasics, osmosis.DefaultNodeHome),
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, osmosis.DefaultNodeHome),
genutilcli.MigrateGenesisCmd(),
genutilcli.GenTxCmd(osmosis.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, osmosis.DefaultNodeHome),
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ module github.com/osmosis-labs/osmosis
go 1.15

require (
github.com/cosmos/cosmos-sdk v0.42.5
github.com/cosmos/cosmos-sdk v0.42.4
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/iavl v0.15.3
github.com/gogo/protobuf v1.3.3
github.com/golang/mock v1.4.4
github.com/golang/protobuf v1.5.1
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/pkg/errors v0.9.1
github.com/rakyll/statik v0.1.7
github.com/regen-network/cosmos-proto v0.3.1
github.com/spf13/cast v1.3.1
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,6 @@ github.com/tendermint/tendermint v0.34.0-rc6/go.mod h1:ugzyZO5foutZImv0Iyx/gOFCX
github.com/tendermint/tendermint v0.34.0/go.mod h1:Aj3PIipBFSNO21r+Lq3TtzQ+uKESxkbA3yo/INM4QwQ=
github.com/tendermint/tendermint v0.34.9 h1:9P2MXDEPOcPW0NBcHQ/HDSfvczZm+q5nUUw7AZ6f1Vc=
github.com/tendermint/tendermint v0.34.9/go.mod h1:kl4Z1JwGx1I+u1SXIzMDy7Z3T8LiMeCAOnzNn6AIMT4=
github.com/tendermint/tendermint v0.34.10 h1:wBOc/It8sh/pVH9np2V5fBvRmIyFN/bUrGPx+eAHexs=
github.com/tendermint/tm-db v0.6.2/go.mod h1:GYtQ67SUvATOcoY8/+x6ylk8Qo02BQyLrAs+yAcLvGI=
github.com/tendermint/tm-db v0.6.3/go.mod h1:lfA1dL9/Y/Y8wwyPp2NMLyn5P5Ptr/gvDFNWtrCWSf8=
github.com/tendermint/tm-db v0.6.4 h1:3N2jlnYQkXNQclQwd/eKV/NzlqPlfK21cpRRIx80XXQ=
Expand Down

0 comments on commit 9ea50ad

Please sign in to comment.