Skip to content

Commit

Permalink
Merge pull request #8 from onomyprotocol/aaron-main-dev
Browse files Browse the repository at this point in the history
Aaron main dev
  • Loading branch information
AaronKutch authored Oct 3, 2023
2 parents c846387 + 2a3aabc commit 967bf0e
Show file tree
Hide file tree
Showing 18 changed files with 49,188 additions and 146 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
uses: actions/checkout@v2
- name: test suite
run: |
go test ./...
make test
rust_tests:
runs-on: ubuntu-latest
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ jobs:

- name: Build
run: |
go build ./cmd/consumer-democracy
mv ./consumer-democracy appnamed
make build
- name: Upload
id: upload-release-asset
uses: actions/upload-release-asset@v1
Expand Down
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@
/vendor
/target
/Cargo.lock
/consumer-democracy
/consumer
/standalone
/appnamed
55 changes: 3 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,8 @@

# Multiverse

This repo is used as the common base for Onomy network consumer chains.
This repo is used as a common base for Onomy network consumer chains. The `main` branch is a generic chain with no special modules, other branches add on their own special functionalities.

# Creating a consumer chain on testnet
Run `make build` to build the binary.

Someone runs a test chain until after the proposal is complete, and runs `cosmovisor run query provider consumer genesis [consumer chain id]` to get an example consumer chain genesis. "soft_opt_out_threshold", "provider_reward_denoms", and "reward_denoms" currently have to be manually set in the consumer genesis file bcause of technical reasons (a future ICS upgrade will fix this). We agree on a genesis template and a corresponding proposal.

Someone runs a "consumer-addition" proposal with the argument file
```
{
"title": "Propose the addition of a new chain",
"description": "Add the [name] consumer chain",
"chain_id": "[chain-id]",
"initial_height": {
"revision_number": 0,
"revision_height": 1
},
"genesis_hash": "Z2VuX2hhc2g=",
"binary_hash": "YmluX2hhc2g=",
"spawn_time": "2023-05-18T01:15:49.83019476-05:00",
"unbonding_period": 1728000000000000,
"consumer_redistribution_fraction": "0.5",
"provider_reward_denoms": ["anom"],
"reward_denoms": ["anative"],
"blocks_per_distribution_transmission": 1000,
"soft_opt_out_threshold": "0.0",
"historical_entries": 10000,
"ccv_timeout_period": 2419200000000000,
"transfer_timeout_period": 3600000000000,
"deposit": "500000000000000000000anom"
}
```
- "genesis_hash" is used for off-chain confirmation of the genesis state without CCV module params (e.x. `cat genesis.json | openssl dgst -binary -sha256 | openssl base64 -A`)
- "binary_hash" is used for off-chain confirmation of the hash of the initialization binary
- "spawn_time" is the time at which validators will be responsible for starting their consumer binaries
- "unbonding_period" is the unbonding period, should be less than the unbonding period for the provider (e.x. 24 hours less than the standard 21 days)
- "ccv_timeout_period" timeout period of CCV related IBC packets
- "transfer_timeout_period" timeout period of transfer related IBC packets
- "consumer_redistribution_fraction": "0.75" means that 75% of distribution events will be allocated to be sent back to the provider through the `cons_redistribute` address
- "soft_opt_out_threshold" should only be nonzero on really large PoS provider chains that want to be easier on smaller validators, Onomy is more strict
- "deposit" the deposit is included with the proposal command, which is 500 NOM for Onomy

After the proposal passes, each validator needs to run
`cosmovisor run tx provider assign-consensus-key [consumer chain id] [tendermint key] [flags]`
where the tendermint key could be from `cosmovisor run tendermint show-validator` if the same key is going to be used for the consumer node.
e.x.
`cosmovisor run tx provider assign-consensus-key haven '{"@type":"/cosmos.crypto.ed25519.PubKey","key":"2YSpwSW4FhMxIOhBmGpyyLGIDKszRA1v+HSRPuMMcQk="}' --fees 1000000anom -y -b block --from validator`

If the consumer chain has its own staking coin, a team member needs to run `cosmovisor run tx provider register-consumer-reward-denom [IBC-version-of-consumer-reward-denom]` in order for redistribution to start working later.

After a supermajority of validators assign their consensus keys, we run `cosmovisor run query provider consumer genesis [consumer chain id]` to get the real CCV state and insert it into the consumer genesis. The params are missing "soft_opt_out_threshold", "provider_reward_denoms", and "reward_denoms" again so those need to be added. Validators need to get their consumer nodes ready with this complete genesis and the same tendermint keys that they assigned earlier.

Upon chain start, a team member will initialize the ICS channels, the transfer channel of which will be the canonical IBC NOM channel. Bootstrap is complete and normal transactions can start once the first CCV packets start arriving (else you will receive "tx contains unsupported message types" errors).

Validators also need to bond their consumer-side validators with `cosmovisor run tx staking create-validator` with their consumer node tendermint keys (their nodes will work without this, but the consumer-side governance will use consumer-side staked tokens for determining voting weights). In a future version of ICS, if the consumer chain does not have its own staking denom, we will probably incorporate provider-driven governance for binary upgrades and some parameter changes.
See `/tests` for more info
66 changes: 35 additions & 31 deletions app/consumer-democracy/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"os"
"path/filepath"

// v0 "github.com/onomyprotocol/multiverse/app/consumer-democracy/upgrades/"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
Expand All @@ -18,7 +20,7 @@ import (
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/simapp"
store "github.com/cosmos/cosmos-sdk/store/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
Expand Down Expand Up @@ -65,7 +67,6 @@ import (
ibctransferkeeper "github.com/cosmos/ibc-go/v4/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v4/modules/core"
ibcconnectiontypes "github.com/cosmos/ibc-go/v4/modules/core/03-connection/types"
porttypes "github.com/cosmos/ibc-go/v4/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v4/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v4/modules/core/keeper"
Expand Down Expand Up @@ -109,11 +110,12 @@ import (

// unnamed import of statik for swagger UI support
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"
"github.com/onomyprotocol/multiverse/docs"
"github.com/tendermint/starport/starport/pkg/openapiconsole"
)

const (
AppName = "appname"
upgradeName = "v0.1.0"
AccountAddressPrefix = "onomy"
)

Expand Down Expand Up @@ -622,34 +624,7 @@ func New(
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)

app.UpgradeKeeper.SetUpgradeHandler(
upgradeName,
func(ctx sdk.Context, _ upgradetypes.Plan, _ module.VersionMap) (module.VersionMap, error) {
app.IBCKeeper.ConnectionKeeper.SetParams(ctx, ibcconnectiontypes.DefaultParams())

fromVM := make(map[string]uint64)

for moduleName, eachModule := range app.MM.Modules {
fromVM[moduleName] = eachModule.ConsensusVersion()
}

ctx.Logger().Info("start to run module migrations...")

return app.MM.RunMigrations(ctx, app.configurator, fromVM)
},
)

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Sprintf("failed to read upgrade info from disk %s", err))
}

if upgradeInfo.Name == upgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := store.StoreUpgrades{}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
app.setupUpgradeHandlers()

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
Expand Down Expand Up @@ -848,6 +823,10 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig
ModuleBasics.RegisterRESTRoutes(clientCtx, apiSvr.Router)
ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// register app's OpenAPI routes.
apiSvr.Router.Handle("/static/openapi.yml", http.FileServer(http.FS(docs.Docs)))
apiSvr.Router.HandleFunc("/", openapiconsole.Handler(AppName, "/static/openapi.yml"))

// register swagger API from root so that other applications can override easily
if apiConfig.Swagger {
RegisterSwaggerAPI(apiSvr.Router)
Expand Down Expand Up @@ -902,3 +881,28 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino

return paramsKeeper
}

func (app *App) setupUpgradeHandlers() {
// app.UpgradeKeeper.SetUpgradeHandler(v0.Name, v0.UpgradeHandler)

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Errorf("failed to read upgrade info from disk: %w", err))
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
if app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
return
}

var storeUpgrades *storetypes.StoreUpgrades

switch upgradeInfo.Name {
default:
// no store upgrades
}

if storeUpgrades != nil {
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, storeUpgrades))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/params/types/proposal"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
app "github.com/onomyprotocol/multiverse/app/consumer-democracy"
"github.com/onomyprotocol/multiverse/app/consumer-democracy/consumer-democracy-ante"
ante "github.com/onomyprotocol/multiverse/app/consumer-democracy/consumer-democracy-ante"
"github.com/stretchr/testify/require"
"github.com/tendermint/spm/cosmoscmd"
)
Expand Down Expand Up @@ -68,6 +69,22 @@ func TestForbiddenProposalsDecorator(t *testing.T) {
},
expectErr: true,
},
{
name: "Upgrade Proposal",
ctx: sdk.Context{},
msgs: []sdk.Msg{
newUpgradeProposalMsg(),
},
expectErr: false,
},
{
name: "Cancel Upgrade Proposal",
ctx: sdk.Context{},
msgs: []sdk.Msg{
newCancelUpgradeProposalMsg(),
},
expectErr: false,
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -95,3 +112,15 @@ func newParamChangeProposalMsg(changes []proposal.ParamChange) *govtypes.MsgSubm
msg, _ := govtypes.NewMsgSubmitProposal(&paramChange, sdk.NewCoins(), sdk.AccAddress{})
return msg
}

func newUpgradeProposalMsg() *govtypes.MsgSubmitProposal {
upgrade := upgradetypes.SoftwareUpgradeProposal{}
msg, _ := govtypes.NewMsgSubmitProposal(&upgrade, sdk.NewCoins(), sdk.AccAddress{})
return msg
}

func newCancelUpgradeProposalMsg() *govtypes.MsgSubmitProposal {
upgrade := upgradetypes.CancelSoftwareUpgradeProposal{}
msg, _ := govtypes.NewMsgSubmitProposal(&upgrade, sdk.NewCoins(), sdk.AccAddress{})
return msg
}
5 changes: 5 additions & 0 deletions app/consumer-democracy/proposals_whitelisting.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/cosmos/cosmos-sdk/x/params/types/proposal"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ibctransfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types"
consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types"
)
Expand All @@ -16,6 +17,10 @@ func IsProposalWhitelisted(content govtypes.Content) bool {
switch c := content.(type) {
case *proposal.ParameterChangeProposal:
return isParamChangeWhitelisted(c.Changes)
case *upgradetypes.SoftwareUpgradeProposal:
return true
case *upgradetypes.CancelSoftwareUpgradeProposal:
return true

default:
return false
Expand Down
10 changes: 10 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package docs

import "embed"

//go:embed static
var Docs embed.FS

// NOTE: to regenerate openapi.yml, `rm -rf vendor`,
// use Ignite v0.23.0 (do not use later versions until we
// upgrade past .45) and `ignite generate openapi`
Loading

0 comments on commit 967bf0e

Please sign in to comment.