Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

Commit

Permalink
Implement nv16 migration according to FIP31 (#1583)
Browse files Browse the repository at this point in the history
* actor manifest data structure and cbor marshaler/unmarshaler

* implement manifest.Load

* system actor v8 state

* implement nv16 migration

* make gen

* check manifest version when loading

* move system actor migration to its own file

* fix system actor state for tests

* update determinism check sum

* lint

* initialize system actor state to undefined

* fix migration tests

* lint

* fix migrated code cids so that state is checkable

* initialize system actor with empty state

* properly initialize system actor state in test vm

* make determinism-gen

* document builtina actors data type

* add comment about manifest data being in the blockstore

* kill space

* keep deferredCodeCids structure around

* make test nv16 specific

* normalize system actor state construction

* follow the pattern in testing vm construction

* fix lint
  • Loading branch information
vyzo authored Apr 4, 2022
1 parent 3c87d38 commit 5f5089f
Show file tree
Hide file tree
Showing 14 changed files with 575 additions and 288 deletions.
244 changes: 244 additions & 0 deletions actors/builtin/manifest/cbor_gen.go

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

49 changes: 49 additions & 0 deletions actors/builtin/manifest/manifest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package manifest

import (
"context"
"fmt"

adt8 "github.com/filecoin-project/specs-actors/v8/actors/util/adt"

"github.com/ipfs/go-cid"
)

type Manifest struct {
Version uint64 // this is really u32, but cbor-gen can't deal with it
Data cid.Cid

entries map[string]cid.Cid
}

type ManifestEntry struct {
Name string
Code cid.Cid
}

type ManifestData struct {
Entries []ManifestEntry
}

func (m *Manifest) Load(ctx context.Context, store adt8.Store) error {
if m.Version != 1 {
return fmt.Errorf("unknown manifest version %d", m.Version)
}

data := ManifestData{}
if err := store.Get(ctx, m.Data, &data); err != nil {
return err
}

m.entries = make(map[string]cid.Cid)
for _, e := range data.Entries {
m.entries[e.Name] = e.Code
}

return nil
}

func (m *Manifest) Get(name string) (cid.Cid, bool) {
c, ok := m.entries[name]
return c, ok
}
24 changes: 22 additions & 2 deletions actors/builtin/system/cbor_gen.go

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

9 changes: 5 additions & 4 deletions actors/builtin/system/system_actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package system
import (
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/cbor"
"github.com/filecoin-project/go-state-types/exitcode"
"github.com/ipfs/go-cid"

"github.com/filecoin-project/specs-actors/v8/actors/builtin"
"github.com/filecoin-project/specs-actors/v8/actors/runtime"
"github.com/filecoin-project/specs-actors/v8/actors/util/adt"
)

type Actor struct{}
Expand All @@ -33,9 +35,8 @@ var _ runtime.VMActor = Actor{}

func (a Actor) Constructor(rt runtime.Runtime, _ *abi.EmptyValue) *abi.EmptyValue {
rt.ValidateImmediateCallerIs(builtin.SystemActorAddr)

rt.StateCreate(&State{})
st, err := ConstructState(adt.AsStore(rt))
builtin.RequireNoErr(rt, err, exitcode.ErrIllegalState, "failed to construct state")
rt.StateCreate(st)
return nil
}

type State struct{}
24 changes: 24 additions & 0 deletions actors/builtin/system/system_actor_state.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package system

import (
"context"

cid "github.com/ipfs/go-cid"
xerrors "golang.org/x/xerrors"

"github.com/filecoin-project/specs-actors/v8/actors/builtin/manifest"
"github.com/filecoin-project/specs-actors/v8/actors/util/adt"
)

type State struct {
BuiltinActors cid.Cid // ManifestData
}

func ConstructState(store adt.Store) (*State, error) {
empty, err := store.Put(context.TODO(), &manifest.ManifestData{})
if err != nil {
return nil, xerrors.Errorf("failed to create empty manifest: %w", err)
}

return &State{BuiltinActors: empty}, nil
}
Loading

0 comments on commit 5f5089f

Please sign in to comment.