@@ -12,22 +12,23 @@ import (
12
12
13
13
"github.com/filecoin-project/go-address"
14
14
"github.com/filecoin-project/go-hamt-ipld/v3"
15
+ "github.com/filecoin-project/go-state-types/abi"
15
16
"github.com/filecoin-project/lotus/api"
16
17
"github.com/filecoin-project/lotus/chain/state"
17
18
"github.com/filecoin-project/lotus/chain/types"
19
+ "github.com/filecoin-project/lotus/chain/vm"
20
+ states0 "github.com/filecoin-project/specs-actors/actors/states"
21
+ states2 "github.com/filecoin-project/specs-actors/v2/actors/states"
22
+ states3 "github.com/filecoin-project/specs-actors/v3/actors/states"
23
+ states4 "github.com/filecoin-project/specs-actors/v4/actors/states"
24
+ states5 "github.com/filecoin-project/specs-actors/v5/actors/states"
18
25
lru "github.com/hashicorp/golang-lru"
19
26
"github.com/ipfs/go-cid"
20
27
logging "github.com/ipfs/go-log/v2"
21
28
"go.opentelemetry.io/otel"
22
29
"go.opentelemetry.io/otel/attribute"
23
30
"golang.org/x/sync/singleflight"
24
31
25
- states0 "github.com/filecoin-project/specs-actors/actors/states"
26
- states2 "github.com/filecoin-project/specs-actors/v2/actors/states"
27
- states3 "github.com/filecoin-project/specs-actors/v3/actors/states"
28
- states4 "github.com/filecoin-project/specs-actors/v4/actors/states"
29
- states5 "github.com/filecoin-project/specs-actors/v5/actors/states"
30
-
31
32
"github.com/filecoin-project/lily/chain/actors/adt"
32
33
"github.com/filecoin-project/lily/chain/actors/adt/diff"
33
34
"github.com/filecoin-project/lily/chain/actors/builtin/miner"
@@ -37,28 +38,28 @@ import (
37
38
)
38
39
39
40
var (
40
- executedBlkMsgCacheSize int
41
- executedTsCacheSize int
42
- diffPreCommitCacheSize int
43
- diffSectorCacheSize int
44
-
45
- executedBlkMsgCacheSizeEnv = "LILY_EXECUTED_BLK_MSG_CACHE_SIZE "
46
- executedTsCacheSizeEnv = "LILY_EXECUTED_TS_CACHE_SIZE"
47
- diffPreCommitCacheSizeEnv = "LILY_DIFF_PRECOMMIT_CACHE_SIZE"
48
- diffSectorCacheSizeEnv = "LILY_DIFF_SECTORS_CACHE_SIZE"
41
+ tipsetMessageReceiptCacheSize int
42
+ executedTsCacheSize int
43
+ diffPreCommitCacheSize int
44
+ diffSectorCacheSize int
45
+
46
+ tipsetMessageReceiptSizeEnv = "LILY_TIPSET_MSG_RECEIPT_CACHE_SIZE "
47
+ executedTsCacheSizeEnv = "LILY_EXECUTED_TS_CACHE_SIZE"
48
+ diffPreCommitCacheSizeEnv = "LILY_DIFF_PRECOMMIT_CACHE_SIZE"
49
+ diffSectorCacheSizeEnv = "LILY_DIFF_SECTORS_CACHE_SIZE"
49
50
)
50
51
51
52
func init () {
52
- executedBlkMsgCacheSize = 4
53
+ tipsetMessageReceiptCacheSize = 4
53
54
executedTsCacheSize = 4
54
55
diffPreCommitCacheSize = 500
55
56
diffSectorCacheSize = 500
56
- if s := os .Getenv (executedBlkMsgCacheSizeEnv ); s != "" {
57
+ if s := os .Getenv (tipsetMessageReceiptSizeEnv ); s != "" {
57
58
v , err := strconv .ParseInt (s , 10 , 64 )
58
59
if err == nil {
59
- executedBlkMsgCacheSize = int (v )
60
+ tipsetMessageReceiptCacheSize = int (v )
60
61
} else {
61
- log .Warnf ("invalid value (%s) for %s defaulting to %d: %s" , s , executedBlkMsgCacheSizeEnv , executedBlkMsgCacheSize , err )
62
+ log .Warnf ("invalid value (%s) for %s defaulting to %d: %s" , s , tipsetMessageReceiptSizeEnv , tipsetMessageReceiptCacheSize , err )
62
63
}
63
64
}
64
65
if s := os .Getenv (executedTsCacheSizeEnv ); s != "" {
@@ -92,28 +93,12 @@ var _ tasks.DataSource = (*DataSource)(nil)
92
93
93
94
var log = logging .Logger ("lily/datasource" )
94
95
95
- type DataSource struct {
96
- node lens.API
97
-
98
- executedBlkMsgCache * lru.Cache
99
- executedBlkMsgGroup singleflight.Group
100
-
101
- executedTsCache * lru.Cache
102
- executedTsGroup singleflight.Group
103
-
104
- diffSectorsCache * lru.Cache
105
- diffSectorsGroup singleflight.Group
106
-
107
- diffPreCommitCache * lru.Cache
108
- diffPreCommitGroup singleflight.Group
109
- }
110
-
111
96
func NewDataSource (node lens.API ) (* DataSource , error ) {
112
97
t := & DataSource {
113
98
node : node ,
114
99
}
115
100
var err error
116
- t .executedBlkMsgCache , err = lru .New (executedBlkMsgCacheSize )
101
+ t .tsBlkMsgRecCache , err = lru .New (tipsetMessageReceiptCacheSize )
117
102
if err != nil {
118
103
return nil , err
119
104
}
@@ -137,6 +122,56 @@ func NewDataSource(node lens.API) (*DataSource, error) {
137
122
return t , nil
138
123
}
139
124
125
+ type DataSource struct {
126
+ node lens.API
127
+
128
+ executedTsCache * lru.Cache
129
+ executedTsGroup singleflight.Group
130
+
131
+ tsBlkMsgRecCache * lru.Cache
132
+ tsBlkMsgRecGroup singleflight.Group
133
+
134
+ diffSectorsCache * lru.Cache
135
+ diffSectorsGroup singleflight.Group
136
+
137
+ diffPreCommitCache * lru.Cache
138
+ diffPreCommitGroup singleflight.Group
139
+ }
140
+
141
+ func (t * DataSource ) ComputeBaseFee (ctx context.Context , ts * types.TipSet ) (abi.TokenAmount , error ) {
142
+ return t .node .ComputeBaseFee (ctx , ts )
143
+ }
144
+
145
+ func (t * DataSource ) TipSetBlockMessages (ctx context.Context , ts * types.TipSet ) ([]* lens.BlockMessages , error ) {
146
+ return t .node .MessagesForTipSetBlocks (ctx , ts )
147
+ }
148
+
149
+ // TipSetMessageReceipts returns the blocks and messages in `pts` and their corresponding receipts from `ts` matching block order in tipset (`pts`).
150
+ // TODO replace with lotus chainstore method when https://github.com/filecoin-project/lotus/pull/9186 lands
151
+ func (t * DataSource ) TipSetMessageReceipts (ctx context.Context , ts , pts * types.TipSet ) ([]* lens.BlockMessageReceipts , error ) {
152
+ key , err := asKey (ts , pts )
153
+ if err != nil {
154
+ return nil , err
155
+ }
156
+ value , found := t .tsBlkMsgRecCache .Get (key )
157
+ if found {
158
+ return value .([]* lens.BlockMessageReceipts ), nil
159
+ }
160
+
161
+ value , err , _ = t .tsBlkMsgRecGroup .Do (key , func () (interface {}, error ) {
162
+ data , innerErr := t .node .TipSetMessageReceipts (ctx , ts , pts )
163
+ if innerErr == nil {
164
+ t .tsBlkMsgRecCache .Add (key , data )
165
+ }
166
+ return data , innerErr
167
+ })
168
+ if err != nil {
169
+ return nil , err
170
+ }
171
+
172
+ return value .([]* lens.BlockMessageReceipts ), nil
173
+ }
174
+
140
175
func (t * DataSource ) TipSet (ctx context.Context , tsk types.TipSetKey ) (* types.TipSet , error ) {
141
176
ctx , span := otel .Tracer ("" ).Start (ctx , "DataSource.TipSet" )
142
177
if span .IsRecording () {
@@ -239,45 +274,20 @@ func (t *DataSource) MessageExecutions(ctx context.Context, ts, pts *types.TipSe
239
274
return value .([]* lens.MessageExecution ), nil
240
275
}
241
276
242
- func (t * DataSource ) ExecutedAndBlockMessages (ctx context.Context , ts , pts * types.TipSet ) (* lens.TipSetMessages , error ) {
243
- metrics .RecordInc (ctx , metrics .DataSourceExecutedAndBlockMessagesRead )
244
- ctx , span := otel .Tracer ("" ).Start (ctx , "DataSource.ExecutedAndBlockMessages" )
245
- if span .IsRecording () {
246
- span .SetAttributes (attribute .String ("tipset" , ts .Key ().String ()))
247
- span .SetAttributes (attribute .String ("parent" , pts .Key ().String ()))
248
- }
249
- defer span .End ()
250
-
251
- key , err := asKey (ts , pts )
252
- if err != nil {
253
- return nil , err
254
- }
255
- value , found := t .executedBlkMsgCache .Get (key )
256
- if found {
257
- metrics .RecordInc (ctx , metrics .DataSourceExecutedAndBlockMessagesCacheHit )
258
- return value .(* lens.TipSetMessages ), nil
259
- }
260
-
261
- value , err , shared := t .executedBlkMsgGroup .Do (key , func () (interface {}, error ) {
262
- data , innerErr := t .node .GetExecutedAndBlockMessagesForTipset (ctx , ts , pts )
263
- if innerErr == nil {
264
- t .executedBlkMsgCache .Add (key , data )
265
- }
277
+ func (t * DataSource ) MinerLoad (store adt.Store , act * types.Actor ) (miner.State , error ) {
278
+ return miner .Load (store , act )
279
+ }
266
280
267
- return data , innerErr
268
- })
281
+ func (t * DataSource ) ShouldBurnFn (ctx context.Context , ts * types.TipSet ) (lens.ShouldBurnFn , error ) {
282
+ return t .node .BurnFundsFn (ctx , ts )
283
+ }
269
284
270
- if span .IsRecording () {
271
- span .SetAttributes (attribute .Bool ("shared" , shared ))
272
- }
285
+ func ComputeGasOutputs (ctx context.Context , block * types.BlockHeader , message * types.Message , receipt * types.MessageReceipt , shouldBurnFn lens.ShouldBurnFn ) (vm.GasOutputs , error ) {
286
+ burn , err := shouldBurnFn (ctx , message , receipt .ExitCode )
273
287
if err != nil {
274
- return nil , err
288
+ return vm. GasOutputs {} , err
275
289
}
276
- return value .(* lens.TipSetMessages ), nil
277
- }
278
-
279
- func (t * DataSource ) MinerLoad (store adt.Store , act * types.Actor ) (miner.State , error ) {
280
- return miner .Load (store , act )
290
+ return vm .ComputeGasOutputs (receipt .GasUsed , message .GasLimit , block .ParentBaseFee , message .GasFeeCap , message .GasPremium , burn ), nil
281
291
}
282
292
283
293
func GetActorStateChanges (ctx context.Context , store adt.Store , current , executed * types.TipSet ) (tasks.ActorStateChangeDiff , error ) {
0 commit comments