Merge pull request #5553 from filecoin-project/feat/data-xfer-percent

show data transfer % for storage deals
This commit is contained in:
Łukasz Magiera 2021-02-11 13:29:43 +01:00 committed by GitHub
commit 95e47cf998
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 41 additions and 24 deletions

View File

@ -938,9 +938,10 @@ type DataSize struct {
} }
type DataCIDSize struct { type DataCIDSize struct {
PayloadSize int64 RawBlockSize uint64
PieceSize abi.PaddedPieceSize PayloadSize int64
PieceCID cid.Cid PieceSize abi.PaddedPieceSize
PieceCID cid.Cid
} }
type CommPRet struct { type CommPRet struct {

View File

@ -850,8 +850,9 @@ uiLoop:
TransferType: storagemarket.TTGraphsync, TransferType: storagemarket.TTGraphsync,
Root: data, Root: data,
PieceCid: &ds.PieceCID, PieceCid: &ds.PieceCID,
PieceSize: ds.PieceSize.Unpadded(), PieceSize: ds.PieceSize.Unpadded(),
RawBlockSize: ds.RawBlockSize,
}, },
Wallet: a, Wallet: a,
Miner: maddr, Miner: maddr,
@ -1567,7 +1568,7 @@ func outputStorageDeals(ctx context.Context, out io.Writer, full lapi.FullNode,
if verbose { if verbose {
w := tabwriter.NewWriter(out, 2, 4, 2, ' ', 0) w := tabwriter.NewWriter(out, 2, 4, 2, ' ', 0)
fmt.Fprintf(w, "Created\tDealCid\tDealId\tProvider\tState\tOn Chain?\tSlashed?\tPieceCID\tSize\tPrice\tDuration\tTransferChannelID\tTransferStatus\tVerified\tMessage\n") fmt.Fprintf(w, "Created\tDealCid\tDealId\tProvider\tState\tOn Chain?\tSlashed?\tPieceCID\tSize\tPrice\tDuration\tTransferChannelID\tTransferStatus\tTransfer %%\tVerified\tMessage\n")
for _, d := range deals { for _, d := range deals {
onChain := "N" onChain := "N"
if d.OnChainDealState.SectorStartEpoch != -1 { if d.OnChainDealState.SectorStartEpoch != -1 {
@ -1585,17 +1586,16 @@ func outputStorageDeals(ctx context.Context, out io.Writer, full lapi.FullNode,
transferChannelID = d.LocalDeal.TransferChannelID.String() transferChannelID = d.LocalDeal.TransferChannelID.String()
} }
transferStatus := "" transferStatus := ""
transferPct := ""
if d.LocalDeal.DataTransfer != nil { if d.LocalDeal.DataTransfer != nil {
transferStatus = datatransfer.Statuses[d.LocalDeal.DataTransfer.Status] transferStatus = datatransfer.Statuses[d.LocalDeal.DataTransfer.Status]
// TODO: Include the transferred percentage once this bug is fixed: // Calculate transfer %
// https://github.com/ipfs/go-graphsync/issues/126 if d.LocalDeal.DataRef.RawBlockSize > 0 {
//fmt.Printf("transferred: %d / size: %d\n", d.LocalDeal.DataTransfer.Transferred, d.LocalDeal.Size) pct := (100 * d.LocalDeal.DataTransfer.Transferred) / d.LocalDeal.DataRef.RawBlockSize
//if d.LocalDeal.Size > 0 { transferPct = fmt.Sprintf("%d%%", pct)
// pct := (100 * d.LocalDeal.DataTransfer.Transferred) / d.LocalDeal.Size }
// transferPct = fmt.Sprintf("%d%%", pct)
//}
} }
fmt.Fprintf(w, "%s\t%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%s\t%s\t%v\t%s\n", fmt.Fprintf(w, "%s\t%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%s\t%s\t%s\t%v\t%s\n",
d.LocalDeal.CreationTime.Format(time.Stamp), d.LocalDeal.CreationTime.Format(time.Stamp),
d.LocalDeal.ProposalCid, d.LocalDeal.ProposalCid,
d.LocalDeal.DealID, d.LocalDeal.DealID,
@ -1609,6 +1609,7 @@ func outputStorageDeals(ctx context.Context, out io.Writer, full lapi.FullNode,
d.LocalDeal.Duration, d.LocalDeal.Duration,
transferChannelID, transferChannelID,
transferStatus, transferStatus,
transferPct,
d.LocalDeal.Verified, d.LocalDeal.Verified,
d.LocalDeal.Message) d.LocalDeal.Message)
} }

View File

@ -69,7 +69,6 @@ func RunClientTest(t *testing.T, cmds []*lcli.Command, clientNode test.TestNode)
dataCid2.String(), dataCid2.String(),
duration, duration,
minerAddr.String(), minerAddr.String(),
"no",
"yes", "yes",
} }
out = clientCLI.RunInteractiveCmd(cmd, interactiveCmds) out = clientCLI.RunInteractiveCmd(cmd, interactiveCmds)

View File

@ -643,7 +643,8 @@ Response:
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
}, },
"PieceCid": null, "PieceCid": null,
"PieceSize": 1024 "PieceSize": 1024,
"RawBlockSize": 42
}, },
"AvailableForRetrieval": true, "AvailableForRetrieval": true,
"DealID": 5432, "DealID": 5432,

View File

@ -930,6 +930,7 @@ Inputs:
Response: Response:
```json ```json
{ {
"RawBlockSize": 42,
"PayloadSize": 9, "PayloadSize": 9,
"PieceSize": 1032, "PieceSize": 1032,
"PieceCID": { "PieceCID": {
@ -1028,7 +1029,8 @@ Response:
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
}, },
"PieceCid": null, "PieceCid": null,
"PieceSize": 1024 "PieceSize": 1024,
"RawBlockSize": 42
}, },
"PieceCID": { "PieceCID": {
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
@ -1098,7 +1100,8 @@ Response:
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
}, },
"PieceCid": null, "PieceCid": null,
"PieceSize": 1024 "PieceSize": 1024,
"RawBlockSize": 42
}, },
"PieceCID": { "PieceCID": {
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
@ -1416,7 +1419,8 @@ Inputs:
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
}, },
"PieceCid": null, "PieceCid": null,
"PieceSize": 1024 "PieceSize": 1024,
"RawBlockSize": 42
}, },
"Wallet": "f01234", "Wallet": "f01234",
"Miner": "f01234", "Miner": "f01234",

2
go.mod
View File

@ -33,7 +33,7 @@ require (
github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03 github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03
github.com/filecoin-project/go-data-transfer v1.2.7 github.com/filecoin-project/go-data-transfer v1.2.7
github.com/filecoin-project/go-fil-commcid v0.0.0-20201016201715-d41df56b4f6a github.com/filecoin-project/go-fil-commcid v0.0.0-20201016201715-d41df56b4f6a
github.com/filecoin-project/go-fil-markets v1.1.7 github.com/filecoin-project/go-fil-markets v1.1.8
github.com/filecoin-project/go-jsonrpc v0.1.2 github.com/filecoin-project/go-jsonrpc v0.1.2
github.com/filecoin-project/go-multistore v0.0.3 github.com/filecoin-project/go-multistore v0.0.3
github.com/filecoin-project/go-padreader v0.0.0-20200903213702-ed5fae088b20 github.com/filecoin-project/go-padreader v0.0.0-20200903213702-ed5fae088b20

4
go.sum
View File

@ -269,8 +269,8 @@ github.com/filecoin-project/go-fil-commcid v0.0.0-20200716160307-8f644712406f/go
github.com/filecoin-project/go-fil-commcid v0.0.0-20201016201715-d41df56b4f6a h1:hyJ+pUm/4U4RdEZBlg6k8Ma4rDiuvqyGpoICXAxwsTg= github.com/filecoin-project/go-fil-commcid v0.0.0-20201016201715-d41df56b4f6a h1:hyJ+pUm/4U4RdEZBlg6k8Ma4rDiuvqyGpoICXAxwsTg=
github.com/filecoin-project/go-fil-commcid v0.0.0-20201016201715-d41df56b4f6a/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ= github.com/filecoin-project/go-fil-commcid v0.0.0-20201016201715-d41df56b4f6a/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ=
github.com/filecoin-project/go-fil-markets v1.0.5-0.20201113164554-c5eba40d5335/go.mod h1:AJySOJC00JRWEZzRG2KsfUnqEf5ITXxeX09BE9N4f9c= github.com/filecoin-project/go-fil-markets v1.0.5-0.20201113164554-c5eba40d5335/go.mod h1:AJySOJC00JRWEZzRG2KsfUnqEf5ITXxeX09BE9N4f9c=
github.com/filecoin-project/go-fil-markets v1.1.7 h1:7yy7alIDWzUxljxZhGmG3+wvaU4Ty5QDMbPmdZeaIJ8= github.com/filecoin-project/go-fil-markets v1.1.8 h1:rnb+9Did4sClxTUHDpzmf9WmTzL1wQsBSsUb9RQa4Rg=
github.com/filecoin-project/go-fil-markets v1.1.7/go.mod h1:6oTRaAsHnCqhi3mpZqdvnWIzH6QzHQc4dbhJrI9/BfQ= github.com/filecoin-project/go-fil-markets v1.1.8/go.mod h1:6oTRaAsHnCqhi3mpZqdvnWIzH6QzHQc4dbhJrI9/BfQ=
github.com/filecoin-project/go-hamt-ipld v0.1.5 h1:uoXrKbCQZ49OHpsTCkrThPNelC4W3LPEk0OrS/ytIBM= github.com/filecoin-project/go-hamt-ipld v0.1.5 h1:uoXrKbCQZ49OHpsTCkrThPNelC4W3LPEk0OrS/ytIBM=
github.com/filecoin-project/go-hamt-ipld v0.1.5/go.mod h1:6Is+ONR5Cd5R6XZoCse1CWaXZc0Hdb/JeX+EQCQzX24= github.com/filecoin-project/go-hamt-ipld v0.1.5/go.mod h1:6Is+ONR5Cd5R6XZoCse1CWaXZc0Hdb/JeX+EQCQzX24=
github.com/filecoin-project/go-hamt-ipld/v2 v2.0.0 h1:b3UDemBYN2HNfk3KOXNuxgTTxlWi3xVvbQP0IT38fvM= github.com/filecoin-project/go-hamt-ipld/v2 v2.0.0 h1:b3UDemBYN2HNfk3KOXNuxgTTxlWi3xVvbQP0IT38fvM=

View File

@ -755,7 +755,13 @@ func (a *API) ClientDealPieceCID(ctx context.Context, root cid.Cid) (api.DataCID
w := &writer.Writer{} w := &writer.Writer{}
bw := bufio.NewWriterSize(w, int(writer.CommPBuf)) bw := bufio.NewWriterSize(w, int(writer.CommPBuf))
err := car.WriteCar(ctx, dag, []cid.Cid{root}, w) // Calculate the raw block size so we can figure out the transfer percentage
// (the raw block size is the denominator)
var rawBlockSize uint64
err := car.WriteCarWithWalker(ctx, dag, []cid.Cid{root}, w, func(nd ipld.Node) ([]*ipld.Link, error) {
rawBlockSize += uint64(len(nd.RawData()))
return nd.Links(), nil
})
if err != nil { if err != nil {
return api.DataCIDSize{}, err return api.DataCIDSize{}, err
} }
@ -765,7 +771,12 @@ func (a *API) ClientDealPieceCID(ctx context.Context, root cid.Cid) (api.DataCID
} }
dataCIDSize, err := w.Sum() dataCIDSize, err := w.Sum()
return api.DataCIDSize(dataCIDSize), err return api.DataCIDSize{
RawBlockSize: rawBlockSize,
PayloadSize: dataCIDSize.PayloadSize,
PieceSize: dataCIDSize.PieceSize,
PieceCID: dataCIDSize.PieceCID,
}, err
} }
func (a *API) ClientGenCar(ctx context.Context, ref api.FileRef, outputPath string) error { func (a *API) ClientGenCar(ctx context.Context, ref api.FileRef, outputPath string) error {