Skip to content

Commit 5a34226

Browse files
TerryhungTerry
andauthored
feat: add new task fevm contract (#1214)
* Add new task: fevm_contract * Refine the util function name and height value --------- Co-authored-by: Terry <[email protected]>
1 parent 744faa5 commit 5a34226

File tree

14 files changed

+199
-7
lines changed

14 files changed

+199
-7
lines changed

chain/indexer/integrated/processor/state.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import (
6060

6161
// fevm task
6262
fevmblockheadertask "github.com/filecoin-project/lily/tasks/fevm/blockheader"
63+
fevmcontracttask "github.com/filecoin-project/lily/tasks/fevm/contract"
6364
fevmreceipttask "github.com/filecoin-project/lily/tasks/fevm/receipt"
6465
fevmtransactiontask "github.com/filecoin-project/lily/tasks/fevm/transaction"
6566
fevmactorstatstask "github.com/filecoin-project/lily/tasks/fevmactorstats"
@@ -650,6 +651,8 @@ func MakeProcessors(api tasks.DataSource, indexerTasks []string) (*IndexerProces
650651
out.TipsetsProcessors[t] = fevmreceipttask.NewTask(api)
651652
case tasktype.FEVMTransaction:
652653
out.TipsetsProcessors[t] = fevmtransactiontask.NewTask(api)
654+
case tasktype.FEVMContract:
655+
out.TipsetsProcessors[t] = fevmcontracttask.NewTask(api)
653656

654657
case BuiltinTaskName:
655658
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, 12)
57+
require.Len(t, proc.tipsetsProcessors, 13)
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
@@ -408,6 +408,6 @@ func TestMakeProcessorsAllTasks(t *testing.T) {
408408
require.NoError(t, err)
409409
require.Len(t, proc.ActorProcessors, 24)
410410
require.Len(t, proc.TipsetProcessors, 10)
411-
require.Len(t, proc.TipsetsProcessors, 12)
411+
require.Len(t, proc.TipsetsProcessors, 13)
412412
require.Len(t, proc.ReportProcessors, 1)
413413
}

chain/indexer/tasktype/table_tasks.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const (
4848
FEVMBlockHeader = "fevm_block_header"
4949
FEVMReceipt = "fevm_receipt"
5050
FEVMTransaction = "fevm_transaction"
51+
FEVMContract = "fevm_contract"
5152
)
5253

5354
var AllTableTasks = []string{
@@ -97,6 +98,7 @@ var AllTableTasks = []string{
9798
FEVMBlockHeader,
9899
FEVMReceipt,
99100
FEVMTransaction,
101+
FEVMContract,
100102
}
101103

102104
var TableLookup = map[string]struct{}{
@@ -146,6 +148,7 @@ var TableLookup = map[string]struct{}{
146148
FEVMBlockHeader: {},
147149
FEVMReceipt: {},
148150
FEVMTransaction: {},
151+
FEVMContract: {},
149152
}
150153

151154
var TableComment = map[string]string{
@@ -195,6 +198,7 @@ var TableComment = map[string]string{
195198
FEVMBlockHeader: ``,
196199
FEVMReceipt: ``,
197200
FEVMTransaction: ``,
201+
FEVMContract: ``,
198202
}
199203

200204
var TableFieldComments = map[string]map[string]string{
@@ -301,4 +305,5 @@ var TableFieldComments = map[string]map[string]string{
301305
FEVMBlockHeader: {},
302306
FEVMReceipt: {},
303307
FEVMTransaction: {},
308+
FEVMContract: {},
304309
}

chain/indexer/tasktype/tasks.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ var TaskLookup = map[string][]string{
9696
FEVMBlockHeader,
9797
FEVMReceipt,
9898
FEVMTransaction,
99+
FEVMContract,
99100
},
100101
}
101102

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 = 46
104+
const TotalTableTasks = 47
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

lens/util/fevm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/filecoin-project/lotus/chain/types"
1010
)
1111

12-
func IsSentToEVMAddress(ctx context.Context, ds tasks.DataSource, addr address.Address, tsk types.TipSetKey) bool {
12+
func IsEVMAddress(ctx context.Context, ds tasks.DataSource, addr address.Address, tsk types.TipSetKey) bool {
1313
act, err := ds.Actor(ctx, addr, tsk)
1414
if err != nil {
1515
// If actor not found, check if it's a placeholder address.

model/fevm/contract.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 FEVMContract struct {
13+
tableName struct{} `pg:"fevm_contracts"` // nolint: structcheck
14+
15+
// Height message was executed at.
16+
Height int64 `pg:",pk,notnull,use_zero"`
17+
18+
// Actor address.
19+
ActorID string `pg:",notnull"`
20+
21+
// Actor Address in ETH
22+
EthAddress string `pg:",notnull"`
23+
24+
ByteCode string `pg:",notnull"`
25+
ByteCodeHash string `pg:",notnull"`
26+
27+
Balance string `pg:"type:numeric,notnull"`
28+
Nonce uint64 `pg:",use_zero"`
29+
}
30+
31+
func (f *FEVMContract) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error {
32+
ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "fevm_contracts"))
33+
metrics.RecordCount(ctx, metrics.PersistModel, 1)
34+
return s.PersistModel(ctx, f)
35+
}
36+
37+
type FEVMContractList []*FEVMContract
38+
39+
func (f FEVMContractList) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error {
40+
if len(f) == 0 {
41+
return nil
42+
}
43+
ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "fevm_contracts"))
44+
metrics.RecordCount(ctx, metrics.PersistModel, len(f))
45+
return s.PersistModel(ctx, f)
46+
}

schemas/v1/25_fevm_contract.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package v1
2+
3+
func init() {
4+
patches.Register(
5+
25,
6+
`
7+
CREATE TABLE IF NOT EXISTS {{ .SchemaName | default "public"}}.fevm_contracts (
8+
height BIGINT NOT NULL,
9+
actor_id TEXT,
10+
eth_address TEXT,
11+
byte_code TEXT,
12+
byte_code_hash TEXT,
13+
balance NUMERIC,
14+
nonce BIGINT,
15+
PRIMARY KEY(height, actor_id, nonce)
16+
);
17+
`,
18+
)
19+
}

storage/sql.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ var Models = []interface{}{
9797
(*fevm.FEVMBlockHeader)(nil),
9898
(*fevm.FEVMReceipt)(nil),
9999
(*fevm.FEVMTransaction)(nil),
100+
(*fevm.FEVMContract)(nil),
100101
}
101102

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

0 commit comments

Comments
 (0)