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 ()
0 commit comments