From bd0f0cd2249f4a115ba57c6266dcc95989a1bc47 Mon Sep 17 00:00:00 2001 From: tom <69969590+simlecode@users.noreply.github.com> Date: Mon, 26 Sep 2022 14:21:02 +0800 Subject: [PATCH] feat: add chain api `StateMinerAllocated` (#5325) --- app/submodule/chain/miner_api.go | 18 ++++++++++++ venus-shared/api/chain/v1/chain.go | 2 ++ venus-shared/api/chain/v1/method.md | 29 +++++++++++++++++++ .../api/chain/v1/mock/mock_fullnode.go | 15 ++++++++++ venus-shared/api/chain/v1/proxy_gen.go | 4 +++ venus-shared/compatible-checks/api-diff.txt | 1 + venus-shared/compatible-checks/api-perm.txt | 1 + 7 files changed, 70 insertions(+) diff --git a/app/submodule/chain/miner_api.go b/app/submodule/chain/miner_api.go index 32946723d0..6495c9bce3 100644 --- a/app/submodule/chain/miner_api.go +++ b/app/submodule/chain/miner_api.go @@ -1080,3 +1080,21 @@ func (msa *minerStateAPI) StateListMessages(ctx context.Context, match *types.Me return out, nil } + +// StateMinerAllocated returns a bitfield containing all sector numbers marked as allocated in miner state +func (msa *minerStateAPI) StateMinerAllocated(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*bitfield.BitField, error) { + _, view, err := msa.Stmgr.ParentStateViewTsk(ctx, tsk) + if err != nil { + return nil, fmt.Errorf("loading tipset:%s parent state view: %v", tsk, err) + } + + act, err := view.LoadActor(ctx, addr) + if err != nil { + return nil, err + } + mas, err := lminer.Load(msa.ChainReader.Store(ctx), act) + if err != nil { + return nil, err + } + return mas.GetAllocatedSectors() +} diff --git a/venus-shared/api/chain/v1/chain.go b/venus-shared/api/chain/v1/chain.go index 2ee5333e59..09099b9984 100644 --- a/venus-shared/api/chain/v1/chain.go +++ b/venus-shared/api/chain/v1/chain.go @@ -165,4 +165,6 @@ type IMinerState interface { StateMarketBalance(ctx context.Context, addr address.Address, tsk types.TipSetKey) (types.MarketBalance, error) //perm:read StateDealProviderCollateralBounds(ctx context.Context, size abi.PaddedPieceSize, verified bool, tsk types.TipSetKey) (types.DealCollateralBounds, error) //perm:read StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*abi.StoragePower, error) //perm:read + // StateMinerAllocated returns a bitfield containing all sector numbers marked as allocated in miner state + StateMinerAllocated(context.Context, address.Address, types.TipSetKey) (*bitfield.BitField, error) //perm:read } diff --git a/venus-shared/api/chain/v1/method.md b/venus-shared/api/chain/v1/method.md index f01d8102cb..534dd05927 100644 --- a/venus-shared/api/chain/v1/method.md +++ b/venus-shared/api/chain/v1/method.md @@ -98,6 +98,7 @@ * [StateMarketDeals](#StateMarketDeals) * [StateMarketStorageDeal](#StateMarketStorageDeal) * [StateMinerActiveSectors](#StateMinerActiveSectors) + * [StateMinerAllocated](#StateMinerAllocated) * [StateMinerAvailableBalance](#StateMinerAvailableBalance) * [StateMinerDeadlines](#StateMinerDeadlines) * [StateMinerFaults](#StateMinerFaults) @@ -3312,6 +3313,34 @@ Response: ] ``` +### StateMinerAllocated +StateMinerAllocated returns a bitfield containing all sector numbers marked as allocated in miner state + + +Perms: read + +Inputs: +```json +[ + "f01234", + [ + { + "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" + }, + { + "/": "bafy2bzacebp3shtrn43k7g3unredz7fxn4gj533d3o43tqn2p2ipxxhrvchve" + } + ] +] +``` + +Response: +```json +[ + 0 +] +``` + ### StateMinerAvailableBalance diff --git a/venus-shared/api/chain/v1/mock/mock_fullnode.go b/venus-shared/api/chain/v1/mock/mock_fullnode.go index 740aa510d0..849512d2df 100644 --- a/venus-shared/api/chain/v1/mock/mock_fullnode.go +++ b/venus-shared/api/chain/v1/mock/mock_fullnode.go @@ -2163,6 +2163,21 @@ func (mr *MockFullNodeMockRecorder) StateMinerActiveSectors(arg0, arg1, arg2 int return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateMinerActiveSectors", reflect.TypeOf((*MockFullNode)(nil).StateMinerActiveSectors), arg0, arg1, arg2) } +// StateMinerAllocated mocks base method. +func (m *MockFullNode) StateMinerAllocated(arg0 context.Context, arg1 address.Address, arg2 types.TipSetKey) (*bitfield.BitField, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StateMinerAllocated", arg0, arg1, arg2) + ret0, _ := ret[0].(*bitfield.BitField) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StateMinerAllocated indicates an expected call of StateMinerAllocated. +func (mr *MockFullNodeMockRecorder) StateMinerAllocated(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateMinerAllocated", reflect.TypeOf((*MockFullNode)(nil).StateMinerAllocated), arg0, arg1, arg2) +} + // StateMinerAvailableBalance mocks base method. func (m *MockFullNode) StateMinerAvailableBalance(arg0 context.Context, arg1 address.Address, arg2 types.TipSetKey) (big.Int, error) { m.ctrl.T.Helper() diff --git a/venus-shared/api/chain/v1/proxy_gen.go b/venus-shared/api/chain/v1/proxy_gen.go index 10fabc71ca..b23ef6ce29 100644 --- a/venus-shared/api/chain/v1/proxy_gen.go +++ b/venus-shared/api/chain/v1/proxy_gen.go @@ -93,6 +93,7 @@ type IMinerStateStruct struct { StateMarketDeals func(ctx context.Context, tsk types.TipSetKey) (map[string]*types.MarketDeal, error) `perm:"read"` StateMarketStorageDeal func(ctx context.Context, dealID abi.DealID, tsk types.TipSetKey) (*types.MarketDeal, error) `perm:"read"` StateMinerActiveSectors func(ctx context.Context, maddr address.Address, tsk types.TipSetKey) ([]*miner.SectorOnChainInfo, error) `perm:"read"` + StateMinerAllocated func(context.Context, address.Address, types.TipSetKey) (*bitfield.BitField, error) `perm:"read"` StateMinerAvailableBalance func(ctx context.Context, maddr address.Address, tsk types.TipSetKey) (big.Int, error) `perm:"read"` StateMinerDeadlines func(ctx context.Context, maddr address.Address, tsk types.TipSetKey) ([]types.Deadline, error) `perm:"read"` StateMinerFaults func(ctx context.Context, maddr address.Address, tsk types.TipSetKey) (bitfield.BitField, error) `perm:"read"` @@ -166,6 +167,9 @@ func (s *IMinerStateStruct) StateMarketStorageDeal(p0 context.Context, p1 abi.De func (s *IMinerStateStruct) StateMinerActiveSectors(p0 context.Context, p1 address.Address, p2 types.TipSetKey) ([]*miner.SectorOnChainInfo, error) { return s.Internal.StateMinerActiveSectors(p0, p1, p2) } +func (s *IMinerStateStruct) StateMinerAllocated(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (*bitfield.BitField, error) { + return s.Internal.StateMinerAllocated(p0, p1, p2) +} func (s *IMinerStateStruct) StateMinerAvailableBalance(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (big.Int, error) { return s.Internal.StateMinerAvailableBalance(p0, p1, p2) } diff --git a/venus-shared/compatible-checks/api-diff.txt b/venus-shared/compatible-checks/api-diff.txt index af0ff3fad9..8d4f102cca 100644 --- a/venus-shared/compatible-checks/api-diff.txt +++ b/venus-shared/compatible-checks/api-diff.txt @@ -202,6 +202,7 @@ github.com/filecoin-project/venus/venus-shared/api/chain/v1.FullNode <> github.c + StateActorManifestCID - StateCompute > StateGetNetworkParams {[func(context.Context) (*types.NetworkParams, error) <> func(context.Context) (*api.NetworkParams, error)] base=func out type: #0 input; nested={[*types.NetworkParams <> *api.NetworkParams] base=pointed type; nested={[types.NetworkParams <> api.NetworkParams] base=struct field; nested={[types.NetworkParams <> api.NetworkParams] base=exported field type: #5 field named ForkUpgradeParams; nested={[types.ForkUpgradeParams <> api.ForkUpgradeParams] base=struct field; nested={[types.ForkUpgradeParams <> api.ForkUpgradeParams] base=exported field name: #8 field, BreezeGasTampingDuration != UpgradePriceListOopsHeight; nested=nil}}}}}} + + StateMinerAllocated + StateMinerSectorSize + StateMinerWorkerAddress - StateReplay diff --git a/venus-shared/compatible-checks/api-perm.txt b/venus-shared/compatible-checks/api-perm.txt index 179ce6d95a..8a683d73e5 100644 --- a/venus-shared/compatible-checks/api-perm.txt +++ b/venus-shared/compatible-checks/api-perm.txt @@ -68,6 +68,7 @@ v1: github.com/filecoin-project/venus/venus-shared/api/chain/v1 <> github.com/fi - IChainInfo.ResolveToKeyAddr - IChainInfo.StateActorManifestCID - IChainInfo.VerifyEntry + - IMinerState.StateMinerAllocated - IMinerState.StateMinerSectorSize - IMinerState.StateMinerWorkerAddress - IMessagePool.GasBatchEstimateMessageGas