Documentation ¶
Index ¶
- Variables
- func CopyCost(pt modules.RPCPriceTable, contractSize uint64) types.Currency
- func InitCost(pt modules.RPCPriceTable, programLen uint64) types.Currency
- func NewAppendInstruction(dataOffset uint64, merkleProof bool) modules.Instruction
- func NewReadSectorInstruction(lengthOffset, offsetOffset, merkleRootOffset uint64, merkleProof bool) modules.Instruction
- func ReadCost(pt modules.RPCPriceTable, readLength uint64) types.Currency
- func SwapCost(pt modules.RPCPriceTable, contractSize uint64) types.Currency
- func TruncateCost(pt modules.RPCPriceTable, contractSize uint64) types.Currency
- func WriteCost(pt modules.RPCPriceTable, writeLength uint64) types.Currency
- type Host
- type MDM
- type Output
- type Program
- type StorageObligation
Constants ¶
This section is empty.
Variables ¶
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.
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 ¶ added in v1.4.3
func NewAppendInstruction(dataOffset uint64, merkleProof bool) modules.Instruction
NewAppendInstruction creates a modules.Instruction from arguments.
func NewReadSectorInstruction ¶ added in v1.4.3
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.
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 (*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.
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.