-
Notifications
You must be signed in to change notification settings - Fork 199
/
keeper.go
127 lines (110 loc) · 3.83 KB
/
keeper.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package keeper
import (
"fmt"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
timerstoretypes "github.com/lavanet/lava/x/timerstore/types"
"github.com/cometbft/cometbft/libs/log"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
fixationtypes "github.com/lavanet/lava/x/fixationstore/types"
"github.com/lavanet/lava/x/pairing/types"
)
type (
Keeper struct {
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
memKey storetypes.StoreKey
paramstore paramtypes.Subspace
bankKeeper types.BankKeeper
accountKeeper types.AccountKeeper
specKeeper types.SpecKeeper
epochStorageKeeper types.EpochstorageKeeper
projectsKeeper types.ProjectsKeeper
subscriptionKeeper types.SubscriptionKeeper
planKeeper types.PlanKeeper
badgeTimerStore timerstoretypes.TimerStore
providerQosFS fixationtypes.FixationStore
downtimeKeeper types.DowntimeKeeper
dualstakingKeeper types.DualstakingKeeper
stakingKeeper types.StakingKeeper
}
)
// sanity checks at start time
func init() {
if types.EPOCHS_NUM_TO_CHECK_CU_FOR_UNRESPONSIVE_PROVIDER == 0 {
panic("types.EPOCHS_NUM_TO_CHECK_FOR_COMPLAINERS == 0")
}
if types.EPOCHS_NUM_TO_CHECK_FOR_COMPLAINERS == 0 {
panic("types.EPOCHS_NUM_TO_CHECK_FOR_COMPLAINERS == 0")
}
}
func NewKeeper(
cdc codec.BinaryCodec,
storeKey,
memKey storetypes.StoreKey,
ps paramtypes.Subspace,
bankKeeper types.BankKeeper,
accountKeeper types.AccountKeeper,
specKeeper types.SpecKeeper,
epochStorageKeeper types.EpochstorageKeeper,
projectsKeeper types.ProjectsKeeper,
subscriptionKeeper types.SubscriptionKeeper,
planKeeper types.PlanKeeper,
downtimeKeeper types.DowntimeKeeper,
dualstakingKeeper types.DualstakingKeeper,
stakingKeeper types.StakingKeeper,
fixationStoreKeeper types.FixationStoreKeeper,
timerStoreKeeper types.TimerStoreKeeper,
) *Keeper {
// set KeyTable if it has not already been set
if !ps.HasKeyTable() {
ps = ps.WithKeyTable(types.ParamKeyTable())
}
keeper := &Keeper{
cdc: cdc,
storeKey: storeKey,
memKey: memKey,
paramstore: ps,
bankKeeper: bankKeeper,
accountKeeper: accountKeeper,
specKeeper: specKeeper,
epochStorageKeeper: epochStorageKeeper,
projectsKeeper: projectsKeeper,
subscriptionKeeper: subscriptionKeeper,
planKeeper: planKeeper,
downtimeKeeper: downtimeKeeper,
dualstakingKeeper: dualstakingKeeper,
stakingKeeper: stakingKeeper,
}
// note that the timer and badgeUsedCu keys are the same (so we can use only the second arg)
badgeTimerCallback := func(ctx sdk.Context, badgeKey, _ []byte) {
keeper.RemoveBadgeUsedCu(ctx, badgeKey)
}
badgeTimerStore := timerStoreKeeper.NewTimerStoreBeginBlock(storeKey, types.BadgeTimerStorePrefix).
WithCallbackByBlockHeight(badgeTimerCallback)
keeper.badgeTimerStore = *badgeTimerStore
keeper.providerQosFS = *fixationStoreKeeper.NewFixationStore(storeKey, types.ProviderQosStorePrefix)
return keeper
}
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}
func (k Keeper) BeginBlock(ctx sdk.Context) {
if k.epochStorageKeeper.IsEpochStart(ctx) {
// remove old session payments
k.RemoveOldEpochPayment(ctx)
// unstake any unstaking providers
k.CheckUnstakingForCommit(ctx)
// unstake/jail unresponsive providers
k.UnstakeUnresponsiveProviders(ctx,
types.EPOCHS_NUM_TO_CHECK_CU_FOR_UNRESPONSIVE_PROVIDER,
types.EPOCHS_NUM_TO_CHECK_FOR_COMPLAINERS)
}
}
func (k Keeper) InitProviderQoS(ctx sdk.Context, gs fixationtypes.GenesisState) {
k.providerQosFS.Init(ctx, gs)
}
func (k Keeper) ExportProviderQoS(ctx sdk.Context) fixationtypes.GenesisState {
return k.providerQosFS.Export(ctx)
}