Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass a correct session end height to NewSession #1545

Merged
merged 1 commit into from
Apr 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion x/pocketcore/types/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,23 @@ func (r *Relay) Validate(ctx sdk.Ctx, posKeeper PosKeeper, appsKeeper AppsKeeper
if err != nil {
return sdk.ZeroInt(), sdk.ErrInternal(err.Error())
}

// With session rollover, the height of `ctx` may already be in the next
// session of the relay's session. In such a case, we need to pass the
// correct context of the session end instead of `ctx`.
sessionEndHeight :=
sessionBlockHeight + posKeeper.BlocksPerSession(sessionCtx) - 1
var sesssionEndCtx sdk.Ctx
if ctx.BlockHeight() > sessionEndHeight {
if sesssionEndCtx, err = ctx.PrevCtx(sessionEndHeight); err != nil {
return sdk.ZeroInt(), sdk.ErrInternal(er.Error())
}
} else {
sesssionEndCtx = ctx
}

var er sdk.Error
session, er = NewSession(sessionCtx, ctx, posKeeper, header, hex.EncodeToString(bh), int(sessionNodeCount))
session, er = NewSession(sessionCtx, sesssionEndCtx, posKeeper, header, hex.EncodeToString(bh), int(sessionNodeCount))
if er != nil {
return sdk.ZeroInt(), er
}
Expand Down