2020-09-12 03:07:52 +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"
|
|
|
|
|
2020-09-24 00:40:29 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
|
2022-11-08 05:53:13 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
"github.com/filecoin-project/go-state-types/builtin"
|
|
|
|
smoothingtypes "github.com/filecoin-project/go-state-types/builtin/v8/util/smoothing"
|
|
|
|
minertypes "github.com/filecoin-project/go-state-types/builtin/v9/miner"
|
|
|
|
"github.com/filecoin-project/go-state-types/proof"
|
2022-04-07 18:46:23 +00:00
|
|
|
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
|
|
|
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
|
|
|
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
|
|
|
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
|
|
|
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
|
|
|
|
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
|
|
|
|
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
2022-09-06 15:49:29 +00:00
|
|
|
|
2022-04-04 11:25:03 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
2020-09-12 03:07:52 +00:00
|
|
|
)
|
|
|
|
|
2022-05-16 23:43:06 +00:00
|
|
|
var SystemActorAddr = builtin.SystemActorAddr
|
|
|
|
var BurntFundsActorAddr = builtin.BurntFundsActorAddr
|
|
|
|
var CronActorAddr = builtin.CronActorAddr
|
2020-10-11 22:17:28 +00:00
|
|
|
var SaftAddress = makeAddress("t0122")
|
2020-10-05 01:38:52 +00:00
|
|
|
var ReserveAddress = makeAddress("t090")
|
2020-10-06 21:47:03 +00:00
|
|
|
var RootVerifierAddress = makeAddress("t080")
|
2020-09-29 04:24:38 +00:00
|
|
|
|
2020-10-08 01:09:33 +00:00
|
|
|
var (
|
2022-05-16 23:43:06 +00:00
|
|
|
ExpectedLeadersPerEpoch = builtin.ExpectedLeadersPerEpoch
|
2020-10-08 01:09:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2022-05-16 23:43:06 +00:00
|
|
|
EpochDurationSeconds = builtin.EpochDurationSeconds
|
|
|
|
EpochsInDay = builtin.EpochsInDay
|
|
|
|
SecondsInDay = builtin.SecondsInDay
|
2020-10-08 01:09:33 +00:00
|
|
|
)
|
|
|
|
|
2020-10-08 20:32:54 +00:00
|
|
|
const (
|
2022-05-16 23:43:06 +00:00
|
|
|
MethodSend = builtin.MethodSend
|
|
|
|
MethodConstructor = builtin.MethodConstructor
|
2020-10-08 20:32:54 +00:00
|
|
|
)
|
|
|
|
|
2021-04-26 14:48:20 +00:00
|
|
|
// These are all just type aliases across actor versions. In the future, that might change
|
2021-01-18 23:15:18 +00:00
|
|
|
// 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
|
2020-09-20 21:53:46 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-09-28 19:48:08 +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:25:03 +00:00
|
|
|
}
|
2022-03-01 03:57:40 +00:00
|
|
|
|
2022-04-04 11:25:03 +00:00
|
|
|
switch {
|
2022-04-07 18:46:23 +00:00
|
|
|
|
|
|
|
case builtin0.IsBuiltinActor(c):
|
|
|
|
return builtin0.ActorNameByCode(c)
|
|
|
|
|
|
|
|
case builtin2.IsBuiltinActor(c):
|
|
|
|
return builtin2.ActorNameByCode(c)
|
|
|
|
|
|
|
|
case builtin3.IsBuiltinActor(c):
|
|
|
|
return builtin3.ActorNameByCode(c)
|
|
|
|
|
|
|
|
case builtin4.IsBuiltinActor(c):
|
|
|
|
return builtin4.ActorNameByCode(c)
|
|
|
|
|
|
|
|
case builtin5.IsBuiltinActor(c):
|
|
|
|
return builtin5.ActorNameByCode(c)
|
|
|
|
|
|
|
|
case builtin6.IsBuiltinActor(c):
|
|
|
|
return builtin6.ActorNameByCode(c)
|
|
|
|
|
|
|
|
case builtin7.IsBuiltinActor(c):
|
|
|
|
return builtin7.ActorNameByCode(c)
|
|
|
|
|
2020-09-28 19:48:08 +00:00
|
|
|
default:
|
|
|
|
return "<unknown>"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsBuiltinActor(c cid.Cid) bool {
|
2022-04-04 11:25:03 +00:00
|
|
|
_, _, ok := actors.GetActorMetaByCode(c)
|
2022-04-07 18:46:23 +00:00
|
|
|
if ok {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if builtin0.IsBuiltinActor(c) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if builtin2.IsBuiltinActor(c) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if builtin3.IsBuiltinActor(c) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if builtin4.IsBuiltinActor(c) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if builtin5.IsBuiltinActor(c) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if builtin6.IsBuiltinActor(c) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if builtin7.IsBuiltinActor(c) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-09-29 04:24:38 +00:00
|
|
|
func IsAccountActor(c cid.Cid) bool {
|
2022-04-04 11:25:03 +00:00
|
|
|
name, _, ok := actors.GetActorMetaByCode(c)
|
2022-04-07 18:46:23 +00:00
|
|
|
if ok {
|
|
|
|
return name == "account"
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin0.AccountActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin2.AccountActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin3.AccountActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin4.AccountActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin5.AccountActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin6.AccountActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin7.AccountActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-09-29 04:24:38 +00:00
|
|
|
func IsStorageMinerActor(c cid.Cid) bool {
|
2022-04-04 11:25:03 +00:00
|
|
|
name, _, ok := actors.GetActorMetaByCode(c)
|
2022-04-07 18:46:23 +00:00
|
|
|
if ok {
|
2022-04-20 21:34:28 +00:00
|
|
|
return name == actors.MinerKey
|
2022-04-07 18:46:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin0.StorageMinerActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin2.StorageMinerActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin3.StorageMinerActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin4.StorageMinerActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin5.StorageMinerActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin6.StorageMinerActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin7.StorageMinerActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-09-29 04:24:38 +00:00
|
|
|
func IsMultisigActor(c cid.Cid) bool {
|
2022-04-04 11:25:03 +00:00
|
|
|
name, _, ok := actors.GetActorMetaByCode(c)
|
2022-04-07 18:46:23 +00:00
|
|
|
if ok {
|
2022-04-20 21:34:28 +00:00
|
|
|
return name == actors.MultisigKey
|
2022-04-07 18:46:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin0.MultisigActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin2.MultisigActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin3.MultisigActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin4.MultisigActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin5.MultisigActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin6.MultisigActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin7.MultisigActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-09-29 04:24:38 +00:00
|
|
|
func IsPaymentChannelActor(c cid.Cid) bool {
|
2022-04-04 11:25:03 +00:00
|
|
|
name, _, ok := actors.GetActorMetaByCode(c)
|
2022-04-07 18:46:23 +00:00
|
|
|
if ok {
|
|
|
|
return name == "paymentchannel"
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin0.PaymentChannelActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin2.PaymentChannelActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin3.PaymentChannelActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin4.PaymentChannelActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin5.PaymentChannelActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin6.PaymentChannelActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin7.PaymentChannelActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-10-05 01:38:52 +00:00
|
|
|
func makeAddress(addr string) address.Address {
|
|
|
|
ret, err := address.NewFromString(addr)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret
|
|
|
|
}
|