Skip to content

Commit

Permalink
change the params and returns type
Browse files Browse the repository at this point in the history
  • Loading branch information
Terry authored and Terry committed Jun 7, 2023
1 parent 10cd5d5 commit 33e7571
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 42 deletions.
24 changes: 14 additions & 10 deletions model/fevm/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,39 @@ type FEVMTrace struct {

// Cid of the trace.
TraceCid string `pg:",pk,notnull"`
// Filecoin Address of the sender.
From string `pg:",notnull"`
// Filecoin Address of the receiver.
To string `pg:",notnull"`
// ETH Address of the sender.
FromEthAddress string `pg:",notnull"`
From string `pg:",notnull"`
// ETH Address of the receiver.
ToEthAddress string `pg:",notnull"`
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"`
// GasUsed by message.
GasUsed int64 `pg:",notnull,use_zero"`
// Params contained in message encode in base64.
// Params contained in message encode in eth bytes.
Params string `pg:",notnull"`
// Returns value of message receipt encode in base64.
// 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 (v *FEVMTrace) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error {
Expand Down
20 changes: 11 additions & 9 deletions schemas/v1/26_fevm_traces.go → schemas/v1/27_fevm_traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,31 @@ package v1

func init() {
patches.Register(
26,
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,
trace_cid TEXT,
"from" TEXT,
"to" TEXT,
from_eth_address TEXT,
to_eth_address TEXT,
from_filecoin_address TEXT,
to_filecoin_address TEXT,
value NUMERIC,
method BIGINT,
parsed_method TEXT,
actor_code TEXT,
exit_code BIGINT,
gas_used BIGINT,
params TEXT,
returns TEXT,
index BIGINT,
returns TEXT,
index BIGINT,
parsed_params JSONB,
parsed_returns JSONB,
PRIMARY KEY(height, message_state_root, trace_cid, message_cid)
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");
Expand Down
51 changes: 28 additions & 23 deletions tasks/fevm/trace/task.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fevmvm
package fevmtrace

import (
"context"
Expand All @@ -22,9 +22,10 @@ import (
"github.com/filecoin-project/lily/model/fevm"
visormodel "github.com/filecoin-project/lily/model/visor"
tasks "github.com/filecoin-project/lily/tasks"
builtin "github.com/filecoin-project/lotus/chain/actors/builtin"
)

var log = logging.Logger("lily/tasks/fevmvm")
var log = logging.Logger("lily/tasks/fevmtrace")

type Task struct {
node tasks.DataSource
Expand Down Expand Up @@ -150,35 +151,39 @@ func (t *Task) ProcessTipSets(ctx context.Context, current *types.TipSet, execut
toEthAddress := getEthAddress(child.Message.To)

vmMsg := &fevm.FEVMTrace{
Height: int64(parentMsg.Height),
TransactionHash: transaction.Hash.String(),
MessageStateRoot: parentMsg.StateRoot.String(),
MessageCid: parentMsg.Cid.String(),
TraceCid: getMessageTraceCid(child.Message).String(),
To: child.Message.To.String(),
From: child.Message.From.String(),
FromEthAddress: fromEthAddress,
ToEthAddress: toEthAddress,
Value: child.Message.Value.String(),
GasUsed: 0,
ExitCode: int64(child.Receipt.ExitCode),
ActorCode: toActorCode,
Method: uint64(child.Message.Method),
Index: child.Index,
Params: base64.StdEncoding.EncodeToString(child.Message.Params),
Returns: base64.StdEncoding.EncodeToString(child.Receipt.Return),
Height: int64(parentMsg.Height),
TransactionHash: transaction.Hash.String(),
MessageStateRoot: parentMsg.StateRoot.String(),
MessageCid: parentMsg.Cid.String(),
TraceCid: getMessageTraceCid(child.Message).String(),
ToFilecoinAddress: child.Message.To.String(),
FromFilecoinAddress: child.Message.From.String(),
From: fromEthAddress,
To: toEthAddress,
Value: child.Message.Value.String(),
ExitCode: int64(child.Receipt.ExitCode),
ActorCode: toActorCode,
Method: uint64(child.Message.Method),
Index: child.Index,
Params: ethtypes.EthBytes(child.Message.Params).String(),
Returns: ethtypes.EthBytes(child.Receipt.Return).String(),
ParamsCodec: child.Message.ParamsCodec,
ReturnsCodec: child.Receipt.ReturnCodec,
}

// only parse params and return of successful messages since unsuccessful messages don't return a parseable value.
// As an example: a message may return ErrForbidden, it will have valid params, but will not contain a
// parsable return value in its receipt.
if child.Receipt.ExitCode.IsSuccess() {
params, _, err := util.ParseVmMessageParams(child.Message.Params, child.Message.ParamsCodec, child.Message.Method, toCode)
if err == nil {
params, parsedMethod, err := util.ParseVmMessageParams(child.Message.Params, child.Message.ParamsCodec, child.Message.Method, toCode)
// in ParseVmMessageParams it will return actor name when actor not found
if err == nil && parsedMethod != builtin.ActorNameByCode(toCode) {
vmMsg.ParsedParams = params
vmMsg.ParsedMethod = parsedMethod
}
ret, _, err := util.ParseVmMessageReturn(child.Receipt.Return, child.Receipt.ReturnCodec, child.Message.Method, toCode)
if err == nil {
ret, parsedMethod, err := util.ParseVmMessageReturn(child.Receipt.Return, child.Receipt.ReturnCodec, child.Message.Method, toCode)
// in ParseVmMessageParams it will return actor name when actor not found
if err == nil && parsedMethod != builtin.ActorNameByCode(toCode) {
vmMsg.ParsedReturns = ret
}
}
Expand Down

0 comments on commit 33e7571

Please sign in to comment.