Skip to content

Commit

Permalink
fix module override
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Feb 4, 2025
1 parent 4ac59a3 commit 6e84e47
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 64 deletions.
20 changes: 10 additions & 10 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ import (
ibctransfertypes "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types"
ibcporttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types"
ibckeeper "github.com/cosmos/ibc-go/v9/modules/core/keeper"
ibctesting "github.com/cosmos/ibc-go/v9/testing"
)

// maccPerms is short for module account permissions. It is a map from module
Expand Down Expand Up @@ -150,8 +151,7 @@ const (

var (
_ celestiaserver.Application = (*App)(nil)
// TODO: removed pending full IBC integration
// _ ibctesting.TestingApp = (*App)(nil)
_ ibctesting.TestingApp = (*App)(nil)
)

// App extends an ABCI application, but with most of its parameters exported.
Expand Down Expand Up @@ -529,25 +529,25 @@ func New(
genutil.NewAppModule(encodingConfig.Codec, app.AuthKeeper, app.StakingKeeper, app, encodingConfig.TxConfig, genutiltypes.DefaultMessageValidator),
auth.NewAppModule(encodingConfig.Codec, app.AuthKeeper, app.AccountsKeeper, nil, nil),
vesting.NewAppModule(app.AuthKeeper, app.BankKeeper),
bank.NewAppModule(encodingConfig.Codec, app.BankKeeper, app.AuthKeeper),
bankModule{bank.NewAppModule(encodingConfig.Codec, app.BankKeeper, app.AuthKeeper), app.encodingConfig.Codec},
feegrantmodule.NewAppModule(encodingConfig.Codec, app.FeeGrantKeeper, encodingConfig.InterfaceRegistry),
gov.NewAppModule(encodingConfig.Codec, app.GovKeeper, app.AuthKeeper, app.BankKeeper, app.PoolKeeper),
mint.NewAppModule(encodingConfig.Codec, app.MintKeeper, app.AuthKeeper),
slashing.NewAppModule(encodingConfig.Codec, app.SlashingKeeper, app.AuthKeeper,
app.BankKeeper, app.StakingKeeper, encodingConfig.InterfaceRegistry, cometService),
govModule{gov.NewAppModule(encodingConfig.Codec, app.GovKeeper, app.AuthKeeper, app.BankKeeper, app.PoolKeeper), app.encodingConfig.Codec},
mintModule{mint.NewAppModule(encodingConfig.Codec, app.MintKeeper, app.AuthKeeper), app.encodingConfig.Codec},
slashingModule{slashing.NewAppModule(encodingConfig.Codec, app.SlashingKeeper, app.AuthKeeper,
app.BankKeeper, app.StakingKeeper, encodingConfig.InterfaceRegistry, cometService), app.encodingConfig.Codec},
distr.NewAppModule(encodingConfig.Codec, app.DistrKeeper, app.StakingKeeper),
staking.NewAppModule(encodingConfig.Codec, app.StakingKeeper),
stakingModule{staking.NewAppModule(encodingConfig.Codec, app.StakingKeeper), app.encodingConfig.Codec},
evidence.NewAppModule(encodingConfig.Codec, app.EvidenceKeeper, cometService),
authzmodule.NewAppModule(encodingConfig.Codec, app.AuthzKeeper, encodingConfig.InterfaceRegistry),
ibc.NewAppModule(encodingConfig.Codec, app.IBCKeeper),
ibcModule{ibc.NewAppModule(encodingConfig.Codec, app.IBCKeeper), app.encodingConfig.Codec},
params.NewAppModule(app.ParamsKeeper),
transfer.NewAppModule(encodingConfig.Codec, app.TransferKeeper),
blob.NewAppModule(encodingConfig.Codec, app.BlobKeeper),
blobstream.NewAppModule(encodingConfig.Codec, app.BlobstreamKeeper), // v1->v1
signal.NewAppModule(app.SignalKeeper),
minfee.NewAppModule(encodingConfig.Codec, app.ParamsKeeper),
// packetforward.NewAppModule(app.PacketForwardKeeper),
ica.NewAppModule(encodingConfig.Codec, &app.ICAControllerKeeper, &app.ICAHostKeeper),
icaModule{ica.NewAppModule(encodingConfig.Codec, &app.ICAControllerKeeper, &app.ICAHostKeeper), app.encodingConfig.Codec},
)

// order begin block, end block and init genesis
Expand Down
84 changes: 34 additions & 50 deletions app/default_overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"cosmossdk.io/math"
"cosmossdk.io/x/bank"
banktypes "cosmossdk.io/x/bank/types"
distribution "cosmossdk.io/x/distribution"
distributiontypes "cosmossdk.io/x/distribution/types"
"cosmossdk.io/x/gov"
govtypes "cosmossdk.io/x/gov/types/v1"
"cosmossdk.io/x/slashing"
Expand All @@ -35,10 +33,11 @@ import (
// implementation to provide custom default genesis state.
type bankModule struct {
bank.AppModule
codec.Codec
}

// DefaultGenesis returns custom x/bank module genesis state.
func (bankModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
func (m bankModule) DefaultGenesis() json.RawMessage {
metadata := banktypes.Metadata{
Description: "The native token of the Celestia network.",
Base: BondDenom,
Expand All @@ -64,116 +63,101 @@ func (bankModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
genState := banktypes.DefaultGenesisState()
genState.DenomMetadata = append(genState.DenomMetadata, metadata)

return cdc.MustMarshalJSON(genState)
return m.Codec.MustMarshalJSON(genState)
}

// stakingModule wraps the x/staking module in order to overwrite specific
// ModuleManager APIs.
type stakingModule struct {
staking.AppModule
codec.Codec
}

// DefaultGenesis returns custom x/staking module genesis state.
func (stakingModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
params := stakingtypes.DefaultParams()
params.UnbondingTime = appconsts.DefaultUnbondingTime
params.BondDenom = BondDenom
params.MinCommissionRate = math.LegacyNewDecWithPrec(5, 2) // 5%

return cdc.MustMarshalJSON(&stakingtypes.GenesisState{
Params: params,
})
func (m stakingModule) DefaultGenesis() json.RawMessage {
genesis := stakingtypes.DefaultGenesisState()
genesis.Params.UnbondingTime = appconsts.DefaultUnbondingTime
genesis.Params.BondDenom = BondDenom
genesis.Params.MinCommissionRate = math.LegacyNewDecWithPrec(5, 2) // 5%

return m.Codec.MustMarshalJSON(genesis)
}

// stakingModule wraps the x/staking module in order to overwrite specific
// ModuleManager APIs.
type slashingModule struct {
slashing.AppModule
codec.Codec
}

// DefaultGenesis returns custom x/staking module genesis state.
func (slashingModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
params := slashingtypes.DefaultParams()
params.MinSignedPerWindow = math.LegacyNewDecWithPrec(75, 2) // 75%
params.SignedBlocksWindow = 5000
params.DowntimeJailDuration = time.Minute * 1
params.SlashFractionDoubleSign = math.LegacyNewDecWithPrec(2, 2) // 2%
params.SlashFractionDowntime = math.LegacyZeroDec() // 0%

return cdc.MustMarshalJSON(&slashingtypes.GenesisState{
Params: params,
})
}

type distributionModule struct {
distribution.AppModule
}

// DefaultGenesis returns custom x/distribution module genesis state.
func (distributionModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
params := distributiontypes.DefaultParams()
params.BaseProposerReward = math.LegacyZeroDec() // 0%
params.BonusProposerReward = math.LegacyZeroDec() // 0%
return cdc.MustMarshalJSON(&distributiontypes.GenesisState{
Params: params,
})
func (m slashingModule) DefaultGenesis() json.RawMessage {
genesis := slashingtypes.DefaultGenesisState()
genesis.Params.MinSignedPerWindow = math.LegacyNewDecWithPrec(75, 2) // 75%
genesis.Params.SignedBlocksWindow = 5000
genesis.Params.DowntimeJailDuration = time.Minute * 1
genesis.Params.SlashFractionDoubleSign = math.LegacyNewDecWithPrec(2, 2) // 2%
genesis.Params.SlashFractionDowntime = math.LegacyZeroDec() // 0%

return m.Codec.MustMarshalJSON(genesis)
}

type ibcModule struct {
ibc.AppModule
codec.Codec
}

// DefaultGenesis returns custom x/ibc module genesis state.
func (ibcModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
func (m ibcModule) DefaultGenesis() json.RawMessage {
// per ibc documentation, this value should be 3-5 times the expected block
// time. The expected block time is 15 seconds, therefore this value is 75
// seconds.
maxBlockTime := appconsts.GoalBlockTime * 5
gs := ibctypes.DefaultGenesisState()
gs.ClientGenesis.Params.AllowedClients = []string{"06-solomachine", "07-tendermint"}
gs.ConnectionGenesis.Params.MaxExpectedTimePerBlock = uint64(maxBlockTime.Nanoseconds())
return cdc.MustMarshalJSON(gs)

return m.Codec.MustMarshalJSON(gs)
}

// icaModule defines a custom wrapper around the ica module to provide custom
// default genesis state.
type icaModule struct {
ica.AppModule
codec.Codec
}

// DefaultGenesis returns custom ica module genesis state.
func (icaModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
func (m icaModule) DefaultGenesis() json.RawMessage {
gs := icagenesistypes.DefaultGenesis()
gs.HostGenesisState.Params.AllowMessages = icaAllowMessages()
gs.HostGenesisState.Params.HostEnabled = true
gs.ControllerGenesisState.Params.ControllerEnabled = false
return cdc.MustMarshalJSON(gs)
return m.Codec.MustMarshalJSON(gs)
}

type mintModule struct {
mint.AppModule
codec.Codec
}

// DefaultGenesis returns custom x/mint module genesis state.
func (mintModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
func (m mintModule) DefaultGenesis() json.RawMessage {
genState := minttypes.DefaultGenesisState()
genState.BondDenom = BondDenom

return cdc.MustMarshalJSON(genState)
}

func newGovModule() govModule {
return govModule{gov.AppModule{}}
return m.Codec.MustMarshalJSON(genState)
}

// govModule is a custom wrapper around the x/gov module's AppModuleBasic
// implementation to provide custom default genesis state.
type govModule struct {
gov.AppModule
codec.Codec
}

// DefaultGenesis returns custom x/gov module genesis state.
func (govModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
func (m govModule) DefaultGenesis() json.RawMessage {
genState := govtypes.DefaultGenesisState()
day := time.Hour * 24
oneWeek := day * 7
Expand All @@ -182,7 +166,7 @@ func (govModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
genState.Params.MaxDepositPeriod = &oneWeek
genState.Params.VotingPeriod = &oneWeek

return cdc.MustMarshalJSON(genState)
return m.Codec.MustMarshalJSON(genState)
}

// DefaultConsensusParams returns a ConsensusParams with a MaxBytes
Expand Down
4 changes: 0 additions & 4 deletions app/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ const Name = "celestia-app"
// to store configs, data, keyrings, etc.
const appDirectory = ".celestia-app"

// celestiaHome is an environment variable that sets where appDirectory will be placed.
// If celestiaHome isn't specified, the default user home directory will be used.
const celestiaHome = "CELESTIA_HOME"

// DefaultNodeHome is the default home directory for the application daemon.
// This gets set as a side-effect of the init() function.
var DefaultNodeHome string
Expand Down

0 comments on commit 6e84e47

Please sign in to comment.