|
|
|
@@ -4,7 +4,6 @@ import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/binary"
|
|
|
|
|
"math"
|
|
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
@@ -29,6 +28,7 @@ import (
|
|
|
|
|
adt0 "github.com/filecoin-project/specs-actors/actors/util/adt"
|
|
|
|
|
"github.com/filecoin-project/specs-actors/v2/actors/migration/nv4"
|
|
|
|
|
"github.com/filecoin-project/specs-actors/v2/actors/migration/nv7"
|
|
|
|
|
"github.com/filecoin-project/specs-actors/v3/actors/migration/nv9"
|
|
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
|
cbor "github.com/ipfs/go-ipld-cbor"
|
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
@@ -100,32 +100,12 @@ func DefaultUpgradeSchedule() UpgradeSchedule {
|
|
|
|
|
Height: build.UpgradeOrangeHeight,
|
|
|
|
|
Network: network.Version9,
|
|
|
|
|
Migration: nil,
|
|
|
|
|
}, {
|
|
|
|
|
Height: build.UpgradeActorsV3Height,
|
|
|
|
|
Network: network.Version10,
|
|
|
|
|
Migration: UpgradeActorsV3,
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
|
|
if build.UpgradeActorsV2Height == math.MaxInt64 { // disable actors upgrade
|
|
|
|
|
updates = []Upgrade{{
|
|
|
|
|
Height: build.UpgradeBreezeHeight,
|
|
|
|
|
Network: network.Version1,
|
|
|
|
|
Migration: UpgradeFaucetBurnRecovery,
|
|
|
|
|
}, {
|
|
|
|
|
Height: build.UpgradeSmokeHeight,
|
|
|
|
|
Network: network.Version2,
|
|
|
|
|
Migration: nil,
|
|
|
|
|
}, {
|
|
|
|
|
Height: build.UpgradeIgnitionHeight,
|
|
|
|
|
Network: network.Version3,
|
|
|
|
|
Migration: UpgradeIgnition,
|
|
|
|
|
}, {
|
|
|
|
|
Height: build.UpgradeRefuelHeight,
|
|
|
|
|
Network: network.Version3,
|
|
|
|
|
Migration: UpgradeRefuel,
|
|
|
|
|
}, {
|
|
|
|
|
Height: build.UpgradeLiftoffHeight,
|
|
|
|
|
Network: network.Version3,
|
|
|
|
|
Migration: UpgradeLiftoff,
|
|
|
|
|
}}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, u := range updates {
|
|
|
|
|
if u.Height < 0 {
|
|
|
|
|
// upgrade disabled
|
|
|
|
@@ -704,6 +684,73 @@ func UpgradeCalico(ctx context.Context, sm *StateManager, cb ExecCallback, root
|
|
|
|
|
return newRoot, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func UpgradeActorsV3(ctx context.Context, sm *StateManager, cb ExecCallback, root cid.Cid, epoch abi.ChainEpoch, ts *types.TipSet) (cid.Cid, error) {
|
|
|
|
|
buf := bufbstore.NewTieredBstore(sm.cs.Blockstore(), bstore.NewTemporarySync())
|
|
|
|
|
store := store.ActorStore(ctx, buf)
|
|
|
|
|
|
|
|
|
|
// Load the state root.
|
|
|
|
|
|
|
|
|
|
var stateRoot types.StateRoot
|
|
|
|
|
if err := store.Get(ctx, root, &stateRoot); err != nil {
|
|
|
|
|
return cid.Undef, xerrors.Errorf("failed to decode state root: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if stateRoot.Version != types.StateTreeVersion1 {
|
|
|
|
|
return cid.Undef, xerrors.Errorf(
|
|
|
|
|
"expected state root version 1 for actors v3 upgrade, got %d",
|
|
|
|
|
stateRoot.Version,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Perform the migration
|
|
|
|
|
|
|
|
|
|
// TODO: store this somewhere and pre-migrate
|
|
|
|
|
cache := nv9.NewMemMigrationCache()
|
|
|
|
|
// TODO: tune this.
|
|
|
|
|
config := nv9.Config{MaxWorkers: 1}
|
|
|
|
|
newHamtRoot, err := nv9.MigrateStateTree(ctx, store, stateRoot.Actors, epoch, config, migrationLogger{}, cache)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return cid.Undef, xerrors.Errorf("upgrading to actors v2: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Persist the result.
|
|
|
|
|
|
|
|
|
|
newRoot, err := store.Put(ctx, &types.StateRoot{
|
|
|
|
|
Version: types.StateTreeVersion2,
|
|
|
|
|
Actors: newHamtRoot,
|
|
|
|
|
Info: stateRoot.Info,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return cid.Undef, xerrors.Errorf("failed to persist new state root: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check the result.
|
|
|
|
|
|
|
|
|
|
// perform some basic sanity checks to make sure everything still works.
|
|
|
|
|
if newSm, err := state.LoadStateTree(store, newRoot); err != nil {
|
|
|
|
|
return cid.Undef, xerrors.Errorf("state tree sanity load failed: %w", err)
|
|
|
|
|
} else if newRoot2, err := newSm.Flush(ctx); err != nil {
|
|
|
|
|
return cid.Undef, xerrors.Errorf("state tree sanity flush failed: %w", err)
|
|
|
|
|
} else if newRoot2 != newRoot {
|
|
|
|
|
return cid.Undef, xerrors.Errorf("state-root mismatch: %s != %s", newRoot, newRoot2)
|
|
|
|
|
} else if _, err := newSm.GetActor(init_.Address); err != nil {
|
|
|
|
|
return cid.Undef, xerrors.Errorf("failed to load init actor after upgrade: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Persist the new tree.
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
from := buf
|
|
|
|
|
to := buf.Read()
|
|
|
|
|
|
|
|
|
|
if err := vm.Copy(ctx, from, to, newRoot); err != nil {
|
|
|
|
|
return cid.Undef, xerrors.Errorf("copying migrated tree: %w", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newRoot, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func setNetworkName(ctx context.Context, store adt.Store, tree *state.StateTree, name string) error {
|
|
|
|
|
ia, err := tree.GetActor(builtin0.InitActorAddr)
|
|
|
|
|
if err != nil {
|
|
|
|
|