Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into zale144/make-initial-…
Browse files Browse the repository at this point in the history
…supply-nullable
  • Loading branch information
zale144 committed Sep 25, 2024
2 parents 1bddb43 + 5601240 commit ccbd284
Show file tree
Hide file tree
Showing 139 changed files with 16,757 additions and 756 deletions.
9 changes: 3 additions & 6 deletions app/ante/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

delayedack "github.com/dymensionxyz/dymension/v3/x/delayedack"
lightclientante "github.com/dymensionxyz/dymension/v3/x/lightclient/ante"
"github.com/dymensionxyz/dymension/v3/x/rollapp/transfergenesis"
)

func newEthAnteHandler(options HandlerOptions) sdk.AnteHandler {
Expand Down Expand Up @@ -74,9 +75,7 @@ func newLegacyCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler {
delayedack.NewIBCProofHeightDecorator(),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
ethante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper),

// disabled until #1208 handled (https://github.com/dymensionxyz/dymension/issues/1208)
// transfergenesis.NewTransferEnabledDecorator(options.RollappKeeper.GetRollapp, options.IBCKeeper.ChannelKeeper),
transfergenesis.NewTransferEnabledDecorator(options.RollappKeeper.GetRollapp, options.IBCKeeper.ChannelKeeper),
)
}

Expand Down Expand Up @@ -112,8 +111,6 @@ func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
lightclientante.NewIBCMessagesDecorator(*options.LightClientKeeper, options.IBCKeeper.ClientKeeper, options.IBCKeeper.ChannelKeeper, options.RollappKeeper),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
ethante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper),

// disabled until #1208 handled (https://github.com/dymensionxyz/dymension/issues/1208)
// transfergenesis.NewTransferEnabledDecorator(options.RollappKeeper.GetRollapp, options.IBCKeeper.ChannelKeeper),
transfergenesis.NewTransferEnabledDecorator(options.RollappKeeper.GetRollapp, options.IBCKeeper.ChannelKeeper),
)
}
22 changes: 13 additions & 9 deletions app/apptesting/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
app "github.com/dymensionxyz/dymension/v3/app"
incentivestypes "github.com/dymensionxyz/dymension/v3/x/incentives/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
)

Expand Down Expand Up @@ -80,17 +81,20 @@ func SetupTestingApp() (*app.App, app.GenesisState) {
params.SetAddressPrefixes()

newApp := app.New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, app.DefaultNodeHome, 5, encCdc, EmptyAppOptions{}, bam.SetChainID(TestChainID))

defaultGenesisState := app.NewDefaultGenesisState(encCdc.Codec)

// set EnableCreate to false
if evmGenesisStateJson, found := defaultGenesisState[evmtypes.ModuleName]; found {
// force disable Enable Create of x/evm
var evmGenesisState evmtypes.GenesisState
encCdc.Codec.MustUnmarshalJSON(evmGenesisStateJson, &evmGenesisState)
evmGenesisState.Params.EnableCreate = false
defaultGenesisState[evmtypes.ModuleName] = encCdc.Codec.MustMarshalJSON(&evmGenesisState)
}
incentivesGenesisStateJson := defaultGenesisState[incentivestypes.ModuleName]
var incentivesGenesisState incentivestypes.GenesisState
encCdc.Codec.MustUnmarshalJSON(incentivesGenesisStateJson, &incentivesGenesisState)
incentivesGenesisState.LockableDurations = append(incentivesGenesisState.LockableDurations, time.Second*60)
defaultGenesisState[incentivestypes.ModuleName] = encCdc.Codec.MustMarshalJSON(&incentivesGenesisState)

// force disable EnableCreate of x/evm
evmGenesisStateJson := defaultGenesisState[evmtypes.ModuleName]
var evmGenesisState evmtypes.GenesisState
encCdc.Codec.MustUnmarshalJSON(evmGenesisStateJson, &evmGenesisState)
evmGenesisState.Params.EnableCreate = false
defaultGenesisState[evmtypes.ModuleName] = encCdc.Codec.MustMarshalJSON(&evmGenesisState)

return newApp, defaultGenesisState
}
Expand Down
12 changes: 9 additions & 3 deletions app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (s *KeeperTestHelper) CreateRollappByName(name string) {
Bech32Prefix: strings.ToLower(rand.Str(3)),
GenesisChecksum: "1234567890abcdefg",
InitialSupply: uptr.To(sdk.NewInt(1000)),
NativeDenom: &rollapptypes.DenomMetadata{
NativeDenom: rollapptypes.DenomMetadata{
Display: "DEN",
Base: "aden",
Exponent: 18,
Expand Down Expand Up @@ -116,10 +116,14 @@ func (s *KeeperTestHelper) CreateSequencerByPubkey(ctx sdk.Context, rollappId st
}

func (s *KeeperTestHelper) PostStateUpdate(ctx sdk.Context, rollappId, seqAddr string, startHeight, numOfBlocks uint64) (lastHeight uint64, err error) {
return s.PostStateUpdateWithDRSVersion(ctx, rollappId, seqAddr, startHeight, numOfBlocks, "")
}

func (s *KeeperTestHelper) PostStateUpdateWithDRSVersion(ctx sdk.Context, rollappId, seqAddr string, startHeight, numOfBlocks uint64, drsVersion string) (lastHeight uint64, err error) {
var bds rollapptypes.BlockDescriptors
bds.BD = make([]rollapptypes.BlockDescriptor, numOfBlocks)
for k := 0; k < int(numOfBlocks); k++ {
bds.BD[k] = rollapptypes.BlockDescriptor{Height: startHeight + uint64(k), Timestamp: time.Now().UTC()}
for k := uint64(0); k < numOfBlocks; k++ {
bds.BD[k] = rollapptypes.BlockDescriptor{Height: startHeight + k, Timestamp: time.Now().UTC()}
}

updateState := rollapptypes.MsgUpdateState{
Expand All @@ -129,6 +133,8 @@ func (s *KeeperTestHelper) PostStateUpdate(ctx sdk.Context, rollappId, seqAddr s
NumBlocks: numOfBlocks,
DAPath: "",
BDs: bds,
Last: false,
DrsVersion: drsVersion,
}
msgServer := rollappkeeper.NewMsgServerImpl(*s.App.RollappKeeper)
_, err = msgServer.UpdateState(ctx, &updateState)
Expand Down
22 changes: 18 additions & 4 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,15 @@ import (
eibcmoduletypes "github.com/dymensionxyz/dymension/v3/x/eibc/types"
incentiveskeeper "github.com/dymensionxyz/dymension/v3/x/incentives/keeper"
incentivestypes "github.com/dymensionxyz/dymension/v3/x/incentives/types"
irokeeper "github.com/dymensionxyz/dymension/v3/x/iro/keeper"
irotypes "github.com/dymensionxyz/dymension/v3/x/iro/types"
lightclientmodulekeeper "github.com/dymensionxyz/dymension/v3/x/lightclient/keeper"
lightclientmoduletypes "github.com/dymensionxyz/dymension/v3/x/lightclient/types"
lockupkeeper "github.com/dymensionxyz/dymension/v3/x/lockup/keeper"
lockuptypes "github.com/dymensionxyz/dymension/v3/x/lockup/types"
rollappmodule "github.com/dymensionxyz/dymension/v3/x/rollapp"
rollappmodulekeeper "github.com/dymensionxyz/dymension/v3/x/rollapp/keeper"
"github.com/dymensionxyz/dymension/v3/x/rollapp/transfergenesis"
rollappmoduletypes "github.com/dymensionxyz/dymension/v3/x/rollapp/types"
sequencermodulekeeper "github.com/dymensionxyz/dymension/v3/x/sequencer/keeper"
sequencermoduletypes "github.com/dymensionxyz/dymension/v3/x/sequencer/types"
Expand Down Expand Up @@ -121,6 +124,7 @@ type AppKeepers struct {
FeeGrantKeeper feegrantkeeper.Keeper
PacketForwardMiddlewareKeeper *packetforwardkeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper
IROKeeper *irokeeper.Keeper

// Ethermint keepers
EvmKeeper *evmkeeper.Keeper
Expand Down Expand Up @@ -352,6 +356,7 @@ func (a *AppKeepers) InitKeepers(
a.IBCKeeper.ClientKeeper,
nil,
a.BankKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

a.SequencerKeeper = *sequencermodulekeeper.NewKeeper(
Expand All @@ -378,11 +383,21 @@ func (a *AppKeepers) InitKeepers(
a.BankKeeper,
a.LockupKeeper,
a.EpochsKeeper,
a.DistrKeeper,
a.TxFeesKeeper,
a.RollappKeeper,
)

a.IROKeeper = irokeeper.NewKeeper(
appCodec,
a.keys[irotypes.StoreKey],
&a.AccountKeeper,
a.BankKeeper,
a.RollappKeeper,
a.GAMMKeeper,
a.IncentivesKeeper,
a.PoolManagerKeeper,
)

a.SponsorshipKeeper = sponsorshipkeeper.NewKeeper(
appCodec,
a.keys[sponsorshiptypes.StoreKey],
Expand Down Expand Up @@ -511,9 +526,7 @@ func (a *AppKeepers) InitTransferStack() {
delayedackmodule.WithRollappKeeper(a.RollappKeeper),
)
a.TransferStack = a.delayedAckMiddleware

// disabled until #1208 handled (https://github.com/dymensionxyz/dymension/issues/1208)
// a.TransferStack = transfergenesis.NewIBCModule(a.TransferStack, a.DelayedAckKeeper, *a.RollappKeeper, a.TransferKeeper, a.DenomMetadataKeeper)
a.TransferStack = transfergenesis.NewIBCModule(a.TransferStack, a.RollappKeeper, a.TransferKeeper, a.DenomMetadataKeeper, a.IROKeeper)

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := ibcporttypes.NewRouter()
Expand Down Expand Up @@ -589,6 +602,7 @@ func (a *AppKeepers) SetupHooks() {
a.StreamerKeeper.Hooks(),
a.DymNSKeeper.GetRollAppHooks(),
a.LightClientKeeper.RollappHooks(),
a.IROKeeper,
))
}

Expand Down
2 changes: 2 additions & 0 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
irotypes "github.com/dymensionxyz/dymension/v3/x/iro/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
epochstypes "github.com/osmosis-labs/osmosis/v15/x/epochs/types"
Expand Down Expand Up @@ -114,6 +115,7 @@ var KVStoreKeys = sdk.NewKVStoreKeys(
capabilitytypes.StoreKey,
crisistypes.StoreKey,
consensusparamtypes.StoreKey,
irotypes.StoreKey,
rollappmoduletypes.StoreKey,
sequencermoduletypes.StoreKey,
sponsorshiptypes.StoreKey,
Expand Down
12 changes: 10 additions & 2 deletions app/keepers/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ import (
"github.com/dymensionxyz/dymension/v3/x/eibc"
eibcmoduletypes "github.com/dymensionxyz/dymension/v3/x/eibc/types"
incentivestypes "github.com/dymensionxyz/dymension/v3/x/incentives/types"
"github.com/dymensionxyz/dymension/v3/x/rollapp"

"github.com/dymensionxyz/dymension/v3/x/iro"
irotypes "github.com/dymensionxyz/dymension/v3/x/iro/types"
lightclientmodule "github.com/dymensionxyz/dymension/v3/x/lightclient"
lightclientmoduletypes "github.com/dymensionxyz/dymension/v3/x/lightclient/types"
"github.com/dymensionxyz/dymension/v3/x/rollapp"
rollappmoduleclient "github.com/dymensionxyz/dymension/v3/x/rollapp/client"
rollappmoduletypes "github.com/dymensionxyz/dymension/v3/x/rollapp/types"
"github.com/dymensionxyz/dymension/v3/x/sequencer"
Expand Down Expand Up @@ -150,6 +151,7 @@ var ModuleBasics = module.NewBasicManager(
streamer.AppModuleBasic{},
denommetadata.AppModuleBasic{},
packetforward.AppModuleBasic{},
iro.AppModuleBasic{},
delayedack.AppModuleBasic{},
eibc.AppModuleBasic{},
dymnsmodule.AppModuleBasic{},
Expand Down Expand Up @@ -199,6 +201,7 @@ func (a *AppKeepers) SetupModules(
packetforwardmiddleware.NewAppModule(a.PacketForwardMiddlewareKeeper, a.GetSubspace(packetforwardtypes.ModuleName)),
ibctransfer.NewAppModule(a.TransferKeeper),
rollappmodule.NewAppModule(appCodec, a.RollappKeeper, a.AccountKeeper, a.BankKeeper),
iro.NewAppModule(appCodec, *a.IROKeeper),
sequencermodule.NewAppModule(appCodec, a.SequencerKeeper, a.AccountKeeper, a.BankKeeper, a.GetSubspace(sequencertypes.ModuleName)),
sponsorship.NewAppModule(a.SponsorshipKeeper),
streamermodule.NewAppModule(a.StreamerKeeper, a.AccountKeeper, a.BankKeeper, a.EpochsKeeper),
Expand Down Expand Up @@ -232,6 +235,7 @@ func (*AppKeepers) ModuleAccountAddrs() map[string]bool {
// exclude the streamer as we want him to be able to get external incentives
modAccAddrs[authtypes.NewModuleAddress(streamermoduletypes.ModuleName).String()] = false
modAccAddrs[authtypes.NewModuleAddress(txfeestypes.ModuleName).String()] = false
modAccAddrs[authtypes.NewModuleAddress(irotypes.ModuleName).String()] = false
return modAccAddrs
}

Expand All @@ -255,6 +259,7 @@ var maccPerms = map[string][]string{
incentivestypes.ModuleName: {authtypes.Minter, authtypes.Burner},
txfeestypes.ModuleName: {authtypes.Burner},
dymnstypes.ModuleName: {authtypes.Minter, authtypes.Burner},
irotypes.ModuleName: {authtypes.Minter, authtypes.Burner},
}

var BeginBlockers = []string{
Expand Down Expand Up @@ -294,6 +299,7 @@ var BeginBlockers = []string{
incentivestypes.ModuleName,
txfeestypes.ModuleName,
consensusparamtypes.ModuleName,
irotypes.ModuleName,
lightclientmoduletypes.ModuleName,
}

Expand Down Expand Up @@ -333,6 +339,7 @@ var EndBlockers = []string{
incentivestypes.ModuleName,
txfeestypes.ModuleName,
consensusparamtypes.ModuleName,
irotypes.ModuleName,
lightclientmoduletypes.ModuleName,
crisistypes.ModuleName,
}
Expand Down Expand Up @@ -373,6 +380,7 @@ var InitGenesis = []string{
incentivestypes.ModuleName,
txfeestypes.ModuleName,
consensusparamtypes.ModuleName,
irotypes.ModuleName,
lightclientmoduletypes.ModuleName,
crisistypes.ModuleName,
}
25 changes: 19 additions & 6 deletions app/upgrades/v4/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package v4
import (
"github.com/cometbft/cometbft/crypto"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/dymensionxyz/sdk-utils/utils/uptr"
epochskeeper "github.com/osmosis-labs/osmosis/v15/x/epochs/keeper"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
Expand All @@ -24,8 +22,8 @@ import (

evmtypes "github.com/evmos/ethermint/x/evm/types"
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
epochskeeper "github.com/osmosis-labs/osmosis/v15/x/epochs/keeper"

// Ethermint modules
"github.com/dymensionxyz/dymension/v3/app/keepers"
"github.com/dymensionxyz/dymension/v3/app/upgrades"
delayedackkeeper "github.com/dymensionxyz/dymension/v3/x/delayedack/keeper"
Expand All @@ -39,6 +37,7 @@ import (
sequencertypes "github.com/dymensionxyz/dymension/v3/x/sequencer/types"
streamerkeeper "github.com/dymensionxyz/dymension/v3/x/streamer/keeper"
streamertypes "github.com/dymensionxyz/dymension/v3/x/streamer/types"
"github.com/dymensionxyz/sdk-utils/utils/uptr"
)

// CreateUpgradeHandler creates an SDK upgrade handler for v4
Expand Down Expand Up @@ -67,7 +66,9 @@ func CreateUpgradeHandler(
}
migrateIncentivesParams(ctx, keepers.IncentivesKeeper)

// TODO: create rollapp gauges for each existing rollapp (https://github.com/dymensionxyz/dymension/issues/1005)
if err := migrateRollappGauges(ctx, keepers.RollappKeeper, keepers.IncentivesKeeper); err != nil {
return nil, err
}

// Start running the module migrations
logger.Debug("running module migrations ...")
Expand Down Expand Up @@ -140,6 +141,18 @@ func migrateRollappParams(ctx sdk.Context, rollappkeeper *rollappkeeper.Keeper)
rollappkeeper.SetParams(ctx, params)
}

// migrateRollappGauges creates a gauge for each rollapp in the store
func migrateRollappGauges(ctx sdk.Context, rollappkeeper *rollappkeeper.Keeper, incentivizeKeeper *incentiveskeeper.Keeper) error {
rollapps := rollappkeeper.GetAllRollapps(ctx)
for _, rollapp := range rollapps {
_, err := incentivizeKeeper.CreateRollappGauge(ctx, rollapp.RollappId)
if err != nil {
return err
}
}
return nil
}

func migrateRollapps(ctx sdk.Context, rollappkeeper *rollappkeeper.Keeper) error {
list := rollappkeeper.GetAllRollapps(ctx)
for _, oldRollapp := range list {
Expand Down Expand Up @@ -227,10 +240,10 @@ func ConvertOldRollappToNew(oldRollapp rollapptypes.Rollapp) rollapptypes.Rollap
GenesisInfo: rollapptypes.GenesisInfo{
Bech32Prefix: oldRollapp.RollappId[:5], // placeholder data
GenesisChecksum: string(crypto.Sha256([]byte(oldRollapp.RollappId))), // placeholder data
NativeDenom: &rollapptypes.DenomMetadata{
NativeDenom: rollapptypes.DenomMetadata{
Display: "DEN", // placeholder data
Base: "aden", // placeholder data
Exponent: 6, // placeholder data
Exponent: 18, // placeholder data
},
InitialSupply: uptr.To(sdk.NewInt(100000)), // placeholder data
Sealed: true,
Expand Down
40 changes: 38 additions & 2 deletions app/upgrades/v4/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,12 @@ func (s *UpgradeTestSuite) TestUpgrade() {
return
}

s.validateStreamerMigration()
// Check rollapp gauges
if err = s.validateRollappGaugesMigration(); err != nil {
return
}

// TODO: check for rollapp gauges creation
s.validateStreamerMigration()

return
},
Expand Down Expand Up @@ -192,6 +195,39 @@ func (s *UpgradeTestSuite) validateRollappsMigration(numRoll int) error {
return nil
}

// validate rollapp gauges
func (s *UpgradeTestSuite) validateRollappGaugesMigration() error {
rollappMap := make(map[string]bool) // Create a map to store rollappId<->gaugeCreated

rollapps := s.App.RollappKeeper.GetAllRollapps(s.Ctx)
for _, rollapp := range rollapps {
rollappMap[rollapp.RollappId] = false // false until gauge is validated
}

gauges := s.App.IncentivesKeeper.GetGauges(s.Ctx)
if len(gauges) != len(rollapps) {
return fmt.Errorf("rollapp gauges not created for all rollapps")
}

// Check that for each rollapp there exists a rollapp gauge
for _, gauge := range gauges {
if gauge.GetRollapp() != nil {
gaugeExists, ok := rollappMap[gauge.GetRollapp().RollappId]
if !ok {
return fmt.Errorf("rollapp gauge for unknown rollapp %s", gauge.GetRollapp().RollappId)
}

if gaugeExists {
return fmt.Errorf("rollapp gauge for rollapp %s already created", gauge.GetRollapp().RollappId)
}

rollappMap[gauge.GetRollapp().RollappId] = true
}
}

return nil
}

func (s *UpgradeTestSuite) validateSequencersMigration(numSeq int) error {
testSeqs := s.seedSequencers(numSeq)
expectSequencers := make([]sequencertypes.Sequencer, len(testSeqs))
Expand Down
Loading

0 comments on commit ccbd284

Please sign in to comment.