/
internal.go
94 lines (77 loc) · 3.1 KB
/
internal.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package messages
import (
"context"
"go.opencensus.io/tag"
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/label"
"github.com/filecoin-project/sentinel-visor/metrics"
"github.com/filecoin-project/sentinel-visor/model"
)
type InternalMessage struct {
//lint:ignore U1000 tableName is a convention used by go-pg
tableName struct{} `pg:"internal_messages"`
Height int64 `pg:",pk,notnull,use_zero"`
Cid string `pg:",pk,notnull"`
StateRoot string `pg:",notnull"`
SourceMessage string
From string `pg:",notnull"`
To string `pg:",notnull"`
Value string `pg:"type:numeric,notnull"`
Method uint64 `pg:",use_zero"`
ActorName string `pg:",notnull"`
ActorFamily string `pg:",notnull"`
ExitCode int64 `pg:",use_zero"`
GasUsed int64 `pg:",use_zero"`
}
func (im *InternalMessage) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error {
ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "internal_messages"))
stop := metrics.Timer(ctx, metrics.PersistDuration)
defer stop()
metrics.RecordCount(ctx, metrics.PersistModel, 1)
return s.PersistModel(ctx, im)
}
type InternalMessageList []*InternalMessage
func (l InternalMessageList) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error {
if len(l) == 0 {
return nil
}
ctx, span := global.Tracer("").Start(ctx, "InternalMessageList.Persist", trace.WithAttributes(label.Int("count", len(l))))
defer span.End()
ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "internal_messages"))
stop := metrics.Timer(ctx, metrics.PersistDuration)
defer stop()
metrics.RecordCount(ctx, metrics.PersistModel, len(l))
return s.PersistModel(ctx, l)
}
type InternalParsedMessage struct {
//lint:ignore U1000 tableName is a convention used by go-pg
tableName struct{} `pg:"internal_parsed_messages"`
Height int64 `pg:",pk,notnull,use_zero"`
Cid string `pg:",pk,notnull"`
From string `pg:",notnull"`
To string `pg:",notnull"`
Value string `pg:"type:numeric,notnull"`
Method string `pg:",use_zero"`
Params string `pg:",type:jsonb"`
}
func (ipm *InternalParsedMessage) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error {
ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "internal_parsed_messages"))
stop := metrics.Timer(ctx, metrics.PersistDuration)
defer stop()
metrics.RecordCount(ctx, metrics.PersistModel, 1)
return s.PersistModel(ctx, ipm)
}
type InternalParsedMessageList []*InternalParsedMessage
func (l InternalParsedMessageList) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error {
if len(l) == 0 {
return nil
}
ctx, span := global.Tracer("").Start(ctx, "InternalParsedMessageList.Persist", trace.WithAttributes(label.Int("count", len(l))))
defer span.End()
ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "internal_parsed_messages"))
stop := metrics.Timer(ctx, metrics.PersistDuration)
defer stop()
metrics.RecordCount(ctx, metrics.PersistModel, len(l))
return s.PersistModel(ctx, l)
}