-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix storage provider restart in publish stage #657
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package shared | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/ipfs/go-cid" | ||
"golang.org/x/xerrors" | ||
|
||
"github.com/filecoin-project/go-commp-utils/writer" | ||
commcid "github.com/filecoin-project/go-fil-commcid" | ||
commp "github.com/filecoin-project/go-fil-commp-hashhash" | ||
) | ||
|
||
func GenerateCommp(reader io.Reader, payloadSize uint64, targetSize uint64) (cid.Cid, error) { | ||
// dump the CARv1 payload of the CARv2 file to the Commp Writer and get back the CommP. | ||
w := &writer.Writer{} | ||
written, err := io.Copy(w, reader) | ||
if err != nil { | ||
return cid.Undef, xerrors.Errorf("failed to write to CommP writer: %w", err) | ||
} | ||
if written != int64(payloadSize) { | ||
return cid.Undef, xerrors.Errorf("number of bytes written to CommP writer %d not equal to the CARv1 payload size %d", written, payloadSize) | ||
} | ||
|
||
cidAndSize, err := w.Sum() | ||
if err != nil { | ||
return cid.Undef, xerrors.Errorf("failed to get CommP: %w", err) | ||
} | ||
|
||
if uint64(cidAndSize.PieceSize) < targetSize { | ||
// need to pad up! | ||
rawPaddedCommp, err := commp.PadCommP( | ||
// we know how long a pieceCid "hash" is, just blindly extract the trailing 32 bytes | ||
cidAndSize.PieceCID.Hash()[len(cidAndSize.PieceCID.Hash())-32:], | ||
uint64(cidAndSize.PieceSize), | ||
uint64(targetSize), | ||
) | ||
if err != nil { | ||
return cid.Undef, err | ||
} | ||
cidAndSize.PieceCID, _ = commcid.DataCommitmentV1ToCID(rawPaddedCommp) | ||
} | ||
|
||
return cidAndSize.PieceCID, err | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ package storageimpl | |
|
||
import ( | ||
"context" | ||
"io" | ||
"os" | ||
|
||
"github.com/ipfs/go-cid" | ||
|
@@ -12,13 +11,11 @@ import ( | |
"golang.org/x/xerrors" | ||
|
||
"github.com/filecoin-project/go-address" | ||
"github.com/filecoin-project/go-commp-utils/writer" | ||
commcid "github.com/filecoin-project/go-fil-commcid" | ||
commp "github.com/filecoin-project/go-fil-commp-hashhash" | ||
"github.com/filecoin-project/go-state-types/abi" | ||
|
||
"github.com/filecoin-project/go-fil-markets/filestore" | ||
"github.com/filecoin-project/go-fil-markets/piecestore" | ||
"github.com/filecoin-project/go-fil-markets/shared" | ||
"github.com/filecoin-project/go-fil-markets/storagemarket" | ||
"github.com/filecoin-project/go-fil-markets/storagemarket/impl/providerstates" | ||
"github.com/filecoin-project/go-fil-markets/storagemarket/network" | ||
|
@@ -44,6 +41,10 @@ func (p *providerDealEnvironment) ReadCAR(path string) (*carv2.Reader, error) { | |
func (p *providerDealEnvironment) FinalizeBlockstore(proposalCid cid.Cid) error { | ||
bs, err := p.p.stores.Get(proposalCid.String()) | ||
if err != nil { | ||
if xerrors.Is(err, stores.ErrNotFound) { | ||
// The blockstore has already been cleaned up | ||
return nil | ||
} | ||
return xerrors.Errorf("failed to get read/write blockstore: %w", err) | ||
} | ||
|
||
|
@@ -107,36 +108,8 @@ func (p *providerDealEnvironment) GeneratePieceCommitment(proposalCid cid.Cid, c | |
} | ||
}() | ||
|
||
// dump the CARv1 payload of the CARv2 file to the Commp Writer and get back the CommP. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved this code to its own file so it can be used from the test - no logical changes |
||
w := &writer.Writer{} | ||
written, err := io.Copy(w, rd.DataReader()) | ||
if err != nil { | ||
return cid.Undef, "", xerrors.Errorf("failed to write to CommP writer: %w", err) | ||
} | ||
if written != int64(rd.Header.DataSize) { | ||
return cid.Undef, "", xerrors.Errorf("number of bytes written to CommP writer %d not equal to the CARv1 payload size %d", written, rd.Header.DataSize) | ||
} | ||
|
||
cidAndSize, err := w.Sum() | ||
if err != nil { | ||
return cid.Undef, "", xerrors.Errorf("failed to get CommP: %w", err) | ||
} | ||
|
||
if cidAndSize.PieceSize < dealSize { | ||
// need to pad up! | ||
rawPaddedCommp, err := commp.PadCommP( | ||
// we know how long a pieceCid "hash" is, just blindly extract the trailing 32 bytes | ||
cidAndSize.PieceCID.Hash()[len(cidAndSize.PieceCID.Hash())-32:], | ||
uint64(cidAndSize.PieceSize), | ||
uint64(dealSize), | ||
) | ||
if err != nil { | ||
return cid.Undef, "", err | ||
} | ||
cidAndSize.PieceCID, _ = commcid.DataCommitmentV1ToCID(rawPaddedCommp) | ||
} | ||
|
||
return cidAndSize.PieceCID, filestore.Path(""), err | ||
pieceCID, err := shared.GenerateCommp(rd.DataReader(), rd.Header.DataSize, uint64(dealSize)) | ||
return pieceCID, "", err | ||
} | ||
|
||
func (p *providerDealEnvironment) FileStore() filestore.FileStore { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ package testnodes | |
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"io/ioutil" | ||
"sync" | ||
"testing" | ||
|
@@ -340,6 +341,7 @@ type FakeProviderNode struct { | |
PublishDealsError error | ||
WaitForPublishDealsError error | ||
OnDealCompleteError error | ||
OnDealCompleteSkipCommP bool | ||
LastOnDealCompleteBytes []byte | ||
OnDealCompleteCalls []storagemarket.MinerDeal | ||
LocatePieceForDealWithinSectorError error | ||
|
@@ -380,7 +382,28 @@ func (n *FakeProviderNode) WaitForPublishDeals(ctx context.Context, mcid cid.Cid | |
func (n *FakeProviderNode) OnDealComplete(ctx context.Context, deal storagemarket.MinerDeal, pieceSize abi.UnpaddedPieceSize, pieceReader shared.ReadSeekStarter) (*storagemarket.PackingResult, error) { | ||
n.OnDealCompleteCalls = append(n.OnDealCompleteCalls, deal) | ||
n.LastOnDealCompleteBytes, _ = ioutil.ReadAll(pieceReader) | ||
// TODO: probably need to return some mock value here | ||
|
||
if n.OnDealCompleteError != nil || n.OnDealCompleteSkipCommP { | ||
return &storagemarket.PackingResult{}, n.OnDealCompleteError | ||
} | ||
|
||
// We read in all the bytes from the reader above, so seek back to the start | ||
err := pieceReader.SeekStart() | ||
if err != nil { | ||
return nil, fmt.Errorf("on deal complete: seeking to start of piece data: %w", err) | ||
} | ||
|
||
// Generate commP | ||
pieceCID, err := shared.GenerateCommp(pieceReader, uint64(pieceSize), uint64(pieceSize)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added commp generation to the test so if the data is bad the test will fail |
||
if err != nil { | ||
return nil, fmt.Errorf("on deal complete: generating commp: %w", err) | ||
} | ||
|
||
// Check that commP of the data matches the proposal piece CID | ||
if pieceCID != deal.Proposal.PieceCID { | ||
return nil, fmt.Errorf("on deal complete: proposal piece CID %s does not match calculated commP %s", deal.Proposal.PieceCID, pieceCID) | ||
} | ||
|
||
return &storagemarket.PackingResult{}, n.OnDealCompleteError | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This piece of code was causing the problem - we shouldn't need to do this as stores.GetOrOpen() will be called lazily