Merge pull request #3009 from filecoin-project/feat/offline_commp_calculation
Stop requiring miner address / sector size for `lotus client commP`
This commit is contained in:
commit
e83fa0dd04
@ -247,8 +247,8 @@ type FullNode interface {
|
|||||||
ClientRetrieve(ctx context.Context, order RetrievalOrder, ref *FileRef) (<-chan marketevents.RetrievalEvent, error)
|
ClientRetrieve(ctx context.Context, order RetrievalOrder, ref *FileRef) (<-chan marketevents.RetrievalEvent, error)
|
||||||
// ClientQueryAsk returns a signed StorageAsk from the specified miner.
|
// ClientQueryAsk returns a signed StorageAsk from the specified miner.
|
||||||
ClientQueryAsk(ctx context.Context, p peer.ID, miner address.Address) (*storagemarket.SignedStorageAsk, error)
|
ClientQueryAsk(ctx context.Context, p peer.ID, miner address.Address) (*storagemarket.SignedStorageAsk, error)
|
||||||
// ClientCalcCommP calculates the CommP for a specified file, based on the sector size of the provided miner.
|
// ClientCalcCommP calculates the CommP for a specified file
|
||||||
ClientCalcCommP(ctx context.Context, inpath string, miner address.Address) (*CommPRet, error)
|
ClientCalcCommP(ctx context.Context, inpath string) (*CommPRet, error)
|
||||||
// ClientGenCar generates a CAR file for the specified file.
|
// ClientGenCar generates a CAR file for the specified file.
|
||||||
ClientGenCar(ctx context.Context, ref FileRef, outpath string) error
|
ClientGenCar(ctx context.Context, ref FileRef, outpath string) error
|
||||||
// ClientDealSize calculates real deal data size
|
// ClientDealSize calculates real deal data size
|
||||||
|
@ -137,7 +137,7 @@ type FullNodeStruct struct {
|
|||||||
ClientListDeals func(ctx context.Context) ([]api.DealInfo, error) `perm:"write"`
|
ClientListDeals func(ctx context.Context) ([]api.DealInfo, error) `perm:"write"`
|
||||||
ClientRetrieve func(ctx context.Context, order api.RetrievalOrder, ref *api.FileRef) (<-chan marketevents.RetrievalEvent, error) `perm:"admin"`
|
ClientRetrieve func(ctx context.Context, order api.RetrievalOrder, ref *api.FileRef) (<-chan marketevents.RetrievalEvent, error) `perm:"admin"`
|
||||||
ClientQueryAsk func(ctx context.Context, p peer.ID, miner address.Address) (*storagemarket.SignedStorageAsk, error) `perm:"read"`
|
ClientQueryAsk func(ctx context.Context, p peer.ID, miner address.Address) (*storagemarket.SignedStorageAsk, error) `perm:"read"`
|
||||||
ClientCalcCommP func(ctx context.Context, inpath string, miner address.Address) (*api.CommPRet, error) `perm:"read"`
|
ClientCalcCommP func(ctx context.Context, inpath string) (*api.CommPRet, error) `perm:"read"`
|
||||||
ClientGenCar func(ctx context.Context, ref api.FileRef, outpath string) error `perm:"write"`
|
ClientGenCar func(ctx context.Context, ref api.FileRef, outpath string) error `perm:"write"`
|
||||||
ClientDealSize func(ctx context.Context, root cid.Cid) (api.DataSize, error) `perm:"read"`
|
ClientDealSize func(ctx context.Context, root cid.Cid) (api.DataSize, error) `perm:"read"`
|
||||||
|
|
||||||
@ -426,8 +426,8 @@ func (c *FullNodeStruct) ClientRetrieve(ctx context.Context, order api.Retrieval
|
|||||||
func (c *FullNodeStruct) ClientQueryAsk(ctx context.Context, p peer.ID, miner address.Address) (*storagemarket.SignedStorageAsk, error) {
|
func (c *FullNodeStruct) ClientQueryAsk(ctx context.Context, p peer.ID, miner address.Address) (*storagemarket.SignedStorageAsk, error) {
|
||||||
return c.Internal.ClientQueryAsk(ctx, p, miner)
|
return c.Internal.ClientQueryAsk(ctx, p, miner)
|
||||||
}
|
}
|
||||||
func (c *FullNodeStruct) ClientCalcCommP(ctx context.Context, inpath string, miner address.Address) (*api.CommPRet, error) {
|
func (c *FullNodeStruct) ClientCalcCommP(ctx context.Context, inpath string) (*api.CommPRet, error) {
|
||||||
return c.Internal.ClientCalcCommP(ctx, inpath, miner)
|
return c.Internal.ClientCalcCommP(ctx, inpath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FullNodeStruct) ClientGenCar(ctx context.Context, ref api.FileRef, outpath string) error {
|
func (c *FullNodeStruct) ClientGenCar(ctx context.Context, ref api.FileRef, outpath string) error {
|
||||||
|
@ -174,7 +174,7 @@ var clientDropCmd = &cli.Command{
|
|||||||
var clientCommPCmd = &cli.Command{
|
var clientCommPCmd = &cli.Command{
|
||||||
Name: "commP",
|
Name: "commP",
|
||||||
Usage: "Calculate the piece-cid (commP) of a CAR file",
|
Usage: "Calculate the piece-cid (commP) of a CAR file",
|
||||||
ArgsUsage: "[inputFile minerAddress]",
|
ArgsUsage: "[inputFile]",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&CidBaseFlag,
|
&CidBaseFlag,
|
||||||
},
|
},
|
||||||
@ -186,16 +186,11 @@ var clientCommPCmd = &cli.Command{
|
|||||||
defer closer()
|
defer closer()
|
||||||
ctx := ReqContext(cctx)
|
ctx := ReqContext(cctx)
|
||||||
|
|
||||||
if cctx.Args().Len() != 2 {
|
if cctx.Args().Len() != 1 {
|
||||||
return fmt.Errorf("usage: commP <inputPath> <minerAddr>")
|
return fmt.Errorf("usage: commP <inputPath>")
|
||||||
}
|
}
|
||||||
|
|
||||||
miner, err := address.NewFromString(cctx.Args().Get(1))
|
ret, err := api.ClientCalcCommP(ctx, cctx.Args().Get(0))
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ret, err := api.ClientCalcCommP(ctx, cctx.Args().Get(0), miner)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -565,13 +565,19 @@ func (a *API) ClientQueryAsk(ctx context.Context, p peer.ID, miner address.Addre
|
|||||||
return signedAsk, nil
|
return signedAsk, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) ClientCalcCommP(ctx context.Context, inpath string, miner address.Address) (*api.CommPRet, error) {
|
func (a *API) ClientCalcCommP(ctx context.Context, inpath string) (*api.CommPRet, error) {
|
||||||
mi, err := a.StateMinerInfo(ctx, miner, types.EmptyTSK)
|
|
||||||
if err != nil {
|
|
||||||
return nil, xerrors.Errorf("failed checking miners sector size: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
rt, err := ffiwrapper.SealProofTypeFromSectorSize(mi.SectorSize)
|
// Hard-code the sector size to 32GiB, because:
|
||||||
|
// - pieceio.GeneratePieceCommitment requires a RegisteredSealProof
|
||||||
|
// - commP itself is sector-size independent, with rather low probability of that changing
|
||||||
|
// ( note how the final rust call is identical for every RegSP type )
|
||||||
|
// https://github.com/filecoin-project/rust-filecoin-proofs-api/blob/v5.0.0/src/seal.rs#L1040-L1050
|
||||||
|
//
|
||||||
|
// IF/WHEN this changes in the future we will have to be able to calculate
|
||||||
|
// "old style" commP, and thus will need to introduce a version switch or similar
|
||||||
|
arbitrarySectorSize := abi.SectorSize(32 << 30)
|
||||||
|
|
||||||
|
rt, err := ffiwrapper.SealProofTypeFromSectorSize(arbitrarySectorSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("bad sector size: %w", err)
|
return nil, xerrors.Errorf("bad sector size: %w", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user