Added support for Filecoin network version 21 (v12 state types)
This commit includes the following updates: - Imported v12 of the filecoin state types in migrations.go. This allows the system to interpret and operate on the latest structure of filecoin state information, ensuring compatibility with the latest version of the Filecoin network. - Updated the 'getMigrationFuncsForNetwork' function to include a case for network.Version21, enabling the use of the UpgradeActorsV12 and PreUpgradeActorsV12 functions for network migration. These changes ensure the system correctly handles migrations when the network upgrades to version 21. - Implemented a new 'checkNv21Invariants' function to check the invariants for version 21 of the Filecoin network. This function: 1. Loads the new state root from the actor store. 2. Retrieves the actor code IDs for the current state version (v12). 3. Loads the actor tree from the state root and checks state invariants using the actor code IDs. 4. Logs any error messages generated during the invariant check. 5. Finally, prints a message with the time taken to complete the checks. By checking these invariants, we can ensure the system's state is consistent and valid after migrating to network version 21.
This commit is contained in:
parent
7adf8237f6
commit
1eca520076
@ -21,6 +21,7 @@ import (
|
||||
"github.com/filecoin-project/go-state-types/builtin"
|
||||
v10 "github.com/filecoin-project/go-state-types/builtin/v10"
|
||||
v11 "github.com/filecoin-project/go-state-types/builtin/v11"
|
||||
v12 "github.com/filecoin-project/go-state-types/builtin/v12"
|
||||
market8 "github.com/filecoin-project/go-state-types/builtin/v8/market"
|
||||
adt8 "github.com/filecoin-project/go-state-types/builtin/v8/util/adt"
|
||||
v9 "github.com/filecoin-project/go-state-types/builtin/v9"
|
||||
@ -243,6 +244,8 @@ func getMigrationFuncsForNetwork(nv network.Version) (UpgradeActorsFunc, PreUpgr
|
||||
return filcns.UpgradeActorsV10, filcns.PreUpgradeActorsV10, checkNv18Invariants, nil
|
||||
case network.Version19:
|
||||
return filcns.UpgradeActorsV11, filcns.PreUpgradeActorsV11, checkNv19Invariants, nil
|
||||
case network.Version21:
|
||||
return filcns.UpgradeActorsV12, filcns.PreUpgradeActorsV12, checkNv21Invariants, nil
|
||||
default:
|
||||
return nil, nil, nil, xerrors.Errorf("migration not implemented for nv%d", nv)
|
||||
}
|
||||
@ -252,6 +255,38 @@ type UpgradeActorsFunc = func(context.Context, *stmgr.StateManager, stmgr.Migrat
|
||||
type PreUpgradeActorsFunc = func(context.Context, *stmgr.StateManager, stmgr.MigrationCache, cid.Cid, abi.ChainEpoch, *types.TipSet) error
|
||||
type CheckInvariantsFunc = func(context.Context, cid.Cid, cid.Cid, blockstore.Blockstore, abi.ChainEpoch) error
|
||||
|
||||
func checkNv21Invariants(ctx context.Context, oldStateRootCid cid.Cid, newStateRootCid cid.Cid, bs blockstore.Blockstore, epoch abi.ChainEpoch) error {
|
||||
|
||||
actorStore := store.ActorStore(ctx, bs)
|
||||
startTime := time.Now()
|
||||
|
||||
// Load the new state root.
|
||||
var newStateRoot types.StateRoot
|
||||
if err := actorStore.Get(ctx, newStateRootCid, &newStateRoot); err != nil {
|
||||
return xerrors.Errorf("failed to decode state root: %w", err)
|
||||
}
|
||||
|
||||
actorCodeCids, err := actors.GetActorCodeIDs(actorstypes.Version12)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
newActorTree, err := builtin.LoadTree(actorStore, newStateRoot.Actors)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
messages, err := v12.CheckStateInvariants(newActorTree, epoch, actorCodeCids)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("checking state invariants: %w", err)
|
||||
}
|
||||
|
||||
for _, message := range messages.Messages() {
|
||||
fmt.Println("got the following error: ", message)
|
||||
}
|
||||
|
||||
fmt.Println("completed invariant checks, took ", time.Since(startTime))
|
||||
|
||||
return nil
|
||||
}
|
||||
func checkNv19Invariants(ctx context.Context, oldStateRootCid cid.Cid, newStateRootCid cid.Cid, bs blockstore.Blockstore, epoch abi.ChainEpoch) error {
|
||||
|
||||
actorStore := store.ActorStore(ctx, bs)
|
||||
|
Loading…
Reference in New Issue
Block a user