Skip to content
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: upgrade to cosmos v50 #1833

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
5d37557
WIP
Nov 25, 2024
aed37e0
fix errors in app.go
Dec 9, 2024
a5b90c8
WIP
Dec 9, 2024
6a31f54
WIP
Dec 9, 2024
3bdc6ae
fix all bond denom
Dec 10, 2024
cd2a8d5
WIP
Dec 10, 2024
a598996
update proto files types
Dec 10, 2024
88e9c23
WIP
Dec 10, 2024
a03db32
remove legacy handlers
Dec 10, 2024
ca91754
WIP
Dec 10, 2024
6dc16a4
fix simulations
Dec 10, 2024
fb3ee7b
fix simulations
Dec 10, 2024
c9b14b1
fix equal method for coins
Dec 10, 2024
f2f47ef
WIP
Dec 10, 2024
e48f10c
WIP
Dec 10, 2024
c2e0613
mock keepers
Dec 10, 2024
52e10b9
fix test keepers
Dec 10, 2024
9fa7393
tidy
Dec 10, 2024
6156c2b
remove the use of "core"
Dec 12, 2024
2c5c1b1
module basic
Dec 12, 2024
29345bd
lint
Dec 12, 2024
ab7c0f3
add auto cli
Dec 12, 2024
964bfb3
remove old proto files
Dec 12, 2024
6680e44
update config use of lavad
Dec 12, 2024
f66fabb
fix signing methods
Dec 12, 2024
ce24ff2
update genesis file util
Dec 12, 2024
b3e27e5
now upgrade works
Dec 12, 2024
814ff12
fixed CLI
Dec 13, 2024
eb137c9
remove get signedbytes method from tx
Dec 13, 2024
a6c4b28
fix subscription tx.proto
Dec 13, 2024
8c098e4
now init chain commands works!
Dec 13, 2024
6eaebcf
remove getsigners methods
Dec 13, 2024
5eb2d82
fix tests
Dec 13, 2024
6b55d8c
remove addquery/txcommands
Dec 13, 2024
449b14c
add module assertions
Dec 15, 2024
0d5750d
add ibc to allowed expedited proposals
Dec 15, 2024
a8f17c4
lint
Dec 15, 2024
d3caa02
lint
Dec 15, 2024
4316577
Merge branch 'main' into CNS-cosmos-50-upgrade
Dec 15, 2024
70898dc
generate protobufs
Dec 15, 2024
b01ea2b
Revert "remove addquery/txcommands"
Dec 15, 2024
97087ee
TODOs
Dec 16, 2024
2d9987e
Merge branch 'main' into CNS-cosmos-50-upgrade
Dec 16, 2024
67c7f0b
make sort specs onchain
Dec 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions app/ante.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package app

import (
txsigning "cosmossdk.io/x/tx/signing"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/cosmos/cosmos-sdk/x/auth/signing"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
dualstakingante "github.com/lavanet/lava/v4/x/dualstaking/ante"
dualstakingkeeper "github.com/lavanet/lava/v4/x/dualstaking/keeper"
specante "github.com/lavanet/lava/v4/x/spec/ante"
"github.com/lavanet/lava/v4/x/spec/keeper"
)

func NewAnteHandler(accountKeeper ante.AccountKeeper, bankKeeper authtypes.BankKeeper, dualstakingKeeper dualstakingkeeper.Keeper, signModeHandler signing.SignModeHandler, feegrantKeeper ante.FeegrantKeeper, specKeeper keeper.Keeper, sigGasConsumer ante.SignatureVerificationGasConsumer) sdk.AnteHandler {
func NewAnteHandler(accountKeeper ante.AccountKeeper, bankKeeper authtypes.BankKeeper, dualstakingKeeper dualstakingkeeper.Keeper, signModeHandler *txsigning.HandlerMap, feegrantKeeper ante.FeegrantKeeper, specKeeper keeper.Keeper, sigGasConsumer ante.SignatureVerificationGasConsumer) sdk.AnteHandler {
anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
ante.NewExtensionOptionsDecorator(nil),
Expand Down
267 changes: 164 additions & 103 deletions app/app.go

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions app/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package app

import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/std"
"github.com/cosmos/cosmos-sdk/x/auth/tx"

Expand All @@ -12,7 +11,7 @@ import (
// makeEncodingConfig creates an EncodingConfig for an amino based test configuration.
func makeEncodingConfig() params.EncodingConfig {
amino := codec.NewLegacyAmino()
interfaceRegistry := types.NewInterfaceRegistry()
interfaceRegistry := params.MakeEncodingConfig().InterfaceRegistry
marshaler := codec.NewProtoCodec(interfaceRegistry)
txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes)

Expand All @@ -29,7 +28,7 @@ func MakeEncodingConfig() params.EncodingConfig {
encodingConfig := makeEncodingConfig()
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
// ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)
return encodingConfig
}
159 changes: 13 additions & 146 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package app

import (
"encoding/json"
"log"
"fmt"

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

servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

// ExportAppStateAndValidators(
Expand All @@ -21,171 +19,40 @@ import (
// ExportAppStateAndValidators exports the state of the application for a genesis
// file.
func (app *LavaApp) ExportAppStateAndValidators(
forZeroHeight bool, jailAllowedAddrs []string,
modulesToExport []string,
forZeroHeight bool, jailAllowedAddrs []string, modulesToExport []string,
) (servertypes.ExportedApp, error) {
// as if they could withdraw from the start of the next block
ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})
ctx := app.NewContextLegacy(true, tmproto.Header{Height: app.LastBlockHeight()})

// We export at last height + 1, because that's the height at which
// Tendermint will start InitChain.
height := app.LastBlockHeight() + 1
if forZeroHeight {
height = 0
app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs)
return servertypes.ExportedApp{}, fmt.Errorf("forZeroHeight not supported")
}

genState := app.mm.ExportGenesisForModules(ctx, app.appCodec, modulesToExport)
appState, err := json.MarshalIndent(genState, "", " ")
genState, err := app.mm.ExportGenesisForModules(ctx, app.appCodec, modulesToExport)
if err != nil {
return servertypes.ExportedApp{}, err
}

validators, err := staking.WriteValidators(ctx, app.StakingKeeper)
appState, err := json.MarshalIndent(genState, "", " ")
if err != nil {
return servertypes.ExportedApp{}, err
}

validators, err := staking.WriteValidators(ctx, app.StakingKeeper)
return servertypes.ExportedApp{
AppState: appState,
Validators: validators,
Height: height,
ConsensusParams: app.BaseApp.GetConsensusParams(ctx),
}, nil
}, err
}

// prepare for fresh start at zero height
// NOTE zero height genesis is a temporary feature which will be deprecated
//
// in favour of export at a block height
func (app *LavaApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) {
applyAllowedAddrs := false

// check if there is a allowed address list
if len(jailAllowedAddrs) > 0 {
applyAllowedAddrs = true
}

allowedAddrsMap := make(map[string]bool)

for _, addr := range jailAllowedAddrs {
_, err := sdk.ValAddressFromBech32(addr)
if err != nil {
log.Fatal(err)
}
allowedAddrsMap[addr] = true
}

/* Just to be safe, assert the invariants on current state. */
app.CrisisKeeper.AssertInvariants(ctx)

/* Handle fee distribution state. */

// withdraw all validator commission
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
_, err := app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
if err != nil {
panic(err)
}
return false
})

// withdraw all delegator rewards
dels := app.StakingKeeper.GetAllDelegations(ctx)
for _, delegation := range dels {
_, err := app.DistrKeeper.WithdrawDelegationRewards(ctx, delegation.GetDelegatorAddr(), delegation.GetValidatorAddr())
if err != nil {
panic(err)
}
}

// clear validator slash events
app.DistrKeeper.DeleteAllValidatorSlashEvents(ctx)

// clear validator historical rewards
app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx)

// set context height to zero
height := ctx.BlockHeight()
ctx = ctx.WithBlockHeight(0)

// reinitialize all validators
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
// donate any unwithdrawn outstanding reward fraction tokens to the community pool
scraps := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator())
feePool := app.DistrKeeper.GetFeePool(ctx)
feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
app.DistrKeeper.SetFeePool(ctx, feePool)

app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator())
return false
})

// reinitialize all delegations
for _, del := range dels {
app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
app.DistrKeeper.Hooks().AfterDelegationModified(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
}

// reset context height
ctx = ctx.WithBlockHeight(height)

/* Handle staking state. */

// iterate through redelegations, reset creation height
app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) {
for i := range red.Entries {
red.Entries[i].CreationHeight = 0
}
app.StakingKeeper.SetRedelegation(ctx, red)
return false
})

// iterate through unbonding delegations, reset creation height
app.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) {
for i := range ubd.Entries {
ubd.Entries[i].CreationHeight = 0
}
app.StakingKeeper.SetUnbondingDelegation(ctx, ubd)
return false
})

// Iterate through validators by power descending, reset bond heights, and
// update bond intra-tx counters.
store := ctx.KVStore(app.keys[stakingtypes.StoreKey])
iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey)
counter := int16(0)

for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(iter.Key()[1:])
validator, found := app.StakingKeeper.GetValidator(ctx, addr)
if !found {
panic("expected validator, not found")
}

validator.UnbondingHeight = 0
if applyAllowedAddrs && !allowedAddrsMap[addr.String()] {
validator.Jailed = true
}

app.StakingKeeper.SetValidator(ctx, validator)
counter++
}

iter.Close()

if _, err := app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx); err != nil {
func (app *LavaApp) ExportState(ctx sdk.Context) map[string]json.RawMessage {
export, err := app.mm.ExportGenesis(ctx, app.AppCodec())
if err != nil {
panic(err)
}

/* Handle slashing state. */

// reset start height on signing infos
app.SlashingKeeper.IterateValidatorSigningInfos(
ctx,
func(addr sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) (stop bool) {
info.StartHeight = 0
app.SlashingKeeper.SetValidatorSigningInfo(ctx, addr, info)
return false
},
)
return export
}
16 changes: 8 additions & 8 deletions app/keepers/lavaKeepers.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package keepers

import (
evidencekeeper "cosmossdk.io/x/evidence/keeper"
feegrantkeeper "cosmossdk.io/x/feegrant/keeper"
upgradekeeper "cosmossdk.io/x/upgrade/keeper"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
evidencekeeper "github.com/cosmos/cosmos-sdk/x/evidence/keeper"
feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/keeper"
icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper"
ibctransferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/keeper"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
icahostkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/keeper"
ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
conflictmodulekeeper "github.com/lavanet/lava/v4/x/conflict/keeper"
downtimemodulekeeper "github.com/lavanet/lava/v4/x/downtime/keeper"
dualstakingmodulekeeper "github.com/lavanet/lava/v4/x/dualstaking/keeper"
Expand Down
39 changes: 39 additions & 0 deletions app/params/proto.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package params

import (
"github.com/cosmos/gogoproto/proto"

"cosmossdk.io/x/tx/signing"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/address"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
)

func MakeEncodingConfig() EncodingConfig {
amino := codec.NewLegacyAmino()
interfaceRegistry, err := codectypes.NewInterfaceRegistryWithOptions(codectypes.InterfaceRegistryOptions{
ProtoFiles: proto.HybridResolver,
SigningOptions: signing.Options{
AddressCodec: address.Bech32Codec{
Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(),
},
ValidatorAddressCodec: address.Bech32Codec{
Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(),
},
},
})
if err != nil {
panic(err)
}
cdc := codec.NewProtoCodec(interfaceRegistry)
txCfg := tx.NewTxConfig(cdc, tx.DefaultSignModes)
return EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Marshaler: cdc,
TxConfig: txCfg,
Amino: amino,
}
}
9 changes: 4 additions & 5 deletions app/test_helper.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package app

import (
tmdb "github.com/cometbft/cometbft-db"
"github.com/cometbft/cometbft/libs/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
"cosmossdk.io/log"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// Setup a new App for testing purposes
func TestSetup() (*LavaApp, sdk.Context) {
db := tmdb.NewMemDB()
db := dbm.NewMemDB()
encoding := MakeEncodingConfig()
app := New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, encoding, sims.EmptyAppOptions{})
return app, app.NewContext(true, tmproto.Header{})
return app, app.NewContext(true)
}
9 changes: 5 additions & 4 deletions app/upgrades/empty_upgrades.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package upgrades

import (
store "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"context"

store "cosmossdk.io/store/types"
upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/lavanet/lava/v4/app/keepers"
)

Expand All @@ -14,7 +15,7 @@ func defaultUpgradeHandler(
bapm BaseAppParamManager,
lk *keepers.LavaKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
return func(ctx context.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
return m.RunMigrations(ctx, c, vm)
}
}
Expand Down
Loading
Loading