@@ -12,22 +12,23 @@ import (
1212
1313 "github.com/filecoin-project/go-address"
1414 "github.com/filecoin-project/go-hamt-ipld/v3"
15+ "github.com/filecoin-project/go-state-types/abi"
1516 "github.com/filecoin-project/lotus/api"
1617 "github.com/filecoin-project/lotus/chain/state"
1718 "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"
1825 lru "github.com/hashicorp/golang-lru"
1926 "github.com/ipfs/go-cid"
2027 logging "github.com/ipfs/go-log/v2"
2128 "go.opentelemetry.io/otel"
2229 "go.opentelemetry.io/otel/attribute"
2330 "golang.org/x/sync/singleflight"
2431
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-
3132 "github.com/filecoin-project/lily/chain/actors/adt"
3233 "github.com/filecoin-project/lily/chain/actors/adt/diff"
3334 "github.com/filecoin-project/lily/chain/actors/builtin/miner"
@@ -37,28 +38,28 @@ import (
3738)
3839
3940var (
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"
4950)
5051
5152func init () {
52- executedBlkMsgCacheSize = 4
53+ tipsetMessageReceiptCacheSize = 4
5354 executedTsCacheSize = 4
5455 diffPreCommitCacheSize = 500
5556 diffSectorCacheSize = 500
56- if s := os .Getenv (executedBlkMsgCacheSizeEnv ); s != "" {
57+ if s := os .Getenv (tipsetMessageReceiptSizeEnv ); s != "" {
5758 v , err := strconv .ParseInt (s , 10 , 64 )
5859 if err == nil {
59- executedBlkMsgCacheSize = int (v )
60+ tipsetMessageReceiptCacheSize = int (v )
6061 } 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 )
6263 }
6364 }
6465 if s := os .Getenv (executedTsCacheSizeEnv ); s != "" {
@@ -92,28 +93,12 @@ var _ tasks.DataSource = (*DataSource)(nil)
9293
9394var log = logging .Logger ("lily/datasource" )
9495
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-
11196func NewDataSource (node lens.API ) (* DataSource , error ) {
11297 t := & DataSource {
11398 node : node ,
11499 }
115100 var err error
116- t .executedBlkMsgCache , err = lru .New (executedBlkMsgCacheSize )
101+ t .tsBlkMsgRecCache , err = lru .New (tipsetMessageReceiptCacheSize )
117102 if err != nil {
118103 return nil , err
119104 }
@@ -137,6 +122,56 @@ func NewDataSource(node lens.API) (*DataSource, error) {
137122 return t , nil
138123}
139124
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+
140175func (t * DataSource ) TipSet (ctx context.Context , tsk types.TipSetKey ) (* types.TipSet , error ) {
141176 ctx , span := otel .Tracer ("" ).Start (ctx , "DataSource.TipSet" )
142177 if span .IsRecording () {
@@ -239,45 +274,20 @@ func (t *DataSource) MessageExecutions(ctx context.Context, ts, pts *types.TipSe
239274 return value .([]* lens.MessageExecution ), nil
240275}
241276
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+ }
266280
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+ }
269284
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 )
273287 if err != nil {
274- return nil , err
288+ return vm. GasOutputs {} , err
275289 }
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
281291}
282292
283293func GetActorStateChanges (ctx context.Context , store adt.Store , current , executed * types.TipSet ) (tasks.ActorStateChangeDiff , error ) {
0 commit comments