/
abci.go
36 lines (28 loc) · 1.04 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
package oracle
import (
"time"
"github.com/incubus-network/fanfury-sdk/v2/x/oracle/keeper"
"github.com/incubus-network/fanfury-sdk/v2/x/oracle/types"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// EndBlocker is called at the end of every block
func EndBlocker(ctx sdk.Context, k keeper.Keeper) error {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker)
params := k.GetParams(ctx)
if isPeriodLastBlock(ctx, params.VotePeriod) {
if err := k.BuildClaimsMapAndTally(ctx, params); err != nil {
return err
}
}
// Slash oracle providers who missed voting over the threshold and
// reset miss counters of all validators at the last block of slash window
if isPeriodLastBlock(ctx, params.SlashWindow) {
k.SlashAndResetMissCounters(ctx)
}
return nil
}
// isPeriodLastBlock returns true if we are at the last block of the period
func isPeriodLastBlock(ctx sdk.Context, blocksPerPeriod uint64) bool {
return (uint64(ctx.BlockHeight())+1)%blocksPerPeriod == 0
}