Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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.
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 ReadSectorCost ¶
func ReadSectorCost() Cost
ReadSectorCost is the cost of executing a 'ReadSector' instruction.
func TruncateCost ¶
TruncateCost is the cost of executing a 'Truncate' instruction.
func WriteSectorCost ¶
WriteSectorCost is the cost of executing a 'WriteSector' instruction.
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 (*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.
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.