Skip to content

Commit

Permalink
feat: set hooks per version
Browse files Browse the repository at this point in the history
  • Loading branch information
rootulp committed Apr 23, 2024
1 parent f1b2528 commit ccf3b5d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
27 changes: 19 additions & 8 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions scripts/single-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
# {
Expand Down
11 changes: 5 additions & 6 deletions x/blobstream/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit ccf3b5d

Please sign in to comment.