Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move venus-shared/builtin-actors to venus-shared/actors #5134

Merged
merged 2 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test-venus-shared:
cd venus-shared && go test -covermode=set ./...

bundle-gen:
cd venus-devtool && go run ./bundle-gen/*.go --dst ./../venus-shared/builtin-actors/builtin_actors_gen.go
cd venus-devtool && go run ./bundle-gen/*.go --dst ./../venus-shared/actors/builtin_actors_gen.go

api-gen:
cd ./venus-devtool/ && go run ./api-gen/ proxy
Expand Down
6 changes: 3 additions & 3 deletions cmd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/filecoin-project/venus/fixtures/assets"
"github.com/filecoin-project/venus/fixtures/networks"
builtinactors "github.com/filecoin-project/venus/venus-shared/builtin-actors"
"github.com/filecoin-project/venus/venus-shared/actors"
"github.com/filecoin-project/venus/venus-shared/utils"

"github.com/filecoin-project/venus/pkg/constants"
Expand Down Expand Up @@ -141,7 +141,7 @@ func initRun(req *cmds.Request) error {
}

node.SetNetParams(cfg.NetworkParams)
if err := builtinactors.SetNetworkBundle(cfg.NetworkParams.NetworkType); err != nil {
if err := actors.SetNetworkBundle(int(cfg.NetworkParams.NetworkType)); err != nil {
return err
}
utils.ReloadMethodsMap()
Expand Down Expand Up @@ -180,7 +180,7 @@ func daemonRun(req *cmds.Request, re cmds.ResponseEmitter) error {

config := rep.Config()

if err := builtinactors.SetNetworkBundle(config.NetworkParams.NetworkType); err != nil {
if err := actors.SetNetworkBundle(int(config.NetworkParams.NetworkType)); err != nil {
return err
}
utils.ReloadMethodsMap()
Expand Down
5 changes: 2 additions & 3 deletions pkg/fork/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ import (
init_ "github.com/filecoin-project/venus/venus-shared/actors/builtin/init"
"github.com/filecoin-project/venus/venus-shared/actors/builtin/multisig"
"github.com/filecoin-project/venus/venus-shared/actors/builtin/system"
builtinactors "github.com/filecoin-project/venus/venus-shared/builtin-actors"
"github.com/filecoin-project/venus/venus-shared/types"
)

Expand Down Expand Up @@ -2082,7 +2081,7 @@ func (c *ChainFork) upgradeActorsV8Common(
store := chain.ActorStore(ctx, buf)

// ensure that the manifest is loaded in the blockstore
if err := builtinactors.LoadBundles(ctx, buf, actors.Version8); err != nil {
if err := actors.LoadBundles(ctx, buf, actors.Version8); err != nil {
return cid.Undef, fmt.Errorf("failed to load manifest bundle: %w", err)
}

Expand Down Expand Up @@ -2153,7 +2152,7 @@ func (c *ChainFork) GetForkUpgrade() *config.ForkUpgradeConfig {
// newStateTreeVersion := vmstate.StateTreeVersion4

// // ensure that the manifest is loaded in the blockstore
// if err := builtinactors.LoadBundles(ctx, buf, actors.Version9); err != nil {
// if err := actors.LoadBundles(ctx, buf, actors.Version9); err != nil {
// return cid.Undef, fmt.Errorf("failed to load manifest bundle: %w", err)
// }

Expand Down
3 changes: 1 addition & 2 deletions pkg/gen/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/filecoin-project/venus/pkg/fvm"
"github.com/filecoin-project/venus/pkg/util/ffiwrapper/impl"
"github.com/filecoin-project/venus/pkg/vmsupport"
builtinactors "github.com/filecoin-project/venus/venus-shared/builtin-actors"
"github.com/filecoin-project/venus/venus-shared/types"

"github.com/filecoin-project/venus/pkg/config"
Expand Down Expand Up @@ -161,7 +160,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template Te
return nil, nil, fmt.Errorf("get actor version: %w", err)
}

if err := builtinactors.LoadBundles(ctx, bs, av); err != nil {
if err := actors.LoadBundles(ctx, bs, av); err != nil {
return nil, nil, fmt.Errorf("loading actors for genesis block: %w", err)
}
// Create system actor
Expand Down
20 changes: 14 additions & 6 deletions venus-devtool/bundle-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/urfave/cli/v2"

"github.com/filecoin-project/venus/venus-devtool/util"
builtinactors "github.com/filecoin-project/venus/venus-shared/builtin-actors"
"github.com/filecoin-project/venus/venus-shared/actors"
)

func main() {
Expand All @@ -22,7 +22,7 @@ func main() {
},
Action: func(ctx *cli.Context) error {

metadata, err := builtinactors.ReadEmbeddedBuiltinActorsMetadata()
metadata, err := actors.ReadEmbeddedBuiltinActorsMetadata()
if err != nil {
return err
}
Expand Down Expand Up @@ -50,22 +50,30 @@ func main() {

var tmpl *template.Template = template.Must(template.New("actor-metadata").Parse(`
// WARNING: This file has automatically been generated
package builtinactors
package actors
import (
"github.com/filecoin-project/venus/venus-shared/types"
"github.com/ipfs/go-cid"
)
var EmbeddedBuiltinActorsMetadata []*BuiltinActorsMetadata = []*BuiltinActorsMetadata{
{{- range . }} {
Network: {{printf "%q" .Network}},
Version: {{.Version}},
ManifestCid: types.MustParseCid({{printf "%q" .ManifestCid}}),
ManifestCid: mustParseCid({{printf "%q" .ManifestCid}}),
Actors: map[string]cid.Cid {
{{- range $name, $cid := .Actors }}
{{printf "%q" $name}}: types.MustParseCid({{printf "%q" $cid}}),
{{printf "%q" $name}}: mustParseCid({{printf "%q" $cid}}),
{{- end }}
},
},
{{- end -}}
}

func mustParseCid(c string) cid.Cid {
ret, err := cid.Decode(c)
if err != nil {
panic(err)
}

return ret
}
`))
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package builtinactors
package actors

import (
"archive/tar"
Expand All @@ -18,46 +18,55 @@ import (
"github.com/ipld/go-car"

"github.com/filecoin-project/venus/pkg/util/blockstoreutil"
"github.com/filecoin-project/venus/venus-shared/actors"
"github.com/filecoin-project/venus/venus-shared/actors/adt"
"github.com/filecoin-project/venus/venus-shared/types"
)

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

// NOTE: DO NOT change this unless you REALLY know what you're doing. This is consensus critical.
var BundleOverrides map[actors.Version]string
var BundleOverrides map[Version]string

var NetworkBundle = "mainnet"

func init() {
if BundleOverrides == nil {
BundleOverrides = make(map[actors.Version]string)
BundleOverrides = make(map[Version]string)
}

for _, av := range actors.Versions {
for _, av := range Versions {
path := os.Getenv(fmt.Sprintf("VENUS_BUILTIN_ACTORS_V%d_BUNDLE", av))
if path == "" {
continue
}
BundleOverrides[actors.Version(av)] = path
BundleOverrides[Version(av)] = path
}
if err := loadManifests(NetworkBundle); err != nil {
panic(err)
}
}

func SetNetworkBundle(networkType types.NetworkType) error {
// NetworkMainnet NetworkType = 0x1
// Network2k NetworkType = 0x2
// NetworkCalibnet NetworkType = 0x4
// NetworkInterop NetworkType = 0x6
// NetworkForce NetworkType = 0x7
// NetworkButterfly NetworkType = 0x8
// Avoid import cycle, we use concrete values
func SetNetworkBundle(networkType int) error {
networkBundle := ""
switch networkType {
case types.Network2k, types.NetworkForce:
// case types.Network2k, types.NetworkForce:
case 0x2, 0x7:
networkBundle = "devnet"
case types.NetworkButterfly:
// case types.NetworkButterfly:
case 0x8:
networkBundle = "butterflynet"
case types.NetworkInterop:
// case types.NetworkInterop:
case 0x6:
networkBundle = "caterpillarnet"
case types.NetworkCalibnet:
// case types.NetworkCalibnet:
case 0x4:
networkBundle = "calibrationnet"
default:
networkBundle = "mainnet"
Expand All @@ -79,7 +88,7 @@ func UseNetworkBundle(netw string) error {
}

func loadManifests(netw string) error {
overridden := make(map[actors.Version]struct{})
overridden := make(map[Version]struct{})
var newMetadata []*BuiltinActorsMetadata
// First, prefer overrides.
for av, path := range BundleOverrides {
Expand Down Expand Up @@ -107,18 +116,18 @@ func loadManifests(netw string) error {
newMetadata = append(newMetadata, meta)
}

actors.ClearManifests()
ClearManifests()

for _, meta := range newMetadata {
actors.RegisterManifest(meta.Version, meta.ManifestCid, meta.Actors)
RegisterManifest(meta.Version, meta.ManifestCid, meta.Actors)
}

return nil
}

type BuiltinActorsMetadata struct { // nolint
Network string
Version actors.Version
Version Version
ManifestCid cid.Cid
Actors map[string]cid.Cid
}
Expand All @@ -127,7 +136,7 @@ type BuiltinActorsMetadata struct { // nolint
// There should be no need to call this method as the result is cached in the
// `EmbeddedBuiltinActorsMetadata` variable on `make gen`.
func ReadEmbeddedBuiltinActorsMetadata() ([]*BuiltinActorsMetadata, error) {
files, err := embeddedBuiltinActorReleases.ReadDir("actors")
files, err := embeddedBuiltinActorReleases.ReadDir("builtin-actors-code")
if err != nil {
return nil, fmt.Errorf("failed to read embedded bundle directory: %s", err)
}
Expand Down Expand Up @@ -167,7 +176,7 @@ func readEmbeddedBuiltinActorsMetadata(bundle string) ([]*BuiltinActorsMetadata,
if err != nil {
return nil, fmt.Errorf("failed to parse actors version from bundle '%q': %s", bundle, err)
}
fi, err := embeddedBuiltinActorReleases.Open(fmt.Sprintf("actors/%s", bundle))
fi, err := embeddedBuiltinActorReleases.Open(fmt.Sprintf("builtin-actors-code/%s", bundle))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -206,7 +215,7 @@ func readEmbeddedBuiltinActorsMetadata(bundle string) ([]*BuiltinActorsMetadata,
}
bundles = append(bundles, &BuiltinActorsMetadata{
Network: name,
Version: actors.Version(version),
Version: Version(version),
ManifestCid: root,
Actors: actorCids,
})
Expand Down Expand Up @@ -235,12 +244,12 @@ func readBundleManifest(r io.Reader) (cid.Cid, map[string]cid.Cid, error) {
return cid.Undef, nil, fmt.Errorf("expected one root when loading actors bundle, got %d", len(hdr.Roots))
}
root := hdr.Roots[0]
actorCids, err := actors.ReadManifest(context.Background(), adt.WrapStore(context.Background(), cbor.NewCborStore(bs)), root)
actorCids, err := ReadManifest(context.Background(), adt.WrapStore(context.Background(), cbor.NewCborStore(bs)), root)
if err != nil {
return cid.Undef, nil, err
}

// Make sure we have all the actors.
// Make sure we have all the
for name, c := range actorCids {
if has, err := bs.Has(context.Background(), c); err != nil {
return cid.Undef, nil, fmt.Errorf("got an error when checking that the bundle has the actor %q: %w", name, err)
Expand All @@ -253,8 +262,8 @@ func readBundleManifest(r io.Reader) (cid.Cid, map[string]cid.Cid, error) {
}

// GetEmbeddedBuiltinActorsBundle returns the builtin-actors bundle for the given actors version.
func GetEmbeddedBuiltinActorsBundle(version actors.Version) ([]byte, bool) {
fi, err := embeddedBuiltinActorReleases.Open(fmt.Sprintf("actors/v%d.tar.zst", version))
func GetEmbeddedBuiltinActorsBundle(version Version) ([]byte, bool) {
fi, err := embeddedBuiltinActorReleases.Open(fmt.Sprintf("builtin-actors-code/v%d.tar.zst", version))
if err != nil {
return nil, false
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package builtinactors
package actors

import (
"bytes"
Expand All @@ -8,7 +8,6 @@ import (
"os"

blockstore "github.com/filecoin-project/venus/pkg/util/blockstoreutil"
"github.com/filecoin-project/venus/venus-shared/actors"
cid "github.com/ipfs/go-cid"
"github.com/ipld/go-car"
)
Expand Down Expand Up @@ -37,14 +36,14 @@ 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 {
func LoadBundles(ctx context.Context, bs blockstore.Blockstore, versions ...Version) error {
for _, av := range versions {
// No bundles before version 8.
if av < actors.Version8 {
if av < Version8 {
continue
}

manifestCid, ok := actors.GetManifest(av)
manifestCid, ok := GetManifest(av)
if !ok {
// All manifests are registered on start, so this must succeed.
return fmt.Errorf("unknown actor version v%d", av)
Expand Down
Loading