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

Network upgrade support #3781

Merged
merged 110 commits into from
Sep 23, 2020
Merged

Network upgrade support #3781

merged 110 commits into from
Sep 23, 2020

Conversation

Stebalien
Copy link
Member

@Stebalien Stebalien commented Sep 12, 2020

This patch starts adding support for network upgrades.

  • It adds an actors abstraction layer for loading abstract (cross-version) actors.
  • It starts switching over to a shared deadline type.
  • It adds an abstraction for ADTs (hamt/amt).
  • It removes the callback-based API in the StateManager (difficult to abstract across actor versions).
  • It does not actually add support for actors v2. We can do that in a followup patch but that should be relatively easy.

This patch is heavily WIP and does not compile. Feel free to push changes directly to this branch.

Notes:

  • State tree access now needs a network version, because the HAMT type will change. The state-tree now includes a version.
  • I haven't figured out a nice way to abstract over changes to the message types. However, many of them will be type aliased to actors v0 in actors v2 so we can likely continue using the v0 versions (or use the v2 versions everywhere). I've been renaming imports to v0* to make it clear that we're importing types from a specific actors version.

TODO:

  • Consider merging incremental improvements? We'd have to get this compiling again first but we could merge in the new abstractions, and slowly switch over.
  • Finish migrating to the new abstractions.
  • Remove all actor state types from the public API. See miner.State.Info() for the planned approach here.
  • Fix the tests. This is likely going to be a massive pain.
  • Use a specific state-tree version, instead of the actors version.
  • Figure out how to handle chain queries across version upgrades (specifically, hamt version changes).
  • Figure out VM upgrade process.
  • Figure out block format upgrades. I.e., message AMT in blocks.

This patch starts adding support for network upgrades.

* It adds an actors abstraction layer for loading abstract (cross-version) actors.
* It starts switching over to a shared deadline type.
* It adds an abstraction for ADTs (hamt/amt).
* It removes the callback-based API in the StateManager (difficult to abstract
across actor versions).
* It _does not_ actually add support for actors v2. We can do that in a followup
patch but that should be relatively easy.

This patch is heavily WIP and does not compile. Feel free to push changes
directly to this branch.

Notes:

* State tree access now needs a network version, because the HAMT type will change.
* I haven't figured out a nice way to abstract over changes to the _message_
types. However, many of them will be type aliased to actors v0 in actors v2 so
we can likely continue using the v0 versions (or use the v2 versions
everywhere). I've been renaming imports to `v0*` to make it clear that we're
importing types from a _specific_ actors version.

TODO:

* Consider merging incremental improvements? We'd have to get this compiling
again first but we could merge in the new abstractions, and slowly switch over.
* Finish migrating to the new abstractions.
* Remove all actor state types from the public API. See `miner.State.Info()` for
the planned approach here.
* Fix the tests. This is likely going to be a massive pain.
api/api_full.go Show resolved Hide resolved
api/types.go Show resolved Hide resolved
// Converts a network version into a specs-actors version.
func VersionForNetwork(version network.Version) Version {
switch version {
case network.Version0, network.Version1:
Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. Network version != actor version. Also, actor version is going to go from 0 (well, 0.9) to 2. That's going to be rather strange..

Copy link
Member

Choose a reason for hiding this comment

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

If it will just be used as a unique key, maybe use a string "v2" instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

We're now encoding this inside the state tree itself.

@magik6k what version do we actually want in the state tree. We could use:

  • Network version (seems like overkill).
  • Actors version (what we're using here).
  • A specific "state tree" version (for the HAMT). That seems like the best approach, honestly.

Thoughts?

Copy link
Contributor

@magik6k magik6k Sep 21, 2020

Choose a reason for hiding this comment

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

A specific state tree version sounds like what we want here

chain/actors/builtin/init/init.go Show resolved Hide resolved
chain/actors/builtin/init/init.go Show resolved Hide resolved
@@ -47,6 +47,7 @@ func NewInvoker() *Invoker {
}

// add builtInCode using: register(cid, singleton)
// NETUPGRADE: register code IDs for v2, etc.
Copy link
Member Author

Choose a reason for hiding this comment

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

My plan here is to register code IDs for both v1 and v2 actors, at the same time. As far as I know, this should "just work".

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct, though ideally we'd at least specify minimum / maximum epoch at which a given code CID can be used

cmd/lotus-shed/balances.go Outdated Show resolved Hide resolved
cmd/lotus-storage-miner/proving.go Show resolved Hide resolved
cmd/lotus-storage-miner/proving.go Show resolved Hide resolved
cmd/lotus-storage-miner/proving.go Show resolved Hide resolved
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.

Looking good from here

api/types.go Outdated Show resolved Hide resolved
api/types.go Outdated Show resolved Hide resolved
// Converts a network version into a specs-actors version.
func VersionForNetwork(version network.Version) Version {
switch version {
case network.Version0, network.Version1:
Copy link
Member

Choose a reason for hiding this comment

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

If it will just be used as a unique key, maybe use a string "v2" instead?

chain/actors/builtin/market/v0.go Show resolved Hide resolved
chain/actors/version.go Outdated Show resolved Hide resolved
chain/state/statetree.go Outdated Show resolved Hide resolved
@magik6k magik6k added the P0 P0: Critical Blocker label Sep 14, 2020
@magik6k
Copy link
Contributor

magik6k commented Sep 14, 2020

Consider merging incremental improvements? We'd have to get this compiling again first but we could merge in the new abstractions, and slowly switch over

Yes, definitely want non-consensus breaking changes in before, so the PR with the actual consensus upgrade is as small/easy to review as possible

chain/stmgr/utils.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.

I think this is good to merge. The biggest thing kicked down the road is probably genesis setup stuff (along with lots of tests explicitly using v0 actors). I think that's fine for now.

Some of the "just use v0 actors it'll be fine" needs to be scrutinised, but we can do a second pass when we actually introduce v1 actors.

@arajasek arajasek marked this pull request as ready for review September 23, 2020 06:33
@magik6k magik6k changed the title [WIP] Network upgrade support Network upgrade support Sep 23, 2020
@@ -300,7 +290,11 @@ func (sm *StateManager) ApplyBlocks(ctx context.Context, parentEpoch abi.ChainEp
return cid.Cid{}, cid.Cid{}, err
}

rectarr := adt.MakeEmptyArray(sm.cs.Store(ctx))
// XXX: Is the height correct? Or should it be epoch-1?
Copy link
Contributor

Choose a reason for hiding this comment

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

This is matching how the VM GetNtwkVersion works, so most likely correct

(differently something to manually verify when we test the fork)

case act.IsAccountActor():
st, err := account.Load(store, act)
if err != nil {
// TODO: magik6k: this _used_ to log instead of failing, why?
Copy link
Contributor

Choose a reason for hiding this comment

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

That's a @whyrusleeping question

Copy link
Contributor

@magik6k magik6k left a comment

Choose a reason for hiding this comment

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

Looks good, also works, ship it!

@magik6k magik6k merged commit c46e157 into master Sep 23, 2020
@magik6k magik6k deleted the refactor/net-upgrade branch September 23, 2020 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P0 P0: Critical Blocker
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants