From 5cf438866896a7e39936ab9eaf12841d73413252 Mon Sep 17 00:00:00 2001 From: birdy Date: Wed, 29 Mar 2023 00:49:56 -0700 Subject: [PATCH 1/8] Create fevm tasks for actor balance and count --- chain/indexer/integrated/processor/state.go | 9 ++ chain/indexer/tasktype/table_tasks.go | 10 ++ model/fevm/actorcount.go | 46 +++++++++ tasks/fevm/actorbalance/task.go | 1 + tasks/fevm/actorcount/task.go | 104 ++++++++++++++++++++ 5 files changed, 170 insertions(+) create mode 100644 model/fevm/actorcount.go create mode 100644 tasks/fevm/actorbalance/task.go create mode 100644 tasks/fevm/actorcount/task.go diff --git a/chain/indexer/integrated/processor/state.go b/chain/indexer/integrated/processor/state.go index 566fc5592..a1895392b 100644 --- a/chain/indexer/integrated/processor/state.go +++ b/chain/indexer/integrated/processor/state.go @@ -58,6 +58,9 @@ import ( receipttask "github.com/filecoin-project/lily/tasks/messages/receipt" msapprovaltask "github.com/filecoin-project/lily/tasks/msapprovals" + // FEVM task + fevmactortask "github.com/filecoin-project/lily/tasks/fevm/actorcount" + "github.com/filecoin-project/lily/chain/indexer/tasktype" "github.com/filecoin-project/lily/metrics" "github.com/filecoin-project/lily/model" @@ -628,6 +631,12 @@ func MakeProcessors(api tasks.DataSource, indexerTasks []string) (*IndexerProces case tasktype.ChainConsensus: out.TipsetProcessors[t] = consensustask.NewTask(api) + // + // FEVM + // + case tasktype.FEVMActorCount: + out.TipsetProcessors[t] = fevmactortask.NewTask(api) + case BuiltinTaskName: out.ReportProcessors[t] = indexertask.NewTask(api) default: diff --git a/chain/indexer/tasktype/table_tasks.go b/chain/indexer/tasktype/table_tasks.go index f1f1040e1..2d0493d2e 100644 --- a/chain/indexer/tasktype/table_tasks.go +++ b/chain/indexer/tasktype/table_tasks.go @@ -44,6 +44,8 @@ const ( VerifiedRegistryVerifier = "verified_registry_verifier" VerifiedRegistryVerifiedClient = "verified_registry_verified_client" VerifiedRegistryClaim = "verified_registry_claim" + FEVMActorBalance = "fevm_actor_balance" + FEVMActorCount = "fevm_actor_count" ) var AllTableTasks = []string{ @@ -89,6 +91,8 @@ var AllTableTasks = []string{ VerifiedRegistryVerifier, VerifiedRegistryVerifiedClient, VerifiedRegistryClaim, + FEVMActorBalance, + FEVMActorCount, } var TableLookup = map[string]struct{}{ @@ -134,6 +138,8 @@ var TableLookup = map[string]struct{}{ VerifiedRegistryVerifier: {}, VerifiedRegistryVerifiedClient: {}, VerifiedRegistryClaim: {}, + FEVMActorBalance: {}, + FEVMActorCount: {}, } var TableComment = map[string]string{ @@ -179,6 +185,8 @@ var TableComment = map[string]string{ VerifiedRegistryVerifier: ``, VerifiedRegistryVerifiedClient: ``, VerifiedRegistryClaim: ``, + FEVMActorBalance: ``, + FEVMActorCount: ``, } var TableFieldComments = map[string]map[string]string{ @@ -281,4 +289,6 @@ var TableFieldComments = map[string]map[string]string{ VerifiedRegistryVerifier: {}, VerifiedRegistryVerifiedClient: {}, VerifiedRegistryClaim: {}, + FEVMActorBalance: {}, + FEVMActorCount: {}, } diff --git a/model/fevm/actorcount.go b/model/fevm/actorcount.go new file mode 100644 index 000000000..7ff3a54a0 --- /dev/null +++ b/model/fevm/actorcount.go @@ -0,0 +1,46 @@ +package fevm + +import ( + "context" + + "go.opencensus.io/tag" + + "github.com/filecoin-project/lily/metrics" + "github.com/filecoin-project/lily/model" +) + +type FEVMActorCount struct { + tableName struct{} `pg:"fevm_actor_count"` // nolint: structcheck + + // Height message was executed at. + Height int64 `pg:",pk,notnull,use_zero"` + // Balance of EVM Actor in attoFIL. + EVMBalance string `pg:",notnull"` + // Balance of Eth Account Actor in attoFIL. + EthAccountBalance string `pg:",notnull"` + // Balance of Placeholder Actor in attoFIL. + PlaceholderBalance string `pg:",notnull"` +} + +func (f *FEVMActorCount) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error { + ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "fevm_actor_count")) + stop := metrics.Timer(ctx, metrics.PersistDuration) + defer stop() + + metrics.RecordCount(ctx, metrics.PersistModel, 1) + return s.PersistModel(ctx, f) +} + +type FEVMActorCountList []*FEVMActorCount + +func (f FEVMActorCountList) 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_actor_count")) + stop := metrics.Timer(ctx, metrics.PersistDuration) + defer stop() + + metrics.RecordCount(ctx, metrics.PersistModel, len(f)) + return s.PersistModel(ctx, f) +} diff --git a/tasks/fevm/actorbalance/task.go b/tasks/fevm/actorbalance/task.go new file mode 100644 index 000000000..39e7fa8a6 --- /dev/null +++ b/tasks/fevm/actorbalance/task.go @@ -0,0 +1 @@ +package actorbalance diff --git a/tasks/fevm/actorcount/task.go b/tasks/fevm/actorcount/task.go new file mode 100644 index 000000000..ddd7678d9 --- /dev/null +++ b/tasks/fevm/actorcount/task.go @@ -0,0 +1,104 @@ +package actorcount + +import ( + "context" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/lily/model" + visormodel "github.com/filecoin-project/lily/model/visor" + "github.com/filecoin-project/lily/tasks" + "github.com/filecoin-project/lotus/chain/actors/builtin" + evm2 "github.com/filecoin-project/lotus/chain/actors/builtin/evm" + "github.com/filecoin-project/lotus/chain/state" + "github.com/filecoin-project/lotus/chain/types" + "github.com/ipfs/go-cid" + logging "github.com/ipfs/go-log/v2" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" +) + +var log = logging.Logger("lily/tasks/fevmactor") + +type Task struct { + node tasks.DataSource +} + +func NewTask(node tasks.DataSource) *Task { + return &Task{ + node: node, + } +} + +func (p *Task) ProcessTipSet(ctx context.Context, ts *types.TipSet) (model.Persistable, *visormodel.ProcessingReport, error) { + _, span := otel.Tracer("").Start(ctx, "ProcessTipSet") + if span.IsRecording() { + span.SetAttributes( + attribute.String("tipset", ts.Key().String()), + attribute.Int64("height", int64(ts.Height())), + attribute.String("processor", "chaineconomics"), + ) + } + report := &visormodel.ProcessingReport{ + Height: int64(ts.Height()), + StateRoot: ts.ParentState().String(), + } + + st, err := state.LoadStateTree(p.node.Store(), ts.ParentState()) + if err != nil { + return nil, report, err + } + + log.Infow("iterating over all actors") + count := 0 + EvmCount := 0 + EthAccountCount := 0 + PlaceholderCount := 0 + bytecodeCIDs := []cid.Cid{} + + err = st.ForEach(func(addr address.Address, act *types.Actor) error { + if count%200000 == 0 { + log.Infow("processed /n", count) + } + count++ + + if builtin.IsEvmActor(act.Code) { + EvmCount++ + e, err := evm2.Load(p.node.Store(), act) + if err != nil { + log.Errorw("fail to load evm actorcount: %w", err) + return nil + } + bcid, err := e.GetBytecodeCID() + bytecodeCIDs = append(bytecodeCIDs, bcid) + } + + if builtin.IsEthAccountActor(act.Code) { + EthAccountCount++ + } + + if builtin.IsPlaceholderActor(act.Code) { + PlaceholderCount++ + } + + return nil + }) + + uniqueBytecodeCIDs := unique(bytecodeCIDs) + log.Infow("# of EVM contracts: ", EvmCount) + log.Infow("# of unqiue EVM contracts: ", len(uniqueBytecodeCIDs)) + log.Infow("b# of Eth accounts: ", EthAccountCount) + log.Infow("# of placeholder: ", PlaceholderCount) + + return nil, report, nil +} +func unique(intSlice []cid.Cid) []cid.Cid { + keys := make(map[cid.Cid]bool) + list := []cid.Cid{} + for _, entry := range intSlice { + if _, value := keys[entry]; !value { + keys[entry] = true + list = append(list, entry) + } + } + return list +} From 73a96253fd524ab0dbfa5892bbfa48b16af75173 Mon Sep 17 00:00:00 2001 From: birdy Date: Wed, 29 Mar 2023 02:32:45 -0700 Subject: [PATCH 2/8] fix logging --- tasks/fevm/actorcount/task.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tasks/fevm/actorcount/task.go b/tasks/fevm/actorcount/task.go index ddd7678d9..bdde372af 100644 --- a/tasks/fevm/actorcount/task.go +++ b/tasks/fevm/actorcount/task.go @@ -57,7 +57,7 @@ func (p *Task) ProcessTipSet(ctx context.Context, ts *types.TipSet) (model.Persi err = st.ForEach(func(addr address.Address, act *types.Actor) error { if count%200000 == 0 { - log.Infow("processed /n", count) + log.Infow("processed: ", "count", count) } count++ @@ -65,7 +65,7 @@ func (p *Task) ProcessTipSet(ctx context.Context, ts *types.TipSet) (model.Persi EvmCount++ e, err := evm2.Load(p.node.Store(), act) if err != nil { - log.Errorw("fail to load evm actorcount: %w", err) + log.Errorw("fail to load evm actorcount: ", "error", err) return nil } bcid, err := e.GetBytecodeCID() @@ -84,10 +84,10 @@ func (p *Task) ProcessTipSet(ctx context.Context, ts *types.TipSet) (model.Persi }) uniqueBytecodeCIDs := unique(bytecodeCIDs) - log.Infow("# of EVM contracts: ", EvmCount) - log.Infow("# of unqiue EVM contracts: ", len(uniqueBytecodeCIDs)) - log.Infow("b# of Eth accounts: ", EthAccountCount) - log.Infow("# of placeholder: ", PlaceholderCount) + log.Infow("# of EVM contracts: ", "count", EvmCount) + log.Infow("# of unqiue EVM contracts: ", "count", len(uniqueBytecodeCIDs)) + log.Infow("b# of Eth accounts: ", "count", EthAccountCount) + log.Infow("# of placeholder: ", "count", PlaceholderCount) return nil, report, nil } From 7a692d89cc9ab572338b9702e49598ef8d3c55dd Mon Sep 17 00:00:00 2001 From: birdy Date: Thu, 30 Mar 2023 02:00:00 -0700 Subject: [PATCH 3/8] refactor and add balance code --- chain/indexer/integrated/processor/state.go | 6 +- chain/indexer/tasktype/table_tasks.go | 15 ++--- model/fevm/actorcount.go | 46 --------------- model/fevm/fevmactorstats.go | 56 +++++++++++++++++++ schemas/v1/19_fevm_actor_stats.go | 20 +++++++ storage/sql.go | 3 + tasks/fevm/actorbalance/task.go | 1 - .../actorcount => fevmactorstats}/task.go | 41 ++++++++------ 8 files changed, 111 insertions(+), 77 deletions(-) delete mode 100644 model/fevm/actorcount.go create mode 100644 model/fevm/fevmactorstats.go create mode 100644 schemas/v1/19_fevm_actor_stats.go delete mode 100644 tasks/fevm/actorbalance/task.go rename tasks/{fevm/actorcount => fevmactorstats}/task.go (68%) diff --git a/chain/indexer/integrated/processor/state.go b/chain/indexer/integrated/processor/state.go index a1895392b..05bc54e81 100644 --- a/chain/indexer/integrated/processor/state.go +++ b/chain/indexer/integrated/processor/state.go @@ -3,6 +3,7 @@ package processor import ( "context" "fmt" + fevmactortask "github.com/filecoin-project/lily/tasks/fevmactorstats" "sync" "time" @@ -58,9 +59,6 @@ import ( receipttask "github.com/filecoin-project/lily/tasks/messages/receipt" msapprovaltask "github.com/filecoin-project/lily/tasks/msapprovals" - // FEVM task - fevmactortask "github.com/filecoin-project/lily/tasks/fevm/actorcount" - "github.com/filecoin-project/lily/chain/indexer/tasktype" "github.com/filecoin-project/lily/metrics" "github.com/filecoin-project/lily/model" @@ -634,7 +632,7 @@ func MakeProcessors(api tasks.DataSource, indexerTasks []string) (*IndexerProces // // FEVM // - case tasktype.FEVMActorCount: + case tasktype.FEVMActorStats: out.TipsetProcessors[t] = fevmactortask.NewTask(api) case BuiltinTaskName: diff --git a/chain/indexer/tasktype/table_tasks.go b/chain/indexer/tasktype/table_tasks.go index 2d0493d2e..13e1ca4e3 100644 --- a/chain/indexer/tasktype/table_tasks.go +++ b/chain/indexer/tasktype/table_tasks.go @@ -44,8 +44,7 @@ const ( VerifiedRegistryVerifier = "verified_registry_verifier" VerifiedRegistryVerifiedClient = "verified_registry_verified_client" VerifiedRegistryClaim = "verified_registry_claim" - FEVMActorBalance = "fevm_actor_balance" - FEVMActorCount = "fevm_actor_count" + FEVMActorStats = "fevm_actor_stats" ) var AllTableTasks = []string{ @@ -91,8 +90,7 @@ var AllTableTasks = []string{ VerifiedRegistryVerifier, VerifiedRegistryVerifiedClient, VerifiedRegistryClaim, - FEVMActorBalance, - FEVMActorCount, + FEVMActorStats, } var TableLookup = map[string]struct{}{ @@ -138,8 +136,7 @@ var TableLookup = map[string]struct{}{ VerifiedRegistryVerifier: {}, VerifiedRegistryVerifiedClient: {}, VerifiedRegistryClaim: {}, - FEVMActorBalance: {}, - FEVMActorCount: {}, + FEVMActorStats: {}, } var TableComment = map[string]string{ @@ -185,8 +182,7 @@ var TableComment = map[string]string{ VerifiedRegistryVerifier: ``, VerifiedRegistryVerifiedClient: ``, VerifiedRegistryClaim: ``, - FEVMActorBalance: ``, - FEVMActorCount: ``, + FEVMActorStats: ``, } var TableFieldComments = map[string]map[string]string{ @@ -289,6 +285,5 @@ var TableFieldComments = map[string]map[string]string{ VerifiedRegistryVerifier: {}, VerifiedRegistryVerifiedClient: {}, VerifiedRegistryClaim: {}, - FEVMActorBalance: {}, - FEVMActorCount: {}, + FEVMActorStats: {}, } diff --git a/model/fevm/actorcount.go b/model/fevm/actorcount.go deleted file mode 100644 index 7ff3a54a0..000000000 --- a/model/fevm/actorcount.go +++ /dev/null @@ -1,46 +0,0 @@ -package fevm - -import ( - "context" - - "go.opencensus.io/tag" - - "github.com/filecoin-project/lily/metrics" - "github.com/filecoin-project/lily/model" -) - -type FEVMActorCount struct { - tableName struct{} `pg:"fevm_actor_count"` // nolint: structcheck - - // Height message was executed at. - Height int64 `pg:",pk,notnull,use_zero"` - // Balance of EVM Actor in attoFIL. - EVMBalance string `pg:",notnull"` - // Balance of Eth Account Actor in attoFIL. - EthAccountBalance string `pg:",notnull"` - // Balance of Placeholder Actor in attoFIL. - PlaceholderBalance string `pg:",notnull"` -} - -func (f *FEVMActorCount) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error { - ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "fevm_actor_count")) - stop := metrics.Timer(ctx, metrics.PersistDuration) - defer stop() - - metrics.RecordCount(ctx, metrics.PersistModel, 1) - return s.PersistModel(ctx, f) -} - -type FEVMActorCountList []*FEVMActorCount - -func (f FEVMActorCountList) 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_actor_count")) - stop := metrics.Timer(ctx, metrics.PersistDuration) - defer stop() - - metrics.RecordCount(ctx, metrics.PersistModel, len(f)) - return s.PersistModel(ctx, f) -} diff --git a/model/fevm/fevmactorstats.go b/model/fevm/fevmactorstats.go new file mode 100644 index 000000000..24e509ed8 --- /dev/null +++ b/model/fevm/fevmactorstats.go @@ -0,0 +1,56 @@ +package fevm + +import ( + "context" + + "go.opencensus.io/tag" + + "github.com/filecoin-project/lily/metrics" + "github.com/filecoin-project/lily/model" +) + +type FEVMActorStats struct { + tableName struct{} `pg:"fevm_actor_stats"` // nolint: structcheck + + // Height message was executed at. + Height int64 `pg:",pk,notnull,use_zero"` + + // Balance of EVM actor in attoFIL. + ContractBalance string `pg:",notnull"` + // Balance of Eth account actor in attoFIL. + EthAccountBalance string `pg:",notnull"` + // Balance of Placeholder Actor in attoFIL. + PlaceholderBalance string `pg:",notnull"` + + // number of contracts + ContractCount uint64 `pg:",use_zero"` + // number of unique contracts + UniqueContractCount uint64 `pg:",use_zero"` + // number of Eth account actors + EthAccountCount uint64 `pg:",use_zero"` + // number of placeholder actors + PlaceholderCount uint64 `pg:",use_zero"` +} + +func (f *FEVMActorStats) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error { + ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "fevm_actor_stats")) + stop := metrics.Timer(ctx, metrics.PersistDuration) + defer stop() + + metrics.RecordCount(ctx, metrics.PersistModel, 1) + return s.PersistModel(ctx, f) +} + +type FEVMActorStatsList []*FEVMActorStats + +func (f FEVMActorStatsList) 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_actor_stats")) + stop := metrics.Timer(ctx, metrics.PersistDuration) + defer stop() + + metrics.RecordCount(ctx, metrics.PersistModel, len(f)) + return s.PersistModel(ctx, f) +} diff --git a/schemas/v1/19_fevm_actor_stats.go b/schemas/v1/19_fevm_actor_stats.go new file mode 100644 index 000000000..8bab3732d --- /dev/null +++ b/schemas/v1/19_fevm_actor_stats.go @@ -0,0 +1,20 @@ +package v1 + +func init() { + patches.Register( + 19, + ` + CREATE TABLE IF NOT EXISTS {{ .SchemaName | default "public"}}.fevm_actor_stats ( + height BIGINT NOT NULL, + contract_balance TEXT NOT NULL, + eth_account_balance TEXT NOT NULL, + placeholder_balance TEXT NOT NULL, + contract_count BIGINT NOT NULL, + unique_contract_count BIGINT NOT NULL, + eth_account_count BIGINT NOT NULL, + placeholder_count BIGINT NOT NULL, + PRIMARY KEY(height) + ); +`, + ) +} diff --git a/storage/sql.go b/storage/sql.go index 64c10b42d..e2b3adc60 100644 --- a/storage/sql.go +++ b/storage/sql.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "github.com/filecoin-project/lily/model/fevm" "reflect" "sort" "strings" @@ -91,6 +92,8 @@ var Models = []interface{}{ (*verifreg.VerifiedRegistryVerifier)(nil), (*verifreg.VerifiedRegistryVerifiedClient)(nil), (*verifreg.VerifiedRegistryClaim)(nil), + + (*fevm.FEVMActorStatsList)(nil), } var log = logging.Logger("lily/storage") diff --git a/tasks/fevm/actorbalance/task.go b/tasks/fevm/actorbalance/task.go deleted file mode 100644 index 39e7fa8a6..000000000 --- a/tasks/fevm/actorbalance/task.go +++ /dev/null @@ -1 +0,0 @@ -package actorbalance diff --git a/tasks/fevm/actorcount/task.go b/tasks/fevmactorstats/task.go similarity index 68% rename from tasks/fevm/actorcount/task.go rename to tasks/fevmactorstats/task.go index bdde372af..ecc16f0a2 100644 --- a/tasks/fevm/actorcount/task.go +++ b/tasks/fevmactorstats/task.go @@ -1,7 +1,8 @@ -package actorcount +package fevmactorstats import ( "context" + "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-address" "github.com/filecoin-project/lily/model" @@ -17,7 +18,7 @@ import ( "go.opentelemetry.io/otel/attribute" ) -var log = logging.Logger("lily/tasks/fevmactor") +var log = logging.Logger("lily/tasks/fevmactorstats") type Task struct { node tasks.DataSource @@ -50,19 +51,20 @@ func (p *Task) ProcessTipSet(ctx context.Context, ts *types.TipSet) (model.Persi log.Infow("iterating over all actors") count := 0 - EvmCount := 0 - EthAccountCount := 0 - PlaceholderCount := 0 + evmBalance := abi.NewTokenAmount(0) + ethAccountBalance := abi.NewTokenAmount(0) + placeholderBalance := abi.NewTokenAmount(0) + evmCount := 0 + ethAccountCount := 0 + placeholderCount := 0 bytecodeCIDs := []cid.Cid{} err = st.ForEach(func(addr address.Address, act *types.Actor) error { - if count%200000 == 0 { - log.Infow("processed: ", "count", count) - } count++ if builtin.IsEvmActor(act.Code) { - EvmCount++ + evmBalance = types.BigAdd(evmBalance, act.Balance) + evmCount++ e, err := evm2.Load(p.node.Store(), act) if err != nil { log.Errorw("fail to load evm actorcount: ", "error", err) @@ -73,21 +75,28 @@ func (p *Task) ProcessTipSet(ctx context.Context, ts *types.TipSet) (model.Persi } if builtin.IsEthAccountActor(act.Code) { - EthAccountCount++ + ethAccountBalance = types.BigAdd(ethAccountBalance, act.Balance) + ethAccountCount++ } if builtin.IsPlaceholderActor(act.Code) { - PlaceholderCount++ + placeholderBalance = types.BigAdd(placeholderBalance, act.Balance) + placeholderCount++ } return nil }) - uniqueBytecodeCIDs := unique(bytecodeCIDs) - log.Infow("# of EVM contracts: ", "count", EvmCount) - log.Infow("# of unqiue EVM contracts: ", "count", len(uniqueBytecodeCIDs)) - log.Infow("b# of Eth accounts: ", "count", EthAccountCount) - log.Infow("# of placeholder: ", "count", PlaceholderCount) + uniqueBytecode := unique(bytecodeCIDs) + + log.Info("total actor count: ", count) + log.Info("EVM count: ", evmCount) + log.Info("unique EVM count: ", len(uniqueBytecode)) + log.Info("Eth accounts count: ", ethAccountCount) + log.Info("placeholder count: ", placeholderCount) + log.Info("EVM balance: ", evmBalance) + log.Info("Eth balance: ", ethAccountBalance) + log.Info("placeholder balance: ", placeholderBalance) return nil, report, nil } From 92a0e68f723fed0769c66356bbd544d703d276a4 Mon Sep 17 00:00:00 2001 From: birdy Date: Thu, 30 Mar 2023 02:28:23 -0700 Subject: [PATCH 4/8] fix lint --- tasks/fevmactorstats/task.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tasks/fevmactorstats/task.go b/tasks/fevmactorstats/task.go index ecc16f0a2..78ba94769 100644 --- a/tasks/fevmactorstats/task.go +++ b/tasks/fevmactorstats/task.go @@ -59,18 +59,22 @@ func (p *Task) ProcessTipSet(ctx context.Context, ts *types.TipSet) (model.Persi placeholderCount := 0 bytecodeCIDs := []cid.Cid{} - err = st.ForEach(func(addr address.Address, act *types.Actor) error { + _ = st.ForEach(func(addr address.Address, act *types.Actor) error { count++ if builtin.IsEvmActor(act.Code) { evmBalance = types.BigAdd(evmBalance, act.Balance) evmCount++ - e, err := evm2.Load(p.node.Store(), act) + es, err := evm2.Load(p.node.Store(), act) if err != nil { log.Errorw("fail to load evm actorcount: ", "error", err) - return nil + return err + } + bcid, err := es.GetBytecodeCID() + if err != nil { + log.Errorw("fail to get evm bytecode: ", "error", err) + return err } - bcid, err := e.GetBytecodeCID() bytecodeCIDs = append(bytecodeCIDs, bcid) } From b6d1c3b1a111e0573fa966ee7deed606b0f828ae Mon Sep 17 00:00:00 2001 From: birdy Date: Thu, 30 Mar 2023 10:54:32 -0700 Subject: [PATCH 5/8] persist --- tasks/fevmactorstats/task.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tasks/fevmactorstats/task.go b/tasks/fevmactorstats/task.go index 78ba94769..063befb83 100644 --- a/tasks/fevmactorstats/task.go +++ b/tasks/fevmactorstats/task.go @@ -3,6 +3,7 @@ package fevmactorstats import ( "context" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/model/fevm" "github.com/filecoin-project/go-address" "github.com/filecoin-project/lily/model" @@ -36,7 +37,7 @@ func (p *Task) ProcessTipSet(ctx context.Context, ts *types.TipSet) (model.Persi span.SetAttributes( attribute.String("tipset", ts.Key().String()), attribute.Int64("height", int64(ts.Height())), - attribute.String("processor", "chaineconomics"), + attribute.String("processor", "fevmactorstats"), ) } report := &visormodel.ProcessingReport{ @@ -102,7 +103,16 @@ func (p *Task) ProcessTipSet(ctx context.Context, ts *types.TipSet) (model.Persi log.Info("Eth balance: ", ethAccountBalance) log.Info("placeholder balance: ", placeholderBalance) - return nil, report, nil + return &fevm.FEVMActorStats{ + Height: int64(ts.Height()), + ContractBalance: evmBalance.String(), + EthAccountBalance: ethAccountBalance.String(), + PlaceholderBalance: placeholderBalance.String(), + ContractCount: uint64(evmCount), + UniqueContractCount: uint64(len(uniqueBytecode)), + EthAccountCount: uint64(ethAccountCount), + PlaceholderCount: uint64(placeholderCount), + }, report, nil } func unique(intSlice []cid.Cid) []cid.Cid { keys := make(map[cid.Cid]bool) From d84c9e2e0b0057f20ee4326060f34427e65b1177 Mon Sep 17 00:00:00 2001 From: birdy Date: Thu, 30 Mar 2023 11:14:27 -0700 Subject: [PATCH 6/8] fix test --- chain/indexer/integrated/processor/state_internal_test.go | 2 +- chain/indexer/integrated/processor/state_test.go | 2 +- chain/indexer/tasktype/tasks.go | 4 ++++ chain/indexer/tasktype/tasks_test.go | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/chain/indexer/integrated/processor/state_internal_test.go b/chain/indexer/integrated/processor/state_internal_test.go index 432f98617..a37d00830 100644 --- a/chain/indexer/integrated/processor/state_internal_test.go +++ b/chain/indexer/integrated/processor/state_internal_test.go @@ -53,7 +53,7 @@ func TestNewProcessor(t *testing.T) { require.NoError(t, err) require.Equal(t, t.Name(), proc.name) require.Len(t, proc.actorProcessors, 24) - require.Len(t, proc.tipsetProcessors, 9) + require.Len(t, proc.tipsetProcessors, 10) require.Len(t, proc.tipsetsProcessors, 9) require.Len(t, proc.builtinProcessors, 1) diff --git a/chain/indexer/integrated/processor/state_test.go b/chain/indexer/integrated/processor/state_test.go index 01494d896..819670982 100644 --- a/chain/indexer/integrated/processor/state_test.go +++ b/chain/indexer/integrated/processor/state_test.go @@ -402,7 +402,7 @@ func TestMakeProcessorsAllTasks(t *testing.T) { proc, err := processor.MakeProcessors(nil, append(tasktype.AllTableTasks, processor.BuiltinTaskName)) require.NoError(t, err) require.Len(t, proc.ActorProcessors, 24) - require.Len(t, proc.TipsetProcessors, 9) + require.Len(t, proc.TipsetProcessors, 10) require.Len(t, proc.TipsetsProcessors, 9) require.Len(t, proc.ReportProcessors, 1) } diff --git a/chain/indexer/tasktype/tasks.go b/chain/indexer/tasktype/tasks.go index 0d6fd23a0..6bed854cb 100644 --- a/chain/indexer/tasktype/tasks.go +++ b/chain/indexer/tasktype/tasks.go @@ -17,6 +17,7 @@ const ( MultisigApprovalsTask = "msapprovals" // task that extracts multisig actor approvals ImplicitMessageTask = "implicitmessage" // task that extract implicitly executed messages: cron tick and block reward. ChainConsensusTask = "consensus" + FEVMTask = "fevm" ) var TaskLookup = map[string][]string{ @@ -90,6 +91,9 @@ var TaskLookup = map[string][]string{ ChainConsensusTask: { ChainConsensus, }, + FEVMTask: { + FEVMActorStats, + }, } func MakeTaskNames(tasks []string) ([]string, error) { diff --git a/chain/indexer/tasktype/tasks_test.go b/chain/indexer/tasktype/tasks_test.go index 851227632..ecc0de66c 100644 --- a/chain/indexer/tasktype/tasks_test.go +++ b/chain/indexer/tasktype/tasks_test.go @@ -101,7 +101,7 @@ func TestMakeAllTaskAliasNames(t *testing.T) { } func TestMakeAllTaskNames(t *testing.T) { - const TotalTableTasks = 42 + const TotalTableTasks = 43 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 From 8b432c94d7678762a0a5559eff3a8c498b726aaf Mon Sep 17 00:00:00 2001 From: birdy Date: Thu, 30 Mar 2023 13:52:46 -0700 Subject: [PATCH 7/8] fix test & lint --- chain/indexer/integrated/processor/state.go | 6 ++++-- storage/sql.go | 4 ++-- tasks/fevmactorstats/task.go | 9 ++++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/chain/indexer/integrated/processor/state.go b/chain/indexer/integrated/processor/state.go index 05bc54e81..0b133221a 100644 --- a/chain/indexer/integrated/processor/state.go +++ b/chain/indexer/integrated/processor/state.go @@ -3,7 +3,6 @@ package processor import ( "context" "fmt" - fevmactortask "github.com/filecoin-project/lily/tasks/fevmactorstats" "sync" "time" @@ -59,6 +58,9 @@ import ( receipttask "github.com/filecoin-project/lily/tasks/messages/receipt" msapprovaltask "github.com/filecoin-project/lily/tasks/msapprovals" + // fevm task + fevmactorstatstask "github.com/filecoin-project/lily/tasks/fevmactorstats" + "github.com/filecoin-project/lily/chain/indexer/tasktype" "github.com/filecoin-project/lily/metrics" "github.com/filecoin-project/lily/model" @@ -633,7 +635,7 @@ func MakeProcessors(api tasks.DataSource, indexerTasks []string) (*IndexerProces // FEVM // case tasktype.FEVMActorStats: - out.TipsetProcessors[t] = fevmactortask.NewTask(api) + out.TipsetProcessors[t] = fevmactorstatstask.NewTask(api) case BuiltinTaskName: out.ReportProcessors[t] = indexertask.NewTask(api) diff --git a/storage/sql.go b/storage/sql.go index e2b3adc60..73b7b0dfa 100644 --- a/storage/sql.go +++ b/storage/sql.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "github.com/filecoin-project/lily/model/fevm" "reflect" "sort" "strings" @@ -28,6 +27,7 @@ import ( "github.com/filecoin-project/lily/model/blocks" "github.com/filecoin-project/lily/model/chain" "github.com/filecoin-project/lily/model/derived" + "github.com/filecoin-project/lily/model/fevm" "github.com/filecoin-project/lily/model/messages" "github.com/filecoin-project/lily/model/msapprovals" "github.com/filecoin-project/lily/model/visor" @@ -93,7 +93,7 @@ var Models = []interface{}{ (*verifreg.VerifiedRegistryVerifiedClient)(nil), (*verifreg.VerifiedRegistryClaim)(nil), - (*fevm.FEVMActorStatsList)(nil), + (*fevm.FEVMActorStats)(nil), } var log = logging.Logger("lily/storage") diff --git a/tasks/fevmactorstats/task.go b/tasks/fevmactorstats/task.go index 063befb83..23a71888f 100644 --- a/tasks/fevmactorstats/task.go +++ b/tasks/fevmactorstats/task.go @@ -2,13 +2,12 @@ package fevmactorstats import ( "context" + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/model/fevm" "github.com/filecoin-project/go-address" - "github.com/filecoin-project/lily/model" - visormodel "github.com/filecoin-project/lily/model/visor" - "github.com/filecoin-project/lily/tasks" "github.com/filecoin-project/lotus/chain/actors/builtin" evm2 "github.com/filecoin-project/lotus/chain/actors/builtin/evm" "github.com/filecoin-project/lotus/chain/state" @@ -17,6 +16,10 @@ import ( logging "github.com/ipfs/go-log/v2" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" + + "github.com/filecoin-project/lily/model" + visormodel "github.com/filecoin-project/lily/model/visor" + "github.com/filecoin-project/lily/tasks" ) var log = logging.Logger("lily/tasks/fevmactorstats") From ff8cc2fa819750348305312229dbc253455c60f5 Mon Sep 17 00:00:00 2001 From: birdy Date: Thu, 30 Mar 2023 14:09:45 -0700 Subject: [PATCH 8/8] remove logging --- tasks/fevmactorstats/task.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tasks/fevmactorstats/task.go b/tasks/fevmactorstats/task.go index 23a71888f..08abe4ca4 100644 --- a/tasks/fevmactorstats/task.go +++ b/tasks/fevmactorstats/task.go @@ -97,15 +97,6 @@ func (p *Task) ProcessTipSet(ctx context.Context, ts *types.TipSet) (model.Persi uniqueBytecode := unique(bytecodeCIDs) - log.Info("total actor count: ", count) - log.Info("EVM count: ", evmCount) - log.Info("unique EVM count: ", len(uniqueBytecode)) - log.Info("Eth accounts count: ", ethAccountCount) - log.Info("placeholder count: ", placeholderCount) - log.Info("EVM balance: ", evmBalance) - log.Info("Eth balance: ", ethAccountBalance) - log.Info("placeholder balance: ", placeholderBalance) - return &fevm.FEVMActorStats{ Height: int64(ts.Height()), ContractBalance: evmBalance.String(),