mdm

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2020 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInsufficientBudget             = errors.New("program has insufficient budget to execute")
	ErrInsufficientComputeBudget      = errors.New("insufficient 'compute' budget")
	ErrInsufficientDiskAccessesBudget = errors.New("insufficient 'diskaccess' budget")
	ErrInsufficientDiskReadBudget     = errors.New("insufficient 'diskread' budget")
	ErrInsufficientDiskWriteBudget    = errors.New("insufficient 'diskwrite' budget")
	ErrInsufficientMemoryBudget       = errors.New("insufficient 'memory' budget")
)

The following errors are returned by `cost.Sub` in case of an underflow. ErrInsufficientBudget is always returned in combination with the error of the corresponding resource.

View Source
var (
	// ErrInterrupted indicates that the program was interrupted during
	// execution and couldn't finish.
	ErrInterrupted = errors.New("execution of program was interrupted")
)

Functions

This section is empty.

Types

type Cost

type Cost struct {
	Compute      uint64 // NOTE: 1 compute cost corresponds to an estimated 2^17 hashes performed on data.
	DiskAccesses uint64 // # of writes and reads
	DiskRead     uint64 // bytes read from disk
	DiskWrite    uint64 // bytes written to disk
	Memory       uint64 // estimated ram used in bytes
}

Cost describes the cost of executing an instruction on the MDM split up into its individual counterparts.

func CopyCost

func CopyCost(contractSize uint64) Cost

CopyCost is the cost of executing a 'Copy' instruction.

func InitCost

func InitCost(programLen uint64) Cost

InitCost is the cost of instantiating the MDM

func ReadCost

func ReadCost(contractSize uint64) Cost

ReadCost is the cost of executing a 'Read' instruction.

func ReadSectorCost

func ReadSectorCost() Cost

ReadSectorCost is the cost of executing a 'ReadSector' instruction.

func SwapCost

func SwapCost(contractSize uint64) Cost

SwapCost is the cost of executing a 'Swap' instruction.

func TruncateCost

func TruncateCost(contractSize uint64) Cost

TruncateCost is the cost of executing a 'Truncate' instruction.

func WriteSectorCost

func WriteSectorCost(contractSize uint64) Cost

WriteSectorCost is the cost of executing a 'WriteSector' instruction.

func (Cost) Add

func (c Cost) Add(c2 Cost) Cost

Add adds a Cost to another Cost and returns the result.

func (Cost) Sub

func (c Cost) Sub(c2 Cost) (cost Cost, err error)

Sub subtracts a Cost from another Cost.

type Host

type Host interface {
	BlockHeight() types.BlockHeight
	ReadSector(sectorRoot crypto.Hash) ([]byte, error)
}

Host defines the minimal interface a Host needs to implement to be used by the mdm.

type MDM

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

MDM (Merklized Data Machine) is a virtual machine that executes instructions on the data in a Sia file contract. The file contract tracks the size and Merkle root of the underlying data, which the MDM will update when running instructions that modify the file contract data. Each instruction can optionally produce a cryptographic proof that the instruction was executed honestly. Every instruction has an execution cost, and instructions are batched into atomic sets called 'programs' that are either entirely applied or are not applied at all.

func New

func New(h Host) *MDM

New creates a new MDM.

func (*MDM) ExecuteProgram

func (mdm *MDM) ExecuteProgram(ctx context.Context, instructions []modules.Instruction, budget Cost, so StorageObligation, initialContractSize uint64, initialMerkleRoot crypto.Hash, programDataLen uint64, data io.Reader) (func() error, <-chan Output, error)

ExecuteProgram initializes a new program from a set of instructions and a reader which can be used to fetch the program's data and executes it.

func (*MDM) Stop

func (mdm *MDM) Stop() error

Stop will stop the MDM and wait for all of the spawned programs to stop executing while also preventing new programs from being started.

type Output

type Output struct {
	// The error will be set to nil unless the instruction experienced an error
	// during execution. If the instruction did experience an error during
	// execution, the program will halt at this instruction and no changes will
	// be committed.
	//
	// The error will be prefixed by 'invalid' if the error resulted from an
	// invalid program, and the error will be prefixed by 'hosterr' if the error
	// resulted from a host error such as a disk failure.
	Error error

	// NewSize is the size of a file contract after the execution of an
	// instruction.
	NewSize uint64

	// NewMerkleRoot is the merkle root after the execution of an instruction.
	NewMerkleRoot crypto.Hash

	// The output will be set to nil unless the instruction produces output for
	// the caller. One example of such an instruction would be 'Read()'. If
	// there was an error during execution, the output will be nil.
	Output []byte

	// The proof will be set to nil if there was an error, and also if no proof
	// was requested by the caller. Using only the proof, the caller will be
	// able to compute the next Merkle root and size of the contract.
	Proof []crypto.Hash
}

Output is the type returned by all instructions when being executed.

type Program

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

Program is a collection of instructions. Within a program, each instruction will potentially modify the size and merkle root of a file contract. After the final instruction is executed, the MDM will create an updated revision of the FileContract which has to be signed by the renter and the host.

type StorageObligation

type StorageObligation interface {
	Locked() bool
	Update(sectorsRemoved, sectorsGained []crypto.Hash, gainedSectorData [][]byte) error
}

StorageObligation defines the minimal interface a StorageObligation needs to implement to be used by the mdm.

Jump to

Keyboard shortcuts

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