Skip to content

Commit

Permalink
calibnet patch: check whether network is calibration from init actor …
Browse files Browse the repository at this point in the history
…state
  • Loading branch information
arajasek committed Oct 31, 2023
1 parent ccb96b7 commit 2c2c7c8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions chain/actors/builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/filecoin-project/lotus/chain/actors"
)

var InitActorAddr = builtin.InitActorAddr
var SystemActorAddr = builtin.SystemActorAddr
var BurntFundsActorAddr = builtin.BurntFundsActorAddr
var CronActorAddr = builtin.CronActorAddr
Expand Down
1 change: 1 addition & 0 deletions chain/actors/builtin/builtin.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
smoothingtypes "github.com/filecoin-project/go-state-types/builtin/v8/util/smoothing"
)

var InitActorAddr = builtin.InitActorAddr
var SystemActorAddr = builtin.SystemActorAddr
var BurntFundsActorAddr = builtin.BurntFundsActorAddr
var CronActorAddr = builtin.CronActorAddr
Expand Down
29 changes: 23 additions & 6 deletions chain/consensus/filcns/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"strconv"
"time"

system11 "github.com/filecoin-project/go-state-types/builtin/v11/system"

"github.com/docker/go-units"
"github.com/ipfs/go-cid"
cbor "github.com/ipfs/go-ipld-cbor"
Expand All @@ -22,7 +20,9 @@ import (
actorstypes "github.com/filecoin-project/go-state-types/actors"
"github.com/filecoin-project/go-state-types/big"
nv18 "github.com/filecoin-project/go-state-types/builtin/v10/migration"
init11 "github.com/filecoin-project/go-state-types/builtin/v11/init"
nv19 "github.com/filecoin-project/go-state-types/builtin/v11/migration"
system11 "github.com/filecoin-project/go-state-types/builtin/v11/system"
nv21 "github.com/filecoin-project/go-state-types/builtin/v12/migration"
nv17 "github.com/filecoin-project/go-state-types/builtin/v9/migration"
"github.com/filecoin-project/go-state-types/manifest"
Expand Down Expand Up @@ -1901,10 +1901,26 @@ func upgradeActorsV12Common(
)
}

isCalibrationnet := true
// check whether or not this is a calibnet upgrade
// we do this because calibnet upgraded to a "wrong" actors bundle, which was then corrected
// we thus upgrade to calibrationnet-buggy in this upgrade
actorsIn, err := state.LoadStateTree(adtStore, root)
if err != nil {
return cid.Undef, xerrors.Errorf("loading state tree: %w", err)
}

initActor, err := actorsIn.GetActor(builtin.InitActorAddr)
if err != nil {
return cid.Undef, xerrors.Errorf("failed to get system actor: %w", err)
}

var initState init11.State
if err := adtStore.Get(ctx, initActor.Head, &initState); err != nil {
return cid.Undef, xerrors.Errorf("failed to get system actor state: %w", err)
}

var manifestCid cid.Cid
// TODO: check calibrationnet-ness by looking at init actor state
if isCalibrationnet {
if initState.NetworkName == "calibrationnet" {
embedded, ok := build.GetEmbeddedBuiltinActorsBundle(actorstypes.Version12, "calibrationnet-buggy")
if !ok {
return cid.Undef, xerrors.Errorf("didn't find buggy calibrationnet bundle")
Expand All @@ -1913,7 +1929,7 @@ func upgradeActorsV12Common(
var err error
manifestCid, err = bundle.LoadBundle(ctx, writeStore, bytes.NewReader(embedded))
if err != nil {
return cid.Undef, xerrors.Errorf("failed to load buggy calibnet bundle: %w")
return cid.Undef, xerrors.Errorf("failed to load buggy calibnet bundle: %w", err)
}

expectedCid := cid.MustParse("bafy2bzacedrunxfqta5skb7q7x32lnp4efz2oq7fn226ffm7fu5iqs62jkmvs")
Expand Down Expand Up @@ -2009,6 +2025,7 @@ func upgradeActorsV12Fix(ctx context.Context, sm *stmgr.StateManager, cache stmg
return cid.Undef, xerrors.Errorf("missing manifest entry for %s", oldEntry.Name)
}

// Note: we expect newCID to be the same as oldEntry.Code for all actors except the miner actor
codeMapping[oldEntry.Code] = newCID
}

Expand Down

0 comments on commit 2c2c7c8

Please sign in to comment.