From b4f7ec6a2a673ccbf16fed6e319f01aa5200652e Mon Sep 17 00:00:00 2001 From: Redouane Lakrache Date: Wed, 8 Nov 2023 20:30:08 +0100 Subject: [PATCH] feat: Add session_end_block_height to SessionHeader (#162) --- proto/pocket/session/session.proto | 1 + x/session/keeper/session_hydrator.go | 1 + x/session/keeper/session_hydrator_test.go | 7 +++++++ 3 files changed, 9 insertions(+) diff --git a/proto/pocket/session/session.proto b/proto/pocket/session/session.proto index 3008e749f..e92a5b5ac 100644 --- a/proto/pocket/session/session.proto +++ b/proto/pocket/session/session.proto @@ -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 diff --git a/x/session/keeper/session_hydrator.go b/x/session/keeper/session_hydrator.go index ed312f066..2b71143d1 100644 --- a/x/session/keeper/session_hydrator.go +++ b/x/session/keeper/session_hydrator.go @@ -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 } diff --git a/x/session/keeper/session_hydrator_test.go b/x/session/keeper/session_hydrator_test.go index 505f56fad..61d591900 100644 --- a/x/session/keeper/session_hydrator_test.go +++ b/x/session/keeper/session_hydrator_test.go @@ -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 @@ -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. @@ -65,6 +67,7 @@ func TestSession_HydrateSession_Metadata(t *testing.T) { expectedNumBlocksPerSession: 4, expectedSessionNumber: 0, expectedSessionStartBlock: 0, + expectedSessionEndBlock: 4, }, { name: "blockHeight = 1", @@ -73,6 +76,7 @@ func TestSession_HydrateSession_Metadata(t *testing.T) { expectedNumBlocksPerSession: 4, expectedSessionNumber: 0, expectedSessionStartBlock: 0, + expectedSessionEndBlock: 4, }, { name: "blockHeight = sessionHeight", @@ -81,6 +85,7 @@ func TestSession_HydrateSession_Metadata(t *testing.T) { expectedNumBlocksPerSession: 4, expectedSessionNumber: 1, expectedSessionStartBlock: 4, + expectedSessionEndBlock: 8, }, { name: "blockHeight != sessionHeight", @@ -89,6 +94,7 @@ func TestSession_HydrateSession_Metadata(t *testing.T) { expectedNumBlocksPerSession: 4, expectedSessionNumber: 1, expectedSessionStartBlock: 4, + expectedSessionEndBlock: 8, }, } @@ -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) }) } }