Skip to content

Commit

Permalink
v5 incentives/gravity rc1 (#201)
Browse files Browse the repository at this point in the history
* v5 upgrade with only incentives and gravity updates

* go.mod major version v4 -> v5

* go 1.15 -> 1.16

* Update prost_build and somm_proto

* Generate somm_proto for v5

* Fix proto import path bug and regenerate protos

* Fix linter

* Pin to ubuntu version in releaser

* Set incentives cutoff height
  • Loading branch information
EricBolten authored Feb 18, 2023
1 parent 318442d commit 7e2062d
Show file tree
Hide file tree
Showing 93 changed files with 3,677 additions and 288 deletions.
1 change: 1 addition & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ jobs:
test_type: [
"Cork",
"ScheduledCork",
"Incentives",
]
steps:
# Not needed on self hosted test runner that already has go installed
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 6
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.16
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v4
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- uses: golangci/golangci-lint-action@master
- uses: golangci/golangci-lint-action@v3
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.37
skip-go-installation: true
args: --timeout 10m
github-token: ${{ secrets.github_token }}
if: env.GIT_DIFF
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

jobs:
goreleaser:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/[email protected]
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Unit tests

on:
push:
branches:
- main
tags:
- "v*.*.*"
pull_request:

jobs:
test:
strategy:
matrix:
go-version: [1.16]
os: [ubuntu-latest]
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v3
- run: go test github.com/peggyjv/sommelier/.../x/...
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ e2e_cork_test: e2e_clean_slate
e2e_scheduled_cork_test: e2e_clean_slate
@E2E_SKIP_CLEANUP=true integration_tests/integration_tests.test -test.failfast -test.v -test.run IntegrationTestSuite -testify.m TestScheduledCork || make -s fail

e2e_incentives_test: e2e_clean_slate
@E2E_SKIP_CLEANUP=true integration_tests/integration_tests.test -test.failfast -test.v -test.run IntegrationTestSuite -testify.m TestIncentives || make -s fail

fail:
@echo 'test failed; dumping container logs into ./testlogs for review'
@docker logs ethereum > testlogs/ethereum.log 2>&1 || true
Expand Down
72 changes: 53 additions & 19 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,19 @@ import (
gravityclient "github.com/peggyjv/gravity-bridge/module/v2/x/gravity/client"
gravitykeeper "github.com/peggyjv/gravity-bridge/module/v2/x/gravity/keeper"
gravitytypes "github.com/peggyjv/gravity-bridge/module/v2/x/gravity/types"
appParams "github.com/peggyjv/sommelier/v4/app/params"
v4 "github.com/peggyjv/sommelier/v4/app/upgrades/v4"
"github.com/peggyjv/sommelier/v4/x/cellarfees"
cellarfeeskeeper "github.com/peggyjv/sommelier/v4/x/cellarfees/keeper"
cellarfeestypes "github.com/peggyjv/sommelier/v4/x/cellarfees/types"
"github.com/peggyjv/sommelier/v4/x/cork"
corkclient "github.com/peggyjv/sommelier/v4/x/cork/client"
corkkeeper "github.com/peggyjv/sommelier/v4/x/cork/keeper"
corktypes "github.com/peggyjv/sommelier/v4/x/cork/types"
appParams "github.com/peggyjv/sommelier/v5/app/params"
v4 "github.com/peggyjv/sommelier/v5/app/upgrades/v4"
v5 "github.com/peggyjv/sommelier/v5/app/upgrades/v5"
"github.com/peggyjv/sommelier/v5/x/cellarfees"
cellarfeeskeeper "github.com/peggyjv/sommelier/v5/x/cellarfees/keeper"
cellarfeestypes "github.com/peggyjv/sommelier/v5/x/cellarfees/types"
"github.com/peggyjv/sommelier/v5/x/cork"
corkclient "github.com/peggyjv/sommelier/v5/x/cork/client"
corkkeeper "github.com/peggyjv/sommelier/v5/x/cork/keeper"
corktypes "github.com/peggyjv/sommelier/v5/x/cork/types"
"github.com/peggyjv/sommelier/v5/x/incentives"
incentiveskeeper "github.com/peggyjv/sommelier/v5/x/incentives/keeper"
incentivestypes "github.com/peggyjv/sommelier/v5/x/incentives/types"
"github.com/rakyll/statik/fs"
abci "github.com/tendermint/tendermint/abci/types"
tmjson "github.com/tendermint/tendermint/libs/json"
Expand Down Expand Up @@ -153,6 +157,7 @@ var (
gravity.AppModuleBasic{},
cork.AppModuleBasic{},
cellarfees.AppModuleBasic{},
incentives.AppModuleBasic{},
)

// module account permissions
Expand All @@ -166,6 +171,7 @@ var (
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
gravitytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
cellarfeestypes.ModuleName: nil,
incentivestypes.ModuleName: nil,
}

// module accounts that are allowed to receive tokens
Expand Down Expand Up @@ -213,6 +219,7 @@ type SommelierApp struct {
// Sommelier keepers
CorkKeeper corkkeeper.Keeper
CellarFeesKeeper cellarfeeskeeper.Keeper
IncentivesKeeper incentiveskeeper.Keeper

// make capability scoped keepers public for test purposes (IBC only)
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -257,6 +264,7 @@ func NewSommelierApp(
govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
gravitytypes.StoreKey, feegrant.StoreKey, authzkeeper.StoreKey, corktypes.StoreKey,
incentivestypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -358,6 +366,10 @@ func NewSommelierApp(
app.AccountKeeper, app.BankKeeper,
)

app.IncentivesKeeper = incentiveskeeper.NewKeeper(
appCodec, keys[incentivestypes.StoreKey], app.GetSubspace(incentivestypes.ModuleName), app.DistrKeeper, app.BankKeeper, app.MintKeeper,
)

app.GravityKeeper = *app.GravityKeeper.SetHooks(
gravitytypes.NewMultiGravityHooks(
app.CorkKeeper.Hooks(),
Expand Down Expand Up @@ -398,9 +410,6 @@ func NewSommelierApp(
skipGenesisInvariants = opt
}

// NOTE: Any module instantiated in the module manager that is later modified
// must be passed by reference here.

// NOTE: Any module instantiated in the module manager that is later modified
// must be passed by reference here.
app.mm = module.NewManager(
Expand All @@ -412,7 +421,6 @@ func NewSommelierApp(
vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
capability.NewAppModule(appCodec, *app.CapabilityKeeper),

crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
Expand All @@ -429,6 +437,7 @@ func NewSommelierApp(
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
cork.NewAppModule(app.CorkKeeper, appCodec),
cellarfees.NewAppModule(app.CellarFeesKeeper, appCodec, app.AccountKeeper, app.BankKeeper),
incentives.NewAppModule(app.IncentivesKeeper, app.DistrKeeper, app.BankKeeper, app.MintKeeper, appCodec),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand All @@ -440,13 +449,13 @@ func NewSommelierApp(
upgradetypes.ModuleName, capabilitytypes.ModuleName, minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName,
evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName, ibctransfertypes.ModuleName, authtypes.ModuleName,
banktypes.ModuleName, govtypes.ModuleName, crisistypes.ModuleName, genutiltypes.ModuleName, authz.ModuleName, feegrant.ModuleName,
paramstypes.ModuleName, gravitytypes.ModuleName, corktypes.ModuleName, cellarfeestypes.ModuleName,
paramstypes.ModuleName, incentivestypes.ModuleName, gravitytypes.ModuleName, corktypes.ModuleName, cellarfeestypes.ModuleName,
)
app.mm.SetOrderEndBlockers(
crisistypes.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName, ibctransfertypes.ModuleName,
capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName,
minttypes.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName, feegrant.ModuleName, paramstypes.ModuleName,
upgradetypes.ModuleName, gravitytypes.ModuleName, corktypes.ModuleName, cellarfeestypes.ModuleName,
upgradetypes.ModuleName, incentivestypes.ModuleName, gravitytypes.ModuleName, corktypes.ModuleName, cellarfeestypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand All @@ -459,7 +468,7 @@ func NewSommelierApp(
stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName,
crisistypes.ModuleName, ibchost.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName,
ibctransfertypes.ModuleName, gravitytypes.ModuleName, authz.ModuleName,
feegrant.ModuleName, corktypes.ModuleName, cellarfeestypes.ModuleName,
feegrant.ModuleName, incentivestypes.ModuleName, corktypes.ModuleName, cellarfeestypes.ModuleName,
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
Expand Down Expand Up @@ -489,6 +498,7 @@ func NewSommelierApp(
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
cork.NewAppModule(app.CorkKeeper, appCodec),
cellarfees.NewAppModule(app.CellarFeesKeeper, appCodec, app.AccountKeeper, app.BankKeeper),
incentives.NewAppModule(app.IncentivesKeeper, app.DistrKeeper, app.BankKeeper, app.MintKeeper, appCodec),
)

app.sm.RegisterStoreDecoders()
Expand Down Expand Up @@ -720,6 +730,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(gravitytypes.ModuleName)
paramsKeeper.Subspace(corktypes.ModuleName)
paramsKeeper.Subspace(cellarfeestypes.ModuleName)
paramsKeeper.Subspace(incentivestypes.ModuleName)

return paramsKeeper
}
Expand All @@ -730,13 +741,27 @@ func (app *SommelierApp) setupUpgradeStoreLoaders() {
panic(fmt.Sprintf("failed to read upgrade info from disk %s", err))
}

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

var storeUpgrades *store.StoreUpgrades = nil

if upgradeInfo.Name == v4.UpgradeName {
storeUpgrades = &store.StoreUpgrades{
Added: []string{corktypes.ModuleName, cellarfeestypes.ModuleName},
Deleted: []string{"allocation"},
}
}

app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
if upgradeInfo.Name == v5.UpgradeName {
storeUpgrades = &store.StoreUpgrades{
Added: []string{incentivestypes.ModuleName},
}
}

if storeUpgrades != nil {
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, storeUpgrades))
}
}

Expand All @@ -750,4 +775,13 @@ func (app *SommelierApp) setupUpgradeHandlers() {
app.BankKeeper,
),
)

app.UpgradeKeeper.SetUpgradeHandler(
v5.UpgradeName,
v5.CreateUpgradeHandler(
app.mm,
app.configurator,
app.IncentivesKeeper,
),
)
}
2 changes: 1 addition & 1 deletion app/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app

import (
"github.com/cosmos/cosmos-sdk/std"
"github.com/peggyjv/sommelier/v4/app/params"
"github.com/peggyjv/sommelier/v5/app/params"
)

// MakeEncodingConfig creates an EncodingConfig for testing. This function
Expand Down
2 changes: 1 addition & 1 deletion app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"testing"

sommelier "github.com/peggyjv/sommelier/v4/app"
sommelier "github.com/peggyjv/sommelier/v5/app"

"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
Expand Down
4 changes: 2 additions & 2 deletions app/upgrades/v4/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
gravitytypes "github.com/peggyjv/gravity-bridge/module/v2/x/gravity/types"
cellarfeestypes "github.com/peggyjv/sommelier/v4/x/cellarfees/types"
corktypes "github.com/peggyjv/sommelier/v4/x/cork/types"
cellarfeestypes "github.com/peggyjv/sommelier/v5/x/cellarfees/types"
corktypes "github.com/peggyjv/sommelier/v5/x/cork/types"
)

func CreateUpgradeHandler(
Expand Down
8 changes: 8 additions & 0 deletions app/upgrades/v5/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# v5 upgrade

This upgrade moves Sommelier to major version 5.

## Summary of changes

* Add the incentives module to provide a way of distributing community pool funds on a per-block, pro-rata basis to incentivize stakers while cellar TVL is built over time into a meaningful staking return
* Pin to a version of the gravity module with ledger support
4 changes: 4 additions & 0 deletions app/upgrades/v5/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package v5

// UpgradeName defines the on-chain upgrade name for the Sommelier v5 upgrade
const UpgradeName = "v5"
47 changes: 47 additions & 0 deletions app/upgrades/v5/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package v5

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
appparams "github.com/peggyjv/sommelier/v5/app/params"
incentiveskeeper "github.com/peggyjv/sommelier/v5/x/incentives/keeper"
incentivestypes "github.com/peggyjv/sommelier/v5/x/incentives/types"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
incentivesKeeper incentiveskeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("v5 upgrade: entering handler")

// We must manually run InitGenesis for incentives so we can adjust their values during the upgrade process.
// Setting the consensus version to 1 prevents RunMigrations from running InitGenesis itself.
fromVM[incentivestypes.ModuleName] = mm.Modules[incentivestypes.ModuleName].ConsensusVersion()

ctx.Logger().Info("v5 upgrade: initializing incentives genesis state")
incentivesInitGenesis(ctx, incentivesKeeper)

ctx.Logger().Info("v5 upgrade: running migrations and exiting handler")
return mm.RunMigrations(ctx, configurator, fromVM)
}
}

// Launch the incentives module with 2 SOMM per block distribution and a cutoff height 5 million blocks past
// the upgrade height
func incentivesInitGenesis(ctx sdk.Context, incentivesKeeper incentiveskeeper.Keeper) {
genesisState := incentivestypes.DefaultGenesisState()

upgradeHeight := uint64(7766725)
incentivesBlocks := uint64(5000000)

params := incentivestypes.Params{
DistributionPerBlock: sdk.NewCoin(appparams.BaseCoinUnit, sdk.NewInt(2000000)),
IncentivesCutoffHeight: upgradeHeight + incentivesBlocks,
}
genesisState.Params = params

incentiveskeeper.InitGenesis(ctx, incentivesKeeper, genesisState)
}
4 changes: 2 additions & 2 deletions cmd/sommelier/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
dbm "github.com/tendermint/tm-db"

bridgecmd "github.com/peggyjv/gravity-bridge/module/v2/cmd/gravity/cmd"
"github.com/peggyjv/sommelier/v4/app"
"github.com/peggyjv/sommelier/v4/app/params"
"github.com/peggyjv/sommelier/v5/app"
"github.com/peggyjv/sommelier/v5/app/params"
)

// NewRootCmd creates a new root command for simd. It is called once in the
Expand Down
4 changes: 2 additions & 2 deletions cmd/sommelier/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (

"github.com/cosmos/cosmos-sdk/server"
scmd "github.com/cosmos/cosmos-sdk/server/cmd"
"github.com/peggyjv/sommelier/v4/app"
"github.com/peggyjv/sommelier/v4/cmd/sommelier/cmd"
"github.com/peggyjv/sommelier/v5/app"
"github.com/peggyjv/sommelier/v5/cmd/sommelier/cmd"
)

func main() {
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/peggyjv/sommelier/v4
module github.com/peggyjv/sommelier/v5

go 1.15
go 1.16

require (
github.com/StackExchange/wmi v1.2.1 // indirect
Expand All @@ -9,14 +9,15 @@ require (
github.com/cosmos/ibc-go/v2 v2.0.0
github.com/ethereum/go-ethereum v1.10.11
github.com/gogo/protobuf v1.3.3
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.2
github.com/google/uuid v1.2.0 // indirect
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/miguelmota/go-ethereum-hdwallet v0.1.1
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
github.com/ory/dockertest/v3 v3.8.1
github.com/peggyjv/gravity-bridge/module/v2 v2.0.2
github.com/peggyjv/gravity-bridge/module/v2 v2.0.3-0.20230113013243-7ce6b3c12502
github.com/rakyll/statik v0.1.7
github.com/regen-network/cosmos-proto v0.3.1
github.com/spf13/cast v1.4.1
Expand Down
Loading

0 comments on commit 7e2062d

Please sign in to comment.