Documentation ¶
Index ¶
- Variables
- func Execute()
- type DAG
- type Datastore
- type SealedSectorMetadataOrder
- type SectorBuilder
- type SimpleSectorBuilder
- func (sb *SimpleSectorBuilder) AddPiece(ctx context.Context, minerAddr address.Address, pieceRef cid.Cid, ...) (sectorID uint64, err error)
- func (sb *SimpleSectorBuilder) Close()
- func (sb *SimpleSectorBuilder) GeneratePoSt(minerAddr address.Address, r sectorbuilder.GeneratePoStRequest) (sectorbuilder.GeneratePoStResponse, error)
- func (sb *SimpleSectorBuilder) SealAllStagedUnsealedSectors()
Constants ¶
This section is empty.
Variables ¶
View Source
var AddressCmd = &cobra.Command{
Use: "address",
Short: "Commands for filecoin address",
Long: "",
}
View Source
var AddressParseCmd = &cobra.Command{ Use: "parse", Short: "Parse and show parts of filecoin address", Long: "", Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { addr, err := address.NewFromString(args[0]) if err != nil { fmt.Println(err) os.Exit(1) } var network string if string(args[0][0]) == address.MainnetPrefix { network = "Mainnet" } else { network = "Testnet" } var protocol string switch addr.Protocol() { case address.ID: protocol = "ID" case address.SECP256K1: protocol = "SECP256K1" case address.Actor: protocol = "Actor" case address.BLS: protocol = "BLS" } payload := hex.EncodeToString(addr.Payload()) fmt.Printf("Address: %s\n", args[0]) fmt.Printf(" network: %s, protocol: %s, payload: %s", network, protocol, payload) var addrStr string if addr.Protocol() != address.ID { checksum := address.Checksum(append([]byte{addr.Protocol()}, addr.Payload()...)) fmt.Printf(", checksum: %s", hex.EncodeToString(checksum)) addrStr = string(args[0][0]) + fmt.Sprintf("%d", addr.Protocol()) + address.AddressEncoding.WithPadding(-1).EncodeToString(append(addr.Payload(), checksum[:]...)) } else { id := leb128.ToUInt64(addr.Payload()) fmt.Printf("\n ID: %d", id) addrStr = string(args[0][0]) + fmt.Sprintf("%d", addr.Protocol()) + fmt.Sprintf("%d", leb128.ToUInt64(addr.Payload())) } if addrStr != args[0] { panic("invalid address") } fmt.Println() }, }
View Source
var CidCmd = &cobra.Command{
Use: "cid",
Short: "Commands for CID (Content Identifier)",
Long: "",
}
View Source
var CidParseCmd = &cobra.Command{ Use: "parse", Short: "Parse and show parts of cid", Long: "", Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { v := args[0] c, err := cid.Decode(v) if err != nil { fmt.Println(err) os.Exit(1) } p := c.Prefix() if len(v) == 46 && v[:2] == "Qm" { fmt.Printf("CIDv0: %s\n", v) fmt.Printf(" multihash: %s-%d-%s\n (implicitly: base58btc, cidv0, protobuf)", multihash.Codes[p.MhType], p.MhLength, c.Hash()) } else { fmt.Printf("CIDv1: %s\n", v) base, _, _ := mbase.Decode(v) hash, _ := multihash.Decode(c.Hash()) fmt.Printf(" multibase: %s, cid-version: cidv%d, multicodec: %s, multihash: %s-%d-%s\n", strings.ToLower(multibaseNames[base]), p.Version, cid.CodecToStr[p.Codec], multihash.Codes[p.MhType], 8*p.MhLength, hex.EncodeToString(hash.Digest)) } }, }
View Source
var InitCmd = &cobra.Command{ Use: "init", Short: "Initialize a filutil directory", Long: "", Run: func(cmd *cobra.Command, args []string) { var err error defer func() { if err != nil { fmt.Println(err) os.Exit(1) } }() filutilDir := getFilutilDir() err = repo.EnsureWritableDirectory(filutilDir) if err != nil { return } empty, err := repo.IsEmptyDir(filutilDir) if err != nil { err = errors.Wrapf(err, "failed to list filutil directory %s", filutilDir) return } if !empty { err = fmt.Errorf("refusing to initialize filutil in non-empty directory %s", filutilDir) return } dag := openSectorBuilderPiecesDAG() defer dag.Close() datastore := openMetaDatastore() defer datastore.Close() }, }
View Source
var IpldCmd = &cobra.Command{
Use: "ipld",
Short: "Commands for IPLD (InterPlanetary Linked Data)",
Long: "IPLD is a set of standards and implementations for creating decentralized data-structures that are universally addressable and linkable.",
}
View Source
var KeystoreCmd = &cobra.Command{
Use: "keystore",
Short: "Commands for filecoin keystore",
Long: "",
}
View Source
var KeystoreLsCmd = &cobra.Command{ Use: "ls", Short: "List keys in filecoin keystore", Long: "", Run: func(cmd *cobra.Command, args []string) { var err error defer func() { if err != nil { fmt.Println(err) os.Exit(1) } }() repoDir, err := paths.GetRepoPath(repoDir) if err != nil { return } ksp := filepath.Join(repoDir, "keystore") ks, err := keystore.NewFSKeystore(ksp) if err != nil { return } identifiers, err := ks.List() if err != nil { return } for _, id := range identifiers { var privKey crypto.PrivKey privKey, err = ks.Get(id) if err != nil { return } t := privKey.Type() var pv, pb []byte pv, err = privKey.Raw() if err != nil { return } pb, err = privKey.GetPublic().Raw() if err != nil { return } fmt.Printf("%s: %s %s, %s %s, %s %s\n", red(id), blue("type"), t, blue("private key"), hex.EncodeToString(pv), blue("public key"), hex.EncodeToString(pb)) } }, }
View Source
var SectorBuilderAddPieceCmd = &cobra.Command{ Use: "add-piece <file>", Short: "Add piece", Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { filename := args[0] file, err := os.Open(filename) if err != nil { panic(err) } defer file.Close() dag := openSectorBuilderPiecesDAG() defer dag.Close() ds := openMetaDatastore() nd, err := dag.dag.ImportData(context.Background(), file) if err != nil { panic(err) } err = ds.Put(makeKey(metaSectorBuilderPiecePrefix, nd.Cid().String()), nil) if err != nil { return } ds.Close() sb := openSectorBuilder() defer sb.Close() r, err := dag.dag.Cat(context.Background(), nd.Cid()) if err != nil { return } t := time.Now() sectorID, err := sb.AddPiece(context.Background(), nd.Cid(), r.Size(), r) if err != nil { panic(err) } fmt.Printf("Added piece %s into staging sector %d, took %v\n", nd.Cid(), sectorID, time.Since(t)) sb.SealAllStagedUnsealedSectors() }, }
View Source
var SectorBuilderCmd = &cobra.Command{
Use: "sector-builder",
Short: "Commands for filecoin sector builder",
}
View Source
var SectorBuilderGenPieceCmd = &cobra.Command{ Use: "generate-piece <file>", Short: "Generate piece", Run: func(cmd *cobra.Command, args []string) { sb := openSectorBuilder() defer sb.Close() for i := 0; i < pieceNum; i++ { pieceData := make([]byte, sb.MaxBytesPerSector.Uint64()) _, err := io.ReadFull(rand.Reader, pieceData) if err != nil { panic(err) } data := merkledag.NewRawNode(pieceData) t := time.Now() sectorID, err := sb.AddPiece(context.Background(), data.Cid(), uint64(len(pieceData)), bytes.NewReader(pieceData)) if err != nil { panic(err) } fmt.Printf("Generate and add piece %s with size %d into staging sector %d, took %v\n", data.Cid(), len(pieceData), sectorID, time.Since(t)) } sb.SealAllStagedUnsealedSectors() }, }
View Source
var SectorBuilderGetPiecesCmd = &cobra.Command{ Use: "get-piece <cid> <file>", Short: "Get piece and save into file", Args: cobra.RangeArgs(1, 2), Run: func(cmd *cobra.Command, args []string) { var err error defer func() { if err != nil { fmt.Println(err) os.Exit(1) } }() dag := openSectorBuilderPiecesDAG() defer dag.Close() c, err := cid.Parse(args[0]) if err != nil { return } r, err := dag.dag.Cat(context.Background(), c) if err != nil { return } filename := args[0] if len(args) == 2 { filename = args[1] } f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) if err != nil { return } n, err := io.Copy(f, r) if err == nil && uint64(n) < r.Size() { err = io.ErrShortWrite } if err1 := f.Close(); err == nil { err = err1 } }, }
View Source
var SectorBuilderLsPiecesCmd = &cobra.Command{ Use: "ls-pieces", Short: "List all pieces", Run: func(cmd *cobra.Command, args []string) { var err error defer func() { if err != nil { fmt.Println(err) os.Exit(1) } }() ds := openMetaDatastore() defer ds.Close() dag := openSectorBuilderPiecesDAG() defer dag.Close() result, err := ds.Query(query.Query{ Prefix: metaSectorBuilderPiecePrefix, KeysOnly: true, }) if err != nil { return } for entry := range result.Next() { err = entry.Error if err != nil { return } var c cid.Cid c, err = cid.Parse(strings.TrimLeft(entry.Key, metaSectorBuilderPiecePrefix+"/")) r, err := dag.dag.Cat(context.Background(), c) if err != nil { return } var node format.Node node, err = dag.dagService.Get(context.Background(), c) if err != nil { return } err = traverseNode(dag.dagService, node, 0, func(node format.Node, depth int) error { stat, err := node.Stat() if err != nil { return err } s := fmt.Sprintf("data size: %d, links: %d, cumulative size: %d", stat.DataSize, stat.NumLinks, stat.CumulativeSize) if depth == 0 { fmt.Printf("Piece: %s, %s, original data size: %d\n", blue(node.Cid().String()), s, r.Size()) } else { fmt.Printf("%s%s, %s\n", strings.Repeat(" ", depth), red(node.Cid().String()), s) } return nil }) if err != nil { return } } fmt.Println("Note: data size is node contained bytes (greater than the original data size), cumulative size is node size plus its all children size.") }, }
View Source
var SectorBuilderLsSectorsCmd = &cobra.Command{ Use: "ls-sectors", Short: "List all sectors", Run: func(cmd *cobra.Command, args []string) { sb := openSectorBuilder() defer sb.Close() fmt.Println(green("Staged sectors:")) allStaged, err := sb.GetAllStagedSectors() if err != nil { panic(err) } for _, s := range allStaged { fmt.Printf(" Sector %d\n", s.SectorID) } fmt.Println(green("Sealed sectors:")) allSealed := getSealedSectorMetadataList(sb.MetaStore) for _, s := range allSealed { fmt.Printf(" Sector %d\n", s.SectorID) for _, p := range s.Pieces { fmt.Printf(" Piece %s, size %d\n", cyan(p.Ref), p.Size) } } }, }
View Source
var SectorBuilderSealSectorsCmd = &cobra.Command{ Use: "seal-sectors", Short: "Seal all staged sectors", Run: func(cmd *cobra.Command, args []string) { sb := openSectorBuilder() defer sb.Close() sb.SealAllStagedUnsealedSectors() }, }
View Source
var SectorBuilderVerifySectorsPorepCmd = &cobra.Command{ Use: "verify-sectors-porep", Short: "Verify PoRep (Proof-of-Replication) of all sealed sectors", Run: func(cmd *cobra.Command, args []string) { sb := openSectorBuilder() defer sb.Close() allSealed := getSealedSectorMetadataList(sb.MetaStore) var sectorIDs []string for _, s := range allSealed { sectorIDs = append(sectorIDs, fmt.Sprint(s.SectorID)) } fmt.Printf("All sealed sectors: [%s]\n", blue(strings.Join(sectorIDs, ", "))) for _, s := range allSealed { fmt.Printf("Verify sector %d: ", s.SectorID) t := time.Now() res, err := (&verification.RustVerifier{}).VerifySeal(verification.VerifySealRequest{ CommD: s.CommD, CommR: s.CommR, CommRStar: s.CommRStar, Proof: s.Proof, ProverID: sectorbuilder.AddressToProverID(minerAddr), SectorID: s.SectorID, SectorSize: types.TwoHundredFiftySixMiBSectorSize, }) if err != nil { fmt.Printf("error %s", red(err)) } else if !res.IsValid { fmt.Print(red("invalid")) } else { fmt.Print("valid") } fmt.Printf(", took %v\n", time.Since(t)) } }, }
View Source
var SectorBuilderVerifySectorsPostCmd = &cobra.Command{ Use: "verify-sectors-post", Short: "Challenge and verify PoSt (Proof-of-Spacetime) of all sealed sectors", Run: func(cmd *cobra.Command, args []string) { var challengeSeed types.PoStChallengeSeed _, err := io.ReadFull(rand.Reader, challengeSeed[:]) if err != nil { panic(err) } fmt.Printf("Use challenge seed: %s\n", hex.EncodeToString(challengeSeed[:])) sb := openSectorBuilder() defer sb.Close() allSealed := getSealedSectorMetadataList(sb.MetaStore) var sectorInfos []go_sectorbuilder.SectorInfo var sectorIDs []string for _, s := range allSealed { sectorInfos = append(sectorInfos, go_sectorbuilder.SectorInfo{ SectorID: s.SectorID, CommR: s.CommR, }) sectorIDs = append(sectorIDs, fmt.Sprint(s.SectorID)) } sortedSectorInfo := go_sectorbuilder.NewSortedSectorInfo(sectorInfos...) fmt.Println("Generate PoSt ...") t := time.Now() gres, err := sb.GeneratePoSt(sectorbuilder.GeneratePoStRequest{ SortedSectorInfo: sortedSectorInfo, ChallengeSeed: challengeSeed, }) if err != nil { panic(err) } fmt.Printf(" sectors: [%s]\n", blue(strings.Join(sectorIDs, ", "))) fmt.Printf(" proof %s, took %v\n", hex.EncodeToString(gres.Proof), time.Since(t)) fmt.Println("Verify PoSt ...") t = time.Now() vres, err := (&verification.RustVerifier{}).VerifyPoSt(verification.VerifyPoStRequest{ ChallengeSeed: challengeSeed, SortedSectorInfo: sortedSectorInfo, Faults: []uint64{}, Proof: gres.Proof, SectorSize: types.TwoHundredFiftySixMiBSectorSize, }) if err != nil { panic(err) } if !vres.IsValid { fmt.Print(red(" invalid")) } else { fmt.Print(" valid") } fmt.Printf(", took %v\n", time.Since(t)) }, }
View Source
var SimpleSectorBuilderAddPieceCmd = &cobra.Command{ Use: "add-piece <file>", Short: "Add piece", Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { filename := args[0] file, err := os.Open(filename) if err != nil { panic(err) } defer file.Close() dag := openSectorBuilderPiecesDAG() defer dag.Close() ds := openMetaDatastore() nd, err := dag.dag.ImportData(context.Background(), file) if err != nil { panic(err) } err = ds.Put(makeKey(metaSectorBuilderPiecePrefix, nd.Cid().String()), nil) if err != nil { return } ds.Close() sb := openSimpleSectorBuilder() defer sb.Close() r, err := dag.dag.Cat(context.Background(), nd.Cid()) if err != nil { return } t := time.Now() sectorID, err := sb.AddPiece(context.Background(), minerAddr, nd.Cid(), r.Size(), r) if err != nil { panic(err) } fmt.Printf("Added piece %s into staging sector %d, took %v\n", nd.Cid(), sectorID, time.Since(t)) }, }
View Source
var SimpleSectorBuilderCmd = &cobra.Command{
Use: "simple-sector-builder",
Short: "Commands for filecoin simple sector builder",
}
View Source
var SimpleSectorBuilderGenPieceCmd = &cobra.Command{ Use: "generate-piece <file>", Short: "Generate piece", Run: func(cmd *cobra.Command, args []string) { sb := openSimpleSectorBuilder() defer sb.Close() for i := 0; i < simplePieceNum; i++ { pieceData := make([]byte, sb.MaxBytesPerSector.Uint64()) _, err := io.ReadFull(rand.Reader, pieceData) if err != nil { panic(err) } data := merkledag.NewRawNode(pieceData) t := time.Now() sectorID, err := sb.AddPiece(context.Background(), minerAddr, data.Cid(), uint64(len(pieceData)), bytes.NewReader(pieceData)) if err != nil { panic(err) } fmt.Printf("Generate and add piece %s with size %d into staging sector %d, took %v\n", data.Cid(), len(pieceData), sectorID, time.Since(t)) } }, }
View Source
var SimpleSectorBuilderGetPiecesCmd = &cobra.Command{ Use: "get-piece <cid> <file>", Short: "Get piece and save into file", Args: cobra.RangeArgs(1, 2), Run: func(cmd *cobra.Command, args []string) { SectorBuilderGetPiecesCmd.Run(cmd, args) var err error defer func() { if err != nil { fmt.Println(err) os.Exit(1) } }() }, }
View Source
var SimpleSectorBuilderLsPiecesCmd = &cobra.Command{ Use: "ls-pieces", Short: "List all pieces", Run: func(cmd *cobra.Command, args []string) { SectorBuilderLsPiecesCmd.Run(cmd, args) }, }
View Source
var SimpleSectorBuilderLsSectorsCmd = &cobra.Command{ Use: "ls-sectors", Short: "List all sectors", Run: func(cmd *cobra.Command, args []string) { sb := openSimpleSectorBuilder() defer sb.Close() fmt.Println(green("Staged sectors:")) stagedMap, _ := sb.sectorManager.GetStaged(minerAddr) if len(stagedMap) > 0 { for id := range stagedMap { fmt.Printf(" Sector %d\n", id) } } fmt.Println(green("Sealed sectors:")) sealedMap, _ := sb.sectorManager.GetSealed(minerAddr) if len(sealedMap) > 0 { for id, sector := range sealedMap { fmt.Printf(" Sector %d\n", id) for _, p := range sector.Pieces { fmt.Printf(" Piece %s, size %d\n", cyan(p.Key), p.Size) } } } }, }
View Source
var SimpleSectorBuilderSealSectorsCmd = &cobra.Command{ Use: "seal-sectors", Short: "Seal all staged sectors", Run: func(cmd *cobra.Command, args []string) { sb := openSimpleSectorBuilder() defer sb.Close() sb.SealAllStagedUnsealedSectors() }, }
View Source
var SimpleSectorBuilderVerifySectorsPorepCmd = &cobra.Command{ Use: "verify-sectors-porep", Short: "Verify PoRep (Proof-of-Replication) of all sealed sectors", Run: func(cmd *cobra.Command, args []string) { sb := openSimpleSectorBuilder() defer sb.Close() sealedMap, _ := sb.sectorManager.GetSealed(minerAddr) var sealedSectorIDs []string if len(sealedMap) > 0 { for id := range sealedMap { sealedSectorIDs = append(sealedSectorIDs, fmt.Sprint(id)) } } fmt.Printf("All sealed sectors: [%s]\n", blue(strings.Join(sealedSectorIDs, ", "))) if len(sealedMap) == 0 { return } for _, s := range sealedMap { fmt.Printf("Verify sector %d: ", s.SectorID) t := time.Now() res, err := (&verification.RustVerifier{}).VerifySeal(verification.VerifySealRequest{ CommD: s.CommD, CommR: s.CommR, CommRStar: s.CommRStar, Proof: s.Proof, ProverID: sectorbuilder.AddressToProverID(minerAddr), SectorID: s.SectorID, SectorSize: types.TwoHundredFiftySixMiBSectorSize, }) if err != nil { fmt.Printf("error %s", red(err)) } else if !res.IsValid { fmt.Print(red("invalid")) } else { fmt.Print("valid") } fmt.Printf(", took %v\n", time.Since(t)) } }, }
View Source
var SimpleSectorBuilderVerifySectorsPostCmd = &cobra.Command{ Use: "verify-sectors-post", Short: "Challenge and verify PoSt (Proof-of-Spacetime) of all sealed sectors", Run: func(cmd *cobra.Command, args []string) { var challengeSeed types.PoStChallengeSeed _, err := io.ReadFull(rand.Reader, challengeSeed[:]) if err != nil { panic(err) } fmt.Printf("Use challenge seed: %s\n", hex.EncodeToString(challengeSeed[:])) sb := openSimpleSectorBuilder() defer sb.Close() sealedMap, _ := sb.sectorManager.GetSealed(minerAddr) var sectorInfos []go_sectorbuilder.SectorInfo var sealedSectorIDs []string if len(sealedMap) > 0 { for id, s := range sealedMap { sectorInfos = append(sectorInfos, go_sectorbuilder.SectorInfo{ SectorID: s.SectorID, CommR: s.CommR, }) sealedSectorIDs = append(sealedSectorIDs, fmt.Sprint(id)) } } sortedSectorInfo := go_sectorbuilder.NewSortedSectorInfo(sectorInfos...) fmt.Println("Generate PoSt ...") t := time.Now() gres, err := sb.GeneratePoSt(minerAddr, sectorbuilder.GeneratePoStRequest{ SortedSectorInfo: sortedSectorInfo, ChallengeSeed: challengeSeed, }) if err != nil { panic(err) } fmt.Printf(" sectors: [%s]\n", blue(strings.Join(sealedSectorIDs, ", "))) fmt.Printf(" proof %s, took %v\n", hex.EncodeToString(gres.Proof), time.Since(t)) fmt.Println("Verify PoSt ...") t = time.Now() vres, err := (&verification.RustVerifier{}).VerifyPoSt(verification.VerifyPoStRequest{ ChallengeSeed: challengeSeed, SortedSectorInfo: sortedSectorInfo, Faults: []uint64{}, Proof: gres.Proof, SectorSize: types.TwoHundredFiftySixMiBSectorSize, }) if err != nil { panic(err) } if !vres.IsValid { fmt.Print(red(" invalid")) } else { fmt.Print(" valid") } fmt.Printf(", took %v\n", time.Since(t)) }, }
Functions ¶
Types ¶
type SealedSectorMetadataOrder ¶
type SealedSectorMetadataOrder struct { }
type SectorBuilder ¶
type SectorBuilder struct { sectorbuilder.SectorBuilder MetaStore *Datastore MaxBytesPerSector *types.BytesAmount }
func (*SectorBuilder) Close ¶
func (sb *SectorBuilder) Close()
func (*SectorBuilder) HandleSectorSealResult ¶
func (sb *SectorBuilder) HandleSectorSealResult(r *sectorbuilder.SectorSealResult, startAt time.Time)
func (*SectorBuilder) SealAllStagedUnsealedSectors ¶
func (sb *SectorBuilder) SealAllStagedUnsealedSectors()
type SimpleSectorBuilder ¶
type SimpleSectorBuilder struct { MetaStore *Datastore MaxBytesPerSector *types.BytesAmount // contains filtered or unexported fields }
func (*SimpleSectorBuilder) Close ¶
func (sb *SimpleSectorBuilder) Close()
func (*SimpleSectorBuilder) GeneratePoSt ¶
func (sb *SimpleSectorBuilder) GeneratePoSt(minerAddr address.Address, r sectorbuilder.GeneratePoStRequest) (sectorbuilder.GeneratePoStResponse, error)
func (*SimpleSectorBuilder) SealAllStagedUnsealedSectors ¶
func (sb *SimpleSectorBuilder) SealAllStagedUnsealedSectors()
Click to show internal directories.
Click to hide internal directories.