/
epoch_details.go
104 lines (92 loc) · 3.08 KB
/
epoch_details.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package keeper
import (
"fmt"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/lavanet/lava/utils"
"github.com/lavanet/lava/x/epochstorage/types"
)
// SetEpochDetails set epochDetails in the store
func (k Keeper) SetEpochDetails(ctx sdk.Context, epochDetails types.EpochDetails) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.EpochDetailsKey))
b := k.cdc.MustMarshal(&epochDetails)
store.Set([]byte{0}, b)
}
// GetEpochDetails returns epochDetails
func (k Keeper) GetEpochDetails(ctx sdk.Context) (val types.EpochDetails, found bool) {
if k.storeKey == nil {
return val, false
}
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.EpochDetailsKey))
b := store.Get([]byte{0})
if b == nil {
return val, false
}
k.cdc.MustUnmarshal(b, &val)
return val, true
}
// RemoveEpochDetails removes epochDetails from the store
func (k Keeper) RemoveEpochDetails(ctx sdk.Context) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.EpochDetailsKey))
store.Delete([]byte{0})
}
func (k Keeper) SetEpochDetailsStart(ctx sdk.Context, block uint64) {
details, found := k.GetEpochDetails(ctx)
if !found {
// panic:ok: EpochDetails is fundamental for operation
utils.LavaFormatPanic("critical: SetEpochDetailsStart failed",
fmt.Errorf("EpochDetails not found"),
utils.LogAttr("block", block),
utils.LogAttr("ctxBlock", ctx.BlockHeight()),
)
}
details.StartBlock = block
k.SetEpochDetails(ctx, details)
}
func (k Keeper) GetEpochStart(ctx sdk.Context) uint64 {
details, found := k.GetEpochDetails(ctx)
if !found {
// panic:ok: EpochDetails is fundamental for operation
utils.LavaFormatPanic("critical: GetEpochStart failed",
fmt.Errorf("EpochDetails not found"),
utils.LogAttr("ctxBlock", ctx.BlockHeight()),
)
}
return details.StartBlock
}
func (k Keeper) GetEarliestEpochStart(ctx sdk.Context) uint64 {
details, found := k.GetEpochDetails(ctx)
if !found {
// panic:ok: EpochDetails is fundamental for operation
utils.LavaFormatPanic("critical: GetEarliestEpochStart failed",
fmt.Errorf("EpochDetails not found"),
utils.LogAttr("ctxBlock", ctx.BlockHeight()),
)
}
return details.EarliestStart
}
func (k Keeper) GetDeletedEpochs(ctx sdk.Context) []uint64 {
details, found := k.GetEpochDetails(ctx)
if !found {
// panic:ok: EpochDetails is fundamental for operation
utils.LavaFormatPanic("critical: GetDeletedEpochs failed",
fmt.Errorf("EpochDetails not found"),
utils.LogAttr("ctxBlock", ctx.BlockHeight()),
)
}
return details.DeletedEpochs
}
func (k Keeper) SetEarliestEpochStart(ctx sdk.Context, block uint64, deletedEpochs []uint64) {
details, found := k.GetEpochDetails(ctx)
if !found {
// panic:ok: EpochDetails is fundamental for operation
utils.LavaFormatPanic("critical: SetEarliestEpochStart failed",
fmt.Errorf("EpochDetails not found"),
utils.LogAttr("block", block),
utils.LogAttr("ctxBlock", ctx.BlockHeight()),
)
}
details.DeletedEpochs = deletedEpochs
details.EarliestStart = block
k.SetEpochDetails(ctx, details)
}