api: Move StateComputeDataCID to full-node
This commit is contained in:
parent
a084445e6c
commit
2dc1df878d
@ -517,6 +517,8 @@ type FullNode interface {
|
|||||||
StateMarketDeals(context.Context, types.TipSetKey) (map[string]*MarketDeal, error) //perm:read
|
StateMarketDeals(context.Context, types.TipSetKey) (map[string]*MarketDeal, error) //perm:read
|
||||||
// StateMarketStorageDeal returns information about the indicated deal
|
// StateMarketStorageDeal returns information about the indicated deal
|
||||||
StateMarketStorageDeal(context.Context, abi.DealID, types.TipSetKey) (*MarketDeal, error) //perm:read
|
StateMarketStorageDeal(context.Context, abi.DealID, types.TipSetKey) (*MarketDeal, error) //perm:read
|
||||||
|
// StateComputeDataCID computes DataCID from a set of on-chain deals
|
||||||
|
StateComputeDataCID(ctx context.Context, maddr address.Address, sectorType abi.RegisteredSealProof, deals []abi.DealID, tsk types.TipSetKey) (cid.Cid, error) //perm:read
|
||||||
// StateLookupID retrieves the ID address of the given address
|
// StateLookupID retrieves the ID address of the given address
|
||||||
StateLookupID(context.Context, address.Address, types.TipSetKey) (address.Address, error) //perm:read
|
StateLookupID(context.Context, address.Address, types.TipSetKey) (address.Address, error) //perm:read
|
||||||
// StateAccountKey returns the public key address of the given ID address for secp and bls accounts
|
// StateAccountKey returns the public key address of the given ID address for secp and bls accounts
|
||||||
|
@ -2348,6 +2348,21 @@ func (mr *MockFullNodeMockRecorder) StateCompute(arg0, arg1, arg2, arg3 interfac
|
|||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateCompute", reflect.TypeOf((*MockFullNode)(nil).StateCompute), arg0, arg1, arg2, arg3)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateCompute", reflect.TypeOf((*MockFullNode)(nil).StateCompute), arg0, arg1, arg2, arg3)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StateComputeDataCID mocks base method.
|
||||||
|
func (m *MockFullNode) StateComputeDataCID(arg0 context.Context, arg1 address.Address, arg2 abi.RegisteredSealProof, arg3 []abi.DealID, arg4 types.TipSetKey) (cid.Cid, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "StateComputeDataCID", arg0, arg1, arg2, arg3, arg4)
|
||||||
|
ret0, _ := ret[0].(cid.Cid)
|
||||||
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
|
}
|
||||||
|
|
||||||
|
// StateComputeDataCID indicates an expected call of StateComputeDataCID.
|
||||||
|
func (mr *MockFullNodeMockRecorder) StateComputeDataCID(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateComputeDataCID", reflect.TypeOf((*MockFullNode)(nil).StateComputeDataCID), arg0, arg1, arg2, arg3, arg4)
|
||||||
|
}
|
||||||
|
|
||||||
// StateDealProviderCollateralBounds mocks base method.
|
// StateDealProviderCollateralBounds mocks base method.
|
||||||
func (m *MockFullNode) StateDealProviderCollateralBounds(arg0 context.Context, arg1 abi.PaddedPieceSize, arg2 bool, arg3 types.TipSetKey) (api.DealCollateralBounds, error) {
|
func (m *MockFullNode) StateDealProviderCollateralBounds(arg0 context.Context, arg1 abi.PaddedPieceSize, arg2 bool, arg3 types.TipSetKey) (api.DealCollateralBounds, error) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
|
@ -350,6 +350,8 @@ type FullNodeStruct struct {
|
|||||||
|
|
||||||
StateCompute func(p0 context.Context, p1 abi.ChainEpoch, p2 []*types.Message, p3 types.TipSetKey) (*ComputeStateOutput, error) `perm:"read"`
|
StateCompute func(p0 context.Context, p1 abi.ChainEpoch, p2 []*types.Message, p3 types.TipSetKey) (*ComputeStateOutput, error) `perm:"read"`
|
||||||
|
|
||||||
|
StateComputeDataCID func(p0 context.Context, p1 address.Address, p2 abi.RegisteredSealProof, p3 []abi.DealID, p4 types.TipSetKey) (cid.Cid, error) `perm:"read"`
|
||||||
|
|
||||||
StateDealProviderCollateralBounds func(p0 context.Context, p1 abi.PaddedPieceSize, p2 bool, p3 types.TipSetKey) (DealCollateralBounds, error) `perm:"read"`
|
StateDealProviderCollateralBounds func(p0 context.Context, p1 abi.PaddedPieceSize, p2 bool, p3 types.TipSetKey) (DealCollateralBounds, error) `perm:"read"`
|
||||||
|
|
||||||
StateDecodeParams func(p0 context.Context, p1 address.Address, p2 abi.MethodNum, p3 []byte, p4 types.TipSetKey) (interface{}, error) `perm:"read"`
|
StateDecodeParams func(p0 context.Context, p1 address.Address, p2 abi.MethodNum, p3 []byte, p4 types.TipSetKey) (interface{}, error) `perm:"read"`
|
||||||
@ -2453,6 +2455,17 @@ func (s *FullNodeStub) StateCompute(p0 context.Context, p1 abi.ChainEpoch, p2 []
|
|||||||
return nil, ErrNotSupported
|
return nil, ErrNotSupported
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *FullNodeStruct) StateComputeDataCID(p0 context.Context, p1 address.Address, p2 abi.RegisteredSealProof, p3 []abi.DealID, p4 types.TipSetKey) (cid.Cid, error) {
|
||||||
|
if s.Internal.StateComputeDataCID == nil {
|
||||||
|
return *new(cid.Cid), ErrNotSupported
|
||||||
|
}
|
||||||
|
return s.Internal.StateComputeDataCID(p0, p1, p2, p3, p4)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *FullNodeStub) StateComputeDataCID(p0 context.Context, p1 address.Address, p2 abi.RegisteredSealProof, p3 []abi.DealID, p4 types.TipSetKey) (cid.Cid, error) {
|
||||||
|
return *new(cid.Cid), ErrNotSupported
|
||||||
|
}
|
||||||
|
|
||||||
func (s *FullNodeStruct) StateDealProviderCollateralBounds(p0 context.Context, p1 abi.PaddedPieceSize, p2 bool, p3 types.TipSetKey) (DealCollateralBounds, error) {
|
func (s *FullNodeStruct) StateDealProviderCollateralBounds(p0 context.Context, p1 abi.PaddedPieceSize, p2 bool, p3 types.TipSetKey) (DealCollateralBounds, error) {
|
||||||
if s.Internal.StateDealProviderCollateralBounds == nil {
|
if s.Internal.StateDealProviderCollateralBounds == nil {
|
||||||
return *new(DealCollateralBounds), ErrNotSupported
|
return *new(DealCollateralBounds), ErrNotSupported
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -170,6 +170,7 @@
|
|||||||
* [StateChangedActors](#StateChangedActors)
|
* [StateChangedActors](#StateChangedActors)
|
||||||
* [StateCirculatingSupply](#StateCirculatingSupply)
|
* [StateCirculatingSupply](#StateCirculatingSupply)
|
||||||
* [StateCompute](#StateCompute)
|
* [StateCompute](#StateCompute)
|
||||||
|
* [StateComputeDataCID](#StateComputeDataCID)
|
||||||
* [StateDealProviderCollateralBounds](#StateDealProviderCollateralBounds)
|
* [StateDealProviderCollateralBounds](#StateDealProviderCollateralBounds)
|
||||||
* [StateDecodeParams](#StateDecodeParams)
|
* [StateDecodeParams](#StateDecodeParams)
|
||||||
* [StateEncodeParams](#StateEncodeParams)
|
* [StateEncodeParams](#StateEncodeParams)
|
||||||
@ -5521,6 +5522,38 @@ Response:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### StateComputeDataCID
|
||||||
|
StateComputeDataCID computes DataCID from a set of on-chain deals
|
||||||
|
|
||||||
|
|
||||||
|
Perms: read
|
||||||
|
|
||||||
|
Inputs:
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
"f01234",
|
||||||
|
8,
|
||||||
|
[
|
||||||
|
5432
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"/": "bafy2bzacebp3shtrn43k7g3unredz7fxn4gj533d3o43tqn2p2ipxxhrvchve"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
Response:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### StateDealProviderCollateralBounds
|
### StateDealProviderCollateralBounds
|
||||||
StateDealProviderCollateralBounds returns the min and max collateral a storage provider
|
StateDealProviderCollateralBounds returns the min and max collateral a storage provider
|
||||||
can issue. It takes the deal size and verified status as parameters.
|
can issue. It takes the deal size and verified status as parameters.
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
"github.com/libp2p/go-libp2p-core/peer"
|
"github.com/libp2p/go-libp2p-core/peer"
|
||||||
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
"go.uber.org/fx"
|
"go.uber.org/fx"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
@ -21,9 +22,12 @@ import (
|
|||||||
"github.com/filecoin-project/go-state-types/crypto"
|
"github.com/filecoin-project/go-state-types/crypto"
|
||||||
"github.com/filecoin-project/go-state-types/dline"
|
"github.com/filecoin-project/go-state-types/dline"
|
||||||
"github.com/filecoin-project/go-state-types/network"
|
"github.com/filecoin-project/go-state-types/network"
|
||||||
|
market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market"
|
||||||
|
market5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/market"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
|
"github.com/filecoin-project/lotus/chain/actors"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
|
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
||||||
@ -756,6 +760,69 @@ func (m *StateModule) StateMarketStorageDeal(ctx context.Context, dealId abi.Dea
|
|||||||
return stmgr.GetStorageDeal(ctx, m.StateManager, dealId, ts)
|
return stmgr.GetStorageDeal(ctx, m.StateManager, dealId, ts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *StateAPI) StateComputeDataCID(ctx context.Context, maddr address.Address, sectorType abi.RegisteredSealProof, deals []abi.DealID, tsk types.TipSetKey) (cid.Cid, error) {
|
||||||
|
nv, err := a.StateNetworkVersion(ctx, tsk)
|
||||||
|
if err != nil {
|
||||||
|
return cid.Cid{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var ccparams []byte
|
||||||
|
if nv < network.Version13 {
|
||||||
|
ccparams, err = actors.SerializeParams(&market2.ComputeDataCommitmentParams{
|
||||||
|
DealIDs: deals,
|
||||||
|
SectorType: sectorType,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
ccparams, err = actors.SerializeParams(&market5.ComputeDataCommitmentParams{
|
||||||
|
Inputs: []*market5.SectorDataSpec{
|
||||||
|
{
|
||||||
|
DealIDs: deals,
|
||||||
|
SectorType: sectorType,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return cid.Undef, xerrors.Errorf("computing params for ComputeDataCommitment: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ccmt := &types.Message{
|
||||||
|
To: market.Address,
|
||||||
|
From: maddr,
|
||||||
|
Value: types.NewInt(0),
|
||||||
|
Method: market.Methods.ComputeDataCommitment,
|
||||||
|
Params: ccparams,
|
||||||
|
}
|
||||||
|
r, err := a.StateCall(ctx, ccmt, tsk)
|
||||||
|
if err != nil {
|
||||||
|
return cid.Undef, xerrors.Errorf("calling ComputeDataCommitment: %w", err)
|
||||||
|
}
|
||||||
|
if r.MsgRct.ExitCode != 0 {
|
||||||
|
return cid.Undef, xerrors.Errorf("receipt for ComputeDataCommitment had exit code %d", r.MsgRct.ExitCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
if nv < network.Version13 {
|
||||||
|
var c cbg.CborCid
|
||||||
|
if err := c.UnmarshalCBOR(bytes.NewReader(r.MsgRct.Return)); err != nil {
|
||||||
|
return cid.Undef, xerrors.Errorf("failed to unmarshal CBOR to CborCid: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return cid.Cid(c), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var cr market5.ComputeDataCommitmentReturn
|
||||||
|
if err := cr.UnmarshalCBOR(bytes.NewReader(r.MsgRct.Return)); err != nil {
|
||||||
|
return cid.Undef, xerrors.Errorf("failed to unmarshal CBOR to CborCid: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(cr.CommDs) != 1 {
|
||||||
|
return cid.Undef, xerrors.Errorf("CommD output must have 1 entry")
|
||||||
|
}
|
||||||
|
|
||||||
|
return cid.Cid(cr.CommDs[0]), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *StateAPI) StateChangedActors(ctx context.Context, old cid.Cid, new cid.Cid) (map[string]types.Actor, error) {
|
func (a *StateAPI) StateChangedActors(ctx context.Context, old cid.Cid, new cid.Cid) (map[string]types.Actor, error) {
|
||||||
store := a.Chain.ActorStore(ctx)
|
store := a.Chain.ActorStore(ctx)
|
||||||
|
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
package storage
|
package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
@ -15,12 +13,9 @@ import (
|
|||||||
"github.com/filecoin-project/go-state-types/crypto"
|
"github.com/filecoin-project/go-state-types/crypto"
|
||||||
"github.com/filecoin-project/go-state-types/dline"
|
"github.com/filecoin-project/go-state-types/dline"
|
||||||
"github.com/filecoin-project/go-state-types/network"
|
"github.com/filecoin-project/go-state-types/network"
|
||||||
market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market"
|
|
||||||
market5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/market"
|
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/blockstore"
|
"github.com/filecoin-project/lotus/blockstore"
|
||||||
"github.com/filecoin-project/lotus/chain/actors"
|
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
|
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
||||||
"github.com/filecoin-project/lotus/chain/store"
|
"github.com/filecoin-project/lotus/chain/store"
|
||||||
@ -116,67 +111,7 @@ func (s SealingAPIAdapter) ChainHead(ctx context.Context) (*types.TipSet, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s SealingAPIAdapter) StateComputeDataCommitment(ctx context.Context, maddr address.Address, sectorType abi.RegisteredSealProof, deals []abi.DealID, tsk types.TipSetKey) (cid.Cid, error) {
|
func (s SealingAPIAdapter) StateComputeDataCommitment(ctx context.Context, maddr address.Address, sectorType abi.RegisteredSealProof, deals []abi.DealID, tsk types.TipSetKey) (cid.Cid, error) {
|
||||||
|
return s.delegate.StateComputeDataCID(ctx, maddr, sectorType, deals, tsk)
|
||||||
nv, err := s.delegate.StateNetworkVersion(ctx, tsk)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Cid{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var ccparams []byte
|
|
||||||
if nv < network.Version13 {
|
|
||||||
ccparams, err = actors.SerializeParams(&market2.ComputeDataCommitmentParams{
|
|
||||||
DealIDs: deals,
|
|
||||||
SectorType: sectorType,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
ccparams, err = actors.SerializeParams(&market5.ComputeDataCommitmentParams{
|
|
||||||
Inputs: []*market5.SectorDataSpec{
|
|
||||||
{
|
|
||||||
DealIDs: deals,
|
|
||||||
SectorType: sectorType,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, xerrors.Errorf("computing params for ComputeDataCommitment: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
ccmt := &types.Message{
|
|
||||||
To: market.Address,
|
|
||||||
From: maddr,
|
|
||||||
Value: types.NewInt(0),
|
|
||||||
Method: market.Methods.ComputeDataCommitment,
|
|
||||||
Params: ccparams,
|
|
||||||
}
|
|
||||||
r, err := s.delegate.StateCall(ctx, ccmt, tsk)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, xerrors.Errorf("calling ComputeDataCommitment: %w", err)
|
|
||||||
}
|
|
||||||
if r.MsgRct.ExitCode != 0 {
|
|
||||||
return cid.Undef, xerrors.Errorf("receipt for ComputeDataCommitment had exit code %d", r.MsgRct.ExitCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
if nv < network.Version13 {
|
|
||||||
var c cbg.CborCid
|
|
||||||
if err := c.UnmarshalCBOR(bytes.NewReader(r.MsgRct.Return)); err != nil {
|
|
||||||
return cid.Undef, xerrors.Errorf("failed to unmarshal CBOR to CborCid: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return cid.Cid(c), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var cr market5.ComputeDataCommitmentReturn
|
|
||||||
if err := cr.UnmarshalCBOR(bytes.NewReader(r.MsgRct.Return)); err != nil {
|
|
||||||
return cid.Undef, xerrors.Errorf("failed to unmarshal CBOR to CborCid: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(cr.CommDs) != 1 {
|
|
||||||
return cid.Undef, xerrors.Errorf("CommD output must have 1 entry")
|
|
||||||
}
|
|
||||||
|
|
||||||
return cid.Cid(cr.CommDs[0]), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SealingAPIAdapter) StateSectorPreCommitInfo(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tsk types.TipSetKey) (*minertypes.SectorPreCommitOnChainInfo, error) {
|
func (s SealingAPIAdapter) StateSectorPreCommitInfo(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tsk types.TipSetKey) (*minertypes.SectorPreCommitOnChainInfo, error) {
|
||||||
|
@ -102,6 +102,7 @@ type fullNodeFilteredAPI interface {
|
|||||||
StateMinerRecoveries(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error)
|
StateMinerRecoveries(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error)
|
||||||
StateAccountKey(context.Context, address.Address, types.TipSetKey) (address.Address, error)
|
StateAccountKey(context.Context, address.Address, types.TipSetKey) (address.Address, error)
|
||||||
StateNetworkVersion(context.Context, types.TipSetKey) (network.Version, error)
|
StateNetworkVersion(context.Context, types.TipSetKey) (network.Version, error)
|
||||||
|
StateComputeDataCID(ctx context.Context, maddr address.Address, sectorType abi.RegisteredSealProof, deals []abi.DealID, tsk types.TipSetKey) (cid.Cid, error)
|
||||||
StateLookupID(context.Context, address.Address, types.TipSetKey) (address.Address, error)
|
StateLookupID(context.Context, address.Address, types.TipSetKey) (address.Address, error)
|
||||||
|
|
||||||
MpoolPushMessage(context.Context, *types.Message, *api.MessageSendSpec) (*types.SignedMessage, error)
|
MpoolPushMessage(context.Context, *types.Message, *api.MessageSendSpec) (*types.SignedMessage, error)
|
||||||
|
Loading…
Reference in New Issue
Block a user