2020-09-12 03:07:52 +00:00
|
|
|
package builtin
|
|
|
|
|
|
|
|
import (
|
2020-10-05 01:38:52 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
2020-09-24 00:40:29 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
2020-10-11 22:17:28 +00:00
|
|
|
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
2021-05-06 04:17:35 +00:00
|
|
|
smoothing0 "github.com/filecoin-project/specs-actors/actors/util/smoothing"
|
|
|
|
|
2021-01-18 23:10:03 +00:00
|
|
|
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
2021-05-06 04:17:35 +00:00
|
|
|
smoothing2 "github.com/filecoin-project/specs-actors/v2/actors/util/smoothing"
|
|
|
|
|
2021-01-18 23:10:03 +00:00
|
|
|
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
2021-05-06 04:17:35 +00:00
|
|
|
smoothing3 "github.com/filecoin-project/specs-actors/v3/actors/util/smoothing"
|
|
|
|
|
2021-04-23 12:29:46 +00:00
|
|
|
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
2021-05-06 04:17:35 +00:00
|
|
|
smoothing4 "github.com/filecoin-project/specs-actors/v4/actors/util/smoothing"
|
2020-10-11 22:17:28 +00:00
|
|
|
|
2020-09-22 04:12:07 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2020-09-24 00:40:29 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/cbor"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
|
2021-05-06 04:17:35 +00:00
|
|
|
miner4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner"
|
|
|
|
proof4 "github.com/filecoin-project/specs-actors/v4/actors/runtime/proof"
|
2020-09-12 03:07:52 +00:00
|
|
|
)
|
|
|
|
|
2021-05-06 04:17:35 +00:00
|
|
|
var SystemActorAddr = builtin4.SystemActorAddr
|
|
|
|
var BurntFundsActorAddr = builtin4.BurntFundsActorAddr
|
|
|
|
var CronActorAddr = builtin4.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 (
|
2021-05-06 04:17:35 +00:00
|
|
|
ExpectedLeadersPerEpoch = builtin4.ExpectedLeadersPerEpoch
|
2020-10-08 01:09:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2021-05-06 04:17:35 +00:00
|
|
|
EpochDurationSeconds = builtin4.EpochDurationSeconds
|
|
|
|
EpochsInDay = builtin4.EpochsInDay
|
|
|
|
SecondsInDay = builtin4.SecondsInDay
|
2020-10-08 01:09:33 +00:00
|
|
|
)
|
|
|
|
|
2020-10-08 20:32:54 +00:00
|
|
|
const (
|
2021-04-23 12:29:46 +00:00
|
|
|
MethodSend = builtin4.MethodSend
|
|
|
|
MethodConstructor = builtin4.MethodConstructor
|
2020-10-08 20:32:54 +00:00
|
|
|
)
|
|
|
|
|
2021-05-06 04:17:35 +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.
|
2021-05-06 04:17:35 +00:00
|
|
|
type SectorInfo = proof4.SectorInfo
|
|
|
|
type PoStProof = proof4.PoStProof
|
2020-09-20 21:53:46 +00:00
|
|
|
type FilterEstimate = smoothing0.FilterEstimate
|
|
|
|
|
2021-05-06 04:17:35 +00:00
|
|
|
func QAPowerForWeight(size abi.SectorSize, duration abi.ChainEpoch, dealWeight, verifiedWeight abi.DealWeight) abi.StoragePower {
|
|
|
|
return miner4.QAPowerForWeight(size, duration, dealWeight, verifiedWeight)
|
|
|
|
}
|
|
|
|
|
2020-09-20 21:53:46 +00:00
|
|
|
func FromV0FilterEstimate(v0 smoothing0.FilterEstimate) FilterEstimate {
|
2021-05-06 04:17:35 +00:00
|
|
|
|
2021-03-26 00:17:46 +00:00
|
|
|
return (FilterEstimate)(v0) //nolint:unconvert
|
2020-09-22 04:12:07 +00:00
|
|
|
|
|
|
|
}
|
2020-09-19 03:46:03 +00:00
|
|
|
|
2021-01-16 07:39:35 +00:00
|
|
|
func FromV2FilterEstimate(v2 smoothing2.FilterEstimate) FilterEstimate {
|
2021-05-06 04:17:35 +00:00
|
|
|
|
2021-01-16 07:39:35 +00:00
|
|
|
return (FilterEstimate)(v2)
|
2021-05-06 04:17:35 +00:00
|
|
|
|
2021-01-16 07:39:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func FromV3FilterEstimate(v3 smoothing3.FilterEstimate) FilterEstimate {
|
2021-05-06 04:17:35 +00:00
|
|
|
|
2021-01-16 07:39:35 +00:00
|
|
|
return (FilterEstimate)(v3)
|
2021-05-06 04:17:35 +00:00
|
|
|
|
2020-09-19 03:46:03 +00:00
|
|
|
}
|
2020-09-24 00:40:29 +00:00
|
|
|
|
2021-04-23 12:29:46 +00:00
|
|
|
func FromV4FilterEstimate(v4 smoothing4.FilterEstimate) FilterEstimate {
|
2021-05-06 04:17:35 +00:00
|
|
|
|
2021-04-23 12:29:46 +00:00
|
|
|
return (FilterEstimate)(v4)
|
2021-05-06 04:17:35 +00:00
|
|
|
|
2021-04-23 12:29:46 +00:00
|
|
|
}
|
|
|
|
|
2020-09-24 00:40:29 +00:00
|
|
|
type ActorStateLoader func(store adt.Store, root cid.Cid) (cbor.Marshaler, error)
|
|
|
|
|
|
|
|
var ActorStateLoaders = make(map[cid.Cid]ActorStateLoader)
|
|
|
|
|
|
|
|
func RegisterActorState(code cid.Cid, loader ActorStateLoader) {
|
|
|
|
ActorStateLoaders[code] = loader
|
|
|
|
}
|
|
|
|
|
|
|
|
func Load(store adt.Store, act *types.Actor) (cbor.Marshaler, error) {
|
|
|
|
loader, found := ActorStateLoaders[act.Code]
|
|
|
|
if !found {
|
|
|
|
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
|
|
|
}
|
|
|
|
return loader(store, act.Head)
|
|
|
|
}
|
2020-09-28 19:48:08 +00:00
|
|
|
|
|
|
|
func ActorNameByCode(c cid.Cid) string {
|
|
|
|
switch {
|
2021-05-06 04:17:35 +00:00
|
|
|
|
2020-09-28 19:48:08 +00:00
|
|
|
case builtin0.IsBuiltinActor(c):
|
|
|
|
return builtin0.ActorNameByCode(c)
|
2021-05-06 04:17:35 +00:00
|
|
|
|
2020-09-28 20:13:18 +00:00
|
|
|
case builtin2.IsBuiltinActor(c):
|
|
|
|
return builtin2.ActorNameByCode(c)
|
2021-05-06 04:17:35 +00:00
|
|
|
|
2021-01-18 23:15:18 +00:00
|
|
|
case builtin3.IsBuiltinActor(c):
|
|
|
|
return builtin3.ActorNameByCode(c)
|
2021-05-06 04:17:35 +00:00
|
|
|
|
2021-04-23 12:29:46 +00:00
|
|
|
case builtin4.IsBuiltinActor(c):
|
|
|
|
return builtin4.ActorNameByCode(c)
|
2021-05-06 04:17:35 +00:00
|
|
|
|
2020-09-28 19:48:08 +00:00
|
|
|
default:
|
|
|
|
return "<unknown>"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsBuiltinActor(c cid.Cid) bool {
|
2021-05-06 04:17:35 +00:00
|
|
|
|
|
|
|
if builtin0.IsBuiltinActor(c) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if builtin2.IsBuiltinActor(c) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if builtin3.IsBuiltinActor(c) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if builtin4.IsBuiltinActor(c) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
2020-09-28 19:48:08 +00:00
|
|
|
}
|
2020-09-29 04:24:38 +00:00
|
|
|
|
|
|
|
func IsAccountActor(c cid.Cid) bool {
|
2021-05-06 04:17:35 +00:00
|
|
|
|
|
|
|
if c == builtin0.AccountActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin2.AccountActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin3.AccountActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin4.AccountActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
2020-09-29 04:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func IsStorageMinerActor(c cid.Cid) bool {
|
2021-05-06 04:17:35 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
2020-09-29 04:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func IsMultisigActor(c cid.Cid) bool {
|
2021-05-06 04:17:35 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
2020-09-29 04:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func IsPaymentChannelActor(c cid.Cid) bool {
|
2021-05-06 04:17:35 +00:00
|
|
|
|
|
|
|
if c == builtin0.PaymentChannelActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin2.PaymentChannelActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin3.PaymentChannelActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c == builtin4.PaymentChannelActorCodeID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
2020-09-29 04:24:38 +00:00
|
|
|
}
|
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
|
|
|
|
}
|