From 73ae2563c4f167493ce715fc27ec07effbfe10e9 Mon Sep 17 00:00:00 2001 From: "terry.hung" Date: Thu, 16 May 2024 13:54:24 +0800 Subject: [PATCH 1/4] Integrate sectorNumber to dealState --- chain/actors/builtin/market/actor.go.template | 1 + chain/actors/builtin/market/market.go | 5 +++++ chain/actors/builtin/market/state.go.template | 8 ++++++++ chain/actors/builtin/market/v0.go | 6 ++++++ chain/actors/builtin/market/v10.go | 6 ++++++ chain/actors/builtin/market/v11.go | 6 ++++++ chain/actors/builtin/market/v12.go | 6 ++++++ chain/actors/builtin/market/v13.go | 6 ++++++ chain/actors/builtin/market/v2.go | 6 ++++++ chain/actors/builtin/market/v3.go | 6 ++++++ chain/actors/builtin/market/v4.go | 6 ++++++ chain/actors/builtin/market/v5.go | 6 ++++++ chain/actors/builtin/market/v6.go | 6 ++++++ chain/actors/builtin/market/v7.go | 6 ++++++ chain/actors/builtin/market/v8.go | 6 ++++++ chain/actors/builtin/market/v9.go | 6 ++++++ 16 files changed, 92 insertions(+) diff --git a/chain/actors/builtin/market/actor.go.template b/chain/actors/builtin/market/actor.go.template index bd507e16..1b20493d 100644 --- a/chain/actors/builtin/market/actor.go.template +++ b/chain/actors/builtin/market/actor.go.template @@ -106,6 +106,7 @@ type DealProposal = markettypes.DealProposal type DealLabel = markettypes.DealLabel type DealState interface { + SectorNumber() abi.SectorNumber SectorStartEpoch() abi.ChainEpoch // -1 if not yet included in proven sector LastUpdatedEpoch() abi.ChainEpoch // -1 if deal state never updated SlashEpoch() abi.ChainEpoch // -1 if deal never slashed diff --git a/chain/actors/builtin/market/market.go b/chain/actors/builtin/market/market.go index ee5ef667..4d0f8b91 100644 --- a/chain/actors/builtin/market/market.go +++ b/chain/actors/builtin/market/market.go @@ -135,6 +135,7 @@ type DealProposal = markettypes.DealProposal type DealLabel = markettypes.DealLabel type DealState interface { + SectorNumber() abi.SectorNumber SectorStartEpoch() abi.ChainEpoch // -1 if not yet included in proven sector LastUpdatedEpoch() abi.ChainEpoch // -1 if deal state never updated SlashEpoch() abi.ChainEpoch // -1 if deal never slashed @@ -196,6 +197,10 @@ func (e *emptyDealState) SlashEpoch() abi.ChainEpoch { return -1 } +func (e *emptyDealState) SectorNumber() abi.SectorNumber { + return 0 +} + func (e *emptyDealState) Equals(other DealState) bool { if e.SectorStartEpoch() != other.SectorStartEpoch() { return false diff --git a/chain/actors/builtin/market/state.go.template b/chain/actors/builtin/market/state.go.template index 31d483f1..0a935b00 100644 --- a/chain/actors/builtin/market/state.go.template +++ b/chain/actors/builtin/market/state.go.template @@ -156,6 +156,14 @@ func (d dealStateV{{.v}}) SectorStartEpoch() abi.ChainEpoch { return d.ds{{.v}}.SectorStartEpoch } +func (d dealStateV{{.v}}) SectorNumber() abi.SectorNumber { + {{if ge .v 13}} + return d.ds{{.v}}.SectorNumber + {{else}} + return 0 + {{end}} +} + func (d dealStateV{{.v}}) LastUpdatedEpoch() abi.ChainEpoch { return d.ds{{.v}}.LastUpdatedEpoch } diff --git a/chain/actors/builtin/market/v0.go b/chain/actors/builtin/market/v0.go index f0d7db46..d1a5aec5 100644 --- a/chain/actors/builtin/market/v0.go +++ b/chain/actors/builtin/market/v0.go @@ -139,6 +139,12 @@ func (d dealStateV0) SectorStartEpoch() abi.ChainEpoch { return d.ds0.SectorStartEpoch } +func (d dealStateV0) SectorNumber() abi.SectorNumber { + + return 0 + +} + func (d dealStateV0) LastUpdatedEpoch() abi.ChainEpoch { return d.ds0.LastUpdatedEpoch } diff --git a/chain/actors/builtin/market/v10.go b/chain/actors/builtin/market/v10.go index 8c0ccf1c..606b5dab 100644 --- a/chain/actors/builtin/market/v10.go +++ b/chain/actors/builtin/market/v10.go @@ -135,6 +135,12 @@ func (d dealStateV10) SectorStartEpoch() abi.ChainEpoch { return d.ds10.SectorStartEpoch } +func (d dealStateV10) SectorNumber() abi.SectorNumber { + + return 0 + +} + func (d dealStateV10) LastUpdatedEpoch() abi.ChainEpoch { return d.ds10.LastUpdatedEpoch } diff --git a/chain/actors/builtin/market/v11.go b/chain/actors/builtin/market/v11.go index 102acb30..3d780652 100644 --- a/chain/actors/builtin/market/v11.go +++ b/chain/actors/builtin/market/v11.go @@ -135,6 +135,12 @@ func (d dealStateV11) SectorStartEpoch() abi.ChainEpoch { return d.ds11.SectorStartEpoch } +func (d dealStateV11) SectorNumber() abi.SectorNumber { + + return 0 + +} + func (d dealStateV11) LastUpdatedEpoch() abi.ChainEpoch { return d.ds11.LastUpdatedEpoch } diff --git a/chain/actors/builtin/market/v12.go b/chain/actors/builtin/market/v12.go index e03e20f6..bc42d561 100644 --- a/chain/actors/builtin/market/v12.go +++ b/chain/actors/builtin/market/v12.go @@ -135,6 +135,12 @@ func (d dealStateV12) SectorStartEpoch() abi.ChainEpoch { return d.ds12.SectorStartEpoch } +func (d dealStateV12) SectorNumber() abi.SectorNumber { + + return 0 + +} + func (d dealStateV12) LastUpdatedEpoch() abi.ChainEpoch { return d.ds12.LastUpdatedEpoch } diff --git a/chain/actors/builtin/market/v13.go b/chain/actors/builtin/market/v13.go index 6e19d4e0..d7065db7 100644 --- a/chain/actors/builtin/market/v13.go +++ b/chain/actors/builtin/market/v13.go @@ -135,6 +135,12 @@ func (d dealStateV13) SectorStartEpoch() abi.ChainEpoch { return d.ds13.SectorStartEpoch } +func (d dealStateV13) SectorNumber() abi.SectorNumber { + + return d.ds13.SectorNumber + +} + func (d dealStateV13) LastUpdatedEpoch() abi.ChainEpoch { return d.ds13.LastUpdatedEpoch } diff --git a/chain/actors/builtin/market/v2.go b/chain/actors/builtin/market/v2.go index a1cf9596..457fe9c4 100644 --- a/chain/actors/builtin/market/v2.go +++ b/chain/actors/builtin/market/v2.go @@ -139,6 +139,12 @@ func (d dealStateV2) SectorStartEpoch() abi.ChainEpoch { return d.ds2.SectorStartEpoch } +func (d dealStateV2) SectorNumber() abi.SectorNumber { + + return 0 + +} + func (d dealStateV2) LastUpdatedEpoch() abi.ChainEpoch { return d.ds2.LastUpdatedEpoch } diff --git a/chain/actors/builtin/market/v3.go b/chain/actors/builtin/market/v3.go index 6cfcc5e8..fa9b1b84 100644 --- a/chain/actors/builtin/market/v3.go +++ b/chain/actors/builtin/market/v3.go @@ -134,6 +134,12 @@ func (d dealStateV3) SectorStartEpoch() abi.ChainEpoch { return d.ds3.SectorStartEpoch } +func (d dealStateV3) SectorNumber() abi.SectorNumber { + + return 0 + +} + func (d dealStateV3) LastUpdatedEpoch() abi.ChainEpoch { return d.ds3.LastUpdatedEpoch } diff --git a/chain/actors/builtin/market/v4.go b/chain/actors/builtin/market/v4.go index d74875ac..6b9a94fb 100644 --- a/chain/actors/builtin/market/v4.go +++ b/chain/actors/builtin/market/v4.go @@ -134,6 +134,12 @@ func (d dealStateV4) SectorStartEpoch() abi.ChainEpoch { return d.ds4.SectorStartEpoch } +func (d dealStateV4) SectorNumber() abi.SectorNumber { + + return 0 + +} + func (d dealStateV4) LastUpdatedEpoch() abi.ChainEpoch { return d.ds4.LastUpdatedEpoch } diff --git a/chain/actors/builtin/market/v5.go b/chain/actors/builtin/market/v5.go index c00d49bc..3823e505 100644 --- a/chain/actors/builtin/market/v5.go +++ b/chain/actors/builtin/market/v5.go @@ -134,6 +134,12 @@ func (d dealStateV5) SectorStartEpoch() abi.ChainEpoch { return d.ds5.SectorStartEpoch } +func (d dealStateV5) SectorNumber() abi.SectorNumber { + + return 0 + +} + func (d dealStateV5) LastUpdatedEpoch() abi.ChainEpoch { return d.ds5.LastUpdatedEpoch } diff --git a/chain/actors/builtin/market/v6.go b/chain/actors/builtin/market/v6.go index 78609b8b..20dfc0ea 100644 --- a/chain/actors/builtin/market/v6.go +++ b/chain/actors/builtin/market/v6.go @@ -134,6 +134,12 @@ func (d dealStateV6) SectorStartEpoch() abi.ChainEpoch { return d.ds6.SectorStartEpoch } +func (d dealStateV6) SectorNumber() abi.SectorNumber { + + return 0 + +} + func (d dealStateV6) LastUpdatedEpoch() abi.ChainEpoch { return d.ds6.LastUpdatedEpoch } diff --git a/chain/actors/builtin/market/v7.go b/chain/actors/builtin/market/v7.go index 380073e1..fb0c0861 100644 --- a/chain/actors/builtin/market/v7.go +++ b/chain/actors/builtin/market/v7.go @@ -134,6 +134,12 @@ func (d dealStateV7) SectorStartEpoch() abi.ChainEpoch { return d.ds7.SectorStartEpoch } +func (d dealStateV7) SectorNumber() abi.SectorNumber { + + return 0 + +} + func (d dealStateV7) LastUpdatedEpoch() abi.ChainEpoch { return d.ds7.LastUpdatedEpoch } diff --git a/chain/actors/builtin/market/v8.go b/chain/actors/builtin/market/v8.go index 830d5109..2923e58c 100644 --- a/chain/actors/builtin/market/v8.go +++ b/chain/actors/builtin/market/v8.go @@ -135,6 +135,12 @@ func (d dealStateV8) SectorStartEpoch() abi.ChainEpoch { return d.ds8.SectorStartEpoch } +func (d dealStateV8) SectorNumber() abi.SectorNumber { + + return 0 + +} + func (d dealStateV8) LastUpdatedEpoch() abi.ChainEpoch { return d.ds8.LastUpdatedEpoch } diff --git a/chain/actors/builtin/market/v9.go b/chain/actors/builtin/market/v9.go index a5ee1349..2c30e53b 100644 --- a/chain/actors/builtin/market/v9.go +++ b/chain/actors/builtin/market/v9.go @@ -135,6 +135,12 @@ func (d dealStateV9) SectorStartEpoch() abi.ChainEpoch { return d.ds9.SectorStartEpoch } +func (d dealStateV9) SectorNumber() abi.SectorNumber { + + return 0 + +} + func (d dealStateV9) LastUpdatedEpoch() abi.ChainEpoch { return d.ds9.LastUpdatedEpoch } From 5233f0a2424672bb0b5bc3a2a71c18175e0a70c7 Mon Sep 17 00:00:00 2001 From: "terry.hung" Date: Thu, 16 May 2024 14:06:30 +0800 Subject: [PATCH 2/4] Use the sectorNumber to refine the ProviderSector function --- chain/actors/builtin/market/actor.go.template | 2 +- chain/actors/builtin/market/market.go | 2 +- chain/actors/builtin/market/state.go.template | 6 +++++- chain/actors/builtin/market/v0.go | 2 +- chain/actors/builtin/market/v10.go | 2 +- chain/actors/builtin/market/v11.go | 2 +- chain/actors/builtin/market/v12.go | 2 +- chain/actors/builtin/market/v13.go | 6 +++++- chain/actors/builtin/market/v2.go | 2 +- chain/actors/builtin/market/v3.go | 2 +- chain/actors/builtin/market/v4.go | 2 +- chain/actors/builtin/market/v5.go | 2 +- chain/actors/builtin/market/v6.go | 2 +- chain/actors/builtin/market/v7.go | 2 +- chain/actors/builtin/market/v8.go | 2 +- chain/actors/builtin/market/v9.go | 2 +- lens/util/builtinactor.go | 3 ++- tasks/actorstate/market/sector_deals_v2.go | 15 ++++++++++----- 18 files changed, 36 insertions(+), 22 deletions(-) diff --git a/chain/actors/builtin/market/actor.go.template b/chain/actors/builtin/market/actor.go.template index 1b20493d..7734454b 100644 --- a/chain/actors/builtin/market/actor.go.template +++ b/chain/actors/builtin/market/actor.go.template @@ -77,7 +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) + GetProviderSectorsByDealID(map[abi.DealID]bool, map[abi.SectorNumber]bool) (map[abi.DealID]abi.SectorID, error) } type BalanceTable interface { diff --git a/chain/actors/builtin/market/market.go b/chain/actors/builtin/market/market.go index 4d0f8b91..546d039b 100644 --- a/chain/actors/builtin/market/market.go +++ b/chain/actors/builtin/market/market.go @@ -107,7 +107,7 @@ type State interface { DealStatesAmtBitwidth() int GetProviderSectors() (map[abi.SectorID][]abi.DealID, error) - GetProviderSectorsByDealID(map[abi.DealID]bool) (map[abi.DealID]abi.SectorID, error) + GetProviderSectorsByDealID(map[abi.DealID]bool, map[abi.SectorNumber]bool) (map[abi.DealID]abi.SectorID, error) } type BalanceTable interface { diff --git a/chain/actors/builtin/market/state.go.template b/chain/actors/builtin/market/state.go.template index 0a935b00..f645a943 100644 --- a/chain/actors/builtin/market/state.go.template +++ b/chain/actors/builtin/market/state.go.template @@ -356,7 +356,7 @@ func (s *state{{.v}}) GetProviderSectors() (map[abi.SectorID][]abi.DealID, error {{end}} } -func (s *state{{.v}}) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool) (map[abi.DealID]abi.SectorID, error) { +func (s *state{{.v}}) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool, sectorIDMap map[abi.SectorNumber]bool) (map[abi.DealID]abi.SectorID, error) { {{if (le .v 12)}} return nil, nil {{else}} @@ -384,6 +384,10 @@ func (s *state{{.v}}) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool) return err } + if _, found := sectorIDMap[abi.SectorNumber(sectorNumber)]; !found { + return nil + } + dealIDsCopy := make([]abi.DealID, len(dealIDs)) copy(dealIDsCopy, dealIDs) diff --git a/chain/actors/builtin/market/v0.go b/chain/actors/builtin/market/v0.go index d1a5aec5..c3acb9e3 100644 --- a/chain/actors/builtin/market/v0.go +++ b/chain/actors/builtin/market/v0.go @@ -282,7 +282,7 @@ func (s *state0) GetProviderSectors() (map[abi.SectorID][]abi.DealID, error) { } -func (s *state0) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool) (map[abi.DealID]abi.SectorID, error) { +func (s *state0) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool, sectorIDMap map[abi.SectorNumber]bool) (map[abi.DealID]abi.SectorID, error) { return nil, nil diff --git a/chain/actors/builtin/market/v10.go b/chain/actors/builtin/market/v10.go index 606b5dab..2cd65e0c 100644 --- a/chain/actors/builtin/market/v10.go +++ b/chain/actors/builtin/market/v10.go @@ -294,7 +294,7 @@ func (s *state10) GetProviderSectors() (map[abi.SectorID][]abi.DealID, error) { } -func (s *state10) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool) (map[abi.DealID]abi.SectorID, error) { +func (s *state10) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool, sectorIDMap map[abi.SectorNumber]bool) (map[abi.DealID]abi.SectorID, error) { return nil, nil diff --git a/chain/actors/builtin/market/v11.go b/chain/actors/builtin/market/v11.go index 3d780652..ce984d71 100644 --- a/chain/actors/builtin/market/v11.go +++ b/chain/actors/builtin/market/v11.go @@ -294,7 +294,7 @@ func (s *state11) GetProviderSectors() (map[abi.SectorID][]abi.DealID, error) { } -func (s *state11) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool) (map[abi.DealID]abi.SectorID, error) { +func (s *state11) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool, sectorIDMap map[abi.SectorNumber]bool) (map[abi.DealID]abi.SectorID, error) { return nil, nil diff --git a/chain/actors/builtin/market/v12.go b/chain/actors/builtin/market/v12.go index bc42d561..3f4a24a6 100644 --- a/chain/actors/builtin/market/v12.go +++ b/chain/actors/builtin/market/v12.go @@ -294,7 +294,7 @@ func (s *state12) GetProviderSectors() (map[abi.SectorID][]abi.DealID, error) { } -func (s *state12) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool) (map[abi.DealID]abi.SectorID, error) { +func (s *state12) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool, sectorIDMap map[abi.SectorNumber]bool) (map[abi.DealID]abi.SectorID, error) { return nil, nil diff --git a/chain/actors/builtin/market/v13.go b/chain/actors/builtin/market/v13.go index d7065db7..748a7e33 100644 --- a/chain/actors/builtin/market/v13.go +++ b/chain/actors/builtin/market/v13.go @@ -326,7 +326,7 @@ func (s *state13) GetProviderSectors() (map[abi.SectorID][]abi.DealID, error) { } -func (s *state13) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool) (map[abi.DealID]abi.SectorID, error) { +func (s *state13) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool, sectorIDMap map[abi.SectorNumber]bool) (map[abi.DealID]abi.SectorID, error) { sectorDeals, err := adt13.AsMap(s.store, s.State.ProviderSectors, market13.ProviderSectorsHamtBitwidth) if err != nil { @@ -352,6 +352,10 @@ func (s *state13) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool) (map return err } + if _, found := sectorIDMap[abi.SectorNumber(sectorNumber)]; !found { + return nil + } + dealIDsCopy := make([]abi.DealID, len(dealIDs)) copy(dealIDsCopy, dealIDs) diff --git a/chain/actors/builtin/market/v2.go b/chain/actors/builtin/market/v2.go index 457fe9c4..3a160b7f 100644 --- a/chain/actors/builtin/market/v2.go +++ b/chain/actors/builtin/market/v2.go @@ -282,7 +282,7 @@ func (s *state2) GetProviderSectors() (map[abi.SectorID][]abi.DealID, error) { } -func (s *state2) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool) (map[abi.DealID]abi.SectorID, error) { +func (s *state2) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool, sectorIDMap map[abi.SectorNumber]bool) (map[abi.DealID]abi.SectorID, error) { return nil, nil diff --git a/chain/actors/builtin/market/v3.go b/chain/actors/builtin/market/v3.go index fa9b1b84..bbe10367 100644 --- a/chain/actors/builtin/market/v3.go +++ b/chain/actors/builtin/market/v3.go @@ -277,7 +277,7 @@ func (s *state3) GetProviderSectors() (map[abi.SectorID][]abi.DealID, error) { } -func (s *state3) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool) (map[abi.DealID]abi.SectorID, error) { +func (s *state3) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool, sectorIDMap map[abi.SectorNumber]bool) (map[abi.DealID]abi.SectorID, error) { return nil, nil diff --git a/chain/actors/builtin/market/v4.go b/chain/actors/builtin/market/v4.go index 6b9a94fb..06a63bae 100644 --- a/chain/actors/builtin/market/v4.go +++ b/chain/actors/builtin/market/v4.go @@ -277,7 +277,7 @@ func (s *state4) GetProviderSectors() (map[abi.SectorID][]abi.DealID, error) { } -func (s *state4) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool) (map[abi.DealID]abi.SectorID, error) { +func (s *state4) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool, sectorIDMap map[abi.SectorNumber]bool) (map[abi.DealID]abi.SectorID, error) { return nil, nil diff --git a/chain/actors/builtin/market/v5.go b/chain/actors/builtin/market/v5.go index 3823e505..f7eab4cf 100644 --- a/chain/actors/builtin/market/v5.go +++ b/chain/actors/builtin/market/v5.go @@ -277,7 +277,7 @@ func (s *state5) GetProviderSectors() (map[abi.SectorID][]abi.DealID, error) { } -func (s *state5) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool) (map[abi.DealID]abi.SectorID, error) { +func (s *state5) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool, sectorIDMap map[abi.SectorNumber]bool) (map[abi.DealID]abi.SectorID, error) { return nil, nil diff --git a/chain/actors/builtin/market/v6.go b/chain/actors/builtin/market/v6.go index 20dfc0ea..5d601a27 100644 --- a/chain/actors/builtin/market/v6.go +++ b/chain/actors/builtin/market/v6.go @@ -277,7 +277,7 @@ func (s *state6) GetProviderSectors() (map[abi.SectorID][]abi.DealID, error) { } -func (s *state6) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool) (map[abi.DealID]abi.SectorID, error) { +func (s *state6) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool, sectorIDMap map[abi.SectorNumber]bool) (map[abi.DealID]abi.SectorID, error) { return nil, nil diff --git a/chain/actors/builtin/market/v7.go b/chain/actors/builtin/market/v7.go index fb0c0861..c4e114f7 100644 --- a/chain/actors/builtin/market/v7.go +++ b/chain/actors/builtin/market/v7.go @@ -277,7 +277,7 @@ func (s *state7) GetProviderSectors() (map[abi.SectorID][]abi.DealID, error) { } -func (s *state7) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool) (map[abi.DealID]abi.SectorID, error) { +func (s *state7) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool, sectorIDMap map[abi.SectorNumber]bool) (map[abi.DealID]abi.SectorID, error) { return nil, nil diff --git a/chain/actors/builtin/market/v8.go b/chain/actors/builtin/market/v8.go index 2923e58c..5a5c5ce2 100644 --- a/chain/actors/builtin/market/v8.go +++ b/chain/actors/builtin/market/v8.go @@ -294,7 +294,7 @@ func (s *state8) GetProviderSectors() (map[abi.SectorID][]abi.DealID, error) { } -func (s *state8) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool) (map[abi.DealID]abi.SectorID, error) { +func (s *state8) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool, sectorIDMap map[abi.SectorNumber]bool) (map[abi.DealID]abi.SectorID, error) { return nil, nil diff --git a/chain/actors/builtin/market/v9.go b/chain/actors/builtin/market/v9.go index 2c30e53b..0f36a79d 100644 --- a/chain/actors/builtin/market/v9.go +++ b/chain/actors/builtin/market/v9.go @@ -294,7 +294,7 @@ func (s *state9) GetProviderSectors() (map[abi.SectorID][]abi.DealID, error) { } -func (s *state9) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool) (map[abi.DealID]abi.SectorID, error) { +func (s *state9) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool, sectorIDMap map[abi.SectorNumber]bool) (map[abi.DealID]abi.SectorID, error) { return nil, nil diff --git a/lens/util/builtinactor.go b/lens/util/builtinactor.go index c5db2fa1..f3ba8f08 100644 --- a/lens/util/builtinactor.go +++ b/lens/util/builtinactor.go @@ -3,13 +3,14 @@ package util import ( "strconv" - "github.com/filecoin-project/lotus/chain/types" "github.com/fxamacker/cbor/v2" "github.com/ipfs/go-cid" "github.com/ipld/go-ipld-prime" "github.com/ipld/go-ipld-prime/codec/dagcbor" "github.com/ipld/go-ipld-prime/node/basicnode" "github.com/ipld/go-ipld-prime/node/bindnode" + + "github.com/filecoin-project/lotus/chain/types" ) type KVEvent struct { diff --git a/tasks/actorstate/market/sector_deals_v2.go b/tasks/actorstate/market/sector_deals_v2.go index d153466c..6cf209f3 100644 --- a/tasks/actorstate/market/sector_deals_v2.go +++ b/tasks/actorstate/market/sector_deals_v2.go @@ -70,24 +70,29 @@ func (SectorDealStateExtractor) Extract(ctx context.Context, a actorstate.ActorI } dealIDs := make(map[abi.DealID]bool, 0) + sectorIDs := make(map[abi.SectorNumber]bool, 0) out := make(miner.MinerSectorDealListV2, 0) for _, add := range changes.Added { out = append(out, &miner.MinerSectorDealV2{ - Height: int64(ec.CurrTs.Height()), - DealID: uint64(add.ID), + Height: int64(ec.CurrTs.Height()), + DealID: uint64(add.ID), + SectorID: uint64(add.Deal.SectorNumber()), }) dealIDs[add.ID] = true + sectorIDs[add.Deal.SectorNumber()] = true } for _, mod := range changes.Modified { out = append(out, &miner.MinerSectorDealV2{ - Height: int64(ec.CurrTs.Height()), - DealID: uint64(mod.ID), + Height: int64(ec.CurrTs.Height()), + DealID: uint64(mod.ID), + SectorID: uint64(mod.To.SectorNumber()), }) dealIDs[mod.ID] = true + sectorIDs[mod.To.SectorNumber()] = true } - dealIDSectorMap, err := ec.CurrState.GetProviderSectorsByDealID(dealIDs) + dealIDSectorMap, err := ec.CurrState.GetProviderSectorsByDealID(dealIDs, sectorIDs) if err != nil { log.Errorf("Get the errors during getting provider sectors: %v", err) return nil, nil From 6d314525a3021c3ca711898cdf1edbd82ac1f470 Mon Sep 17 00:00:00 2001 From: "terry.hung" Date: Thu, 16 May 2024 15:50:25 +0800 Subject: [PATCH 3/4] Use dealProposal --- tasks/actorstate/market/sector_deals_v2.go | 41 +++++++++------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/tasks/actorstate/market/sector_deals_v2.go b/tasks/actorstate/market/sector_deals_v2.go index 6cf209f3..37a171a5 100644 --- a/tasks/actorstate/market/sector_deals_v2.go +++ b/tasks/actorstate/market/sector_deals_v2.go @@ -7,6 +7,7 @@ import ( "go.opentelemetry.io/otel" "go.uber.org/zap" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lily/chain/actors/builtin/market" "github.com/filecoin-project/lily/model" @@ -69,44 +70,36 @@ func (SectorDealStateExtractor) Extract(ctx context.Context, a actorstate.ActorI return nil, fmt.Errorf("diffing deal states: %w", err) } - dealIDs := make(map[abi.DealID]bool, 0) - sectorIDs := make(map[abi.SectorNumber]bool, 0) - out := make(miner.MinerSectorDealListV2, 0) + + proposals, _ := ec.CurrState.Proposals() + for _, add := range changes.Added { + dealProposal, found, _ := proposals.Get(add.ID) + minerID := address.Address{} + if found { + minerID = dealProposal.Provider + } out = append(out, &miner.MinerSectorDealV2{ Height: int64(ec.CurrTs.Height()), DealID: uint64(add.ID), SectorID: uint64(add.Deal.SectorNumber()), + MinerID: minerID.String(), }) - dealIDs[add.ID] = true - sectorIDs[add.Deal.SectorNumber()] = true } for _, mod := range changes.Modified { + dealProposal, found, _ := proposals.Get(mod.ID) + minerID := address.Address{} + if found { + minerID = dealProposal.Provider + } out = append(out, &miner.MinerSectorDealV2{ Height: int64(ec.CurrTs.Height()), DealID: uint64(mod.ID), SectorID: uint64(mod.To.SectorNumber()), + MinerID: minerID.String(), }) - dealIDs[mod.ID] = true - sectorIDs[mod.To.SectorNumber()] = true - } - - dealIDSectorMap, err := ec.CurrState.GetProviderSectorsByDealID(dealIDs, sectorIDs) - 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 completeSectorDeal, nil + return out, nil } From 58dfb95543c53f67847ad5ad54704fa3512a9cd7 Mon Sep 17 00:00:00 2001 From: "terry.hung" Date: Thu, 16 May 2024 16:24:41 +0800 Subject: [PATCH 4/4] Refine the logic --- tasks/actorstate/market/sector_deals_v2.go | 35 +++++++++++----------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/tasks/actorstate/market/sector_deals_v2.go b/tasks/actorstate/market/sector_deals_v2.go index 37a171a5..e3adf78e 100644 --- a/tasks/actorstate/market/sector_deals_v2.go +++ b/tasks/actorstate/market/sector_deals_v2.go @@ -7,7 +7,6 @@ import ( "go.opentelemetry.io/otel" "go.uber.org/zap" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lily/chain/actors/builtin/market" "github.com/filecoin-project/lily/model" @@ -75,30 +74,32 @@ func (SectorDealStateExtractor) Extract(ctx context.Context, a actorstate.ActorI proposals, _ := ec.CurrState.Proposals() for _, add := range changes.Added { - dealProposal, found, _ := proposals.Get(add.ID) - minerID := address.Address{} - if found { - minerID = dealProposal.Provider - } - out = append(out, &miner.MinerSectorDealV2{ + minerSectorDeal := miner.MinerSectorDealV2{ Height: int64(ec.CurrTs.Height()), DealID: uint64(add.ID), SectorID: uint64(add.Deal.SectorNumber()), - MinerID: minerID.String(), - }) + } + + // Get the miner address from dealProposal + if dealProposal, found, err := proposals.Get(add.ID); found && err == nil { + minerSectorDeal.MinerID = dealProposal.Provider.String() + } + + out = append(out, &minerSectorDeal) } for _, mod := range changes.Modified { - dealProposal, found, _ := proposals.Get(mod.ID) - minerID := address.Address{} - if found { - minerID = dealProposal.Provider - } - out = append(out, &miner.MinerSectorDealV2{ + minerSectorDeal := miner.MinerSectorDealV2{ Height: int64(ec.CurrTs.Height()), DealID: uint64(mod.ID), SectorID: uint64(mod.To.SectorNumber()), - MinerID: minerID.String(), - }) + } + + // Get the miner address from dealProposal + if dealProposal, found, err := proposals.Get(mod.ID); found && err == nil { + minerSectorDeal.MinerID = dealProposal.Provider.String() + } + + out = append(out, &minerSectorDeal) } return out, nil