Skip to content

Commit

Permalink
chore: batch insert miner_sector_deal (#1221)
Browse files Browse the repository at this point in the history
  • Loading branch information
birdychang authored Jun 5, 2023
1 parent 341cd36 commit fd2168e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
11 changes: 8 additions & 3 deletions chain/indexer/integrated/processor/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,14 @@ func MakeProcessors(api tasks.DataSource, indexerTasks []string) (*IndexerProces
minertask.PreCommitInfoExtractorV9{},
)
case tasktype.MinerSectorDeal:
out.ActorProcessors[t] = actorstate.NewTask(api, actorstate.NewTypedActorExtractorMap(
mineractors.AllCodes(), minertask.SectorDealsExtractor{},
))
out.ActorProcessors[t] = actorstate.NewTaskWithTransformer(
api,
actorstate.NewTypedActorExtractorMap(
mineractors.AllCodes(),
minertask.SectorDealsExtractor{},
),
minertask.SectorDealsExtractor{},
)
case tasktype.MinerSectorEvent:
out.ActorProcessors[t] = actorstate.NewTaskWithTransformer(
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 @@ -81,7 +81,7 @@ func TestNewProcessor(t *testing.T) {
require.Equal(t, actorstate.NewTask(nil, actorstate.NewTypedActorExtractorMap(miner.AllCodes(), minertask.FeeDebtExtractor{})), proc.actorProcessors[tasktype.MinerFeeDebt])
require.Equal(t, actorstate.NewTask(nil, actorstate.NewTypedActorExtractorMap(miner.AllCodes(), minertask.InfoExtractor{})), proc.actorProcessors[tasktype.MinerInfo])
require.Equal(t, actorstate.NewTaskWithTransformer(nil, actorstate.NewTypedActorExtractorMap(miner.AllCodes(), minertask.LockedFundsExtractor{}), minertask.LockedFundsExtractor{}), proc.actorProcessors[tasktype.MinerLockedFund])
require.Equal(t, actorstate.NewTask(nil, actorstate.NewTypedActorExtractorMap(miner.AllCodes(), minertask.SectorDealsExtractor{})), proc.actorProcessors[tasktype.MinerSectorDeal])
require.Equal(t, actorstate.NewTaskWithTransformer(nil, actorstate.NewTypedActorExtractorMap(miner.AllCodes(), minertask.SectorDealsExtractor{}), minertask.SectorDealsExtractor{}), proc.actorProcessors[tasktype.MinerSectorDeal])
require.Equal(t, actorstate.NewTaskWithTransformer(nil, actorstate.NewTypedActorExtractorMap(miner.AllCodes(), minertask.SectorEventsExtractor{}), minertask.SectorEventsExtractor{}), proc.actorProcessors[tasktype.MinerSectorEvent])
require.Equal(t, actorstate.NewTask(nil, actorstate.NewTypedActorExtractorMap(miner.AllCodes(), minertask.PoStExtractor{})), proc.actorProcessors[tasktype.MinerSectorPost])
require.Equal(t, actorstate.NewTask(nil, actorstate.NewCustomTypedActorExtractorMap(
Expand Down
9 changes: 5 additions & 4 deletions chain/indexer/integrated/processor/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ func TestMakeProcessorsActors(t *testing.T) {
taskName: tasktype.MinerInfo,
extractor: actorstate.NewTypedActorExtractorMap(miner.AllCodes(), minertask.InfoExtractor{}),
},
{
taskName: tasktype.MinerSectorDeal,
extractor: actorstate.NewTypedActorExtractorMap(miner.AllCodes(), minertask.SectorDealsExtractor{}),
},
{
taskName: tasktype.MinerSectorPost,
extractor: actorstate.NewTypedActorExtractorMap(miner.AllCodes(), minertask.PoStExtractor{}),
Expand Down Expand Up @@ -139,6 +135,11 @@ func TestMakeProcessorsActors(t *testing.T) {
),
transformer: minertask.PreCommitInfoExtractorV9{},
},
{
taskName: tasktype.MinerSectorDeal,
extractor: actorstate.NewTypedActorExtractorMap(miner.AllCodes(), minertask.SectorDealsExtractor{}),
transformer: minertask.SectorDealsExtractor{},
},
}
for _, tc := range testCases2 {
t.Run(tc.taskName, func(t *testing.T) {
Expand Down
14 changes: 14 additions & 0 deletions tasks/actorstate/miner/sector_deals.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,17 @@ func ExtractSectorDealsModel(ctx context.Context, ec extraction.State) (minermod
}
return result, nil
}

func (SectorDealsExtractor) Transform(ctx context.Context, data model.PersistableList) (model.PersistableList, error) {
persistableList := make(minermodel.MinerSectorDealList, 0, len(data))
for _, d := range data {
ml, ok := d.(minermodel.MinerSectorDealList)
if !ok {
return nil, fmt.Errorf("expected MinerSectorDealList type but got: %T", d)
}
for _, m := range ml {
persistableList = append(persistableList, m)
}
}
return model.PersistableList{persistableList}, nil
}

0 comments on commit fd2168e

Please sign in to comment.