Skip to content

Commit

Permalink
feat: refine the provider sectors related func (#1294)
Browse files Browse the repository at this point in the history
* Introduce the new method GetProviderSectorsByDealID
  • Loading branch information
Terryhung authored Apr 26, 2024
1 parent 44b31c2 commit 048c14e
Show file tree
Hide file tree
Showing 17 changed files with 193 additions and 30 deletions.
1 change: 1 addition & 0 deletions chain/actors/builtin/market/actor.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type State interface {
DealStatesAmtBitwidth() int

GetProviderSectors() (map[abi.SectorID][]abi.DealID, error)
GetProviderSectorsByDealID(map[abi.DealID]bool) (map[abi.DealID]abi.SectorID, error)
}

type BalanceTable interface {
Expand Down
1 change: 1 addition & 0 deletions chain/actors/builtin/market/market.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions chain/actors/builtin/market/state.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -346,4 +346,50 @@ func (s *state{{.v}}) GetProviderSectors() (map[abi.SectorID][]abi.DealID, error
})
return providerSectors, err
{{end}}
}

func (s *state{{.v}}) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool) (map[abi.DealID]abi.SectorID, error) {
{{if (le .v 12)}}
return nil, nil
{{else}}
sectorDeals, err := adt{{.v}}.AsMap(s.store, s.State.ProviderSectors, market{{.v}}.ProviderSectorsHamtBitwidth)
if err != nil {
return nil, err
}
var sectorMapRoot cbg.CborCid
dealIDSectorMap := make(map[abi.DealID]abi.SectorID)
err = sectorDeals.ForEach(&sectorMapRoot, func(providerID string) error {
provider, err := abi.ParseUIntKey(providerID)
if err != nil {
return nil
}

sectorMap, err := adt{{.v}}.AsMap(s.store, cid.Cid(sectorMapRoot), market{{.v}}.ProviderSectorsHamtBitwidth)
if err != nil {
return err
}

var dealIDs market{{.v}}.SectorDealIDs
err = sectorMap.ForEach(&dealIDs, func(sectorID string) error {
sectorNumber, err := abi.ParseUIntKey(sectorID)
if err != nil {
return err
}

dealIDsCopy := make([]abi.DealID, len(dealIDs))
copy(dealIDsCopy, dealIDs)

for _, dealID := range dealIDsCopy {
_, found := dealIDMap[dealID]
if found {
dealIDSectorMap[dealID] = abi.SectorID{Miner: abi.ActorID(provider), Number: abi.SectorNumber(sectorNumber)}
}
}

return nil
})
return err
})
return dealIDSectorMap, err
{{end}}
}
6 changes: 6 additions & 0 deletions chain/actors/builtin/market/v0.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions chain/actors/builtin/market/v10.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions chain/actors/builtin/market/v11.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions chain/actors/builtin/market/v12.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions chain/actors/builtin/market/v13.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions chain/actors/builtin/market/v2.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions chain/actors/builtin/market/v3.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions chain/actors/builtin/market/v4.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions chain/actors/builtin/market/v5.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions chain/actors/builtin/market/v6.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions chain/actors/builtin/market/v7.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions chain/actors/builtin/market/v8.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions chain/actors/builtin/market/v9.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 29 additions & 30 deletions tasks/actorstate/market/sector_deals_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,45 +64,44 @@ func (SectorDealStateExtractor) Extract(ctx context.Context, a actorstate.ActorI
return nil, nil
}

result, err := ec.CurrState.GetProviderSectors()
if err != nil {
log.Errorf("Get the errors during getting provider sectors: %v", err)
return nil, nil
}
dealSectorMap := make(map[abi.DealID]abi.SectorID)
for sectorID, dealIDs := range result {
for _, dealID := range dealIDs {
dealSectorMap[dealID] = sectorID
}
}

changes, err := market.DiffDealStates(ctx, ec.Store, ec.PrevState, ec.CurrState)
if err != nil {
return nil, fmt.Errorf("diffing deal states: %w", err)
}

dealIDs := make(map[abi.DealID]bool, 0)

out := make(miner.MinerSectorDealListV2, 0)
for _, add := range changes.Added {
sector, exists := dealSectorMap[add.ID]
if exists {
out = append(out, &miner.MinerSectorDealV2{
Height: int64(ec.CurrTs.Height()),
DealID: uint64(add.ID),
SectorID: uint64(dealSectorMap[add.ID].Number),
MinerID: sector.Miner.String(),
})
}
out = append(out, &miner.MinerSectorDealV2{
Height: int64(ec.CurrTs.Height()),
DealID: uint64(add.ID),
})
dealIDs[add.ID] = true
}
for _, mod := range changes.Modified {
sector, exists := dealSectorMap[mod.ID]
if exists {
out = append(out, &miner.MinerSectorDealV2{
Height: int64(ec.CurrTs.Height()),
DealID: uint64(mod.ID),
SectorID: uint64(dealSectorMap[mod.ID].Number),
MinerID: sector.Miner.String(),
})
out = append(out, &miner.MinerSectorDealV2{
Height: int64(ec.CurrTs.Height()),
DealID: uint64(mod.ID),
})
dealIDs[mod.ID] = true
}

dealIDSectorMap, err := ec.CurrState.GetProviderSectorsByDealID(dealIDs)
if err != nil {
log.Errorf("Get the errors during getting provider sectors: %v", err)
return nil, nil
}

completeSectorDeal := make(miner.MinerSectorDealListV2, 0)
for _, sectorDeal := range out {
sectorID, found := dealIDSectorMap[abi.DealID(sectorDeal.DealID)]
if found {
sectorDeal.MinerID = sectorID.Miner.String()
sectorDeal.SectorID = uint64(sectorID.Number)
completeSectorDeal = append(completeSectorDeal, sectorDeal)
}
}
return out, nil

return completeSectorDeal, nil
}

0 comments on commit 048c14e

Please sign in to comment.