Skip to content

Commit

Permalink
CNS-930: changed UniqueEpochSessionGenesis to hold the decoded key
Browse files Browse the repository at this point in the history
  • Loading branch information
oren-lava committed Mar 27, 2024
1 parent 3e4937a commit 35e283c
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 74 deletions.
5 changes: 4 additions & 1 deletion proto/lavanet/lava/pairing/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ message GenesisState {

message UniqueEpochSessionGenesis {
uint64 epoch = 1;
string unique_epoch_session = 2;
string provider = 2;
string project = 3;
string chain_id = 4;
uint64 session_id = 5;
}

message ProviderEpochCuGenesis {
Expand Down
19 changes: 11 additions & 8 deletions x/pairing/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ import (
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
// Set all the uniquePaymentStorageClientProvider
for _, elem := range genState.UniqueEpochSessions {
provider, project, chainID, sessionID, err := types.DecodeUniqueEpochSessionKey(elem.UniqueEpochSession)
if err != nil {
utils.LavaFormatError("could not decode UniqueEpochSessionKey", err, utils.LogAttr("key", elem))
continue
}
k.SetUniqueEpochSession(ctx, elem.Epoch, provider, project, chainID, sessionID)
k.SetUniqueEpochSession(ctx, elem.Epoch, elem.Provider, elem.Project, elem.ChainId, elem.SessionId)
}
// Set all the providerPaymentStorage
for _, elem := range genState.ProviderEpochCus {
Expand Down Expand Up @@ -45,9 +40,17 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {

epochs, uniqueEpochSessions := k.GetAllUniqueEpochSessionStore(ctx)
for i := range epochs {
provider, project, chainID, sessionID, err := types.DecodeUniqueEpochSessionKey(uniqueEpochSessions[i])
if err != nil {
utils.LavaFormatError("could not decode UniqueEpochSessionKey", err, utils.LogAttr("key", uniqueEpochSessions[i]))
continue
}
ues := types.UniqueEpochSessionGenesis{
Epoch: epochs[i],
UniqueEpochSession: uniqueEpochSessions[i],
Epoch: epochs[i],
Provider: provider,
Project: project,
ChainId: chainID,
SessionId: sessionID,
}
genesis.UniqueEpochSessions = append(genesis.UniqueEpochSessions, ues)
}
Expand Down
14 changes: 10 additions & 4 deletions x/pairing/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ func TestGenesis(t *testing.T) {

UniqueEpochSessions: []types.UniqueEpochSessionGenesis{
{
Epoch: 0,
UniqueEpochSession: string(types.UniqueEpochSessionKey("0", "0", "0", 0)),
Epoch: 0,
Provider: "0",
Project: "0",
ChainId: "0",
SessionId: 0,
},
{
Epoch: 1,
UniqueEpochSession: string(types.UniqueEpochSessionKey("1", "1", "1", 1)),
Epoch: 1,
Provider: "1",
Project: "1",
ChainId: "1",
SessionId: 1,
},
},
ProviderEpochCus: []types.ProviderEpochCuGenesis{
Expand Down
5 changes: 3 additions & 2 deletions x/pairing/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ func (gs GenesisState) Validate() error {
UniqueEpochSessionsProviderIndexMap := make(map[string]struct{})

for _, elem := range gs.UniqueEpochSessions {
if _, ok := UniqueEpochSessionsProviderIndexMap[elem.UniqueEpochSession]; ok {
index := string(UniqueEpochSessionKey(elem.Provider, elem.Project, elem.ChainId, elem.SessionId))
if _, ok := UniqueEpochSessionsProviderIndexMap[index]; ok {
return fmt.Errorf("duplicated index for UniqueEpochSession")
}
UniqueEpochSessionsProviderIndexMap[elem.UniqueEpochSession] = struct{}{}
UniqueEpochSessionsProviderIndexMap[index] = struct{}{}
}
// Check for duplicated index in ProviderEpochCu
providerEpochCusIndexMap := make(map[string]struct{})
Expand Down
240 changes: 189 additions & 51 deletions x/pairing/types/genesis.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 35e283c

Please sign in to comment.