|
| 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 | +} |
0 commit comments