From 59aa115e7e165ce8f599ac249edb0f2c464e5a4c Mon Sep 17 00:00:00 2001 From: "terry.hung" Date: Thu, 27 Jun 2024 16:03:57 +0800 Subject: [PATCH] chore: update the actor versions (#1305) * chore: update the actor versions * update the miner state mocks --- chain/actors/builtin/datacap/datacap.go | 14 +- chain/actors/builtin/datacap/v14.go | 94 +++ chain/actors/builtin/init/init.go | 14 +- chain/actors/builtin/init/v14.go | 152 +++++ chain/actors/builtin/market/market.go | 5 + chain/actors/builtin/market/v14.go | 375 +++++++++++ chain/actors/builtin/miner/miner.go | 12 +- chain/actors/builtin/miner/mocks/state.go | 26 +- chain/actors/builtin/miner/v14.go | 624 ++++++++++++++++++ chain/actors/builtin/multisig/multisig.go | 21 +- chain/actors/builtin/multisig/v14.go | 131 ++++ chain/actors/builtin/power/power.go | 11 +- chain/actors/builtin/power/v14.go | 187 ++++++ chain/actors/builtin/reward/reward.go | 11 +- chain/actors/builtin/reward/v14.go | 111 ++++ chain/actors/builtin/verifreg/v14.go | 222 +++++++ chain/actors/builtin/verifreg/verifreg.go | 11 +- chain/indexer/integrated/processor/state.go | 3 + .../processor/state_internal_test.go | 3 + .../integrated/processor/state_test.go | 3 + 20 files changed, 1992 insertions(+), 38 deletions(-) create mode 100644 chain/actors/builtin/datacap/v14.go create mode 100644 chain/actors/builtin/init/v14.go create mode 100644 chain/actors/builtin/market/v14.go create mode 100644 chain/actors/builtin/miner/v14.go create mode 100644 chain/actors/builtin/multisig/v14.go create mode 100644 chain/actors/builtin/power/v14.go create mode 100644 chain/actors/builtin/reward/v14.go create mode 100644 chain/actors/builtin/verifreg/v14.go diff --git a/chain/actors/builtin/datacap/datacap.go b/chain/actors/builtin/datacap/datacap.go index e59d08f09..7fbd422ba 100644 --- a/chain/actors/builtin/datacap/datacap.go +++ b/chain/actors/builtin/datacap/datacap.go @@ -7,7 +7,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" actorstypes "github.com/filecoin-project/go-state-types/actors" - builtin13 "github.com/filecoin-project/go-state-types/builtin" + builtin14 "github.com/filecoin-project/go-state-types/builtin" "github.com/filecoin-project/go-state-types/cbor" "github.com/filecoin-project/go-state-types/manifest" @@ -17,8 +17,8 @@ import ( ) var ( - Address = builtin13.DatacapActorAddr - Methods = builtin13.MethodsDatacap + Address = builtin14.DatacapActorAddr + Methods = builtin14.MethodsDatacap ) func Load(store adt.Store, act *types.Actor) (State, error) { @@ -44,6 +44,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) { case actorstypes.Version13: return load13(store, act.Head) + case actorstypes.Version14: + return load14(store, act.Head) + } } @@ -68,6 +71,9 @@ func MakeState(store adt.Store, av actorstypes.Version, governor address.Address case actorstypes.Version13: return make13(store, governor, bitwidth) + case actorstypes.Version14: + return make14(store, governor, bitwidth) + default: return nil, xerrors.Errorf("datacap actor only valid for actors v9 and above, got %d", av) } @@ -97,6 +103,7 @@ func AllCodes() []cid.Cid { (&state11{}).Code(), (&state12{}).Code(), (&state13{}).Code(), + (&state14{}).Code(), } } @@ -107,5 +114,6 @@ func VersionCodes() map[actorstypes.Version]cid.Cid { actorstypes.Version11: (&state11{}).Code(), actorstypes.Version12: (&state12{}).Code(), actorstypes.Version13: (&state13{}).Code(), + actorstypes.Version14: (&state14{}).Code(), } } diff --git a/chain/actors/builtin/datacap/v14.go b/chain/actors/builtin/datacap/v14.go new file mode 100644 index 000000000..0529204c1 --- /dev/null +++ b/chain/actors/builtin/datacap/v14.go @@ -0,0 +1,94 @@ +package datacap + +import ( + "crypto/sha256" + "fmt" + + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + actorstypes "github.com/filecoin-project/go-state-types/actors" + datacap14 "github.com/filecoin-project/go-state-types/builtin/v14/datacap" + adt14 "github.com/filecoin-project/go-state-types/builtin/v14/util/adt" + "github.com/filecoin-project/go-state-types/manifest" + + "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/adt" +) + +var _ State = (*state14)(nil) + +func load14(store adt.Store, root cid.Cid) (State, error) { + out := state14{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make14(store adt.Store, governor address.Address, bitwidth uint64) (State, error) { + out := state14{store: store} + s, err := datacap14.ConstructState(store, governor, bitwidth) + if err != nil { + return nil, err + } + + out.State = *s + + return &out, nil +} + +type state14 struct { + datacap14.State + store adt.Store +} + +func (s *state14) Governor() (address.Address, error) { + return s.State.Governor, nil +} + +func (s *state14) GetState() interface{} { + return &s.State +} + +func (s *state14) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error { + return forEachClient(s.store, actorstypes.Version14, s.VerifiedClients, cb) +} + +func (s *state14) VerifiedClients() (adt.Map, error) { + return adt14.AsMap(s.store, s.Token.Balances, int(s.Token.HamtBitWidth)) +} + +func (s *state14) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) { + return getDataCap(s.store, actorstypes.Version14, s.VerifiedClients, addr) +} + +func (s *state14) VerifiedClientsMapBitWidth() int { + return int(s.Token.HamtBitWidth) +} + +func (s *state14) VerifiedClientsMapHashFunction() func(input []byte) []byte { + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } +} + +func (s *state14) ActorKey() string { + return manifest.DatacapKey +} + +func (s *state14) ActorVersion() actorstypes.Version { + return actorstypes.Version14 +} + +func (s *state14) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/init/init.go b/chain/actors/builtin/init/init.go index 3038a37ac..cc2f4318a 100644 --- a/chain/actors/builtin/init/init.go +++ b/chain/actors/builtin/init/init.go @@ -9,7 +9,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" actorstypes "github.com/filecoin-project/go-state-types/actors" - builtin13 "github.com/filecoin-project/go-state-types/builtin" + builtin14 "github.com/filecoin-project/go-state-types/builtin" "github.com/filecoin-project/go-state-types/cbor" "github.com/filecoin-project/go-state-types/manifest" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" @@ -27,8 +27,8 @@ import ( ) var ( - Address = builtin13.InitActorAddr - Methods = builtin13.MethodsInit + Address = builtin14.InitActorAddr + Methods = builtin14.MethodsInit ) func Load(store adt.Store, act *types.Actor) (State, error) { @@ -57,6 +57,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) { case actorstypes.Version13: return load13(store, act.Head) + case actorstypes.Version14: + return load14(store, act.Head) + } } @@ -130,6 +133,9 @@ func MakeState(store adt.Store, av actorstypes.Version, networkName string) (Sta case actorstypes.Version13: return make13(store, networkName) + case actorstypes.Version14: + return make14(store, networkName) + } return nil, fmt.Errorf("unknown actor version %d", av) } @@ -183,6 +189,7 @@ func AllCodes() []cid.Cid { (&state11{}).Code(), (&state12{}).Code(), (&state13{}).Code(), + (&state14{}).Code(), } } @@ -201,5 +208,6 @@ func VersionCodes() map[actorstypes.Version]cid.Cid { actorstypes.Version11: (&state11{}).Code(), actorstypes.Version12: (&state12{}).Code(), actorstypes.Version13: (&state13{}).Code(), + actorstypes.Version14: (&state14{}).Code(), } } diff --git a/chain/actors/builtin/init/v14.go b/chain/actors/builtin/init/v14.go new file mode 100644 index 000000000..7a7b87ad0 --- /dev/null +++ b/chain/actors/builtin/init/v14.go @@ -0,0 +1,152 @@ +// Code generated by: `make actors-gen`. DO NOT EDIT. + +package init + +import ( + "crypto/sha256" + "fmt" + + "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + actorstypes "github.com/filecoin-project/go-state-types/actors" + builtin14 "github.com/filecoin-project/go-state-types/builtin" + init14 "github.com/filecoin-project/go-state-types/builtin/v14/init" + adt14 "github.com/filecoin-project/go-state-types/builtin/v14/util/adt" + "github.com/filecoin-project/go-state-types/manifest" + + lotusactors "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/node/modules/dtypes" +) + +var _ State = (*state14)(nil) + +func load14(store adt.Store, root cid.Cid) (State, error) { + out := state14{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make14(store adt.Store, networkName string) (State, error) { + out := state14{store: store} + + s, err := init14.ConstructState(store, networkName) + if err != nil { + return nil, err + } + + out.State = *s + + return &out, nil +} + +type state14 struct { + init14.State + store adt.Store +} + +func (s *state14) ResolveAddress(address address.Address) (address.Address, bool, error) { + return s.State.ResolveAddress(s.store, address) +} + +func (s *state14) MapAddressToNewID(address address.Address) (address.Address, error) { + return s.State.MapAddressToNewID(s.store, address) +} + +func (s *state14) ForEachActor(cb func(id abi.ActorID, address address.Address) error) error { + addrs, err := adt14.AsMap(s.store, s.State.AddressMap, builtin14.DefaultHamtBitwidth) + if err != nil { + return err + } + var actorID cbg.CborInt + return addrs.ForEach(&actorID, func(key string) error { + addr, err := address.NewFromBytes([]byte(key)) + if err != nil { + return err + } + return cb(abi.ActorID(actorID), addr) + }) +} + +func (s *state14) NetworkName() (dtypes.NetworkName, error) { + return dtypes.NetworkName(s.State.NetworkName), nil +} + +func (s *state14) SetNetworkName(name string) error { + s.State.NetworkName = name + return nil +} + +func (s *state14) SetNextID(id abi.ActorID) error { + s.State.NextID = id + return nil +} + +func (s *state14) Remove(addrs ...address.Address) (err error) { + m, err := adt14.AsMap(s.store, s.State.AddressMap, builtin14.DefaultHamtBitwidth) + if err != nil { + return err + } + for _, addr := range addrs { + if err = m.Delete(abi.AddrKey(addr)); err != nil { + return fmt.Errorf("failed to delete entry for address: %s; err: %w", addr, err) + } + } + amr, err := m.Root() + if err != nil { + return fmt.Errorf("failed to get address map root: %w", err) + } + s.State.AddressMap = amr + return nil +} + +func (s *state14) SetAddressMap(mcid cid.Cid) error { + s.State.AddressMap = mcid + return nil +} + +func (s *state14) AddressMap() (adt.Map, error) { + return adt14.AsMap(s.store, s.State.AddressMap, builtin14.DefaultHamtBitwidth) +} + +func (s *state14) AddressMapBitWidth() int { + + return builtin14.DefaultHamtBitwidth + +} + +func (s *state14) AddressMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state14) GetState() interface{} { + return &s.State +} + +func (s *state14) ActorKey() string { + return manifest.InitKey +} + +func (s *state14) ActorVersion() actorstypes.Version { + return actorstypes.Version14 +} + +func (s *state14) Code() cid.Cid { + code, ok := lotusactors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/market/market.go b/chain/actors/builtin/market/market.go index 546d039bf..2b8d8459f 100644 --- a/chain/actors/builtin/market/market.go +++ b/chain/actors/builtin/market/market.go @@ -60,6 +60,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) { case actorstypes.Version13: return load13(store, act.Head) + case actorstypes.Version14: + return load14(store, act.Head) + } } @@ -233,6 +236,7 @@ func AllCodes() []cid.Cid { (&state11{}).Code(), (&state12{}).Code(), (&state13{}).Code(), + (&state14{}).Code(), } } @@ -251,5 +255,6 @@ func VersionCodes() map[actorstypes.Version]cid.Cid { actorstypes.Version11: (&state11{}).Code(), actorstypes.Version12: (&state12{}).Code(), actorstypes.Version13: (&state13{}).Code(), + actorstypes.Version14: (&state14{}).Code(), } } diff --git a/chain/actors/builtin/market/v14.go b/chain/actors/builtin/market/v14.go new file mode 100644 index 000000000..ba2bb6c42 --- /dev/null +++ b/chain/actors/builtin/market/v14.go @@ -0,0 +1,375 @@ +// Code generated by: `make actors-gen`. DO NOT EDIT. + +package market + +import ( + "bytes" + "fmt" + + "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" + + "github.com/filecoin-project/go-state-types/abi" + actorstypes "github.com/filecoin-project/go-state-types/actors" + market14 "github.com/filecoin-project/go-state-types/builtin/v14/market" + adt14 "github.com/filecoin-project/go-state-types/builtin/v14/util/adt" + markettypes "github.com/filecoin-project/go-state-types/builtin/v9/market" + "github.com/filecoin-project/go-state-types/manifest" + + lotusactors "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/adt" +) + +var _ State = (*state14)(nil) + +func load14(store adt.Store, root cid.Cid) (State, error) { + out := state14{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make14(store adt.Store) (State, error) { + out := state14{store: store} + + s, err := market14.ConstructState(store) + if err != nil { + return nil, err + } + + out.State = *s + + return &out, nil +} + +type state14 struct { + market14.State + store adt.Store +} + +func (s *state14) StatesChanged(otherState State) (bool, error) { + otherState14, ok := otherState.(*state14) + if !ok { + // there's no way to compare different versions of the state, so let's + // just say that means the state of balances has changed + return true, nil + } + return !s.State.States.Equals(otherState14.State.States), nil +} + +func (s *state14) States() (DealStates, error) { + stateArray, err := adt14.AsArray(s.store, s.State.States, market14.StatesAmtBitwidth) + if err != nil { + return nil, err + } + return &dealStates14{stateArray}, nil +} + +func (s *state14) ProposalsChanged(otherState State) (bool, error) { + otherState14, ok := otherState.(*state14) + if !ok { + // there's no way to compare different versions of the state, so let's + // just say that means the state of balances has changed + return true, nil + } + return !s.State.Proposals.Equals(otherState14.State.Proposals), nil +} + +func (s *state14) Proposals() (DealProposals, error) { + proposalArray, err := adt14.AsArray(s.store, s.State.Proposals, market14.ProposalsAmtBitwidth) + if err != nil { + return nil, err + } + return &dealProposals14{proposalArray}, nil +} + +type dealStates14 struct { + adt.Array +} + +func (s *dealStates14) Get(dealID abi.DealID) (DealState, bool, error) { + var deal14 market14.DealState + found, err := s.Array.Get(uint64(dealID), &deal14) + if err != nil { + return nil, false, err + } + if !found { + return nil, false, nil + } + deal := fromV14DealState(deal14) + return deal, true, nil +} + +func (s *dealStates14) ForEach(cb func(dealID abi.DealID, ds DealState) error) error { + var ds14 market14.DealState + return s.Array.ForEach(&ds14, func(idx int64) error { + return cb(abi.DealID(idx), fromV14DealState(ds14)) + }) +} + +func (s *dealStates14) decode(val *cbg.Deferred) (DealState, error) { + var ds14 market14.DealState + if err := ds14.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { + return nil, err + } + ds := fromV14DealState(ds14) + return ds, nil +} + +func (s *dealStates14) array() adt.Array { + return s.Array +} + +func fromV14DealState(v14 market14.DealState) DealState { + return dealStateV14{v14} +} + +type dealStateV14 struct { + ds14 market14.DealState +} + +func (d dealStateV14) SectorStartEpoch() abi.ChainEpoch { + return d.ds14.SectorStartEpoch +} + +func (d dealStateV14) SectorNumber() abi.SectorNumber { + + return d.ds14.SectorNumber + +} + +func (d dealStateV14) LastUpdatedEpoch() abi.ChainEpoch { + return d.ds14.LastUpdatedEpoch +} + +func (d dealStateV14) SlashEpoch() abi.ChainEpoch { + return d.ds14.SlashEpoch +} + +func (d dealStateV14) Equals(other DealState) bool { + if ov14, ok := other.(dealStateV14); ok { + return d.ds14 == ov14.ds14 + } + + if d.SectorStartEpoch() != other.SectorStartEpoch() { + return false + } + if d.LastUpdatedEpoch() != other.LastUpdatedEpoch() { + return false + } + if d.SlashEpoch() != other.SlashEpoch() { + return false + } + + return true +} + +var _ DealState = (*dealStateV14)(nil) + +type dealProposals14 struct { + adt.Array +} + +func (s *dealProposals14) Get(dealID abi.DealID) (*DealProposal, bool, error) { + var proposal14 market14.DealProposal + found, err := s.Array.Get(uint64(dealID), &proposal14) + if err != nil { + return nil, false, err + } + if !found { + return nil, false, nil + } + + proposal, err := fromV14DealProposal(proposal14) + if err != nil { + return nil, true, xerrors.Errorf("decoding proposal: %w", err) + } + + return &proposal, true, nil +} + +func (s *dealProposals14) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error { + var dp14 market14.DealProposal + return s.Array.ForEach(&dp14, func(idx int64) error { + dp, err := fromV14DealProposal(dp14) + if err != nil { + return xerrors.Errorf("decoding proposal: %w", err) + } + + return cb(abi.DealID(idx), dp) + }) +} + +func (s *dealProposals14) decode(val *cbg.Deferred) (*DealProposal, error) { + var dp14 market14.DealProposal + if err := dp14.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { + return nil, err + } + + dp, err := fromV14DealProposal(dp14) + if err != nil { + return nil, err + } + + return &dp, nil +} + +func (s *dealProposals14) array() adt.Array { + return s.Array +} + +func fromV14DealProposal(v14 market14.DealProposal) (DealProposal, error) { + + label, err := fromV14Label(v14.Label) + + if err != nil { + return DealProposal{}, xerrors.Errorf("error setting deal label: %w", err) + } + + return DealProposal{ + PieceCID: v14.PieceCID, + PieceSize: v14.PieceSize, + VerifiedDeal: v14.VerifiedDeal, + Client: v14.Client, + Provider: v14.Provider, + + Label: label, + + StartEpoch: v14.StartEpoch, + EndEpoch: v14.EndEpoch, + StoragePricePerEpoch: v14.StoragePricePerEpoch, + + ProviderCollateral: v14.ProviderCollateral, + ClientCollateral: v14.ClientCollateral, + }, nil +} + +func (s *state14) DealProposalsAmtBitwidth() int { + return market14.ProposalsAmtBitwidth +} + +func (s *state14) DealStatesAmtBitwidth() int { + return market14.StatesAmtBitwidth +} + +func (s *state14) ActorKey() string { + return manifest.MarketKey +} + +func (s *state14) ActorVersion() actorstypes.Version { + return actorstypes.Version14 +} + +func (s *state14) Code() cid.Cid { + code, ok := lotusactors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} + +func fromV14Label(v14 market14.DealLabel) (DealLabel, error) { + if v14.IsString() { + str, err := v14.ToString() + if err != nil { + return markettypes.EmptyDealLabel, xerrors.Errorf("failed to convert string label to string: %w", err) + } + return markettypes.NewLabelFromString(str) + } + + bs, err := v14.ToBytes() + if err != nil { + return markettypes.EmptyDealLabel, xerrors.Errorf("failed to convert bytes label to bytes: %w", err) + } + return markettypes.NewLabelFromBytes(bs) +} + +func (s *state14) GetProviderSectors() (map[abi.SectorID][]abi.DealID, error) { + + sectorDeals, err := adt14.AsMap(s.store, s.State.ProviderSectors, market14.ProviderSectorsHamtBitwidth) + if err != nil { + return nil, err + } + var sectorMapRoot cbg.CborCid + providerSectors := make(map[abi.SectorID][]abi.DealID) + err = sectorDeals.ForEach(§orMapRoot, func(providerID string) error { + provider, err := abi.ParseUIntKey(providerID) + if err != nil { + return nil + } + + sectorMap, err := adt14.AsMap(s.store, cid.Cid(sectorMapRoot), market14.ProviderSectorsHamtBitwidth) + if err != nil { + return err + } + + var dealIDs market14.SectorDealIDs + err = sectorMap.ForEach(&dealIDs, func(sectorID string) error { + sectorNumber, err := abi.ParseUIntKey(sectorID) + if err != nil { + return err + } + + dealIDsCopy := make([]abi.DealID, len(dealIDs)) + copy(dealIDsCopy, dealIDs) + + providerSectors[abi.SectorID{Miner: abi.ActorID(provider), Number: abi.SectorNumber(sectorNumber)}] = dealIDsCopy + return nil + }) + return err + }) + return providerSectors, err + +} + +func (s *state14) GetProviderSectorsByDealID(dealIDMap map[abi.DealID]bool, sectorIDMap map[abi.SectorNumber]bool) (map[abi.DealID]abi.SectorID, error) { + + sectorDeals, err := adt14.AsMap(s.store, s.State.ProviderSectors, market14.ProviderSectorsHamtBitwidth) + if err != nil { + return nil, err + } + var sectorMapRoot cbg.CborCid + dealIDSectorMap := make(map[abi.DealID]abi.SectorID) + err = sectorDeals.ForEach(§orMapRoot, func(providerID string) error { + provider, err := abi.ParseUIntKey(providerID) + if err != nil { + return nil + } + + sectorMap, err := adt14.AsMap(s.store, cid.Cid(sectorMapRoot), market14.ProviderSectorsHamtBitwidth) + if err != nil { + return err + } + + var dealIDs market14.SectorDealIDs + err = sectorMap.ForEach(&dealIDs, func(sectorID string) error { + sectorNumber, err := abi.ParseUIntKey(sectorID) + if err != nil { + return err + } + + if _, found := sectorIDMap[abi.SectorNumber(sectorNumber)]; !found { + return nil + } + + dealIDsCopy := make([]abi.DealID, len(dealIDs)) + copy(dealIDsCopy, dealIDs) + + for _, dealID := range dealIDsCopy { + _, found := dealIDMap[dealID] + if found { + dealIDSectorMap[dealID] = abi.SectorID{Miner: abi.ActorID(provider), Number: abi.SectorNumber(sectorNumber)} + } + } + + return nil + }) + return err + }) + return dealIDSectorMap, err + +} diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index 7f14a82f3..7d89de24d 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -10,7 +10,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" actorstypes "github.com/filecoin-project/go-state-types/actors" "github.com/filecoin-project/go-state-types/big" - miner13 "github.com/filecoin-project/go-state-types/builtin/v13/miner" + miner14 "github.com/filecoin-project/go-state-types/builtin/v14/miner" miner8 "github.com/filecoin-project/go-state-types/builtin/v8/miner" minertypes "github.com/filecoin-project/go-state-types/builtin/v9/miner" "github.com/filecoin-project/go-state-types/cbor" @@ -57,6 +57,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) { case actorstypes.Version13: return load13(store, act.Head) + case actorstypes.Version14: + return load14(store, act.Head) + } } @@ -130,6 +133,9 @@ func MakeState(store adt.Store, av actorstypes.Version) (State, error) { case actorstypes.Version13: return make13(store) + case actorstypes.Version14: + return make14(store) + } return nil, xerrors.Errorf("unknown actor version %d", av) } @@ -227,7 +233,7 @@ type Partition interface { UnprovenSectors() (bitfield.BitField, error) } -type SectorOnChainInfo = miner13.SectorOnChainInfo +type SectorOnChainInfo = miner14.SectorOnChainInfo func PreferredSealProofTypeFromWindowPoStType(nver network.Version, proof abi.RegisteredPoStProof, configWantSynthetic bool) (abi.RegisteredSealProof, error) { // We added support for the new proofs in network version 7, and removed support for the old @@ -395,6 +401,7 @@ func AllCodes() []cid.Cid { (&state11{}).Code(), (&state12{}).Code(), (&state13{}).Code(), + (&state14{}).Code(), } } @@ -413,5 +420,6 @@ func VersionCodes() map[actorstypes.Version]cid.Cid { actorstypes.Version11: (&state11{}).Code(), actorstypes.Version12: (&state12{}).Code(), actorstypes.Version13: (&state13{}).Code(), + actorstypes.Version14: (&state14{}).Code(), } } diff --git a/chain/actors/builtin/miner/mocks/state.go b/chain/actors/builtin/miner/mocks/state.go index 8a2fe0017..3ecf287de 100644 --- a/chain/actors/builtin/miner/mocks/state.go +++ b/chain/actors/builtin/miner/mocks/state.go @@ -13,7 +13,7 @@ import ( abi "github.com/filecoin-project/go-state-types/abi" actors "github.com/filecoin-project/go-state-types/actors" big "github.com/filecoin-project/go-state-types/big" - v13miner "github.com/filecoin-project/go-state-types/builtin/v13/miner" + v14miner "github.com/filecoin-project/go-state-types/builtin/v14/miner" v8miner "github.com/filecoin-project/go-state-types/builtin/v8/miner" v9miner "github.com/filecoin-project/go-state-types/builtin/v9/miner" dline "github.com/filecoin-project/go-state-types/dline" @@ -156,14 +156,14 @@ func (_m *State) DeadlinesChanged(_a0 miner.State) (bool, error) { } // DecodeSectorOnChainInfo provides a mock function with given fields: _a0 -func (_m *State) DecodeSectorOnChainInfo(_a0 *typegen.Deferred) (v13miner.SectorOnChainInfo, error) { +func (_m *State) DecodeSectorOnChainInfo(_a0 *typegen.Deferred) (v14miner.SectorOnChainInfo, error) { ret := _m.Called(_a0) - var r0 v13miner.SectorOnChainInfo - if rf, ok := ret.Get(0).(func(*typegen.Deferred) v13miner.SectorOnChainInfo); ok { + var r0 v14miner.SectorOnChainInfo + if rf, ok := ret.Get(0).(func(*typegen.Deferred) v14miner.SectorOnChainInfo); ok { r0 = rf(_a0) } else { - r0 = ret.Get(0).(v13miner.SectorOnChainInfo) + r0 = ret.Get(0).(v14miner.SectorOnChainInfo) } var r1 error @@ -386,15 +386,15 @@ func (_m *State) GetProvingPeriodStart() (abi.ChainEpoch, error) { } // GetSector provides a mock function with given fields: _a0 -func (_m *State) GetSector(_a0 abi.SectorNumber) (*v13miner.SectorOnChainInfo, error) { +func (_m *State) GetSector(_a0 abi.SectorNumber) (*v14miner.SectorOnChainInfo, error) { ret := _m.Called(_a0) - var r0 *v13miner.SectorOnChainInfo - if rf, ok := ret.Get(0).(func(abi.SectorNumber) *v13miner.SectorOnChainInfo); ok { + var r0 *v14miner.SectorOnChainInfo + if rf, ok := ret.Get(0).(func(abi.SectorNumber) *v14miner.SectorOnChainInfo); ok { r0 = rf(_a0) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*v13miner.SectorOnChainInfo) + r0 = ret.Get(0).(*v14miner.SectorOnChainInfo) } } @@ -513,15 +513,15 @@ func (_m *State) LoadDeadline(idx uint64) (miner.Deadline, error) { } // LoadSectors provides a mock function with given fields: sectorNos -func (_m *State) LoadSectors(sectorNos *bitfield.BitField) ([]*v13miner.SectorOnChainInfo, error) { +func (_m *State) LoadSectors(sectorNos *bitfield.BitField) ([]*v14miner.SectorOnChainInfo, error) { ret := _m.Called(sectorNos) - var r0 []*v13miner.SectorOnChainInfo - if rf, ok := ret.Get(0).(func(*bitfield.BitField) []*v13miner.SectorOnChainInfo); ok { + var r0 []*v14miner.SectorOnChainInfo + if rf, ok := ret.Get(0).(func(*bitfield.BitField) []*v14miner.SectorOnChainInfo); ok { r0 = rf(sectorNos) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]*v13miner.SectorOnChainInfo) + r0 = ret.Get(0).([]*v14miner.SectorOnChainInfo) } } diff --git a/chain/actors/builtin/miner/v14.go b/chain/actors/builtin/miner/v14.go new file mode 100644 index 000000000..aeb4f6df2 --- /dev/null +++ b/chain/actors/builtin/miner/v14.go @@ -0,0 +1,624 @@ +// Code generated by: `make actors-gen`. DO NOT EDIT. +package miner + +import ( + "bytes" + "crypto/sha256" + "errors" + "fmt" + + "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" + + "github.com/filecoin-project/go-bitfield" + rle "github.com/filecoin-project/go-bitfield/rle" + "github.com/filecoin-project/go-state-types/abi" + actorstypes "github.com/filecoin-project/go-state-types/actors" + builtin14 "github.com/filecoin-project/go-state-types/builtin" + miner14 "github.com/filecoin-project/go-state-types/builtin/v14/miner" + adt14 "github.com/filecoin-project/go-state-types/builtin/v14/util/adt" + minertypesv8 "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "github.com/filecoin-project/go-state-types/dline" + "github.com/filecoin-project/go-state-types/manifest" + + "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/adt" +) + +var _ State = (*state14)(nil) + +func load14(store adt.Store, root cid.Cid) (State, error) { + out := state14{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make14(store adt.Store) (State, error) { + out := state14{store: store} + out.State = miner14.State{} + return &out, nil +} + +type state14 struct { + miner14.State + store adt.Store +} + +type deadline14 struct { + miner14.Deadline + store adt.Store +} + +type partition14 struct { + miner14.Partition + store adt.Store +} + +func (s *state14) AvailableBalance(bal abi.TokenAmount) (available abi.TokenAmount, err error) { + defer func() { + if r := recover(); r != nil { + err = xerrors.Errorf("failed to get available balance: %w", r) + available = abi.NewTokenAmount(0) + } + }() + // this panics if the miner doesnt have enough funds to cover their locked pledge + available, err = s.GetAvailableBalance(bal) + return available, err +} + +func (s *state14) VestedFunds(epoch abi.ChainEpoch) (abi.TokenAmount, error) { + return s.CheckVestedFunds(s.store, epoch) +} + +func (s *state14) LockedFunds() (LockedFunds, error) { + return LockedFunds{ + VestingFunds: s.State.LockedFunds, + InitialPledgeRequirement: s.State.InitialPledge, + PreCommitDeposits: s.State.PreCommitDeposits, + }, nil +} + +func (s *state14) FeeDebt() (abi.TokenAmount, error) { + return s.State.FeeDebt, nil +} + +func (s *state14) InitialPledge() (abi.TokenAmount, error) { + return s.State.InitialPledge, nil +} + +func (s *state14) PreCommitDeposits() (abi.TokenAmount, error) { + return s.State.PreCommitDeposits, nil +} + +func (s *state14) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) { + info, ok, err := s.State.GetSector(s.store, num) + if !ok || err != nil { + return nil, err + } + + ret := fromV14SectorOnChainInfo(*info) + return &ret, nil +} + +func (s *state14) FindSector(num abi.SectorNumber) (*SectorLocation, error) { + dlIdx, partIdx, err := s.State.FindSector(s.store, num) + if err != nil { + return nil, err + } + return &SectorLocation{ + Deadline: dlIdx, + Partition: partIdx, + }, nil +} + +func (s *state14) NumLiveSectors() (uint64, error) { + dls, err := s.State.LoadDeadlines(s.store) + if err != nil { + return 0, err + } + var total uint64 + if err := dls.ForEach(s.store, func(dlIdx uint64, dl *miner14.Deadline) error { + total += dl.LiveSectors + return nil + }); err != nil { + return 0, err + } + return total, nil +} + +// GetSectorExpiration returns the effective expiration of the given sector. +// +// If the sector does not expire early, the Early expiration field is 0. +func (s *state14) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, error) { + dls, err := s.State.LoadDeadlines(s.store) + if err != nil { + return nil, err + } + // NOTE: this can be optimized significantly. + // 1. If the sector is non-faulty, it will expire on-time (can be + // learned from the sector info). + // 2. If it's faulty, it will expire early within the first 42 entries + // of the expiration queue. + + stopErr := errors.New("stop") + out := SectorExpiration{} + err = dls.ForEach(s.store, func(dlIdx uint64, dl *miner14.Deadline) error { + partitions, err := dl.PartitionsArray(s.store) + if err != nil { + return err + } + quant := s.State.QuantSpecForDeadline(dlIdx) + var part miner14.Partition + return partitions.ForEach(&part, func(partIdx int64) error { + if found, err := part.Sectors.IsSet(uint64(num)); err != nil { + return err + } else if !found { + return nil + } + if found, err := part.Terminated.IsSet(uint64(num)); err != nil { + return err + } else if found { + // already terminated + return stopErr + } + + q, err := miner14.LoadExpirationQueue(s.store, part.ExpirationsEpochs, quant, miner14.PartitionExpirationAmtBitwidth) + if err != nil { + return err + } + var exp miner14.ExpirationSet + return q.ForEach(&exp, func(epoch int64) error { + if early, err := exp.EarlySectors.IsSet(uint64(num)); err != nil { + return err + } else if early { + out.Early = abi.ChainEpoch(epoch) + return nil + } + if onTime, err := exp.OnTimeSectors.IsSet(uint64(num)); err != nil { + return err + } else if onTime { + out.OnTime = abi.ChainEpoch(epoch) + return stopErr + } + return nil + }) + }) + }) + if err == stopErr { + err = nil + } + if err != nil { + return nil, err + } + if out.Early == 0 && out.OnTime == 0 { + return nil, xerrors.Errorf("failed to find sector %d", num) + } + return &out, nil +} + +func (s *state14) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) { + info, ok, err := s.State.GetPrecommittedSector(s.store, num) + if !ok || err != nil { + return nil, err + } + + ret := fromV14SectorPreCommitOnChainInfo(*info) + + return &ret, nil +} + +func (s *state14) ForEachPrecommittedSector(cb func(SectorPreCommitOnChainInfo) error) error { + precommitted, err := adt14.AsMap(s.store, s.State.PreCommittedSectors, builtin14.DefaultHamtBitwidth) + if err != nil { + return err + } + + var info miner14.SectorPreCommitOnChainInfo + if err := precommitted.ForEach(&info, func(_ string) error { + return cb(fromV14SectorPreCommitOnChainInfo(info)) + }); err != nil { + return err + } + + return nil +} + +func (s *state14) LoadSectors(snos *bitfield.BitField) ([]*SectorOnChainInfo, error) { + sectors, err := miner14.LoadSectors(s.store, s.State.Sectors) + if err != nil { + return nil, err + } + + // If no sector numbers are specified, load all. + if snos == nil { + infos := make([]*SectorOnChainInfo, 0, sectors.Length()) + var info14 miner14.SectorOnChainInfo + if err := sectors.ForEach(&info14, func(_ int64) error { + info := fromV14SectorOnChainInfo(info14) + infos = append(infos, &info) + return nil + }); err != nil { + return nil, err + } + return infos, nil + } + + // Otherwise, load selected. + infos14, err := sectors.Load(*snos) + if err != nil { + return nil, err + } + infos := make([]*SectorOnChainInfo, len(infos14)) + for i, info14 := range infos14 { + info := fromV14SectorOnChainInfo(*info14) + infos[i] = &info + } + return infos, nil +} + +func (s *state14) loadAllocatedSectorNumbers() (bitfield.BitField, error) { + var allocatedSectors bitfield.BitField + err := s.store.Get(s.store.Context(), s.State.AllocatedSectors, &allocatedSectors) + return allocatedSectors, err +} + +func (s *state14) IsAllocated(num abi.SectorNumber) (bool, error) { + allocatedSectors, err := s.loadAllocatedSectorNumbers() + if err != nil { + return false, err + } + + return allocatedSectors.IsSet(uint64(num)) +} + +func (s *state14) GetProvingPeriodStart() (abi.ChainEpoch, error) { + return s.State.ProvingPeriodStart, nil +} + +func (s *state14) UnallocatedSectorNumbers(count int) ([]abi.SectorNumber, error) { + allocatedSectors, err := s.loadAllocatedSectorNumbers() + if err != nil { + return nil, err + } + + allocatedRuns, err := allocatedSectors.RunIterator() + if err != nil { + return nil, err + } + + unallocatedRuns, err := rle.Subtract( + &rle.RunSliceIterator{Runs: []rle.Run{{Val: true, Len: abi.MaxSectorNumber}}}, + allocatedRuns, + ) + if err != nil { + return nil, err + } + + iter, err := rle.BitsFromRuns(unallocatedRuns) + if err != nil { + return nil, err + } + + sectors := make([]abi.SectorNumber, 0, count) + for iter.HasNext() && len(sectors) < count { + nextNo, err := iter.Next() + if err != nil { + return nil, err + } + sectors = append(sectors, abi.SectorNumber(nextNo)) + } + + return sectors, nil +} + +func (s *state14) GetAllocatedSectors() (*bitfield.BitField, error) { + var allocatedSectors bitfield.BitField + if err := s.store.Get(s.store.Context(), s.State.AllocatedSectors, &allocatedSectors); err != nil { + return nil, err + } + + return &allocatedSectors, nil +} + +func (s *state14) LoadDeadline(idx uint64) (Deadline, error) { + dls, err := s.State.LoadDeadlines(s.store) + if err != nil { + return nil, err + } + dl, err := dls.LoadDeadline(s.store, idx) + if err != nil { + return nil, err + } + return &deadline14{*dl, s.store}, nil +} + +func (s *state14) ForEachDeadline(cb func(uint64, Deadline) error) error { + dls, err := s.State.LoadDeadlines(s.store) + if err != nil { + return err + } + return dls.ForEach(s.store, func(i uint64, dl *miner14.Deadline) error { + return cb(i, &deadline14{*dl, s.store}) + }) +} + +func (s *state14) NumDeadlines() (uint64, error) { + return miner14.WPoStPeriodDeadlines, nil +} + +func (s *state14) DeadlinesChanged(other State) (bool, error) { + other14, ok := other.(*state14) + if !ok { + // treat an upgrade as a change, always + return true, nil + } + + return !s.State.Deadlines.Equals(other14.Deadlines), nil +} + +func (s *state14) MinerInfoChanged(other State) (bool, error) { + other0, ok := other.(*state14) + if !ok { + // treat an upgrade as a change, always + return true, nil + } + return !s.State.Info.Equals(other0.State.Info), nil +} + +func (s *state14) Info() (MinerInfo, error) { + info, err := s.State.GetInfo(s.store) + if err != nil { + return MinerInfo{}, err + } + + mi := MinerInfo{ + Owner: info.Owner, + Worker: info.Worker, + ControlAddresses: info.ControlAddresses, + + PendingWorkerKey: (*WorkerKeyChange)(info.PendingWorkerKey), + + PeerId: info.PeerId, + Multiaddrs: info.Multiaddrs, + WindowPoStProofType: info.WindowPoStProofType, + SectorSize: info.SectorSize, + WindowPoStPartitionSectors: info.WindowPoStPartitionSectors, + ConsensusFaultElapsed: info.ConsensusFaultElapsed, + + Beneficiary: info.Beneficiary, + BeneficiaryTerm: BeneficiaryTerm(info.BeneficiaryTerm), + PendingBeneficiaryTerm: (*PendingBeneficiaryChange)(info.PendingBeneficiaryTerm), + } + + return mi, nil +} + +func (s *state14) DeadlineInfo(epoch abi.ChainEpoch) (*dline.Info, error) { + return s.State.RecordedDeadlineInfo(epoch), nil +} + +func (s *state14) DeadlineCronActive() (bool, error) { + return s.State.DeadlineCronActive, nil +} + +func (s *state14) SectorsArray() (adt.Array, error) { + return adt14.AsArray(s.store, s.Sectors, miner14.SectorsAmtBitwidth) +} + +func (s *state14) DecodeSectorOnChainInfo(val *cbg.Deferred) (SectorOnChainInfo, error) { + var si miner14.SectorOnChainInfo + err := si.UnmarshalCBOR(bytes.NewReader(val.Raw)) + if err != nil { + return SectorOnChainInfo{}, err + } + + return fromV14SectorOnChainInfo(si), nil +} + +func (s *state14) PrecommitsMap() (adt.Map, error) { + return adt14.AsMap(s.store, s.PreCommittedSectors, builtin14.DefaultHamtBitwidth) +} + +func (s *state14) PrecommitsMapBitWidth() int { + + return builtin14.DefaultHamtBitwidth + +} + +func (s *state14) PrecommitsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state14) DecodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreCommitOnChainInfo, error) { + var sp miner14.SectorPreCommitOnChainInfo + err := sp.UnmarshalCBOR(bytes.NewReader(val.Raw)) + if err != nil { + return SectorPreCommitOnChainInfo{}, err + } + + return fromV14SectorPreCommitOnChainInfo(sp), nil +} + +func (s *state14) DecodeSectorPreCommitOnChainInfoToV8(val *cbg.Deferred) (minertypesv8.SectorPreCommitOnChainInfo, error) { + + return minertypesv8.SectorPreCommitOnChainInfo{}, fmt.Errorf("unsupported in actors v9") + +} + +func (s *state14) ForEachPrecommittedSectorV8(cb func(minertypesv8.SectorPreCommitOnChainInfo) error) error { + + return fmt.Errorf("unsupported for actors v9") + +} + +func (s *state14) EraseAllUnproven() error { + + dls, err := s.State.LoadDeadlines(s.store) + if err != nil { + return err + } + + err = dls.ForEach(s.store, func(dindx uint64, dl *miner14.Deadline) error { + ps, err := dl.PartitionsArray(s.store) + if err != nil { + return err + } + + var part miner14.Partition + err = ps.ForEach(&part, func(pindx int64) error { + _ = part.ActivateUnproven() + err = ps.Set(uint64(pindx), &part) + return nil + }) + + if err != nil { + return err + } + + dl.Partitions, err = ps.Root() + if err != nil { + return err + } + + return dls.UpdateDeadline(s.store, dindx, dl) + }) + if err != nil { + return err + } + + return s.State.SaveDeadlines(s.store, dls) + +} + +func (d *deadline14) LoadPartition(idx uint64) (Partition, error) { + p, err := d.Deadline.LoadPartition(d.store, idx) + if err != nil { + return nil, err + } + return &partition14{*p, d.store}, nil +} + +func (d *deadline14) ForEachPartition(cb func(uint64, Partition) error) error { + ps, err := d.Deadline.PartitionsArray(d.store) + if err != nil { + return err + } + var part miner14.Partition + return ps.ForEach(&part, func(i int64) error { + return cb(uint64(i), &partition14{part, d.store}) + }) +} + +func (d *deadline14) PartitionsChanged(other Deadline) (bool, error) { + other14, ok := other.(*deadline14) + if !ok { + // treat an upgrade as a change, always + return true, nil + } + + return !d.Deadline.Partitions.Equals(other14.Deadline.Partitions), nil +} + +func (d *deadline14) PartitionsPoSted() (bitfield.BitField, error) { + return d.Deadline.PartitionsPoSted, nil +} + +func (d *deadline14) DisputableProofCount() (uint64, error) { + + ops, err := d.OptimisticProofsSnapshotArray(d.store) + if err != nil { + return 0, err + } + + return ops.Length(), nil + +} + +func (p *partition14) AllSectors() (bitfield.BitField, error) { + return p.Partition.Sectors, nil +} + +func (p *partition14) FaultySectors() (bitfield.BitField, error) { + return p.Partition.Faults, nil +} + +func (p *partition14) RecoveringSectors() (bitfield.BitField, error) { + return p.Partition.Recoveries, nil +} + +func (p *partition14) UnprovenSectors() (bitfield.BitField, error) { + return p.Partition.Unproven, nil +} + +func fromV14SectorOnChainInfo(v14 miner14.SectorOnChainInfo) SectorOnChainInfo { + info := SectorOnChainInfo{ + SectorNumber: v14.SectorNumber, + SealProof: v14.SealProof, + SealedCID: v14.SealedCID, + DealIDs: v14.DealIDs, + Activation: v14.Activation, + Expiration: v14.Expiration, + DealWeight: v14.DealWeight, + VerifiedDealWeight: v14.VerifiedDealWeight, + InitialPledge: v14.InitialPledge, + ExpectedDayReward: v14.ExpectedDayReward, + ExpectedStoragePledge: v14.ExpectedStoragePledge, + + SectorKeyCID: v14.SectorKeyCID, + } + return info +} + +func fromV14SectorPreCommitOnChainInfo(v14 miner14.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo { + ret := SectorPreCommitOnChainInfo{ + Info: SectorPreCommitInfo{ + SealProof: v14.Info.SealProof, + SectorNumber: v14.Info.SectorNumber, + SealedCID: v14.Info.SealedCID, + SealRandEpoch: v14.Info.SealRandEpoch, + DealIDs: v14.Info.DealIDs, + Expiration: v14.Info.Expiration, + UnsealedCid: nil, + }, + PreCommitDeposit: v14.PreCommitDeposit, + PreCommitEpoch: v14.PreCommitEpoch, + } + + ret.Info.UnsealedCid = v14.Info.UnsealedCid + + return ret +} + +func (s *state14) GetState() interface{} { + return &s.State +} + +func (s *state14) SectorsAmtBitwidth() int { + return miner14.SectorsAmtBitwidth +} + +func (s *state14) ActorKey() string { + return manifest.MinerKey +} + +func (s *state14) ActorVersion() actorstypes.Version { + return actorstypes.Version14 +} + +func (s *state14) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/multisig/multisig.go b/chain/actors/builtin/multisig/multisig.go index a194a2746..10d27e5a5 100644 --- a/chain/actors/builtin/multisig/multisig.go +++ b/chain/actors/builtin/multisig/multisig.go @@ -12,7 +12,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" actorstypes "github.com/filecoin-project/go-state-types/actors" builtintypes "github.com/filecoin-project/go-state-types/builtin" - msig13 "github.com/filecoin-project/go-state-types/builtin/v13/multisig" + msig14 "github.com/filecoin-project/go-state-types/builtin/v14/multisig" "github.com/filecoin-project/go-state-types/cbor" "github.com/filecoin-project/go-state-types/manifest" "github.com/filecoin-project/lily/chain/actors" @@ -55,6 +55,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) { case actorstypes.Version13: return load13(store, act.Head) + case actorstypes.Version14: + return load14(store, act.Head) + } } @@ -109,19 +112,19 @@ type State interface { decodeTransaction(val *cbg.Deferred) (Transaction, error) } -type Transaction = msig13.Transaction +type Transaction = msig14.Transaction var Methods = builtintypes.MethodsMultisig // these types are the same between v0 and v6 -type ProposalHashData = msig13.ProposalHashData -type ProposeReturn = msig13.ProposeReturn -type ProposeParams = msig13.ProposeParams -type ApproveReturn = msig13.ApproveReturn -type TxnIDParams = msig13.TxnIDParams +type ProposalHashData = msig14.ProposalHashData +type ProposeReturn = msig14.ProposeReturn +type ProposeParams = msig14.ProposeParams +type ApproveReturn = msig14.ApproveReturn +type TxnIDParams = msig14.TxnIDParams func txnParams(id uint64, data *ProposalHashData) ([]byte, error) { - params := msig13.TxnIDParams{ID: msig13.TxnID(id)} + params := msig14.TxnIDParams{ID: msig14.TxnID(id)} if data != nil { if data.Requester.Protocol() != address.ID { return nil, fmt.Errorf("proposer address must be an ID address, was %s", data.Requester) @@ -158,6 +161,7 @@ func AllCodes() []cid.Cid { (&state11{}).Code(), (&state12{}).Code(), (&state13{}).Code(), + (&state14{}).Code(), } } @@ -176,5 +180,6 @@ func VersionCodes() map[actorstypes.Version]cid.Cid { actorstypes.Version11: (&state11{}).Code(), actorstypes.Version12: (&state12{}).Code(), actorstypes.Version13: (&state13{}).Code(), + actorstypes.Version14: (&state14{}).Code(), } } diff --git a/chain/actors/builtin/multisig/v14.go b/chain/actors/builtin/multisig/v14.go new file mode 100644 index 000000000..10a3f1295 --- /dev/null +++ b/chain/actors/builtin/multisig/v14.go @@ -0,0 +1,131 @@ +// Code generated by: `make actors-gen`. DO NOT EDIT. +package multisig + +import ( + "bytes" + "crypto/sha256" + "encoding/binary" + "fmt" + + "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + actorstypes "github.com/filecoin-project/go-state-types/actors" + builtin14 "github.com/filecoin-project/go-state-types/builtin" + msig14 "github.com/filecoin-project/go-state-types/builtin/v14/multisig" + adt14 "github.com/filecoin-project/go-state-types/builtin/v14/util/adt" + "github.com/filecoin-project/go-state-types/manifest" + "github.com/filecoin-project/lily/chain/actors/adt" + + "github.com/filecoin-project/lotus/chain/actors" +) + +var _ State = (*state14)(nil) + +func load14(store adt.Store, root cid.Cid) (State, error) { + out := state14{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +type state14 struct { + msig14.State + store adt.Store +} + +func (s *state14) LockedBalance(currEpoch abi.ChainEpoch) (abi.TokenAmount, error) { + return s.State.AmountLocked(currEpoch - s.State.StartEpoch), nil +} + +func (s *state14) StartEpoch() (abi.ChainEpoch, error) { + return s.State.StartEpoch, nil +} + +func (s *state14) UnlockDuration() (abi.ChainEpoch, error) { + return s.State.UnlockDuration, nil +} + +func (s *state14) InitialBalance() (abi.TokenAmount, error) { + return s.State.InitialBalance, nil +} + +func (s *state14) Threshold() (uint64, error) { + return s.State.NumApprovalsThreshold, nil +} + +func (s *state14) Signers() ([]address.Address, error) { + return s.State.Signers, nil +} + +func (s *state14) ForEachPendingTxn(cb func(id int64, txn Transaction) error) error { + arr, err := adt14.AsMap(s.store, s.State.PendingTxns, builtin14.DefaultHamtBitwidth) + if err != nil { + return err + } + var out msig14.Transaction + return arr.ForEach(&out, func(key string) error { + txid, n := binary.Varint([]byte(key)) + if n <= 0 { + return fmt.Errorf("invalid pending transaction key: %v", key) + } + return cb(txid, (Transaction)(out)) //nolint:unconvert + }) +} + +func (s *state14) PendingTxnChanged(other State) (bool, error) { + other14, ok := other.(*state14) + if !ok { + // treat an upgrade as a change, always + return true, nil + } + return !s.State.PendingTxns.Equals(other14.PendingTxns), nil +} + +func (s *state14) PendingTransactionsMap() (adt.Map, error) { + return adt14.AsMap(s.store, s.PendingTxns, builtin14.DefaultHamtBitwidth) +} + +func (s *state14) PendingTransactionsMapBitWidth() int { + + return builtin14.DefaultHamtBitwidth + +} + +func (s *state14) PendingTransactionsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state14) decodeTransaction(val *cbg.Deferred) (Transaction, error) { + var tx msig14.Transaction + if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { + return Transaction{}, err + } + return Transaction(tx), nil +} + +func (s *state14) ActorKey() string { + return manifest.MultisigKey +} + +func (s *state14) ActorVersion() actorstypes.Version { + return actorstypes.Version14 +} + +func (s *state14) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/power/power.go b/chain/actors/builtin/power/power.go index 169e26656..4e20c941d 100644 --- a/chain/actors/builtin/power/power.go +++ b/chain/actors/builtin/power/power.go @@ -11,7 +11,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" actorstypes "github.com/filecoin-project/go-state-types/actors" "github.com/filecoin-project/go-state-types/big" - builtin13 "github.com/filecoin-project/go-state-types/builtin" + builtin14 "github.com/filecoin-project/go-state-types/builtin" "github.com/filecoin-project/go-state-types/cbor" "github.com/filecoin-project/go-state-types/manifest" "github.com/filecoin-project/lily/chain/actors/adt" @@ -29,8 +29,8 @@ import ( ) var ( - Address = builtin13.StoragePowerActorAddr - Methods = builtin13.MethodsPower + Address = builtin14.StoragePowerActorAddr + Methods = builtin14.MethodsPower ) func Load(store adt.Store, act *types.Actor) (State, error) { @@ -59,6 +59,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) { case actorstypes.Version13: return load13(store, act.Head) + case actorstypes.Version14: + return load14(store, act.Head) + } } @@ -148,6 +151,7 @@ func AllCodes() []cid.Cid { (&state11{}).Code(), (&state12{}).Code(), (&state13{}).Code(), + (&state14{}).Code(), } } @@ -166,5 +170,6 @@ func VersionCodes() map[actorstypes.Version]cid.Cid { actorstypes.Version11: (&state11{}).Code(), actorstypes.Version12: (&state12{}).Code(), actorstypes.Version13: (&state13{}).Code(), + actorstypes.Version14: (&state14{}).Code(), } } diff --git a/chain/actors/builtin/power/v14.go b/chain/actors/builtin/power/v14.go new file mode 100644 index 000000000..b15140c72 --- /dev/null +++ b/chain/actors/builtin/power/v14.go @@ -0,0 +1,187 @@ +// Code generated by: `make actors-gen`. DO NOT EDIT. +package power + +import ( + "bytes" + "crypto/sha256" + "fmt" + + "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + actorstypes "github.com/filecoin-project/go-state-types/actors" + builtin14 "github.com/filecoin-project/go-state-types/builtin" + power14 "github.com/filecoin-project/go-state-types/builtin/v14/power" + adt14 "github.com/filecoin-project/go-state-types/builtin/v14/util/adt" + "github.com/filecoin-project/go-state-types/manifest" + "github.com/filecoin-project/lily/chain/actors/adt" + "github.com/filecoin-project/lily/chain/actors/builtin" + + "github.com/filecoin-project/lotus/chain/actors" +) + +var _ State = (*state14)(nil) + +func load14(store adt.Store, root cid.Cid) (State, error) { + out := state14{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +type state14 struct { + power14.State + store adt.Store +} + +func (s *state14) TotalLocked() (abi.TokenAmount, error) { + return s.TotalPledgeCollateral, nil +} + +func (s *state14) TotalPower() (Claim, error) { + return Claim{ + RawBytePower: s.TotalRawBytePower, + QualityAdjPower: s.TotalQualityAdjPower, + }, nil +} + +// Committed power to the network. Includes miners below the minimum threshold. +func (s *state14) TotalCommitted() (Claim, error) { + return Claim{ + RawBytePower: s.TotalBytesCommitted, + QualityAdjPower: s.TotalQABytesCommitted, + }, nil +} + +func (s *state14) MinerPower(addr address.Address) (Claim, bool, error) { + claims, err := s.ClaimsMap() + if err != nil { + return Claim{}, false, err + } + var claim power14.Claim + ok, err := claims.Get(abi.AddrKey(addr), &claim) + if err != nil { + return Claim{}, false, err + } + return Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }, ok, nil +} + +func (s *state14) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (bool, error) { + return s.State.MinerNominalPowerMeetsConsensusMinimum(s.store, a) +} + +func (s *state14) TotalPowerSmoothed() (builtin.FilterEstimate, error) { + return builtin.FilterEstimate(s.State.ThisEpochQAPowerSmoothed), nil +} + +func (s *state14) MinerCounts() (uint64, uint64, error) { + return uint64(s.State.MinerAboveMinPowerCount), uint64(s.State.MinerCount), nil +} + +func (s *state14) ListAllMiners() ([]address.Address, error) { + claims, err := s.ClaimsMap() + if err != nil { + return nil, err + } + + var miners []address.Address + err = claims.ForEach(nil, func(k string) error { + a, err := address.NewFromBytes([]byte(k)) + if err != nil { + return err + } + miners = append(miners, a) + return nil + }) + if err != nil { + return nil, err + } + + return miners, nil +} + +func (s *state14) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { + claims, err := s.ClaimsMap() + if err != nil { + return err + } + + var claim power14.Claim + return claims.ForEach(&claim, func(k string) error { + a, err := address.NewFromBytes([]byte(k)) + if err != nil { + return err + } + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + }) +} + +func (s *state14) ClaimsChanged(other State) (bool, error) { + other14, ok := other.(*state14) + if !ok { + // treat an upgrade as a change, always + return true, nil + } + return !s.State.Claims.Equals(other14.State.Claims), nil +} + +func (s *state14) ClaimsMap() (adt.Map, error) { + return adt14.AsMap(s.store, s.Claims, builtin14.DefaultHamtBitwidth) +} + +func (s *state14) ClaimsMapBitWidth() int { + + return builtin14.DefaultHamtBitwidth + +} + +func (s *state14) ClaimsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state14) decodeClaim(val *cbg.Deferred) (Claim, error) { + var ci power14.Claim + if err := ci.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { + return Claim{}, err + } + return fromV14Claim(ci), nil +} + +func fromV14Claim(v14 power14.Claim) Claim { + return Claim{ + RawBytePower: v14.RawBytePower, + QualityAdjPower: v14.QualityAdjPower, + } +} + +func (s *state14) ActorKey() string { + return manifest.PowerKey +} + +func (s *state14) ActorVersion() actorstypes.Version { + return actorstypes.Version14 +} + +func (s *state14) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/reward/reward.go b/chain/actors/builtin/reward/reward.go index 836aed8b1..49997f7b2 100644 --- a/chain/actors/builtin/reward/reward.go +++ b/chain/actors/builtin/reward/reward.go @@ -8,7 +8,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" actorstypes "github.com/filecoin-project/go-state-types/actors" - builtin13 "github.com/filecoin-project/go-state-types/builtin" + builtin14 "github.com/filecoin-project/go-state-types/builtin" "github.com/filecoin-project/go-state-types/cbor" "github.com/filecoin-project/go-state-types/manifest" "github.com/filecoin-project/lily/chain/actors/adt" @@ -27,8 +27,8 @@ import ( ) var ( - Address = builtin13.RewardActorAddr - Methods = builtin13.MethodsReward + Address = builtin14.RewardActorAddr + Methods = builtin14.MethodsReward ) func Load(store adt.Store, act *types.Actor) (State, error) { @@ -57,6 +57,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) { case actorstypes.Version13: return load13(store, act.Head) + case actorstypes.Version14: + return load14(store, act.Head) + } } @@ -128,6 +131,7 @@ func AllCodes() []cid.Cid { (&state11{}).Code(), (&state12{}).Code(), (&state13{}).Code(), + (&state14{}).Code(), } } @@ -146,5 +150,6 @@ func VersionCodes() map[actorstypes.Version]cid.Cid { actorstypes.Version11: (&state11{}).Code(), actorstypes.Version12: (&state12{}).Code(), actorstypes.Version13: (&state13{}).Code(), + actorstypes.Version14: (&state14{}).Code(), } } diff --git a/chain/actors/builtin/reward/v14.go b/chain/actors/builtin/reward/v14.go new file mode 100644 index 000000000..88828f72e --- /dev/null +++ b/chain/actors/builtin/reward/v14.go @@ -0,0 +1,111 @@ +// Code generated by: `make actors-gen`. DO NOT EDIT. +package reward + +import ( + "fmt" + + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/go-state-types/abi" + actorstypes "github.com/filecoin-project/go-state-types/actors" + miner14 "github.com/filecoin-project/go-state-types/builtin/v14/miner" + reward14 "github.com/filecoin-project/go-state-types/builtin/v14/reward" + smoothing14 "github.com/filecoin-project/go-state-types/builtin/v14/util/smoothing" + "github.com/filecoin-project/go-state-types/manifest" + "github.com/filecoin-project/lily/chain/actors/adt" + "github.com/filecoin-project/lily/chain/actors/builtin" + + "github.com/filecoin-project/lotus/chain/actors" +) + +var _ State = (*state14)(nil) + +func load14(store adt.Store, root cid.Cid) (State, error) { + out := state14{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +type state14 struct { + reward14.State + store adt.Store +} + +func (s *state14) ThisEpochReward() (abi.TokenAmount, error) { + return s.State.ThisEpochReward, nil +} + +func (s *state14) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) { + + return builtin.FilterEstimate{ + PositionEstimate: s.State.ThisEpochRewardSmoothed.PositionEstimate, + VelocityEstimate: s.State.ThisEpochRewardSmoothed.VelocityEstimate, + }, nil + +} + +func (s *state14) ThisEpochBaselinePower() (abi.StoragePower, error) { + return s.State.ThisEpochBaselinePower, nil +} + +func (s *state14) TotalStoragePowerReward() (abi.TokenAmount, error) { + return s.State.TotalStoragePowerReward, nil +} + +func (s *state14) EffectiveBaselinePower() (abi.StoragePower, error) { + return s.State.EffectiveBaselinePower, nil +} + +func (s *state14) EffectiveNetworkTime() (abi.ChainEpoch, error) { + return s.State.EffectiveNetworkTime, nil +} + +func (s *state14) CumsumBaseline() (reward14.Spacetime, error) { + return s.State.CumsumBaseline, nil +} + +func (s *state14) CumsumRealized() (reward14.Spacetime, error) { + return s.State.CumsumRealized, nil +} + +func (s *state14) InitialPledgeForPower(qaPower abi.StoragePower, networkTotalPledge abi.TokenAmount, networkQAPower *builtin.FilterEstimate, circSupply abi.TokenAmount) (abi.TokenAmount, error) { + return miner14.InitialPledgeForPower( + qaPower, + s.State.ThisEpochBaselinePower, + s.State.ThisEpochRewardSmoothed, + smoothing14.FilterEstimate{ + PositionEstimate: networkQAPower.PositionEstimate, + VelocityEstimate: networkQAPower.VelocityEstimate, + }, + circSupply, + ), nil +} + +func (s *state14) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate, sectorWeight abi.StoragePower) (abi.TokenAmount, error) { + return miner14.PreCommitDepositForPower(s.State.ThisEpochRewardSmoothed, + smoothing14.FilterEstimate{ + PositionEstimate: networkQAPower.PositionEstimate, + VelocityEstimate: networkQAPower.VelocityEstimate, + }, + sectorWeight), nil +} + +func (s *state14) ActorKey() string { + return manifest.RewardKey +} + +func (s *state14) ActorVersion() actorstypes.Version { + return actorstypes.Version14 +} + +func (s *state14) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/verifreg/v14.go b/chain/actors/builtin/verifreg/v14.go new file mode 100644 index 000000000..a00bf2b0e --- /dev/null +++ b/chain/actors/builtin/verifreg/v14.go @@ -0,0 +1,222 @@ +// Code generated by: `make actors-gen`. DO NOT EDIT. +package verifreg + +import ( + "crypto/sha256" + "fmt" + + "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + actorstypes "github.com/filecoin-project/go-state-types/actors" + "github.com/filecoin-project/go-state-types/big" + builtin14 "github.com/filecoin-project/go-state-types/builtin" + adt14 "github.com/filecoin-project/go-state-types/builtin/v14/util/adt" + verifreg14 "github.com/filecoin-project/go-state-types/builtin/v14/verifreg" + verifreg9 "github.com/filecoin-project/go-state-types/builtin/v9/verifreg" + "github.com/filecoin-project/go-state-types/manifest" + "github.com/filecoin-project/lily/chain/actors/adt" + + "github.com/filecoin-project/lotus/chain/actors" +) + +var _ State = (*state14)(nil) + +func load14(store adt.Store, root cid.Cid) (State, error) { + out := state14{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +type state14 struct { + verifreg14.State + store adt.Store +} + +func (s *state14) ActorKey() string { + return manifest.VerifregKey +} + +func (s *state14) ActorVersion() actorstypes.Version { + return actorstypes.Version14 +} + +func (s *state14) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} + +func (s *state14) VerifiedClientsMapBitWidth() int { + + return builtin14.DefaultHamtBitwidth + +} + +func (s *state14) VerifiedClientsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state14) VerifiedClientsMap() (adt.Map, error) { + + return nil, fmt.Errorf("unsupported in actors v14") + +} + +func (s *state14) VerifiersMap() (adt.Map, error) { + return adt14.AsMap(s.store, s.Verifiers, builtin14.DefaultHamtBitwidth) +} + +func (s *state14) VerifiersMapBitWidth() int { + + return builtin14.DefaultHamtBitwidth + +} + +func (s *state14) VerifiersMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state14) RootKey() (address.Address, error) { + return s.State.RootKey, nil +} + +func (s *state14) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) { + + return false, big.Zero(), fmt.Errorf("unsupported in actors v14") + +} + +func (s *state14) VerifierDataCap(addr address.Address) (bool, abi.StoragePower, error) { + return getDataCap(s.store, actorstypes.Version14, s.VerifiersMap, addr) +} + +func (s *state14) RemoveDataCapProposalID(verifier address.Address, client address.Address) (bool, uint64, error) { + return getRemoveDataCapProposalID(s.store, actorstypes.Version14, s.removeDataCapProposalIDs, verifier, client) +} + +func (s *state14) ForEachVerifier(cb func(addr address.Address, dcap abi.StoragePower) error) error { + return forEachCap(s.store, actorstypes.Version14, s.VerifiersMap, cb) +} + +func (s *state14) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error { + + return fmt.Errorf("unsupported in actors v14") + +} + +func (s *state14) removeDataCapProposalIDs() (adt.Map, error) { + return adt14.AsMap(s.store, s.RemoveDataCapProposalIDs, builtin14.DefaultHamtBitwidth) +} + +func (s *state14) GetState() interface{} { + return &s.State +} + +func (s *state14) GetAllocation(clientIdAddr address.Address, allocationId verifreg9.AllocationId) (*Allocation, bool, error) { + + alloc, ok, err := s.FindAllocation(s.store, clientIdAddr, verifreg14.AllocationId(allocationId)) + return (*Allocation)(alloc), ok, err +} + +func (s *state14) GetAllocations(clientIdAddr address.Address) (map[AllocationId]Allocation, error) { + + v14Map, err := s.LoadAllocationsToMap(s.store, clientIdAddr) + + retMap := make(map[AllocationId]Allocation, len(v14Map)) + for k, v := range v14Map { + retMap[AllocationId(k)] = Allocation(v) + } + + return retMap, err + +} + +func (s *state14) GetClaim(providerIdAddr address.Address, claimId verifreg9.ClaimId) (*Claim, bool, error) { + + claim, ok, err := s.FindClaim(s.store, providerIdAddr, verifreg14.ClaimId(claimId)) + return (*Claim)(claim), ok, err + +} + +func (s *state14) GetClaims(providerIdAddr address.Address) (map[ClaimId]Claim, error) { + + v14Map, err := s.LoadClaimsToMap(s.store, providerIdAddr) + + retMap := make(map[ClaimId]Claim, len(v14Map)) + for k, v := range v14Map { + retMap[ClaimId(k)] = Claim(v) + } + + return retMap, err + +} + +func (s *state14) ClaimsMap() (adt.Map, error) { + + return adt14.AsMap(s.store, s.Claims, builtin14.DefaultHamtBitwidth) + +} + +// TODO this could return an error since not all versions have a claims map +func (s *state14) ClaimsMapBitWidth() int { + + return builtin14.DefaultHamtBitwidth + +} + +// TODO this could return an error since not all versions have a claims map +func (s *state14) ClaimsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state14) ClaimMapForProvider(providerIdAddr address.Address) (adt.Map, error) { + + innerHamtCid, err := s.getInnerHamtCid(s.store, abi.IdAddrKey(providerIdAddr), s.Claims, builtin14.DefaultHamtBitwidth) + if err != nil { + return nil, err + } + return adt14.AsMap(s.store, innerHamtCid, builtin14.DefaultHamtBitwidth) + +} + +func (s *state14) getInnerHamtCid(store adt.Store, key abi.Keyer, mapCid cid.Cid, bitwidth int) (cid.Cid, error) { + + actorToHamtMap, err := adt14.AsMap(store, mapCid, bitwidth) + if err != nil { + return cid.Undef, fmt.Errorf("couldn't get outer map: %x", err) + } + + var innerHamtCid cbg.CborCid + if found, err := actorToHamtMap.Get(key, &innerHamtCid); err != nil { + return cid.Undef, fmt.Errorf("looking up key: %s: %w", key, err) + } else if !found { + return cid.Undef, fmt.Errorf("did not find key: %s", key) + } + + return cid.Cid(innerHamtCid), nil + +} diff --git a/chain/actors/builtin/verifreg/verifreg.go b/chain/actors/builtin/verifreg/verifreg.go index 6a94e46c2..1330f5eb7 100644 --- a/chain/actors/builtin/verifreg/verifreg.go +++ b/chain/actors/builtin/verifreg/verifreg.go @@ -9,7 +9,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" actorstypes "github.com/filecoin-project/go-state-types/actors" - builtin13 "github.com/filecoin-project/go-state-types/builtin" + builtin14 "github.com/filecoin-project/go-state-types/builtin" verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg" "github.com/filecoin-project/go-state-types/cbor" "github.com/filecoin-project/go-state-types/manifest" @@ -27,8 +27,8 @@ import ( ) var ( - Address = builtin13.VerifiedRegistryActorAddr - Methods = builtin13.MethodsVerifiedRegistry + Address = builtin14.VerifiedRegistryActorAddr + Methods = builtin14.MethodsVerifiedRegistry ) func Load(store adt.Store, act *types.Actor) (State, error) { @@ -57,6 +57,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) { case actorstypes.Version13: return load13(store, act.Head) + case actorstypes.Version14: + return load14(store, act.Head) + } } @@ -152,6 +155,7 @@ func AllCodes() []cid.Cid { (&state11{}).Code(), (&state12{}).Code(), (&state13{}).Code(), + (&state14{}).Code(), } } @@ -170,6 +174,7 @@ func VersionCodes() map[actorstypes.Version]cid.Cid { actorstypes.Version11: (&state11{}).Code(), actorstypes.Version12: (&state12{}).Code(), actorstypes.Version13: (&state13{}).Code(), + actorstypes.Version14: (&state14{}).Code(), } } diff --git a/chain/indexer/integrated/processor/state.go b/chain/indexer/integrated/processor/state.go index 21bd0924e..626152bde 100644 --- a/chain/indexer/integrated/processor/state.go +++ b/chain/indexer/integrated/processor/state.go @@ -597,6 +597,7 @@ func MakeProcessors(api tasks.DataSource, indexerTasks []string) (*IndexerProces mineractors.VersionCodes()[actorstypes.Version11]: {minertask.PreCommitInfoExtractorV9{}}, mineractors.VersionCodes()[actorstypes.Version12]: {minertask.PreCommitInfoExtractorV9{}}, mineractors.VersionCodes()[actorstypes.Version13]: {minertask.PreCommitInfoExtractorV9{}}, + mineractors.VersionCodes()[actorstypes.Version14]: {minertask.PreCommitInfoExtractorV9{}}, }, ), minertask.PreCommitInfoExtractorV9{}, @@ -645,6 +646,7 @@ func MakeProcessors(api tasks.DataSource, indexerTasks []string) (*IndexerProces mineractors.VersionCodes()[actorstypes.Version11]: {minertask.V7SectorInfoExtractor{}}, mineractors.VersionCodes()[actorstypes.Version12]: {minertask.V7SectorInfoExtractor{}}, mineractors.VersionCodes()[actorstypes.Version13]: {minertask.V7SectorInfoExtractor{}}, + mineractors.VersionCodes()[actorstypes.Version14]: {minertask.V7SectorInfoExtractor{}}, }, ), minertask.V7SectorInfoExtractor{}, @@ -740,6 +742,7 @@ func MakeProcessors(api tasks.DataSource, indexerTasks []string) (*IndexerProces verifregactors.VersionCodes()[actorstypes.Version11]: {verifregtask.ClaimExtractor{}}, verifregactors.VersionCodes()[actorstypes.Version12]: {verifregtask.ClaimExtractor{}}, verifregactors.VersionCodes()[actorstypes.Version13]: {verifregtask.ClaimExtractor{}}, + verifregactors.VersionCodes()[actorstypes.Version14]: {verifregtask.ClaimExtractor{}}, }, )) diff --git a/chain/indexer/integrated/processor/state_internal_test.go b/chain/indexer/integrated/processor/state_internal_test.go index 9e955b6f4..a45b58040 100644 --- a/chain/indexer/integrated/processor/state_internal_test.go +++ b/chain/indexer/integrated/processor/state_internal_test.go @@ -105,6 +105,7 @@ func TestNewProcessor(t *testing.T) { miner.VersionCodes()[actorstypes.Version11]: {minertask.V7SectorInfoExtractor{}}, miner.VersionCodes()[actorstypes.Version12]: {minertask.V7SectorInfoExtractor{}}, miner.VersionCodes()[actorstypes.Version13]: {minertask.V7SectorInfoExtractor{}}, + miner.VersionCodes()[actorstypes.Version14]: {minertask.V7SectorInfoExtractor{}}, }), minertask.V7SectorInfoExtractor{}, ), @@ -127,6 +128,7 @@ func TestNewProcessor(t *testing.T) { miner.VersionCodes()[actorstypes.Version11]: {minertask.PreCommitInfoExtractorV9{}}, miner.VersionCodes()[actorstypes.Version12]: {minertask.PreCommitInfoExtractorV9{}}, miner.VersionCodes()[actorstypes.Version13]: {minertask.PreCommitInfoExtractorV9{}}, + miner.VersionCodes()[actorstypes.Version14]: {minertask.PreCommitInfoExtractorV9{}}, }, ), minertask.PreCommitInfoExtractorV9{}, @@ -154,6 +156,7 @@ func TestNewProcessor(t *testing.T) { verifreg.VersionCodes()[actorstypes.Version11]: {verifregtask.ClaimExtractor{}}, verifreg.VersionCodes()[actorstypes.Version12]: {verifregtask.ClaimExtractor{}}, verifreg.VersionCodes()[actorstypes.Version13]: {verifregtask.ClaimExtractor{}}, + verifreg.VersionCodes()[actorstypes.Version14]: {verifregtask.ClaimExtractor{}}, }, )), proc.actorProcessors[tasktype.VerifiedRegistryClaim]) diff --git a/chain/indexer/integrated/processor/state_test.go b/chain/indexer/integrated/processor/state_test.go index 84eec88b1..5da5d1967 100644 --- a/chain/indexer/integrated/processor/state_test.go +++ b/chain/indexer/integrated/processor/state_test.go @@ -114,6 +114,7 @@ func TestMakeProcessorsActors(t *testing.T) { miner.VersionCodes()[actorstypes.Version11]: {minertask.V7SectorInfoExtractor{}}, miner.VersionCodes()[actorstypes.Version12]: {minertask.V7SectorInfoExtractor{}}, miner.VersionCodes()[actorstypes.Version13]: {minertask.V7SectorInfoExtractor{}}, + miner.VersionCodes()[actorstypes.Version14]: {minertask.V7SectorInfoExtractor{}}, }, ), transformer: minertask.V7SectorInfoExtractor{}, @@ -143,6 +144,7 @@ func TestMakeProcessorsActors(t *testing.T) { miner.VersionCodes()[actorstypes.Version11]: {minertask.PreCommitInfoExtractorV9{}}, miner.VersionCodes()[actorstypes.Version12]: {minertask.PreCommitInfoExtractorV9{}}, miner.VersionCodes()[actorstypes.Version13]: {minertask.PreCommitInfoExtractorV9{}}, + miner.VersionCodes()[actorstypes.Version14]: {minertask.PreCommitInfoExtractorV9{}}, }, ), transformer: minertask.PreCommitInfoExtractorV9{}, @@ -304,6 +306,7 @@ func TestMakeProcessorsActors(t *testing.T) { verifreg.VersionCodes()[actorstypes.Version11]: {verifregtask.ClaimExtractor{}}, verifreg.VersionCodes()[actorstypes.Version12]: {verifregtask.ClaimExtractor{}}, verifreg.VersionCodes()[actorstypes.Version13]: {verifregtask.ClaimExtractor{}}, + verifreg.VersionCodes()[actorstypes.Version14]: {verifregtask.ClaimExtractor{}}, }), }, }