Integrate v7 actors
This commit is contained in:
parent
a95b77a940
commit
a8cb027c08
Binary file not shown.
@ -47,6 +47,8 @@ var UpgradeHyperdriveHeight = abi.ChainEpoch(-16)
|
||||
|
||||
var UpgradeChocolateHeight = abi.ChainEpoch(-17)
|
||||
|
||||
var UpgradeSnapDealsHeight = abi.ChainEpoch(-18)
|
||||
|
||||
var DrandSchedule = map[abi.ChainEpoch]DrandEnum{
|
||||
0: DrandMainnet,
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ const UpgradeNorwegianHeight = -14
|
||||
const UpgradeTurboHeight = -15
|
||||
const UpgradeHyperdriveHeight = -16
|
||||
const UpgradeChocolateHeight = 6360
|
||||
const UpgradeSnapDealsHeight = 99999999
|
||||
|
||||
func init() {
|
||||
policy.SetConsensusMinerMinPower(abi.NewStoragePower(2 << 30))
|
||||
|
@ -54,6 +54,8 @@ const UpgradeHyperdriveHeight = 420
|
||||
|
||||
const UpgradeChocolateHeight = 312746
|
||||
|
||||
const UpgradeSnapDealsHeight = 99999999
|
||||
|
||||
func init() {
|
||||
policy.SetConsensusMinerMinPower(abi.NewStoragePower(32 << 30))
|
||||
policy.SetSupportedProofTypes(
|
||||
|
@ -47,6 +47,7 @@ var UpgradeTurboHeight = abi.ChainEpoch(-15)
|
||||
|
||||
var UpgradeHyperdriveHeight = abi.ChainEpoch(-16)
|
||||
var UpgradeChocolateHeight = abi.ChainEpoch(-17)
|
||||
var UpgradeSnapDealsHeight = abi.ChainEpoch(-18)
|
||||
|
||||
var DrandSchedule = map[abi.ChainEpoch]DrandEnum{
|
||||
0: DrandMainnet,
|
||||
|
@ -62,18 +62,20 @@ const UpgradeNorwegianHeight = 665280
|
||||
const UpgradeTurboHeight = 712320
|
||||
|
||||
// 2021-06-30T22:00:00Z
|
||||
var UpgradeHyperdriveHeight = abi.ChainEpoch(892800)
|
||||
const UpgradeHyperdriveHeight = 892800
|
||||
|
||||
// 2021-10-26T13:30:00Z
|
||||
var UpgradeChocolateHeight = abi.ChainEpoch(1231620)
|
||||
const UpgradeChocolateHeight = 1231620
|
||||
|
||||
var UpgradeSnapDealsHeight = abi.ChainEpoch(999999999999)
|
||||
|
||||
func init() {
|
||||
if os.Getenv("LOTUS_USE_TEST_ADDRESSES") != "1" {
|
||||
SetAddressNetwork(address.Mainnet)
|
||||
}
|
||||
|
||||
if os.Getenv("LOTUS_DISABLE_CHOCOLATE") == "1" {
|
||||
UpgradeChocolateHeight = math.MaxInt64
|
||||
if os.Getenv("LOTUS_DISABLE_SNAPDEALS") == "1" {
|
||||
UpgradeSnapDealsHeight = math.MaxInt64
|
||||
}
|
||||
|
||||
Devnet = false
|
||||
|
@ -34,7 +34,7 @@ const NewestNetworkVersion = network.Version{{.latestNetworkVersion}}
|
||||
|
||||
/* inline-gen start */
|
||||
|
||||
const NewestNetworkVersion = network.Version14
|
||||
const NewestNetworkVersion = network.Version15
|
||||
|
||||
/* inline-gen end */
|
||||
|
||||
|
@ -99,6 +99,7 @@ var (
|
||||
UpgradeTurboHeight abi.ChainEpoch = -14
|
||||
UpgradeHyperdriveHeight abi.ChainEpoch = -15
|
||||
UpgradeChocolateHeight abi.ChainEpoch = -16
|
||||
UpgradeSnapDealsHeight abi.ChainEpoch = -17
|
||||
|
||||
DrandSchedule = map[abi.ChainEpoch]DrandEnum{
|
||||
0: DrandMainnet,
|
||||
|
@ -23,6 +23,8 @@ import (
|
||||
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"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -50,6 +52,10 @@ func init() {
|
||||
builtin.RegisterActorState(builtin6.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load6(store, root)
|
||||
})
|
||||
|
||||
builtin.RegisterActorState(builtin7.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load7(store, root)
|
||||
})
|
||||
}
|
||||
|
||||
var Methods = builtin4.MethodsAccount
|
||||
@ -75,6 +81,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
case builtin6.AccountActorCodeID:
|
||||
return load6(store, act.Head)
|
||||
|
||||
case builtin7.AccountActorCodeID:
|
||||
return load7(store, act.Head)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||
}
|
||||
@ -100,6 +109,9 @@ func MakeState(store adt.Store, av actors.Version, addr address.Address) (State,
|
||||
case actors.Version6:
|
||||
return make6(store, addr)
|
||||
|
||||
case actors.Version7:
|
||||
return make7(store, addr)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor version %d", av)
|
||||
}
|
||||
@ -125,6 +137,9 @@ func GetActorCodeID(av actors.Version) (cid.Cid, error) {
|
||||
case actors.Version6:
|
||||
return builtin6.AccountActorCodeID, nil
|
||||
|
||||
case actors.Version7:
|
||||
return builtin7.AccountActorCodeID, nil
|
||||
|
||||
}
|
||||
|
||||
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
|
||||
|
40
chain/actors/builtin/account/v7.go
Normal file
40
chain/actors/builtin/account/v7.go
Normal file
@ -0,0 +1,40 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/ipfs/go-cid"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
|
||||
account7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/account"
|
||||
)
|
||||
|
||||
var _ State = (*state7)(nil)
|
||||
|
||||
func load7(store adt.Store, root cid.Cid) (State, error) {
|
||||
out := state7{store: store}
|
||||
err := store.Get(store.Context(), root, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func make7(store adt.Store, addr address.Address) (State, error) {
|
||||
out := state7{store: store}
|
||||
out.State = account7.State{Address: addr}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
type state7 struct {
|
||||
account7.State
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
func (s *state7) PubkeyAddress() (address.Address, error) {
|
||||
return s.Address, nil
|
||||
}
|
||||
|
||||
func (s *state7) GetState() interface{} {
|
||||
return &s.State
|
||||
}
|
@ -23,46 +23,49 @@ import (
|
||||
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
|
||||
smoothing6 "github.com/filecoin-project/specs-actors/v6/actors/util/smoothing"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
smoothing7 "github.com/filecoin-project/specs-actors/v7/actors/util/smoothing"
|
||||
|
||||
"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"
|
||||
|
||||
miner6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/miner"
|
||||
proof6 "github.com/filecoin-project/specs-actors/v6/actors/runtime/proof"
|
||||
miner7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/miner"
|
||||
proof7 "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof"
|
||||
)
|
||||
|
||||
var SystemActorAddr = builtin6.SystemActorAddr
|
||||
var BurntFundsActorAddr = builtin6.BurntFundsActorAddr
|
||||
var CronActorAddr = builtin6.CronActorAddr
|
||||
var SystemActorAddr = builtin7.SystemActorAddr
|
||||
var BurntFundsActorAddr = builtin7.BurntFundsActorAddr
|
||||
var CronActorAddr = builtin7.CronActorAddr
|
||||
var SaftAddress = makeAddress("t0122")
|
||||
var ReserveAddress = makeAddress("t090")
|
||||
var RootVerifierAddress = makeAddress("t080")
|
||||
|
||||
var (
|
||||
ExpectedLeadersPerEpoch = builtin6.ExpectedLeadersPerEpoch
|
||||
ExpectedLeadersPerEpoch = builtin7.ExpectedLeadersPerEpoch
|
||||
)
|
||||
|
||||
const (
|
||||
EpochDurationSeconds = builtin6.EpochDurationSeconds
|
||||
EpochsInDay = builtin6.EpochsInDay
|
||||
SecondsInDay = builtin6.SecondsInDay
|
||||
EpochDurationSeconds = builtin7.EpochDurationSeconds
|
||||
EpochsInDay = builtin7.EpochsInDay
|
||||
SecondsInDay = builtin7.SecondsInDay
|
||||
)
|
||||
|
||||
const (
|
||||
MethodSend = builtin6.MethodSend
|
||||
MethodConstructor = builtin6.MethodConstructor
|
||||
MethodSend = builtin7.MethodSend
|
||||
MethodConstructor = builtin7.MethodConstructor
|
||||
)
|
||||
|
||||
// These are all just type aliases across actor versions. In the future, that might change
|
||||
// and we might need to do something fancier.
|
||||
type SectorInfo = proof6.SectorInfo
|
||||
type PoStProof = proof6.PoStProof
|
||||
type SectorInfo = proof7.SectorInfo
|
||||
type PoStProof = proof7.PoStProof
|
||||
type FilterEstimate = smoothing0.FilterEstimate
|
||||
|
||||
func QAPowerForWeight(size abi.SectorSize, duration abi.ChainEpoch, dealWeight, verifiedWeight abi.DealWeight) abi.StoragePower {
|
||||
return miner6.QAPowerForWeight(size, duration, dealWeight, verifiedWeight)
|
||||
return miner7.QAPowerForWeight(size, duration, dealWeight, verifiedWeight)
|
||||
}
|
||||
|
||||
func FromV0FilterEstimate(v0 smoothing0.FilterEstimate) FilterEstimate {
|
||||
@ -101,6 +104,12 @@ func FromV6FilterEstimate(v6 smoothing6.FilterEstimate) FilterEstimate {
|
||||
|
||||
}
|
||||
|
||||
func FromV7FilterEstimate(v7 smoothing7.FilterEstimate) FilterEstimate {
|
||||
|
||||
return (FilterEstimate)(v7)
|
||||
|
||||
}
|
||||
|
||||
type ActorStateLoader func(store adt.Store, root cid.Cid) (cbor.Marshaler, error)
|
||||
|
||||
var ActorStateLoaders = make(map[cid.Cid]ActorStateLoader)
|
||||
@ -138,6 +147,9 @@ func ActorNameByCode(c cid.Cid) string {
|
||||
case builtin6.IsBuiltinActor(c):
|
||||
return builtin6.ActorNameByCode(c)
|
||||
|
||||
case builtin7.IsBuiltinActor(c):
|
||||
return builtin7.ActorNameByCode(c)
|
||||
|
||||
default:
|
||||
return "<unknown>"
|
||||
}
|
||||
@ -169,6 +181,10 @@ func IsBuiltinActor(c cid.Cid) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
if builtin7.IsBuiltinActor(c) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@ -198,6 +214,10 @@ func IsAccountActor(c cid.Cid) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
if c == builtin7.AccountActorCodeID {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@ -227,6 +247,10 @@ func IsStorageMinerActor(c cid.Cid) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
if c == builtin7.StorageMinerActorCodeID {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@ -256,6 +280,10 @@ func IsMultisigActor(c cid.Cid) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
if c == builtin7.MultisigActorCodeID {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@ -285,6 +313,10 @@ func IsPaymentChannelActor(c cid.Cid) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
if c == builtin7.PaymentChannelActorCodeID {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,8 @@ import (
|
||||
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"
|
||||
)
|
||||
|
||||
func MakeState(store adt.Store, av actors.Version) (State, error) {
|
||||
@ -40,6 +42,9 @@ func MakeState(store adt.Store, av actors.Version) (State, error) {
|
||||
case actors.Version6:
|
||||
return make6(store)
|
||||
|
||||
case actors.Version7:
|
||||
return make7(store)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor version %d", av)
|
||||
}
|
||||
@ -65,14 +70,17 @@ func GetActorCodeID(av actors.Version) (cid.Cid, error) {
|
||||
case actors.Version6:
|
||||
return builtin6.CronActorCodeID, nil
|
||||
|
||||
case actors.Version7:
|
||||
return builtin7.CronActorCodeID, nil
|
||||
|
||||
}
|
||||
|
||||
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
|
||||
}
|
||||
|
||||
var (
|
||||
Address = builtin6.CronActorAddr
|
||||
Methods = builtin6.MethodsCron
|
||||
Address = builtin7.CronActorAddr
|
||||
Methods = builtin7.MethodsCron
|
||||
)
|
||||
|
||||
type State interface {
|
||||
|
35
chain/actors/builtin/cron/v7.go
Normal file
35
chain/actors/builtin/cron/v7.go
Normal file
@ -0,0 +1,35 @@
|
||||
package cron
|
||||
|
||||
import (
|
||||
"github.com/ipfs/go-cid"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
|
||||
cron7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/cron"
|
||||
)
|
||||
|
||||
var _ State = (*state7)(nil)
|
||||
|
||||
func load7(store adt.Store, root cid.Cid) (State, error) {
|
||||
out := state7{store: store}
|
||||
err := store.Get(store.Context(), root, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func make7(store adt.Store) (State, error) {
|
||||
out := state7{store: store}
|
||||
out.State = *cron7.ConstructState(cron7.BuiltInEntries())
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
type state7 struct {
|
||||
cron7.State
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
func (s *state7) GetState() interface{} {
|
||||
return &s.State
|
||||
}
|
@ -25,6 +25,8 @@ import (
|
||||
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"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -52,11 +54,15 @@ func init() {
|
||||
builtin.RegisterActorState(builtin6.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load6(store, root)
|
||||
})
|
||||
|
||||
builtin.RegisterActorState(builtin7.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load7(store, root)
|
||||
})
|
||||
}
|
||||
|
||||
var (
|
||||
Address = builtin6.InitActorAddr
|
||||
Methods = builtin6.MethodsInit
|
||||
Address = builtin7.InitActorAddr
|
||||
Methods = builtin7.MethodsInit
|
||||
)
|
||||
|
||||
func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
@ -80,6 +86,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
case builtin6.InitActorCodeID:
|
||||
return load6(store, act.Head)
|
||||
|
||||
case builtin7.InitActorCodeID:
|
||||
return load7(store, act.Head)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||
}
|
||||
@ -105,6 +114,9 @@ func MakeState(store adt.Store, av actors.Version, networkName string) (State, e
|
||||
case actors.Version6:
|
||||
return make6(store, networkName)
|
||||
|
||||
case actors.Version7:
|
||||
return make7(store, networkName)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor version %d", av)
|
||||
}
|
||||
@ -130,6 +142,9 @@ func GetActorCodeID(av actors.Version) (cid.Cid, error) {
|
||||
case actors.Version6:
|
||||
return builtin6.InitActorCodeID, nil
|
||||
|
||||
case actors.Version7:
|
||||
return builtin7.InitActorCodeID, nil
|
||||
|
||||
}
|
||||
|
||||
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
|
||||
|
114
chain/actors/builtin/init/v7.go
Normal file
114
chain/actors/builtin/init/v7.go
Normal file
@ -0,0 +1,114 @@
|
||||
package init
|
||||
|
||||
import (
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/ipfs/go-cid"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
|
||||
init7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/init"
|
||||
adt7 "github.com/filecoin-project/specs-actors/v7/actors/util/adt"
|
||||
)
|
||||
|
||||
var _ State = (*state7)(nil)
|
||||
|
||||
func load7(store adt.Store, root cid.Cid) (State, error) {
|
||||
out := state7{store: store}
|
||||
err := store.Get(store.Context(), root, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func make7(store adt.Store, networkName string) (State, error) {
|
||||
out := state7{store: store}
|
||||
|
||||
s, err := init7.ConstructState(store, networkName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out.State = *s
|
||||
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
type state7 struct {
|
||||
init7.State
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
func (s *state7) ResolveAddress(address address.Address) (address.Address, bool, error) {
|
||||
return s.State.ResolveAddress(s.store, address)
|
||||
}
|
||||
|
||||
func (s *state7) MapAddressToNewID(address address.Address) (address.Address, error) {
|
||||
return s.State.MapAddressToNewID(s.store, address)
|
||||
}
|
||||
|
||||
func (s *state7) ForEachActor(cb func(id abi.ActorID, address address.Address) error) error {
|
||||
addrs, err := adt7.AsMap(s.store, s.State.AddressMap, builtin7.DefaultHamtBitwidth)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var actorID cbg.CborInt
|
||||
return addrs.ForEach(&actorID, func(key string) error {
|
||||
addr, err := address.NewFromBytes([]byte(key))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cb(abi.ActorID(actorID), addr)
|
||||
})
|
||||
}
|
||||
|
||||
func (s *state7) NetworkName() (dtypes.NetworkName, error) {
|
||||
return dtypes.NetworkName(s.State.NetworkName), nil
|
||||
}
|
||||
|
||||
func (s *state7) SetNetworkName(name string) error {
|
||||
s.State.NetworkName = name
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *state7) SetNextID(id abi.ActorID) error {
|
||||
s.State.NextID = id
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *state7) Remove(addrs ...address.Address) (err error) {
|
||||
m, err := adt7.AsMap(s.store, s.State.AddressMap, builtin7.DefaultHamtBitwidth)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, addr := range addrs {
|
||||
if err = m.Delete(abi.AddrKey(addr)); err != nil {
|
||||
return xerrors.Errorf("failed to delete entry for address: %s; err: %w", addr, err)
|
||||
}
|
||||
}
|
||||
amr, err := m.Root()
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to get address map root: %w", err)
|
||||
}
|
||||
s.State.AddressMap = amr
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *state7) SetAddressMap(mcid cid.Cid) error {
|
||||
s.State.AddressMap = mcid
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *state7) AddressMap() (adt.Map, error) {
|
||||
return adt7.AsMap(s.store, s.State.AddressMap, builtin7.DefaultHamtBitwidth)
|
||||
}
|
||||
|
||||
func (s *state7) GetState() interface{} {
|
||||
return &s.State
|
||||
}
|
@ -25,6 +25,8 @@ import (
|
||||
|
||||
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||
@ -56,11 +58,15 @@ func init() {
|
||||
builtin.RegisterActorState(builtin6.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load6(store, root)
|
||||
})
|
||||
|
||||
builtin.RegisterActorState(builtin7.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load7(store, root)
|
||||
})
|
||||
}
|
||||
|
||||
var (
|
||||
Address = builtin6.StorageMarketActorAddr
|
||||
Methods = builtin6.MethodsMarket
|
||||
Address = builtin7.StorageMarketActorAddr
|
||||
Methods = builtin7.MethodsMarket
|
||||
)
|
||||
|
||||
func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
@ -84,6 +90,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
case builtin6.StorageMarketActorCodeID:
|
||||
return load6(store, act.Head)
|
||||
|
||||
case builtin7.StorageMarketActorCodeID:
|
||||
return load7(store, act.Head)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||
}
|
||||
@ -109,6 +118,9 @@ func MakeState(store adt.Store, av actors.Version) (State, error) {
|
||||
case actors.Version6:
|
||||
return make6(store)
|
||||
|
||||
case actors.Version7:
|
||||
return make7(store)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor version %d", av)
|
||||
}
|
||||
@ -134,6 +146,9 @@ func GetActorCodeID(av actors.Version) (cid.Cid, error) {
|
||||
case actors.Version6:
|
||||
return builtin6.StorageMarketActorCodeID, nil
|
||||
|
||||
case actors.Version7:
|
||||
return builtin7.StorageMarketActorCodeID, nil
|
||||
|
||||
}
|
||||
|
||||
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
|
||||
@ -211,6 +226,9 @@ func DecodePublishStorageDealsReturn(b []byte, nv network.Version) (PublishStora
|
||||
case actors.Version6:
|
||||
return decodePublishStorageDealsReturn6(b)
|
||||
|
||||
case actors.Version7:
|
||||
return decodePublishStorageDealsReturn7(b)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor version %d", av)
|
||||
}
|
||||
|
252
chain/actors/builtin/market/v7.go
Normal file
252
chain/actors/builtin/market/v7.go
Normal file
@ -0,0 +1,252 @@
|
||||
package market
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/ipfs/go-cid"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
|
||||
market7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/market"
|
||||
adt7 "github.com/filecoin-project/specs-actors/v7/actors/util/adt"
|
||||
)
|
||||
|
||||
var _ State = (*state7)(nil)
|
||||
|
||||
func load7(store adt.Store, root cid.Cid) (State, error) {
|
||||
out := state7{store: store}
|
||||
err := store.Get(store.Context(), root, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func make7(store adt.Store) (State, error) {
|
||||
out := state7{store: store}
|
||||
|
||||
s, err := market7.ConstructState(store)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out.State = *s
|
||||
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
type state7 struct {
|
||||
market7.State
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
func (s *state7) TotalLocked() (abi.TokenAmount, error) {
|
||||
fml := types.BigAdd(s.TotalClientLockedCollateral, s.TotalProviderLockedCollateral)
|
||||
fml = types.BigAdd(fml, s.TotalClientStorageFee)
|
||||
return fml, nil
|
||||
}
|
||||
|
||||
func (s *state7) BalancesChanged(otherState State) (bool, error) {
|
||||
otherState7, ok := otherState.(*state7)
|
||||
if !ok {
|
||||
// there's no way to compare different versions of the state, so let's
|
||||
// just say that means the state of balances has changed
|
||||
return true, nil
|
||||
}
|
||||
return !s.State.EscrowTable.Equals(otherState7.State.EscrowTable) || !s.State.LockedTable.Equals(otherState7.State.LockedTable), nil
|
||||
}
|
||||
|
||||
func (s *state7) StatesChanged(otherState State) (bool, error) {
|
||||
otherState7, ok := otherState.(*state7)
|
||||
if !ok {
|
||||
// there's no way to compare different versions of the state, so let's
|
||||
// just say that means the state of balances has changed
|
||||
return true, nil
|
||||
}
|
||||
return !s.State.States.Equals(otherState7.State.States), nil
|
||||
}
|
||||
|
||||
func (s *state7) States() (DealStates, error) {
|
||||
stateArray, err := adt7.AsArray(s.store, s.State.States, market7.StatesAmtBitwidth)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &dealStates7{stateArray}, nil
|
||||
}
|
||||
|
||||
func (s *state7) ProposalsChanged(otherState State) (bool, error) {
|
||||
otherState7, ok := otherState.(*state7)
|
||||
if !ok {
|
||||
// there's no way to compare different versions of the state, so let's
|
||||
// just say that means the state of balances has changed
|
||||
return true, nil
|
||||
}
|
||||
return !s.State.Proposals.Equals(otherState7.State.Proposals), nil
|
||||
}
|
||||
|
||||
func (s *state7) Proposals() (DealProposals, error) {
|
||||
proposalArray, err := adt7.AsArray(s.store, s.State.Proposals, market7.ProposalsAmtBitwidth)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &dealProposals7{proposalArray}, nil
|
||||
}
|
||||
|
||||
func (s *state7) EscrowTable() (BalanceTable, error) {
|
||||
bt, err := adt7.AsBalanceTable(s.store, s.State.EscrowTable)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &balanceTable7{bt}, nil
|
||||
}
|
||||
|
||||
func (s *state7) LockedTable() (BalanceTable, error) {
|
||||
bt, err := adt7.AsBalanceTable(s.store, s.State.LockedTable)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &balanceTable7{bt}, nil
|
||||
}
|
||||
|
||||
func (s *state7) VerifyDealsForActivation(
|
||||
minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch,
|
||||
) (weight, verifiedWeight abi.DealWeight, err error) {
|
||||
w, vw, _, err := market7.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch)
|
||||
return w, vw, err
|
||||
}
|
||||
|
||||
func (s *state7) NextID() (abi.DealID, error) {
|
||||
return s.State.NextID, nil
|
||||
}
|
||||
|
||||
type balanceTable7 struct {
|
||||
*adt7.BalanceTable
|
||||
}
|
||||
|
||||
func (bt *balanceTable7) ForEach(cb func(address.Address, abi.TokenAmount) error) error {
|
||||
asMap := (*adt7.Map)(bt.BalanceTable)
|
||||
var ta abi.TokenAmount
|
||||
return asMap.ForEach(&ta, func(key string) error {
|
||||
a, err := address.NewFromBytes([]byte(key))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cb(a, ta)
|
||||
})
|
||||
}
|
||||
|
||||
type dealStates7 struct {
|
||||
adt.Array
|
||||
}
|
||||
|
||||
func (s *dealStates7) Get(dealID abi.DealID) (*DealState, bool, error) {
|
||||
var deal7 market7.DealState
|
||||
found, err := s.Array.Get(uint64(dealID), &deal7)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
if !found {
|
||||
return nil, false, nil
|
||||
}
|
||||
deal := fromV7DealState(deal7)
|
||||
return &deal, true, nil
|
||||
}
|
||||
|
||||
func (s *dealStates7) ForEach(cb func(dealID abi.DealID, ds DealState) error) error {
|
||||
var ds7 market7.DealState
|
||||
return s.Array.ForEach(&ds7, func(idx int64) error {
|
||||
return cb(abi.DealID(idx), fromV7DealState(ds7))
|
||||
})
|
||||
}
|
||||
|
||||
func (s *dealStates7) decode(val *cbg.Deferred) (*DealState, error) {
|
||||
var ds7 market7.DealState
|
||||
if err := ds7.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ds := fromV7DealState(ds7)
|
||||
return &ds, nil
|
||||
}
|
||||
|
||||
func (s *dealStates7) array() adt.Array {
|
||||
return s.Array
|
||||
}
|
||||
|
||||
func fromV7DealState(v7 market7.DealState) DealState {
|
||||
return (DealState)(v7)
|
||||
}
|
||||
|
||||
type dealProposals7 struct {
|
||||
adt.Array
|
||||
}
|
||||
|
||||
func (s *dealProposals7) Get(dealID abi.DealID) (*DealProposal, bool, error) {
|
||||
var proposal7 market7.DealProposal
|
||||
found, err := s.Array.Get(uint64(dealID), &proposal7)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
if !found {
|
||||
return nil, false, nil
|
||||
}
|
||||
proposal := fromV7DealProposal(proposal7)
|
||||
return &proposal, true, nil
|
||||
}
|
||||
|
||||
func (s *dealProposals7) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error {
|
||||
var dp7 market7.DealProposal
|
||||
return s.Array.ForEach(&dp7, func(idx int64) error {
|
||||
return cb(abi.DealID(idx), fromV7DealProposal(dp7))
|
||||
})
|
||||
}
|
||||
|
||||
func (s *dealProposals7) decode(val *cbg.Deferred) (*DealProposal, error) {
|
||||
var dp7 market7.DealProposal
|
||||
if err := dp7.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dp := fromV7DealProposal(dp7)
|
||||
return &dp, nil
|
||||
}
|
||||
|
||||
func (s *dealProposals7) array() adt.Array {
|
||||
return s.Array
|
||||
}
|
||||
|
||||
func fromV7DealProposal(v7 market7.DealProposal) DealProposal {
|
||||
return (DealProposal)(v7)
|
||||
}
|
||||
|
||||
func (s *state7) GetState() interface{} {
|
||||
return &s.State
|
||||
}
|
||||
|
||||
var _ PublishStorageDealsReturn = (*publishStorageDealsReturn7)(nil)
|
||||
|
||||
func decodePublishStorageDealsReturn7(b []byte) (PublishStorageDealsReturn, error) {
|
||||
var retval market7.PublishStorageDealsReturn
|
||||
if err := retval.UnmarshalCBOR(bytes.NewReader(b)); err != nil {
|
||||
return nil, xerrors.Errorf("failed to unmarshal PublishStorageDealsReturn: %w", err)
|
||||
}
|
||||
|
||||
return &publishStorageDealsReturn7{retval}, nil
|
||||
}
|
||||
|
||||
type publishStorageDealsReturn7 struct {
|
||||
market7.PublishStorageDealsReturn
|
||||
}
|
||||
|
||||
func (r *publishStorageDealsReturn7) IsDealValid(index uint64) (bool, error) {
|
||||
|
||||
return r.ValidDeals.IsSet(index)
|
||||
|
||||
}
|
||||
|
||||
func (r *publishStorageDealsReturn7) DealIDs() ([]abi.DealID, error) {
|
||||
return r.IDs, nil
|
||||
}
|
@ -35,6 +35,8 @@ import (
|
||||
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"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -63,9 +65,13 @@ func init() {
|
||||
return load6(store, root)
|
||||
})
|
||||
|
||||
builtin.RegisterActorState(builtin7.StorageMinerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load7(store, root)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
var Methods = builtin6.MethodsMiner
|
||||
var Methods = builtin7.MethodsMiner
|
||||
|
||||
// Unchanged between v0, v2, v3, v4, and v5 actors
|
||||
var WPoStProvingPeriod = miner0.WPoStProvingPeriod
|
||||
@ -102,6 +108,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
case builtin6.StorageMinerActorCodeID:
|
||||
return load6(store, act.Head)
|
||||
|
||||
case builtin7.StorageMinerActorCodeID:
|
||||
return load7(store, act.Head)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||
}
|
||||
@ -127,6 +136,9 @@ func MakeState(store adt.Store, av actors.Version) (State, error) {
|
||||
case actors.Version6:
|
||||
return make6(store)
|
||||
|
||||
case actors.Version7:
|
||||
return make7(store)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor version %d", av)
|
||||
}
|
||||
@ -152,6 +164,9 @@ func GetActorCodeID(av actors.Version) (cid.Cid, error) {
|
||||
case actors.Version6:
|
||||
return builtin6.StorageMinerActorCodeID, nil
|
||||
|
||||
case actors.Version7:
|
||||
return builtin7.StorageMinerActorCodeID, nil
|
||||
|
||||
}
|
||||
|
||||
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
|
||||
|
570
chain/actors/builtin/miner/v7.go
Normal file
570
chain/actors/builtin/miner/v7.go
Normal file
@ -0,0 +1,570 @@
|
||||
package miner
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-bitfield"
|
||||
rle "github.com/filecoin-project/go-bitfield/rle"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/go-state-types/dline"
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
|
||||
miner7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/miner"
|
||||
adt7 "github.com/filecoin-project/specs-actors/v7/actors/util/adt"
|
||||
)
|
||||
|
||||
var _ State = (*state7)(nil)
|
||||
|
||||
func load7(store adt.Store, root cid.Cid) (State, error) {
|
||||
out := state7{store: store}
|
||||
err := store.Get(store.Context(), root, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func make7(store adt.Store) (State, error) {
|
||||
out := state7{store: store}
|
||||
out.State = miner7.State{}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
type state7 struct {
|
||||
miner7.State
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
type deadline7 struct {
|
||||
miner7.Deadline
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
type partition7 struct {
|
||||
miner7.Partition
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
func (s *state7) AvailableBalance(bal abi.TokenAmount) (available abi.TokenAmount, err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err = xerrors.Errorf("failed to get available balance: %w", r)
|
||||
available = abi.NewTokenAmount(0)
|
||||
}
|
||||
}()
|
||||
// this panics if the miner doesnt have enough funds to cover their locked pledge
|
||||
available, err = s.GetAvailableBalance(bal)
|
||||
return available, err
|
||||
}
|
||||
|
||||
func (s *state7) VestedFunds(epoch abi.ChainEpoch) (abi.TokenAmount, error) {
|
||||
return s.CheckVestedFunds(s.store, epoch)
|
||||
}
|
||||
|
||||
func (s *state7) LockedFunds() (LockedFunds, error) {
|
||||
return LockedFunds{
|
||||
VestingFunds: s.State.LockedFunds,
|
||||
InitialPledgeRequirement: s.State.InitialPledge,
|
||||
PreCommitDeposits: s.State.PreCommitDeposits,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *state7) FeeDebt() (abi.TokenAmount, error) {
|
||||
return s.State.FeeDebt, nil
|
||||
}
|
||||
|
||||
func (s *state7) InitialPledge() (abi.TokenAmount, error) {
|
||||
return s.State.InitialPledge, nil
|
||||
}
|
||||
|
||||
func (s *state7) PreCommitDeposits() (abi.TokenAmount, error) {
|
||||
return s.State.PreCommitDeposits, nil
|
||||
}
|
||||
|
||||
func (s *state7) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) {
|
||||
info, ok, err := s.State.GetSector(s.store, num)
|
||||
if !ok || err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret := fromV7SectorOnChainInfo(*info)
|
||||
return &ret, nil
|
||||
}
|
||||
|
||||
func (s *state7) FindSector(num abi.SectorNumber) (*SectorLocation, error) {
|
||||
dlIdx, partIdx, err := s.State.FindSector(s.store, num)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &SectorLocation{
|
||||
Deadline: dlIdx,
|
||||
Partition: partIdx,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *state7) NumLiveSectors() (uint64, error) {
|
||||
dls, err := s.State.LoadDeadlines(s.store)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
var total uint64
|
||||
if err := dls.ForEach(s.store, func(dlIdx uint64, dl *miner7.Deadline) error {
|
||||
total += dl.LiveSectors
|
||||
return nil
|
||||
}); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return total, nil
|
||||
}
|
||||
|
||||
// GetSectorExpiration returns the effective expiration of the given sector.
|
||||
//
|
||||
// If the sector does not expire early, the Early expiration field is 0.
|
||||
func (s *state7) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, error) {
|
||||
dls, err := s.State.LoadDeadlines(s.store)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// NOTE: this can be optimized significantly.
|
||||
// 1. If the sector is non-faulty, it will either expire on-time (can be
|
||||
// learned from the sector info), or in the next quantized expiration
|
||||
// epoch (i.e., the first element in the partition's expiration queue.
|
||||
// 2. If it's faulty, it will expire early within the first 14 entries
|
||||
// of the expiration queue.
|
||||
stopErr := errors.New("stop")
|
||||
out := SectorExpiration{}
|
||||
err = dls.ForEach(s.store, func(dlIdx uint64, dl *miner7.Deadline) error {
|
||||
partitions, err := dl.PartitionsArray(s.store)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
quant := s.State.QuantSpecForDeadline(dlIdx)
|
||||
var part miner7.Partition
|
||||
return partitions.ForEach(&part, func(partIdx int64) error {
|
||||
if found, err := part.Sectors.IsSet(uint64(num)); err != nil {
|
||||
return err
|
||||
} else if !found {
|
||||
return nil
|
||||
}
|
||||
if found, err := part.Terminated.IsSet(uint64(num)); err != nil {
|
||||
return err
|
||||
} else if found {
|
||||
// already terminated
|
||||
return stopErr
|
||||
}
|
||||
|
||||
q, err := miner7.LoadExpirationQueue(s.store, part.ExpirationsEpochs, quant, miner7.PartitionExpirationAmtBitwidth)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var exp miner7.ExpirationSet
|
||||
return q.ForEach(&exp, func(epoch int64) error {
|
||||
if early, err := exp.EarlySectors.IsSet(uint64(num)); err != nil {
|
||||
return err
|
||||
} else if early {
|
||||
out.Early = abi.ChainEpoch(epoch)
|
||||
return nil
|
||||
}
|
||||
if onTime, err := exp.OnTimeSectors.IsSet(uint64(num)); err != nil {
|
||||
return err
|
||||
} else if onTime {
|
||||
out.OnTime = abi.ChainEpoch(epoch)
|
||||
return stopErr
|
||||
}
|
||||
return nil
|
||||
})
|
||||
})
|
||||
})
|
||||
if err == stopErr {
|
||||
err = nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if out.Early == 0 && out.OnTime == 0 {
|
||||
return nil, xerrors.Errorf("failed to find sector %d", num)
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func (s *state7) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) {
|
||||
info, ok, err := s.State.GetPrecommittedSector(s.store, num)
|
||||
if !ok || err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret := fromV7SectorPreCommitOnChainInfo(*info)
|
||||
|
||||
return &ret, nil
|
||||
}
|
||||
|
||||
func (s *state7) ForEachPrecommittedSector(cb func(SectorPreCommitOnChainInfo) error) error {
|
||||
precommitted, err := adt7.AsMap(s.store, s.State.PreCommittedSectors, builtin7.DefaultHamtBitwidth)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var info miner7.SectorPreCommitOnChainInfo
|
||||
if err := precommitted.ForEach(&info, func(_ string) error {
|
||||
return cb(fromV7SectorPreCommitOnChainInfo(info))
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *state7) LoadSectors(snos *bitfield.BitField) ([]*SectorOnChainInfo, error) {
|
||||
sectors, err := miner7.LoadSectors(s.store, s.State.Sectors)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// If no sector numbers are specified, load all.
|
||||
if snos == nil {
|
||||
infos := make([]*SectorOnChainInfo, 0, sectors.Length())
|
||||
var info7 miner7.SectorOnChainInfo
|
||||
if err := sectors.ForEach(&info7, func(_ int64) error {
|
||||
info := fromV7SectorOnChainInfo(info7)
|
||||
infos = append(infos, &info)
|
||||
return nil
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return infos, nil
|
||||
}
|
||||
|
||||
// Otherwise, load selected.
|
||||
infos7, err := sectors.Load(*snos)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
infos := make([]*SectorOnChainInfo, len(infos7))
|
||||
for i, info7 := range infos7 {
|
||||
info := fromV7SectorOnChainInfo(*info7)
|
||||
infos[i] = &info
|
||||
}
|
||||
return infos, nil
|
||||
}
|
||||
|
||||
func (s *state7) loadAllocatedSectorNumbers() (bitfield.BitField, error) {
|
||||
var allocatedSectors bitfield.BitField
|
||||
err := s.store.Get(s.store.Context(), s.State.AllocatedSectors, &allocatedSectors)
|
||||
return allocatedSectors, err
|
||||
}
|
||||
|
||||
func (s *state7) IsAllocated(num abi.SectorNumber) (bool, error) {
|
||||
allocatedSectors, err := s.loadAllocatedSectorNumbers()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return allocatedSectors.IsSet(uint64(num))
|
||||
}
|
||||
|
||||
func (s *state7) GetProvingPeriodStart() (abi.ChainEpoch, error) {
|
||||
return s.State.ProvingPeriodStart, nil
|
||||
}
|
||||
|
||||
func (s *state7) UnallocatedSectorNumbers(count int) ([]abi.SectorNumber, error) {
|
||||
allocatedSectors, err := s.loadAllocatedSectorNumbers()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
allocatedRuns, err := allocatedSectors.RunIterator()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
unallocatedRuns, err := rle.Subtract(
|
||||
&rle.RunSliceIterator{Runs: []rle.Run{{Val: true, Len: abi.MaxSectorNumber}}},
|
||||
allocatedRuns,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
iter, err := rle.BitsFromRuns(unallocatedRuns)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sectors := make([]abi.SectorNumber, 0, count)
|
||||
for iter.HasNext() && len(sectors) < count {
|
||||
nextNo, err := iter.Next()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sectors = append(sectors, abi.SectorNumber(nextNo))
|
||||
}
|
||||
|
||||
return sectors, nil
|
||||
}
|
||||
|
||||
func (s *state7) GetAllocatedSectors() (*bitfield.BitField, error) {
|
||||
var allocatedSectors bitfield.BitField
|
||||
if err := s.store.Get(s.store.Context(), s.State.AllocatedSectors, &allocatedSectors); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &allocatedSectors, nil
|
||||
}
|
||||
|
||||
func (s *state7) LoadDeadline(idx uint64) (Deadline, error) {
|
||||
dls, err := s.State.LoadDeadlines(s.store)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dl, err := dls.LoadDeadline(s.store, idx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &deadline7{*dl, s.store}, nil
|
||||
}
|
||||
|
||||
func (s *state7) ForEachDeadline(cb func(uint64, Deadline) error) error {
|
||||
dls, err := s.State.LoadDeadlines(s.store)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return dls.ForEach(s.store, func(i uint64, dl *miner7.Deadline) error {
|
||||
return cb(i, &deadline7{*dl, s.store})
|
||||
})
|
||||
}
|
||||
|
||||
func (s *state7) NumDeadlines() (uint64, error) {
|
||||
return miner7.WPoStPeriodDeadlines, nil
|
||||
}
|
||||
|
||||
func (s *state7) DeadlinesChanged(other State) (bool, error) {
|
||||
other7, ok := other.(*state7)
|
||||
if !ok {
|
||||
// treat an upgrade as a change, always
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return !s.State.Deadlines.Equals(other7.Deadlines), nil
|
||||
}
|
||||
|
||||
func (s *state7) MinerInfoChanged(other State) (bool, error) {
|
||||
other0, ok := other.(*state7)
|
||||
if !ok {
|
||||
// treat an upgrade as a change, always
|
||||
return true, nil
|
||||
}
|
||||
return !s.State.Info.Equals(other0.State.Info), nil
|
||||
}
|
||||
|
||||
func (s *state7) Info() (MinerInfo, error) {
|
||||
info, err := s.State.GetInfo(s.store)
|
||||
if err != nil {
|
||||
return MinerInfo{}, err
|
||||
}
|
||||
|
||||
var pid *peer.ID
|
||||
if peerID, err := peer.IDFromBytes(info.PeerId); err == nil {
|
||||
pid = &peerID
|
||||
}
|
||||
|
||||
mi := MinerInfo{
|
||||
Owner: info.Owner,
|
||||
Worker: info.Worker,
|
||||
ControlAddresses: info.ControlAddresses,
|
||||
|
||||
NewWorker: address.Undef,
|
||||
WorkerChangeEpoch: -1,
|
||||
|
||||
PeerId: pid,
|
||||
Multiaddrs: info.Multiaddrs,
|
||||
WindowPoStProofType: info.WindowPoStProofType,
|
||||
SectorSize: info.SectorSize,
|
||||
WindowPoStPartitionSectors: info.WindowPoStPartitionSectors,
|
||||
ConsensusFaultElapsed: info.ConsensusFaultElapsed,
|
||||
}
|
||||
|
||||
if info.PendingWorkerKey != nil {
|
||||
mi.NewWorker = info.PendingWorkerKey.NewWorker
|
||||
mi.WorkerChangeEpoch = info.PendingWorkerKey.EffectiveAt
|
||||
}
|
||||
|
||||
return mi, nil
|
||||
}
|
||||
|
||||
func (s *state7) DeadlineInfo(epoch abi.ChainEpoch) (*dline.Info, error) {
|
||||
return s.State.RecordedDeadlineInfo(epoch), nil
|
||||
}
|
||||
|
||||
func (s *state7) DeadlineCronActive() (bool, error) {
|
||||
return s.State.DeadlineCronActive, nil
|
||||
}
|
||||
|
||||
func (s *state7) sectors() (adt.Array, error) {
|
||||
return adt7.AsArray(s.store, s.Sectors, miner7.SectorsAmtBitwidth)
|
||||
}
|
||||
|
||||
func (s *state7) decodeSectorOnChainInfo(val *cbg.Deferred) (SectorOnChainInfo, error) {
|
||||
var si miner7.SectorOnChainInfo
|
||||
err := si.UnmarshalCBOR(bytes.NewReader(val.Raw))
|
||||
if err != nil {
|
||||
return SectorOnChainInfo{}, err
|
||||
}
|
||||
|
||||
return fromV7SectorOnChainInfo(si), nil
|
||||
}
|
||||
|
||||
func (s *state7) precommits() (adt.Map, error) {
|
||||
return adt7.AsMap(s.store, s.PreCommittedSectors, builtin7.DefaultHamtBitwidth)
|
||||
}
|
||||
|
||||
func (s *state7) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreCommitOnChainInfo, error) {
|
||||
var sp miner7.SectorPreCommitOnChainInfo
|
||||
err := sp.UnmarshalCBOR(bytes.NewReader(val.Raw))
|
||||
if err != nil {
|
||||
return SectorPreCommitOnChainInfo{}, err
|
||||
}
|
||||
|
||||
return fromV7SectorPreCommitOnChainInfo(sp), nil
|
||||
}
|
||||
|
||||
func (s *state7) EraseAllUnproven() error {
|
||||
|
||||
dls, err := s.State.LoadDeadlines(s.store)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = dls.ForEach(s.store, func(dindx uint64, dl *miner7.Deadline) error {
|
||||
ps, err := dl.PartitionsArray(s.store)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var part miner7.Partition
|
||||
err = ps.ForEach(&part, func(pindx int64) error {
|
||||
_ = part.ActivateUnproven()
|
||||
err = ps.Set(uint64(pindx), &part)
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dl.Partitions, err = ps.Root()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return dls.UpdateDeadline(s.store, dindx, dl)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return s.State.SaveDeadlines(s.store, dls)
|
||||
|
||||
}
|
||||
|
||||
func (d *deadline7) LoadPartition(idx uint64) (Partition, error) {
|
||||
p, err := d.Deadline.LoadPartition(d.store, idx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &partition7{*p, d.store}, nil
|
||||
}
|
||||
|
||||
func (d *deadline7) ForEachPartition(cb func(uint64, Partition) error) error {
|
||||
ps, err := d.Deadline.PartitionsArray(d.store)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var part miner7.Partition
|
||||
return ps.ForEach(&part, func(i int64) error {
|
||||
return cb(uint64(i), &partition7{part, d.store})
|
||||
})
|
||||
}
|
||||
|
||||
func (d *deadline7) PartitionsChanged(other Deadline) (bool, error) {
|
||||
other7, ok := other.(*deadline7)
|
||||
if !ok {
|
||||
// treat an upgrade as a change, always
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return !d.Deadline.Partitions.Equals(other7.Deadline.Partitions), nil
|
||||
}
|
||||
|
||||
func (d *deadline7) PartitionsPoSted() (bitfield.BitField, error) {
|
||||
return d.Deadline.PartitionsPoSted, nil
|
||||
}
|
||||
|
||||
func (d *deadline7) DisputableProofCount() (uint64, error) {
|
||||
|
||||
ops, err := d.OptimisticProofsSnapshotArray(d.store)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return ops.Length(), nil
|
||||
|
||||
}
|
||||
|
||||
func (p *partition7) AllSectors() (bitfield.BitField, error) {
|
||||
return p.Partition.Sectors, nil
|
||||
}
|
||||
|
||||
func (p *partition7) FaultySectors() (bitfield.BitField, error) {
|
||||
return p.Partition.Faults, nil
|
||||
}
|
||||
|
||||
func (p *partition7) RecoveringSectors() (bitfield.BitField, error) {
|
||||
return p.Partition.Recoveries, nil
|
||||
}
|
||||
|
||||
func (p *partition7) UnprovenSectors() (bitfield.BitField, error) {
|
||||
return p.Partition.Unproven, nil
|
||||
}
|
||||
|
||||
func fromV7SectorOnChainInfo(v7 miner7.SectorOnChainInfo) SectorOnChainInfo {
|
||||
|
||||
return SectorOnChainInfo{
|
||||
SectorNumber: v7.SectorNumber,
|
||||
SealProof: v7.SealProof,
|
||||
SealedCID: v7.SealedCID,
|
||||
DealIDs: v7.DealIDs,
|
||||
Activation: v7.Activation,
|
||||
Expiration: v7.Expiration,
|
||||
DealWeight: v7.DealWeight,
|
||||
VerifiedDealWeight: v7.VerifiedDealWeight,
|
||||
InitialPledge: v7.InitialPledge,
|
||||
ExpectedDayReward: v7.ExpectedDayReward,
|
||||
ExpectedStoragePledge: v7.ExpectedStoragePledge,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func fromV7SectorPreCommitOnChainInfo(v7 miner7.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo {
|
||||
|
||||
return SectorPreCommitOnChainInfo{
|
||||
Info: (SectorPreCommitInfo)(v7.Info),
|
||||
PreCommitDeposit: v7.PreCommitDeposit,
|
||||
PreCommitEpoch: v7.PreCommitEpoch,
|
||||
DealWeight: v7.DealWeight,
|
||||
VerifiedDealWeight: v7.VerifiedDealWeight,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *state7) GetState() interface{} {
|
||||
return &s.State
|
||||
}
|
71
chain/actors/builtin/multisig/message7.go
Normal file
71
chain/actors/builtin/multisig/message7.go
Normal file
@ -0,0 +1,71 @@
|
||||
package multisig
|
||||
|
||||
import (
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
init7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/init"
|
||||
multisig7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/multisig"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
)
|
||||
|
||||
type message7 struct{ message0 }
|
||||
|
||||
func (m message7) Create(
|
||||
signers []address.Address, threshold uint64,
|
||||
unlockStart, unlockDuration abi.ChainEpoch,
|
||||
initialAmount abi.TokenAmount,
|
||||
) (*types.Message, error) {
|
||||
|
||||
lenAddrs := uint64(len(signers))
|
||||
|
||||
if lenAddrs < threshold {
|
||||
return nil, xerrors.Errorf("cannot require signing of more addresses than provided for multisig")
|
||||
}
|
||||
|
||||
if threshold == 0 {
|
||||
threshold = lenAddrs
|
||||
}
|
||||
|
||||
if m.from == address.Undef {
|
||||
return nil, xerrors.Errorf("must provide source address")
|
||||
}
|
||||
|
||||
// Set up constructor parameters for multisig
|
||||
msigParams := &multisig7.ConstructorParams{
|
||||
Signers: signers,
|
||||
NumApprovalsThreshold: threshold,
|
||||
UnlockDuration: unlockDuration,
|
||||
StartEpoch: unlockStart,
|
||||
}
|
||||
|
||||
enc, actErr := actors.SerializeParams(msigParams)
|
||||
if actErr != nil {
|
||||
return nil, actErr
|
||||
}
|
||||
|
||||
// new actors are created by invoking 'exec' on the init actor with the constructor params
|
||||
execParams := &init7.ExecParams{
|
||||
CodeCID: builtin7.MultisigActorCodeID,
|
||||
ConstructorParams: enc,
|
||||
}
|
||||
|
||||
enc, actErr = actors.SerializeParams(execParams)
|
||||
if actErr != nil {
|
||||
return nil, actErr
|
||||
}
|
||||
|
||||
return &types.Message{
|
||||
To: init_.Address,
|
||||
From: m.from,
|
||||
Method: builtin7.MethodsInit.Exec,
|
||||
Params: enc,
|
||||
Value: initialAmount,
|
||||
}, nil
|
||||
}
|
@ -13,7 +13,7 @@ import (
|
||||
"github.com/ipfs/go-cid"
|
||||
|
||||
msig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig"
|
||||
msig6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/multisig"
|
||||
msig7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/multisig"
|
||||
|
||||
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
||||
|
||||
@ -27,6 +27,8 @@ import (
|
||||
|
||||
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||
@ -58,6 +60,10 @@ func init() {
|
||||
builtin.RegisterActorState(builtin6.MultisigActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load6(store, root)
|
||||
})
|
||||
|
||||
builtin.RegisterActorState(builtin7.MultisigActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load7(store, root)
|
||||
})
|
||||
}
|
||||
|
||||
func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
@ -81,6 +87,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
case builtin6.MultisigActorCodeID:
|
||||
return load6(store, act.Head)
|
||||
|
||||
case builtin7.MultisigActorCodeID:
|
||||
return load7(store, act.Head)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||
}
|
||||
@ -106,6 +115,9 @@ func MakeState(store adt.Store, av actors.Version, signers []address.Address, th
|
||||
case actors.Version6:
|
||||
return make6(store, signers, threshold, startEpoch, unlockDuration, initialBalance)
|
||||
|
||||
case actors.Version7:
|
||||
return make7(store, signers, threshold, startEpoch, unlockDuration, initialBalance)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor version %d", av)
|
||||
}
|
||||
@ -131,6 +143,9 @@ func GetActorCodeID(av actors.Version) (cid.Cid, error) {
|
||||
case actors.Version6:
|
||||
return builtin6.MultisigActorCodeID, nil
|
||||
|
||||
case actors.Version7:
|
||||
return builtin7.MultisigActorCodeID, nil
|
||||
|
||||
}
|
||||
|
||||
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
|
||||
@ -156,7 +171,7 @@ type State interface {
|
||||
|
||||
type Transaction = msig0.Transaction
|
||||
|
||||
var Methods = builtin6.MethodsMultisig
|
||||
var Methods = builtin7.MethodsMultisig
|
||||
|
||||
func Message(version actors.Version, from address.Address) MessageBuilder {
|
||||
switch version {
|
||||
@ -178,6 +193,9 @@ func Message(version actors.Version, from address.Address) MessageBuilder {
|
||||
|
||||
case actors.Version6:
|
||||
return message6{message0{from}}
|
||||
|
||||
case actors.Version7:
|
||||
return message7{message0{from}}
|
||||
default:
|
||||
panic(fmt.Sprintf("unsupported actors version: %d", version))
|
||||
}
|
||||
@ -201,13 +219,13 @@ type MessageBuilder interface {
|
||||
}
|
||||
|
||||
// this type is the same between v0 and v2
|
||||
type ProposalHashData = msig6.ProposalHashData
|
||||
type ProposeReturn = msig6.ProposeReturn
|
||||
type ProposeParams = msig6.ProposeParams
|
||||
type ApproveReturn = msig6.ApproveReturn
|
||||
type ProposalHashData = msig7.ProposalHashData
|
||||
type ProposeReturn = msig7.ProposeReturn
|
||||
type ProposeParams = msig7.ProposeParams
|
||||
type ApproveReturn = msig7.ApproveReturn
|
||||
|
||||
func txnParams(id uint64, data *ProposalHashData) ([]byte, error) {
|
||||
params := msig6.TxnIDParams{ID: msig6.TxnID(id)}
|
||||
params := msig7.TxnIDParams{ID: msig7.TxnID(id)}
|
||||
if data != nil {
|
||||
if data.Requester.Protocol() != address.ID {
|
||||
return nil, xerrors.Errorf("proposer address must be an ID address, was %s", data.Requester)
|
||||
|
119
chain/actors/builtin/multisig/v7.go
Normal file
119
chain/actors/builtin/multisig/v7.go
Normal file
@ -0,0 +1,119 @@
|
||||
package multisig
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
|
||||
adt7 "github.com/filecoin-project/specs-actors/v7/actors/util/adt"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/ipfs/go-cid"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
|
||||
msig7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/multisig"
|
||||
)
|
||||
|
||||
var _ State = (*state7)(nil)
|
||||
|
||||
func load7(store adt.Store, root cid.Cid) (State, error) {
|
||||
out := state7{store: store}
|
||||
err := store.Get(store.Context(), root, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func make7(store adt.Store, signers []address.Address, threshold uint64, startEpoch abi.ChainEpoch, unlockDuration abi.ChainEpoch, initialBalance abi.TokenAmount) (State, error) {
|
||||
out := state7{store: store}
|
||||
out.State = msig7.State{}
|
||||
out.State.Signers = signers
|
||||
out.State.NumApprovalsThreshold = threshold
|
||||
out.State.StartEpoch = startEpoch
|
||||
out.State.UnlockDuration = unlockDuration
|
||||
out.State.InitialBalance = initialBalance
|
||||
|
||||
em, err := adt7.StoreEmptyMap(store, builtin7.DefaultHamtBitwidth)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out.State.PendingTxns = em
|
||||
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
type state7 struct {
|
||||
msig7.State
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
func (s *state7) LockedBalance(currEpoch abi.ChainEpoch) (abi.TokenAmount, error) {
|
||||
return s.State.AmountLocked(currEpoch - s.State.StartEpoch), nil
|
||||
}
|
||||
|
||||
func (s *state7) StartEpoch() (abi.ChainEpoch, error) {
|
||||
return s.State.StartEpoch, nil
|
||||
}
|
||||
|
||||
func (s *state7) UnlockDuration() (abi.ChainEpoch, error) {
|
||||
return s.State.UnlockDuration, nil
|
||||
}
|
||||
|
||||
func (s *state7) InitialBalance() (abi.TokenAmount, error) {
|
||||
return s.State.InitialBalance, nil
|
||||
}
|
||||
|
||||
func (s *state7) Threshold() (uint64, error) {
|
||||
return s.State.NumApprovalsThreshold, nil
|
||||
}
|
||||
|
||||
func (s *state7) Signers() ([]address.Address, error) {
|
||||
return s.State.Signers, nil
|
||||
}
|
||||
|
||||
func (s *state7) ForEachPendingTxn(cb func(id int64, txn Transaction) error) error {
|
||||
arr, err := adt7.AsMap(s.store, s.State.PendingTxns, builtin7.DefaultHamtBitwidth)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var out msig7.Transaction
|
||||
return arr.ForEach(&out, func(key string) error {
|
||||
txid, n := binary.Varint([]byte(key))
|
||||
if n <= 0 {
|
||||
return xerrors.Errorf("invalid pending transaction key: %v", key)
|
||||
}
|
||||
return cb(txid, (Transaction)(out)) //nolint:unconvert
|
||||
})
|
||||
}
|
||||
|
||||
func (s *state7) PendingTxnChanged(other State) (bool, error) {
|
||||
other7, ok := other.(*state7)
|
||||
if !ok {
|
||||
// treat an upgrade as a change, always
|
||||
return true, nil
|
||||
}
|
||||
return !s.State.PendingTxns.Equals(other7.PendingTxns), nil
|
||||
}
|
||||
|
||||
func (s *state7) transactions() (adt.Map, error) {
|
||||
return adt7.AsMap(s.store, s.PendingTxns, builtin7.DefaultHamtBitwidth)
|
||||
}
|
||||
|
||||
func (s *state7) decodeTransaction(val *cbg.Deferred) (Transaction, error) {
|
||||
var tx msig7.Transaction
|
||||
if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
||||
return Transaction{}, err
|
||||
}
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
func (s *state7) GetState() interface{} {
|
||||
return &s.State
|
||||
}
|
74
chain/actors/builtin/paych/message7.go
Normal file
74
chain/actors/builtin/paych/message7.go
Normal file
@ -0,0 +1,74 @@
|
||||
package paych
|
||||
|
||||
import (
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
init7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/init"
|
||||
paych7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/paych"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
)
|
||||
|
||||
type message7 struct{ from address.Address }
|
||||
|
||||
func (m message7) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) {
|
||||
params, aerr := actors.SerializeParams(&paych7.ConstructorParams{From: m.from, To: to})
|
||||
if aerr != nil {
|
||||
return nil, aerr
|
||||
}
|
||||
enc, aerr := actors.SerializeParams(&init7.ExecParams{
|
||||
CodeCID: builtin7.PaymentChannelActorCodeID,
|
||||
ConstructorParams: params,
|
||||
})
|
||||
if aerr != nil {
|
||||
return nil, aerr
|
||||
}
|
||||
|
||||
return &types.Message{
|
||||
To: init_.Address,
|
||||
From: m.from,
|
||||
Value: initialAmount,
|
||||
Method: builtin7.MethodsInit.Exec,
|
||||
Params: enc,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m message7) Update(paych address.Address, sv *SignedVoucher, secret []byte) (*types.Message, error) {
|
||||
params, aerr := actors.SerializeParams(&paych7.UpdateChannelStateParams{
|
||||
Sv: *sv,
|
||||
Secret: secret,
|
||||
})
|
||||
if aerr != nil {
|
||||
return nil, aerr
|
||||
}
|
||||
|
||||
return &types.Message{
|
||||
To: paych,
|
||||
From: m.from,
|
||||
Value: abi.NewTokenAmount(0),
|
||||
Method: builtin7.MethodsPaych.UpdateChannelState,
|
||||
Params: params,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m message7) Settle(paych address.Address) (*types.Message, error) {
|
||||
return &types.Message{
|
||||
To: paych,
|
||||
From: m.from,
|
||||
Value: abi.NewTokenAmount(0),
|
||||
Method: builtin7.MethodsPaych.Settle,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m message7) Collect(paych address.Address) (*types.Message, error) {
|
||||
return &types.Message{
|
||||
To: paych,
|
||||
From: m.from,
|
||||
Value: abi.NewTokenAmount(0),
|
||||
Method: builtin7.MethodsPaych.Collect,
|
||||
}, nil
|
||||
}
|
@ -27,6 +27,8 @@ import (
|
||||
|
||||
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||
@ -58,6 +60,10 @@ func init() {
|
||||
builtin.RegisterActorState(builtin6.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load6(store, root)
|
||||
})
|
||||
|
||||
builtin.RegisterActorState(builtin7.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load7(store, root)
|
||||
})
|
||||
}
|
||||
|
||||
// Load returns an abstract copy of payment channel state, irregardless of actor version
|
||||
@ -82,6 +88,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
case builtin6.PaymentChannelActorCodeID:
|
||||
return load6(store, act.Head)
|
||||
|
||||
case builtin7.PaymentChannelActorCodeID:
|
||||
return load7(store, act.Head)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||
}
|
||||
@ -107,6 +116,9 @@ func MakeState(store adt.Store, av actors.Version) (State, error) {
|
||||
case actors.Version6:
|
||||
return make6(store)
|
||||
|
||||
case actors.Version7:
|
||||
return make7(store)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor version %d", av)
|
||||
}
|
||||
@ -132,6 +144,9 @@ func GetActorCodeID(av actors.Version) (cid.Cid, error) {
|
||||
case actors.Version6:
|
||||
return builtin6.PaymentChannelActorCodeID, nil
|
||||
|
||||
case actors.Version7:
|
||||
return builtin7.PaymentChannelActorCodeID, nil
|
||||
|
||||
}
|
||||
|
||||
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
|
||||
@ -185,7 +200,7 @@ func DecodeSignedVoucher(s string) (*SignedVoucher, error) {
|
||||
return &sv, nil
|
||||
}
|
||||
|
||||
var Methods = builtin6.MethodsPaych
|
||||
var Methods = builtin7.MethodsPaych
|
||||
|
||||
func Message(version actors.Version, from address.Address) MessageBuilder {
|
||||
switch version {
|
||||
@ -208,6 +223,9 @@ func Message(version actors.Version, from address.Address) MessageBuilder {
|
||||
case actors.Version6:
|
||||
return message6{from}
|
||||
|
||||
case actors.Version7:
|
||||
return message7{from}
|
||||
|
||||
default:
|
||||
panic(fmt.Sprintf("unsupported actors version: %d", version))
|
||||
}
|
||||
|
114
chain/actors/builtin/paych/v7.go
Normal file
114
chain/actors/builtin/paych/v7.go
Normal file
@ -0,0 +1,114 @@
|
||||
package paych
|
||||
|
||||
import (
|
||||
"github.com/ipfs/go-cid"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/go-state-types/big"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
|
||||
paych7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/paych"
|
||||
adt7 "github.com/filecoin-project/specs-actors/v7/actors/util/adt"
|
||||
)
|
||||
|
||||
var _ State = (*state7)(nil)
|
||||
|
||||
func load7(store adt.Store, root cid.Cid) (State, error) {
|
||||
out := state7{store: store}
|
||||
err := store.Get(store.Context(), root, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func make7(store adt.Store) (State, error) {
|
||||
out := state7{store: store}
|
||||
out.State = paych7.State{}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
type state7 struct {
|
||||
paych7.State
|
||||
store adt.Store
|
||||
lsAmt *adt7.Array
|
||||
}
|
||||
|
||||
// Channel owner, who has funded the actor
|
||||
func (s *state7) From() (address.Address, error) {
|
||||
return s.State.From, nil
|
||||
}
|
||||
|
||||
// Recipient of payouts from channel
|
||||
func (s *state7) To() (address.Address, error) {
|
||||
return s.State.To, nil
|
||||
}
|
||||
|
||||
// Height at which the channel can be `Collected`
|
||||
func (s *state7) SettlingAt() (abi.ChainEpoch, error) {
|
||||
return s.State.SettlingAt, nil
|
||||
}
|
||||
|
||||
// Amount successfully redeemed through the payment channel, paid out on `Collect()`
|
||||
func (s *state7) ToSend() (abi.TokenAmount, error) {
|
||||
return s.State.ToSend, nil
|
||||
}
|
||||
|
||||
func (s *state7) getOrLoadLsAmt() (*adt7.Array, error) {
|
||||
if s.lsAmt != nil {
|
||||
return s.lsAmt, nil
|
||||
}
|
||||
|
||||
// Get the lane state from the chain
|
||||
lsamt, err := adt7.AsArray(s.store, s.State.LaneStates, paych7.LaneStatesAmtBitwidth)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s.lsAmt = lsamt
|
||||
return lsamt, nil
|
||||
}
|
||||
|
||||
// Get total number of lanes
|
||||
func (s *state7) LaneCount() (uint64, error) {
|
||||
lsamt, err := s.getOrLoadLsAmt()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return lsamt.Length(), nil
|
||||
}
|
||||
|
||||
func (s *state7) GetState() interface{} {
|
||||
return &s.State
|
||||
}
|
||||
|
||||
// Iterate lane states
|
||||
func (s *state7) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error {
|
||||
// Get the lane state from the chain
|
||||
lsamt, err := s.getOrLoadLsAmt()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Note: we use a map instead of an array to store laneStates because the
|
||||
// client sets the lane ID (the index) and potentially they could use a
|
||||
// very large index.
|
||||
var ls paych7.LaneState
|
||||
return lsamt.ForEach(&ls, func(i int64) error {
|
||||
return cb(uint64(i), &laneState7{ls})
|
||||
})
|
||||
}
|
||||
|
||||
type laneState7 struct {
|
||||
paych7.LaneState
|
||||
}
|
||||
|
||||
func (ls *laneState7) Redeemed() (big.Int, error) {
|
||||
return ls.LaneState.Redeemed, nil
|
||||
}
|
||||
|
||||
func (ls *laneState7) Nonce() (uint64, error) {
|
||||
return ls.LaneState.Nonce, nil
|
||||
}
|
@ -26,6 +26,8 @@ import (
|
||||
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"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -53,11 +55,15 @@ func init() {
|
||||
builtin.RegisterActorState(builtin6.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load6(store, root)
|
||||
})
|
||||
|
||||
builtin.RegisterActorState(builtin7.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load7(store, root)
|
||||
})
|
||||
}
|
||||
|
||||
var (
|
||||
Address = builtin6.StoragePowerActorAddr
|
||||
Methods = builtin6.MethodsPower
|
||||
Address = builtin7.StoragePowerActorAddr
|
||||
Methods = builtin7.MethodsPower
|
||||
)
|
||||
|
||||
func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
@ -81,6 +87,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
case builtin6.StoragePowerActorCodeID:
|
||||
return load6(store, act.Head)
|
||||
|
||||
case builtin7.StoragePowerActorCodeID:
|
||||
return load7(store, act.Head)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||
}
|
||||
@ -106,6 +115,9 @@ func MakeState(store adt.Store, av actors.Version) (State, error) {
|
||||
case actors.Version6:
|
||||
return make6(store)
|
||||
|
||||
case actors.Version7:
|
||||
return make7(store)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor version %d", av)
|
||||
}
|
||||
@ -131,6 +143,9 @@ func GetActorCodeID(av actors.Version) (cid.Cid, error) {
|
||||
case actors.Version6:
|
||||
return builtin6.StoragePowerActorCodeID, nil
|
||||
|
||||
case actors.Version7:
|
||||
return builtin7.StoragePowerActorCodeID, nil
|
||||
|
||||
}
|
||||
|
||||
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
|
||||
|
187
chain/actors/builtin/power/v7.go
Normal file
187
chain/actors/builtin/power/v7.go
Normal file
@ -0,0 +1,187 @@
|
||||
package power
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/ipfs/go-cid"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
|
||||
power7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/power"
|
||||
adt7 "github.com/filecoin-project/specs-actors/v7/actors/util/adt"
|
||||
)
|
||||
|
||||
var _ State = (*state7)(nil)
|
||||
|
||||
func load7(store adt.Store, root cid.Cid) (State, error) {
|
||||
out := state7{store: store}
|
||||
err := store.Get(store.Context(), root, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func make7(store adt.Store) (State, error) {
|
||||
out := state7{store: store}
|
||||
|
||||
s, err := power7.ConstructState(store)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out.State = *s
|
||||
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
type state7 struct {
|
||||
power7.State
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
func (s *state7) TotalLocked() (abi.TokenAmount, error) {
|
||||
return s.TotalPledgeCollateral, nil
|
||||
}
|
||||
|
||||
func (s *state7) TotalPower() (Claim, error) {
|
||||
return Claim{
|
||||
RawBytePower: s.TotalRawBytePower,
|
||||
QualityAdjPower: s.TotalQualityAdjPower,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Committed power to the network. Includes miners below the minimum threshold.
|
||||
func (s *state7) TotalCommitted() (Claim, error) {
|
||||
return Claim{
|
||||
RawBytePower: s.TotalBytesCommitted,
|
||||
QualityAdjPower: s.TotalQABytesCommitted,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *state7) MinerPower(addr address.Address) (Claim, bool, error) {
|
||||
claims, err := s.claims()
|
||||
if err != nil {
|
||||
return Claim{}, false, err
|
||||
}
|
||||
var claim power7.Claim
|
||||
ok, err := claims.Get(abi.AddrKey(addr), &claim)
|
||||
if err != nil {
|
||||
return Claim{}, false, err
|
||||
}
|
||||
return Claim{
|
||||
RawBytePower: claim.RawBytePower,
|
||||
QualityAdjPower: claim.QualityAdjPower,
|
||||
}, ok, nil
|
||||
}
|
||||
|
||||
func (s *state7) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (bool, error) {
|
||||
return s.State.MinerNominalPowerMeetsConsensusMinimum(s.store, a)
|
||||
}
|
||||
|
||||
func (s *state7) TotalPowerSmoothed() (builtin.FilterEstimate, error) {
|
||||
return builtin.FromV7FilterEstimate(s.State.ThisEpochQAPowerSmoothed), nil
|
||||
}
|
||||
|
||||
func (s *state7) MinerCounts() (uint64, uint64, error) {
|
||||
return uint64(s.State.MinerAboveMinPowerCount), uint64(s.State.MinerCount), nil
|
||||
}
|
||||
|
||||
func (s *state7) ListAllMiners() ([]address.Address, error) {
|
||||
claims, err := s.claims()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var miners []address.Address
|
||||
err = claims.ForEach(nil, func(k string) error {
|
||||
a, err := address.NewFromBytes([]byte(k))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
miners = append(miners, a)
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return miners, nil
|
||||
}
|
||||
|
||||
func (s *state7) ForEachClaim(cb func(miner address.Address, claim Claim) error) error {
|
||||
claims, err := s.claims()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var claim power7.Claim
|
||||
return claims.ForEach(&claim, func(k string) error {
|
||||
a, err := address.NewFromBytes([]byte(k))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cb(a, Claim{
|
||||
RawBytePower: claim.RawBytePower,
|
||||
QualityAdjPower: claim.QualityAdjPower,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (s *state7) ClaimsChanged(other State) (bool, error) {
|
||||
other7, ok := other.(*state7)
|
||||
if !ok {
|
||||
// treat an upgrade as a change, always
|
||||
return true, nil
|
||||
}
|
||||
return !s.State.Claims.Equals(other7.State.Claims), nil
|
||||
}
|
||||
|
||||
func (s *state7) SetTotalQualityAdjPower(p abi.StoragePower) error {
|
||||
s.State.TotalQualityAdjPower = p
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *state7) SetTotalRawBytePower(p abi.StoragePower) error {
|
||||
s.State.TotalRawBytePower = p
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *state7) SetThisEpochQualityAdjPower(p abi.StoragePower) error {
|
||||
s.State.ThisEpochQualityAdjPower = p
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *state7) SetThisEpochRawBytePower(p abi.StoragePower) error {
|
||||
s.State.ThisEpochRawBytePower = p
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *state7) GetState() interface{} {
|
||||
return &s.State
|
||||
}
|
||||
|
||||
func (s *state7) claims() (adt.Map, error) {
|
||||
return adt7.AsMap(s.store, s.Claims, builtin7.DefaultHamtBitwidth)
|
||||
}
|
||||
|
||||
func (s *state7) decodeClaim(val *cbg.Deferred) (Claim, error) {
|
||||
var ci power7.Claim
|
||||
if err := ci.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
||||
return Claim{}, err
|
||||
}
|
||||
return fromV7Claim(ci), nil
|
||||
}
|
||||
|
||||
func fromV7Claim(v7 power7.Claim) Claim {
|
||||
return Claim{
|
||||
RawBytePower: v7.RawBytePower,
|
||||
QualityAdjPower: v7.QualityAdjPower,
|
||||
}
|
||||
}
|
@ -21,6 +21,8 @@ import (
|
||||
|
||||
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
@ -51,11 +53,15 @@ func init() {
|
||||
builtin.RegisterActorState(builtin6.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load6(store, root)
|
||||
})
|
||||
|
||||
builtin.RegisterActorState(builtin7.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load7(store, root)
|
||||
})
|
||||
}
|
||||
|
||||
var (
|
||||
Address = builtin6.RewardActorAddr
|
||||
Methods = builtin6.MethodsReward
|
||||
Address = builtin7.RewardActorAddr
|
||||
Methods = builtin7.MethodsReward
|
||||
)
|
||||
|
||||
func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
@ -79,6 +85,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
case builtin6.RewardActorCodeID:
|
||||
return load6(store, act.Head)
|
||||
|
||||
case builtin7.RewardActorCodeID:
|
||||
return load7(store, act.Head)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||
}
|
||||
@ -104,6 +113,9 @@ func MakeState(store adt.Store, av actors.Version, currRealizedPower abi.Storage
|
||||
case actors.Version6:
|
||||
return make6(store, currRealizedPower)
|
||||
|
||||
case actors.Version7:
|
||||
return make7(store, currRealizedPower)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor version %d", av)
|
||||
}
|
||||
@ -129,6 +141,9 @@ func GetActorCodeID(av actors.Version) (cid.Cid, error) {
|
||||
case actors.Version6:
|
||||
return builtin6.RewardActorCodeID, nil
|
||||
|
||||
case actors.Version7:
|
||||
return builtin7.RewardActorCodeID, nil
|
||||
|
||||
}
|
||||
|
||||
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
|
||||
|
98
chain/actors/builtin/reward/v7.go
Normal file
98
chain/actors/builtin/reward/v7.go
Normal file
@ -0,0 +1,98 @@
|
||||
package reward
|
||||
|
||||
import (
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/ipfs/go-cid"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||
|
||||
miner7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/miner"
|
||||
reward7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/reward"
|
||||
smoothing7 "github.com/filecoin-project/specs-actors/v7/actors/util/smoothing"
|
||||
)
|
||||
|
||||
var _ State = (*state7)(nil)
|
||||
|
||||
func load7(store adt.Store, root cid.Cid) (State, error) {
|
||||
out := state7{store: store}
|
||||
err := store.Get(store.Context(), root, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func make7(store adt.Store, currRealizedPower abi.StoragePower) (State, error) {
|
||||
out := state7{store: store}
|
||||
out.State = *reward7.ConstructState(currRealizedPower)
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
type state7 struct {
|
||||
reward7.State
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
func (s *state7) ThisEpochReward() (abi.TokenAmount, error) {
|
||||
return s.State.ThisEpochReward, nil
|
||||
}
|
||||
|
||||
func (s *state7) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) {
|
||||
|
||||
return builtin.FilterEstimate{
|
||||
PositionEstimate: s.State.ThisEpochRewardSmoothed.PositionEstimate,
|
||||
VelocityEstimate: s.State.ThisEpochRewardSmoothed.VelocityEstimate,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func (s *state7) ThisEpochBaselinePower() (abi.StoragePower, error) {
|
||||
return s.State.ThisEpochBaselinePower, nil
|
||||
}
|
||||
|
||||
func (s *state7) TotalStoragePowerReward() (abi.TokenAmount, error) {
|
||||
return s.State.TotalStoragePowerReward, nil
|
||||
}
|
||||
|
||||
func (s *state7) EffectiveBaselinePower() (abi.StoragePower, error) {
|
||||
return s.State.EffectiveBaselinePower, nil
|
||||
}
|
||||
|
||||
func (s *state7) EffectiveNetworkTime() (abi.ChainEpoch, error) {
|
||||
return s.State.EffectiveNetworkTime, nil
|
||||
}
|
||||
|
||||
func (s *state7) CumsumBaseline() (reward7.Spacetime, error) {
|
||||
return s.State.CumsumBaseline, nil
|
||||
}
|
||||
|
||||
func (s *state7) CumsumRealized() (reward7.Spacetime, error) {
|
||||
return s.State.CumsumRealized, nil
|
||||
}
|
||||
|
||||
func (s *state7) InitialPledgeForPower(qaPower abi.StoragePower, networkTotalPledge abi.TokenAmount, networkQAPower *builtin.FilterEstimate, circSupply abi.TokenAmount) (abi.TokenAmount, error) {
|
||||
return miner7.InitialPledgeForPower(
|
||||
qaPower,
|
||||
s.State.ThisEpochBaselinePower,
|
||||
s.State.ThisEpochRewardSmoothed,
|
||||
smoothing7.FilterEstimate{
|
||||
PositionEstimate: networkQAPower.PositionEstimate,
|
||||
VelocityEstimate: networkQAPower.VelocityEstimate,
|
||||
},
|
||||
circSupply,
|
||||
), nil
|
||||
}
|
||||
|
||||
func (s *state7) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate, sectorWeight abi.StoragePower) (abi.TokenAmount, error) {
|
||||
return miner7.PreCommitDepositForPower(s.State.ThisEpochRewardSmoothed,
|
||||
smoothing7.FilterEstimate{
|
||||
PositionEstimate: networkQAPower.PositionEstimate,
|
||||
VelocityEstimate: networkQAPower.VelocityEstimate,
|
||||
},
|
||||
sectorWeight), nil
|
||||
}
|
||||
|
||||
func (s *state7) GetState() interface{} {
|
||||
return &s.State
|
||||
}
|
@ -17,10 +17,12 @@ import (
|
||||
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"
|
||||
)
|
||||
|
||||
var (
|
||||
Address = builtin6.SystemActorAddr
|
||||
Address = builtin7.SystemActorAddr
|
||||
)
|
||||
|
||||
func MakeState(store adt.Store, av actors.Version) (State, error) {
|
||||
@ -44,6 +46,9 @@ func MakeState(store adt.Store, av actors.Version) (State, error) {
|
||||
case actors.Version6:
|
||||
return make6(store)
|
||||
|
||||
case actors.Version7:
|
||||
return make7(store)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor version %d", av)
|
||||
}
|
||||
@ -69,6 +74,9 @@ func GetActorCodeID(av actors.Version) (cid.Cid, error) {
|
||||
case actors.Version6:
|
||||
return builtin6.SystemActorCodeID, nil
|
||||
|
||||
case actors.Version7:
|
||||
return builtin7.SystemActorCodeID, nil
|
||||
|
||||
}
|
||||
|
||||
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
|
||||
|
35
chain/actors/builtin/system/v7.go
Normal file
35
chain/actors/builtin/system/v7.go
Normal file
@ -0,0 +1,35 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/ipfs/go-cid"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
|
||||
system7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/system"
|
||||
)
|
||||
|
||||
var _ State = (*state7)(nil)
|
||||
|
||||
func load7(store adt.Store, root cid.Cid) (State, error) {
|
||||
out := state7{store: store}
|
||||
err := store.Get(store.Context(), root, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func make7(store adt.Store) (State, error) {
|
||||
out := state7{store: store}
|
||||
out.State = system7.State{}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
type state7 struct {
|
||||
system7.State
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
func (s *state7) GetState() interface{} {
|
||||
return &s.State
|
||||
}
|
75
chain/actors/builtin/verifreg/v7.go
Normal file
75
chain/actors/builtin/verifreg/v7.go
Normal file
@ -0,0 +1,75 @@
|
||||
package verifreg
|
||||
|
||||
import (
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/ipfs/go-cid"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
verifreg7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/verifreg"
|
||||
adt7 "github.com/filecoin-project/specs-actors/v7/actors/util/adt"
|
||||
)
|
||||
|
||||
var _ State = (*state7)(nil)
|
||||
|
||||
func load7(store adt.Store, root cid.Cid) (State, error) {
|
||||
out := state7{store: store}
|
||||
err := store.Get(store.Context(), root, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func make7(store adt.Store, rootKeyAddress address.Address) (State, error) {
|
||||
out := state7{store: store}
|
||||
|
||||
s, err := verifreg7.ConstructState(store, rootKeyAddress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out.State = *s
|
||||
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
type state7 struct {
|
||||
verifreg7.State
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
func (s *state7) RootKey() (address.Address, error) {
|
||||
return s.State.RootKey, nil
|
||||
}
|
||||
|
||||
func (s *state7) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) {
|
||||
return getDataCap(s.store, actors.Version7, s.verifiedClients, addr)
|
||||
}
|
||||
|
||||
func (s *state7) VerifierDataCap(addr address.Address) (bool, abi.StoragePower, error) {
|
||||
return getDataCap(s.store, actors.Version7, s.verifiers, addr)
|
||||
}
|
||||
|
||||
func (s *state7) ForEachVerifier(cb func(addr address.Address, dcap abi.StoragePower) error) error {
|
||||
return forEachCap(s.store, actors.Version7, s.verifiers, cb)
|
||||
}
|
||||
|
||||
func (s *state7) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error {
|
||||
return forEachCap(s.store, actors.Version7, s.verifiedClients, cb)
|
||||
}
|
||||
|
||||
func (s *state7) verifiedClients() (adt.Map, error) {
|
||||
return adt7.AsMap(s.store, s.VerifiedClients, builtin7.DefaultHamtBitwidth)
|
||||
}
|
||||
|
||||
func (s *state7) verifiers() (adt.Map, error) {
|
||||
return adt7.AsMap(s.store, s.Verifiers, builtin7.DefaultHamtBitwidth)
|
||||
}
|
||||
|
||||
func (s *state7) GetState() interface{} {
|
||||
return &s.State
|
||||
}
|
@ -21,6 +21,8 @@ import (
|
||||
|
||||
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||
@ -53,11 +55,15 @@ func init() {
|
||||
return load6(store, root)
|
||||
})
|
||||
|
||||
builtin.RegisterActorState(builtin7.VerifiedRegistryActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||
return load7(store, root)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
Address = builtin6.VerifiedRegistryActorAddr
|
||||
Methods = builtin6.MethodsVerifiedRegistry
|
||||
Address = builtin7.VerifiedRegistryActorAddr
|
||||
Methods = builtin7.MethodsVerifiedRegistry
|
||||
)
|
||||
|
||||
func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
@ -81,6 +87,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
case builtin6.VerifiedRegistryActorCodeID:
|
||||
return load6(store, act.Head)
|
||||
|
||||
case builtin7.VerifiedRegistryActorCodeID:
|
||||
return load7(store, act.Head)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||
}
|
||||
@ -106,6 +115,9 @@ func MakeState(store adt.Store, av actors.Version, rootKeyAddress address.Addres
|
||||
case actors.Version6:
|
||||
return make6(store, rootKeyAddress)
|
||||
|
||||
case actors.Version7:
|
||||
return make7(store, rootKeyAddress)
|
||||
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor version %d", av)
|
||||
}
|
||||
@ -131,6 +143,9 @@ func GetActorCodeID(av actors.Version) (cid.Cid, error) {
|
||||
case actors.Version6:
|
||||
return builtin6.VerifiedRegistryActorCodeID, nil
|
||||
|
||||
case actors.Version7:
|
||||
return builtin7.VerifiedRegistryActorCodeID, nil
|
||||
|
||||
}
|
||||
|
||||
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
|
||||
|
@ -40,14 +40,19 @@ import (
|
||||
miner6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/miner"
|
||||
verifreg6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/verifreg"
|
||||
|
||||
paych6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/paych"
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
market7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/market"
|
||||
miner7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/miner"
|
||||
verifreg7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/verifreg"
|
||||
|
||||
paych7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/paych"
|
||||
)
|
||||
|
||||
const (
|
||||
ChainFinality = miner6.ChainFinality
|
||||
ChainFinality = miner7.ChainFinality
|
||||
SealRandomnessLookback = ChainFinality
|
||||
PaychSettleDelay = paych6.SettleDelay
|
||||
MaxPreCommitRandomnessLookback = builtin6.EpochsInDay + SealRandomnessLookback
|
||||
PaychSettleDelay = paych7.SettleDelay
|
||||
MaxPreCommitRandomnessLookback = builtin7.EpochsInDay + SealRandomnessLookback
|
||||
)
|
||||
|
||||
// SetSupportedProofTypes sets supported proof types, across all actor versions.
|
||||
@ -72,6 +77,8 @@ func SetSupportedProofTypes(types ...abi.RegisteredSealProof) {
|
||||
|
||||
miner6.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types))
|
||||
|
||||
miner7.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types))
|
||||
|
||||
AddSupportedProofTypes(types...)
|
||||
}
|
||||
|
||||
@ -119,6 +126,15 @@ func AddSupportedProofTypes(types ...abi.RegisteredSealProof) {
|
||||
|
||||
miner6.WindowPoStProofTypes[wpp] = struct{}{}
|
||||
|
||||
miner7.PreCommitSealProofTypesV8[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{}
|
||||
wpp, err = t.RegisteredWindowPoStProof()
|
||||
if err != nil {
|
||||
// Fine to panic, this is a test-only method
|
||||
panic(err)
|
||||
}
|
||||
|
||||
miner7.WindowPoStProofTypes[wpp] = struct{}{}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,11 +155,13 @@ func SetPreCommitChallengeDelay(delay abi.ChainEpoch) {
|
||||
|
||||
miner6.PreCommitChallengeDelay = delay
|
||||
|
||||
miner7.PreCommitChallengeDelay = delay
|
||||
|
||||
}
|
||||
|
||||
// TODO: this function shouldn't really exist. Instead, the API should expose the precommit delay.
|
||||
func GetPreCommitChallengeDelay() abi.ChainEpoch {
|
||||
return miner6.PreCommitChallengeDelay
|
||||
return miner7.PreCommitChallengeDelay
|
||||
}
|
||||
|
||||
// SetConsensusMinerMinPower sets the minimum power of an individual miner must
|
||||
@ -173,6 +191,10 @@ func SetConsensusMinerMinPower(p abi.StoragePower) {
|
||||
policy.ConsensusMinerMinPower = p
|
||||
}
|
||||
|
||||
for _, policy := range builtin7.PoStProofPolicies {
|
||||
policy.ConsensusMinerMinPower = p
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// SetMinVerifiedDealSize sets the minimum size of a verified deal. This should
|
||||
@ -191,6 +213,8 @@ func SetMinVerifiedDealSize(size abi.StoragePower) {
|
||||
|
||||
verifreg6.MinVerifiedDealSize = size
|
||||
|
||||
verifreg7.MinVerifiedDealSize = size
|
||||
|
||||
}
|
||||
|
||||
func GetMaxProveCommitDuration(ver actors.Version, t abi.RegisteredSealProof) (abi.ChainEpoch, error) {
|
||||
@ -220,6 +244,10 @@ func GetMaxProveCommitDuration(ver actors.Version, t abi.RegisteredSealProof) (a
|
||||
|
||||
return miner6.MaxProveCommitDuration[t], nil
|
||||
|
||||
case actors.Version7:
|
||||
|
||||
return miner7.MaxProveCommitDuration[t], nil
|
||||
|
||||
default:
|
||||
return 0, xerrors.Errorf("unsupported actors version")
|
||||
}
|
||||
@ -255,6 +283,11 @@ func SetProviderCollateralSupplyTarget(num, denom big.Int) {
|
||||
Denominator: denom,
|
||||
}
|
||||
|
||||
market7.ProviderCollateralSupplyTarget = builtin7.BigFrac{
|
||||
Numerator: num,
|
||||
Denominator: denom,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func DealProviderCollateralBounds(
|
||||
@ -298,13 +331,18 @@ func DealProviderCollateralBounds(
|
||||
min, max := market6.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil)
|
||||
return min, max, nil
|
||||
|
||||
case actors.Version7:
|
||||
|
||||
min, max := market7.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil)
|
||||
return min, max, nil
|
||||
|
||||
default:
|
||||
return big.Zero(), big.Zero(), xerrors.Errorf("unsupported actors version")
|
||||
}
|
||||
}
|
||||
|
||||
func DealDurationBounds(pieceSize abi.PaddedPieceSize) (min, max abi.ChainEpoch) {
|
||||
return market6.DealDurationBounds(pieceSize)
|
||||
return market7.DealDurationBounds(pieceSize)
|
||||
}
|
||||
|
||||
// Sets the challenge window and scales the proving period to match (such that
|
||||
@ -345,6 +383,13 @@ func SetWPoStChallengeWindow(period abi.ChainEpoch) {
|
||||
// scale it if we're scaling the challenge period.
|
||||
miner6.WPoStDisputeWindow = period * 30
|
||||
|
||||
miner7.WPoStChallengeWindow = period
|
||||
miner7.WPoStProvingPeriod = period * abi.ChainEpoch(miner7.WPoStPeriodDeadlines)
|
||||
|
||||
// by default, this is 2x finality which is 30 periods.
|
||||
// scale it if we're scaling the challenge period.
|
||||
miner7.WPoStDisputeWindow = period * 30
|
||||
|
||||
}
|
||||
|
||||
func GetWinningPoStSectorSetLookback(nwVer network.Version) abi.ChainEpoch {
|
||||
@ -357,15 +402,15 @@ func GetWinningPoStSectorSetLookback(nwVer network.Version) abi.ChainEpoch {
|
||||
}
|
||||
|
||||
func GetMaxSectorExpirationExtension() abi.ChainEpoch {
|
||||
return miner6.MaxSectorExpirationExtension
|
||||
return miner7.MaxSectorExpirationExtension
|
||||
}
|
||||
|
||||
func GetMinSectorExpiration() abi.ChainEpoch {
|
||||
return miner6.MinSectorExpiration
|
||||
return miner7.MinSectorExpiration
|
||||
}
|
||||
|
||||
func GetMaxPoStPartitions(nv network.Version, p abi.RegisteredPoStProof) (int, error) {
|
||||
sectorsPerPart, err := builtin6.PoStProofWindowPoStPartitionSectors(p)
|
||||
sectorsPerPart, err := builtin7.PoStProofWindowPoStPartitionSectors(p)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@ -378,8 +423,8 @@ func GetMaxPoStPartitions(nv network.Version, p abi.RegisteredPoStProof) (int, e
|
||||
|
||||
func GetDefaultSectorSize() abi.SectorSize {
|
||||
// supported sector sizes are the same across versions.
|
||||
szs := make([]abi.SectorSize, 0, len(miner6.PreCommitSealProofTypesV8))
|
||||
for spt := range miner6.PreCommitSealProofTypesV8 {
|
||||
szs := make([]abi.SectorSize, 0, len(miner7.PreCommitSealProofTypesV8))
|
||||
for spt := range miner7.PreCommitSealProofTypesV8 {
|
||||
ss, err := spt.SectorSize()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -404,7 +449,7 @@ func GetSectorMaxLifetime(proof abi.RegisteredSealProof, nwVer network.Version)
|
||||
return builtin4.SealProofPoliciesV0[proof].SectorMaxLifetime
|
||||
}
|
||||
|
||||
return builtin6.SealProofPoliciesV11[proof].SectorMaxLifetime
|
||||
return builtin7.SealProofPoliciesV11[proof].SectorMaxLifetime
|
||||
}
|
||||
|
||||
func GetAddressedSectorsMax(nwVer network.Version) (int, error) {
|
||||
@ -432,6 +477,9 @@ func GetAddressedSectorsMax(nwVer network.Version) (int, error) {
|
||||
case actors.Version6:
|
||||
return miner6.AddressedSectorsMax, nil
|
||||
|
||||
case actors.Version7:
|
||||
return miner7.AddressedSectorsMax, nil
|
||||
|
||||
default:
|
||||
return 0, xerrors.Errorf("unsupported network version")
|
||||
}
|
||||
@ -469,6 +517,10 @@ func GetDeclarationsMax(nwVer network.Version) (int, error) {
|
||||
|
||||
return miner6.DeclarationsMax, nil
|
||||
|
||||
case actors.Version7:
|
||||
|
||||
return miner7.DeclarationsMax, nil
|
||||
|
||||
default:
|
||||
return 0, xerrors.Errorf("unsupported network version")
|
||||
}
|
||||
@ -505,6 +557,10 @@ func AggregateProveCommitNetworkFee(nwVer network.Version, aggregateSize int, ba
|
||||
|
||||
return miner6.AggregateProveCommitNetworkFee(aggregateSize, baseFee), nil
|
||||
|
||||
case actors.Version7:
|
||||
|
||||
return miner7.AggregateProveCommitNetworkFee(aggregateSize, baseFee), nil
|
||||
|
||||
default:
|
||||
return big.Zero(), xerrors.Errorf("unsupported network version")
|
||||
}
|
||||
@ -541,6 +597,10 @@ func AggregatePreCommitNetworkFee(nwVer network.Version, aggregateSize int, base
|
||||
|
||||
return miner6.AggregatePreCommitNetworkFee(aggregateSize, baseFee), nil
|
||||
|
||||
case actors.Version7:
|
||||
|
||||
return miner7.AggregatePreCommitNetworkFee(aggregateSize, baseFee), nil
|
||||
|
||||
default:
|
||||
return big.Zero(), xerrors.Errorf("unsupported network version")
|
||||
}
|
||||
|
@ -20,9 +20,9 @@ const ({{range .actorVersions}}
|
||||
|
||||
/* inline-gen start */
|
||||
|
||||
var LatestVersion = 6
|
||||
var LatestVersion = 7
|
||||
|
||||
var Versions = []int{0, 2, 3, 4, 5, 6}
|
||||
var Versions = []int{0, 2, 3, 4, 5, 6, 7}
|
||||
|
||||
const (
|
||||
Version0 Version = 0
|
||||
@ -31,6 +31,7 @@ const (
|
||||
Version4 Version = 4
|
||||
Version5 Version = 5
|
||||
Version6 Version = 6
|
||||
Version7 Version = 7
|
||||
)
|
||||
|
||||
/* inline-gen end */
|
||||
@ -50,6 +51,8 @@ func VersionForNetwork(version network.Version) (Version, error) {
|
||||
return Version5, nil
|
||||
case network.Version14:
|
||||
return Version6, nil
|
||||
case network.Version15:
|
||||
return Version7, nil
|
||||
default:
|
||||
return -1, fmt.Errorf("unsupported network version %d", version)
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import (
|
||||
exported4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/exported"
|
||||
exported5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/exported"
|
||||
exported6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/exported"
|
||||
exported7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/exported"
|
||||
|
||||
/* inline-gen end */
|
||||
|
||||
@ -59,6 +60,7 @@ func NewActorRegistry() *vm.ActorRegistry {
|
||||
inv.Register(vm.ActorsVersionPredicate(actors.Version4), exported4.BuiltinActors()...)
|
||||
inv.Register(vm.ActorsVersionPredicate(actors.Version5), exported5.BuiltinActors()...)
|
||||
inv.Register(vm.ActorsVersionPredicate(actors.Version6), exported6.BuiltinActors()...)
|
||||
inv.Register(vm.ActorsVersionPredicate(actors.Version7), exported7.BuiltinActors()...)
|
||||
|
||||
/* inline-gen end */
|
||||
|
||||
|
@ -156,6 +156,22 @@ func DefaultUpgradeSchedule() stmgr.UpgradeSchedule {
|
||||
StopWithin: 5,
|
||||
}},
|
||||
Expensive: true,
|
||||
}, {
|
||||
Height: build.UpgradeSnapDealsHeight,
|
||||
Network: network.Version15,
|
||||
Migration: UpgradeActorsV7,
|
||||
PreMigrations: []stmgr.PreMigration{{
|
||||
PreMigration: PreUpgradeActorsV7,
|
||||
StartWithin: 120,
|
||||
DontStartWithin: 60,
|
||||
StopWithin: 35,
|
||||
}, {
|
||||
PreMigration: PreUpgradeActorsV7,
|
||||
StartWithin: 30,
|
||||
DontStartWithin: 15,
|
||||
StopWithin: 5,
|
||||
}},
|
||||
Expensive: true,
|
||||
},
|
||||
}
|
||||
|
||||
@ -1170,7 +1186,97 @@ func upgradeActorsV6Common(
|
||||
// Perform the migration
|
||||
newHamtRoot, err := nv14.MigrateStateTree(ctx, store, stateRoot.Actors, epoch, config, migrationLogger{}, cache)
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("upgrading to actors v5: %w", err)
|
||||
return cid.Undef, xerrors.Errorf("upgrading to actors v6: %w", err)
|
||||
}
|
||||
|
||||
// Persist the result.
|
||||
newRoot, err := store.Put(ctx, &types.StateRoot{
|
||||
Version: types.StateTreeVersion4,
|
||||
Actors: newHamtRoot,
|
||||
Info: stateRoot.Info,
|
||||
})
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("failed to persist new state root: %w", err)
|
||||
}
|
||||
|
||||
// Persist the new tree.
|
||||
|
||||
{
|
||||
from := buf
|
||||
to := buf.Read()
|
||||
|
||||
if err := vm.Copy(ctx, from, to, newRoot); err != nil {
|
||||
return cid.Undef, xerrors.Errorf("copying migrated tree: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return newRoot, nil
|
||||
}
|
||||
|
||||
func UpgradeActorsV7(ctx context.Context, sm *stmgr.StateManager, cache stmgr.MigrationCache, cb stmgr.ExecMonitor, root cid.Cid, epoch abi.ChainEpoch, ts *types.TipSet) (cid.Cid, error) {
|
||||
// Use all the CPUs except 3.
|
||||
workerCount := runtime.NumCPU() - 3
|
||||
if workerCount <= 0 {
|
||||
workerCount = 1
|
||||
}
|
||||
|
||||
config := nv14.Config{
|
||||
MaxWorkers: uint(workerCount),
|
||||
JobQueueSize: 1000,
|
||||
ResultQueueSize: 100,
|
||||
ProgressLogPeriod: 10 * time.Second,
|
||||
}
|
||||
|
||||
newRoot, err := upgradeActorsV7Common(ctx, sm, cache, root, epoch, ts, config)
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("migrating actors v6 state: %w", err)
|
||||
}
|
||||
|
||||
return newRoot, nil
|
||||
}
|
||||
|
||||
func PreUpgradeActorsV7(ctx context.Context, sm *stmgr.StateManager, cache stmgr.MigrationCache, root cid.Cid, epoch abi.ChainEpoch, ts *types.TipSet) error {
|
||||
// Use half the CPUs for pre-migration, but leave at least 3.
|
||||
workerCount := runtime.NumCPU()
|
||||
if workerCount <= 4 {
|
||||
workerCount = 1
|
||||
} else {
|
||||
workerCount /= 2
|
||||
}
|
||||
|
||||
//TODO: nv15
|
||||
config := nv14.Config{MaxWorkers: uint(workerCount)}
|
||||
_, err := upgradeActorsV7Common(ctx, sm, cache, root, epoch, ts, config)
|
||||
return err
|
||||
}
|
||||
|
||||
func upgradeActorsV7Common(
|
||||
ctx context.Context, sm *stmgr.StateManager, cache stmgr.MigrationCache,
|
||||
root cid.Cid, epoch abi.ChainEpoch, ts *types.TipSet,
|
||||
//TODO: nv15
|
||||
config nv14.Config,
|
||||
) (cid.Cid, error) {
|
||||
buf := blockstore.NewTieredBstore(sm.ChainStore().StateBlockstore(), blockstore.NewMemorySync())
|
||||
store := store.ActorStore(ctx, buf)
|
||||
|
||||
// Load the state root.
|
||||
var stateRoot types.StateRoot
|
||||
if err := store.Get(ctx, root, &stateRoot); err != nil {
|
||||
return cid.Undef, xerrors.Errorf("failed to decode state root: %w", err)
|
||||
}
|
||||
|
||||
if stateRoot.Version != types.StateTreeVersion4 {
|
||||
return cid.Undef, xerrors.Errorf(
|
||||
"expected state root version 4 for actors v7 upgrade, got %d",
|
||||
stateRoot.Version,
|
||||
)
|
||||
}
|
||||
|
||||
// Perform the migration
|
||||
//TODO: nv15
|
||||
newHamtRoot, err := nv14.MigrateStateTree(ctx, store, stateRoot.Actors, epoch, config, migrationLogger{}, cache)
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("upgrading to actors v7: %w", err)
|
||||
}
|
||||
|
||||
// Persist the result.
|
||||
|
@ -9,6 +9,8 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
proof7 "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/rand"
|
||||
|
||||
"github.com/filecoin-project/go-state-types/network"
|
||||
@ -686,6 +688,10 @@ func (m genFakeVerifier) VerifyAggregateSeals(aggregate proof5.AggregateSealVeri
|
||||
panic("not supported")
|
||||
}
|
||||
|
||||
func (m genFakeVerifier) VerifyReplicaUpdate(update proof7.ReplicaUpdateInfo) (bool, error) {
|
||||
panic("not supported")
|
||||
}
|
||||
|
||||
func (m genFakeVerifier) VerifyWinningPoSt(ctx context.Context, info proof5.WinningPoStVerifyInfo) (bool, error) {
|
||||
panic("not supported")
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
runtime7 "github.com/filecoin-project/specs-actors/v7/actors/runtime"
|
||||
|
||||
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
|
||||
|
||||
"github.com/ipfs/go-cid"
|
||||
@ -29,7 +31,6 @@ import (
|
||||
market4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/market"
|
||||
power4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/power"
|
||||
reward4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/reward"
|
||||
runtime5 "github.com/filecoin-project/specs-actors/v5/actors/runtime"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
@ -57,7 +58,7 @@ func MinerAddress(genesisIndex uint64) address.Address {
|
||||
}
|
||||
|
||||
type fakedSigSyscalls struct {
|
||||
runtime5.Syscalls
|
||||
runtime7.Syscalls
|
||||
}
|
||||
|
||||
func (fss *fakedSigSyscalls) VerifySignature(signature crypto.Signature, signer address.Address, plaintext []byte) error {
|
||||
@ -65,7 +66,7 @@ func (fss *fakedSigSyscalls) VerifySignature(signature crypto.Signature, signer
|
||||
}
|
||||
|
||||
func mkFakedSigSyscalls(base vm.SyscallBuilder) vm.SyscallBuilder {
|
||||
return func(ctx context.Context, rt *vm.Runtime) runtime5.Syscalls {
|
||||
return func(ctx context.Context, rt *vm.Runtime) runtime7.Syscalls {
|
||||
return &fakedSigSyscalls{
|
||||
base(ctx, rt),
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ func VersionForNetwork(ver network.Version) (types.StateTreeVersion, error) {
|
||||
|
||||
/* inline-gen start */
|
||||
|
||||
case network.Version13, network.Version14:
|
||||
case network.Version13, network.Version14, network.Version15:
|
||||
|
||||
/* inline-gen end */
|
||||
return types.StateTreeVersion4, nil
|
||||
|
@ -3,13 +3,14 @@ package vm
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
vmr "github.com/filecoin-project/specs-actors/v7/actors/runtime"
|
||||
proof7 "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
addr "github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/go-state-types/crypto"
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
vmr5 "github.com/filecoin-project/specs-actors/v5/actors/runtime"
|
||||
proof5 "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof"
|
||||
"github.com/ipfs/go-cid"
|
||||
)
|
||||
|
||||
@ -73,9 +74,10 @@ type Pricelist interface {
|
||||
OnVerifySignature(sigType crypto.SigType, planTextSize int) (GasCharge, error)
|
||||
OnHashing(dataSize int) GasCharge
|
||||
OnComputeUnsealedSectorCid(proofType abi.RegisteredSealProof, pieces []abi.PieceInfo) GasCharge
|
||||
OnVerifySeal(info proof5.SealVerifyInfo) GasCharge
|
||||
OnVerifyAggregateSeals(aggregate proof5.AggregateSealVerifyProofAndInfos) GasCharge
|
||||
OnVerifyPost(info proof5.WindowPoStVerifyInfo) GasCharge
|
||||
OnVerifySeal(info proof7.SealVerifyInfo) GasCharge
|
||||
OnVerifyAggregateSeals(aggregate proof7.AggregateSealVerifyProofAndInfos) GasCharge
|
||||
OnVerifyReplicaUpdate(update proof7.ReplicaUpdateInfo) GasCharge
|
||||
OnVerifyPost(info proof7.WindowPoStVerifyInfo) GasCharge
|
||||
OnVerifyConsensusFault() GasCharge
|
||||
}
|
||||
|
||||
@ -227,7 +229,7 @@ func PricelistByEpoch(epoch abi.ChainEpoch) Pricelist {
|
||||
}
|
||||
|
||||
type pricedSyscalls struct {
|
||||
under vmr5.Syscalls
|
||||
under vmr.Syscalls
|
||||
pl Pricelist
|
||||
chargeGas func(GasCharge)
|
||||
}
|
||||
@ -261,7 +263,7 @@ func (ps pricedSyscalls) ComputeUnsealedSectorCID(reg abi.RegisteredSealProof, p
|
||||
}
|
||||
|
||||
// Verifies a sector seal proof.
|
||||
func (ps pricedSyscalls) VerifySeal(vi proof5.SealVerifyInfo) error {
|
||||
func (ps pricedSyscalls) VerifySeal(vi proof7.SealVerifyInfo) error {
|
||||
ps.chargeGas(ps.pl.OnVerifySeal(vi))
|
||||
defer ps.chargeGas(gasOnActorExec)
|
||||
|
||||
@ -269,7 +271,7 @@ func (ps pricedSyscalls) VerifySeal(vi proof5.SealVerifyInfo) error {
|
||||
}
|
||||
|
||||
// Verifies a proof of spacetime.
|
||||
func (ps pricedSyscalls) VerifyPoSt(vi proof5.WindowPoStVerifyInfo) error {
|
||||
func (ps pricedSyscalls) VerifyPoSt(vi proof7.WindowPoStVerifyInfo) error {
|
||||
ps.chargeGas(ps.pl.OnVerifyPost(vi))
|
||||
defer ps.chargeGas(gasOnActorExec)
|
||||
|
||||
@ -286,14 +288,14 @@ func (ps pricedSyscalls) VerifyPoSt(vi proof5.WindowPoStVerifyInfo) error {
|
||||
// the "parent grinding fault", in which case it must be the sibling of h1 (same parent tipset) and one of the
|
||||
// blocks in the parent of h2 (i.e. h2's grandparent).
|
||||
// Returns nil and an error if the headers don't prove a fault.
|
||||
func (ps pricedSyscalls) VerifyConsensusFault(h1 []byte, h2 []byte, extra []byte) (*vmr5.ConsensusFault, error) {
|
||||
func (ps pricedSyscalls) VerifyConsensusFault(h1 []byte, h2 []byte, extra []byte) (*vmr.ConsensusFault, error) {
|
||||
ps.chargeGas(ps.pl.OnVerifyConsensusFault())
|
||||
defer ps.chargeGas(gasOnActorExec)
|
||||
|
||||
return ps.under.VerifyConsensusFault(h1, h2, extra)
|
||||
}
|
||||
|
||||
func (ps pricedSyscalls) BatchVerifySeals(inp map[address.Address][]proof5.SealVerifyInfo) (map[address.Address][]bool, error) {
|
||||
func (ps pricedSyscalls) BatchVerifySeals(inp map[address.Address][]proof7.SealVerifyInfo) (map[address.Address][]bool, error) {
|
||||
count := int64(0)
|
||||
for _, svis := range inp {
|
||||
count += int64(len(svis))
|
||||
@ -307,9 +309,16 @@ func (ps pricedSyscalls) BatchVerifySeals(inp map[address.Address][]proof5.SealV
|
||||
return ps.under.BatchVerifySeals(inp)
|
||||
}
|
||||
|
||||
func (ps pricedSyscalls) VerifyAggregateSeals(aggregate proof5.AggregateSealVerifyProofAndInfos) error {
|
||||
func (ps pricedSyscalls) VerifyAggregateSeals(aggregate proof7.AggregateSealVerifyProofAndInfos) error {
|
||||
ps.chargeGas(ps.pl.OnVerifyAggregateSeals(aggregate))
|
||||
defer ps.chargeGas(gasOnActorExec)
|
||||
|
||||
return ps.under.VerifyAggregateSeals(aggregate)
|
||||
}
|
||||
|
||||
func (ps pricedSyscalls) VerifyReplicaUpdate(update proof7.ReplicaUpdateInfo) error {
|
||||
ps.chargeGas(ps.pl.OnVerifyReplicaUpdate(update))
|
||||
defer ps.chargeGas(gasOnActorExec)
|
||||
|
||||
return ps.under.VerifyReplicaUpdate(update)
|
||||
}
|
||||
|
@ -3,8 +3,7 @@ package vm
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
proof2 "github.com/filecoin-project/specs-actors/v2/actors/runtime/proof"
|
||||
proof5 "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof"
|
||||
proof7 "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof"
|
||||
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/go-state-types/big"
|
||||
@ -206,14 +205,14 @@ func (pl *pricelistV0) OnComputeUnsealedSectorCid(proofType abi.RegisteredSealPr
|
||||
}
|
||||
|
||||
// OnVerifySeal
|
||||
func (pl *pricelistV0) OnVerifySeal(info proof2.SealVerifyInfo) GasCharge {
|
||||
func (pl *pricelistV0) OnVerifySeal(info proof7.SealVerifyInfo) GasCharge {
|
||||
// TODO: this needs more cost tunning, check with @lotus
|
||||
// this is not used
|
||||
return newGasCharge("OnVerifySeal", pl.verifySealBase, 0)
|
||||
}
|
||||
|
||||
// OnVerifyAggregateSeals
|
||||
func (pl *pricelistV0) OnVerifyAggregateSeals(aggregate proof5.AggregateSealVerifyProofAndInfos) GasCharge {
|
||||
func (pl *pricelistV0) OnVerifyAggregateSeals(aggregate proof7.AggregateSealVerifyProofAndInfos) GasCharge {
|
||||
proofType := aggregate.SealProof
|
||||
perProof, ok := pl.verifyAggregateSealPer[proofType]
|
||||
if !ok {
|
||||
@ -228,8 +227,14 @@ func (pl *pricelistV0) OnVerifyAggregateSeals(aggregate proof5.AggregateSealVeri
|
||||
return newGasCharge("OnVerifyAggregateSeals", perProof*num+step.Lookup(num), 0)
|
||||
}
|
||||
|
||||
// OnVerifyReplicaUpdate
|
||||
func (pl *pricelistV0) OnVerifyReplicaUpdate(update proof7.ReplicaUpdateInfo) GasCharge {
|
||||
// TODO: do the thing
|
||||
return GasCharge{}
|
||||
}
|
||||
|
||||
// OnVerifyPost
|
||||
func (pl *pricelistV0) OnVerifyPost(info proof2.WindowPoStVerifyInfo) GasCharge {
|
||||
func (pl *pricelistV0) OnVerifyPost(info proof7.WindowPoStVerifyInfo) GasCharge {
|
||||
sectorSize := "unknown"
|
||||
var proofType abi.RegisteredPoStProof
|
||||
|
||||
|
@ -16,7 +16,7 @@ import (
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
vmr "github.com/filecoin-project/specs-actors/v5/actors/runtime"
|
||||
vmr "github.com/filecoin-project/specs-actors/v7/actors/runtime"
|
||||
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/go-state-types/exitcode"
|
||||
|
@ -26,6 +26,7 @@ import (
|
||||
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"
|
||||
|
||||
/* inline-gen end */
|
||||
|
||||
@ -130,6 +131,8 @@ func newAccountActor(ver actors.Version) *types.Actor {
|
||||
code = builtin5.AccountActorCodeID
|
||||
case actors.Version6:
|
||||
code = builtin6.AccountActorCodeID
|
||||
case actors.Version7:
|
||||
code = builtin7.AccountActorCodeID
|
||||
/* inline-gen end */
|
||||
default:
|
||||
panic("unsupported actors version")
|
||||
|
@ -17,7 +17,7 @@ import (
|
||||
rtt "github.com/filecoin-project/go-state-types/rt"
|
||||
rt0 "github.com/filecoin-project/specs-actors/actors/runtime"
|
||||
rt5 "github.com/filecoin-project/specs-actors/v5/actors/runtime"
|
||||
rt6 "github.com/filecoin-project/specs-actors/v6/actors/runtime"
|
||||
rt7 "github.com/filecoin-project/specs-actors/v7/actors/runtime"
|
||||
"github.com/ipfs/go-cid"
|
||||
ipldcbor "github.com/ipfs/go-ipld-cbor"
|
||||
"go.opencensus.io/trace"
|
||||
@ -55,8 +55,8 @@ func (m *Message) ValueReceived() abi.TokenAmount {
|
||||
var EnableGasTracing = false
|
||||
|
||||
type Runtime struct {
|
||||
rt5.Message
|
||||
rt5.Syscalls
|
||||
rt7.Message
|
||||
rt7.Syscalls
|
||||
|
||||
ctx context.Context
|
||||
|
||||
@ -142,7 +142,7 @@ func (rt *Runtime) StorePut(x cbor.Marshaler) cid.Cid {
|
||||
|
||||
var _ rt0.Runtime = (*Runtime)(nil)
|
||||
var _ rt5.Runtime = (*Runtime)(nil)
|
||||
var _ rt6.Runtime = (*Runtime)(nil)
|
||||
var _ rt7.Runtime = (*Runtime)(nil)
|
||||
|
||||
func (rt *Runtime) shimCall(f func() interface{}) (rval []byte, aerr aerrors.ActorError) {
|
||||
defer func() {
|
||||
|
@ -7,6 +7,8 @@ import (
|
||||
goruntime "runtime"
|
||||
"sync"
|
||||
|
||||
proof5 "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof"
|
||||
|
||||
"github.com/ipfs/go-cid"
|
||||
cbor "github.com/ipfs/go-ipld-cbor"
|
||||
"github.com/minio/blake2b-simd"
|
||||
@ -26,8 +28,8 @@ import (
|
||||
"github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper"
|
||||
"github.com/filecoin-project/lotus/lib/sigs"
|
||||
|
||||
runtime5 "github.com/filecoin-project/specs-actors/v5/actors/runtime"
|
||||
proof5 "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof"
|
||||
runtime7 "github.com/filecoin-project/specs-actors/v7/actors/runtime"
|
||||
proof7 "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -36,10 +38,10 @@ func init() {
|
||||
|
||||
// Actual type is defined in chain/types/vmcontext.go because the VMContext interface is there
|
||||
|
||||
type SyscallBuilder func(ctx context.Context, rt *Runtime) runtime5.Syscalls
|
||||
type SyscallBuilder func(ctx context.Context, rt *Runtime) runtime7.Syscalls
|
||||
|
||||
func Syscalls(verifier ffiwrapper.Verifier) SyscallBuilder {
|
||||
return func(ctx context.Context, rt *Runtime) runtime5.Syscalls {
|
||||
return func(ctx context.Context, rt *Runtime) runtime7.Syscalls {
|
||||
|
||||
return &syscallShim{
|
||||
ctx: ctx,
|
||||
@ -90,7 +92,7 @@ func (ss *syscallShim) HashBlake2b(data []byte) [32]byte {
|
||||
// Checks validity of the submitted consensus fault with the two block headers needed to prove the fault
|
||||
// and an optional extra one to check common ancestry (as needed).
|
||||
// Note that the blocks are ordered: the method requires a.Epoch() <= b.Epoch().
|
||||
func (ss *syscallShim) VerifyConsensusFault(a, b, extra []byte) (*runtime5.ConsensusFault, error) {
|
||||
func (ss *syscallShim) VerifyConsensusFault(a, b, extra []byte) (*runtime7.ConsensusFault, error) {
|
||||
// Note that block syntax is not validated. Any validly signed block will be accepted pursuant to the below conditions.
|
||||
// Whether or not it could ever have been accepted in a chain is not checked/does not matter here.
|
||||
// for that reason when checking block parent relationships, rather than instantiating a Tipset to do so
|
||||
@ -133,14 +135,14 @@ func (ss *syscallShim) VerifyConsensusFault(a, b, extra []byte) (*runtime5.Conse
|
||||
}
|
||||
|
||||
// (2) check for the consensus faults themselves
|
||||
var consensusFault *runtime5.ConsensusFault
|
||||
var consensusFault *runtime7.ConsensusFault
|
||||
|
||||
// (a) double-fork mining fault
|
||||
if blockA.Height == blockB.Height {
|
||||
consensusFault = &runtime5.ConsensusFault{
|
||||
consensusFault = &runtime7.ConsensusFault{
|
||||
Target: blockA.Miner,
|
||||
Epoch: blockB.Height,
|
||||
Type: runtime5.ConsensusFaultDoubleForkMining,
|
||||
Type: runtime7.ConsensusFaultDoubleForkMining,
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,10 +150,10 @@ func (ss *syscallShim) VerifyConsensusFault(a, b, extra []byte) (*runtime5.Conse
|
||||
// strictly speaking no need to compare heights based on double fork mining check above,
|
||||
// but at same height this would be a different fault.
|
||||
if types.CidArrsEqual(blockA.Parents, blockB.Parents) && blockA.Height != blockB.Height {
|
||||
consensusFault = &runtime5.ConsensusFault{
|
||||
consensusFault = &runtime7.ConsensusFault{
|
||||
Target: blockA.Miner,
|
||||
Epoch: blockB.Height,
|
||||
Type: runtime5.ConsensusFaultTimeOffsetMining,
|
||||
Type: runtime7.ConsensusFaultTimeOffsetMining,
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,10 +173,10 @@ func (ss *syscallShim) VerifyConsensusFault(a, b, extra []byte) (*runtime5.Conse
|
||||
|
||||
if types.CidArrsEqual(blockA.Parents, blockC.Parents) && blockA.Height == blockC.Height &&
|
||||
types.CidArrsContains(blockB.Parents, blockC.Cid()) && !types.CidArrsContains(blockB.Parents, blockA.Cid()) {
|
||||
consensusFault = &runtime5.ConsensusFault{
|
||||
consensusFault = &runtime7.ConsensusFault{
|
||||
Target: blockA.Miner,
|
||||
Epoch: blockB.Height,
|
||||
Type: runtime5.ConsensusFaultParentGrinding,
|
||||
Type: runtime7.ConsensusFaultParentGrinding,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -286,6 +288,7 @@ func (ss *syscallShim) VerifyAggregateSeals(aggregate proof5.AggregateSealVerify
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to verify aggregated PoRep: %w", err)
|
||||
}
|
||||
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid aggregate proof")
|
||||
}
|
||||
@ -293,6 +296,19 @@ func (ss *syscallShim) VerifyAggregateSeals(aggregate proof5.AggregateSealVerify
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ss *syscallShim) VerifyReplicaUpdate(update proof7.ReplicaUpdateInfo) error {
|
||||
ok, err := ss.verifier.VerifyReplicaUpdate(update)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to verify replica update: %w", err)
|
||||
}
|
||||
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid replica update")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ss *syscallShim) VerifySignature(sig crypto.Signature, addr address.Address, input []byte) error {
|
||||
// TODO: in genesis setup, we are currently faking signatures
|
||||
|
||||
|
@ -5,10 +5,11 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
proof7 "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof"
|
||||
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper"
|
||||
proof2 "github.com/filecoin-project/specs-actors/v2/actors/runtime/proof"
|
||||
proof5 "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof"
|
||||
"github.com/ipfs/go-datastore"
|
||||
"github.com/minio/blake2b-simd"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
@ -97,8 +98,12 @@ func (cv *cachingVerifier) GenerateWinningPoStSectorChallenge(ctx context.Contex
|
||||
return cv.backend.GenerateWinningPoStSectorChallenge(ctx, proofType, a, rnd, u)
|
||||
}
|
||||
|
||||
func (cv cachingVerifier) VerifyAggregateSeals(aggregate proof5.AggregateSealVerifyProofAndInfos) (bool, error) {
|
||||
func (cv cachingVerifier) VerifyAggregateSeals(aggregate proof7.AggregateSealVerifyProofAndInfos) (bool, error) {
|
||||
return cv.backend.VerifyAggregateSeals(aggregate)
|
||||
}
|
||||
|
||||
func (cv cachingVerifier) VerifyReplicaUpdate(update proof7.ReplicaUpdateInfo) (bool, error) {
|
||||
return cv.backend.VerifyReplicaUpdate(update)
|
||||
}
|
||||
|
||||
var _ ffiwrapper.Verifier = (*cachingVerifier)(nil)
|
||||
|
@ -6,6 +6,8 @@ import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
proof7 "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/ipfs/go-cid"
|
||||
@ -70,6 +72,12 @@ func (mockVerifier) VerifyAggregateSeals(aggregate proof5.AggregateSealVerifyPro
|
||||
)
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// TODO: do the thing
|
||||
func (mockVerifier) VerifyReplicaUpdate(update proof7.ReplicaUpdateInfo) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (mockVerifier) VerifyWinningPoSt(ctx context.Context, info proof5.WinningPoStVerifyInfo) (bool, error) {
|
||||
panic("should not be called")
|
||||
}
|
||||
|
@ -4699,7 +4699,7 @@ Inputs:
|
||||
]
|
||||
```
|
||||
|
||||
Response: `14`
|
||||
Response: `15`
|
||||
|
||||
### StateReadState
|
||||
StateReadState returns the indicated actor's state.
|
||||
|
@ -4982,7 +4982,7 @@ Inputs:
|
||||
]
|
||||
```
|
||||
|
||||
Response: `14`
|
||||
Response: `15`
|
||||
|
||||
### StateReadState
|
||||
StateReadState returns the indicated actor's state.
|
||||
|
3
extern/sector-storage/ffiwrapper/types.go
vendored
3
extern/sector-storage/ffiwrapper/types.go
vendored
@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"io"
|
||||
|
||||
proof7 "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof"
|
||||
|
||||
proof5 "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof"
|
||||
|
||||
"github.com/ipfs/go-cid"
|
||||
@ -36,6 +38,7 @@ type Storage interface {
|
||||
type Verifier interface {
|
||||
VerifySeal(proof5.SealVerifyInfo) (bool, error)
|
||||
VerifyAggregateSeals(aggregate proof5.AggregateSealVerifyProofAndInfos) (bool, error)
|
||||
VerifyReplicaUpdate(update proof7.ReplicaUpdateInfo) (bool, error)
|
||||
VerifyWinningPoSt(ctx context.Context, info proof5.WinningPoStVerifyInfo) (bool, error)
|
||||
VerifyWindowPoSt(ctx context.Context, info proof5.WindowPoStVerifyInfo) (bool, error)
|
||||
|
||||
|
@ -6,6 +6,8 @@ package ffiwrapper
|
||||
import (
|
||||
"context"
|
||||
|
||||
proof7 "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof"
|
||||
|
||||
"go.opencensus.io/trace"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
@ -120,6 +122,11 @@ func (proofVerifier) VerifyAggregateSeals(aggregate proof5.AggregateSealVerifyPr
|
||||
return ffi.VerifyAggregateSeals(aggregate)
|
||||
}
|
||||
|
||||
func (proofVerifier) VerifyReplicaUpdate(update proof7.ReplicaUpdateInfo) (bool, error) {
|
||||
//TODO: do the thing
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (proofVerifier) VerifyWinningPoSt(ctx context.Context, info proof5.WinningPoStVerifyInfo) (bool, error) {
|
||||
info.Randomness[31] &= 0x3f
|
||||
_, span := trace.StartSpan(ctx, "VerifyWinningPoSt")
|
||||
|
7
extern/sector-storage/mock/mock.go
vendored
7
extern/sector-storage/mock/mock.go
vendored
@ -10,6 +10,8 @@ import (
|
||||
"math/rand"
|
||||
"sync"
|
||||
|
||||
proof7 "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof"
|
||||
|
||||
proof5 "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof"
|
||||
|
||||
"github.com/filecoin-project/dagstore/mount"
|
||||
@ -558,6 +560,11 @@ func (m mockVerifProver) VerifyAggregateSeals(aggregate proof5.AggregateSealVeri
|
||||
return ok, nil
|
||||
}
|
||||
|
||||
// TODO: do the thing
|
||||
func (m mockVerifProver) VerifyReplicaUpdate(update proof7.ReplicaUpdateInfo) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (m mockVerifProver) AggregateSealProofs(aggregateInfo proof5.AggregateSealVerifyProofAndInfos, proofs [][]byte) ([]byte, error) {
|
||||
out := make([]byte, m.aggLen(len(aggregateInfo.Infos))) // todo: figure out more real length
|
||||
for pi, proof := range proofs {
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"actorVersions": [0, 2, 3, 4, 5, 6],
|
||||
"latestActorsVersion": 6,
|
||||
"actorVersions": [0, 2, 3, 4, 5, 6, 7],
|
||||
"latestActorsVersion": 7,
|
||||
|
||||
"networkVersions": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
|
||||
"latestNetworkVersion": 14
|
||||
"networkVersions": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
||||
"latestNetworkVersion": 15
|
||||
}
|
||||
|
1
go.mod
1
go.mod
@ -51,6 +51,7 @@ require (
|
||||
github.com/filecoin-project/specs-actors/v4 v4.0.1
|
||||
github.com/filecoin-project/specs-actors/v5 v5.0.4
|
||||
github.com/filecoin-project/specs-actors/v6 v6.0.1
|
||||
github.com/filecoin-project/specs-actors/v7 v7.0.0-20211110223913-e2abd33b42d4
|
||||
github.com/filecoin-project/specs-storage v0.1.1-0.20201105051918-5188d9774506
|
||||
github.com/filecoin-project/test-vectors/schema v0.0.5
|
||||
github.com/gbrlsnchs/jwt/v3 v3.0.1
|
||||
|
5
go.sum
5
go.sum
@ -392,8 +392,13 @@ github.com/filecoin-project/specs-actors/v4 v4.0.1/go.mod h1:TkHXf/l7Wyw4ZejyXIP
|
||||
github.com/filecoin-project/specs-actors/v5 v5.0.0-20210512015452-4fe3889fff57/go.mod h1:283yBMMUSDB2abcjP/hhrwTkhb9h3sfM6KGrep/ZlBI=
|
||||
github.com/filecoin-project/specs-actors/v5 v5.0.4 h1:OY7BdxJWlUfUFXWV/kpNBYGXNPasDIedf42T3sGx08s=
|
||||
github.com/filecoin-project/specs-actors/v5 v5.0.4/go.mod h1:5BAKRAMsOOlD8+qCw4UvT/lTLInCJ3JwOWZbX8Ipwq4=
|
||||
github.com/filecoin-project/specs-actors/v6 v6.0.0/go.mod h1:V1AYfi5GkHXipx1mnVivoICZh3wtwPxDVuds+fbfQtk=
|
||||
github.com/filecoin-project/specs-actors/v6 v6.0.1 h1:laxvHNsvrq83Y9n+W7znVCePi3oLyRf0Rkl4jFO8Wew=
|
||||
github.com/filecoin-project/specs-actors/v6 v6.0.1/go.mod h1:V1AYfi5GkHXipx1mnVivoICZh3wtwPxDVuds+fbfQtk=
|
||||
github.com/filecoin-project/specs-actors/v7 v7.0.0-20211109185520-8807da1012c5 h1:8SCNu2TkLCfsS8BpRfeOVt5e4pw2Ej3GInDlFEWqKHo=
|
||||
github.com/filecoin-project/specs-actors/v7 v7.0.0-20211109185520-8807da1012c5/go.mod h1:F3/N4dIRgwEcSk7xp3RizaVyBE/Jlzhv9Le1/ZH50ZA=
|
||||
github.com/filecoin-project/specs-actors/v7 v7.0.0-20211110223913-e2abd33b42d4 h1:5sswsw6rhw/JFG5+xU4En5na4K5QPf3jZ33zvAzGrY8=
|
||||
github.com/filecoin-project/specs-actors/v7 v7.0.0-20211110223913-e2abd33b42d4/go.mod h1:F3/N4dIRgwEcSk7xp3RizaVyBE/Jlzhv9Le1/ZH50ZA=
|
||||
github.com/filecoin-project/specs-storage v0.1.1-0.20201105051918-5188d9774506 h1:Ur/l2+6qN+lQiqjozWWc5p9UDaAMDZKTlDS98oRnlIw=
|
||||
github.com/filecoin-project/specs-storage v0.1.1-0.20201105051918-5188d9774506/go.mod h1:nJRRM7Aa9XVvygr3W9k6xGF46RWzr2zxF/iGoAIfA/g=
|
||||
github.com/filecoin-project/test-vectors/schema v0.0.5 h1:w3zHQhzM4pYxJDl21avXjOKBLF8egrvwUwjpT8TquDg=
|
||||
|
@ -49,12 +49,12 @@ func LatestActorsAt(upgradeHeight abi.ChainEpoch) EnsembleOpt {
|
||||
})
|
||||
/* inline-gen start */
|
||||
return UpgradeSchedule(stmgr.Upgrade{
|
||||
Network: network.Version13,
|
||||
Network: network.Version14,
|
||||
Height: -1,
|
||||
}, stmgr.Upgrade{
|
||||
Network: network.Version14,
|
||||
Network: network.Version15,
|
||||
Height: upgradeHeight,
|
||||
Migration: filcns.UpgradeActorsV6,
|
||||
Migration: filcns.UpgradeActorsV7,
|
||||
})
|
||||
/* inline-gen end */
|
||||
}
|
||||
|
@ -622,5 +622,112 @@
|
||||
"AddVerifiedClient",
|
||||
"UseBytes",
|
||||
"RestoreBytes"
|
||||
],
|
||||
"fil/7/account": [
|
||||
"Send",
|
||||
"Constructor",
|
||||
"PubkeyAddress"
|
||||
],
|
||||
"fil/7/cron": [
|
||||
"Send",
|
||||
"Constructor",
|
||||
"EpochTick"
|
||||
],
|
||||
"fil/7/init": [
|
||||
"Send",
|
||||
"Constructor",
|
||||
"Exec"
|
||||
],
|
||||
"fil/7/multisig": [
|
||||
"Send",
|
||||
"Constructor",
|
||||
"Propose",
|
||||
"Approve",
|
||||
"Cancel",
|
||||
"AddSigner",
|
||||
"RemoveSigner",
|
||||
"SwapSigner",
|
||||
"ChangeNumApprovalsThreshold",
|
||||
"LockBalance"
|
||||
],
|
||||
"fil/7/paymentchannel": [
|
||||
"Send",
|
||||
"Constructor",
|
||||
"UpdateChannelState",
|
||||
"Settle",
|
||||
"Collect"
|
||||
],
|
||||
"fil/7/reward": [
|
||||
"Send",
|
||||
"Constructor",
|
||||
"AwardBlockReward",
|
||||
"ThisEpochReward",
|
||||
"UpdateNetworkKPI"
|
||||
],
|
||||
"fil/7/storagemarket": [
|
||||
"Send",
|
||||
"Constructor",
|
||||
"AddBalance",
|
||||
"WithdrawBalance",
|
||||
"PublishStorageDeals",
|
||||
"VerifyDealsForActivation",
|
||||
"ActivateDeals",
|
||||
"OnMinerSectorsTerminate",
|
||||
"ComputeDataCommitment",
|
||||
"CronTick"
|
||||
],
|
||||
"fil/7/storageminer": [
|
||||
"Send",
|
||||
"Constructor",
|
||||
"ControlAddresses",
|
||||
"ChangeWorkerAddress",
|
||||
"ChangePeerID",
|
||||
"SubmitWindowedPoSt",
|
||||
"PreCommitSector",
|
||||
"ProveCommitSector",
|
||||
"ExtendSectorExpiration",
|
||||
"TerminateSectors",
|
||||
"DeclareFaults",
|
||||
"DeclareFaultsRecovered",
|
||||
"OnDeferredCronEvent",
|
||||
"CheckSectorProven",
|
||||
"ApplyRewards",
|
||||
"ReportConsensusFault",
|
||||
"WithdrawBalance",
|
||||
"ConfirmSectorProofsValid",
|
||||
"ChangeMultiaddrs",
|
||||
"CompactPartitions",
|
||||
"CompactSectorNumbers",
|
||||
"ConfirmUpdateWorkerKey",
|
||||
"RepayDebt",
|
||||
"ChangeOwnerAddress",
|
||||
"DisputeWindowedPoSt",
|
||||
"PreCommitSectorBatch",
|
||||
"ProveCommitAggregate",
|
||||
"ProveReplicaUpdates"
|
||||
],
|
||||
"fil/7/storagepower": [
|
||||
"Send",
|
||||
"Constructor",
|
||||
"CreateMiner",
|
||||
"UpdateClaimedPower",
|
||||
"EnrollCronEvent",
|
||||
"OnEpochTickEnd",
|
||||
"UpdatePledgeTotal",
|
||||
"SubmitPoRepForBulkVerify",
|
||||
"CurrentTotalPower"
|
||||
],
|
||||
"fil/7/system": [
|
||||
"Send",
|
||||
"Constructor"
|
||||
],
|
||||
"fil/7/verifiedregistry": [
|
||||
"Send",
|
||||
"Constructor",
|
||||
"AddVerifier",
|
||||
"RemoveVerifier",
|
||||
"AddVerifiedClient",
|
||||
"UseBytes",
|
||||
"RestoreBytes"
|
||||
]
|
||||
}
|
@ -5,6 +5,8 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
proof7 "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof"
|
||||
|
||||
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
|
||||
miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner"
|
||||
|
||||
@ -22,12 +24,6 @@ import (
|
||||
"github.com/filecoin-project/go-state-types/crypto"
|
||||
"github.com/filecoin-project/go-state-types/dline"
|
||||
"github.com/filecoin-project/go-state-types/network"
|
||||
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
||||
miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner"
|
||||
proof2 "github.com/filecoin-project/specs-actors/v2/actors/runtime/proof"
|
||||
tutils "github.com/filecoin-project/specs-actors/v2/support/testing"
|
||||
proof5 "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
||||
@ -35,6 +31,10 @@ import (
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/extern/sector-storage/storiface"
|
||||
"github.com/filecoin-project/lotus/journal"
|
||||
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
||||
miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner"
|
||||
proof2 "github.com/filecoin-project/specs-actors/v2/actors/runtime/proof"
|
||||
tutils "github.com/filecoin-project/specs-actors/v2/support/testing"
|
||||
)
|
||||
|
||||
type mockStorageMinerAPI struct {
|
||||
@ -149,7 +149,11 @@ func (m mockVerif) VerifyWindowPoSt(ctx context.Context, info proof2.WindowPoStV
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (m mockVerif) VerifyAggregateSeals(aggregate proof5.AggregateSealVerifyProofAndInfos) (bool, error) {
|
||||
func (m mockVerif) VerifyAggregateSeals(aggregate proof7.AggregateSealVerifyProofAndInfos) (bool, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (m mockVerif) VerifyReplicaUpdate(update proof7.ReplicaUpdateInfo) (bool, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user