Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new task for fevm trace #1217

Merged
merged 8 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions chain/indexer/integrated/processor/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import (
fevmblockheadertask "github.com/filecoin-project/lily/tasks/fevm/blockheader"
fevmcontracttask "github.com/filecoin-project/lily/tasks/fevm/contract"
fevmreceipttask "github.com/filecoin-project/lily/tasks/fevm/receipt"
fevmtracetask "github.com/filecoin-project/lily/tasks/fevm/trace"
fevmtransactiontask "github.com/filecoin-project/lily/tasks/fevm/transaction"
fevmactorstatstask "github.com/filecoin-project/lily/tasks/fevmactorstats"

Expand Down Expand Up @@ -674,6 +675,8 @@ func MakeProcessors(api tasks.DataSource, indexerTasks []string) (*IndexerProces
out.TipsetsProcessors[t] = fevmtransactiontask.NewTask(api)
case tasktype.FEVMContract:
out.TipsetsProcessors[t] = fevmcontracttask.NewTask(api)
case tasktype.FEVMTrace:
out.TipsetsProcessors[t] = fevmtracetask.NewTask(api)

case BuiltinTaskName:
out.ReportProcessors[t] = indexertask.NewTask(api)
Expand Down
2 changes: 1 addition & 1 deletion chain/indexer/integrated/processor/state_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestNewProcessor(t *testing.T) {
require.Equal(t, t.Name(), proc.name)
require.Len(t, proc.actorProcessors, 24)
require.Len(t, proc.tipsetProcessors, 10)
require.Len(t, proc.tipsetsProcessors, 13)
require.Len(t, proc.tipsetsProcessors, 14)
require.Len(t, proc.builtinProcessors, 1)

require.Equal(t, gasoutput.NewTask(nil), proc.tipsetsProcessors[tasktype.GasOutputs])
Expand Down
2 changes: 1 addition & 1 deletion chain/indexer/integrated/processor/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,6 @@ func TestMakeProcessorsAllTasks(t *testing.T) {
require.NoError(t, err)
require.Len(t, proc.ActorProcessors, 24)
require.Len(t, proc.TipsetProcessors, 10)
require.Len(t, proc.TipsetsProcessors, 13)
require.Len(t, proc.TipsetsProcessors, 14)
require.Len(t, proc.ReportProcessors, 1)
}
5 changes: 5 additions & 0 deletions chain/indexer/tasktype/table_tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const (
FEVMReceipt = "fevm_receipt"
FEVMTransaction = "fevm_transaction"
FEVMContract = "fevm_contract"
FEVMTrace = "fevm_trace"
)

var AllTableTasks = []string{
Expand Down Expand Up @@ -99,6 +100,7 @@ var AllTableTasks = []string{
FEVMReceipt,
FEVMTransaction,
FEVMContract,
FEVMTrace,
}

var TableLookup = map[string]struct{}{
Expand Down Expand Up @@ -149,6 +151,7 @@ var TableLookup = map[string]struct{}{
FEVMReceipt: {},
FEVMTransaction: {},
FEVMContract: {},
FEVMTrace: {},
}

var TableComment = map[string]string{
Expand Down Expand Up @@ -199,6 +202,7 @@ var TableComment = map[string]string{
FEVMReceipt: ``,
FEVMTransaction: ``,
FEVMContract: ``,
FEVMTrace: ``,
}

var TableFieldComments = map[string]map[string]string{
Expand Down Expand Up @@ -306,4 +310,5 @@ var TableFieldComments = map[string]map[string]string{
FEVMReceipt: {},
FEVMTransaction: {},
FEVMContract: {},
FEVMTrace: {},
}
1 change: 1 addition & 0 deletions chain/indexer/tasktype/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ var TaskLookup = map[string][]string{
FEVMReceipt,
FEVMTransaction,
FEVMContract,
FEVMTrace,
},
}

Expand Down
2 changes: 1 addition & 1 deletion chain/indexer/tasktype/tasks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestMakeAllTaskAliasNames(t *testing.T) {
}

func TestMakeAllTaskNames(t *testing.T) {
const TotalTableTasks = 47
const TotalTableTasks = 48
actual, err := tasktype.MakeTaskNames(tasktype.AllTableTasks)
require.NoError(t, err)
// if this test fails it means a new task name was added, update the above test
Expand Down
76 changes: 76 additions & 0 deletions model/fevm/trace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package fevm

import (
"context"

"go.opencensus.io/tag"

"github.com/filecoin-project/lily/metrics"
"github.com/filecoin-project/lily/model"
)

type FEVMTrace struct {
tableName struct{} `pg:"fevm_traces"` // nolint: structcheck

// Height message was executed at.
Height int64 `pg:",pk,notnull,use_zero"`
// StateRoot message was applied to.
MessageStateRoot string `pg:",pk,notnull"`
// On-chain message triggering the message.
MessageCid string `pg:",pk,notnull"`
// On-chain message ETH transaction hash
TransactionHash string `pg:",notnull"`

// Cid of the trace.
TraceCid string `pg:",pk,notnull"`
// ETH Address of the sender.
From string `pg:",notnull"`
// ETH Address of the receiver.
To string `pg:",notnull"`
// Filecoin Address of the sender.
FromFilecoinAddress string `pg:",notnull"`
// Filecoin Address of the receiver.
ToFilecoinAddress string `pg:",notnull"`

// Value attoFIL contained in message.
Value string `pg:"type:numeric,notnull"`
// Method called on To (receiver).
Method uint64 `pg:",notnull,use_zero"`
// Params contained in message encode in eth bytes.
ParsedMethod string `pg:",notnull"`
// ActorCode of To (receiver).
ActorCode string `pg:",notnull"`
// ExitCode of message execution.
ExitCode int64 `pg:",notnull,use_zero"`
// Params contained in message encode in eth bytes.
Params string `pg:",notnull"`
// Returns value of message receipt encode in eth bytes.
Returns string `pg:",notnull"`
// Index indicating the order of the messages execution.
Index uint64 `pg:",notnull,use_zero"`
// Params contained in message.
ParsedParams string `pg:",type:jsonb"`
// Returns value of message receipt.
ParsedReturns string `pg:",type:jsonb"`
// Params codec.
ParamsCodec uint64 `pg:",notnull,use_zero"`
// Returns codec.
ReturnsCodec uint64 `pg:",notnull,use_zero"`
}

func (f *FEVMTrace) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error {
ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "fevm_traces"))
metrics.RecordCount(ctx, metrics.PersistModel, 1)
return s.PersistModel(ctx, f)
}

type FEVMTraceList []*FEVMTrace

func (f FEVMTraceList) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error {
if len(f) == 0 {
return nil
}
ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "fevm_traces"))
metrics.RecordCount(ctx, metrics.PersistModel, len(f))
return s.PersistModel(ctx, f)
}
46 changes: 46 additions & 0 deletions schemas/v1/27_fevm_traces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package v1

func init() {
patches.Register(
27,
`
CREATE TABLE IF NOT EXISTS {{ .SchemaName | default "public"}}.fevm_traces (
height BIGINT NOT NULL,
message_state_root TEXT,
transaction_hash TEXT,
message_cid TEXT,
trace_cid TEXT,
"from" TEXT,
"to" TEXT,
from_filecoin_address TEXT,
to_filecoin_address TEXT,
value NUMERIC,
method BIGINT,
parsed_method TEXT,
actor_code TEXT,
exit_code BIGINT,
params TEXT,
returns TEXT,
index BIGINT,
parsed_params JSONB,
parsed_returns JSONB,
params_codec BIGINT,
returns_codec BIGINT,
PRIMARY KEY(height, message_state_root, trace_cid, message_cid)
);
CREATE INDEX IF NOT EXISTS fevm_traces_height_idx ON {{ .SchemaName | default "public"}}.fevm_traces USING BTREE (height);
CREATE INDEX IF NOT EXISTS fevm_traces_from_idx ON {{ .SchemaName | default "public"}}.fevm_traces USING HASH ("from");
CREATE INDEX IF NOT EXISTS fevm_traces_to_idx ON {{ .SchemaName | default "public"}}.fevm_traces USING HASH ("to");

SELECT create_hypertable(
'fevm_traces',
'height',
chunk_time_interval => 2880,
if_not_exists => TRUE,
migrate_data => TRUE
);
SELECT set_integer_now_func('fevm_traces', 'current_height', replace_if_exists => true);

`,
)
}
1 change: 1 addition & 0 deletions storage/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ var Models = []interface{}{
(*fevm.FEVMReceipt)(nil),
(*fevm.FEVMTransaction)(nil),
(*fevm.FEVMContract)(nil),
(*fevm.FEVMTrace)(nil),
}

var log = logging.Logger("lily/storage")
Expand Down
Loading