Skip to content

Commit

Permalink
Merge pull request #897 from comdex-official/feature/dev
Browse files Browse the repository at this point in the history
Comdex ICS changes
  • Loading branch information
vishnukumavat authored Jul 10, 2024
2 parents 7841a9e + d1d5914 commit af4284a
Show file tree
Hide file tree
Showing 17 changed files with 1,375 additions and 157 deletions.
4 changes: 4 additions & 0 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
consumerante "github.com/cosmos/interchain-security/v4/app/consumer/ante"
ccvconsumerkeeper "github.com/cosmos/interchain-security/v4/x/ccv/consumer/keeper"
auctionanteskip "github.com/skip-mev/block-sdk/x/auction/ante"
auctionkeeperskip "github.com/skip-mev/block-sdk/x/auction/keeper"
)
Expand All @@ -31,6 +33,7 @@ type HandlerOptions struct {
TxDecoder sdk.TxDecoder
TxEncoder sdk.TxEncoder
auctionkeeperskip auctionkeeperskip.Keeper
ConsumerKeeper ccvconsumerkeeper.Keeper
}

func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
Expand All @@ -55,6 +58,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
wasmkeeper.NewCountTXDecorator(options.txCounterStoreKey),
decorators.NewGovPreventSpamDecorator(options.Cdc, options.GovKeeper),
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
consumerante.NewDisabledModulesDecorator("/cosmos.evidence", "/cosmos.slashing"),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
Expand Down
218 changes: 137 additions & 81 deletions app/app.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions app/export.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package app

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

tmprototypes "github.com/cometbft/cometbft/proto/tendermint/types"
Expand Down Expand Up @@ -34,7 +34,7 @@ func (a *App) ExportAppStateAndValidators(
return servertypes.ExportedApp{}, err
}

validators, err := staking.WriteValidators(ctx, a.StakingKeeper)
validators, err := staking.WriteValidators(ctx, &a.StakingKeeper)
return servertypes.ExportedApp{
AppState: appState,
Validators: validators,
Expand Down Expand Up @@ -107,7 +107,7 @@ func (a *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []strin
feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
a.DistrKeeper.SetFeePool(ctx, feePool)

if err := a.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator()); err !=nil {
if err := a.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator()); err != nil {
panic(err)
}
return false
Expand Down
17 changes: 17 additions & 0 deletions app/proposals_whitelisting.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package app

import (
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)

// This is used for non-legacy gov transactions
// Returning true cause all txs are whitelisted
func IsModuleWhiteList(typeUrl string) bool {
return true
}

// This is used for legacy gov transactions
// Returning true cause all txs are whitelisted
func IsProposalWhitelisted(content govv1beta1.Content) bool {
return true
}
19 changes: 19 additions & 0 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
consumertypes "github.com/cosmos/interchain-security/v4/x/ccv/consumer/types"
testutil "github.com/comdex-official/comdex/testutil"
"github.com/stretchr/testify/require"
"testing"
"time"
Expand Down Expand Up @@ -134,6 +136,7 @@ func genesisStateWithValSet(t *testing.T,
delegations := make([]stakingtypes.Delegation, 0, len(valSet.Validators))

bondAmt := sdk.DefaultPowerReduction
initValPowers := []abci.ValidatorUpdate{}

for _, val := range valSet.Validators {
pk, err := cryptocodec.FromTmPubKeyInterface(val.PubKey)
Expand All @@ -155,6 +158,12 @@ func genesisStateWithValSet(t *testing.T,
}
validators = append(validators, validator)
delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress(), val.Address.Bytes(), math.LegacyOneDec()))
// add initial validator powers so consumer InitGenesis runs correctly
pub, _ := val.ToProto()
initValPowers = append(initValPowers, abci.ValidatorUpdate{
Power: val.VotingPower,
PubKey: pub.PubKey,
})

}

Expand Down Expand Up @@ -188,6 +197,16 @@ func genesisStateWithValSet(t *testing.T,
bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{}, []banktypes.SendEnabled{})
genesisState[banktypes.ModuleName] = codec.MustMarshalJSON(bankGenesis)
// println("genesisStateWithValSet bankState:", string(genesisState[banktypes.ModuleName]))
vals, err := tmtypes.PB2TM.ValidatorUpdates(initValPowers)
if err != nil {
panic("failed to get vals")
}

consumerGenesisState := testutil.CreateMinimalConsumerTestGenesis()
consumerGenesisState.Provider.InitialValSet = initValPowers
consumerGenesisState.Provider.ConsensusState.NextValidatorsHash = tmtypes.NewValidatorSet(vals).Hash()
consumerGenesisState.Params.Enabled = true
genesisState[consumertypes.ModuleName] = app.AppCodec().MustMarshalJSON(consumerGenesisState)

return genesisState
}
Expand Down
12 changes: 6 additions & 6 deletions app/upgrades/mainnet/v14/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package v14_test

import (
"github.com/comdex-official/comdex/app"
v14 "github.com/comdex-official/comdex/app/upgrades/mainnet/v14"
// v14 "github.com/comdex-official/comdex/app/upgrades/mainnet/v14"
"github.com/stretchr/testify/suite"
"testing"
)
Expand All @@ -21,14 +21,14 @@ func TestKeeperTestSuite(t *testing.T) {

// Ensures the test does not error out.
func (s *UpgradeTestSuite) TestUpgrade() {
s.Setup()
// s.Setup()

preUpgradeChecks(s)
// preUpgradeChecks(s)

upgradeHeight := int64(5)
s.ConfirmUpgradeSucceeded(v14.UpgradeName, upgradeHeight)
// upgradeHeight := int64(5)
// s.ConfirmUpgradeSucceeded(v14.UpgradeName, upgradeHeight)

postUpgradeChecks(s)
// postUpgradeChecks(s)
}

func preUpgradeChecks(s *UpgradeTestSuite) {
Expand Down
15 changes: 15 additions & 0 deletions app/upgrades/testnet/v15/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package v15

const (
UpgradeName = "v15.0.0"
UpgradeHeight = ""
UpgradeInfo = `'{
"binaries": {
"darwin/arm64":"",
"darwin/x86_64":"",
"linux/arm64":"",
"linux/x86_64":"",
"windows/x86_64":""
}
}'`
)
58 changes: 58 additions & 0 deletions app/upgrades/testnet/v15/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package v15

import (
"fmt"

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ibcconnectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
ccvconsumerkeeper "github.com/cosmos/interchain-security/v4/x/ccv/consumer/keeper"
consumertypes "github.com/cosmos/interchain-security/v4/x/ccv/consumer/types"
"github.com/spf13/cast"
)

// CreateUpgradeHandler creates an SDK upgrade handler for v15
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
cdc codec.Codec,
appOpts servertypes.AppOptions,
ibcKeeper ibckeeper.Keeper,
consumerKeeper *ccvconsumerkeeper.Keeper,
stakingKeeper stakingkeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Starting upgrade testnet v15...")
ibcKeeper.ConnectionKeeper.SetParams(ctx, ibcconnectiontypes.DefaultParams())

fromVM := make(map[string]uint64)

nodeHome := cast.ToString(appOpts.Get(flags.FlagHome))
consumerUpgradeGenFile := nodeHome + "/config/ccv.json"
appState, _, err := genutiltypes.GenesisStateFromGenFile(consumerUpgradeGenFile)
if err != nil {
return fromVM, fmt.Errorf("failed to unmarshal genesis state: %w", err)
}

var consumerGenesis = consumertypes.GenesisState{}
cdc.MustUnmarshalJSON(appState[consumertypes.ModuleName], &consumerGenesis)

consumerGenesis.PreCCV = true
consumerGenesis.Params.SoftOptOutThreshold = "0.05"
consumerGenesis.Params.RewardDenoms = []string{"ucmdx"}
consumerGenesis.Params.Enabled = true
consumerGenesis.Params.ProviderFeePoolAddrStr = "" // replace with provider address
consumerGenesis.Params.ConsumerRedistributionFraction = "0.70"
consumerKeeper.InitGenesis(ctx, &consumerGenesis)
consumerKeeper.SetDistributionTransmissionChannel(ctx, "channel-2") // replace with correct channel

return fromVM, nil
}
}
16 changes: 6 additions & 10 deletions cmd/comdex/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@ package main
import (
"os"

"github.com/cosmos/cosmos-sdk/server"
"github.com/comdex-official/comdex/cmd"
servercmd "github.com/cosmos/cosmos-sdk/server/cmd"

comdex "github.com/comdex-official/comdex/app"
app "github.com/comdex-official/comdex/app"
)

func main() {
comdex.SetAccountAddressPrefixes()
app.SetAccountAddressPrefixes()

root, _ := NewRootCmd()
if err := servercmd.Execute(root, "", comdex.DefaultNodeHome); err != nil {
switch e := err.(type) {
case server.ErrorCode:
os.Exit(e.Code)
default:
os.Exit(1)
}
root.AddCommand(cmd.AddConsumerSectionCmd(app.DefaultNodeHome))
if err := servercmd.Execute(root, "", app.DefaultNodeHome); err != nil {
os.Exit(1)
}
}
Loading

0 comments on commit af4284a

Please sign in to comment.