lotus/gen/bundle/bundle.go
Steven Allen ddc9425c07 feat: refactor: actor bundling system (#8838)
1. Include the builtin-actors in the lotus source tree.
2. Embed the bundle on build instead of downloading at runtime.
3. Avoid reading the bundle whenever possible by including bundle
   metadata (the bundle CID, the actor CIDs, etc.).
4. Remove everything related to dependency injection.
    1. We're no longer downloading the bundle, so doing anything ahead
       of time doesn't really help.
    2. We register the manifests on init because, unfortunately, they're
       global.
    3. We explicitly load the current actors bundle in the genesis
       state-tree method.
    4. For testing, we just change the in-use bundle with a bit of a
       hack. It's not great, but using dependency injection doesn't make
       any sense either because, again, the manifest information is
       global.
    5. Remove the bundle.toml file. Bundles may be overridden by
       specifying an override path in the parameters file, or an
       environment variable.

fixes #8701
2022-06-13 10:51:49 -07:00

51 lines
966 B
Go

package main
import (
"os"
"text/template"
"github.com/filecoin-project/lotus/build"
)
var tmpl *template.Template = template.Must(template.New("actor-metadata").Parse(`
// WARNING: This file has automatically been generated
package build
import (
"github.com/ipfs/go-cid"
)
var EmbeddedBuiltinActorsMetadata []*BuiltinActorsMetadata = []*BuiltinActorsMetadata{
{{- range . }} {
Network: {{printf "%q" .Network}},
Version: {{.Version}},
ManifestCid: MustParseCid({{printf "%q" .ManifestCid}}),
Actors: map[string]cid.Cid {
{{- range $name, $cid := .Actors }}
{{printf "%q" $name}}: MustParseCid({{printf "%q" $cid}}),
{{- end }}
},
},
{{- end -}}
}
`))
func main() {
metadata, err := build.ReadEmbeddedBuiltinActorsMetadata()
if err != nil {
panic(err)
}
fi, err := os.Create("./build/builtin_actors_gen.go")
if err != nil {
panic(err)
}
defer fi.Close() //nolint
err = tmpl.Execute(fi, metadata)
if err != nil {
panic(err)
}
}