Skip to content

Commit b907a50

Browse files
TerryhungTerry
andauthored
feat: add new task for fevm trace (#1217)
* Add new task for fevm trace --------- Co-authored-by: Terry <[email protected]>
1 parent 76a849c commit b907a50

File tree

10 files changed

+328
-3
lines changed

10 files changed

+328
-3
lines changed

chain/indexer/integrated/processor/state.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import (
6262
fevmblockheadertask "github.com/filecoin-project/lily/tasks/fevm/blockheader"
6363
fevmcontracttask "github.com/filecoin-project/lily/tasks/fevm/contract"
6464
fevmreceipttask "github.com/filecoin-project/lily/tasks/fevm/receipt"
65+
fevmtracetask "github.com/filecoin-project/lily/tasks/fevm/trace"
6566
fevmtransactiontask "github.com/filecoin-project/lily/tasks/fevm/transaction"
6667
fevmactorstatstask "github.com/filecoin-project/lily/tasks/fevmactorstats"
6768

@@ -674,6 +675,8 @@ func MakeProcessors(api tasks.DataSource, indexerTasks []string) (*IndexerProces
674675
out.TipsetsProcessors[t] = fevmtransactiontask.NewTask(api)
675676
case tasktype.FEVMContract:
676677
out.TipsetsProcessors[t] = fevmcontracttask.NewTask(api)
678+
case tasktype.FEVMTrace:
679+
out.TipsetsProcessors[t] = fevmtracetask.NewTask(api)
677680

678681
case BuiltinTaskName:
679682
out.ReportProcessors[t] = indexertask.NewTask(api)

chain/indexer/integrated/processor/state_internal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestNewProcessor(t *testing.T) {
5454
require.Equal(t, t.Name(), proc.name)
5555
require.Len(t, proc.actorProcessors, 24)
5656
require.Len(t, proc.tipsetProcessors, 10)
57-
require.Len(t, proc.tipsetsProcessors, 13)
57+
require.Len(t, proc.tipsetsProcessors, 14)
5858
require.Len(t, proc.builtinProcessors, 1)
5959

6060
require.Equal(t, gasoutput.NewTask(nil), proc.tipsetsProcessors[tasktype.GasOutputs])

chain/indexer/integrated/processor/state_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,6 @@ func TestMakeProcessorsAllTasks(t *testing.T) {
427427
require.NoError(t, err)
428428
require.Len(t, proc.ActorProcessors, 24)
429429
require.Len(t, proc.TipsetProcessors, 10)
430-
require.Len(t, proc.TipsetsProcessors, 13)
430+
require.Len(t, proc.TipsetsProcessors, 14)
431431
require.Len(t, proc.ReportProcessors, 1)
432432
}

chain/indexer/tasktype/table_tasks.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const (
4949
FEVMReceipt = "fevm_receipt"
5050
FEVMTransaction = "fevm_transaction"
5151
FEVMContract = "fevm_contract"
52+
FEVMTrace = "fevm_trace"
5253
)
5354

5455
var AllTableTasks = []string{
@@ -99,6 +100,7 @@ var AllTableTasks = []string{
99100
FEVMReceipt,
100101
FEVMTransaction,
101102
FEVMContract,
103+
FEVMTrace,
102104
}
103105

104106
var TableLookup = map[string]struct{}{
@@ -149,6 +151,7 @@ var TableLookup = map[string]struct{}{
149151
FEVMReceipt: {},
150152
FEVMTransaction: {},
151153
FEVMContract: {},
154+
FEVMTrace: {},
152155
}
153156

154157
var TableComment = map[string]string{
@@ -199,6 +202,7 @@ var TableComment = map[string]string{
199202
FEVMReceipt: ``,
200203
FEVMTransaction: ``,
201204
FEVMContract: ``,
205+
FEVMTrace: ``,
202206
}
203207

204208
var TableFieldComments = map[string]map[string]string{
@@ -306,4 +310,5 @@ var TableFieldComments = map[string]map[string]string{
306310
FEVMReceipt: {},
307311
FEVMTransaction: {},
308312
FEVMContract: {},
313+
FEVMTrace: {},
309314
}

chain/indexer/tasktype/tasks.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ var TaskLookup = map[string][]string{
9797
FEVMReceipt,
9898
FEVMTransaction,
9999
FEVMContract,
100+
FEVMTrace,
100101
},
101102
}
102103

chain/indexer/tasktype/tasks_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func TestMakeAllTaskAliasNames(t *testing.T) {
101101
}
102102

103103
func TestMakeAllTaskNames(t *testing.T) {
104-
const TotalTableTasks = 47
104+
const TotalTableTasks = 48
105105
actual, err := tasktype.MakeTaskNames(tasktype.AllTableTasks)
106106
require.NoError(t, err)
107107
// if this test fails it means a new task name was added, update the above test

model/fevm/trace.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package fevm
2+
3+
import (
4+
"context"
5+
6+
"go.opencensus.io/tag"
7+
8+
"github.com/filecoin-project/lily/metrics"
9+
"github.com/filecoin-project/lily/model"
10+
)
11+
12+
type FEVMTrace struct {
13+
tableName struct{} `pg:"fevm_traces"` // nolint: structcheck
14+
15+
// Height message was executed at.
16+
Height int64 `pg:",pk,notnull,use_zero"`
17+
// StateRoot message was applied to.
18+
MessageStateRoot string `pg:",pk,notnull"`
19+
// On-chain message triggering the message.
20+
MessageCid string `pg:",pk,notnull"`
21+
// On-chain message ETH transaction hash
22+
TransactionHash string `pg:",notnull"`
23+
24+
// Cid of the trace.
25+
TraceCid string `pg:",pk,notnull"`
26+
// ETH Address of the sender.
27+
From string `pg:",notnull"`
28+
// ETH Address of the receiver.
29+
To string `pg:",notnull"`
30+
// Filecoin Address of the sender.
31+
FromFilecoinAddress string `pg:",notnull"`
32+
// Filecoin Address of the receiver.
33+
ToFilecoinAddress string `pg:",notnull"`
34+
35+
// Value attoFIL contained in message.
36+
Value string `pg:"type:numeric,notnull"`
37+
// Method called on To (receiver).
38+
Method uint64 `pg:",notnull,use_zero"`
39+
// Params contained in message encode in eth bytes.
40+
ParsedMethod string `pg:",notnull"`
41+
// ActorCode of To (receiver).
42+
ActorCode string `pg:",notnull"`
43+
// ExitCode of message execution.
44+
ExitCode int64 `pg:",notnull,use_zero"`
45+
// Params contained in message encode in eth bytes.
46+
Params string `pg:",notnull"`
47+
// Returns value of message receipt encode in eth bytes.
48+
Returns string `pg:",notnull"`
49+
// Index indicating the order of the messages execution.
50+
Index uint64 `pg:",notnull,use_zero"`
51+
// Params contained in message.
52+
ParsedParams string `pg:",type:jsonb"`
53+
// Returns value of message receipt.
54+
ParsedReturns string `pg:",type:jsonb"`
55+
// Params codec.
56+
ParamsCodec uint64 `pg:",notnull,use_zero"`
57+
// Returns codec.
58+
ReturnsCodec uint64 `pg:",notnull,use_zero"`
59+
}
60+
61+
func (f *FEVMTrace) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error {
62+
ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "fevm_traces"))
63+
metrics.RecordCount(ctx, metrics.PersistModel, 1)
64+
return s.PersistModel(ctx, f)
65+
}
66+
67+
type FEVMTraceList []*FEVMTrace
68+
69+
func (f FEVMTraceList) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error {
70+
if len(f) == 0 {
71+
return nil
72+
}
73+
ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "fevm_traces"))
74+
metrics.RecordCount(ctx, metrics.PersistModel, len(f))
75+
return s.PersistModel(ctx, f)
76+
}

schemas/v1/27_fevm_traces.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package v1
2+
3+
func init() {
4+
patches.Register(
5+
27,
6+
`
7+
CREATE TABLE IF NOT EXISTS {{ .SchemaName | default "public"}}.fevm_traces (
8+
height BIGINT NOT NULL,
9+
message_state_root TEXT,
10+
transaction_hash TEXT,
11+
message_cid TEXT,
12+
trace_cid TEXT,
13+
"from" TEXT,
14+
"to" TEXT,
15+
from_filecoin_address TEXT,
16+
to_filecoin_address TEXT,
17+
value NUMERIC,
18+
method BIGINT,
19+
parsed_method TEXT,
20+
actor_code TEXT,
21+
exit_code BIGINT,
22+
params TEXT,
23+
returns TEXT,
24+
index BIGINT,
25+
parsed_params JSONB,
26+
parsed_returns JSONB,
27+
params_codec BIGINT,
28+
returns_codec BIGINT,
29+
PRIMARY KEY(height, message_state_root, trace_cid, message_cid)
30+
);
31+
CREATE INDEX IF NOT EXISTS fevm_traces_height_idx ON {{ .SchemaName | default "public"}}.fevm_traces USING BTREE (height);
32+
CREATE INDEX IF NOT EXISTS fevm_traces_from_idx ON {{ .SchemaName | default "public"}}.fevm_traces USING HASH ("from");
33+
CREATE INDEX IF NOT EXISTS fevm_traces_to_idx ON {{ .SchemaName | default "public"}}.fevm_traces USING HASH ("to");
34+
35+
SELECT create_hypertable(
36+
'fevm_traces',
37+
'height',
38+
chunk_time_interval => 2880,
39+
if_not_exists => TRUE,
40+
migrate_data => TRUE
41+
);
42+
SELECT set_integer_now_func('fevm_traces', 'current_height', replace_if_exists => true);
43+
44+
`,
45+
)
46+
}

storage/sql.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ var Models = []interface{}{
9898
(*fevm.FEVMReceipt)(nil),
9999
(*fevm.FEVMTransaction)(nil),
100100
(*fevm.FEVMContract)(nil),
101+
(*fevm.FEVMTrace)(nil),
101102
}
102103

103104
var log = logging.Logger("lily/storage")

0 commit comments

Comments
 (0)