Skip to content

Commit 87c7fd4

Browse files
committed
review fixes
1 parent 339692c commit 87c7fd4

File tree

11 files changed

+7797
-59
lines changed

11 files changed

+7797
-59
lines changed

build/openrpc/full.json.gz

64 Bytes
Binary file not shown.

build/openrpc/miner.json.gz

-1 Bytes
Binary file not shown.

build/openrpc/worker.json.gz

0 Bytes
Binary file not shown.

chain/actors/builtin/system/actor.go.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
4949
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
5050
}
5151

52-
func MakeState(store adt.Store, av actors.Version) (State, error) {
52+
func MakeState(store adt.Store, av actors.Version, builtinActors cid.Cid) (State, error) {
5353
switch av {
5454
{{range .versions}}
5555
case actors.Version{{.}}:
56-
return make{{.}}(store)
56+
return make{{.}}(store{{if (ge . 8)}}, builtinActors{{end}})
5757
{{end}}
5858
}
5959
return nil, xerrors.Errorf("unknown actor version %d", av)

chain/actors/builtin/system/state.go.template

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ func load{{.v}}(store adt.Store, root cid.Cid) (State, error) {
2323
return &out, nil
2424
}
2525

26-
func make{{.v}}(store adt.Store) (State, error) {
26+
func make{{.v}}(store adt.Store{{if (ge .v 8)}}, builtinActors cid.Cid{{end}}) (State, error) {
2727
out := state{{.v}}{store: store}
28-
out.State = system{{.v}}.State{}
28+
out.State = system{{.v}}.State{
29+
{{if (ge .v 8)}}BuiltinActors: builtinActors,{{end}}
30+
}
2931
return &out, nil
3032
}
3133

chain/actors/builtin/system/system.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
7171
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
7272
}
7373

74-
func MakeState(store adt.Store, av actors.Version) (State, error) {
74+
func MakeState(store adt.Store, av actors.Version, builtinActors cid.Cid) (State, error) {
7575
switch av {
7676

7777
case actors.Version0:
@@ -96,7 +96,7 @@ func MakeState(store adt.Store, av actors.Version) (State, error) {
9696
return make7(store)
9797

9898
case actors.Version8:
99-
return make8(store)
99+
return make8(store, builtinActors)
100100

101101
}
102102
return nil, xerrors.Errorf("unknown actor version %d", av)

chain/actors/builtin/system/v8.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ func load8(store adt.Store, root cid.Cid) (State, error) {
1919
return &out, nil
2020
}
2121

22-
func make8(store adt.Store) (State, error) {
22+
func make8(store adt.Store, builtinActors cid.Cid) (State, error) {
2323
out := state8{store: store}
24-
out.State = system8.State{}
24+
out.State = system8.State{
25+
BuiltinActors: builtinActors,
26+
}
2527
return &out, nil
2628
}
2729

chain/consensus/filcns/upgrades.go

Lines changed: 46 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"runtime"
66
"time"
77

8+
adt8 "github.com/filecoin-project/specs-actors/v8/actors/util/adt"
9+
810
"github.com/docker/go-units"
911
"github.com/ipfs/go-cid"
1012
cbor "github.com/ipfs/go-ipld-cbor"
@@ -17,7 +19,6 @@ import (
1719
"github.com/filecoin-project/go-state-types/network"
1820
"github.com/filecoin-project/go-state-types/rt"
1921

20-
system8 "github.com/filecoin-project/go-state-types/builtin/v8/system"
2122
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
2223
miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner"
2324
multisig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig"
@@ -32,8 +33,6 @@ import (
3233
"github.com/filecoin-project/specs-actors/v6/actors/migration/nv14"
3334
"github.com/filecoin-project/specs-actors/v7/actors/migration/nv15"
3435
"github.com/filecoin-project/specs-actors/v8/actors/migration/nv16"
35-
states8 "github.com/filecoin-project/specs-actors/v8/actors/states"
36-
adt8 "github.com/filecoin-project/specs-actors/v8/actors/util/adt"
3736

3837
"github.com/filecoin-project/lotus/blockstore"
3938
"github.com/filecoin-project/lotus/build"
@@ -1433,12 +1432,12 @@ func upgradeActorsV8Common(
14331432
return newRoot, nil
14341433
}
14351434

1436-
func UpgradeActorsCode(ctx context.Context, sm *stmgr.StateManager, newActorsManifestCid cid.Cid, root cid.Cid) (cid.Cid, error) {
1435+
func UpgradeActorsCode(ctx context.Context, sm *stmgr.StateManager, newActorsManifestCid cid.Cid, root cid.Cid, av actors.Version, oldStateTreeVersion types.StateTreeVersion, newStateTreeVersion types.StateTreeVersion) (cid.Cid, error) { // nolint
14371436
bstore := sm.ChainStore().StateBlockstore()
1438-
return LiteMigration(ctx, bstore, newActorsManifestCid, root)
1437+
return LiteMigration(ctx, bstore, newActorsManifestCid, root, av, oldStateTreeVersion, newStateTreeVersion)
14391438
}
14401439

1441-
func LiteMigration(ctx context.Context, bstore blockstore.Blockstore, newActorsManifestCid cid.Cid, root cid.Cid) (cid.Cid, error) {
1440+
func LiteMigration(ctx context.Context, bstore blockstore.Blockstore, newActorsManifestCid cid.Cid, root cid.Cid, av actors.Version, oldStateTreeVersion types.StateTreeVersion, newStateTreeVersion types.StateTreeVersion) (cid.Cid, error) {
14421441
buf := blockstore.NewTieredBstore(bstore, blockstore.NewMemorySync())
14431442
store := store.ActorStore(ctx, buf)
14441443
adtStore := adt8.WrapStore(ctx, store)
@@ -1449,29 +1448,24 @@ func LiteMigration(ctx context.Context, bstore blockstore.Blockstore, newActorsM
14491448
return cid.Undef, xerrors.Errorf("failed to decode state root: %w", err)
14501449
}
14511450

1452-
if stateRoot.Version != types.StateTreeVersion4 {
1451+
if stateRoot.Version != oldStateTreeVersion {
14531452
return cid.Undef, xerrors.Errorf(
14541453
"expected state root version 4 for actors code upgrade, got %d",
14551454
stateRoot.Version,
14561455
)
14571456
}
14581457

1459-
// Get old actors
1460-
actorsIn, err := states8.LoadTree(adtStore, stateRoot.Actors)
1458+
st, err := state.LoadStateTree(store, root)
14611459
if err != nil {
14621460
return cid.Undef, xerrors.Errorf("failed to load state tree: %w", err)
14631461
}
1464-
systemActor, ok, err := actorsIn.GetActor(system.Address)
1465-
if !ok {
1462+
1463+
// Get old actors
1464+
systemActor, err := st.GetActor(system.Address)
1465+
if err != nil {
14661466
return cid.Undef, xerrors.Errorf("failed to get system actor: %w", err)
14671467
}
1468-
systemActorType := types.Actor{
1469-
Code: systemActor.Code,
1470-
Head: systemActor.Head,
1471-
Nonce: systemActor.CallSeqNum,
1472-
Balance: systemActor.Balance,
1473-
}
1474-
systemActorState, err := system.Load(store, &systemActorType)
1468+
systemActorState, err := system.Load(store, systemActor)
14751469
if err != nil {
14761470
return cid.Undef, xerrors.Errorf("failed to load system actor state: %w", err)
14771471
}
@@ -1485,6 +1479,10 @@ func LiteMigration(ctx context.Context, bstore blockstore.Blockstore, newActorsM
14851479
if err := oldManifest.Load(ctx, adtStore); err != nil {
14861480
return cid.Undef, xerrors.Errorf("error loading old actor manifest: %w", err)
14871481
}
1482+
oldManifestData := manifest.ManifestData{}
1483+
if err := store.Get(ctx, oldManifest.Data, &oldManifestData); err != nil {
1484+
return cid.Undef, xerrors.Errorf("error loading old manifest data: %w", err)
1485+
}
14881486

14891487
// load new manifest
14901488
newManifest := manifest.Manifest{}
@@ -1496,6 +1494,13 @@ func LiteMigration(ctx context.Context, bstore blockstore.Blockstore, newActorsM
14961494
return cid.Undef, xerrors.Errorf("error loading new manifest data: %w", err)
14971495
}
14981496

1497+
if len(newManifestData.Entries) != len(actors.GetBuiltinActorsKeys()) {
1498+
return cid.Undef, xerrors.Errorf("incomplete new manifest with %d code CIDs", len(newManifestData.Entries))
1499+
}
1500+
if len(oldManifestData.Entries) != len(actors.GetBuiltinActorsKeys()) {
1501+
return cid.Undef, xerrors.Errorf("incomplete old manifest with %d code CIDs", len(oldManifestData.Entries))
1502+
}
1503+
14991504
// Maps prior version code CIDs to migration functions.
15001505
migrations := make(map[cid.Cid]cid.Cid)
15011506

@@ -1507,42 +1512,42 @@ func LiteMigration(ctx context.Context, bstore blockstore.Blockstore, newActorsM
15071512
migrations[oldCodeCid] = entry.Code
15081513
}
15091514

1510-
if len(migrations) != 11 {
1511-
return cid.Undef, xerrors.Errorf("incomplete manifest with %d code CIDs", len(migrations))
1512-
}
15131515
startTime := time.Now()
15141516

15151517
// Load output state tree
1516-
actorsOut, err := states8.NewTree(adtStore)
1518+
actorsOut, err := state.NewStateTree(adtStore, newStateTreeVersion)
15171519
if err != nil {
15181520
return cid.Undef, err
15191521
}
15201522

15211523
// Insert migrated records in output state tree.
1522-
err = actorsIn.ForEach(func(addr address.Address, actorIn *states8.Actor) error {
1523-
var newActor states8.Actor
1524+
err = st.ForEach(func(addr address.Address, actorIn *types.Actor) error {
15241525
newCid, ok := migrations[actorIn.Code]
15251526
if !ok {
1526-
return xerrors.Errorf("new code cid for system actor not found in migrations for actor %s", addr)
1527+
return xerrors.Errorf("new code cid not found in migrations for actor %s", addr)
15271528
}
1529+
var newActor types.Actor
15281530
if addr == system.Address {
1529-
newSystemState := system8.State{BuiltinActors: newManifest.Data}
1530-
systemStateHead, err := store.Put(ctx, &newSystemState)
1531+
newSystemState, err := system.MakeState(store, av, newManifest.Data)
1532+
if err != nil {
1533+
return xerrors.Errorf("could not make system actor state: %w", err)
1534+
}
1535+
systemStateHead, err := store.Put(ctx, newSystemState)
15311536
if err != nil {
15321537
return xerrors.Errorf("could not set system actor state head: %w", err)
15331538
}
1534-
newActor = states8.Actor{
1535-
Code: newCid,
1536-
Head: systemStateHead,
1537-
CallSeqNum: actorIn.CallSeqNum,
1538-
Balance: actorIn.Balance,
1539+
newActor = types.Actor{
1540+
Code: newCid,
1541+
Head: systemStateHead,
1542+
Nonce: actorIn.Nonce,
1543+
Balance: actorIn.Balance,
15391544
}
15401545
} else {
1541-
newActor = states8.Actor{
1542-
Code: newCid,
1543-
Head: actorIn.Head,
1544-
CallSeqNum: actorIn.CallSeqNum,
1545-
Balance: actorIn.Balance,
1546+
newActor = types.Actor{
1547+
Code: newCid,
1548+
Head: actorIn.Head,
1549+
Nonce: actorIn.Nonce,
1550+
Balance: actorIn.Balance,
15461551
}
15471552
}
15481553
err = actorsOut.SetActor(addr, &newActor)
@@ -1552,26 +1557,18 @@ func LiteMigration(ctx context.Context, bstore blockstore.Blockstore, newActorsM
15521557

15531558
return nil
15541559
})
1560+
if err != nil {
1561+
return cid.Undef, xerrors.Errorf("failed update actor states: %w", err)
1562+
}
15551563

15561564
elapsed := time.Since(startTime)
15571565
log.Infof("All done after %v. Flushing state tree root.", elapsed)
1558-
newHamtRoot, err := actorsOut.Flush()
1566+
newRoot, err := actorsOut.Flush(ctx)
15591567
if err != nil {
15601568
return cid.Undef, xerrors.Errorf("failed to flush new actors: %w", err)
15611569
}
15621570

1563-
// Persist the result.
1564-
newRoot, err := store.Put(ctx, &types.StateRoot{
1565-
Version: types.StateTreeVersion4,
1566-
Actors: newHamtRoot,
1567-
Info: stateRoot.Info,
1568-
})
1569-
if err != nil {
1570-
return cid.Undef, xerrors.Errorf("failed to persist new state root: %w", err)
1571-
}
1572-
15731571
// Persist the new tree.
1574-
15751572
{
15761573
from := buf
15771574
to := buf.Read()

chain/gen/genesis/f00_system.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package genesis
33
import (
44
"context"
55

6+
"github.com/ipfs/go-cid"
7+
68
systemtypes "github.com/filecoin-project/go-state-types/builtin/v8/system"
79

810
"github.com/filecoin-project/go-state-types/manifest"
@@ -25,7 +27,8 @@ import (
2527
func SetupSystemActor(ctx context.Context, bs bstore.Blockstore, av actors.Version) (*types.Actor, error) {
2628

2729
cst := cbor.NewCborStore(bs)
28-
st, err := system.MakeState(adt.WrapStore(ctx, cst), av)
30+
// TODO pass in built-in actors cid for V8 and later
31+
st, err := system.MakeState(adt.WrapStore(ctx, cst), av, cid.Undef)
2932
if err != nil {
3033
return nil, err
3134
}

0 commit comments

Comments
 (0)