2021-04-26 14:48:20 +00:00
|
|
|
package builtin
|
|
|
|
|
|
|
|
import (
|
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 17:15:00 +00:00
|
|
|
"fmt"
|
|
|
|
|
2021-04-26 14:48:20 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
{{range .versions}}
|
2022-09-06 15:49:29 +00:00
|
|
|
{{if (le . 7)}}
|
2022-04-20 21:34:28 +00:00
|
|
|
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
|
2022-09-06 15:49:29 +00:00
|
|
|
{{end}}
|
2022-04-20 21:34:28 +00:00
|
|
|
{{end}}
|
2021-04-26 14:48:20 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2022-04-20 21:34:28 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/proof"
|
2022-05-16 23:43:06 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/builtin"
|
2022-12-13 23:02:34 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/manifest"
|
2021-04-26 14:48:20 +00:00
|
|
|
|
2022-04-04 11:23:13 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
2021-04-26 14:48:20 +00:00
|
|
|
|
2022-09-07 23:30:55 +00:00
|
|
|
minertypes "github.com/filecoin-project/go-state-types/builtin/v9/miner"
|
2022-04-20 21:34:28 +00:00
|
|
|
smoothingtypes "github.com/filecoin-project/go-state-types/builtin/v8/util/smoothing"
|
2021-04-26 14:48:20 +00:00
|
|
|
)
|
|
|
|
|
2022-05-16 23:43:06 +00:00
|
|
|
var SystemActorAddr = builtin.SystemActorAddr
|
|
|
|
var BurntFundsActorAddr = builtin.BurntFundsActorAddr
|
|
|
|
var CronActorAddr = builtin.CronActorAddr
|
2023-01-26 15:26:39 +00:00
|
|
|
var EthereumAddressManagerActorAddr = builtin.EthereumAddressManagerActorAddr
|
2021-04-26 14:48:20 +00:00
|
|
|
var SaftAddress = makeAddress("t0122")
|
|
|
|
var ReserveAddress = makeAddress("t090")
|
|
|
|
var RootVerifierAddress = makeAddress("t080")
|
|
|
|
|
|
|
|
var (
|
2022-05-16 23:43:06 +00:00
|
|
|
ExpectedLeadersPerEpoch = builtin.ExpectedLeadersPerEpoch
|
2021-04-26 14:48:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2022-05-16 23:43:06 +00:00
|
|
|
EpochDurationSeconds = builtin.EpochDurationSeconds
|
|
|
|
EpochsInDay = builtin.EpochsInDay
|
|
|
|
SecondsInDay = builtin.SecondsInDay
|
2021-04-26 14:48:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2022-05-16 23:43:06 +00:00
|
|
|
MethodSend = builtin.MethodSend
|
|
|
|
MethodConstructor = builtin.MethodConstructor
|
2021-04-26 14:48:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// These are all just type aliases across actor versions. In the future, that might change
|
|
|
|
// and we might need to do something fancier.
|
2022-04-20 21:34:28 +00:00
|
|
|
type SectorInfo = proof.SectorInfo
|
|
|
|
type ExtendedSectorInfo = proof.ExtendedSectorInfo
|
|
|
|
type PoStProof = proof.PoStProof
|
|
|
|
type FilterEstimate = smoothingtypes.FilterEstimate
|
2021-04-26 14:48:20 +00:00
|
|
|
|
|
|
|
func QAPowerForWeight(size abi.SectorSize, duration abi.ChainEpoch, dealWeight, verifiedWeight abi.DealWeight) abi.StoragePower {
|
2022-09-07 23:30:55 +00:00
|
|
|
return minertypes.QAPowerForWeight(size, duration, dealWeight, verifiedWeight)
|
2021-04-26 14:48:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func ActorNameByCode(c cid.Cid) string {
|
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 17:15:00 +00:00
|
|
|
if name, version, ok := actors.GetActorMetaByCode(c); ok {
|
|
|
|
return fmt.Sprintf("fil/%d/%s", version, name)
|
2022-04-04 11:23:13 +00:00
|
|
|
}
|
|
|
|
|
2021-04-26 14:48:20 +00:00
|
|
|
switch {
|
2022-05-15 19:26:52 +00:00
|
|
|
{{range .versions}}
|
2022-09-06 15:49:29 +00:00
|
|
|
{{if (le . 7)}}
|
2022-05-16 23:43:06 +00:00
|
|
|
case builtin{{.}}.IsBuiltinActor(c):
|
|
|
|
return builtin{{.}}.ActorNameByCode(c)
|
2022-09-06 15:49:29 +00:00
|
|
|
{{end}}
|
2022-05-15 19:26:52 +00:00
|
|
|
{{end}}
|
2021-04-26 14:48:20 +00:00
|
|
|
default:
|
|
|
|
return "<unknown>"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsBuiltinActor(c cid.Cid) bool {
|
2022-04-04 11:23:13 +00:00
|
|
|
_, _, ok := actors.GetActorMetaByCode(c)
|
|
|
|
if ok {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-05-15 01:11:23 +00:00
|
|
|
{{range .versions}}
|
2022-04-20 21:34:28 +00:00
|
|
|
{{if (le . 7)}}
|
|
|
|
if builtin{{.}}.IsBuiltinActor(c) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
{{end}}
|
2021-05-15 01:11:23 +00:00
|
|
|
{{end}}
|
|
|
|
return false
|
2021-04-26 14:48:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func IsAccountActor(c cid.Cid) bool {
|
2022-04-04 11:23:13 +00:00
|
|
|
name, _, ok := actors.GetActorMetaByCode(c)
|
|
|
|
if ok {
|
|
|
|
return name == "account"
|
|
|
|
}
|
|
|
|
|
2021-05-15 01:11:23 +00:00
|
|
|
{{range .versions}}
|
2022-04-20 21:34:28 +00:00
|
|
|
{{if (le . 7)}}
|
|
|
|
if c == builtin{{.}}.AccountActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
{{end}}
|
2021-05-15 01:11:23 +00:00
|
|
|
{{end}}
|
|
|
|
return false
|
2021-04-26 14:48:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func IsStorageMinerActor(c cid.Cid) bool {
|
2022-04-04 11:23:13 +00:00
|
|
|
name, _, ok := actors.GetActorMetaByCode(c)
|
|
|
|
if ok {
|
2022-12-13 23:02:34 +00:00
|
|
|
return name == manifest.MinerKey
|
2022-04-04 11:23:13 +00:00
|
|
|
}
|
|
|
|
|
2021-05-15 01:11:23 +00:00
|
|
|
{{range .versions}}
|
2022-04-20 21:34:28 +00:00
|
|
|
{{if (le . 7)}}
|
|
|
|
if c == builtin{{.}}.StorageMinerActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
{{end}}
|
2021-05-15 01:11:23 +00:00
|
|
|
{{end}}
|
|
|
|
return false
|
2021-04-26 14:48:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func IsMultisigActor(c cid.Cid) bool {
|
2022-04-04 11:23:13 +00:00
|
|
|
name, _, ok := actors.GetActorMetaByCode(c)
|
|
|
|
if ok {
|
2022-12-13 23:02:34 +00:00
|
|
|
return name == manifest.MultisigKey
|
2022-04-04 11:23:13 +00:00
|
|
|
}
|
|
|
|
|
2021-05-15 01:11:23 +00:00
|
|
|
{{range .versions}}
|
2022-04-20 21:34:28 +00:00
|
|
|
{{if (le . 7)}}
|
|
|
|
if c == builtin{{.}}.MultisigActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
{{end}}
|
2021-05-15 01:11:23 +00:00
|
|
|
{{end}}
|
|
|
|
return false
|
2021-04-26 14:48:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func IsPaymentChannelActor(c cid.Cid) bool {
|
2022-04-04 11:23:13 +00:00
|
|
|
name, _, ok := actors.GetActorMetaByCode(c)
|
|
|
|
if ok {
|
|
|
|
return name == "paymentchannel"
|
|
|
|
}
|
|
|
|
|
2021-05-15 01:11:23 +00:00
|
|
|
{{range .versions}}
|
2022-04-20 21:34:28 +00:00
|
|
|
{{if (le . 7)}}
|
|
|
|
if c == builtin{{.}}.PaymentChannelActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
{{end}}
|
2021-05-15 01:11:23 +00:00
|
|
|
{{end}}
|
|
|
|
return false
|
2021-04-26 14:48:20 +00:00
|
|
|
}
|
|
|
|
|
2023-01-13 19:11:13 +00:00
|
|
|
func IsPlaceholderActor(c cid.Cid) bool {
|
|
|
|
name, _, ok := actors.GetActorMetaByCode(c)
|
|
|
|
if ok {
|
|
|
|
return name == manifest.PlaceholderKey
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsEvmActor(c cid.Cid) bool {
|
|
|
|
name, _, ok := actors.GetActorMetaByCode(c)
|
|
|
|
if ok {
|
|
|
|
return name == manifest.EvmKey
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsEthAccountActor(c cid.Cid) bool {
|
|
|
|
name, _, ok := actors.GetActorMetaByCode(c)
|
|
|
|
if ok {
|
|
|
|
return name == manifest.EthAccountKey
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-04-26 14:48:20 +00:00
|
|
|
func makeAddress(addr string) address.Address {
|
|
|
|
ret, err := address.NewFromString(addr)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret
|
|
|
|
}
|