wrapper

package module
v0.0.0-...-8967377 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULTSECTORNAME = "sector.dat"
	DEFAULTSECTORMODE = 0644

	DEFAULTSTAGEDNAME = "staged.dat"
	DEFAULTSTAGEDMODE = 0644

	DEFAULTCACHENAME = "cache"
	DEFAULTCACHEMODE = 0755
)
View Source
const RANDBUFLEN = 32

RANDBUFLEN is the length of random bytes

Variables

This section is empty.

Functions

func CreateFakeDataFile

func CreateFakeDataFile(path string, size uint64) error

CreateFakeDataFile used for test purpose only

func UnpaddedSpace

func UnpaddedSpace(sectorSize uint64) abi.UnpaddedPieceSize

UnpaddedSpace returns the actual effective space in Byte

Types

type Challenge

type Challenge struct {
	StatementID abi.SealRandomness
	Content     abi.InteractiveSealRandomness
}

Challenge contains necessary info for a miner to generate proof

type Keeper

type Keeper struct {
	// contains filtered or unexported fields
}

func (*Keeper) GetChallenge

func (k *Keeper) GetChallenge() *Challenge

GetChallenge

func (*Keeper) GetStatement

func (k *Keeper) GetStatement() *Statement

GetStatement as getter

func (*Keeper) PickStatement

func (k *Keeper) PickStatement() *Statement

PickStatement mimic the actual method with the same name

func (*Keeper) SetChallenge

func (k *Keeper) SetChallenge(chal *Challenge)

SetChallenge

func (*Keeper) SetStatement

func (k *Keeper) SetStatement(st *Statement)

SetStatement save the validator commited statement

type Miner

type Miner struct {
	ID                  abi.ActorID
	ProofType           abi.RegisteredSealProof
	SectorUnpaddedSpace abi.UnpaddedPieceSize
	Validator           *Validator
	Store               *MinerStorage
}

Miner is the `storage` part in this demo

func NewMiner

func NewMiner(givenID int64, givenType abi.RegisteredSealProof) (*Miner, error)

NewMiner as the factory

func (*Miner) AssemblePieces

func (m *Miner) AssemblePieces(staged *os.File, piecePaths []string) (
	left, total abi.UnpaddedPieceSize,
	pi []abi.PieceInfo,
	err error,
)

AssemblePieces tries to assemble pieces

func (*Miner) CommitStatement

func (m *Miner) CommitStatement(
	givenID []byte,
	sectorNum uint64,
	sectorDir string,
	sectorPieces []abi.PieceInfo,
) *Statement

CommitStatement used to build a statement and send it to validator

func (*Miner) FilPiece

func (m *Miner) FilPiece(
	pieceFile *os.File,
	pieceLen abi.UnpaddedPieceSize,
	stagedFile *os.File,
	existingPieces []abi.UnpaddedPieceSize,
) (left, total abi.UnpaddedPieceSize, contentID cid.Cid, callErr error)

FilPiece tries to assemble piece data to the staged sector file

func (*Miner) InitSectorDir

func (m *Miner) InitSectorDir(dir string) (staged *os.File, sector, cache string, err error)

InitSectorDir will: 1. create a staged file to assemble the data pieces 2. create a sector file 3. create a cache dir for setup operation

func (*Miner) Pledge

func (m *Miner) Pledge(val *Validator)

Pledge mimic the miner pledge process

func (*Miner) PoRepProve

func (m *Miner) PoRepProve(
	sealedCID, unsealedCID cid.Cid,
	cacheDir, sealedFilePath string,
	proofType abi.RegisteredSealProof,
	sectorNum abi.SectorNumber,
	statementID abi.SealRandomness,
	chal abi.InteractiveSealRandomness,
	pieces []abi.PieceInfo,
) ([]byte, error)

PoRepProve responses to a PoRep challenge

func (*Miner) PoRepSetup

func (m *Miner) PoRepSetup(
	cacheDir, stagedFilePath, sealedFilePath string,
	sectorNum abi.SectorNumber,
	statementID abi.SealRandomness,
	pieces []abi.PieceInfo,
) (sealedCID, unsealedCID cid.Cid, callErr error)

PoRepSetup actually create the sealed sector file

func (*Miner) QueryChallengeSet

func (m *Miner) QueryChallengeSet() *Challenge

QueryChallengeSet query the challenge info from the validator

func (*Miner) ResponseToChallenge

func (m *Miner) ResponseToChallenge(chal *Challenge) *Proof

ResponseToChallenge create an answer proof

type MinerStorage

type MinerStorage struct {
	// contains filtered or unexported fields
}

MinerStorage works as the mimic of storage node

func NewMinerStorage

func NewMinerStorage() *MinerStorage

NewMinerStorage as the factory

func (*MinerStorage) GetStatement

func (ms *MinerStorage) GetStatement(givenID abi.SealRandomness) *Statement

GetStatement as getter mimic

func (*MinerStorage) GetStatementDir

func (ms *MinerStorage) GetStatementDir(givenID abi.SealRandomness) string

GetStatementDir as getter mimic

func (*MinerStorage) SetStatement

func (ms *MinerStorage) SetStatement(st *Statement)

SetStatement as setter mimic

func (*MinerStorage) SetStatementDir

func (ms *MinerStorage) SetStatementDir(givenID []byte, path string)

SetStatementDir as setter mimic

type Proof

type Proof struct {
	Content []byte
}

Proof contains necessary info for a validator to check if a sector is VALID

type Report

type Report struct {
	Detail     string         `json:"detail"`
	SectorSize string         `json:"sector_size"`
	Steps      []*StepMeasure `json:"steps"`
	TotalCost  string         `json:"total_cost"`
	// contains filtered or unexported fields
}

Report holds the step measure information for a whole PoRep procedure

func NewReport

func NewReport(detail string, typ abi.RegisteredSealProof) (*Report, error)

NewReport as the factory

func (*Report) AddStep

func (r *Report) AddStep(s *StepMeasure)

AddStep add a *DONE* step measure instance to the steps list

func (*Report) Dump

func (r *Report) Dump(dir string) error

Dump push the json formated report to the disk

type Statement

type Statement struct {
	ID          abi.SealRandomness
	MinerID     abi.ActorID
	ProofType   abi.RegisteredSealProof
	SectorNum   abi.SectorNumber
	SealedCID   cid.Cid
	UnsealedCID cid.Cid
	// optional
	Pieces []abi.PieceInfo
}

Statement contains necessary info for PoRep verify

type StepMeasure

type StepMeasure struct {
	Name string `json:"name"`
	Cost string `json:"cost"`
	// contains filtered or unexported fields
}

StepMeasure holds the time cost info of a single PoRep phase

func NewStepMeasure

func NewStepMeasure(n string) *StepMeasure

NewStepMeasure as the factory

func (*StepMeasure) Done

func (s *StepMeasure) Done() *StepMeasure

Done end the step's

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator is the statement challenge

func NewValidator

func NewValidator() *Validator

NewValidator as the factor method

func (*Validator) GenChallenge

func (v *Validator) GenChallenge()

GenChallenge mimic the actual method with the same name

func (*Validator) HandlePoRepProof

func (v *Validator) HandlePoRepProof(prf *Proof) (bool, error)

HandlePoRepProof mimics the cosmos handler

func (*Validator) HandlePoRepStatement

func (v *Validator) HandlePoRepStatement(st *Statement)

HandlePoRepStatement mimics the cosmos handler

func (*Validator) PoRepChallenge

func (v *Validator) PoRepChallenge() abi.InteractiveSealRandomness

PoRepChallenge fire a challenge

func (*Validator) PoRepVerify

func (v *Validator) PoRepVerify(
	minerID abi.ActorID,
	sectorNum abi.SectorNumber,
	proofType abi.RegisteredSealProof,
	sealedCID, unsealedCID cid.Cid,
	statementID abi.SealRandomness,
	chal abi.InteractiveSealRandomness,
	proof []byte,
) (bool, error)

PoRepVerify validate the proof commit by miner

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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