Merge pull request #6305 from filecoin-project/asr/genesis-actor

Allow starting networks from arbitrary actor versions
This commit is contained in:
Łukasz Magiera 2021-05-26 10:19:23 +02:00 committed by GitHub
commit 930f2b4049
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
126 changed files with 3174 additions and 653 deletions

Binary file not shown.

View File

@ -24,20 +24,20 @@ var UpgradeIgnitionHeight = abi.ChainEpoch(-2)
var UpgradeRefuelHeight = abi.ChainEpoch(-3)
var UpgradeTapeHeight = abi.ChainEpoch(-4)
var UpgradeActorsV2Height = abi.ChainEpoch(10)
var UpgradeLiftoffHeight = abi.ChainEpoch(-5)
var UpgradeActorsV2Height = abi.ChainEpoch(-5)
var UpgradeLiftoffHeight = abi.ChainEpoch(-6)
var UpgradeKumquatHeight = abi.ChainEpoch(15)
var UpgradeCalicoHeight = abi.ChainEpoch(20)
var UpgradePersianHeight = abi.ChainEpoch(25)
var UpgradeOrangeHeight = abi.ChainEpoch(27)
var UpgradeClausHeight = abi.ChainEpoch(30)
var UpgradeKumquatHeight = abi.ChainEpoch(-7)
var UpgradeCalicoHeight = abi.ChainEpoch(-8)
var UpgradePersianHeight = abi.ChainEpoch(-9)
var UpgradeOrangeHeight = abi.ChainEpoch(-10)
var UpgradeClausHeight = abi.ChainEpoch(-11)
var UpgradeActorsV3Height = abi.ChainEpoch(35)
var UpgradeActorsV3Height = abi.ChainEpoch(-12)
var UpgradeNorwegianHeight = abi.ChainEpoch(40)
var UpgradeNorwegianHeight = abi.ChainEpoch(-13)
var UpgradeActorsV4Height = abi.ChainEpoch(45)
var UpgradeActorsV4Height = abi.ChainEpoch(-14)
var DrandSchedule = map[abi.ChainEpoch]DrandEnum{
0: DrandMainnet,

View File

@ -25,7 +25,7 @@ const UnixfsLinksPerLevel = 1024
// Consensus / Network
const AllowableClockDriftSecs = uint64(1)
const NewestNetworkVersion = network.Version11
const NewestNetworkVersion = network.Version12
const ActorUpgradeNetworkVersion = network.Version4
// Epochs

0
chain/actors/adt/temp Normal file
View File

View File

View File

@ -6,33 +6,26 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strconv"
"text/template"
lotusactors "github.com/filecoin-project/lotus/chain/actors"
"golang.org/x/xerrors"
)
var latestVersion = 4
var versions = []int{0, 2, 3, latestVersion}
var versionImports = map[int]string{
0: "/",
2: "/v2/",
3: "/v3/",
latestVersion: "/v4/",
}
var actors = map[string][]int{
"account": versions,
"cron": versions,
"init": versions,
"market": versions,
"miner": versions,
"multisig": versions,
"paych": versions,
"power": versions,
"reward": versions,
"verifreg": versions,
"account": lotusactors.Versions,
"cron": lotusactors.Versions,
"init": lotusactors.Versions,
"market": lotusactors.Versions,
"miner": lotusactors.Versions,
"multisig": lotusactors.Versions,
"paych": lotusactors.Versions,
"power": lotusactors.Versions,
"system": lotusactors.Versions,
"reward": lotusactors.Versions,
"verifreg": lotusactors.Versions,
}
func main() {
@ -71,14 +64,14 @@ func generateAdapters() error {
}
tpl := template.Must(template.New("").Funcs(template.FuncMap{
"import": func(v int) string { return versionImports[v] },
"import": func(v int) string { return getVersionImports()[v] },
}).Parse(string(af)))
var b bytes.Buffer
err = tpl.Execute(&b, map[string]interface{}{
"versions": versions,
"latestVersion": latestVersion,
"latestVersion": lotusactors.LatestVersion,
})
if err != nil {
return err
@ -103,14 +96,14 @@ func generateState(actDir string) error {
return xerrors.Errorf("loading state adapter template: %w", err)
}
for _, version := range versions {
for _, version := range lotusactors.Versions {
tpl := template.Must(template.New("").Funcs(template.FuncMap{}).Parse(string(af)))
var b bytes.Buffer
err := tpl.Execute(&b, map[string]interface{}{
"v": version,
"import": versionImports[version],
"import": getVersionImports()[version],
})
if err != nil {
return err
@ -134,14 +127,14 @@ func generateMessages(actDir string) error {
return xerrors.Errorf("loading message adapter template: %w", err)
}
for _, version := range versions {
for _, version := range lotusactors.Versions {
tpl := template.Must(template.New("").Funcs(template.FuncMap{}).Parse(string(af)))
var b bytes.Buffer
err := tpl.Execute(&b, map[string]interface{}{
"v": version,
"import": versionImports[version],
"import": getVersionImports()[version],
})
if err != nil {
return err
@ -167,13 +160,13 @@ func generatePolicy(policyPath string) error {
}
tpl := template.Must(template.New("").Funcs(template.FuncMap{
"import": func(v int) string { return versionImports[v] },
"import": func(v int) string { return getVersionImports()[v] },
}).Parse(string(pf)))
var b bytes.Buffer
err = tpl.Execute(&b, map[string]interface{}{
"versions": versions,
"latestVersion": latestVersion,
"versions": lotusactors.Versions,
"latestVersion": lotusactors.LatestVersion,
})
if err != nil {
return err
@ -198,13 +191,13 @@ func generateBuiltin(builtinPath string) error {
}
tpl := template.Must(template.New("").Funcs(template.FuncMap{
"import": func(v int) string { return versionImports[v] },
"import": func(v int) string { return getVersionImports()[v] },
}).Parse(string(bf)))
var b bytes.Buffer
err = tpl.Execute(&b, map[string]interface{}{
"versions": versions,
"latestVersion": latestVersion,
"versions": lotusactors.Versions,
"latestVersion": lotusactors.LatestVersion,
})
if err != nil {
return err
@ -216,3 +209,16 @@ func generateBuiltin(builtinPath string) error {
return nil
}
func getVersionImports() map[int]string {
versionImports := make(map[int]string, lotusactors.LatestVersion)
for _, v := range lotusactors.Versions {
if v == 0 {
versionImports[v] = "/"
} else {
versionImports[v] = "/v" + strconv.Itoa(v) + "/"
}
}
return versionImports
}

0
chain/actors/agen/temp Normal file
View File

View File

@ -1,6 +1,7 @@
package account
import (
"github.com/filecoin-project/lotus/chain/actors"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
@ -60,8 +61,48 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
}
func MakeState(store adt.Store, av actors.Version, addr address.Address) (State, error) {
switch av {
case actors.Version0:
return make0(store, addr)
case actors.Version2:
return make2(store, addr)
case actors.Version3:
return make3(store, addr)
case actors.Version4:
return make4(store, addr)
}
return nil, xerrors.Errorf("unknown actor version %d", av)
}
func GetActorCodeID(av actors.Version) (cid.Cid, error) {
switch av {
case actors.Version0:
return builtin0.AccountActorCodeID, nil
case actors.Version2:
return builtin2.AccountActorCodeID, nil
case actors.Version3:
return builtin3.AccountActorCodeID, nil
case actors.Version4:
return builtin4.AccountActorCodeID, nil
}
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
}
type State interface {
cbor.Marshaler
PubkeyAddress() (address.Address, error)
GetState() interface{}
}

View File

@ -1,6 +1,7 @@
package account
import (
"github.com/filecoin-project/lotus/chain/actors"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
@ -34,8 +35,30 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
}
func MakeState(store adt.Store, av actors.Version, addr address.Address) (State, error) {
switch av {
{{range .versions}}
case actors.Version{{.}}:
return make{{.}}(store, addr)
{{end}}
}
return nil, xerrors.Errorf("unknown actor version %d", av)
}
func GetActorCodeID(av actors.Version) (cid.Cid, error) {
switch av {
{{range .versions}}
case actors.Version{{.}}:
return builtin{{.}}.AccountActorCodeID, nil
{{end}}
}
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
}
type State interface {
cbor.Marshaler
PubkeyAddress() (address.Address, error)
GetState() interface{}
}

View File

@ -20,6 +20,12 @@ func load{{.v}}(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make{{.v}}(store adt.Store, addr address.Address) (State, error) {
out := state{{.v}}{store: store}
out.State = account{{.v}}.State{Address:addr}
return &out, nil
}
type state{{.v}} struct {
account{{.v}}.State
store adt.Store
@ -28,3 +34,7 @@ type state{{.v}} struct {
func (s *state{{.v}}) PubkeyAddress() (address.Address, error) {
return s.Address, nil
}
func (s *state{{.v}}) GetState() interface{} {
return &s.State
}

View File

View File

@ -20,6 +20,12 @@ func load0(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make0(store adt.Store, addr address.Address) (State, error) {
out := state0{store: store}
out.State = account0.State{Address: addr}
return &out, nil
}
type state0 struct {
account0.State
store adt.Store
@ -28,3 +34,7 @@ type state0 struct {
func (s *state0) PubkeyAddress() (address.Address, error) {
return s.Address, nil
}
func (s *state0) GetState() interface{} {
return &s.State
}

View File

@ -20,6 +20,12 @@ func load2(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make2(store adt.Store, addr address.Address) (State, error) {
out := state2{store: store}
out.State = account2.State{Address: addr}
return &out, nil
}
type state2 struct {
account2.State
store adt.Store
@ -28,3 +34,7 @@ type state2 struct {
func (s *state2) PubkeyAddress() (address.Address, error) {
return s.Address, nil
}
func (s *state2) GetState() interface{} {
return &s.State
}

View File

@ -20,6 +20,12 @@ func load3(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make3(store adt.Store, addr address.Address) (State, error) {
out := state3{store: store}
out.State = account3.State{Address: addr}
return &out, nil
}
type state3 struct {
account3.State
store adt.Store
@ -28,3 +34,7 @@ type state3 struct {
func (s *state3) PubkeyAddress() (address.Address, error) {
return s.Address, nil
}
func (s *state3) GetState() interface{} {
return &s.State
}

View File

@ -20,6 +20,12 @@ func load4(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make4(store adt.Store, addr address.Address) (State, error) {
out := state4{store: store}
out.State = account4.State{Address: addr}
return &out, nil
}
type state4 struct {
account4.State
store adt.Store
@ -28,3 +34,7 @@ type state4 struct {
func (s *state4) PubkeyAddress() (address.Address, error) {
return s.Address, nil
}
func (s *state4) GetState() interface{} {
return &s.State
}

View File

@ -6,9 +6,9 @@ import (
"golang.org/x/xerrors"
{{range .versions}}
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
smoothing{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/util/smoothing"
{{end}}
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
smoothing{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/util/smoothing"
{{end}}
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/cbor"
@ -17,7 +17,7 @@ import (
"github.com/filecoin-project/lotus/chain/types"
miner{{.latestVersion}} "github.com/filecoin-project/specs-actors{{import .latestVersion}}actors/builtin/miner"
proof{{.latestVersion}} "github.com/filecoin-project/specs-actors{{import .latestVersion}}actors/runtime/proof"
proof{{.latestVersion}} "github.com/filecoin-project/specs-actors{{import .latestVersion}}actors/runtime/proof"
)
var SystemActorAddr = builtin{{.latestVersion}}.SystemActorAddr
@ -33,12 +33,12 @@ var (
const (
EpochDurationSeconds = builtin{{.latestVersion}}.EpochDurationSeconds
EpochsInDay = builtin{{.latestVersion}}.EpochsInDay
SecondsInDay = builtin{{.latestVersion}}.SecondsInDay
EpochsInDay = builtin{{.latestVersion}}.EpochsInDay
SecondsInDay = builtin{{.latestVersion}}.SecondsInDay
)
const (
MethodSend = builtin{{.latestVersion}}.MethodSend
MethodSend = builtin{{.latestVersion}}.MethodSend
MethodConstructor = builtin{{.latestVersion}}.MethodConstructor
)
@ -53,13 +53,13 @@ func QAPowerForWeight(size abi.SectorSize, duration abi.ChainEpoch, dealWeight,
}
{{range .versions}}
func FromV{{.}}FilterEstimate(v{{.}} smoothing{{.}}.FilterEstimate) FilterEstimate {
func FromV{{.}}FilterEstimate(v{{.}} smoothing{{.}}.FilterEstimate) FilterEstimate {
{{if (eq . 0)}}
return (FilterEstimate)(v{{.}}) //nolint:unconvert
{{else}}
return (FilterEstimate)(v{{.}})
{{end}}
}
return (FilterEstimate)(v{{.}}) //nolint:unconvert
{{else}}
return (FilterEstimate)(v{{.}})
{{end}}
}
{{end}}
type ActorStateLoader func(store adt.Store, root cid.Cid) (cbor.Marshaler, error)
@ -80,58 +80,58 @@ func Load(store adt.Store, act *types.Actor) (cbor.Marshaler, error) {
func ActorNameByCode(c cid.Cid) string {
switch {
{{range .versions}}
case builtin{{.}}.IsBuiltinActor(c):
return builtin{{.}}.ActorNameByCode(c)
{{end}}
{{range .versions}}
case builtin{{.}}.IsBuiltinActor(c):
return builtin{{.}}.ActorNameByCode(c)
{{end}}
default:
return "<unknown>"
}
}
func IsBuiltinActor(c cid.Cid) bool {
{{range .versions}}
if builtin{{.}}.IsBuiltinActor(c) {
return true
}
{{end}}
return false
{{range .versions}}
if builtin{{.}}.IsBuiltinActor(c) {
return true
}
{{end}}
return false
}
func IsAccountActor(c cid.Cid) bool {
{{range .versions}}
if c == builtin{{.}}.AccountActorCodeID {
return true
}
{{end}}
return false
{{range .versions}}
if c == builtin{{.}}.AccountActorCodeID {
return true
}
{{end}}
return false
}
func IsStorageMinerActor(c cid.Cid) bool {
{{range .versions}}
if c == builtin{{.}}.StorageMinerActorCodeID {
return true
}
{{end}}
return false
{{range .versions}}
if c == builtin{{.}}.StorageMinerActorCodeID {
return true
}
{{end}}
return false
}
func IsMultisigActor(c cid.Cid) bool {
{{range .versions}}
if c == builtin{{.}}.MultisigActorCodeID {
return true
}
{{end}}
return false
{{range .versions}}
if c == builtin{{.}}.MultisigActorCodeID {
return true
}
{{end}}
return false
}
func IsPaymentChannelActor(c cid.Cid) bool {
{{range .versions}}
if c == builtin{{.}}.PaymentChannelActorCodeID {
return true
}
{{end}}
return false
{{range .versions}}
if c == builtin{{.}}.PaymentChannelActorCodeID {
return true
}
{{end}}
return false
}
func makeAddress(addr string) address.Address {

View File

@ -1,10 +1,42 @@
package cron
import (
builtin{{.latestVersion}} "github.com/filecoin-project/specs-actors{{import .latestVersion}}actors/builtin"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/adt"
"golang.org/x/xerrors"
"github.com/ipfs/go-cid"
{{range .versions}}
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
{{end}}
)
func MakeState(store adt.Store, av actors.Version) (State, error) {
switch av {
{{range .versions}}
case actors.Version{{.}}:
return make{{.}}(store)
{{end}}
}
return nil, xerrors.Errorf("unknown actor version %d", av)
}
func GetActorCodeID(av actors.Version) (cid.Cid, error) {
switch av {
{{range .versions}}
case actors.Version{{.}}:
return builtin{{.}}.CronActorCodeID, nil
{{end}}
}
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
}
var (
Address = builtin{{.latestVersion}}.CronActorAddr
Methods = builtin{{.latestVersion}}.MethodsCron
)
type State interface {
GetState() interface{}
}

View File

@ -1,10 +1,64 @@
package cron
import (
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/ipfs/go-cid"
"golang.org/x/xerrors"
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
)
func MakeState(store adt.Store, av actors.Version) (State, error) {
switch av {
case actors.Version0:
return make0(store)
case actors.Version2:
return make2(store)
case actors.Version3:
return make3(store)
case actors.Version4:
return make4(store)
}
return nil, xerrors.Errorf("unknown actor version %d", av)
}
func GetActorCodeID(av actors.Version) (cid.Cid, error) {
switch av {
case actors.Version0:
return builtin0.CronActorCodeID, nil
case actors.Version2:
return builtin2.CronActorCodeID, nil
case actors.Version3:
return builtin3.CronActorCodeID, nil
case actors.Version4:
return builtin4.CronActorCodeID, nil
}
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
}
var (
Address = builtin4.CronActorAddr
Methods = builtin4.MethodsCron
)
type State interface {
GetState() interface{}
}

View File

@ -0,0 +1,35 @@
package cron
import (
"github.com/ipfs/go-cid"
"github.com/filecoin-project/lotus/chain/actors/adt"
cron{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/cron"
)
var _ State = (*state{{.v}})(nil)
func load{{.v}}(store adt.Store, root cid.Cid) (State, error) {
out := state{{.v}}{store: store}
err := store.Get(store.Context(), root, &out)
if err != nil {
return nil, err
}
return &out, nil
}
func make{{.v}}(store adt.Store) (State, error) {
out := state{{.v}}{store: store}
out.State = *cron{{.v}}.ConstructState(cron{{.v}}.BuiltInEntries())
return &out, nil
}
type state{{.v}} struct {
cron{{.v}}.State
store adt.Store
}
func (s *state{{.v}}) GetState() interface{} {
return &s.State
}

View File

View File

@ -0,0 +1,35 @@
package cron
import (
"github.com/ipfs/go-cid"
"github.com/filecoin-project/lotus/chain/actors/adt"
cron0 "github.com/filecoin-project/specs-actors/actors/builtin/cron"
)
var _ State = (*state0)(nil)
func load0(store adt.Store, root cid.Cid) (State, error) {
out := state0{store: store}
err := store.Get(store.Context(), root, &out)
if err != nil {
return nil, err
}
return &out, nil
}
func make0(store adt.Store) (State, error) {
out := state0{store: store}
out.State = *cron0.ConstructState(cron0.BuiltInEntries())
return &out, nil
}
type state0 struct {
cron0.State
store adt.Store
}
func (s *state0) GetState() interface{} {
return &s.State
}

View File

@ -0,0 +1,35 @@
package cron
import (
"github.com/ipfs/go-cid"
"github.com/filecoin-project/lotus/chain/actors/adt"
cron2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/cron"
)
var _ State = (*state2)(nil)
func load2(store adt.Store, root cid.Cid) (State, error) {
out := state2{store: store}
err := store.Get(store.Context(), root, &out)
if err != nil {
return nil, err
}
return &out, nil
}
func make2(store adt.Store) (State, error) {
out := state2{store: store}
out.State = *cron2.ConstructState(cron2.BuiltInEntries())
return &out, nil
}
type state2 struct {
cron2.State
store adt.Store
}
func (s *state2) GetState() interface{} {
return &s.State
}

View File

@ -0,0 +1,35 @@
package cron
import (
"github.com/ipfs/go-cid"
"github.com/filecoin-project/lotus/chain/actors/adt"
cron3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/cron"
)
var _ State = (*state3)(nil)
func load3(store adt.Store, root cid.Cid) (State, error) {
out := state3{store: store}
err := store.Get(store.Context(), root, &out)
if err != nil {
return nil, err
}
return &out, nil
}
func make3(store adt.Store) (State, error) {
out := state3{store: store}
out.State = *cron3.ConstructState(cron3.BuiltInEntries())
return &out, nil
}
type state3 struct {
cron3.State
store adt.Store
}
func (s *state3) GetState() interface{} {
return &s.State
}

View File

@ -0,0 +1,35 @@
package cron
import (
"github.com/ipfs/go-cid"
"github.com/filecoin-project/lotus/chain/actors/adt"
cron4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/cron"
)
var _ State = (*state4)(nil)
func load4(store adt.Store, root cid.Cid) (State, error) {
out := state4{store: store}
err := store.Get(store.Context(), root, &out)
if err != nil {
return nil, err
}
return &out, nil
}
func make4(store adt.Store) (State, error) {
out := state4{store: store}
out.State = *cron4.ConstructState(cron4.BuiltInEntries())
return &out, nil
}
type state4 struct {
cron4.State
store adt.Store
}
func (s *state4) GetState() interface{} {
return &s.State
}

View File

@ -1,6 +1,7 @@
package init
import (
"github.com/filecoin-project/lotus/chain/actors"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
@ -39,6 +40,27 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
}
func MakeState(store adt.Store, av actors.Version, networkName string) (State, error) {
switch av {
{{range .versions}}
case actors.Version{{.}}:
return make{{.}}(store, networkName)
{{end}}
}
return nil, xerrors.Errorf("unknown actor version %d", av)
}
func GetActorCodeID(av actors.Version) (cid.Cid, error) {
switch av {
{{range .versions}}
case actors.Version{{.}}:
return builtin{{.}}.InitActorCodeID, nil
{{end}}
}
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
}
type State interface {
cbor.Marshaler
@ -56,5 +78,12 @@ type State interface {
// Sets the network's name. This should only be used on upgrade/fork.
SetNetworkName(name string) error
addressMap() (adt.Map, error)
// Sets the next ID for the init actor. This should only be used for testing.
SetNextID(id abi.ActorID) error
// Sets the address map for the init actor. This should only be used for testing.
SetAddressMap(mcid cid.Cid) error
AddressMap() (adt.Map, error)
GetState() interface{}
}

View File

@ -11,12 +11,12 @@ import (
)
func DiffAddressMap(pre, cur State) (*AddressMapChanges, error) {
prem, err := pre.addressMap()
prem, err := pre.AddressMap()
if err != nil {
return nil, err
}
curm, err := cur.addressMap()
curm, err := cur.AddressMap()
if err != nil {
return nil, err
}

View File

@ -1,6 +1,7 @@
package init
import (
"github.com/filecoin-project/lotus/chain/actors"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
@ -65,6 +66,45 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
}
func MakeState(store adt.Store, av actors.Version, networkName string) (State, error) {
switch av {
case actors.Version0:
return make0(store, networkName)
case actors.Version2:
return make2(store, networkName)
case actors.Version3:
return make3(store, networkName)
case actors.Version4:
return make4(store, networkName)
}
return nil, xerrors.Errorf("unknown actor version %d", av)
}
func GetActorCodeID(av actors.Version) (cid.Cid, error) {
switch av {
case actors.Version0:
return builtin0.InitActorCodeID, nil
case actors.Version2:
return builtin2.InitActorCodeID, nil
case actors.Version3:
return builtin3.InitActorCodeID, nil
case actors.Version4:
return builtin4.InitActorCodeID, nil
}
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
}
type State interface {
cbor.Marshaler
@ -82,5 +122,12 @@ type State interface {
// Sets the network's name. This should only be used on upgrade/fork.
SetNetworkName(name string) error
addressMap() (adt.Map, error)
// Sets the next ID for the init actor. This should only be used for testing.
SetNextID(id abi.ActorID) error
// Sets the address map for the init actor. This should only be used for testing.
SetAddressMap(mcid cid.Cid) error
AddressMap() (adt.Map, error)
GetState() interface{}
}

View File

@ -29,6 +29,26 @@ func load{{.v}}(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make{{.v}}(store adt.Store, networkName string) (State, error) {
out := state{{.v}}{store: store}
{{if (le .v 2)}}
mr, err := adt{{.v}}.MakeEmptyMap(store).Root()
if err != nil {
return nil, err
}
out.State = *init{{.v}}.ConstructState(mr, networkName)
{{else}}
s, err := init{{.v}}.ConstructState(store, networkName)
if err != nil {
return nil, err
}
out.State = *s
{{end}}
return &out, nil
}
type state{{.v}} struct {
init{{.v}}.State
store adt.Store
@ -66,6 +86,11 @@ func (s *state{{.v}}) SetNetworkName(name string) error {
return nil
}
func (s *state{{.v}}) SetNextID(id abi.ActorID) error {
s.State.NextID = id
return nil
}
func (s *state{{.v}}) Remove(addrs ...address.Address) (err error) {
m, err := adt{{.v}}.AsMap(s.store, s.State.AddressMap{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}})
if err != nil {
@ -84,6 +109,15 @@ func (s *state{{.v}}) Remove(addrs ...address.Address) (err error) {
return nil
}
func (s *state{{.v}}) addressMap() (adt.Map, error) {
return adt{{.v}}.AsMap(s.store, s.AddressMap{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}})
func (s *state{{.v}}) SetAddressMap(mcid cid.Cid) error {
s.State.AddressMap = mcid
return nil
}
func (s *state{{.v}}) AddressMap() (adt.Map, error) {
return adt{{.v}}.AsMap(s.store, s.State.AddressMap{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}})
}
func (s *state{{.v}}) GetState() interface{} {
return &s.State
}

View File

View File

@ -25,6 +25,19 @@ func load0(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make0(store adt.Store, networkName string) (State, error) {
out := state0{store: store}
mr, err := adt0.MakeEmptyMap(store).Root()
if err != nil {
return nil, err
}
out.State = *init0.ConstructState(mr, networkName)
return &out, nil
}
type state0 struct {
init0.State
store adt.Store
@ -62,6 +75,11 @@ func (s *state0) SetNetworkName(name string) error {
return nil
}
func (s *state0) SetNextID(id abi.ActorID) error {
s.State.NextID = id
return nil
}
func (s *state0) Remove(addrs ...address.Address) (err error) {
m, err := adt0.AsMap(s.store, s.State.AddressMap)
if err != nil {
@ -80,6 +98,15 @@ func (s *state0) Remove(addrs ...address.Address) (err error) {
return nil
}
func (s *state0) addressMap() (adt.Map, error) {
return adt0.AsMap(s.store, s.AddressMap)
func (s *state0) SetAddressMap(mcid cid.Cid) error {
s.State.AddressMap = mcid
return nil
}
func (s *state0) AddressMap() (adt.Map, error) {
return adt0.AsMap(s.store, s.State.AddressMap)
}
func (s *state0) GetState() interface{} {
return &s.State
}

View File

@ -25,6 +25,19 @@ func load2(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make2(store adt.Store, networkName string) (State, error) {
out := state2{store: store}
mr, err := adt2.MakeEmptyMap(store).Root()
if err != nil {
return nil, err
}
out.State = *init2.ConstructState(mr, networkName)
return &out, nil
}
type state2 struct {
init2.State
store adt.Store
@ -62,6 +75,11 @@ func (s *state2) SetNetworkName(name string) error {
return nil
}
func (s *state2) SetNextID(id abi.ActorID) error {
s.State.NextID = id
return nil
}
func (s *state2) Remove(addrs ...address.Address) (err error) {
m, err := adt2.AsMap(s.store, s.State.AddressMap)
if err != nil {
@ -80,6 +98,15 @@ func (s *state2) Remove(addrs ...address.Address) (err error) {
return nil
}
func (s *state2) addressMap() (adt.Map, error) {
return adt2.AsMap(s.store, s.AddressMap)
func (s *state2) SetAddressMap(mcid cid.Cid) error {
s.State.AddressMap = mcid
return nil
}
func (s *state2) AddressMap() (adt.Map, error) {
return adt2.AsMap(s.store, s.State.AddressMap)
}
func (s *state2) GetState() interface{} {
return &s.State
}

View File

@ -27,6 +27,19 @@ func load3(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make3(store adt.Store, networkName string) (State, error) {
out := state3{store: store}
s, err := init3.ConstructState(store, networkName)
if err != nil {
return nil, err
}
out.State = *s
return &out, nil
}
type state3 struct {
init3.State
store adt.Store
@ -64,6 +77,11 @@ func (s *state3) SetNetworkName(name string) error {
return nil
}
func (s *state3) SetNextID(id abi.ActorID) error {
s.State.NextID = id
return nil
}
func (s *state3) Remove(addrs ...address.Address) (err error) {
m, err := adt3.AsMap(s.store, s.State.AddressMap, builtin3.DefaultHamtBitwidth)
if err != nil {
@ -82,6 +100,15 @@ func (s *state3) Remove(addrs ...address.Address) (err error) {
return nil
}
func (s *state3) addressMap() (adt.Map, error) {
return adt3.AsMap(s.store, s.AddressMap, builtin3.DefaultHamtBitwidth)
func (s *state3) SetAddressMap(mcid cid.Cid) error {
s.State.AddressMap = mcid
return nil
}
func (s *state3) AddressMap() (adt.Map, error) {
return adt3.AsMap(s.store, s.State.AddressMap, builtin3.DefaultHamtBitwidth)
}
func (s *state3) GetState() interface{} {
return &s.State
}

View File

@ -27,6 +27,19 @@ func load4(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make4(store adt.Store, networkName string) (State, error) {
out := state4{store: store}
s, err := init4.ConstructState(store, networkName)
if err != nil {
return nil, err
}
out.State = *s
return &out, nil
}
type state4 struct {
init4.State
store adt.Store
@ -64,6 +77,11 @@ func (s *state4) SetNetworkName(name string) error {
return nil
}
func (s *state4) SetNextID(id abi.ActorID) error {
s.State.NextID = id
return nil
}
func (s *state4) Remove(addrs ...address.Address) (err error) {
m, err := adt4.AsMap(s.store, s.State.AddressMap, builtin4.DefaultHamtBitwidth)
if err != nil {
@ -82,6 +100,15 @@ func (s *state4) Remove(addrs ...address.Address) (err error) {
return nil
}
func (s *state4) addressMap() (adt.Map, error) {
return adt4.AsMap(s.store, s.AddressMap, builtin4.DefaultHamtBitwidth)
func (s *state4) SetAddressMap(mcid cid.Cid) error {
s.State.AddressMap = mcid
return nil
}
func (s *state4) AddressMap() (adt.Map, error) {
return adt4.AsMap(s.store, s.State.AddressMap, builtin4.DefaultHamtBitwidth)
}
func (s *state4) GetState() interface{} {
return &s.State
}

View File

@ -16,6 +16,7 @@ import (
{{end}}
"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/lotus/chain/types"
)
@ -42,6 +43,27 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
}
func MakeState(store adt.Store, av actors.Version) (State, error) {
switch av {
{{range .versions}}
case actors.Version{{.}}:
return make{{.}}(store)
{{end}}
}
return nil, xerrors.Errorf("unknown actor version %d", av)
}
func GetActorCodeID(av actors.Version) (cid.Cid, error) {
switch av {
{{range .versions}}
case actors.Version{{.}}:
return builtin{{.}}.StorageMarketActorCodeID, nil
{{end}}
}
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
}
type State interface {
cbor.Marshaler
BalancesChanged(State) (bool, error)
@ -56,6 +78,7 @@ type State interface {
minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch,
) (weight, verifiedWeight abi.DealWeight, err error)
NextID() (abi.DealID, error)
GetState() interface{}
}
type BalanceTable interface {
@ -81,7 +104,6 @@ type DealProposals interface {
type PublishStorageDealsParams = market0.PublishStorageDealsParams
type PublishStorageDealsReturn = market0.PublishStorageDealsReturn
type VerifyDealsForActivationParams = market0.VerifyDealsForActivationParams
type WithdrawBalanceParams = market0.WithdrawBalanceParams
type ClientDealProposal = market0.ClientDealProposal
@ -89,71 +111,71 @@ type ClientDealProposal = market0.ClientDealProposal
type DealState struct {
SectorStartEpoch abi.ChainEpoch // -1 if not yet included in proven sector
LastUpdatedEpoch abi.ChainEpoch // -1 if deal state never updated
SlashEpoch abi.ChainEpoch // -1 if deal never slashed
SlashEpoch abi.ChainEpoch // -1 if deal never slashed
}
type DealProposal struct {
PieceCID cid.Cid
PieceSize abi.PaddedPieceSize
VerifiedDeal bool
Client address.Address
Provider address.Address
Label string
StartEpoch abi.ChainEpoch
EndEpoch abi.ChainEpoch
PieceCID cid.Cid
PieceSize abi.PaddedPieceSize
VerifiedDeal bool
Client address.Address
Provider address.Address
Label string
StartEpoch abi.ChainEpoch
EndEpoch abi.ChainEpoch
StoragePricePerEpoch abi.TokenAmount
ProviderCollateral abi.TokenAmount
ClientCollateral abi.TokenAmount
ProviderCollateral abi.TokenAmount
ClientCollateral abi.TokenAmount
}
type DealStateChanges struct {
Added []DealIDState
Added []DealIDState
Modified []DealStateChange
Removed []DealIDState
Removed []DealIDState
}
type DealIDState struct {
ID abi.DealID
ID abi.DealID
Deal DealState
}
// DealStateChange is a change in deal state from -> to
type DealStateChange struct {
ID abi.DealID
ID abi.DealID
From *DealState
To *DealState
To *DealState
}
type DealProposalChanges struct {
Added []ProposalIDState
Added []ProposalIDState
Removed []ProposalIDState
}
type ProposalIDState struct {
ID abi.DealID
ID abi.DealID
Proposal DealProposal
}
func EmptyDealState() *DealState {
return &DealState{
SectorStartEpoch: -1,
SlashEpoch: -1,
SlashEpoch: -1,
LastUpdatedEpoch: -1,
}
}
// returns the earned fees and pending fees for a given deal
func (deal DealProposal) GetDealFees(height abi.ChainEpoch) (abi.TokenAmount, abi.TokenAmount) {
tf := big.Mul(deal.StoragePricePerEpoch, big.NewInt(int64(deal.EndEpoch-deal.StartEpoch)))
tf := big.Mul(deal.StoragePricePerEpoch, big.NewInt(int64(deal.EndEpoch-deal.StartEpoch)))
ef := big.Mul(deal.StoragePricePerEpoch, big.NewInt(int64(height-deal.StartEpoch)))
if ef.LessThan(big.Zero()) {
ef = big.Zero()
}
ef := big.Mul(deal.StoragePricePerEpoch, big.NewInt(int64(height-deal.StartEpoch)))
if ef.LessThan(big.Zero()) {
ef = big.Zero()
}
if ef.GreaterThan(tf) {
ef = tf
}
if ef.GreaterThan(tf) {
ef = tf
}
return ef, big.Sub(tf, ef)
return ef, big.Sub(tf, ef)
}

View File

@ -20,6 +20,7 @@ import (
builtin4 "github.com/filecoin-project/specs-actors/v4/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"
"github.com/filecoin-project/lotus/chain/types"
@ -68,6 +69,45 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
}
func MakeState(store adt.Store, av actors.Version) (State, error) {
switch av {
case actors.Version0:
return make0(store)
case actors.Version2:
return make2(store)
case actors.Version3:
return make3(store)
case actors.Version4:
return make4(store)
}
return nil, xerrors.Errorf("unknown actor version %d", av)
}
func GetActorCodeID(av actors.Version) (cid.Cid, error) {
switch av {
case actors.Version0:
return builtin0.StorageMarketActorCodeID, nil
case actors.Version2:
return builtin2.StorageMarketActorCodeID, nil
case actors.Version3:
return builtin3.StorageMarketActorCodeID, nil
case actors.Version4:
return builtin4.StorageMarketActorCodeID, nil
}
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
}
type State interface {
cbor.Marshaler
BalancesChanged(State) (bool, error)
@ -82,6 +122,7 @@ type State interface {
minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch,
) (weight, verifiedWeight abi.DealWeight, err error)
NextID() (abi.DealID, error)
GetState() interface{}
}
type BalanceTable interface {
@ -107,7 +148,6 @@ type DealProposals interface {
type PublishStorageDealsParams = market0.PublishStorageDealsParams
type PublishStorageDealsReturn = market0.PublishStorageDealsReturn
type VerifyDealsForActivationParams = market0.VerifyDealsForActivationParams
type WithdrawBalanceParams = market0.WithdrawBalanceParams
type ClientDealProposal = market0.ClientDealProposal

View File

@ -26,6 +26,31 @@ func load{{.v}}(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make{{.v}}(store adt.Store) (State, error) {
out := state{{.v}}{store: store}
{{if (le .v 2)}}
ea, err := adt{{.v}}.MakeEmptyArray(store).Root()
if err != nil {
return nil, err
}
em, err := adt{{.v}}.MakeEmptyMap(store).Root()
if err != nil {
return nil, err
}
out.State = *market{{.v}}.ConstructState(ea, em, em)
{{else}}
s, err := market{{.v}}.ConstructState(store)
if err != nil {
return nil, err
}
out.State = *s
{{end}}
return &out, nil
}
type state{{.v}} struct {
market{{.v}}.State
store adt.Store
@ -207,3 +232,7 @@ func (s *dealProposals{{.v}}) array() adt.Array {
func fromV{{.v}}DealProposal(v{{.v}} market{{.v}}.DealProposal) DealProposal {
return (DealProposal)(v{{.v}})
}
func (s *state{{.v}}) GetState() interface{} {
return &s.State
}

View File

View File

@ -26,6 +26,24 @@ func load0(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make0(store adt.Store) (State, error) {
out := state0{store: store}
ea, err := adt0.MakeEmptyArray(store).Root()
if err != nil {
return nil, err
}
em, err := adt0.MakeEmptyMap(store).Root()
if err != nil {
return nil, err
}
out.State = *market0.ConstructState(ea, em, em)
return &out, nil
}
type state0 struct {
market0.State
store adt.Store
@ -207,3 +225,7 @@ func (s *dealProposals0) array() adt.Array {
func fromV0DealProposal(v0 market0.DealProposal) DealProposal {
return (DealProposal)(v0)
}
func (s *state0) GetState() interface{} {
return &s.State
}

View File

@ -26,6 +26,24 @@ func load2(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make2(store adt.Store) (State, error) {
out := state2{store: store}
ea, err := adt2.MakeEmptyArray(store).Root()
if err != nil {
return nil, err
}
em, err := adt2.MakeEmptyMap(store).Root()
if err != nil {
return nil, err
}
out.State = *market2.ConstructState(ea, em, em)
return &out, nil
}
type state2 struct {
market2.State
store adt.Store
@ -207,3 +225,7 @@ func (s *dealProposals2) array() adt.Array {
func fromV2DealProposal(v2 market2.DealProposal) DealProposal {
return (DealProposal)(v2)
}
func (s *state2) GetState() interface{} {
return &s.State
}

View File

@ -26,6 +26,19 @@ func load3(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make3(store adt.Store) (State, error) {
out := state3{store: store}
s, err := market3.ConstructState(store)
if err != nil {
return nil, err
}
out.State = *s
return &out, nil
}
type state3 struct {
market3.State
store adt.Store
@ -207,3 +220,7 @@ func (s *dealProposals3) array() adt.Array {
func fromV3DealProposal(v3 market3.DealProposal) DealProposal {
return (DealProposal)(v3)
}
func (s *state3) GetState() interface{} {
return &s.State
}

View File

@ -26,6 +26,19 @@ func load4(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make4(store adt.Store) (State, error) {
out := state4{store: store}
s, err := market4.ConstructState(store)
if err != nil {
return nil, err
}
out.State = *s
return &out, nil
}
type state4 struct {
market4.State
store adt.Store
@ -207,3 +220,7 @@ func (s *dealProposals4) array() adt.Array {
func fromV4DealProposal(v4 market4.DealProposal) DealProposal {
return (DealProposal)(v4)
}
func (s *state4) GetState() interface{} {
return &s.State
}

View File

@ -3,6 +3,7 @@ package miner
import (
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/network"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/ipfs/go-cid"
"github.com/libp2p/go-libp2p-core/peer"
cbg "github.com/whyrusleeping/cbor-gen"
@ -60,6 +61,27 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
}
func MakeState(store adt.Store, av actors.Version) (State, error) {
switch av {
{{range .versions}}
case actors.Version{{.}}:
return make{{.}}(store)
{{end}}
}
return nil, xerrors.Errorf("unknown actor version %d", av)
}
func GetActorCodeID(av actors.Version) (cid.Cid, error) {
switch av {
{{range .versions}}
case actors.Version{{.}}:
return builtin{{.}}.StorageMinerActorCodeID, nil
{{end}}
}
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
}
type State interface {
cbor.Marshaler
@ -79,6 +101,11 @@ type State interface {
NumLiveSectors() (uint64, error)
IsAllocated(abi.SectorNumber) (bool, error)
// Note that ProvingPeriodStart is deprecated and will be renamed / removed in a future version of actors
GetProvingPeriodStart() (abi.ChainEpoch, error)
// Testing only
EraseAllUnproven() error
LoadDeadline(idx uint64) (Deadline, error)
ForEachDeadline(cb func(idx uint64, dl Deadline) error) error
NumDeadlines() (uint64, error)
@ -95,6 +122,7 @@ type State interface {
decodeSectorOnChainInfo(*cbg.Deferred) (SectorOnChainInfo, error)
precommits() (adt.Map, error)
decodeSectorPreCommitOnChainInfo(*cbg.Deferred) (SectorPreCommitOnChainInfo, error)
GetState() interface{}
}
type Deadline interface {
@ -115,26 +143,26 @@ type Partition interface {
}
type SectorOnChainInfo struct {
SectorNumber abi.SectorNumber
SealProof abi.RegisteredSealProof
SealedCID cid.Cid
DealIDs []abi.DealID
Activation abi.ChainEpoch
Expiration abi.ChainEpoch
DealWeight abi.DealWeight
VerifiedDealWeight abi.DealWeight
InitialPledge abi.TokenAmount
ExpectedDayReward abi.TokenAmount
SectorNumber abi.SectorNumber
SealProof abi.RegisteredSealProof
SealedCID cid.Cid
DealIDs []abi.DealID
Activation abi.ChainEpoch
Expiration abi.ChainEpoch
DealWeight abi.DealWeight
VerifiedDealWeight abi.DealWeight
InitialPledge abi.TokenAmount
ExpectedDayReward abi.TokenAmount
ExpectedStoragePledge abi.TokenAmount
}
type SectorPreCommitInfo = miner0.SectorPreCommitInfo
type SectorPreCommitOnChainInfo struct {
Info SectorPreCommitInfo
Info SectorPreCommitInfo
PreCommitDeposit abi.TokenAmount
PreCommitEpoch abi.ChainEpoch
DealWeight abi.DealWeight
PreCommitEpoch abi.ChainEpoch
DealWeight abi.DealWeight
VerifiedDealWeight abi.DealWeight
}
@ -203,17 +231,17 @@ func WinningPoStProofTypeFromWindowPoStProofType(nver network.Version, proof abi
}
type MinerInfo struct {
Owner address.Address // Must be an ID-address.
Worker address.Address // Must be an ID-address.
NewWorker address.Address // Must be an ID-address.
ControlAddresses []address.Address // Must be an ID-addresses.
WorkerChangeEpoch abi.ChainEpoch
PeerId *peer.ID
Multiaddrs []abi.Multiaddrs
WindowPoStProofType abi.RegisteredPoStProof
SectorSize abi.SectorSize
Owner address.Address // Must be an ID-address.
Worker address.Address // Must be an ID-address.
NewWorker address.Address // Must be an ID-address.
ControlAddresses []address.Address // Must be an ID-addresses.
WorkerChangeEpoch abi.ChainEpoch
PeerId *peer.ID
Multiaddrs []abi.Multiaddrs
WindowPoStProofType abi.RegisteredPoStProof
SectorSize abi.SectorSize
WindowPoStPartitionSectors uint64
ConsensusFaultElapsed abi.ChainEpoch
ConsensusFaultElapsed abi.ChainEpoch
}
func (mi MinerInfo) IsController(addr address.Address) bool {
@ -244,25 +272,25 @@ type SectorLocation struct {
}
type SectorChanges struct {
Added []SectorOnChainInfo
Added []SectorOnChainInfo
Extended []SectorExtensions
Removed []SectorOnChainInfo
Removed []SectorOnChainInfo
}
type SectorExtensions struct {
From SectorOnChainInfo
To SectorOnChainInfo
To SectorOnChainInfo
}
type PreCommitChanges struct {
Added []SectorPreCommitOnChainInfo
Added []SectorPreCommitOnChainInfo
Removed []SectorPreCommitOnChainInfo
}
type LockedFunds struct {
VestingFunds abi.TokenAmount
VestingFunds abi.TokenAmount
InitialPledgeRequirement abi.TokenAmount
PreCommitDeposits abi.TokenAmount
PreCommitDeposits abi.TokenAmount
}
func (lf LockedFunds) TotalLockedFunds() abi.TokenAmount {

View File

@ -3,6 +3,7 @@ package miner
import (
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/network"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/ipfs/go-cid"
"github.com/libp2p/go-libp2p-core/peer"
cbg "github.com/whyrusleeping/cbor-gen"
@ -86,6 +87,45 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
}
func MakeState(store adt.Store, av actors.Version) (State, error) {
switch av {
case actors.Version0:
return make0(store)
case actors.Version2:
return make2(store)
case actors.Version3:
return make3(store)
case actors.Version4:
return make4(store)
}
return nil, xerrors.Errorf("unknown actor version %d", av)
}
func GetActorCodeID(av actors.Version) (cid.Cid, error) {
switch av {
case actors.Version0:
return builtin0.StorageMinerActorCodeID, nil
case actors.Version2:
return builtin2.StorageMinerActorCodeID, nil
case actors.Version3:
return builtin3.StorageMinerActorCodeID, nil
case actors.Version4:
return builtin4.StorageMinerActorCodeID, nil
}
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
}
type State interface {
cbor.Marshaler
@ -105,6 +145,11 @@ type State interface {
NumLiveSectors() (uint64, error)
IsAllocated(abi.SectorNumber) (bool, error)
// Note that ProvingPeriodStart is deprecated and will be renamed / removed in a future version of actors
GetProvingPeriodStart() (abi.ChainEpoch, error)
// Testing only
EraseAllUnproven() error
LoadDeadline(idx uint64) (Deadline, error)
ForEachDeadline(cb func(idx uint64, dl Deadline) error) error
NumDeadlines() (uint64, error)
@ -121,6 +166,7 @@ type State interface {
decodeSectorOnChainInfo(*cbg.Deferred) (SectorOnChainInfo, error)
precommits() (adt.Map, error)
decodeSectorPreCommitOnChainInfo(*cbg.Deferred) (SectorPreCommitOnChainInfo, error)
GetState() interface{}
}
type Deadline interface {

View File

@ -35,6 +35,12 @@ func load{{.v}}(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make{{.v}}(store adt.Store) (State, error) {
out := state{{.v}}{store: store}
out.State = miner{{.v}}.State{}
return &out, nil
}
type state{{.v}} struct {
miner{{.v}}.State
store adt.Store
@ -68,9 +74,9 @@ func (s *state{{.v}}) VestedFunds(epoch abi.ChainEpoch) (abi.TokenAmount, error)
func (s *state{{.v}}) LockedFunds() (LockedFunds, error) {
return LockedFunds{
VestingFunds: s.State.LockedFunds,
VestingFunds: s.State.LockedFunds,
InitialPledgeRequirement: s.State.InitialPledge{{if (le .v 1)}}Requirement{{end}},
PreCommitDeposits: s.State.PreCommitDeposits,
PreCommitDeposits: s.State.PreCommitDeposits,
}, nil
}
@ -245,6 +251,10 @@ func (s *state{{.v}}) IsAllocated(num abi.SectorNumber) (bool, error) {
return allocatedSectors.IsSet(uint64(num))
}
func (s *state{{.v}}) GetProvingPeriodStart() (abi.ChainEpoch, error) {
return s.State.ProvingPeriodStart, nil
}
func (s *state{{.v}}) LoadDeadline(idx uint64) (Deadline, error) {
dls, err := s.State.LoadDeadlines(s.store)
if err != nil {
@ -307,19 +317,19 @@ func (s *state{{.v}}) Info() (MinerInfo, error) {
}
{{end}}
mi := MinerInfo{
Owner: info.Owner,
Worker: info.Worker,
Owner: info.Owner,
Worker: info.Worker,
ControlAddresses: info.ControlAddresses,
NewWorker: address.Undef,
NewWorker: address.Undef,
WorkerChangeEpoch: -1,
PeerId: pid,
Multiaddrs: info.Multiaddrs,
WindowPoStProofType: {{if (ge .v 3)}}info.WindowPoStProofType{{else}}wpp{{end}},
SectorSize: info.SectorSize,
PeerId: pid,
Multiaddrs: info.Multiaddrs,
WindowPoStProofType: {{if (ge .v 3)}}info.WindowPoStProofType{{else}}wpp{{end}},
SectorSize: info.SectorSize,
WindowPoStPartitionSectors: info.WindowPoStPartitionSectors,
ConsensusFaultElapsed: {{if (ge .v 2)}}info.ConsensusFaultElapsed{{else}}-1{{end}},
ConsensusFaultElapsed: {{if (ge .v 2)}}info.ConsensusFaultElapsed{{else}}-1{{end}},
}
if info.PendingWorkerKey != nil {
@ -366,6 +376,45 @@ func (s *state{{.v}}) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (Secto
return fromV{{.v}}SectorPreCommitOnChainInfo(sp), nil
}
func (s *state{{.v}}) EraseAllUnproven() error {
{{if (ge .v 2)}}
dls, err := s.State.LoadDeadlines(s.store)
if err != nil {
return err
}
err = dls.ForEach(s.store, func(dindx uint64, dl *miner{{.v}}.Deadline) error {
ps, err := dl.PartitionsArray(s.store)
if err != nil {
return err
}
var part miner{{.v}}.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)
})
return s.State.SaveDeadlines(s.store, dls)
{{else}}
// field doesn't exist until v2
{{end}}
return nil
}
func (d *deadline{{.v}}) LoadPartition(idx uint64) (Partition, error) {
p, err := d.Deadline.LoadPartition(d.store, idx)
if err != nil {
@ -428,16 +477,16 @@ func (p *partition{{.v}}) RecoveringSectors() (bitfield.BitField, error) {
func fromV{{.v}}SectorOnChainInfo(v{{.v}} miner{{.v}}.SectorOnChainInfo) SectorOnChainInfo {
{{if (ge .v 2)}}
return SectorOnChainInfo{
SectorNumber: v{{.v}}.SectorNumber,
SealProof: v{{.v}}.SealProof,
SealedCID: v{{.v}}.SealedCID,
DealIDs: v{{.v}}.DealIDs,
Activation: v{{.v}}.Activation,
Expiration: v{{.v}}.Expiration,
DealWeight: v{{.v}}.DealWeight,
VerifiedDealWeight: v{{.v}}.VerifiedDealWeight,
InitialPledge: v{{.v}}.InitialPledge,
ExpectedDayReward: v{{.v}}.ExpectedDayReward,
SectorNumber: v{{.v}}.SectorNumber,
SealProof: v{{.v}}.SealProof,
SealedCID: v{{.v}}.SealedCID,
DealIDs: v{{.v}}.DealIDs,
Activation: v{{.v}}.Activation,
Expiration: v{{.v}}.Expiration,
DealWeight: v{{.v}}.DealWeight,
VerifiedDealWeight: v{{.v}}.VerifiedDealWeight,
InitialPledge: v{{.v}}.InitialPledge,
ExpectedDayReward: v{{.v}}.ExpectedDayReward,
ExpectedStoragePledge: v{{.v}}.ExpectedStoragePledge,
}
{{else}}
@ -448,13 +497,17 @@ func fromV{{.v}}SectorOnChainInfo(v{{.v}} miner{{.v}}.SectorOnChainInfo) SectorO
func fromV{{.v}}SectorPreCommitOnChainInfo(v{{.v}} miner{{.v}}.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo {
{{if (ge .v 2)}}
return SectorPreCommitOnChainInfo{
Info: (SectorPreCommitInfo)(v{{.v}}.Info),
PreCommitDeposit: v{{.v}}.PreCommitDeposit,
PreCommitEpoch: v{{.v}}.PreCommitEpoch,
DealWeight: v{{.v}}.DealWeight,
Info: (SectorPreCommitInfo)(v{{.v}}.Info),
PreCommitDeposit: v{{.v}}.PreCommitDeposit,
PreCommitEpoch: v{{.v}}.PreCommitEpoch,
DealWeight: v{{.v}}.DealWeight,
VerifiedDealWeight: v{{.v}}.VerifiedDealWeight,
}
{{else}}
return (SectorPreCommitOnChainInfo)(v0)
{{end}}
}
func (s *state{{.v}}) GetState() interface{} {
return &s.State
}

View File

View File

@ -32,6 +32,12 @@ func load0(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make0(store adt.Store) (State, error) {
out := state0{store: store}
out.State = miner0.State{}
return &out, nil
}
type state0 struct {
miner0.State
store adt.Store
@ -242,6 +248,10 @@ func (s *state0) IsAllocated(num abi.SectorNumber) (bool, error) {
return allocatedSectors.IsSet(uint64(num))
}
func (s *state0) GetProvingPeriodStart() (abi.ChainEpoch, error) {
return s.State.ProvingPeriodStart, nil
}
func (s *state0) LoadDeadline(idx uint64) (Deadline, error) {
dls, err := s.State.LoadDeadlines(s.store)
if err != nil {
@ -363,6 +373,13 @@ func (s *state0) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreC
return fromV0SectorPreCommitOnChainInfo(sp), nil
}
func (s *state0) EraseAllUnproven() error {
// field doesn't exist until v2
return nil
}
func (d *deadline0) LoadPartition(idx uint64) (Partition, error) {
p, err := d.Deadline.LoadPartition(d.store, idx)
if err != nil {
@ -426,3 +443,7 @@ func fromV0SectorPreCommitOnChainInfo(v0 miner0.SectorPreCommitOnChainInfo) Sect
return (SectorPreCommitOnChainInfo)(v0)
}
func (s *state0) GetState() interface{} {
return &s.State
}

View File

@ -30,6 +30,12 @@ func load2(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make2(store adt.Store) (State, error) {
out := state2{store: store}
out.State = miner2.State{}
return &out, nil
}
type state2 struct {
miner2.State
store adt.Store
@ -240,6 +246,10 @@ func (s *state2) IsAllocated(num abi.SectorNumber) (bool, error) {
return allocatedSectors.IsSet(uint64(num))
}
func (s *state2) GetProvingPeriodStart() (abi.ChainEpoch, error) {
return s.State.ProvingPeriodStart, nil
}
func (s *state2) LoadDeadline(idx uint64) (Deadline, error) {
dls, err := s.State.LoadDeadlines(s.store)
if err != nil {
@ -361,6 +371,43 @@ func (s *state2) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreC
return fromV2SectorPreCommitOnChainInfo(sp), nil
}
func (s *state2) EraseAllUnproven() error {
dls, err := s.State.LoadDeadlines(s.store)
if err != nil {
return err
}
err = dls.ForEach(s.store, func(dindx uint64, dl *miner2.Deadline) error {
ps, err := dl.PartitionsArray(s.store)
if err != nil {
return err
}
var part miner2.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)
})
return s.State.SaveDeadlines(s.store, dls)
return nil
}
func (d *deadline2) LoadPartition(idx uint64) (Partition, error) {
p, err := d.Deadline.LoadPartition(d.store, idx)
if err != nil {
@ -442,3 +489,7 @@ func fromV2SectorPreCommitOnChainInfo(v2 miner2.SectorPreCommitOnChainInfo) Sect
}
}
func (s *state2) GetState() interface{} {
return &s.State
}

View File

@ -32,6 +32,12 @@ func load3(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make3(store adt.Store) (State, error) {
out := state3{store: store}
out.State = miner3.State{}
return &out, nil
}
type state3 struct {
miner3.State
store adt.Store
@ -242,6 +248,10 @@ func (s *state3) IsAllocated(num abi.SectorNumber) (bool, error) {
return allocatedSectors.IsSet(uint64(num))
}
func (s *state3) GetProvingPeriodStart() (abi.ChainEpoch, error) {
return s.State.ProvingPeriodStart, nil
}
func (s *state3) LoadDeadline(idx uint64) (Deadline, error) {
dls, err := s.State.LoadDeadlines(s.store)
if err != nil {
@ -358,6 +368,43 @@ func (s *state3) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreC
return fromV3SectorPreCommitOnChainInfo(sp), nil
}
func (s *state3) EraseAllUnproven() error {
dls, err := s.State.LoadDeadlines(s.store)
if err != nil {
return err
}
err = dls.ForEach(s.store, func(dindx uint64, dl *miner3.Deadline) error {
ps, err := dl.PartitionsArray(s.store)
if err != nil {
return err
}
var part miner3.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)
})
return s.State.SaveDeadlines(s.store, dls)
return nil
}
func (d *deadline3) LoadPartition(idx uint64) (Partition, error) {
p, err := d.Deadline.LoadPartition(d.store, idx)
if err != nil {
@ -443,3 +490,7 @@ func fromV3SectorPreCommitOnChainInfo(v3 miner3.SectorPreCommitOnChainInfo) Sect
}
}
func (s *state3) GetState() interface{} {
return &s.State
}

View File

@ -32,6 +32,12 @@ func load4(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make4(store adt.Store) (State, error) {
out := state4{store: store}
out.State = miner4.State{}
return &out, nil
}
type state4 struct {
miner4.State
store adt.Store
@ -242,6 +248,10 @@ func (s *state4) IsAllocated(num abi.SectorNumber) (bool, error) {
return allocatedSectors.IsSet(uint64(num))
}
func (s *state4) GetProvingPeriodStart() (abi.ChainEpoch, error) {
return s.State.ProvingPeriodStart, nil
}
func (s *state4) LoadDeadline(idx uint64) (Deadline, error) {
dls, err := s.State.LoadDeadlines(s.store)
if err != nil {
@ -358,6 +368,43 @@ func (s *state4) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreC
return fromV4SectorPreCommitOnChainInfo(sp), nil
}
func (s *state4) EraseAllUnproven() error {
dls, err := s.State.LoadDeadlines(s.store)
if err != nil {
return err
}
err = dls.ForEach(s.store, func(dindx uint64, dl *miner4.Deadline) error {
ps, err := dl.PartitionsArray(s.store)
if err != nil {
return err
}
var part miner4.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)
})
return s.State.SaveDeadlines(s.store, dls)
return nil
}
func (d *deadline4) LoadPartition(idx uint64) (Partition, error) {
p, err := d.Deadline.LoadPartition(d.store, idx)
if err != nil {
@ -443,3 +490,7 @@ func fromV4SectorPreCommitOnChainInfo(v4 miner4.SectorPreCommitOnChainInfo) Sect
}
}
func (s *state4) GetState() interface{} {
return &s.State
}

View File

@ -40,6 +40,27 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
}
func MakeState(store adt.Store, av actors.Version, signers []address.Address, threshold uint64, startEpoch abi.ChainEpoch, unlockDuration abi.ChainEpoch, initialBalance abi.TokenAmount) (State, error) {
switch av {
{{range .versions}}
case actors.Version{{.}}:
return make{{.}}(store, signers, threshold, startEpoch, unlockDuration, initialBalance)
{{end}}
}
return nil, xerrors.Errorf("unknown actor version %d", av)
}
func GetActorCodeID(av actors.Version) (cid.Cid, error) {
switch av {
{{range .versions}}
case actors.Version{{.}}:
return builtin{{.}}.MultisigActorCodeID, nil
{{end}}
}
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
}
type State interface {
cbor.Marshaler
@ -55,6 +76,7 @@ type State interface {
transactions() (adt.Map, error)
decodeTransaction(val *cbg.Deferred) (Transaction, error)
GetState() interface{}
}
type Transaction = msig{{.latestVersion}}.Transaction
@ -66,7 +88,7 @@ func Message(version actors.Version, from address.Address) MessageBuilder {
{{range .versions}}
case actors.Version{{.}}:
return message{{.}}{{"{"}}{{if (ge . 2)}}message0{from}{{else}}from{{end}}}
{{end}} default:
{{end}} default:
panic(fmt.Sprintf("unsupported actors version: %d", version))
}
}

View File

@ -43,10 +43,10 @@ func (m message{{.v}}) Create(
{{end}}
// Set up constructor parameters for multisig
msigParams := &multisig{{.v}}.ConstructorParams{
Signers: signers,
Signers: signers,
NumApprovalsThreshold: threshold,
UnlockDuration: unlockDuration,{{if (ge .v 2)}}
StartEpoch: unlockStart,{{end}}
UnlockDuration: unlockDuration,{{if (ge .v 2)}}
StartEpoch: unlockStart,{{end}}
}
enc, actErr := actors.SerializeParams(msigParams)
@ -56,7 +56,7 @@ func (m message{{.v}}) Create(
// new actors are created by invoking 'exec' on the init actor with the constructor params
execParams := &init{{.v}}.ExecParams{
CodeCID: builtin{{.v}}.MultisigActorCodeID,
CodeCID: builtin{{.v}}.MultisigActorCodeID,
ConstructorParams: enc,
}
@ -66,11 +66,11 @@ func (m message{{.v}}) Create(
}
return &types.Message{
To: init_.Address,
From: m.from,
To: init_.Address,
From: m.from,
Method: builtin{{.v}}.MethodsInit.Exec,
Params: enc,
Value: initialAmount,
Value: initialAmount,
}, nil
}
@ -96,8 +96,8 @@ func (m message0) Propose(msig, to address.Address, amt abi.TokenAmount,
}
enc, actErr := actors.SerializeParams(&multisig0.ProposeParams{
To: to,
Value: amt,
To: to,
Value: amt,
Method: method,
Params: params,
})
@ -106,9 +106,9 @@ func (m message0) Propose(msig, to address.Address, amt abi.TokenAmount,
}
return &types.Message{
To: msig,
From: m.from,
Value: abi.NewTokenAmount(0),
To: msig,
From: m.from,
Value: abi.NewTokenAmount(0),
Method: builtin0.MethodsMultisig.Propose,
Params: enc,
}, nil
@ -121,9 +121,9 @@ func (m message0) Approve(msig address.Address, txID uint64, hashData *ProposalH
}
return &types.Message{
To: msig,
From: m.from,
Value: types.NewInt(0),
To: msig,
From: m.from,
Value: types.NewInt(0),
Method: builtin0.MethodsMultisig.Approve,
Params: enc,
}, nil
@ -136,9 +136,9 @@ func (m message0) Cancel(msig address.Address, txID uint64, hashData *ProposalHa
}
return &types.Message{
To: msig,
From: m.from,
Value: types.NewInt(0),
To: msig,
From: m.from,
Value: types.NewInt(0),
Method: builtin0.MethodsMultisig.Cancel,
Params: enc,
}, nil

View File

@ -66,6 +66,45 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
}
func MakeState(store adt.Store, av actors.Version, signers []address.Address, threshold uint64, startEpoch abi.ChainEpoch, unlockDuration abi.ChainEpoch, initialBalance abi.TokenAmount) (State, error) {
switch av {
case actors.Version0:
return make0(store, signers, threshold, startEpoch, unlockDuration, initialBalance)
case actors.Version2:
return make2(store, signers, threshold, startEpoch, unlockDuration, initialBalance)
case actors.Version3:
return make3(store, signers, threshold, startEpoch, unlockDuration, initialBalance)
case actors.Version4:
return make4(store, signers, threshold, startEpoch, unlockDuration, initialBalance)
}
return nil, xerrors.Errorf("unknown actor version %d", av)
}
func GetActorCodeID(av actors.Version) (cid.Cid, error) {
switch av {
case actors.Version0:
return builtin0.MultisigActorCodeID, nil
case actors.Version2:
return builtin2.MultisigActorCodeID, nil
case actors.Version3:
return builtin3.MultisigActorCodeID, nil
case actors.Version4:
return builtin4.MultisigActorCodeID, nil
}
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
}
type State interface {
cbor.Marshaler
@ -81,6 +120,7 @@ type State interface {
transactions() (adt.Map, error)
decodeTransaction(val *cbg.Deferred) (Transaction, error)
GetState() interface{}
}
type Transaction = msig4.Transaction

View File

@ -31,6 +31,32 @@ func load{{.v}}(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make{{.v}}(store adt.Store, signers []address.Address, threshold uint64, startEpoch abi.ChainEpoch, unlockDuration abi.ChainEpoch, initialBalance abi.TokenAmount) (State, error) {
out := state{{.v}}{store: store}
out.State = msig{{.v}}.State{}
out.State.Signers = signers
out.State.NumApprovalsThreshold = threshold
out.State.StartEpoch = startEpoch
out.State.UnlockDuration = unlockDuration
out.State.InitialBalance = initialBalance
{{if (le .v 2)}}
em, err := adt{{.v}}.MakeEmptyMap(store).Root()
if err != nil {
return nil, err
}
out.State.PendingTxns = em
{{else}}
em, err := adt{{.v}}.StoreEmptyMap(store, builtin{{.v}}.DefaultHamtBitwidth)
if err != nil {
return nil, err
}
out.State.PendingTxns = em
{{end}}
return &out, nil
}
type state{{.v}} struct {
msig{{.v}}.State
store adt.Store
@ -95,3 +121,7 @@ func (s *state{{.v}}) decodeTransaction(val *cbg.Deferred) (Transaction, error)
}
return tx, nil
}
func (s *state{{.v}}) GetState() interface{} {
return &s.State
}

View File

View File

@ -28,6 +28,25 @@ func load0(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make0(store adt.Store, signers []address.Address, threshold uint64, startEpoch abi.ChainEpoch, unlockDuration abi.ChainEpoch, initialBalance abi.TokenAmount) (State, error) {
out := state0{store: store}
out.State = msig0.State{}
out.State.Signers = signers
out.State.NumApprovalsThreshold = threshold
out.State.StartEpoch = startEpoch
out.State.UnlockDuration = unlockDuration
out.State.InitialBalance = initialBalance
em, err := adt0.MakeEmptyMap(store).Root()
if err != nil {
return nil, err
}
out.State.PendingTxns = em
return &out, nil
}
type state0 struct {
msig0.State
store adt.Store
@ -92,3 +111,7 @@ func (s *state0) decodeTransaction(val *cbg.Deferred) (Transaction, error) {
}
return tx, nil
}
func (s *state0) GetState() interface{} {
return &s.State
}

View File

@ -28,6 +28,25 @@ func load2(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make2(store adt.Store, signers []address.Address, threshold uint64, startEpoch abi.ChainEpoch, unlockDuration abi.ChainEpoch, initialBalance abi.TokenAmount) (State, error) {
out := state2{store: store}
out.State = msig2.State{}
out.State.Signers = signers
out.State.NumApprovalsThreshold = threshold
out.State.StartEpoch = startEpoch
out.State.UnlockDuration = unlockDuration
out.State.InitialBalance = initialBalance
em, err := adt2.MakeEmptyMap(store).Root()
if err != nil {
return nil, err
}
out.State.PendingTxns = em
return &out, nil
}
type state2 struct {
msig2.State
store adt.Store
@ -92,3 +111,7 @@ func (s *state2) decodeTransaction(val *cbg.Deferred) (Transaction, error) {
}
return tx, nil
}
func (s *state2) GetState() interface{} {
return &s.State
}

View File

@ -30,6 +30,25 @@ func load3(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make3(store adt.Store, signers []address.Address, threshold uint64, startEpoch abi.ChainEpoch, unlockDuration abi.ChainEpoch, initialBalance abi.TokenAmount) (State, error) {
out := state3{store: store}
out.State = msig3.State{}
out.State.Signers = signers
out.State.NumApprovalsThreshold = threshold
out.State.StartEpoch = startEpoch
out.State.UnlockDuration = unlockDuration
out.State.InitialBalance = initialBalance
em, err := adt3.StoreEmptyMap(store, builtin3.DefaultHamtBitwidth)
if err != nil {
return nil, err
}
out.State.PendingTxns = em
return &out, nil
}
type state3 struct {
msig3.State
store adt.Store
@ -94,3 +113,7 @@ func (s *state3) decodeTransaction(val *cbg.Deferred) (Transaction, error) {
}
return tx, nil
}
func (s *state3) GetState() interface{} {
return &s.State
}

View File

@ -30,6 +30,25 @@ func load4(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make4(store adt.Store, signers []address.Address, threshold uint64, startEpoch abi.ChainEpoch, unlockDuration abi.ChainEpoch, initialBalance abi.TokenAmount) (State, error) {
out := state4{store: store}
out.State = msig4.State{}
out.State.Signers = signers
out.State.NumApprovalsThreshold = threshold
out.State.StartEpoch = startEpoch
out.State.UnlockDuration = unlockDuration
out.State.InitialBalance = initialBalance
em, err := adt4.StoreEmptyMap(store, builtin4.DefaultHamtBitwidth)
if err != nil {
return nil, err
}
out.State.PendingTxns = em
return &out, nil
}
type state4 struct {
msig4.State
store adt.Store
@ -94,3 +113,7 @@ func (s *state4) decodeTransaction(val *cbg.Deferred) (Transaction, error) {
}
return tx, nil
}
func (s *state4) GetState() interface{} {
return &s.State
}

View File

@ -42,6 +42,27 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
}
func MakeState(store adt.Store, av actors.Version) (State, error) {
switch av {
{{range .versions}}
case actors.Version{{.}}:
return make{{.}}(store)
{{end}}
}
return nil, xerrors.Errorf("unknown actor version %d", av)
}
func GetActorCodeID(av actors.Version) (cid.Cid, error) {
switch av {
{{range .versions}}
case actors.Version{{.}}:
return builtin{{.}}.PaymentChannelActorCodeID, nil
{{end}}
}
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
}
// State is an abstract version of payment channel state that works across
// versions
type State interface {
@ -62,6 +83,8 @@ type State interface {
// Iterate lane states
ForEachLaneState(cb func(idx uint64, dl LaneState) error) error
GetState() interface{}
}
// LaneState is an abstract copy of the state of a single lane

View File

@ -21,7 +21,7 @@ func (m message{{.v}}) Create(to address.Address, initialAmount abi.TokenAmount)
return nil, aerr
}
enc, aerr := actors.SerializeParams(&init{{.v}}.ExecParams{
CodeCID: builtin{{.v}}.PaymentChannelActorCodeID,
CodeCID: builtin{{.v}}.PaymentChannelActorCodeID,
ConstructorParams: params,
})
if aerr != nil {
@ -29,9 +29,9 @@ func (m message{{.v}}) Create(to address.Address, initialAmount abi.TokenAmount)
}
return &types.Message{
To: init_.Address,
From: m.from,
Value: initialAmount,
To: init_.Address,
From: m.from,
Value: initialAmount,
Method: builtin{{.v}}.MethodsInit.Exec,
Params: enc,
}, nil
@ -39,7 +39,7 @@ func (m message{{.v}}) Create(to address.Address, initialAmount abi.TokenAmount)
func (m message{{.v}}) Update(paych address.Address, sv *SignedVoucher, secret []byte) (*types.Message, error) {
params, aerr := actors.SerializeParams(&paych{{.v}}.UpdateChannelStateParams{
Sv: *sv,
Sv: *sv,
Secret: secret,
})
if aerr != nil {
@ -47,9 +47,9 @@ func (m message{{.v}}) Update(paych address.Address, sv *SignedVoucher, secret [
}
return &types.Message{
To: paych,
From: m.from,
Value: abi.NewTokenAmount(0),
To: paych,
From: m.from,
Value: abi.NewTokenAmount(0),
Method: builtin{{.v}}.MethodsPaych.UpdateChannelState,
Params: params,
}, nil
@ -57,18 +57,18 @@ func (m message{{.v}}) Update(paych address.Address, sv *SignedVoucher, secret [
func (m message{{.v}}) Settle(paych address.Address) (*types.Message, error) {
return &types.Message{
To: paych,
From: m.from,
Value: abi.NewTokenAmount(0),
To: paych,
From: m.from,
Value: abi.NewTokenAmount(0),
Method: builtin{{.v}}.MethodsPaych.Settle,
}, nil
}
func (m message{{.v}}) Collect(paych address.Address) (*types.Message, error) {
return &types.Message{
To: paych,
From: m.from,
Value: abi.NewTokenAmount(0),
To: paych,
From: m.from,
Value: abi.NewTokenAmount(0),
Method: builtin{{.v}}.MethodsPaych.Collect,
}, nil
}

View File

@ -17,6 +17,10 @@ type mockState struct {
lanes map[uint64]paych.LaneState
}
func (ms *mockState) GetState() interface{} {
panic("implement me")
}
type mockLaneState struct {
redeemed big.Int
nonce uint64

View File

View File

@ -68,6 +68,45 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
}
func MakeState(store adt.Store, av actors.Version) (State, error) {
switch av {
case actors.Version0:
return make0(store)
case actors.Version2:
return make2(store)
case actors.Version3:
return make3(store)
case actors.Version4:
return make4(store)
}
return nil, xerrors.Errorf("unknown actor version %d", av)
}
func GetActorCodeID(av actors.Version) (cid.Cid, error) {
switch av {
case actors.Version0:
return builtin0.PaymentChannelActorCodeID, nil
case actors.Version2:
return builtin2.PaymentChannelActorCodeID, nil
case actors.Version3:
return builtin3.PaymentChannelActorCodeID, nil
case actors.Version4:
return builtin4.PaymentChannelActorCodeID, nil
}
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
}
// State is an abstract version of payment channel state that works across
// versions
type State interface {
@ -88,6 +127,8 @@ type State interface {
// Iterate lane states
ForEachLaneState(cb func(idx uint64, dl LaneState) error) error
GetState() interface{}
}
// LaneState is an abstract copy of the state of a single lane

View File

@ -24,6 +24,12 @@ func load{{.v}}(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make{{.v}}(store adt.Store) (State, error) {
out := state{{.v}}{store: store}
out.State = paych{{.v}}.State{}
return &out, nil
}
type state{{.v}} struct {
paych{{.v}}.State
store adt.Store
@ -74,6 +80,10 @@ func (s *state{{.v}}) LaneCount() (uint64, error) {
return lsamt.Length(), nil
}
func (s *state{{.v}}) GetState() interface{} {
return &s.State
}
// Iterate lane states
func (s *state{{.v}}) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error {
// Get the lane state from the chain

View File

View File

@ -24,6 +24,12 @@ func load0(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make0(store adt.Store) (State, error) {
out := state0{store: store}
out.State = paych0.State{}
return &out, nil
}
type state0 struct {
paych0.State
store adt.Store
@ -74,6 +80,10 @@ func (s *state0) LaneCount() (uint64, error) {
return lsamt.Length(), nil
}
func (s *state0) GetState() interface{} {
return &s.State
}
// Iterate lane states
func (s *state0) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error {
// Get the lane state from the chain

View File

@ -24,6 +24,12 @@ func load2(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make2(store adt.Store) (State, error) {
out := state2{store: store}
out.State = paych2.State{}
return &out, nil
}
type state2 struct {
paych2.State
store adt.Store
@ -74,6 +80,10 @@ func (s *state2) LaneCount() (uint64, error) {
return lsamt.Length(), nil
}
func (s *state2) GetState() interface{} {
return &s.State
}
// Iterate lane states
func (s *state2) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error {
// Get the lane state from the chain

View File

@ -24,6 +24,12 @@ func load3(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make3(store adt.Store) (State, error) {
out := state3{store: store}
out.State = paych3.State{}
return &out, nil
}
type state3 struct {
paych3.State
store adt.Store
@ -74,6 +80,10 @@ func (s *state3) LaneCount() (uint64, error) {
return lsamt.Length(), nil
}
func (s *state3) GetState() interface{} {
return &s.State
}
// Iterate lane states
func (s *state3) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error {
// Get the lane state from the chain

View File

@ -24,6 +24,12 @@ func load4(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make4(store adt.Store) (State, error) {
out := state4{store: store}
out.State = paych4.State{}
return &out, nil
}
type state4 struct {
paych4.State
store adt.Store
@ -74,6 +80,10 @@ func (s *state4) LaneCount() (uint64, error) {
return lsamt.Length(), nil
}
func (s *state4) GetState() interface{} {
return &s.State
}
// Iterate lane states
func (s *state4) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error {
// Get the lane state from the chain

View File

@ -3,6 +3,7 @@ package power
import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"
@ -40,6 +41,27 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
}
func MakeState(store adt.Store, av actors.Version) (State, error) {
switch av {
{{range .versions}}
case actors.Version{{.}}:
return make{{.}}(store)
{{end}}
}
return nil, xerrors.Errorf("unknown actor version %d", av)
}
func GetActorCodeID(av actors.Version) (cid.Cid, error) {
switch av {
{{range .versions}}
case actors.Version{{.}}:
return builtin{{.}}.StoragePowerActorCodeID, nil
{{end}}
}
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
}
type State interface {
cbor.Marshaler
@ -47,6 +69,7 @@ type State interface {
TotalPower() (Claim, error)
TotalCommitted() (Claim, error)
TotalPowerSmoothed() (builtin.FilterEstimate, error)
GetState() interface{}
// MinerCounts returns the number of miners. Participating is the number
// with power above the minimum miner threshold.
@ -57,6 +80,12 @@ type State interface {
ForEachClaim(func(miner address.Address, claim Claim) error) error
ClaimsChanged(State) (bool, error)
// Testing or genesis setup only
SetTotalQualityAdjPower(abi.StoragePower) error
SetTotalRawBytePower(abi.StoragePower) error
SetThisEpochQualityAdjPower(abi.StoragePower) error
SetThisEpochRawBytePower(abi.StoragePower) error
// Diff helpers. Used by Diff* functions internally.
claims() (adt.Map, error)
decodeClaim(*cbg.Deferred) (Claim, error)
@ -72,7 +101,7 @@ type Claim struct {
func AddClaims(a Claim, b Claim) Claim {
return Claim{
RawBytePower: big.Add(a.RawBytePower, b.RawBytePower),
RawBytePower: big.Add(a.RawBytePower, b.RawBytePower),
QualityAdjPower: big.Add(a.QualityAdjPower, b.QualityAdjPower),
}
}

View File

@ -3,6 +3,7 @@ package power
import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"
@ -66,6 +67,45 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
}
func MakeState(store adt.Store, av actors.Version) (State, error) {
switch av {
case actors.Version0:
return make0(store)
case actors.Version2:
return make2(store)
case actors.Version3:
return make3(store)
case actors.Version4:
return make4(store)
}
return nil, xerrors.Errorf("unknown actor version %d", av)
}
func GetActorCodeID(av actors.Version) (cid.Cid, error) {
switch av {
case actors.Version0:
return builtin0.StoragePowerActorCodeID, nil
case actors.Version2:
return builtin2.StoragePowerActorCodeID, nil
case actors.Version3:
return builtin3.StoragePowerActorCodeID, nil
case actors.Version4:
return builtin4.StoragePowerActorCodeID, nil
}
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
}
type State interface {
cbor.Marshaler
@ -73,6 +113,7 @@ type State interface {
TotalPower() (Claim, error)
TotalCommitted() (Claim, error)
TotalPowerSmoothed() (builtin.FilterEstimate, error)
GetState() interface{}
// MinerCounts returns the number of miners. Participating is the number
// with power above the minimum miner threshold.
@ -83,6 +124,12 @@ type State interface {
ForEachClaim(func(miner address.Address, claim Claim) error) error
ClaimsChanged(State) (bool, error)
// Testing or genesis setup only
SetTotalQualityAdjPower(abi.StoragePower) error
SetTotalRawBytePower(abi.StoragePower) error
SetThisEpochQualityAdjPower(abi.StoragePower) error
SetThisEpochRawBytePower(abi.StoragePower) error
// Diff helpers. Used by Diff* functions internally.
claims() (adt.Map, error)
decodeClaim(*cbg.Deferred) (Claim, error)

View File

@ -29,6 +29,32 @@ func load{{.v}}(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make{{.v}}(store adt.Store) (State, error) {
out := state{{.v}}{store: store}
{{if (le .v 2)}}
em, err := adt{{.v}}.MakeEmptyMap(store).Root()
if err != nil {
return nil, err
}
emm, err := adt{{.v}}.MakeEmptyMultimap(store).Root()
if err != nil {
return nil, err
}
out.State = *power{{.v}}.ConstructState(em, emm)
{{else}}
s, err := power{{.v}}.ConstructState(store)
if err != nil {
return nil, err
}
out.State = *s
{{end}}
return &out, nil
}
type state{{.v}} struct {
power{{.v}}.State
store adt.Store
@ -40,7 +66,7 @@ func (s *state{{.v}}) TotalLocked() (abi.TokenAmount, error) {
func (s *state{{.v}}) TotalPower() (Claim, error) {
return Claim{
RawBytePower: s.TotalRawBytePower,
RawBytePower: s.TotalRawBytePower,
QualityAdjPower: s.TotalQualityAdjPower,
}, nil
}
@ -48,7 +74,7 @@ func (s *state{{.v}}) TotalPower() (Claim, error) {
// Committed power to the network. Includes miners below the minimum threshold.
func (s *state{{.v}}) TotalCommitted() (Claim, error) {
return Claim{
RawBytePower: s.TotalBytesCommitted,
RawBytePower: s.TotalBytesCommitted,
QualityAdjPower: s.TotalQABytesCommitted,
}, nil
}
@ -64,7 +90,7 @@ func (s *state{{.v}}) MinerPower(addr address.Address) (Claim, bool, error) {
return Claim{}, false, err
}
return Claim{
RawBytePower: claim.RawBytePower,
RawBytePower: claim.RawBytePower,
QualityAdjPower: claim.QualityAdjPower,
}, ok, nil
}
@ -116,7 +142,7 @@ func (s *state{{.v}}) ForEachClaim(cb func(miner address.Address, claim Claim) e
return err
}
return cb(a, Claim{
RawBytePower: claim.RawBytePower,
RawBytePower: claim.RawBytePower,
QualityAdjPower: claim.QualityAdjPower,
})
})
@ -131,6 +157,30 @@ func (s *state{{.v}}) ClaimsChanged(other State) (bool, error) {
return !s.State.Claims.Equals(other{{.v}}.State.Claims), nil
}
func (s *state{{.v}}) SetTotalQualityAdjPower(p abi.StoragePower) error {
s.State.TotalQualityAdjPower = p
return nil
}
func (s *state{{.v}}) SetTotalRawBytePower(p abi.StoragePower) error {
s.State.TotalRawBytePower = p
return nil
}
func (s *state{{.v}}) SetThisEpochQualityAdjPower(p abi.StoragePower) error {
s.State.ThisEpochQualityAdjPower = p
return nil
}
func (s *state{{.v}}) SetThisEpochRawBytePower(p abi.StoragePower) error {
s.State.ThisEpochRawBytePower = p
return nil
}
func (s *state{{.v}}) GetState() interface{} {
return &s.State
}
func (s *state{{.v}}) claims() (adt.Map, error) {
return adt{{.v}}.AsMap(s.store, s.Claims{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}})
}
@ -145,7 +195,7 @@ func (s *state{{.v}}) decodeClaim(val *cbg.Deferred) (Claim, error) {
func fromV{{.v}}Claim(v{{.v}} power{{.v}}.Claim) Claim {
return Claim{
RawBytePower: v{{.v}}.RawBytePower,
RawBytePower: v{{.v}}.RawBytePower,
QualityAdjPower: v{{.v}}.QualityAdjPower,
}
}

View File

View File

@ -26,6 +26,24 @@ func load0(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make0(store adt.Store) (State, error) {
out := state0{store: store}
em, err := adt0.MakeEmptyMap(store).Root()
if err != nil {
return nil, err
}
emm, err := adt0.MakeEmptyMultimap(store).Root()
if err != nil {
return nil, err
}
out.State = *power0.ConstructState(em, emm)
return &out, nil
}
type state0 struct {
power0.State
store adt.Store
@ -128,6 +146,30 @@ func (s *state0) ClaimsChanged(other State) (bool, error) {
return !s.State.Claims.Equals(other0.State.Claims), nil
}
func (s *state0) SetTotalQualityAdjPower(p abi.StoragePower) error {
s.State.TotalQualityAdjPower = p
return nil
}
func (s *state0) SetTotalRawBytePower(p abi.StoragePower) error {
s.State.TotalRawBytePower = p
return nil
}
func (s *state0) SetThisEpochQualityAdjPower(p abi.StoragePower) error {
s.State.ThisEpochQualityAdjPower = p
return nil
}
func (s *state0) SetThisEpochRawBytePower(p abi.StoragePower) error {
s.State.ThisEpochRawBytePower = p
return nil
}
func (s *state0) GetState() interface{} {
return &s.State
}
func (s *state0) claims() (adt.Map, error) {
return adt0.AsMap(s.store, s.Claims)
}

View File

@ -26,6 +26,24 @@ func load2(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make2(store adt.Store) (State, error) {
out := state2{store: store}
em, err := adt2.MakeEmptyMap(store).Root()
if err != nil {
return nil, err
}
emm, err := adt2.MakeEmptyMultimap(store).Root()
if err != nil {
return nil, err
}
out.State = *power2.ConstructState(em, emm)
return &out, nil
}
type state2 struct {
power2.State
store adt.Store
@ -128,6 +146,30 @@ func (s *state2) ClaimsChanged(other State) (bool, error) {
return !s.State.Claims.Equals(other2.State.Claims), nil
}
func (s *state2) SetTotalQualityAdjPower(p abi.StoragePower) error {
s.State.TotalQualityAdjPower = p
return nil
}
func (s *state2) SetTotalRawBytePower(p abi.StoragePower) error {
s.State.TotalRawBytePower = p
return nil
}
func (s *state2) SetThisEpochQualityAdjPower(p abi.StoragePower) error {
s.State.ThisEpochQualityAdjPower = p
return nil
}
func (s *state2) SetThisEpochRawBytePower(p abi.StoragePower) error {
s.State.ThisEpochRawBytePower = p
return nil
}
func (s *state2) GetState() interface{} {
return &s.State
}
func (s *state2) claims() (adt.Map, error) {
return adt2.AsMap(s.store, s.Claims)
}

View File

@ -28,6 +28,19 @@ func load3(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make3(store adt.Store) (State, error) {
out := state3{store: store}
s, err := power3.ConstructState(store)
if err != nil {
return nil, err
}
out.State = *s
return &out, nil
}
type state3 struct {
power3.State
store adt.Store
@ -130,6 +143,30 @@ func (s *state3) ClaimsChanged(other State) (bool, error) {
return !s.State.Claims.Equals(other3.State.Claims), nil
}
func (s *state3) SetTotalQualityAdjPower(p abi.StoragePower) error {
s.State.TotalQualityAdjPower = p
return nil
}
func (s *state3) SetTotalRawBytePower(p abi.StoragePower) error {
s.State.TotalRawBytePower = p
return nil
}
func (s *state3) SetThisEpochQualityAdjPower(p abi.StoragePower) error {
s.State.ThisEpochQualityAdjPower = p
return nil
}
func (s *state3) SetThisEpochRawBytePower(p abi.StoragePower) error {
s.State.ThisEpochRawBytePower = p
return nil
}
func (s *state3) GetState() interface{} {
return &s.State
}
func (s *state3) claims() (adt.Map, error) {
return adt3.AsMap(s.store, s.Claims, builtin3.DefaultHamtBitwidth)
}

View File

@ -28,6 +28,19 @@ func load4(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make4(store adt.Store) (State, error) {
out := state4{store: store}
s, err := power4.ConstructState(store)
if err != nil {
return nil, err
}
out.State = *s
return &out, nil
}
type state4 struct {
power4.State
store adt.Store
@ -130,6 +143,30 @@ func (s *state4) ClaimsChanged(other State) (bool, error) {
return !s.State.Claims.Equals(other4.State.Claims), nil
}
func (s *state4) SetTotalQualityAdjPower(p abi.StoragePower) error {
s.State.TotalQualityAdjPower = p
return nil
}
func (s *state4) SetTotalRawBytePower(p abi.StoragePower) error {
s.State.TotalRawBytePower = p
return nil
}
func (s *state4) SetThisEpochQualityAdjPower(p abi.StoragePower) error {
s.State.ThisEpochQualityAdjPower = p
return nil
}
func (s *state4) SetThisEpochRawBytePower(p abi.StoragePower) error {
s.State.ThisEpochRawBytePower = p
return nil
}
func (s *state4) GetState() interface{} {
return &s.State
}
func (s *state4) claims() (adt.Map, error) {
return adt4.AsMap(s.store, s.Claims, builtin4.DefaultHamtBitwidth)
}

View File

@ -4,6 +4,7 @@ import (
"github.com/filecoin-project/go-state-types/abi"
reward0 "github.com/filecoin-project/specs-actors/actors/builtin/reward"
"github.com/ipfs/go-cid"
"github.com/filecoin-project/lotus/chain/actors"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-state-types/cbor"
@ -38,6 +39,27 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
}
func MakeState(store adt.Store, av actors.Version, currRealizedPower abi.StoragePower) (State, error) {
switch av {
{{range .versions}}
case actors.Version{{.}}:
return make{{.}}(store, currRealizedPower)
{{end}}
}
return nil, xerrors.Errorf("unknown actor version %d", av)
}
func GetActorCodeID(av actors.Version) (cid.Cid, error) {
switch av {
{{range .versions}}
case actors.Version{{.}}:
return builtin{{.}}.RewardActorCodeID, nil
{{end}}
}
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
}
type State interface {
cbor.Marshaler
@ -55,6 +77,7 @@ type State interface {
InitialPledgeForPower(abi.StoragePower, abi.TokenAmount, *builtin.FilterEstimate, abi.TokenAmount) (abi.TokenAmount, error)
PreCommitDepositForPower(builtin.FilterEstimate, abi.StoragePower) (abi.TokenAmount, error)
GetState() interface{}
}
type AwardBlockRewardParams = reward0.AwardBlockRewardParams

View File

@ -2,6 +2,7 @@ package reward
import (
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/chain/actors"
reward0 "github.com/filecoin-project/specs-actors/actors/builtin/reward"
"github.com/ipfs/go-cid"
"golang.org/x/xerrors"
@ -64,6 +65,45 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
}
func MakeState(store adt.Store, av actors.Version, currRealizedPower abi.StoragePower) (State, error) {
switch av {
case actors.Version0:
return make0(store, currRealizedPower)
case actors.Version2:
return make2(store, currRealizedPower)
case actors.Version3:
return make3(store, currRealizedPower)
case actors.Version4:
return make4(store, currRealizedPower)
}
return nil, xerrors.Errorf("unknown actor version %d", av)
}
func GetActorCodeID(av actors.Version) (cid.Cid, error) {
switch av {
case actors.Version0:
return builtin0.RewardActorCodeID, nil
case actors.Version2:
return builtin2.RewardActorCodeID, nil
case actors.Version3:
return builtin3.RewardActorCodeID, nil
case actors.Version4:
return builtin4.RewardActorCodeID, nil
}
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
}
type State interface {
cbor.Marshaler
@ -81,6 +121,7 @@ type State interface {
InitialPledgeForPower(abi.StoragePower, abi.TokenAmount, *builtin.FilterEstimate, abi.TokenAmount) (abi.TokenAmount, error)
PreCommitDepositForPower(builtin.FilterEstimate, abi.StoragePower) (abi.TokenAmount, error)
GetState() interface{}
}
type AwardBlockRewardParams = reward0.AwardBlockRewardParams

View File

@ -23,6 +23,12 @@ func load{{.v}}(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make{{.v}}(store adt.Store, currRealizedPower abi.StoragePower) (State, error) {
out := state{{.v}}{store: store}
out.State = *reward{{.v}}.ConstructState(currRealizedPower)
return &out, nil
}
type state{{.v}} struct {
reward{{.v}}.State
store adt.Store
@ -101,3 +107,7 @@ func (s *state{{.v}}) PreCommitDepositForPower(networkQAPower builtin.FilterEsti
},
sectorWeight), nil
}
func (s *state{{.v}}) GetState() interface{} {
return &s.State
}

View File

View File

@ -23,6 +23,12 @@ func load0(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make0(store adt.Store, currRealizedPower abi.StoragePower) (State, error) {
out := state0{store: store}
out.State = *reward0.ConstructState(currRealizedPower)
return &out, nil
}
type state0 struct {
reward0.State
store adt.Store
@ -83,3 +89,7 @@ func (s *state0) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate,
},
sectorWeight), nil
}
func (s *state0) GetState() interface{} {
return &s.State
}

View File

@ -23,6 +23,12 @@ func load2(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make2(store adt.Store, currRealizedPower abi.StoragePower) (State, error) {
out := state2{store: store}
out.State = *reward2.ConstructState(currRealizedPower)
return &out, nil
}
type state2 struct {
reward2.State
store adt.Store
@ -86,3 +92,7 @@ func (s *state2) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate,
},
sectorWeight), nil
}
func (s *state2) GetState() interface{} {
return &s.State
}

View File

@ -23,6 +23,12 @@ func load3(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make3(store adt.Store, currRealizedPower abi.StoragePower) (State, error) {
out := state3{store: store}
out.State = *reward3.ConstructState(currRealizedPower)
return &out, nil
}
type state3 struct {
reward3.State
store adt.Store
@ -86,3 +92,7 @@ func (s *state3) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate,
},
sectorWeight), nil
}
func (s *state3) GetState() interface{} {
return &s.State
}

View File

@ -23,6 +23,12 @@ func load4(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make4(store adt.Store, currRealizedPower abi.StoragePower) (State, error) {
out := state4{store: store}
out.State = *reward4.ConstructState(currRealizedPower)
return &out, nil
}
type state4 struct {
reward4.State
store adt.Store
@ -86,3 +92,7 @@ func (s *state4) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate,
},
sectorWeight), nil
}
func (s *state4) GetState() interface{} {
return &s.State
}

View File

@ -0,0 +1,41 @@
package system
import (
"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/chain/actors"
"golang.org/x/xerrors"
"github.com/ipfs/go-cid"
{{range .versions}}
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
{{end}}
)
var (
Address = builtin{{.latestVersion}}.SystemActorAddr
)
func MakeState(store adt.Store, av actors.Version) (State, error) {
switch av {
{{range .versions}}
case actors.Version{{.}}:
return make{{.}}(store)
{{end}}
}
return nil, xerrors.Errorf("unknown actor version %d", av)
}
func GetActorCodeID(av actors.Version) (cid.Cid, error) {
switch av {
{{range .versions}}
case actors.Version{{.}}:
return builtin{{.}}.SystemActorCodeID, nil
{{end}}
}
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
}
type State interface {
GetState() interface{}
}

View File

@ -0,0 +1,35 @@
package system
import (
"github.com/ipfs/go-cid"
"github.com/filecoin-project/lotus/chain/actors/adt"
system{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/system"
)
var _ State = (*state{{.v}})(nil)
func load{{.v}}(store adt.Store, root cid.Cid) (State, error) {
out := state{{.v}}{store: store}
err := store.Get(store.Context(), root, &out)
if err != nil {
return nil, err
}
return &out, nil
}
func make{{.v}}(store adt.Store) (State, error) {
out := state{{.v}}{store: store}
out.State = system{{.v}}.State{}
return &out, nil
}
type state{{.v}} struct {
system{{.v}}.State
store adt.Store
}
func (s *state{{.v}}) GetState() interface{} {
return &s.State
}

View File

@ -0,0 +1,63 @@
package system
import (
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/ipfs/go-cid"
"golang.org/x/xerrors"
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
)
var (
Address = builtin4.SystemActorAddr
)
func MakeState(store adt.Store, av actors.Version) (State, error) {
switch av {
case actors.Version0:
return make0(store)
case actors.Version2:
return make2(store)
case actors.Version3:
return make3(store)
case actors.Version4:
return make4(store)
}
return nil, xerrors.Errorf("unknown actor version %d", av)
}
func GetActorCodeID(av actors.Version) (cid.Cid, error) {
switch av {
case actors.Version0:
return builtin0.SystemActorCodeID, nil
case actors.Version2:
return builtin2.SystemActorCodeID, nil
case actors.Version3:
return builtin3.SystemActorCodeID, nil
case actors.Version4:
return builtin4.SystemActorCodeID, nil
}
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
}
type State interface {
GetState() interface{}
}

View File

View File

@ -0,0 +1,35 @@
package system
import (
"github.com/ipfs/go-cid"
"github.com/filecoin-project/lotus/chain/actors/adt"
system0 "github.com/filecoin-project/specs-actors/actors/builtin/system"
)
var _ State = (*state0)(nil)
func load0(store adt.Store, root cid.Cid) (State, error) {
out := state0{store: store}
err := store.Get(store.Context(), root, &out)
if err != nil {
return nil, err
}
return &out, nil
}
func make0(store adt.Store) (State, error) {
out := state0{store: store}
out.State = system0.State{}
return &out, nil
}
type state0 struct {
system0.State
store adt.Store
}
func (s *state0) GetState() interface{} {
return &s.State
}

View File

@ -0,0 +1,35 @@
package system
import (
"github.com/ipfs/go-cid"
"github.com/filecoin-project/lotus/chain/actors/adt"
system2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/system"
)
var _ State = (*state2)(nil)
func load2(store adt.Store, root cid.Cid) (State, error) {
out := state2{store: store}
err := store.Get(store.Context(), root, &out)
if err != nil {
return nil, err
}
return &out, nil
}
func make2(store adt.Store) (State, error) {
out := state2{store: store}
out.State = system2.State{}
return &out, nil
}
type state2 struct {
system2.State
store adt.Store
}
func (s *state2) GetState() interface{} {
return &s.State
}

View File

@ -0,0 +1,35 @@
package system
import (
"github.com/ipfs/go-cid"
"github.com/filecoin-project/lotus/chain/actors/adt"
system3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/system"
)
var _ State = (*state3)(nil)
func load3(store adt.Store, root cid.Cid) (State, error) {
out := state3{store: store}
err := store.Get(store.Context(), root, &out)
if err != nil {
return nil, err
}
return &out, nil
}
func make3(store adt.Store) (State, error) {
out := state3{store: store}
out.State = system3.State{}
return &out, nil
}
type state3 struct {
system3.State
store adt.Store
}
func (s *state3) GetState() interface{} {
return &s.State
}

View File

@ -0,0 +1,35 @@
package system
import (
"github.com/ipfs/go-cid"
"github.com/filecoin-project/lotus/chain/actors/adt"
system4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/system"
)
var _ State = (*state4)(nil)
func load4(store adt.Store, root cid.Cid) (State, error) {
out := state4{store: store}
err := store.Get(store.Context(), root, &out)
if err != nil {
return nil, err
}
return &out, nil
}
func make4(store adt.Store) (State, error) {
out := state4{store: store}
out.State = system4.State{}
return &out, nil
}
type state4 struct {
system4.State
store adt.Store
}
func (s *state4) GetState() interface{} {
return &s.State
}

View File

View File

@ -14,6 +14,7 @@ import (
"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/types"
)
@ -40,6 +41,28 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
}
func MakeState(store adt.Store, av actors.Version, rootKeyAddress address.Address) (State, error) {
switch av {
{{range .versions}}
case actors.Version{{.}}:
return make{{.}}(store, rootKeyAddress)
{{end}}
}
return nil, xerrors.Errorf("unknown actor version %d", av)
}
func GetActorCodeID(av actors.Version) (cid.Cid, error) {
switch av {
{{range .versions}}
case actors.Version{{.}}:
return builtin{{.}}.VerifiedRegistryActorCodeID, nil
{{end}}
}
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
}
type State interface {
cbor.Marshaler
@ -48,4 +71,5 @@ type State interface {
VerifierDataCap(address.Address) (bool, abi.StoragePower, error)
ForEachVerifier(func(addr address.Address, dcap abi.StoragePower) error) error
ForEachClient(func(addr address.Address, dcap abi.StoragePower) error) error
GetState() interface{}
}

View File

@ -9,7 +9,7 @@ import (
"github.com/filecoin-project/lotus/chain/actors/adt"
{{if (ge .v 3)}} builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin"
{{end}} verifreg{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/verifreg"
{{end}} verifreg{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/verifreg"
adt{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/util/adt"
)
@ -24,6 +24,26 @@ func load{{.v}}(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make{{.v}}(store adt.Store, rootKeyAddress address.Address) (State, error) {
out := state{{.v}}{store: store}
{{if (le .v 2)}}
em, err := adt{{.v}}.MakeEmptyMap(store).Root()
if err != nil {
return nil, err
}
out.State = *verifreg{{.v}}.ConstructState(em, rootKeyAddress)
{{else}}
s, err := verifreg{{.v}}.ConstructState(store, rootKeyAddress)
if err != nil {
return nil, err
}
out.State = *s
{{end}}
return &out, nil
}
type state{{.v}} struct {
verifreg{{.v}}.State
store adt.Store
@ -56,3 +76,7 @@ func (s *state{{.v}}) verifiedClients() (adt.Map, error) {
func (s *state{{.v}}) verifiers() (adt.Map, error) {
return adt{{.v}}.AsMap(s.store, s.Verifiers{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}})
}
func (s *state{{.v}}) GetState() interface{} {
return &s.State
}

View File

View File

@ -23,6 +23,19 @@ func load0(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make0(store adt.Store, rootKeyAddress address.Address) (State, error) {
out := state0{store: store}
em, err := adt0.MakeEmptyMap(store).Root()
if err != nil {
return nil, err
}
out.State = *verifreg0.ConstructState(em, rootKeyAddress)
return &out, nil
}
type state0 struct {
verifreg0.State
store adt.Store
@ -55,3 +68,7 @@ func (s *state0) verifiedClients() (adt.Map, error) {
func (s *state0) verifiers() (adt.Map, error) {
return adt0.AsMap(s.store, s.Verifiers)
}
func (s *state0) GetState() interface{} {
return &s.State
}

View File

@ -23,6 +23,19 @@ func load2(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make2(store adt.Store, rootKeyAddress address.Address) (State, error) {
out := state2{store: store}
em, err := adt2.MakeEmptyMap(store).Root()
if err != nil {
return nil, err
}
out.State = *verifreg2.ConstructState(em, rootKeyAddress)
return &out, nil
}
type state2 struct {
verifreg2.State
store adt.Store
@ -55,3 +68,7 @@ func (s *state2) verifiedClients() (adt.Map, error) {
func (s *state2) verifiers() (adt.Map, error) {
return adt2.AsMap(s.store, s.Verifiers)
}
func (s *state2) GetState() interface{} {
return &s.State
}

View File

@ -24,6 +24,19 @@ func load3(store adt.Store, root cid.Cid) (State, error) {
return &out, nil
}
func make3(store adt.Store, rootKeyAddress address.Address) (State, error) {
out := state3{store: store}
s, err := verifreg3.ConstructState(store, rootKeyAddress)
if err != nil {
return nil, err
}
out.State = *s
return &out, nil
}
type state3 struct {
verifreg3.State
store adt.Store
@ -56,3 +69,7 @@ func (s *state3) verifiedClients() (adt.Map, error) {
func (s *state3) verifiers() (adt.Map, error) {
return adt3.AsMap(s.store, s.Verifiers, builtin3.DefaultHamtBitwidth)
}
func (s *state3) GetState() interface{} {
return &s.State
}

Some files were not shown because too many files have changed in this diff Show More