From ccf3b5d973c44b0fb7485999e8bfa1ca8adcc9f0 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Tue, 23 Apr 2024 15:09:58 -0400 Subject: [PATCH] feat: set hooks per version --- app/app.go | 27 +++++++++++++++++++-------- scripts/single-node.sh | 5 +++-- x/blobstream/keeper/hooks.go | 11 +++++------ 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/app/app.go b/app/app.go index 6f2ad0e619..07a1d66d25 100644 --- a/app/app.go +++ b/app/app.go @@ -269,14 +269,9 @@ func New( &stakingKeeper, ) - // register the staking hooks - // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks - app.StakingKeeper = *stakingKeeper.SetHooks( - stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), - app.SlashingKeeper.Hooks(), - app.BlobstreamKeeper.Hooks(), - ), - ) + // Register the staking hooks. NOTE: stakingKeeper is passed by reference + // above so that it will contain these hooks. + app.StakingKeeper = *stakingKeeper.SetHooks(app.hooksV1()) app.SignalKeeper = signal.NewKeeper(keys[signaltypes.StoreKey], app.StakingKeeper) @@ -454,6 +449,7 @@ func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo if req.Height == app.upgradeHeightV2-1 { app.SetInitialAppVersionInConsensusParams(ctx, v2) app.SetAppVersion(ctx, v2) + app.StakingKeeper = *app.StakingKeeper.SetHooks(app.hooksV2()) } // from v2 to v3 and onwards we use a signalling mechanism } else if shouldUpgrade, newVersion := app.SignalKeeper.ShouldUpgrade(); shouldUpgrade { @@ -706,6 +702,21 @@ func (app *App) BlockedParams() [][2]string { } } +func (app *App) hooksV1() stakingtypes.MultiStakingHooks { + return stakingtypes.NewMultiStakingHooks( + app.DistrKeeper.Hooks(), + app.SlashingKeeper.Hooks(), + app.BlobstreamKeeper.Hooks(), + ) +} + +func (app *App) hooksV2() stakingtypes.MultiStakingHooks { + return stakingtypes.NewMultiStakingHooks( + app.DistrKeeper.Hooks(), + app.SlashingKeeper.Hooks(), + ) +} + // initParamsKeeper init params keeper and its subspaces func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey storetypes.StoreKey) paramskeeper.Keeper { paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey) diff --git a/scripts/single-node.sh b/scripts/single-node.sh index faa8015a0c..b83a74e3e3 100755 --- a/scripts/single-node.sh +++ b/scripts/single-node.sh @@ -63,9 +63,10 @@ celestia-appd collect-gentxs \ --home ${CELESTIA_APP_HOME} \ &> /dev/null # 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 @@ -84,7 +85,7 @@ celestia-appd start \ --api.enable \ --grpc.enable \ --grpc-web.enable \ - --v2-upgrade-height 10 + --v2-upgrade-height 5 # # Register the validator EVM address # { diff --git a/x/blobstream/keeper/hooks.go b/x/blobstream/keeper/hooks.go index 603b7171a4..d30d0d8825 100644 --- a/x/blobstream/keeper/hooks.go +++ b/x/blobstream/keeper/hooks.go @@ -22,16 +22,15 @@ func (k Keeper) Hooks() Hooks { } func (h Hooks) AfterValidatorBeginUnbonding(ctx sdk.Context, _ sdk.ConsAddress, _ sdk.ValAddress) error { - // When Validator starts Unbonding, Persist the block height in the store - // Later in endblocker, check if there is at least one validator who started + // When Validator starts Unbonding, Persist the block height in the store. + // Later in EndBlocker, check if there is at least one validator who started // unbonding and create a valset request. The reason for creating valset - // requests in endblock is to create only one valset request per block, if - // multiple validators starts unbonding at same block. + // requests in EndBlock is to create only one valset request per block if + // multiple validators start unbonding in the same block. - // this hook IS called for jailing or unbonding triggered by users but it IS + // This hook is called for jailing or unbonding triggered by users but it IS // NOT called for jailing triggered in the endblocker therefore we call the // keeper function ourselves there. - h.k.SetLatestUnBondingBlockHeight(ctx, uint64(ctx.BlockHeight())) return nil }