export

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ExportsCmd = &cli.Command{
	Name:      "export",
	Usage:     "Export sector metadata",
	ArgsUsage: "[sectorNum1 sectorNum2 ...]",
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:     "miner",
			Usage:    "Filecoin Miner. Such as: f01000",
			Required: true,
		},
	},
	Action: func(cctx *cli.Context) error {
		ctx := cliutil.ReqContext(cctx)
		start := time.Now()

		if cctx.Args().Len() < 1 {
			return fmt.Errorf("at least one sector must be specified")
		}

		runSectors := make([]uint64, 0)
		for _, sn := range cctx.Args().Slice() {
			sectorNum, err := strconv.ParseUint(sn, 10, 64)
			if err != nil {
				return fmt.Errorf("could not parse sector number: %w", err)
			}
			runSectors = append(runSectors, sectorNum)
		}

		maddr, err := address.NewFromString(cctx.String("miner"))
		if err != nil {
			return xerrors.Errorf("Getting NewFromString err:", err)
		}

		fullNodeApi, closer, err := cliutil.GetFullNodeAPI(cctx)
		if err != nil {
			return xerrors.Errorf("Getting FullNodeAPI err:", err)
		}
		defer closer()

		mi, err := fullNodeApi.StateMinerInfo(ctx, maddr, types.EmptyTSK)
		if err != nil {
			return xerrors.Errorf("Getting StateMinerInfo err:", err)
		}

		output := &RecoveryParams{
			Miner:      maddr,
			SectorSize: mi.SectorSize,
		}
		sectorInfos := make(SectorInfos, 0)
		failtSectors := make([]uint64, 0)
		for _, sector := range runSectors {
			ts, sectorPreCommitOnChainInfo, err := GetSectorCommitInfoOnChain(ctx, fullNodeApi, maddr, abi.SectorNumber(sector))
			if err != nil {
				log.Errorf("Getting sector (%d) precommit info error: %v ", sector, err)
				continue
			}
			si := &SectorInfo{
				SectorNumber: abi.SectorNumber(sector),
				SealProof:    sectorPreCommitOnChainInfo.Info.SealProof,
				SealedCID:    sectorPreCommitOnChainInfo.Info.SealedCID,
			}

			ticket, err := GetSectorTicketOnChain(ctx, fullNodeApi, maddr, ts, sectorPreCommitOnChainInfo)
			if err != nil {
				log.Errorf("Getting sector (%d) ticket error: %v ", sector, err)
				continue
			}
			si.Ticket = ticket

			sectorInfos = append(sectorInfos, si)
			output.SectorInfos = sectorInfos

			out, err := json.MarshalIndent(output, "", "\t")
			if err != nil {
				return err
			}

			of, err := homedir.Expand("sectors-recovery-" + maddr.String() + ".json")
			if err != nil {
				return err
			}

			if err := ioutil.WriteFile(of, out, 0644); err != nil {
				return err
			}
		}

		end := time.Now()
		fmt.Println("export", len(sectorInfos), "sectors, failt sectors:", failtSectors, ", elapsed:", end.Sub(start))

		return nil
	},
}

Functions

func GetSectorCommitInfoOnChain

func GetSectorCommitInfoOnChain(ctx context.Context, fullNodeApi v0api.FullNode, maddr address.Address, sid abi.SectorNumber) (*types.TipSet, *miner.SectorPreCommitOnChainInfo, error)

func GetSectorTicketOnChain

func GetSectorTicketOnChain(ctx context.Context, fullNodeApi v0api.FullNode, maddr address.Address, ts *types.TipSet, preCommitInfo *miner.SectorPreCommitOnChainInfo) (abi.Randomness, error)

Types

type RecoveryParams

type RecoveryParams struct {
	Miner       address.Address
	SectorSize  abi.SectorSize
	SectorInfos SectorInfos
}

type SectorInfo

type SectorInfo struct {
	SectorNumber abi.SectorNumber
	Ticket       abi.Randomness
	SealProof    abi.RegisteredSealProof
	SealedCID    cid.Cid
}

type SectorInfos

type SectorInfos []*SectorInfo

func (SectorInfos) Len

func (t SectorInfos) Len() int

func (SectorInfos) Less

func (t SectorInfos) Less(i, j int) bool

func (SectorInfos) Swap

func (t SectorInfos) Swap(i, j int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL