capacity

package
v0.0.0-...-163fc3c Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2021 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const TypeSpaceKeeperPlasterer = "spacekeeper.plasterer"
View Source
const (
	TypeSpaceKeeperV1 = "spacekeeper.v1"
)

Variables

View Source
var (
	ErrWorkSpaceDoesNotExist    = errors.New("non-existent workSpace")
	ErrWorkSpaceIsNotRegistered = errors.New("non-registered workSpace")
	ErrWorkSpaceIsNotPlotting   = errors.New("non-plotting workSpace")
	ErrWorkSpaceIsNotReady      = errors.New("non-ready workSpace")
	ErrWorkSpaceIsNotMining     = errors.New("non-mining workSpace")
	ErrWorkSpaceIsNotStill      = errors.New("non-registered or non-ready workSpace")
	ErrWorkSpaceCannotGenerate  = errors.New("not allowed to generate new workSpace")

	ErrSktDBWrongFileName        = errors.New("db file name not standard")
	ErrSktDBDuplicate            = errors.New("db file duplicate in root dirs")
	ErrSktDBDoesNotMatchWithName = errors.New("db file content does not match with name")

	ErrWalletDoesNotContainPubKey = errors.New("wallet does not contain pubKey")
	ErrWalletIsLocked             = errors.New("wallet is locked")

	ErrSpaceKeeperIsRunning         = errors.New("spaceKeeper is running")
	ErrSpaceKeeperIsNotRunning      = errors.New("spaceKeeper is not running")
	ErrSpaceKeeperIsConfiguring     = errors.New("spaceKeeper is configuring")
	ErrSpaceKeeperConfiguredNothing = errors.New("configured nothing for spaceKeeper")
	ErrSpaceKeeperChangeDBDirs      = errors.New("cannot change dbDirs")

	ErrConfigUnderSizeTarget = errors.New("target disk size is smaller than lower bound")
	ErrOSDiskSizeNotEnough   = errors.New("os disk size is not enough")
	ErrInvalidRequiredBytes  = errors.New("required disk size in bytes is not valid")
	ErrConfigInvalidPathSize = errors.New("target path and size is not matched")
	ErrInvalidDir            = errors.New("invalid directory")
)

Functions

func NewSpaceKeeperPlasterer

func NewSpaceKeeperPlasterer(args ...interface{}) (spacekeeper.SpaceKeeper, error)

func NewSpaceKeeperV1

func NewSpaceKeeperV1(args ...interface{}) (spacekeeper.SpaceKeeper, error)

NewSpaceKeeperV1

Types

type PoCWallet

type PoCWallet interface {
	GenerateNewPublicKeyByCointype(cointype uint32) (*pocec.PublicKey, uint32, error)
	GenerateNewPublicKey(accountID string) (*pocec.PublicKey, uint32, error)
	GetPublicKeyOrdinal(*pocec.PublicKey) (uint32, bool)
	SignMessage(pubKey *pocec.PublicKey, hash []byte) (*pocec.Signature, error)
	Unlock(password []byte) error
	Lock()
	IsLocked() bool
}

type SpaceID

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

func NewSpaceID

func NewSpaceID(ordinal int64, pk *pocec.PublicKey, bl int) *SpaceID

func (*SpaceID) BitLength

func (sid *SpaceID) BitLength() int

func (*SpaceID) Ordinal

func (sid *SpaceID) Ordinal() int64

func (*SpaceID) PubKey

func (sid *SpaceID) PubKey() *pocec.PublicKey

func (*SpaceID) PubKeyHash

func (sid *SpaceID) PubKeyHash() pocutil.Hash

func (*SpaceID) String

func (sid *SpaceID) String() string

type SpaceKeeper

type SpaceKeeper struct {
	*service.BaseService
	// contains filtered or unexported fields
}

func (*SpaceKeeper) ActOnWorkSpace

func (sk *SpaceKeeper) ActOnWorkSpace(sid string, action engine.ActionType) (err error)

func (*SpaceKeeper) ActOnWorkSpaces

func (sk *SpaceKeeper) ActOnWorkSpaces(flags engine.WorkSpaceStateFlags, action engine.ActionType) (errs map[string]error, err error)

func (*SpaceKeeper) AvailableDiskSize

func (sk *SpaceKeeper) AvailableDiskSize() uint64

TODO: should consider pending workspaces

func (*SpaceKeeper) ConfigureByBitLength

func (sk *SpaceKeeper) ConfigureByBitLength(BlCount map[int]int, execPlot, execMine bool, cointype uint32) ([]engine.WorkSpaceInfo, error)

func (*SpaceKeeper) ConfigureByFlags

func (sk *SpaceKeeper) ConfigureByFlags(flags engine.WorkSpaceStateFlags, execPlot, execMine bool) ([]engine.WorkSpaceInfo, error)

func (*SpaceKeeper) ConfigureByPath

func (sk *SpaceKeeper) ConfigureByPath(paths []string, sizes []int, execPlot, execMine, autoCreate bool, cointype uint32) ([]engine.WorkSpaceInfo, error)

func (*SpaceKeeper) ConfigureByPubKey

func (sk *SpaceKeeper) ConfigureByPubKey(PubKeyBL map[*pocec.PublicKey]int, PubKeyOrdinal map[*pocec.PublicKey]int, execPlot, execMine bool) ([]engine.WorkSpaceInfo, error)

func (*SpaceKeeper) ConfigureBySize

func (sk *SpaceKeeper) ConfigureBySize(targetSize uint64, execPlot, execMine bool, cointype uint32) ([]engine.WorkSpaceInfo, error)

func (*SpaceKeeper) Configured

func (sk *SpaceKeeper) Configured() bool

func (*SpaceKeeper) DeleteMultiWS

func (sk *SpaceKeeper) DeleteMultiWS(flags engine.WorkSpaceStateFlags) map[string]error

func (*SpaceKeeper) DeleteWS

func (sk *SpaceKeeper) DeleteWS(sid string) error

DeleteWS should only be applied on registered/ready workSpace WorkSpace in spaceKeeper index and data in SktDB would be both deleted

func (*SpaceKeeper) GetProof

func (sk *SpaceKeeper) GetProof(ctx context.Context, sid string, challenge pocutil.Hash) (*engine.WorkSpaceProof, error)

func (*SpaceKeeper) GetProofReader

func (sk *SpaceKeeper) GetProofReader(ctx context.Context, sid string, challenge pocutil.Hash) (engine.ProofReader, error)

func (*SpaceKeeper) GetProofs

func (sk *SpaceKeeper) GetProofs(ctx context.Context, flags engine.WorkSpaceStateFlags, challenge pocutil.Hash) ([]*engine.WorkSpaceProof, error)

func (*SpaceKeeper) GetProofsReader

func (sk *SpaceKeeper) GetProofsReader(ctx context.Context, flags engine.WorkSpaceStateFlags, challenge pocutil.Hash) (engine.ProofReader, error)

func (*SpaceKeeper) IsCapacityAvailable

func (sk *SpaceKeeper) IsCapacityAvailable(path string, capacityBytes uint64) error

IsCapacityAvailable returns nil if given path is able to hold capacityBytes size of spaces.

func (*SpaceKeeper) MineMultiWS

func (sk *SpaceKeeper) MineMultiWS(flags engine.WorkSpaceStateFlags) map[string]error

func (*SpaceKeeper) MineWS

func (sk *SpaceKeeper) MineWS(sid string) error

MineWS should make workSpace state conversion happen like: registered -> plotting -> mining plotting -> mining ready -> mining mining -> mining For registered workSpace, simply push it into spacePlotter Queue with `wouldMining = true` For plotting workSpace, modify queuedWorkspace with `wouldMining = true` For ready workSpace, convert it to mining state

func (*SpaceKeeper) OnStart

func (sk *SpaceKeeper) OnStart() error

func (*SpaceKeeper) OnStop

func (sk *SpaceKeeper) OnStop() error

func (*SpaceKeeper) PlotMultiWS

func (sk *SpaceKeeper) PlotMultiWS(flags engine.WorkSpaceStateFlags) map[string]error

func (*SpaceKeeper) PlotWS

func (sk *SpaceKeeper) PlotWS(sid string) error

PlotWS should make workSpace state conversion happen like: registered -> plotting -> ready registered -> ready plotting -> ready ready -> ready mining -> mining

func (*SpaceKeeper) RemoveMultiWS

func (sk *SpaceKeeper) RemoveMultiWS(flags engine.WorkSpaceStateFlags) map[string]error

func (*SpaceKeeper) RemoveWS

func (sk *SpaceKeeper) RemoveWS(sid string) error

RemoveWS should only be applied on registered/ready workSpace WorkSpace in spaceKeeper workSpaceList would be removed

func (*SpaceKeeper) ResetDBDirs

func (sk *SpaceKeeper) ResetDBDirs(dbDirs []string) error

func (*SpaceKeeper) SignHash

func (sk *SpaceKeeper) SignHash(sid string, hash [32]byte) (*pocec.Signature, error)

func (*SpaceKeeper) StopMultiWS

func (sk *SpaceKeeper) StopMultiWS(flags engine.WorkSpaceStateFlags) map[string]error

func (*SpaceKeeper) StopWS

func (sk *SpaceKeeper) StopWS(sid string) error

StopWs should make workSpace state conversion happen like: registered -> registered plotting -> registered ready -> ready mining -> ready For all states, clear workSpace out from spacePlotter Queue For plotting workSpace, stop plotting and modify queuedWorkspace with `wouldMining = false` For mining workSpace, convert it to ready state

func (*SpaceKeeper) Type

func (sk *SpaceKeeper) Type() string

func (*SpaceKeeper) WorkSpaceIDs

func (sk *SpaceKeeper) WorkSpaceIDs(flags engine.WorkSpaceStateFlags) ([]string, error)

func (*SpaceKeeper) WorkSpaceInfos

func (sk *SpaceKeeper) WorkSpaceInfos(flags engine.WorkSpaceStateFlags) ([]engine.WorkSpaceInfo, error)

func (*SpaceKeeper) WorkSpaceInfosByDirs

func (sk *SpaceKeeper) WorkSpaceInfosByDirs() (dirs []string, results [][]engine.WorkSpaceInfo, err error)

type WorkSpace

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

func NewWorkSpace

func NewWorkSpace(dbType string, rootDir string, ordinal int64, pubKey *pocec.PublicKey, bitLength int) (*WorkSpace, error)

NewWorkSpace loads SktDB from given rootDir with PubKey&BitLength, and set proper state for WorkSpace by its progress To prevent accident, double check PubKey&BitLength on loaded SktDB If SktDB does not exist, create new SktDB.

func (*WorkSpace) BitLength

func (ws *WorkSpace) BitLength() int

func (*WorkSpace) Close

func (ws *WorkSpace) Close() error

func (*WorkSpace) Delete

func (ws *WorkSpace) Delete() error

func (*WorkSpace) Info

func (ws *WorkSpace) Info() engine.WorkSpaceInfo

func (*WorkSpace) Plot

func (ws *WorkSpace) Plot() error

func (*WorkSpace) Progress

func (ws *WorkSpace) Progress() float64

func (*WorkSpace) PubKey

func (ws *WorkSpace) PubKey() *pocec.PublicKey

func (*WorkSpace) PubKeyHash

func (ws *WorkSpace) PubKeyHash() pocutil.Hash

func (*WorkSpace) SpaceID

func (ws *WorkSpace) SpaceID() *SpaceID

func (*WorkSpace) State

func (ws *WorkSpace) State() engine.WorkSpaceState

func (*WorkSpace) StopPlot

func (ws *WorkSpace) StopPlot() error

type WorkSpaceMap

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

func NewWorkSpaceMap

func NewWorkSpaceMap() *WorkSpaceMap

func (*WorkSpaceMap) Count

func (m *WorkSpaceMap) Count() int

func (*WorkSpaceMap) Delete

func (m *WorkSpaceMap) Delete(sid string)

func (*WorkSpaceMap) Get

func (m *WorkSpaceMap) Get(sid string) (*WorkSpace, bool)

func (*WorkSpaceMap) Has

func (m *WorkSpaceMap) Has(sid string) bool

func (*WorkSpaceMap) Items

func (m *WorkSpaceMap) Items() map[string]*WorkSpace

func (*WorkSpaceMap) Set

func (m *WorkSpaceMap) Set(sid string, ws *WorkSpace)

type WorkSpacePath

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

func NewWorkSpacePath

func NewWorkSpacePath(dir string) *WorkSpacePath

func (*WorkSpacePath) Add

func (p *WorkSpacePath) Add(ws *WorkSpace)

func (*WorkSpacePath) WorkSpaces

func (p *WorkSpacePath) WorkSpaces() []*WorkSpace

Jump to

Keyboard shortcuts

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