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

DDO types, nv22 edition #236

Closed
wants to merge 54 commits into from
Closed

DDO types, nv22 edition #236

wants to merge 54 commits into from

Conversation

magik6k
Copy link
Contributor

@magik6k magik6k commented Dec 8, 2023

For filecoin-project/lotus#11226
Resurrects #209 for nv22
On top of #234

@magik6k magik6k force-pushed the feat/ddo-types-nv22 branch 3 times, most recently from 7ef7f4a to dda87e7 Compare December 13, 2023 14:32
builtin/v13/check.go Outdated Show resolved Hide resolved
Copy link
Contributor

@arajasek arajasek left a comment

Choose a reason for hiding this comment

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

Some notes.

builtin/v13/migration/top.go Outdated Show resolved Hide resolved
builtin/v13/migration/top.go Show resolved Hide resolved
builtin/v13/migration/top.go Outdated Show resolved Hide resolved
builtin/v13/migration/miner.go Outdated Show resolved Hide resolved

fmt.Println("sector before: ", string(pjsonb))
fmt.Println("sector after: ", string(pjson))
return nil, xerrors.Errorf("WHAT?! sector %d modified, this not supported and not supposed to happen", i) // todo: is it? Can't happen w/o a deep, deep reorg, and even then we wouldn't use the cache??
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with all of this, but why not just deal with this case too? You know what sectorBefore and sectorAfter's deals are, so you can:

  • set the mapping for sectorAfters deals easily
  • look up the entries for sectorBefore's deals
    • if they map to sectorNo, delete them -- if they need to get updated to something else, that will happen later
    • if they map to something other than sectorNo leave them alone, they've presumably already been cleaned up

Copy link
Contributor

Choose a reason for hiding this comment

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

or alternatively, add sectorBefores deals to removedDealToSector?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we even use the cache through reorgs? If not this really can't happen, and if we do use the cache through reorgs I imagine the market migrator makes a lot of invalid assumptions too.

(also this reminds me that removedDealToSector is actually no longer used)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we use the cache through reorgs, and should be fully reorg-resistant. There is no assumption that the state it ran on is an ancestor of the current state tree. Instead, the assumption is just that if we cached that X -> Y, we can use that information to calculate X' -> Y', where X and X' probably have some commonalities.

Copy link
Contributor

Choose a reason for hiding this comment

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

What are some of the invalid assumptions you're concerned about?

We could tweak how Lotus uses the cache to wipe it if we know its base state was re-orged out, but I'd rather not do that.

builtin/v13/migration/miner.go Outdated Show resolved Hide resolved
builtin/v13/migration/market.go Outdated Show resolved Hide resolved
addProviderSectorEntry := func(deal abi.DealID, newState *market13.DealState) (abi.SectorNumber, error) {
sid, ok := m.providerSectors.dealToSector[deal]
if !ok {
return 0, xerrors.Errorf("deal %d not found in providerSectors", deal) // todo is this normal and possible??
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think so, but I'm not sure.

Copy link
Member

Choose a reason for hiding this comment

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

Isn't this the case annotated "// FIP: if such a sector cannot be found, assert that the deal's end epoch has passed and use sector ID 0" in the FromScratch case (in which case yes)?

Adding the FIP spec as comments in this version too would be helpful. Though this code isn't setting the deal state sector number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function is called inside of a oldState.SlashEpoch != -1 so I believe that this isn't this case, there the sector number will correctly be set to zero

		case amt.Add: // both in case of chain going forward and chain reorg this is just new deals
			var oldState market12.DealState
			if err := oldState.UnmarshalCBOR(bytes.NewReader(change.After.Raw)); err != nil {
				return cid.Cid{}, cid.Cid{}, xerrors.Errorf("failed to unmarshal old state: %w", err)
			}

			var newState market13.DealState
			newState.SlashEpoch = oldState.SlashEpoch
			newState.LastUpdatedEpoch = oldState.LastUpdatedEpoch
			newState.SectorStartEpoch = oldState.SectorStartEpoch
			newState.SectorNumber = 0 // terminated / not found (?)

			if oldState.SlashEpoch == -1 {
				si, err := addProviderSectorEntry(deal)

Copy link
Member

@anorth anorth left a comment

Choose a reason for hiding this comment

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

The case annotated "// todo is this normal and possible??" seems to be returning an error where it shouldn't.

The FromScratch version looks good but is lacking an assertion that the FIP specifies.

The complexity of the Diff version makes it much harder to verify. I didn't see anything wrong from a FIP specification point of view, but I don't understand the diff mechanics in depth.

} else {
//fmt.Printf("deal %d not found in providerSectors: %v\n", deal, oldState)

newState.SectorNumber = 0 // FIP: if such a sector cannot be found, assert that the deal's end epoch has passed and use sector ID 0
Copy link
Member

Choose a reason for hiding this comment

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

This isn't making the assertion that the FIP specifies. If there's a good reason for that, can it be written in the comment? Should the FIP be changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe the assert is caught by this invariant

acc.Require((deal.SectorNumber == sectorDeal.SectorNumber) || (deal.SectorNumber == 0 && deal.SlashEpoch != -1),
			"deal sector number %d does not match sector %d for miner %v (ds: %#v; ss %#v)",

Will add a comment here

addProviderSectorEntry := func(deal abi.DealID, newState *market13.DealState) (abi.SectorNumber, error) {
sid, ok := m.providerSectors.dealToSector[deal]
if !ok {
return 0, xerrors.Errorf("deal %d not found in providerSectors", deal) // todo is this normal and possible??
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this the case annotated "// FIP: if such a sector cannot be found, assert that the deal's end epoch has passed and use sector ID 0" in the FromScratch case (in which case yes)?

Adding the FIP spec as comments in this version too would be helpful. Though this code isn't setting the deal state sector number.

@arajasek
Copy link
Contributor

Closing in favour of #246

@arajasek arajasek closed this Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Review
Development

Successfully merging this pull request may close these issues.

5 participants