Skip to content
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

[wip] sector import c1/pc1 out types #9300

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7cbeafa
sector import: Initial api scaffolding
magik6k Aug 24, 2022
f48cb67
sealing: Drop redundant Piece type
magik6k Aug 26, 2022
6f478ea
sector import: Check pieces in Sealing.Receive
magik6k Aug 26, 2022
d05a4f4
sealing: Validate piece alignment in checkPieces
magik6k Aug 26, 2022
3b28b5a
sector import: Fix missing perm tag on SectorReceive
magik6k Aug 26, 2022
feced5e
sector import: More check progress
magik6k Aug 30, 2022
c2dc2f9
sector import: Put the imported sector into the sealing pipeline
magik6k Aug 31, 2022
bb04b75
sector import: Plumbing for DownloadSectorData in the sealing system
magik6k Aug 31, 2022
8a0fb63
sector import: Sector data download
magik6k Aug 31, 2022
9678090
sector import: Fix tests
magik6k Sep 2, 2022
e5a87e4
sector import: Implement handleReceiveSector
magik6k Sep 2, 2022
513abb8
sector import: Update type-gen
magik6k Sep 2, 2022
4ba30a7
sector import: Initial SectorReceive itest
magik6k Sep 5, 2022
1fc3a68
sector import: Add missing initial fsm state transition
magik6k Sep 6, 2022
cd59831
sector import: Plumb sector download task canfig
magik6k Sep 6, 2022
b85b0a5
sector import: Seal with the correct proof type in saas itest
magik6k Sep 6, 2022
ad77284
sector import: FinalizeInto, send finalized cacde in itest
magik6k Sep 6, 2022
aaa154b
sector import: Remote Commit1
magik6k Sep 9, 2022
0e491ba
sector import: Test remote commit1 retry
magik6k Sep 9, 2022
b3c8282
sector import: Implement seed/ticket/commr/commd checks
magik6k Sep 9, 2022
fd7f543
sector import: Remote Commit2
magik6k Sep 9, 2022
7b0b5fb
tarutil: Strict header checks
magik6k Sep 9, 2022
09ab837
sector import: Fix test build
magik6k Sep 9, 2022
a0fa5ab
sector import: RemoteSealingDoneEndpoint
magik6k Sep 9, 2022
d4c2d14
sector import: Fix lint
magik6k Sep 9, 2022
a6995bb
wip sector import c1/pc1 out types
magik6k Sep 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
sector import: Fix test build
  • Loading branch information
magik6k committed Sep 9, 2022
commit 09ab83767d9acc7cf850096053f4f8455d396b0a
150 changes: 147 additions & 3 deletions itests/sector_import_full_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ package itests
import (
"bytes"
"context"
"encoding/json"
"fmt"
lminer "github.com/filecoin-project/lotus/chain/actors/builtin/miner"
"github.com/filecoin-project/lotus/chain/types"
spaths "github.com/filecoin-project/lotus/storage/paths"
"github.com/filecoin-project/lotus/storage/sealer/tarutil"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -39,7 +44,7 @@ func TestSectorImport(t *testing.T) {

makeTest := func(mut func(*testCase)) *testCase {
tc := &testCase{
c1handler: remoteCommit1,
c1handler: testRemoteCommit1,
}
mut(tc)
return tc
Expand Down Expand Up @@ -72,7 +77,11 @@ func TestSectorImport(t *testing.T) {
mid, err := address.IDFromAddress(maddr)
require.NoError(t, err)

spt, err := currentSealProof(ctx, client, maddr)
mi, err := client.StateMinerInfo(ctx, maddr, types.EmptyTSK)
require.NoError(t, err)
ver, err := client.StateNetworkVersion(ctx, types.EmptyTSK)
require.NoError(t, err)
spt, err := lminer.PreferredSealProofTypeFromWindowPoStType(ver, mi.WindowPoStProofType)
require.NoError(t, err)

ssize, err := spt.SectorSize()
Expand Down Expand Up @@ -141,8 +150,9 @@ func TestSectorImport(t *testing.T) {
// start http server serving sector data

m := mux.NewRouter()
m.HandleFunc("/sectors/{type}/{id}", remoteGetSector(sectorDir)).Methods("GET")
m.HandleFunc("/sectors/{type}/{id}", testRemoteGetSector(sectorDir)).Methods("GET")
m.HandleFunc("/sectors/{id}/commit1", tc.c1handler(sealer)).Methods("POST")
m.HandleFunc("/commit2", testRemoteCommit2(sealer)).Methods("POST")
srv := httptest.NewServer(m)

unsealedURL := fmt.Sprintf("%s/sectors/unsealed/s-t0%d-%d", srv.URL, mid, snum)
Expand Down Expand Up @@ -288,3 +298,137 @@ func TestSectorImport(t *testing.T) {
})))

}

// note: stuff below is almost the same as in _simple version of this file; We need
// to copy it because on Circle we can't call those functions between test files,
// and for the _simple test we want everything in one file to make it easy to follow

func testRemoteCommit1(s *ffiwrapper.Sealer) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)

// validate sector id
id, err := storiface.ParseSectorID(vars["id"])
if err != nil {
w.WriteHeader(500)
return
}

var params api.RemoteCommit1Params
if err := json.NewDecoder(r.Body).Decode(&params); err != nil {
w.WriteHeader(500)
return
}

sref := storiface.SectorRef{
ID: id,
ProofType: params.ProofType,
}

ssize, err := params.ProofType.SectorSize()
if err != nil {
w.WriteHeader(500)
return
}

p, err := s.SealCommit1(r.Context(), sref, params.Ticket, params.Seed, []abi.PieceInfo{
{
Size: abi.PaddedPieceSize(ssize),
PieceCID: params.Unsealed,
},
}, storiface.SectorCids{
Unsealed: params.Unsealed,
Sealed: params.Sealed,
})
if err != nil {
w.WriteHeader(500)
return
}

if _, err := w.Write(p); err != nil {
fmt.Println("c1 write error")
}
}
}

func testRemoteCommit2(s *ffiwrapper.Sealer) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
var params api.RemoteCommit2Params
if err := json.NewDecoder(r.Body).Decode(&params); err != nil {
w.WriteHeader(500)
return
}

sref := storiface.SectorRef{
ID: params.Sector,
ProofType: params.ProofType,
}

p, err := s.SealCommit2(r.Context(), sref, params.Commit1Out)
if err != nil {
fmt.Println("c2 error: ", err)
w.WriteHeader(500)
return
}

if _, err := w.Write(p); err != nil {
fmt.Println("c2 write error")
}
}
}

func testRemoteGetSector(sectorRoot string) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {

vars := mux.Vars(r)

// validate sector id
id, err := storiface.ParseSectorID(vars["id"])
if err != nil {
w.WriteHeader(500)
return
}

// validate type
_, err = spaths.FileTypeFromString(vars["type"])
if err != nil {
w.WriteHeader(500)
return
}

typ := vars["type"]
if typ == "cache" {
// if cache is requested, send the finalized cache we've created above
typ = "fin-cache"
}

path := filepath.Join(sectorRoot, typ, vars["id"])

stat, err := os.Stat(path)
if err != nil {
w.WriteHeader(500)
return
}

if stat.IsDir() {
if _, has := r.Header["Range"]; has {
w.WriteHeader(500)
return
}

w.Header().Set("Content-Type", "application/x-tar")
w.WriteHeader(200)

err := tarutil.TarDirectory(path, w, make([]byte, 1<<20))
if err != nil {
return
}
} else {
w.Header().Set("Content-Type", "application/octet-stream")
// will do a ranged read over the file at the given path if the caller has asked for a ranged read in the request headers.
http.ServeFile(w, r, path)
}

fmt.Printf("served sector file/dir, sectorID=%+v, fileType=%s, path=%s\n", id, vars["type"], path)
}
}
20 changes: 5 additions & 15 deletions itests/sector_import_simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ func TestSectorImportAfterPC2(t *testing.T) {
mid, err := address.IDFromAddress(maddr)
require.NoError(t, err)

spt, err := currentSealProof(ctx, client, maddr)
mi, err := client.StateMinerInfo(ctx, maddr, types.EmptyTSK)
require.NoError(t, err)
ver, err := client.StateNetworkVersion(ctx, types.EmptyTSK)
require.NoError(t, err)
spt, err := lminer.PreferredSealProofTypeFromWindowPoStType(ver, mi.WindowPoStProofType)
require.NoError(t, err)

ssize, err := spt.SectorSize()
Expand Down Expand Up @@ -316,17 +320,3 @@ func remoteGetSector(sectorRoot string) func(w http.ResponseWriter, r *http.Requ
fmt.Printf("served sector file/dir, sectorID=%+v, fileType=%s, path=%s\n", id, vars["type"], path)
}
}

func currentSealProof(ctx context.Context, api api.FullNode, maddr address.Address) (abi.RegisteredSealProof, error) {
mi, err := api.StateMinerInfo(ctx, maddr, types.EmptyTSK)
if err != nil {
return 0, err
}

ver, err := api.StateNetworkVersion(ctx, types.EmptyTSK)
if err != nil {
return 0, err
}

return lminer.PreferredSealProofTypeFromWindowPoStType(ver, mi.WindowPoStProofType)
}