-
Notifications
You must be signed in to change notification settings - Fork 0
/
abci.go
68 lines (58 loc) · 2.22 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
package keeper
import (
"encoding/hex"
"time"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ingenuity-build/quicksilver/x/interchainquery/types"
)
const (
RetryInterval = 25
)
// EndBlocker of interchainquery module
func (k Keeper) EndBlocker(ctx sdk.Context) {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker)
_ = k.Logger(ctx)
events := sdk.Events{}
// emit events for periodic queries
k.IterateQueries(ctx, func(_ int64, queryInfo types.Query) (stop bool) {
// if queryInfo.QueryType == "ibc.ClientUpdate" && queryInfo.LastEmission.AddRaw(1000).LTE(sdk.NewInt(ctx.BlockHeight())) {
// k.DeleteQuery(ctx, queryInfo.Id)
// k.Logger(ctx).Error("Deleting stale query")
// return false
// }
if queryInfo.LastEmission.IsNil() || queryInfo.LastEmission.IsZero() || queryInfo.LastEmission.Add(queryInfo.Period).Equal(sdk.NewInt(ctx.BlockHeight())) {
k.Logger(ctx).Debug("Interchainquery event emitted", "id", queryInfo.Id)
event := sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, types.AttributeValueQuery),
sdk.NewAttribute(types.AttributeKeyQueryID, queryInfo.Id),
sdk.NewAttribute(types.AttributeKeyChainID, queryInfo.ChainId),
sdk.NewAttribute(types.AttributeKeyConnectionID, queryInfo.ConnectionId),
sdk.NewAttribute(types.AttributeKeyType, queryInfo.QueryType),
// TODO: add height to request type
sdk.NewAttribute(types.AttributeKeyHeight, "0"),
sdk.NewAttribute(types.AttributeKeyRequest, hex.EncodeToString(queryInfo.Request)),
)
events = append(events, event)
queryInfo.LastEmission = sdk.NewInt(ctx.BlockHeight())
k.SetQuery(ctx, queryInfo)
}
return false
})
if len(events) > 0 {
ctx.EventManager().EmitEvents(events)
}
k.IterateDatapoints(ctx, func(_ int64, dp types.DataPoint) bool {
q, found := k.GetQuery(ctx, dp.Id)
if !found {
// query was removed; delete datapoint
k.DeleteDatapoint(ctx, dp.Id)
} else if dp.LocalHeight.Int64()+int64(q.Ttl) > ctx.BlockHeader().Height {
// gc old data
k.DeleteDatapoint(ctx, dp.Id)
}
return false
})
}