-
Notifications
You must be signed in to change notification settings - Fork 176
/
genesis.go
75 lines (62 loc) · 2.32 KB
/
genesis.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
package slashing
import (
"strconv"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/maticnetwork/heimdall/slashing/types"
hmTypes "github.com/maticnetwork/heimdall/types"
)
// InitGenesis initialize default parameters
// and the keeper's address to pubkey map
func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) {
// stakingKeeper.IterateValidators(ctx,
// func(index int64, validator exported.ValidatorI) bool {
// keeper.AddPubkey(ctx, validator.GetConsPubKey())
// return false
// },
// )
for _, info := range data.SigningInfos {
keeper.SetValidatorSigningInfo(ctx, info.ValID, info)
}
for valIDStr, array := range data.MissedBlocks {
for _, missed := range array {
valID, _ := strconv.ParseUint(valIDStr, 10, 64)
keeper.SetValidatorMissedBlockBitArray(ctx, hmTypes.ValidatorID(valID), missed.Index, missed.Missed)
}
}
for _, valSlashInfo := range data.BufferValSlashingInfo {
keeper.SetBufferValSlashingInfo(ctx, valSlashInfo.ID, *valSlashInfo)
}
for _, tickValSlashInfo := range data.TickValSlashingInfo {
keeper.SetTickValSlashingInfo(ctx, tickValSlashInfo.ID, *tickValSlashInfo)
}
keeper.SetParams(ctx, data.Params)
// Set initial tick count
keeper.UpdateTickCountWithValue(ctx, data.TickCount)
}
// ExportGenesis writes the current store values
// to a genesis file, which can be imported again
// with InitGenesis
func ExportGenesis(ctx sdk.Context, keeper Keeper) (data types.GenesisState) {
params := keeper.GetParams(ctx)
signingInfos := make(map[string]hmTypes.ValidatorSigningInfo)
missedBlocks := make(map[string][]types.MissedBlock)
keeper.IterateValidatorSigningInfos(ctx, func(valID hmTypes.ValidatorID, info hmTypes.ValidatorSigningInfo) (stop bool) {
signingInfos[valID.String()] = info
localMissedBlocks := []types.MissedBlock{}
keeper.IterateValidatorMissedBlockBitArray(ctx, valID, func(index int64, missed bool) (stop bool) {
localMissedBlocks = append(localMissedBlocks, types.NewMissedBlock(index, missed))
return false
})
missedBlocks[valID.String()] = localMissedBlocks
return false
})
bufSlashInfos, _ := keeper.GetBufferValSlashingInfos(ctx)
tickSlashInfos, _ := keeper.GetTickValSlashingInfos(ctx)
return types.NewGenesisState(
params,
signingInfos,
missedBlocks,
bufSlashInfos,
tickSlashInfos,
keeper.GetTickCount(ctx))
}