/
dealstate.go
42 lines (33 loc) · 1.23 KB
/
dealstate.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
package market
import (
"context"
"go.opencensus.io/tag"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"github.com/filecoin-project/lily/metrics"
"github.com/filecoin-project/lily/model"
)
type MarketDealState struct {
Height int64 `pg:",pk,notnull,use_zero"`
DealID uint64 `pg:",pk,use_zero"`
SectorStartEpoch int64 `pg:",use_zero"`
LastUpdateEpoch int64 `pg:",use_zero"`
SlashEpoch int64 `pg:",use_zero"`
StateRoot string `pg:",pk,notnull"`
}
func (ds *MarketDealState) Persist(ctx context.Context, s model.StorageBatch, _ model.Version) error {
ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "market_deal_states"))
metrics.RecordCount(ctx, metrics.PersistModel, 1)
return s.PersistModel(ctx, ds)
}
type MarketDealStates []*MarketDealState
func (dss MarketDealStates) Persist(ctx context.Context, s model.StorageBatch, _ model.Version) error {
ctx, span := otel.Tracer("").Start(ctx, "MarketDealStates.Persist")
if span.IsRecording() {
span.SetAttributes(attribute.Int("count", len(dss)))
}
defer span.End()
ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "market_deal_states"))
metrics.RecordCount(ctx, metrics.PersistModel, len(dss))
return s.PersistModel(ctx, dss)
}