diff --git a/x/pocketcore/types/service.go b/x/pocketcore/types/service.go index c37b6232e..c28d09521 100644 --- a/x/pocketcore/types/service.go +++ b/x/pocketcore/types/service.go @@ -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 }