mdm

package
v0.0.0-...-88504b6 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInsufficientBudget = errors.New("remaining budget is insufficient")

ErrInsufficientBudget is the error returned if the remaining budget of a program is not sufficient to execute the next instruction.

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

func CopyCost

func CopyCost(pt modules.RPCPriceTable, contractSize uint64) types.Currency

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

func InitCost

func InitCost(pt modules.RPCPriceTable, programLen uint64) types.Currency

InitCost is the cost of instantiatine the MDM. It is defined as: 'InitBaseCost' + 'MemoryTimeCost' * 'programLen' * Time

func NewAppendInstruction

func NewAppendInstruction(dataOffset uint64, merkleProof bool) modules.Instruction

NewAppendInstruction creates a modules.Instruction from arguments.

func NewReadSectorInstruction

func NewReadSectorInstruction(lengthOffset, offsetOffset, merkleRootOffset uint64, merkleProof bool) modules.Instruction

NewReadSectorInstruction creates a modules.Instruction from arguments.

func ReadCost

func ReadCost(pt modules.RPCPriceTable, readLength uint64) types.Currency

ReadCost is the cost of executing a 'Read' instruction. It is defined as: 'readBaseCost' + 'readLengthCost' * `readLength`

func SwapCost

func SwapCost(pt modules.RPCPriceTable, contractSize uint64) types.Currency

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

func TruncateCost

func TruncateCost(pt modules.RPCPriceTable, contractSize uint64) types.Currency

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

func WriteCost

func WriteCost(pt modules.RPCPriceTable, writeLength uint64) types.Currency

WriteCost is the cost of executing a 'Write' instruction of a certain length. It's also used to compute the cost of a `WriteSector` and `Append` instruction.

Types

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, pt modules.RPCPriceTable, instructions []modules.Instruction, budget types.Currency, so StorageObligation, 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 {
	// ContractSize returns the current contract size of the storage obligation.
	ContractSize() uint64
	// Locked returns whether or not the storage obligation is locked.
	Locked() bool
	// MerkleRoot returns the filecontract's current root.
	MerkleRoot() crypto.Hash
	// SectorRoots returns the roots of the storage obligation.
	SectorRoots() []crypto.Hash
	// Update updates the storage obligation.
	Update(sectorRoots, 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