From 30e7f896628743a74bdf8812294bafe47074fac9 Mon Sep 17 00:00:00 2001 From: Geoff Stuart Date: Thu, 26 May 2022 15:14:29 -0400 Subject: [PATCH] Check for manifest CID while loading bundle --- build/params_2k.go | 3 ++ build/params_butterfly.go | 3 ++ build/params_calibnet.go | 3 ++ build/params_interop.go | 6 +++ build/params_mainnet.go | 9 +++- build/params_nerpanet.go | 87 ------------------------------ build/params_testground.go | 3 ++ chain/actors/manifest.go | 22 +------- chain/consensus/filcns/upgrades.go | 8 ++- cmd/lotus-shed/cid.go | 46 ++++++++++++++++ node/bundle/manifest.go | 20 ++++++- node/modules/builtin_actors.go | 5 ++ 12 files changed, 102 insertions(+), 113 deletions(-) delete mode 100644 build/params_nerpanet.go diff --git a/build/params_2k.go b/build/params_2k.go index c00e46f25..a0ceb8fff 100644 --- a/build/params_2k.go +++ b/build/params_2k.go @@ -11,6 +11,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/policy" ) @@ -52,6 +53,8 @@ var UpgradeChocolateHeight = abi.ChainEpoch(-17) var UpgradeOhSnapHeight = abi.ChainEpoch(-18) var UpgradeFVM1Height = abi.ChainEpoch(-19) +var ActorsCIDs = map[actors.Version]cid.Cid{} + var DrandSchedule = map[abi.ChainEpoch]DrandEnum{ 0: DrandMainnet, } diff --git a/build/params_butterfly.go b/build/params_butterfly.go index 1873a9f1e..741e57a2c 100644 --- a/build/params_butterfly.go +++ b/build/params_butterfly.go @@ -7,6 +7,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/policy" builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" "github.com/ipfs/go-cid" @@ -48,6 +49,8 @@ const UpgradeOhSnapHeight = 240 var UpgradeFVM1Height = abi.ChainEpoch(99999999999999) +var ActorsCIDs = map[actors.Version]cid.Cid{} + func init() { policy.SetConsensusMinerMinPower(abi.NewStoragePower(2 << 30)) policy.SetSupportedProofTypes( diff --git a/build/params_calibnet.go b/build/params_calibnet.go index 3214cdbc6..cdd4b2b69 100644 --- a/build/params_calibnet.go +++ b/build/params_calibnet.go @@ -7,6 +7,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/policy" builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" "github.com/ipfs/go-cid" @@ -61,6 +62,8 @@ const UpgradeOhSnapHeight = 682006 var UpgradeFVM1Height = abi.ChainEpoch(99999999999999) +var ActorsCIDs = map[actors.Version]cid.Cid{} + func init() { policy.SetConsensusMinerMinPower(abi.NewStoragePower(32 << 30)) policy.SetSupportedProofTypes( diff --git a/build/params_interop.go b/build/params_interop.go index ae2101bfd..dfe22559b 100644 --- a/build/params_interop.go +++ b/build/params_interop.go @@ -7,6 +7,8 @@ import ( "os" "strconv" + "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/network" @@ -51,6 +53,10 @@ var UpgradeChocolateHeight = abi.ChainEpoch(-17) var UpgradeOhSnapHeight = abi.ChainEpoch(-18) var UpgradeFVM1Height = abi.ChainEpoch(100) +var ActorsCIDs = map[actors.Version]cid.Cid{ + actors.Version8: MustParseCid("bafy2bzaceadr77tamp35bbb3rtio4ver4pnk2cbxqif3nn3mrmxra2nlvwoce"), +} + var DrandSchedule = map[abi.ChainEpoch]DrandEnum{ 0: DrandMainnet, } diff --git a/build/params_mainnet.go b/build/params_mainnet.go index 0bae512d7..085ac4713 100644 --- a/build/params_mainnet.go +++ b/build/params_mainnet.go @@ -1,5 +1,5 @@ -//go:build !debug && !2k && !testground && !calibnet && !nerpanet && !butterflynet && !interopnet -// +build !debug,!2k,!testground,!calibnet,!nerpanet,!butterflynet,!interopnet +//go:build !debug && !2k && !testground && !calibnet && !butterflynet && !interopnet +// +build !debug,!2k,!testground,!calibnet,!butterflynet,!interopnet package build @@ -7,6 +7,9 @@ import ( "math" "os" + "github.com/filecoin-project/lotus/chain/actors" + "github.com/ipfs/go-cid" + "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/go-address" @@ -74,6 +77,8 @@ var UpgradeOhSnapHeight = abi.ChainEpoch(1594680) var UpgradeFVM1Height = abi.ChainEpoch(99999999999999) +var ActorsCIDs = map[actors.Version]cid.Cid{} + func init() { if os.Getenv("LOTUS_USE_TEST_ADDRESSES") != "1" { SetAddressNetwork(address.Mainnet) diff --git a/build/params_nerpanet.go b/build/params_nerpanet.go deleted file mode 100644 index 0e2913adc..000000000 --- a/build/params_nerpanet.go +++ /dev/null @@ -1,87 +0,0 @@ -//go:build nerpanet -// +build nerpanet - -package build - -import ( - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/network" - "github.com/filecoin-project/lotus/chain/actors/policy" - "github.com/ipfs/go-cid" - - builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" -) - -var DrandSchedule = map[abi.ChainEpoch]DrandEnum{ - 0: DrandMainnet, -} - -const GenesisNetworkVersion = network.Version0 - -const BootstrappersFile = "nerpanet.pi" -const GenesisFile = "nerpanet.car" - -const UpgradeBreezeHeight = -1 -const BreezeGasTampingDuration = 0 - -const UpgradeSmokeHeight = -1 - -const UpgradeIgnitionHeight = -2 -const UpgradeRefuelHeight = -3 - -const UpgradeLiftoffHeight = -5 - -const UpgradeAssemblyHeight = 30 // critical: the network can bootstrap from v1 only -const UpgradeTapeHeight = 60 - -const UpgradeKumquatHeight = 90 - -const UpgradeCalicoHeight = 100 -const UpgradePersianHeight = UpgradeCalicoHeight + (builtin2.EpochsInHour * 1) - -const UpgradeClausHeight = 250 - -const UpgradeOrangeHeight = 300 - -const UpgradeTrustHeight = 600 -const UpgradeNorwegianHeight = 201000 -const UpgradeTurboHeight = 203000 -const UpgradeHyperdriveHeight = 379178 - -const UpgradeChocolateHeight = 999999999 - -func init() { - // Minimum block production power is set to 4 TiB - // Rationale is to discourage small-scale miners from trying to take over the network - // One needs to invest in ~2.3x the compute to break consensus, making it not worth it - // - // DOWNSIDE: the fake-seals need to be kept alive/protected, otherwise network will seize - // - policy.SetConsensusMinerMinPower(abi.NewStoragePower(4 << 40)) - - policy.SetSupportedProofTypes( - abi.RegisteredSealProof_StackedDrg512MiBV1, - abi.RegisteredSealProof_StackedDrg32GiBV1, - abi.RegisteredSealProof_StackedDrg64GiBV1, - ) - - // Lower the most time-consuming parts of PoRep - policy.SetPreCommitChallengeDelay(10) - - // TODO - make this a variable - //miner.WPoStChallengeLookback = abi.ChainEpoch(2) - - Devnet = false - - BuildType = BuildNerpanet - -} - -const BlockDelaySecs = uint64(builtin2.EpochDurationSeconds) - -const PropagationDelaySecs = uint64(6) - -// BootstrapPeerThreshold is the minimum number peers we need to track for a sync worker to start -const BootstrapPeerThreshold = 4 - -var WhitelistedBlock = cid.Undef diff --git a/build/params_testground.go b/build/params_testground.go index d10063bd2..2d824bb44 100644 --- a/build/params_testground.go +++ b/build/params_testground.go @@ -17,6 +17,7 @@ import ( builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/policy" ) @@ -121,3 +122,5 @@ var ( ) const BootstrapPeerThreshold = 1 + +var ActorsCIDs = map[actors.Version]cid.Cid{} diff --git a/chain/actors/manifest.go b/chain/actors/manifest.go index 2276ee3e4..984c3f1f6 100644 --- a/chain/actors/manifest.go +++ b/chain/actors/manifest.go @@ -1,7 +1,6 @@ package actors import ( - "bytes" "context" "strings" "sync" @@ -10,12 +9,9 @@ import ( "golang.org/x/xerrors" + "github.com/filecoin-project/lotus/chain/actors/adt" cid "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" - car "github.com/ipld/go-car" - - "github.com/filecoin-project/lotus/blockstore" - "github.com/filecoin-project/lotus/chain/actors/adt" ) var manifestCids map[Version]cid.Cid @@ -144,19 +140,3 @@ func CanonicalName(name string) string { return name } - -func LoadBundle(ctx context.Context, bs blockstore.Blockstore, av Version, data []byte) error { - blobr := bytes.NewReader(data) - - hdr, err := car.LoadCar(ctx, bs, blobr) - if err != nil { - return xerrors.Errorf("error loading builtin actors v%d bundle: %w", av, err) - } - - // TODO: check that this only has one root? - - manifestCid := hdr.Roots[0] - AddManifest(av, manifestCid) - - return nil -} diff --git a/chain/consensus/filcns/upgrades.go b/chain/consensus/filcns/upgrades.go index f21a448ef..233cbeecd 100644 --- a/chain/consensus/filcns/upgrades.go +++ b/chain/consensus/filcns/upgrades.go @@ -1370,7 +1370,7 @@ func upgradeActorsV8Common( buf := blockstore.NewTieredBstore(sm.ChainStore().StateBlockstore(), blockstore.NewMemorySync()) store := store.ActorStore(ctx, buf) - // ensure that the manifet is loaded in the blockstore + // ensure that the manifest is loaded in the blockstore if err := bundle.FetchAndLoadBundles(ctx, buf, map[actors.Version]build.Bundle{ actors.Version8: build.BuiltinActorReleases[actors.Version8], }); err != nil { @@ -1395,6 +1395,12 @@ func upgradeActorsV8Common( return cid.Undef, xerrors.Errorf("no manifest CID for v8 upgrade") } + if val, ok := build.ActorsCIDs[actors.Version8]; ok { + if val != manifest { + return cid.Undef, xerrors.Errorf("actors V8 manifest CID %s did not match CID given in params file: %s", manifest, val) + } + } + // Perform the migration newHamtRoot, err := nv16.MigrateStateTree(ctx, store, manifest, stateRoot.Actors, epoch, config, migrationLogger{}, cache) if err != nil { diff --git a/cmd/lotus-shed/cid.go b/cmd/lotus-shed/cid.go index 09f3d6e6f..8ade74607 100644 --- a/cmd/lotus-shed/cid.go +++ b/cmd/lotus-shed/cid.go @@ -1,9 +1,16 @@ package main import ( + "bytes" "encoding/base64" "encoding/hex" "fmt" + "io" + "os" + + "github.com/filecoin-project/lotus/blockstore" + "github.com/ipld/go-car" + "golang.org/x/net/context" "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" @@ -17,6 +24,7 @@ var cidCmd = &cli.Command{ Usage: "Cid command", Subcommands: cli.Commands{ cidIdCmd, + cidFromCarCmd, }, } @@ -83,3 +91,41 @@ var cidIdCmd = &cli.Command{ return nil }, } + +var cidFromCarCmd = &cli.Command{ + Name: "manifest-cid-from-car", + Usage: "Get the manifest CID from a car file", + ArgsUsage: "[path]", + Action: func(cctx *cli.Context) error { + ctx := context.TODO() + + cf := cctx.Args().Get(0) + f, err := os.OpenFile(cf, os.O_RDONLY, 0664) + if err != nil { + return xerrors.Errorf("opening the car file: %w", err) + } + + bs := blockstore.NewMemory() + if err != nil { + return err + } + + data, err := io.ReadAll(f) + if err != nil { + return xerrors.Errorf("error reading car file: %w", err) + } + + blobr := bytes.NewReader(data) + + hdr, err := car.LoadCar(ctx, bs, blobr) + if err != nil { + return xerrors.Errorf("error loading car file: %w", err) + } + + manifestCid := hdr.Roots[0] + + fmt.Printf("Manifest CID: %s\n", manifestCid.String()) + + return nil + }, +} diff --git a/node/bundle/manifest.go b/node/bundle/manifest.go index a0c0cab93..c514c9eb4 100644 --- a/node/bundle/manifest.go +++ b/node/bundle/manifest.go @@ -1,11 +1,14 @@ package bundle import ( + "bytes" "context" "fmt" "io" "os" + "github.com/ipld/go-car" + "golang.org/x/xerrors" "github.com/filecoin-project/lotus/blockstore" @@ -58,10 +61,23 @@ func LoadBundle(ctx context.Context, bs blockstore.Blockstore, path string, av a return cid.Undef, xerrors.Errorf("error reading bundle for builtin-actors version %d: %w", av, err) } - if err := actors.LoadBundle(ctx, bs, av, data); err != nil { - return cid.Undef, xerrors.Errorf("error loading bundle for builtin-actors version %d: %w", av, err) + blobr := bytes.NewReader(data) + + hdr, err := car.LoadCar(ctx, bs, blobr) + if err != nil { + return cid.Undef, xerrors.Errorf("error loading builtin actors v%d bundle: %w", av, err) } + // TODO: check that this only has one root? + manifestCid := hdr.Roots[0] + + if val, ok := build.ActorsCIDs[av]; ok { + if val != manifestCid { + return cid.Undef, xerrors.Errorf("actors V%d manifest CID %s did not match CID given in params file: %s", av, manifestCid, val) + } + } + actors.AddManifest(av, manifestCid) + mfCid, ok := actors.GetManifest(av) if !ok { return cid.Undef, xerrors.Errorf("missing manifest CID for builtin-actors vrsion %d", av) diff --git a/node/modules/builtin_actors.go b/node/modules/builtin_actors.go index d5b7295c7..474619c05 100644 --- a/node/modules/builtin_actors.go +++ b/node/modules/builtin_actors.go @@ -48,6 +48,11 @@ func LoadBuiltinActors(lc fx.Lifecycle, mctx helpers.MetricsCtx, r repo.LockedRe if has { // it's there, no need to reload the bundle to the blockstore; just add it to the manifest list. + if val, ok := build.ActorsCIDs[av]; ok { + if val != mfCid { + return result, xerrors.Errorf("actors V%d manifest CID %s did not match CID given in params file: %s", av, mfCid, val) + } + } actors.AddManifest(av, mfCid) continue }