This commit is contained in:
Steven Allen 2020-09-14 15:43:12 -07:00
parent 02dcb5e182
commit cc4d5306eb
22 changed files with 205 additions and 150 deletions

View File

@ -21,16 +21,16 @@ type Map interface {
ForEach(v cbor.Unmarshaler, fn func(key string) error) error
}
func AsMap(store Store, root cid.Cid, version network.Version) (Map, error) {
switch builtin.VersionForNetwork(version) {
func AsMap(store Store, root cid.Cid, version builtin.Version) (Map, error) {
switch version {
case builtin.Version0:
return v0adt.AsMap(store, root)
}
return nil, xerrors.Errorf("unknown network version: %d", version)
}
func NewMap(store Store, version network.Version) (Map, error) {
switch builtin.VersionForNetwork(version) {
func NewMap(store Store, version builtin.Version) (Map, error) {
switch version {
case builtin.Version0:
return v0adt.MakeEmptyMap(store), nil
}

View File

@ -9,8 +9,11 @@ import (
"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/node/modules/dtypes"
)
var Address = v0builtin.InitActorAddr
func Load(store adt.Store, act *types.Actor) (State, error) {
switch act.Code {
case v0builtin.InitActorCodeID:
@ -29,4 +32,5 @@ type State interface {
ResolveAddress(address address.Address) (address.Address, bool, error)
MapAddressToNewID(address address.Address) (address.Address, error)
NetworkName() (dtypes.NetworkName, error)
}

View File

@ -6,6 +6,7 @@ import (
init_ "github.com/filecoin-project/specs-actors/actors/builtin/init"
"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/node/modules/dtypes"
)
type v0State struct {
@ -20,3 +21,7 @@ func (s *v0State) ResolveAddress(address address.Address) (address.Address, bool
func (s *v0State) MapAddressToNewID(address address.Address) (address.Address, error) {
return s.State.MapAddressToNewID(s.store, address)
}
func (s *v0State) NetworkName() (dtypes.NetworkName, error) {
return dtypes.NetworkName(s.State.NetworkName), nil
}

View File

@ -14,6 +14,8 @@ import (
"github.com/filecoin-project/lotus/chain/types"
)
var Address = v0builtin.InitActorAddr
func Load(store adt.Store, act *types.Actor) (st State, err error) {
switch act.Code {
case v0builtin.StorageMinerActorCodeID:

View File

@ -29,5 +29,15 @@ type State interface {
cbor.Marshaler
TotalLocked() (abi.TokenAmount, error)
MinerNominalPowerMeetsConsensusMinimum(adt.Store, address.Address) (bool, error)
TotalPower() (Claim, error)
MinerPower(address.Address) (Claim, error)
MinerNominalPowerMeetsConsensusMinimum(address.Address) (bool, error)
}
type Claim struct {
// Sum of raw byte power for a miner's sectors.
RawBytePower abi.StoragePower
// Sum of quality adjusted power for a miner's sectors.
QualityAdjPower abi.StoragePower
}

View File

@ -3,8 +3,8 @@ package power
import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/specs-actors/actors/builtin/power"
"github.com/filecoin-project/specs-actors/actors/util/adt"
)
type v0State struct {
@ -16,6 +16,28 @@ func (s *v0State) TotalLocked() (abi.TokenAmount, error) {
return s.TotalPledgeCollateral, nil
}
func (s *v0State) MinerNominalPowerMeetsConsensusMinimum(st adt.Store, a address.Address) (bool, error) {
return s.State.MinerNominalPowerMeetsConsensusMinimum(st, a)
func (s *v0State) TotalPower() (Claim, error) {
return Claim{
RawBytePower: s.TotalRawBytePower,
QualityAdjPower: s.TotalQualityAdjPower,
}, nil
}
func (s *v0State) MinerPower(addr address.Address) (Claim, error) {
claims, err := adt.AsMap(s.store, s.Claims)
if err != nil {
return Claim{}, err
}
var claim power.Claim
if _, err := claims.Get(abi.AddrKey(addr), &claim); err != nil {
return Claim{}, err
}
return Claim{
RawBytePower: claim.RawBytePower,
QualityAdjPower: claim.QualityAdjPower,
}, nil
}
func (s *v0State) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (bool, error) {
return s.State.MinerNominalPowerMeetsConsensusMinimum(s.store, a)
}

View File

@ -1,24 +0,0 @@
package actors
import (
"fmt"
"github.com/filecoin-project/go-state-types/network"
)
type Version int
const (
Version0 = iota
Version1
)
// VersionForNetwork resolves the network version into an specs-actors version.
func VersionForNetwork(v network.Version) Version {
switch v {
case network.Version0, network.Version1:
return Version0
default:
panic(fmt.Sprintf("unimplemented network version: %d", v))
}
}

View File

@ -17,13 +17,14 @@ import (
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/crypto"
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/builtin/account"
"github.com/filecoin-project/specs-actors/actors/builtin/multisig"
"github.com/filecoin-project/specs-actors/actors/builtin/verifreg"
"github.com/filecoin-project/specs-actors/actors/util/adt"
v0builtin "github.com/filecoin-project/specs-actors/actors/builtin"
v0account "github.com/filecoin-project/specs-actors/actors/builtin/account"
v0multisig "github.com/filecoin-project/specs-actors/actors/builtin/multisig"
v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg"
v0adt "github.com/filecoin-project/specs-actors/actors/util/adt"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/lotus/chain/state"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
@ -114,7 +115,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge
return nil, nil, xerrors.Errorf("putting empty object: %w", err)
}
state, err := state.NewStateTree(cst, GenesisNetworkVersion)
state, err := state.NewStateTree(cst, builtin.Version0)
if err != nil {
return nil, nil, xerrors.Errorf("making new state tree: %w", err)
}
@ -125,7 +126,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge
if err != nil {
return nil, nil, xerrors.Errorf("setup init actor: %w", err)
}
if err := state.SetActor(builtin.SystemActorAddr, sysact); err != nil {
if err := state.SetActor(v0builtin.SystemActorAddr, sysact); err != nil {
return nil, nil, xerrors.Errorf("set init actor: %w", err)
}
@ -135,7 +136,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge
if err != nil {
return nil, nil, xerrors.Errorf("setup init actor: %w", err)
}
if err := state.SetActor(builtin.InitActorAddr, initact); err != nil {
if err := state.SetActor(v0builtin.InitActorAddr, initact); err != nil {
return nil, nil, xerrors.Errorf("set init actor: %w", err)
}
@ -146,7 +147,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge
return nil, nil, xerrors.Errorf("setup init actor: %w", err)
}
err = state.SetActor(builtin.RewardActorAddr, rewact)
err = state.SetActor(v0builtin.RewardActorAddr, rewact)
if err != nil {
return nil, nil, xerrors.Errorf("set network account actor: %w", err)
}
@ -156,7 +157,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge
if err != nil {
return nil, nil, xerrors.Errorf("setup cron actor: %w", err)
}
if err := state.SetActor(builtin.CronActorAddr, cronact); err != nil {
if err := state.SetActor(v0builtin.CronActorAddr, cronact); err != nil {
return nil, nil, xerrors.Errorf("set cron actor: %w", err)
}
@ -165,7 +166,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge
if err != nil {
return nil, nil, xerrors.Errorf("setup storage market actor: %w", err)
}
if err := state.SetActor(builtin.StoragePowerActorAddr, spact); err != nil {
if err := state.SetActor(v0builtin.StoragePowerActorAddr, spact); err != nil {
return nil, nil, xerrors.Errorf("set storage market actor: %w", err)
}
@ -174,7 +175,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge
if err != nil {
return nil, nil, xerrors.Errorf("setup storage market actor: %w", err)
}
if err := state.SetActor(builtin.StorageMarketActorAddr, marketact); err != nil {
if err := state.SetActor(v0builtin.StorageMarketActorAddr, marketact); err != nil {
return nil, nil, xerrors.Errorf("set market actor: %w", err)
}
@ -183,20 +184,20 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge
if err != nil {
return nil, nil, xerrors.Errorf("setup storage market actor: %w", err)
}
if err := state.SetActor(builtin.VerifiedRegistryActorAddr, verifact); err != nil {
if err := state.SetActor(v0builtin.VerifiedRegistryActorAddr, verifact); err != nil {
return nil, nil, xerrors.Errorf("set market actor: %w", err)
}
burntRoot, err := cst.Put(ctx, &account.State{
Address: builtin.BurntFundsActorAddr,
burntRoot, err := cst.Put(ctx, &v0account.State{
Address: v0builtin.BurntFundsActorAddr,
})
if err != nil {
return nil, nil, xerrors.Errorf("failed to setup burnt funds actor state: %w", err)
}
// Setup burnt-funds
err = state.SetActor(builtin.BurntFundsActorAddr, &types.Actor{
Code: builtin.AccountActorCodeID,
err = state.SetActor(v0builtin.BurntFundsActorAddr, &types.Actor{
Code: v0builtin.AccountActorCodeID,
Balance: types.NewInt(0),
Head: burntRoot,
})
@ -261,13 +262,13 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge
return nil, nil, err
}
verifierState, err := cst.Put(ctx, &account.State{Address: verifierAd})
verifierState, err := cst.Put(ctx, &v0account.State{Address: verifierAd})
if err != nil {
return nil, nil, err
}
err = state.SetActor(verifierId, &types.Actor{
Code: builtin.AccountActorCodeID,
Code: v0builtin.AccountActorCodeID,
Balance: types.NewInt(0),
Head: verifierState,
})
@ -314,7 +315,7 @@ func createAccountActor(ctx context.Context, cst cbor.IpldStore, state *state.St
if err := json.Unmarshal(info.Meta, &ainfo); err != nil {
return xerrors.Errorf("unmarshaling account meta: %w", err)
}
st, err := cst.Put(ctx, &account.State{Address: ainfo.Owner})
st, err := cst.Put(ctx, &v0account.State{Address: ainfo.Owner})
if err != nil {
return err
}
@ -325,7 +326,7 @@ func createAccountActor(ctx context.Context, cst cbor.IpldStore, state *state.St
}
err = state.SetActor(ida, &types.Actor{
Code: builtin.AccountActorCodeID,
Code: v0builtin.AccountActorCodeID,
Balance: info.Balance,
Head: st,
})
@ -343,7 +344,7 @@ func createMultisigAccount(ctx context.Context, bs bstore.Blockstore, cst cbor.I
if err := json.Unmarshal(info.Meta, &ainfo); err != nil {
return xerrors.Errorf("unmarshaling account meta: %w", err)
}
pending, err := adt.MakeEmptyMap(adt.WrapStore(ctx, cst)).Root()
pending, err := v0adt.MakeEmptyMap(v0adt.WrapStore(ctx, cst)).Root()
if err != nil {
return xerrors.Errorf("failed to create empty map: %v", err)
}
@ -363,12 +364,12 @@ func createMultisigAccount(ctx context.Context, bs bstore.Blockstore, cst cbor.I
continue
}
st, err := cst.Put(ctx, &account.State{Address: e})
st, err := cst.Put(ctx, &v0account.State{Address: e})
if err != nil {
return err
}
err = state.SetActor(idAddress, &types.Actor{
Code: builtin.AccountActorCodeID,
Code: v0builtin.AccountActorCodeID,
Balance: types.NewInt(0),
Head: st,
})
@ -378,7 +379,7 @@ func createMultisigAccount(ctx context.Context, bs bstore.Blockstore, cst cbor.I
signers = append(signers, idAddress)
}
st, err := cst.Put(ctx, &multisig.State{
st, err := cst.Put(ctx, &v0multisig.State{
Signers: signers,
NumApprovalsThreshold: uint64(ainfo.Threshold),
StartEpoch: abi.ChainEpoch(ainfo.VestingStart),
@ -390,7 +391,7 @@ func createMultisigAccount(ctx context.Context, bs bstore.Blockstore, cst cbor.I
return err
}
err = state.SetActor(ida, &types.Actor{
Code: builtin.MultisigActorCodeID,
Code: v0builtin.MultisigActorCodeID,
Balance: info.Balance,
Head: st,
})
@ -441,7 +442,7 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, stateroot ci
return cid.Undef, err
}
_, err = doExecValue(ctx, vm, builtin.VerifiedRegistryActorAddr, verifregRoot, types.NewInt(0), builtin.MethodsVerifiedRegistry.AddVerifier, mustEnc(&verifreg.AddVerifierParams{
_, err = doExecValue(ctx, vm, v0builtin.VerifiedRegistryActorAddr, verifregRoot, types.NewInt(0), v0builtin.MethodsVerifiedRegistry.AddVerifier, mustEnc(&v0verifreg.AddVerifierParams{
Address: verifier,
Allowance: abi.NewStoragePower(int64(sum)), // eh, close enough
@ -452,7 +453,7 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, stateroot ci
}
for c, amt := range verifNeeds {
_, err := doExecValue(ctx, vm, builtin.VerifiedRegistryActorAddr, verifier, types.NewInt(0), builtin.MethodsVerifiedRegistry.AddVerifiedClient, mustEnc(&verifreg.AddVerifiedClientParams{
_, err := doExecValue(ctx, vm, v0builtin.VerifiedRegistryActorAddr, verifier, types.NewInt(0), v0builtin.MethodsVerifiedRegistry.AddVerifiedClient, mustEnc(&v0verifreg.AddVerifiedClientParams{
Address: c,
Allowance: abi.NewStoragePower(int64(amt)),
}))
@ -494,8 +495,8 @@ func MakeGenesisBlock(ctx context.Context, bs bstore.Blockstore, sys vm.SyscallB
return nil, xerrors.Errorf("setup miners failed: %w", err)
}
store := adt.WrapStore(ctx, cbor.NewCborStore(bs))
emptyroot, err := adt.MakeEmptyArray(store).Root()
store := v0adt.WrapStore(ctx, cbor.NewCborStore(bs))
emptyroot, err := v0adt.MakeEmptyArray(store).Root()
if err != nil {
return nil, xerrors.Errorf("amt build failed: %w", err)
}
@ -543,7 +544,7 @@ func MakeGenesisBlock(ctx context.Context, bs bstore.Blockstore, sys vm.SyscallB
}
b := &types.BlockHeader{
Miner: builtin.SystemActorAddr,
Miner: v0builtin.SystemActorAddr,
Ticket: genesisticket,
Parents: []cid.Cid{filecoinGenesisCid},
Height: 0,

View File

@ -12,9 +12,8 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/network"
"github.com/filecoin-project/lotus/chain/actors/builtin"
init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init"
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/chain/types"
@ -24,8 +23,10 @@ var log = logging.Logger("statetree")
// StateTree stores actors state by their ID.
type StateTree struct {
root adt.Map
Store cbor.IpldStore
root adt.Map
version builtin.Version // TODO
info cid.Cid
Store cbor.IpldStore
snaps *stateSnaps
}
@ -117,31 +118,57 @@ func (ss *stateSnaps) deleteActor(addr address.Address) {
ss.layers[len(ss.layers)-1].actors[addr] = streeOp{Delete: true}
}
func NewStateTree(cst cbor.IpldStore, version network.Version) (*StateTree, error) {
func NewStateTree(cst cbor.IpldStore, version builtin.Version) (*StateTree, error) {
var info cid.Cid
switch version {
case builtin.Version0:
// info is undefined
default:
return nil, xerrors.Errorf("unsupported state tree version: %d", version)
}
root, err := adt.NewMap(adt.WrapStore(context.TODO(), cst), version)
if err != nil {
return nil, err
}
return &StateTree{
root: root,
Store: cst,
snaps: newStateSnaps(),
root: root,
info: info,
version: version,
Store: cst,
snaps: newStateSnaps(),
}, nil
}
func LoadStateTree(cst cbor.IpldStore, c cid.Cid, version network.Version) (*StateTree, error) {
// NETUPGRADE: switch map adt type on version upgrade.
nd, err := adt.AsMap(adt.WrapStore(context.TODO(), cst), c, version)
func LoadStateTree(cst cbor.IpldStore, c cid.Cid) (*StateTree, error) {
var root types.StateRoot
// Try loading as a new-style state-tree (version/actors tuple).
if err := cst.Get(context.TODO(), c, &root); err != nil {
// We failed to decode as the new version, must be an old version.
root.Actors = c
root.Version = builtin.Version0
}
// If that fails, load as an old-style state-tree (direct hampt, version 0.
nd, err := adt.AsMap(adt.WrapStore(context.TODO(), cst), root.Actors, builtin.Version(root.Version))
if err != nil {
log.Errorf("loading hamt node %s failed: %s", c, err)
return nil, err
}
switch root.Version {
case builtin.Version0:
// supported
default:
return nil, xerrors.Errorf("unsupported state tree version: %d", root.Version)
}
return &StateTree{
root: nd,
Store: cst,
snaps: newStateSnaps(),
root: nd,
info: root.Info,
version: builtin.Version(root.Version),
Store: cst,
snaps: newStateSnaps(),
}, nil
}
@ -167,7 +194,7 @@ func (st *StateTree) LookupID(addr address.Address) (address.Address, error) {
return resa, nil
}
act, err := st.GetActor(builtin.InitActorAddr)
act, err := st.GetActor(init_.Address)
if err != nil {
return address.Undef, xerrors.Errorf("getting init actor: %w", err)
}
@ -271,7 +298,16 @@ func (st *StateTree) Flush(ctx context.Context) (cid.Cid, error) {
}
}
return st.root.Root()
root, err := st.root.Root()
if err != nil {
return cid.Undef, xerrors.Errorf("failed to flush state-tree hamt: %w", err)
}
// If we're version 0, return a raw tree.
if st.version == builtin.Version0 {
return root, nil
}
// Otherwise, return a versioned tree.
return st.Store.Put(ctx, &types.StateRoot{Version: uint64(st.version), Actors: root, Info: st.info})
}
func (st *StateTree) Snapshot(ctx context.Context) error {
@ -289,7 +325,7 @@ func (st *StateTree) ClearSnapshot() {
func (st *StateTree) RegisterNewAddress(addr address.Address) (address.Address, error) {
var out address.Address
err := st.MutateActor(builtin.InitActorAddr, func(initact *types.Actor) error {
err := st.MutateActor(init_.Address, func(initact *types.Actor) error {
ias, err := init_.Load(&AdtStore{st.Store}, initact)
if err != nil {
return err

View File

@ -8,7 +8,6 @@ import (
cbor "github.com/ipfs/go-ipld-cbor"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/network"
"github.com/filecoin-project/lotus/chain/state"
"github.com/filecoin-project/lotus/chain/types"
)
@ -23,8 +22,7 @@ func (sm *StateManager) ParentStateTsk(tsk types.TipSetKey) (*state.StateTree, e
func (sm *StateManager) ParentState(ts *types.TipSet) (*state.StateTree, error) {
cst := cbor.NewCborStore(sm.cs.Blockstore())
version := sm.GetNtwkVersion(context.TODO(), ts.Height()-1)
state, err := state.LoadStateTree(cst, sm.parentState(ts), version)
state, err := state.LoadStateTree(cst, sm.parentState(ts))
if err != nil {
return nil, xerrors.Errorf("load state tree: %w", err)
}
@ -32,9 +30,9 @@ func (sm *StateManager) ParentState(ts *types.TipSet) (*state.StateTree, error)
return state, nil
}
func (sm *StateManager) StateTree(st cid.Cid, ntwkVersion network.Version) (*state.StateTree, error) {
func (sm *StateManager) StateTree(st cid.Cid) (*state.StateTree, error) {
cst := cbor.NewCborStore(sm.cs.Blockstore())
state, err := state.LoadStateTree(cst, st, ntwkVersion)
state, err := state.LoadStateTree(cst, st)
if err != nil {
return nil, xerrors.Errorf("load state tree: %w", err)
}
@ -57,3 +55,11 @@ func (sm *StateManager) LoadActorTsk(_ context.Context, addr address.Address, ts
}
return state.GetActor(addr)
}
func (sm *StateManager) LoadActorRaw(_ context.Context, addr address.Address, st cid.Cid) (*types.Actor, error) {
state, err := sm.StateTree(st)
if err != nil {
return nil, err
}
return state.GetActor(addr)
}

View File

@ -383,7 +383,7 @@ func (sm *StateManager) ResolveToKeyAddress(ctx context.Context, addr address.Ad
}
cst := cbor.NewCborStore(sm.cs.Blockstore())
tree, err := state.LoadStateTree(cst, st, sm.GetNtwkVersion(ctx, ts.Height()))
tree, err := state.LoadStateTree(cst, st)
if err != nil {
return address.Undef, xerrors.Errorf("failed to load state tree")
}
@ -406,7 +406,7 @@ func (sm *StateManager) GetBlsPublicKey(ctx context.Context, addr address.Addres
func (sm *StateManager) LookupID(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) {
cst := cbor.NewCborStore(sm.cs.Blockstore())
state, err := state.LoadStateTree(cst, sm.parentState(ts), sm.GetNtwkVersion(ctx, ts.Height()))
state, err := state.LoadStateTree(cst, sm.parentState(ts))
if err != nil {
return address.Undef, xerrors.Errorf("load state tree: %w", err)
}
@ -817,7 +817,7 @@ func (sm *StateManager) setupGenesisActors(ctx context.Context) error {
}
cst := cbor.NewCborStore(sm.cs.Blockstore())
sTree, err := state.LoadStateTree(cst, st, sm.GetNtwkVersion(ctx, gts.Height()))
sTree, err := state.LoadStateTree(cst, st)
if err != nil {
return xerrors.Errorf("loading state tree: %w", err)
}
@ -923,7 +923,7 @@ func (sm *StateManager) setupGenesisActorsTestnet(ctx context.Context) error {
}
cst := cbor.NewCborStore(sm.cs.Blockstore())
sTree, err := state.LoadStateTree(cst, st, sm.GetNtwkVersion(ctx, gts.Height()))
sTree, err := state.LoadStateTree(cst, st)
if err != nil {
return xerrors.Errorf("loading state tree: %w", err)
}

View File

@ -21,23 +21,22 @@ import (
"github.com/filecoin-project/go-bitfield"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/crypto"
power2 "github.com/filecoin-project/lotus/chain/actors/builtin/power"
"github.com/filecoin-project/lotus/chain/actors/builtin/power"
"github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper"
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/builtin/account"
"github.com/filecoin-project/specs-actors/actors/builtin/cron"
init_ "github.com/filecoin-project/specs-actors/actors/builtin/init"
"github.com/filecoin-project/specs-actors/actors/builtin/market"
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
"github.com/filecoin-project/specs-actors/actors/builtin/multisig"
"github.com/filecoin-project/specs-actors/actors/builtin/paych"
"github.com/filecoin-project/specs-actors/actors/builtin/power"
"github.com/filecoin-project/specs-actors/actors/builtin/reward"
"github.com/filecoin-project/specs-actors/actors/builtin/verifreg"
"github.com/filecoin-project/specs-actors/actors/util/adt"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init"
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
"github.com/filecoin-project/lotus/chain/beacon"
"github.com/filecoin-project/lotus/chain/state"
"github.com/filecoin-project/lotus/chain/store"
@ -48,8 +47,11 @@ import (
)
func GetNetworkName(ctx context.Context, sm *StateManager, st cid.Cid) (dtypes.NetworkName, error) {
var state init_.State
err := sm.WithStateTree(st, sm.WithActor(builtin.InitActorAddr, sm.WithActorState(ctx, &state)))
act, err := sm.LoadActorRaw(ctx, init_.Address, st)
if err != nil {
return "", err
}
ias, err := init_.Load(sm.cs.Store(ctx), act)
if err != nil {
return "", err
}
@ -58,21 +60,18 @@ func GetNetworkName(ctx context.Context, sm *StateManager, st cid.Cid) (dtypes.N
}
func GetMinerWorkerRaw(ctx context.Context, sm *StateManager, st cid.Cid, maddr address.Address) (address.Address, error) {
var mas miner.State
_, err := sm.LoadActorStateRaw(ctx, maddr, &mas, st)
act, err := sm.LoadActorRaw(ctx, sm, maddr, st)
if err != nil {
return address.Undef, xerrors.Errorf("(get sset) failed to load miner actor state: %w", err)
}
cst := cbor.NewCborStore(sm.cs.Blockstore())
state, err := state.LoadStateTree(cst, st)
mas, err := miner.Load(sm.cs.Store(ctx), act)
if err != nil {
return address.Undef, xerrors.Errorf("load state tree: %w", err)
}
info, err := mas.GetInfo(sm.cs.Store(ctx))
info, err := mas.Info()
if err != nil {
return address.Address{}, err
return address.Undef, xerrors.Errorf("failed to load actor info: %w", err)
}
return vm.ResolveToKeyAddr(state, cst, info.Worker)
@ -83,36 +82,35 @@ func GetPower(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr add
}
func GetPowerRaw(ctx context.Context, sm *StateManager, st cid.Cid, maddr address.Address) (power.Claim, power.Claim, error) {
var ps power.State
_, err := sm.LoadActorStateRaw(ctx, builtin.StoragePowerActorAddr, &ps, st)
act, err := sm.LoadActorRaw(ctx, builtin.StoragePowerActorAddr, st)
if err != nil {
return power.Claim{}, power.Claim{}, xerrors.Errorf("(get sset) failed to load power actor state: %w", err)
}
mas, err := power.Load(sm.cs.Store(ctx), act)
if err != nil {
return power.Claim{}, power.Claim{}, err
}
tpow, err := mas.TotalPower()
if err != nil {
return power.Claim{}, power.Claim{}, err
}
var mpow power.Claim
if maddr != address.Undef {
cm, err := adt.AsMap(sm.cs.Store(ctx), ps.Claims)
mpow, err = mas.MinerPower(maddr)
if err != nil {
return power.Claim{}, power.Claim{}, err
}
var claim power.Claim
if _, err := cm.Get(abi.AddrKey(maddr), &claim); err != nil {
return power.Claim{}, power.Claim{}, err
}
mpow = claim
}
return mpow, power.Claim{
RawBytePower: ps.TotalRawBytePower,
QualityAdjPower: ps.TotalQualityAdjPower,
}, nil
return mpow, tpow, nil
}
func PreCommitInfo(ctx context.Context, sm *StateManager, maddr address.Address, sid abi.SectorNumber, ts *types.TipSet) (miner.SectorPreCommitOnChainInfo, error) {
var mas miner.State
_, err := sm.LoadActorState(ctx, maddr, &mas, ts)
act, err := sm.LoadActor(ctx, maddr, ts)
if err != nil {
return miner.SectorPreCommitOnChainInfo{}, xerrors.Errorf("(get sset) failed to load miner actor state: %w", err)
}
@ -676,16 +674,16 @@ func MinerHasMinPower(ctx context.Context, sm *StateManager, addr address.Addres
return false, xerrors.Errorf("loading power actor state: %w", err)
}
ps, err := power2.Load(sm.cs.Store(ctx), pact)
ps, err := power.Load(sm.cs.Store(ctx), pact)
if err != nil {
return false, err
}
return ps.MinerNominalPowerMeetsConsensusMinimum(sm.ChainStore().Store(ctx), addr)
return ps.MinerNominalPowerMeetsConsensusMinimum(addr)
}
func CheckTotalFIL(ctx context.Context, sm *StateManager, ts *types.TipSet) (abi.TokenAmount, error) {
str, err := state.LoadStateTree(sm.ChainStore().Store(ctx), ts.ParentState(), sm.GetNtwkVersion(ctx, ts.Height()))
str, err := state.LoadStateTree(sm.ChainStore().Store(ctx), ts.ParentState())
if err != nil {
return abi.TokenAmount{}, err
}

View File

@ -5,8 +5,6 @@ import (
"context"
"encoding/binary"
"encoding/json"
"github.com/filecoin-project/go-state-types/network"
"github.com/filecoin-project/lotus/build"
"io"
"os"
"strconv"
@ -766,29 +764,12 @@ type BlockMessages struct {
WinCount int64
}
// TODO: temp hack until #3682 is merged
func hackgetNtwkVersionhack(ctx context.Context, height abi.ChainEpoch) network.Version {
// TODO: move hard fork epoch checks to a schedule defined in build/
if build.UpgradeBreezeHeight == 0 {
return network.Version1
}
if height <= build.UpgradeBreezeHeight {
return network.Version0
}
return network.Version1
}
func (cs *ChainStore) BlockMsgsForTipset(ts *types.TipSet) ([]BlockMessages, error) {
applied := make(map[address.Address]uint64)
cst := cbor.NewCborStore(cs.bs)
nv := hackgetNtwkVersionhack(context.TODO(), ts.Height()) // TODO: part of the temp hack from above
st, err := state.LoadStateTree(cst, ts.Blocks()[0].ParentStateRoot, nv)
st, err := state.LoadStateTree(cst, ts.Blocks()[0].ParentStateRoot)
if err != nil {
return nil, xerrors.Errorf("failed to load state tree")
}

View File

@ -29,7 +29,7 @@ func (cs *ChainStore) Weight(ctx context.Context, ts *types.TipSet) (types.BigIn
tpow := big2.Zero()
{
cst := cbor.NewCborStore(cs.Blockstore())
state, err := state.LoadStateTree(cst, ts.ParentState(), hackgetNtwkVersionhack(nil, ts.Height())) // TODO: hackgetNtwkVersionhack: HELP
state, err := state.LoadStateTree(cst, ts.ParentState())
if err != nil {
return types.NewInt(0), xerrors.Errorf("load state tree: %w", err)
}

View File

@ -435,7 +435,7 @@ func (bv *BlockValidator) checkPowerAndGetWorkerKey(ctx context.Context, bh *typ
buf := bufbstore.NewBufferedBstore(bv.chain.Blockstore())
cst := cbor.NewCborStore(buf)
state, err := state.LoadStateTree(cst, st, bv.stmgr.GetNtwkVersion(ctx, ts.Height()))
state, err := state.LoadStateTree(cst, st)
if err != nil {
return address.Undef, err
}

View File

@ -1045,10 +1045,9 @@ func (syncer *Syncer) checkBlockMessages(ctx context.Context, b *types.FullBlock
if err != nil {
return err
}
nwVersion := syncer.sm.GetNtwkVersion(ctx, baseTs.Height())
cst := cbor.NewCborStore(syncer.store.Blockstore())
st, err := state.LoadStateTree(cst, stateroot, nwVersion)
st, err := state.LoadStateTree(cst, stateroot)
if err != nil {
return xerrors.Errorf("failed to load base state tree: %w", err)
}

15
chain/types/state.go Normal file
View File

@ -0,0 +1,15 @@
package types
import "github.com/ipfs/go-cid"
type StateRoot struct {
// State root version. Versioned along with actors (for now).
Version uint64
// Actors tree. The structure depends on the state root version.
Actors cid.Cid
// Info. The structure depends on the state root version.
Info cid.Cid
}
// TODO: version this.
type StateInfo struct{}

View File

@ -170,8 +170,7 @@ type VMOpts struct {
func NewVM(ctx context.Context, opts *VMOpts) (*VM, error) {
buf := bufbstore.NewBufferedBstore(opts.Bstore)
cst := cbor.NewCborStore(buf)
nwv := opts.NtwkVersion(ctx, opts.Epoch) // TODO: why do we need a context for this?
state, err := state.LoadStateTree(cst, opts.StateBase, nwv)
state, err := state.LoadStateTree(cst, opts.StateBase)
if err != nil {
return nil, err
}

View File

@ -171,9 +171,8 @@ var chainBalanceStateCmd = &cli.Command{
sm := stmgr.NewStateManager(cs)
// NETUPGRADE: FIXME.
// Options: (a) encode the version in the chain or (b) pass a flag.
tree, err := state.LoadStateTree(cst, sroot, network.Version0)
tree, err := state.LoadStateTree(cst, sroot)
if err != nil {
return err
}

View File

@ -79,7 +79,7 @@ var genesisVerifyCmd = &cli.Command{
cst := cbor.NewCborStore(bs)
stree, err := state.LoadStateTree(cst, ts.ParentState(), sm.GetNtwkVersion())
stree, err := state.LoadStateTree(cst, ts.ParentState())
if err != nil {
return err
}

View File

@ -26,6 +26,8 @@ func main() {
types.BlockMsg{},
types.ExpTipSet{},
types.BeaconEntry{},
types.StateRoot{},
types.StateInfo{},
)
if err != nil {
fmt.Println(err)

View File

@ -317,7 +317,7 @@ func (a *StateAPI) stateForTs(ctx context.Context, ts *types.TipSet) (*state.Sta
buf := bufbstore.NewBufferedBstore(a.Chain.Blockstore())
cst := cbor.NewCborStore(buf)
return state.LoadStateTree(cst, st, a.StateManager.GetNtwkVersion(ctx, ts.Height()))
return state.LoadStateTree(cst, st)
}
func (a *StateAPI) StateGetActor(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*types.Actor, error) {