Skip to content

Commit

Permalink
feat: Add session_end_block_height to SessionHeader (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
red-0ne authored Nov 8, 2023
1 parent 75eb643 commit 15049cb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions proto/pocket/session/session.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ message SessionHeader {
int64 session_start_block_height = 3; // The height at which this session started
// NOTE: session_id can be derived from the above values using on-chain but is included in the header for convenience
string session_id = 4; // A unique pseudoranom ID for this session
int64 session_end_block_height = 5; // The height at which this session ended, this is the last block of the session
}

// Session is a fully hydrated session object that contains all the information for the Session
Expand Down
1 change: 1 addition & 0 deletions x/session/keeper/session_hydrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (k Keeper) hydrateSessionMetadata(ctx sdk.Context, sh *sessionHydrator) err
sh.session.NumBlocksPerSession = NumBlocksPerSession
sh.session.SessionNumber = int64(sh.blockHeight / NumBlocksPerSession)
sh.sessionHeader.SessionStartBlockHeight = sh.blockHeight - (sh.blockHeight % NumBlocksPerSession)
sh.sessionHeader.SessionEndBlockHeight = sh.sessionHeader.SessionStartBlockHeight + NumBlocksPerSession
return nil
}

Expand Down
7 changes: 7 additions & 0 deletions x/session/keeper/session_hydrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestSession_HydrateSession_Success_BaseCase(t *testing.T) {
require.Equal(t, keepertest.TestServiceId1, sessionHeader.Service.Id)
require.Equal(t, "", sessionHeader.Service.Name)
require.Equal(t, int64(8), sessionHeader.SessionStartBlockHeight)
require.Equal(t, int64(12), sessionHeader.SessionEndBlockHeight)
require.Equal(t, "23f037a10f9d51d020d27763c42dd391d7e71765016d95d0d61f36c4a122efd0", sessionHeader.SessionId)

// Check the session
Expand Down Expand Up @@ -53,6 +54,7 @@ func TestSession_HydrateSession_Metadata(t *testing.T) {
expectedNumBlocksPerSession int64
expectedSessionNumber int64
expectedSessionStartBlock int64
expectedSessionEndBlock int64
}

// TODO_TECHDEBT: Extend these tests once `NumBlocksPerSession` is configurable.
Expand All @@ -65,6 +67,7 @@ func TestSession_HydrateSession_Metadata(t *testing.T) {
expectedNumBlocksPerSession: 4,
expectedSessionNumber: 0,
expectedSessionStartBlock: 0,
expectedSessionEndBlock: 4,
},
{
name: "blockHeight = 1",
Expand All @@ -73,6 +76,7 @@ func TestSession_HydrateSession_Metadata(t *testing.T) {
expectedNumBlocksPerSession: 4,
expectedSessionNumber: 0,
expectedSessionStartBlock: 0,
expectedSessionEndBlock: 4,
},
{
name: "blockHeight = sessionHeight",
Expand All @@ -81,6 +85,7 @@ func TestSession_HydrateSession_Metadata(t *testing.T) {
expectedNumBlocksPerSession: 4,
expectedSessionNumber: 1,
expectedSessionStartBlock: 4,
expectedSessionEndBlock: 8,
},
{
name: "blockHeight != sessionHeight",
Expand All @@ -89,6 +94,7 @@ func TestSession_HydrateSession_Metadata(t *testing.T) {
expectedNumBlocksPerSession: 4,
expectedSessionNumber: 1,
expectedSessionStartBlock: 4,
expectedSessionEndBlock: 8,
},
}

Expand All @@ -105,6 +111,7 @@ func TestSession_HydrateSession_Metadata(t *testing.T) {
require.Equal(t, tt.expectedNumBlocksPerSession, session.NumBlocksPerSession)
require.Equal(t, tt.expectedSessionNumber, session.SessionNumber)
require.Equal(t, tt.expectedSessionStartBlock, session.Header.SessionStartBlockHeight)
require.Equal(t, tt.expectedSessionEndBlock, session.Header.SessionEndBlockHeight)
})
}
}
Expand Down

0 comments on commit 15049cb

Please sign in to comment.