Skip to content

Commit

Permalink
feat: build: remove the bundle.toml file
Browse files Browse the repository at this point in the history
Instead, we override bundles using environment variables and overrides
in the build parameter files.
  • Loading branch information
Stebalien committed Jun 10, 2022
1 parent e2c7407 commit 8d927ed
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 133 deletions.
59 changes: 0 additions & 59 deletions build/README-bundle.md

This file was deleted.

88 changes: 24 additions & 64 deletions build/builtin_actors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package build

import (
"archive/tar"
"bytes"
"context"
"embed"
"fmt"
Expand All @@ -13,7 +12,6 @@ import (
"strconv"
"strings"

"github.com/BurntSushi/toml"
"github.com/filecoin-project/lotus/blockstore"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/adt"
Expand All @@ -25,49 +23,19 @@ import (
"golang.org/x/xerrors"
)

var BuiltinActorReleases map[actors.Version]Bundle

type BundleSpec struct {
Bundles []Bundle
}

type Bundle struct {
// Version is the actors version in this bundle
Version actors.Version
// Path is the (optional) bundle path; takes precedence over builtin bundles.
Path map[string]string
}

// GetPathOverride returns a bundle path that should override any builtin bundles. If the
// `LOTUS_BUILTIN_ACTORS_VN_BUNDLE` is set for the appropriate actors version, that path will be
// returned instead.
func (bd *Bundle) GetPathOverride(network string) (string, bool) {
envvar := fmt.Sprintf("LOTUS_BUILTIN_ACTORS_V%d_BUNDLE", bd.Version)
if path := os.Getenv(envvar); path != "" {
return path, true
} else if path := bd.Path[network]; path != "" {
return path, true
} else {
return "", false
}
}

//go:embed bundles.toml
var builtinActorBundles []byte

//go:embed actors/*.tar.zst
var embeddedBuiltinActorReleases embed.FS

func init() {
var spec BundleSpec
if _, err := toml.NewDecoder(bytes.NewReader(builtinActorBundles)).Decode(&spec); err != nil {
panic(err)
if BundleOverrides == nil {
BundleOverrides = make(map[actors.Version]string)
}

BuiltinActorReleases = make(map[actors.Version]Bundle, len(spec.Bundles))

for _, bundle := range spec.Bundles {
BuiltinActorReleases[bundle.Version] = bundle
for _, av := range actors.Versions {
path := os.Getenv(fmt.Sprintf("LOTUS_BUILTIN_ACTORS_V%d_BUNDLE", av))
if path == "" {
continue
}
BundleOverrides[actors.Version(av)] = path
}
if err := loadManifests(NetworkBundle); err != nil {
panic(err)
Expand All @@ -87,42 +55,34 @@ func UseNetworkBundle(netw string) error {
}

func loadManifests(netw string) error {
embedded := make(map[actors.Version]struct{})
newMetadata := make([]*BuiltinActorsMetadata, 0, len(BuiltinActorReleases))
// First, prefer external bundles and overrides.
for av, bd := range BuiltinActorReleases {
if path, ok := bd.GetPathOverride(netw); ok {
root, actorCids, err := readBundleManifestFromFile(path)
if err != nil {
return err
}
newMetadata = append(newMetadata, &BuiltinActorsMetadata{
Network: netw,
Version: av,
ManifestCid: root,
Actors: actorCids,
})
} else {
embedded[av] = struct{}{}
overridden := make(map[actors.Version]struct{})
var newMetadata []*BuiltinActorsMetadata
// First, prefer overrides.
for av, path := range BundleOverrides {
root, actorCids, err := readBundleManifestFromFile(path)
if err != nil {
return err
}
newMetadata = append(newMetadata, &BuiltinActorsMetadata{
Network: netw,
Version: av,
ManifestCid: root,
Actors: actorCids,
})
overridden[av] = struct{}{}
}

// Then fallback on embedded bundles
// Then load embedded bundle metadata.
for _, meta := range EmbeddedBuiltinActorsMetadata {
if meta.Network != netw {
continue
}
if _, ok := embedded[meta.Version]; !ok {
if _, ok := overridden[meta.Version]; ok {
continue
}
delete(embedded, meta.Version)
newMetadata = append(newMetadata, meta)
}

if len(embedded) > 0 {
return xerrors.Errorf("failed to find some actor bundles: %v", embedded)
}

actors.ClearManifests()

for _, meta := range newMetadata {
Expand Down
2 changes: 0 additions & 2 deletions build/bundles.toml

This file was deleted.

3 changes: 3 additions & 0 deletions build/params_2k.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ 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"
)

const BootstrappersFile = ""
const GenesisFile = ""

var NetworkBundle = "devnet"
var BundleOverrides map[actors.Version]string

const GenesisNetworkVersion = network.Version16

Expand Down
1 change: 1 addition & 0 deletions build/params_butterfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var DrandSchedule = map[abi.ChainEpoch]DrandEnum{
const GenesisNetworkVersion = network.Version14

var NetworkBundle = "butterflynet"
var BundleOverrides map[actors.Version]string

const BootstrappersFile = "butterflynet.pi"
const GenesisFile = "butterflynet.car"
Expand Down
1 change: 1 addition & 0 deletions build/params_calibnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var DrandSchedule = map[abi.ChainEpoch]DrandEnum{
const GenesisNetworkVersion = network.Version0

var NetworkBundle = "calibrationnet"
var BundleOverrides map[actors.Version]string

const BootstrappersFile = "calibnet.pi"
const GenesisFile = "calibnet.car"
Expand Down
1 change: 1 addition & 0 deletions build/params_interop.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
)

var NetworkBundle = "caterpillarnet"
var BundleOverrides map[actors.Version]string

const BootstrappersFile = "interopnet.pi"
const GenesisFile = "interopnet.car"
Expand Down
2 changes: 2 additions & 0 deletions build/params_mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"

"github.com/filecoin-project/go-state-types/network"
"github.com/filecoin-project/lotus/chain/actors"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
Expand All @@ -20,6 +21,7 @@ var DrandSchedule = map[abi.ChainEpoch]DrandEnum{
}

var NetworkBundle = "mainnet"
var BundleOverrides map[actors.Version]string

const GenesisNetworkVersion = network.Version0

Expand Down
1 change: 1 addition & 0 deletions build/params_testground.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ var (

GenesisNetworkVersion = network.Version0
NetworkBundle = "devnet"
BundleOverrides map[actors.Version]string

NewestNetworkVersion = network.Version15
ActorUpgradeNetworkVersion = network.Version15
Expand Down
9 changes: 1 addition & 8 deletions node/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ func LoadBundle(ctx context.Context, bs blockstore.Blockstore, r io.Reader) (cid
// LoadBundles loads the bundles for the specified actor versions into the passed blockstore, if and
// only if the bundle's manifest is not already present in the blockstore.
func LoadBundles(ctx context.Context, bs blockstore.Blockstore, versions ...actors.Version) error {
netw := build.NetworkBundle

for _, av := range versions {
// No bundles before version 8.
if av < actors.Version8 {
Expand All @@ -63,16 +61,11 @@ func LoadBundles(ctx context.Context, bs blockstore.Blockstore, versions ...acto
continue
}

bd, ok := build.BuiltinActorReleases[av]
if !ok {
return xerrors.Errorf("unknown actors version %d", av)
}

var (
root cid.Cid
err error
)
if path, ok := bd.GetPathOverride(netw); ok {
if path, ok := build.BundleOverrides[av]; ok {
root, err = LoadBundleFromFile(ctx, bs, path)
} else if embedded, ok := build.GetEmbeddedBuiltinActorsBundle(av); ok {
root, err = LoadBundle(ctx, bs, bytes.NewReader(embedded))
Expand Down

0 comments on commit 8d927ed

Please sign in to comment.