Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migration: sector deal ids index cached #210

Closed
wants to merge 65 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
cdc4fa4
feat: Add SectorDealIDs with CBOR serialization
snissn Aug 23, 2023
c1a758f
feat: Introduce SectorDeals mapping in market state
snissn Aug 23, 2023
a08aa8f
temp: Add logging for sectorToDealIdHamtCid and minerAddr in migration
snissn Aug 23, 2023
f7b3f39
Add HamtCid struct and its CBOR serialization methods
snissn Aug 24, 2023
d7f9e76
commit -m "Enhance miner migration and introduce market migration
snissn Aug 24, 2023
f4616ba
forgot the file for market migration
snissn Aug 24, 2023
b7c927f
Refactor migration logic and streamline market actor updates.
snissn Aug 24, 2023
3d217c0
Rename variables for clarity in market actor migration code
snissn Aug 25, 2023
c4ec6a7
Save the new market state object to the datastore and set the migrate…
snissn Aug 25, 2023
2600de7
bugfixes: Update migration logic to use v12 market state
snissn Aug 25, 2023
ca993fe
xxx remove migration for testing
snissn Aug 25, 2023
435c9c8
Revert "xxx remove migration for testing"
snissn Aug 25, 2023
b97547c
bufix: place RunMigration after the initial set up work to find the m…
snissn Aug 25, 2023
1909372
feat(miner): Implement Migration Cache in Miner Migrator
snissn Aug 29, 2023
0c8a77a
save to sector index hamt to cache after doing all the work!
snissn Aug 31, 2023
c4ef84e
bugfix: use market11cid for code
snissn Sep 1, 2023
232b1c8
bugfix: use MarketKey for market11cid
snissn Sep 1, 2023
a785f26
add hamt lock
snissn Sep 1, 2023
b4865b9
use cbor gen for cid
snissn Sep 1, 2023
778d677
remove duplicate code block
snissn Sep 1, 2023
e7a1505
pass lock by reference
snissn Sep 1, 2023
676a62c
Optimize and refactor miner migration logic
snissn Sep 2, 2023
26084d2
Merge branch 'master' into mikers/sector_deal_ids_index_cached
snissn Sep 2, 2023
98270db
match naming conventions for MinerPrevSectorDealIndexKey
snissn Sep 5, 2023
da0545e
match naming conventions for MarketSectorIndexKey
snissn Sep 5, 2023
d84d293
remove redundant comment
snissn Sep 5, 2023
a697049
remove confusing comment
snissn Sep 5, 2023
7c7b469
remove unused variable in function
snissn Sep 5, 2023
16b4ec5
epxlain comment
snissn Sep 5, 2023
ffbf314
online the Put command for simplicity
snissn Sep 5, 2023
606d9d5
Update deal state schema to match Rust (#215)
anorth Sep 5, 2023
dd380ea
feat: Enhance migration handling with deferredCodeIDs
snissn Sep 6, 2023
ba81ee8
initailize lock otherwise we have a nil pointer
snissn Sep 6, 2023
f35b49f
Refactor minerMigrator to use adt.Map for sectorDeals
snissn Sep 6, 2023
1f8f23b
rename mutex to more explicit name
snissn Sep 6, 2023
a6c9c22
dereference pointer before calling Lock() - not sure why previously c…
snissn Sep 6, 2023
69de893
Revert "dereference pointer before calling Lock() - not sure why prev…
snissn Sep 8, 2023
095e597
adding print statements for the miner address -> hamt
snissn Sep 8, 2023
0df532a
Enhance migration logic to handle dual CIDs and extend cache function…
snissn Sep 8, 2023
a56af3d
Revert "Enhance migration logic to handle dual CIDs and extend cache …
snissn Sep 9, 2023
465d700
Refactor Miner State Migration Logic
snissn Sep 9, 2023
a008d02
look up prevInRoot here, not inRoot. We won't have a cached result fo…
snissn Sep 11, 2023
190fe18
chain errors
snissn Sep 11, 2023
56dc952
Update builtin/v12/migration/top.go
snissn Sep 11, 2023
be33517
Merge branch 'mikers/sector_deal_ids_index_cached' of https://github.…
snissn Sep 11, 2023
7f7613b
remove old todo
snissn Sep 11, 2023
a9745f4
fix error message
snissn Sep 11, 2023
4f851d5
add error message
snissn Sep 11, 2023
740b22b
better name for hamt
snissn Sep 11, 2023
f791133
cleanup errors
snissn Sep 11, 2023
0a40559
Update HAMT Handling in Miner Migration
snissn Sep 11, 2023
869619d
remove verifreg.AllocationId based on fip-0076 requirements
snissn Sep 12, 2023
eae58d8
Enhanced miner migration logic with deal-to-sector indexing
snissn Sep 13, 2023
43bda09
remove delete from m.dealToSectorIndex because of algorithmic tradeof…
snissn Sep 13, 2023
f5a7345
Migrate market states to v12 and update deal states
snissn Sep 13, 2023
4e83d01
Rename 'States' field to 'DealStates' in v12 market
snissn Sep 13, 2023
badebde
lotus fails to build these errors:
snissn Sep 13, 2023
88f5efe
Refactor dealToSectorIndex to use sync.Map
snissn Sep 13, 2023
d731666
Refactor migration logic to incorporate caching previous deal states
snissn Sep 14, 2023
99548ca
handle errors
snissn Sep 14, 2023
6856ec7
add err handler and minor refactor formatting if statements
snissn Sep 14, 2023
143bddb
Revert "add err handler and minor refactor formatting if statements"
snissn Sep 14, 2023
f197c10
add err handler
snissn Sep 14, 2023
6ae71c1
prints for debugging
snissn Sep 15, 2023
efc66d1
adding more print statements for debugging and cleaning up an if stat…
snissn Sep 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion builtin/v11/migration/top.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func MigrateStateTree(ctx context.Context, store cbor.IpldStore, newManifestCID
return cid.Undef, xerrors.Errorf("incomplete migration specification with %d code CIDs, need %d", len(migrations), len(oldManifestData.Entries))
}

actorsOut, err := migration.RunMigration(ctx, cfg, cache, store, log, actorsIn, migrations)
actorsOut, err := migration.RunMigration(ctx, cfg, cache, store, log, actorsIn, migrations, deferredCodeIDs)
if err != nil {
return cid.Undef, xerrors.Errorf("failed to run migration: %w", err)
}
Expand Down
1 change: 1 addition & 0 deletions builtin/v11/miner/miner_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/filecoin-project/go-state-types/builtin/v11/util/adt"
"github.com/filecoin-project/go-state-types/dline"
xc "github.com/filecoin-project/go-state-types/exitcode"

cid "github.com/ipfs/go-cid"
"golang.org/x/xerrors"
)
Expand Down
16 changes: 0 additions & 16 deletions builtin/v12/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,22 +334,6 @@ func CheckVerifregAgainstMiners(acc *builtin.MessageAccumulator, verifregSummary
}

func CheckMarketAgainstVerifreg(acc *builtin.MessageAccumulator, verifregSummary *verifreg.StateSummary, marketSummary *market.StateSummary) {
// all activated verified deals with claim ids reference a claim in verifreg state
// note that it is possible for claims to exist with no matching deal if the deal expires
for claimId, dealId := range marketSummary.ClaimIdToDealId {
claim, found := verifregSummary.Claims[claimId]
acc.Require(found, "claim %d not found for activated deal %d", claimId, dealId)

info, found := marketSummary.Deals[dealId]
acc.Require(found, "internal invariant error invalid market state references missing deal %d", dealId)

providerId, err := address.IDFromAddress(info.Provider)
acc.RequireNoError(err, "error getting ID from provider address")
acc.Require(abi.ActorID(providerId) == claim.Provider, "mismatches providers %d %d on claim %d and deal %d", providerId, claim.Provider, claimId, dealId)

acc.Require(info.PieceCid == claim.Data, "mismatches piece cid %s %s on claim %d and deal %d", info.PieceCid, claim.Data, claimId, dealId)
}

// all pending deal allocation ids have an associated allocation
// note that it is possible for allocations to exist that don't match any deal
// if they are created from a direct DataCap transfer
Expand Down
1 change: 1 addition & 0 deletions builtin/v12/gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func main() {
market.GetDealTermReturn{},
market.GetDealActivationReturn{},
market.OnMinerSectorsTerminateParams{},
market.SectorDealIDs{},

// other types
market.DealProposal{},
Expand Down
152 changes: 129 additions & 23 deletions builtin/v12/market/cbor_gen.go

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

3 changes: 1 addition & 2 deletions builtin/v12/market/deal.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
addr "github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/builtin/v12/verifreg"
acrypto "github.com/filecoin-project/go-state-types/crypto"
)

Expand All @@ -27,10 +26,10 @@ var PieceCIDPrefix = cid.Prefix{
}

type DealState struct {
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
VerifiedClaim verifreg.AllocationId
}

// The DealLabel is a kinded union of string or byte slice.
Expand Down
8 changes: 0 additions & 8 deletions builtin/v12/market/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ type DealSummary struct {
type StateSummary struct {
Deals map[abi.DealID]*DealSummary
PendingDealAllocationIds map[abi.DealID]verifreg.AllocationId
ClaimIdToDealId map[verifreg.ClaimId]abi.DealID
AllocIdToDealId map[verifreg.AllocationId]abi.DealID
PendingProposalCount uint64
DealStateCount uint64
Expand Down Expand Up @@ -118,7 +117,6 @@ func CheckStateInvariants(st *State, store adt.Store, balance abi.TokenAmount, c
}

dealStateCount := uint64(0)
claimIdToDealId := make(map[verifreg.ClaimId]abi.DealID)
if dealStates, err := adt.AsArray(store, st.States, StatesAmtBitwidth); err != nil {
acc.Addf("error loading deal states: %v", err)
} else {
Expand Down Expand Up @@ -156,11 +154,6 @@ func CheckStateInvariants(st *State, store adt.Store, balance abi.TokenAmount, c
acc.Require(!found, "deal %d has pending allocation", dealID)

dealStateCount++

if dealState.VerifiedClaim != verifreg.NoAllocationID {
claimIdToDealId[verifreg.ClaimId(dealState.VerifiedClaim)] = abi.DealID(dealID)
}

return nil
})
acc.RequireNoError(err, "error iterating deal states")
Expand Down Expand Up @@ -266,7 +259,6 @@ func CheckStateInvariants(st *State, store adt.Store, balance abi.TokenAmount, c
LockTableCount: lockTableCount,
DealOpEpochCount: dealOpEpochCount,
DealOpCount: dealOpCount,
ClaimIdToDealId: claimIdToDealId,
AllocIdToDealId: allocationIdToDealId,
}, acc
}
8 changes: 8 additions & 0 deletions builtin/v12/market/market_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ type State struct {

// Verified registry allocation IDs for deals that are not yet activated.
PendingDealAllocationIds cid.Cid // HAMT[DealID]AllocationID

// New mapping of sector IDs to deal IDS, grouped by storage provider.
ProviderSectors cid.Cid // HAMT[Address]HAMT[SectorNumber]SectorDeals
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ProviderSectors cid.Cid // HAMT[Address]HAMT[SectorNumber]SectorDeals
ProviderSectors cid.Cid // HAMT[Address]HAMT[SectorNumber]SectorDealIDs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think?


}

func ConstructState(store adt.Store) (*State, error) {
Expand Down Expand Up @@ -101,6 +105,10 @@ func ConstructState(store adt.Store) (*State, error) {
}, nil
}

type SectorDealIDs struct {
DealIDs []abi.DealID
}

// A specialization of a array to deals.
// It is an error to query for a key that doesn't exist.
type DealArray struct {
Expand Down
Loading