-
Notifications
You must be signed in to change notification settings - Fork 179
/
endblocker.go
43 lines (34 loc) · 1.06 KB
/
endblocker.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
package order
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/okex/exchain/x/common/perf"
"github.com/okex/exchain/x/order/keeper"
"github.com/okex/exchain/x/order/match"
"github.com/okex/exchain/x/order/types"
)
// EndBlocker called every block
// 1. execute matching engine
// 2. flush cache
func EndBlocker(ctx sdk.Context, keeper keeper.Keeper) {
seq := perf.GetPerf().OnEndBlockEnter(ctx, types.ModuleName)
defer perf.GetPerf().OnEndBlockExit(ctx, types.ModuleName, seq)
match.GetEngine().Run(ctx, keeper)
// flush cache at the end
keeper.Cache2Disk(ctx)
keeper.SetMetric()
ret := keeper.GetOperationMetric()
tailmsg := func(name string, num int64) string {
var msg string
if num != 0 {
msg = fmt.Sprintf("%s<%d>,", name, num)
}
return msg
}
message := tailmsg("FullFillNum", ret.FullFillNum)
message += tailmsg("OpenNum", ret.OpenNum)
message += tailmsg("CancelNum", ret.CancelNum)
message += tailmsg("ExpireNum", ret.ExpireNum)
message += tailmsg("PartialFillNum", ret.PartialFillNum)
perf.GetPerf().EnqueueMsg(message)
}