Skip to content

Commit

Permalink
refactor(app): app.go and modules.go (celestiaorg#3372)
Browse files Browse the repository at this point in the history
A bunch of small refactors I made while working on
celestiaorg#3310
  • Loading branch information
rootulp authored Apr 24, 2024
1 parent 9dbc541 commit 43369a4
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 68 deletions.
93 changes: 47 additions & 46 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,24 @@ import (
"io"
"slices"

"github.com/celestiaorg/celestia-app/v2/app/ante"
"github.com/celestiaorg/celestia-app/v2/app/encoding"
"github.com/celestiaorg/celestia-app/v2/app/module"
"github.com/celestiaorg/celestia-app/v2/app/posthandler"
appv1 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v1"
appv2 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v2"
"github.com/celestiaorg/celestia-app/v2/pkg/proof"
blobkeeper "github.com/celestiaorg/celestia-app/v2/x/blob/keeper"
blobtypes "github.com/celestiaorg/celestia-app/v2/x/blob/types"
blobstreamkeeper "github.com/celestiaorg/celestia-app/v2/x/blobstream/keeper"
blobstreamtypes "github.com/celestiaorg/celestia-app/v2/x/blobstream/types"
"github.com/celestiaorg/celestia-app/v2/x/minfee"
mintkeeper "github.com/celestiaorg/celestia-app/v2/x/mint/keeper"
minttypes "github.com/celestiaorg/celestia-app/v2/x/mint/types"
"github.com/celestiaorg/celestia-app/v2/x/paramfilter"
"github.com/celestiaorg/celestia-app/v2/x/signal"
signaltypes "github.com/celestiaorg/celestia-app/v2/x/signal/types"
"github.com/celestiaorg/celestia-app/v2/x/tokenfilter"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
Expand Down Expand Up @@ -54,44 +67,27 @@ import (
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward"
packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward/keeper"
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward/types"
icahost "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host"
icahostkeeper "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/types"
"github.com/cosmos/ibc-go/v6/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v6/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types"
ibcclienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types"
ibcporttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v6/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v6/modules/core/keeper"
ibctestingtypes "github.com/cosmos/ibc-go/v6/testing/types"
"github.com/spf13/cast"
abci "github.com/tendermint/tendermint/abci/types"
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
dbm "github.com/tendermint/tm-db"

"github.com/celestiaorg/celestia-app/v2/app/ante"
"github.com/celestiaorg/celestia-app/v2/app/encoding"
appv1 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v1"
appv2 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v2"
"github.com/celestiaorg/celestia-app/v2/pkg/proof"
blobkeeper "github.com/celestiaorg/celestia-app/v2/x/blob/keeper"
blobtypes "github.com/celestiaorg/celestia-app/v2/x/blob/types"
"github.com/celestiaorg/celestia-app/v2/x/paramfilter"
"github.com/celestiaorg/celestia-app/v2/x/tokenfilter"

blobstreamkeeper "github.com/celestiaorg/celestia-app/v2/x/blobstream/keeper"
blobstreamtypes "github.com/celestiaorg/celestia-app/v2/x/blobstream/types"
"github.com/celestiaorg/celestia-app/v2/x/signal"
signaltypes "github.com/celestiaorg/celestia-app/v2/x/signal/types"
ibctestingtypes "github.com/cosmos/ibc-go/v6/testing/types"

"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward"
packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward/keeper"
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward/types"

icahost "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host"
icahostkeeper "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/types"
)

// maccPerms is short for module account permissions.
Expand Down Expand Up @@ -153,18 +149,18 @@ type App struct {
FeeGrantKeeper feegrantkeeper.Keeper
ICAHostKeeper icahostkeeper.Keeper
PacketForwardKeeper *packetforwardkeeper.Keeper
BlobKeeper blobkeeper.Keeper
BlobstreamKeeper blobstreamkeeper.Keeper

ScopedIBCKeeper capabilitykeeper.ScopedKeeper // This keeper is public for test purposes
ScopedTransferKeeper capabilitykeeper.ScopedKeeper // This keeper is public for test purposes
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper // This keeper is public for test purposes

BlobKeeper blobkeeper.Keeper
BlobstreamKeeper blobstreamkeeper.Keeper

mm *module.Manager
configurator module.Configurator
// used as a coordination mechanism for height based upgrades
upgradeHeight int64
// upgradeHeightV2 is used as a coordination mechanism for the height-based
// upgrade from v1 to v2.
upgradeHeightV2 int64
// used to define what messages are accepted for a given app version
MsgGateKeeper *ante.MsgVersioningGateKeeper
}
Expand All @@ -180,7 +176,7 @@ func New(
traceStore io.Writer,
invCheckPeriod uint,
encodingConfig encoding.Config,
upgradeHeight int64,
upgradeHeightV2 int64,
appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) *App {
Expand All @@ -207,6 +203,7 @@ func New(
keys: keys,
tkeys: tkeys,
memKeys: memKeys,
upgradeHeightV2: upgradeHeightV2,
}

app.ParamsKeeper = initParamsKeeper(appCodec, cdc, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey])
Expand Down Expand Up @@ -259,7 +256,6 @@ func New(
// upgrade. This keeper is not used for the actual upgrades but merely for compatibility reasons. Ideally IBC has their own upgrade module
// for performing IBC based upgrades. Note, as we use rolling upgrades, IBC technically never needs this functionality.
app.UpgradeKeeper = upgradekeeper.NewKeeper(nil, keys[upgradetypes.StoreKey], appCodec, "", app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String())
app.upgradeHeight = upgradeHeight

app.BlobstreamKeeper = *blobstreamkeeper.NewKeeper(
appCodec,
Expand All @@ -268,10 +264,11 @@ func New(
&stakingKeeper,
)

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
// Register the staking hooks. NOTE: stakingKeeper is passed by reference
// above so that it will contain these hooks.
app.StakingKeeper = *stakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(),
stakingtypes.NewMultiStakingHooks(
app.DistrKeeper.Hooks(),
app.SlashingKeeper.Hooks(),
app.BlobstreamKeeper.Hooks(),
),
Expand Down Expand Up @@ -341,18 +338,23 @@ func New(
packetforwardkeeper.DefaultRefundTransferPacketTimeoutTimestamp, // refund timeout
)

// Create evidence Keeper for to register the IBC light client misbehaviour evidence route
evidenceKeeper := evidencekeeper.NewKeeper(
appCodec, keys[evidencetypes.StoreKey], &app.StakingKeeper, app.SlashingKeeper,
app.EvidenceKeeper = *evidencekeeper.NewKeeper(
appCodec,
keys[evidencetypes.StoreKey],
&app.StakingKeeper,
app.SlashingKeeper,
)
// If evidence needs to be handled for the app, set routes in router here and seal
app.EvidenceKeeper = *evidenceKeeper

govConfig := govtypes.DefaultConfig()

app.GovKeeper = govkeeper.NewKeeper(
appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
&stakingKeeper, govRouter, bApp.MsgServiceRouter(), govConfig,
appCodec,
keys[govtypes.StoreKey],
app.GetSubspace(govtypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
&stakingKeeper,
govRouter,
bApp.MsgServiceRouter(),
govtypes.DefaultConfig(),
)

app.BlobKeeper = *blobkeeper.NewKeeper(
Expand Down Expand Up @@ -399,7 +401,6 @@ func New(
app.MountTransientStores(tkeys)
app.MountMemoryStores(memKeys)

// initialize BaseApp
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)
Expand Down Expand Up @@ -446,7 +447,7 @@ func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo
// For v1 only we upgrade using a agreed upon height known ahead of time
if currentVersion == v1 {
// check that we are at the height before the upgrade
if req.Height == app.upgradeHeight-1 {
if req.Height == app.upgradeHeightV2-1 {
app.SetInitialAppVersionInConsensusParams(ctx, v2)
app.SetAppVersion(ctx, v2)
}
Expand Down
9 changes: 9 additions & 0 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ func TestNew(t *testing.T) {
t.Run("initializes ScopedICAHostKeeper", func(t *testing.T) {
assert.NotNil(t, got.ScopedICAHostKeeper)
})
t.Run("initializes StakingKeeper", func(t *testing.T) {
assert.NotNil(t, got.StakingKeeper)
})
t.Run("should have set StakingKeeper hooks", func(t *testing.T) {
// StakingKeeper doesn't expose a GetHooks method so this checks if
// hooks have been set by verifying the a subsequent call to SetHooks
// will panic.
assert.Panics(t, func() { got.StakingKeeper.SetHooks(nil) })
})
}

// NoopWriter is a no-op implementation of a writer.
Expand Down
40 changes: 20 additions & 20 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,39 +307,39 @@ func versionedStoreKeys() map[uint64][]string {
authtypes.StoreKey,
authzkeeper.StoreKey,
banktypes.StoreKey,
stakingtypes.StoreKey,
minttypes.StoreKey,
blobstreamtypes.StoreKey,
blobtypes.StoreKey,
capabilitytypes.StoreKey,
distrtypes.StoreKey,
slashingtypes.StoreKey,
govtypes.StoreKey,
upgradetypes.StoreKey,
feegrant.StoreKey,
evidencetypes.StoreKey,
capabilitytypes.StoreKey,
blobstreamtypes.StoreKey,
ibctransfertypes.StoreKey,
feegrant.StoreKey,
govtypes.StoreKey,
ibchost.StoreKey,
blobtypes.StoreKey,
ibctransfertypes.StoreKey,
minttypes.StoreKey,
slashingtypes.StoreKey,
stakingtypes.StoreKey,
upgradetypes.StoreKey,
},
2: {
authtypes.StoreKey,
authzkeeper.StoreKey,
banktypes.StoreKey,
stakingtypes.StoreKey,
minttypes.StoreKey,
blobstreamtypes.StoreKey,
capabilitytypes.StoreKey,
distrtypes.StoreKey,
slashingtypes.StoreKey,
govtypes.StoreKey,
upgradetypes.StoreKey,
feegrant.StoreKey,
evidencetypes.StoreKey,
capabilitytypes.StoreKey,
blobstreamtypes.StoreKey,
ibctransfertypes.StoreKey,
feegrant.StoreKey,
govtypes.StoreKey,
ibchost.StoreKey,
packetforwardtypes.StoreKey,
ibctransfertypes.StoreKey,
icahosttypes.StoreKey,
minttypes.StoreKey,
packetforwardtypes.StoreKey,
signaltypes.StoreKey,
slashingtypes.StoreKey,
stakingtypes.StoreKey,
upgradetypes.StoreKey,
},
}
}
Expand Down
3 changes: 2 additions & 1 deletion scripts/single-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ celestia-appd collect-gentxs \
--home "${CELESTIA_APP_HOME}" \
> /dev/null 2>&1 # Hide output to reduce terminal noise

# Set proper defaults and change ports
# If you encounter: `sed: -I or -i may not be used with stdin` on MacOS you can mitigate by installing gnu-sed
# https://gist.github.com/andre3k1/e3a1a7133fded5de5a9ee99c87c6fa0d?permalink_comment_id=3082272#gistcomment-3082272

# Override the default RPC servier listening address
sed -i'.bak' 's#"tcp://127.0.0.1:26657"#"tcp://0.0.0.0:26657"#g' "${CELESTIA_APP_HOME}"/config/config.toml

# Enable transaction indexing
Expand Down
2 changes: 1 addition & 1 deletion tools/blockscan/readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Blockscan

This is an inspection tool to scan blocks and display the contents of the transactions that fill them.
This is an inspection tool to scan blocks and display the contents of the transactions that fill them.

## Usage

Expand Down

0 comments on commit 43369a4

Please sign in to comment.