lotus/chain/actors/builtin/builtin.go

139 lines
4.0 KiB
Go
Raw Normal View History

package builtin
import (
"github.com/filecoin-project/go-address"
"github.com/ipfs/go-cid"
"golang.org/x/xerrors"
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
2021-01-18 23:10:03 +00:00
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
2020-09-22 04:12:07 +00:00
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/cbor"
"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/chain/types"
smoothing0 "github.com/filecoin-project/specs-actors/actors/util/smoothing"
2021-01-18 23:15:18 +00:00
smoothing2 "github.com/filecoin-project/specs-actors/v2/actors/util/smoothing"
2021-01-16 07:39:35 +00:00
smoothing3 "github.com/filecoin-project/specs-actors/v3/actors/util/smoothing"
2021-01-18 23:15:18 +00:00
miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner"
proof0 "github.com/filecoin-project/specs-actors/actors/runtime/proof"
)
2020-09-29 04:24:38 +00:00
var SystemActorAddr = builtin0.SystemActorAddr
var BurntFundsActorAddr = builtin0.BurntFundsActorAddr
var CronActorAddr = builtin0.CronActorAddr
var SaftAddress = makeAddress("t0122")
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 (
ExpectedLeadersPerEpoch = builtin0.ExpectedLeadersPerEpoch
)
const (
EpochDurationSeconds = builtin0.EpochDurationSeconds
EpochsInDay = builtin0.EpochsInDay
SecondsInDay = builtin0.SecondsInDay
)
const (
2021-01-18 23:10:03 +00:00
MethodSend = builtin3.MethodSend
MethodConstructor = builtin3.MethodConstructor
)
2021-01-18 23:15:18 +00:00
// These are all just type aliases across actor versions 0, 2, & 3. In the future, that might change
// and we might need to do something fancier.
type SectorInfo = proof0.SectorInfo
type PoStProof = proof0.PoStProof
type FilterEstimate = smoothing0.FilterEstimate
func FromV0FilterEstimate(v0 smoothing0.FilterEstimate) FilterEstimate {
return (FilterEstimate)(v0)
}
2020-09-22 04:12:07 +00:00
2021-01-18 23:15:18 +00:00
// Doesn't change between actors v0, v2, and v3.
2020-09-22 04:12:07 +00:00
func QAPowerForWeight(size abi.SectorSize, duration abi.ChainEpoch, dealWeight, verifiedWeight abi.DealWeight) abi.StoragePower {
return miner0.QAPowerForWeight(size, duration, dealWeight, verifiedWeight)
}
2020-09-19 03:46:03 +00:00
2021-01-16 07:39:35 +00:00
func FromV2FilterEstimate(v2 smoothing2.FilterEstimate) FilterEstimate {
return (FilterEstimate)(v2)
}
func FromV3FilterEstimate(v3 smoothing3.FilterEstimate) FilterEstimate {
return (FilterEstimate)(v3)
2020-09-19 03:46:03 +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)
}
func ActorNameByCode(c cid.Cid) string {
switch {
case builtin0.IsBuiltinActor(c):
return builtin0.ActorNameByCode(c)
case builtin2.IsBuiltinActor(c):
return builtin2.ActorNameByCode(c)
2021-01-18 23:15:18 +00:00
case builtin3.IsBuiltinActor(c):
return builtin3.ActorNameByCode(c)
default:
return "<unknown>"
}
}
func IsBuiltinActor(c cid.Cid) bool {
2021-01-18 23:15:18 +00:00
return builtin0.IsBuiltinActor(c) ||
builtin2.IsBuiltinActor(c) ||
builtin3.IsBuiltinActor(c)
}
2020-09-29 04:24:38 +00:00
func IsAccountActor(c cid.Cid) bool {
2021-01-18 23:15:18 +00:00
return c == builtin0.AccountActorCodeID ||
c == builtin2.AccountActorCodeID ||
c == builtin3.AccountActorCodeID
2020-09-29 04:24:38 +00:00
}
func IsStorageMinerActor(c cid.Cid) bool {
2021-01-18 23:15:18 +00:00
return c == builtin0.StorageMinerActorCodeID ||
c == builtin2.StorageMinerActorCodeID ||
c == builtin3.StorageMinerActorCodeID
2020-09-29 04:24:38 +00:00
}
func IsMultisigActor(c cid.Cid) bool {
2021-01-18 23:15:18 +00:00
return c == builtin0.MultisigActorCodeID ||
c == builtin2.MultisigActorCodeID ||
c == builtin3.MultisigActorCodeID
2020-09-29 04:24:38 +00:00
}
func IsPaymentChannelActor(c cid.Cid) bool {
2021-01-18 23:15:18 +00:00
return c == builtin0.PaymentChannelActorCodeID ||
c == builtin2.PaymentChannelActorCodeID ||
c == builtin3.PaymentChannelActorCodeID
2020-09-29 04:24:38 +00:00
}
func makeAddress(addr string) address.Address {
ret, err := address.NewFromString(addr)
if err != nil {
panic(err)
}
return ret
}