-
Notifications
You must be signed in to change notification settings - Fork 337
/
abci.go
70 lines (55 loc) · 2.13 KB
/
abci.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
package validatorvesting
import (
"bytes"
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/kava-labs/kava/x/validator-vesting/keeper"
)
// BeginBlocker updates the vote signing information for each validator vesting account, updates account when period changes, and updates the previousBlockTime value in the store.
func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) {
previousBlockTime, found := k.GetPreviousBlockTime(ctx)
if !found {
k.SetPreviousBlockTime(ctx, ctx.BlockTime())
return
}
currentBlockTime := ctx.BlockTime()
var voteInfos VoteInfos
voteInfos = req.LastCommitInfo.GetVotes()
validatorVestingKeys := k.GetAllAccountKeys(ctx)
for _, key := range validatorVestingKeys {
acc := k.GetAccountFromAuthKeeper(ctx, key)
if !k.AccountIsVesting(ctx, acc.GetAddress()) {
continue
}
vote, found := voteInfos.FilterByValidatorAddress(acc.ValidatorAddress)
var missedBlock bool
// if the validator was not found or explicitly didn't sign, increment the missing sign count
if (!found || !vote.SignedLastBlock) && ctx.BlockHeight() > 1 {
missedBlock = true
}
k.UpdateMissingSignCount(ctx, acc.GetAddress(), missedBlock)
// check if a period ended in the last block
endTimes := k.GetPeriodEndTimes(ctx, key)
for i, t := range endTimes {
if currentBlockTime.Unix() >= t && previousBlockTime.Unix() < t {
k.UpdateVestedCoinsProgress(ctx, key, i)
}
}
// handle any new/remaining debt on the account
k.HandleVestingDebt(ctx, key, currentBlockTime)
}
k.SetPreviousBlockTime(ctx, currentBlockTime)
}
// VoteInfos an array of abci.VoteInfo
type VoteInfos []abci.VoteInfo
// FilterByValidatorAddress returns the VoteInfo of the validator address matching the input validator address
// and a boolean for if the address was found.
func (vis VoteInfos) FilterByValidatorAddress(consAddress sdk.ConsAddress) (abci.VoteInfo, bool) {
for i, vi := range vis {
votingAddress := sdk.ConsAddress(vi.Validator.Address)
if bytes.Equal(consAddress, votingAddress) {
return vis[i], true
}
}
return abci.VoteInfo{}, false
}