Documentation ¶
Index ¶
- Constants
- Variables
- func AppendMemory() uint64
- func DropSectorsMemory() uint64
- func HasSectorMemory() uint64
- func MemoryCost(pt modules.RPCPriceTable, usedMemory, time uint64) types.Currency
- func NewAppendInstruction(dataOffset uint64, merkleProof bool) modules.Instruction
- func NewDropSectorsInstruction(numSectorsOffset uint64, merkleProof bool) modules.Instruction
- func NewHasSectorInstruction(merkleRootOffset uint64) modules.Instruction
- func NewReadSectorInstruction(lengthOffset, offsetOffset, merkleRootOffset uint64, merkleProof bool) modules.Instruction
- func ReadMemory() uint64
- type Host
- type MDM
- type Output
- type Program
- type StorageObligation
- type StorageObligationSnapshot
Constants ¶
const ( // ProgramInitTime is the time it takes to execute a program. This is a // hardcoded value which is meant to be replaced in the future. // TODO: The time is hardcoded to 10 for now until we add time management in the // future. ProgramInitTime = 10 // TimeAppend is the time for executing an 'Append' instruction. TimeAppend = 10000 // TimeCommit is the time used for executing managedFinalize. TimeCommit = 50e3 // TimeDropSingleSector is the time for dropping a single sector. TimeDropSingleSector = 1 // TimeHasSector is the time for executing a 'HasSector' instruction. TimeHasSector = 1 // TimeReadSector is the time for executing a 'ReadSector' instruction. TimeReadSector = 1000 // TimeWriteSector is the time for executing a 'WriteSector' instruction. TimeWriteSector = 10000 )
The following constants defines the time modifiers used for memory price calculations in the MDM.
Variables ¶
var ( // ErrInterrupted indicates that the program was interrupted during // execution and couldn't finish. ErrInterrupted = errors.New("execution of program was interrupted") )
Functions ¶
func AppendMemory ¶ added in v1.4.4
func AppendMemory() uint64
AppendMemory returns the additional memory consumption of a 'Append' instruction.
func DropSectorsMemory ¶ added in v1.4.4
func DropSectorsMemory() uint64
DropSectorsMemory returns the additional memory consumption of a `DropSectors` instruction
func HasSectorMemory ¶ added in v1.4.4
func HasSectorMemory() uint64
HasSectorMemory returns the additional memory consumption of a 'HasSector' instruction.
func MemoryCost ¶ added in v1.4.4
func MemoryCost(pt modules.RPCPriceTable, usedMemory, time uint64) types.Currency
MemoryCost computes the memory cost given a price table, memory and time.
func NewAppendInstruction ¶ added in v1.4.3
func NewAppendInstruction(dataOffset uint64, merkleProof bool) modules.Instruction
NewAppendInstruction creates a modules.Instruction from arguments.
func NewDropSectorsInstruction ¶ added in v1.4.4
func NewDropSectorsInstruction(numSectorsOffset uint64, merkleProof bool) modules.Instruction
NewDropSectorsInstruction creates a modules.Instruction from arguments.
func NewHasSectorInstruction ¶ added in v1.4.4
func NewHasSectorInstruction(merkleRootOffset uint64) modules.Instruction
NewHasSectorInstruction 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 ReadMemory ¶ added in v1.4.4
func ReadMemory() uint64
ReadMemory returns the additional memory consumption of a 'Read' instruction.
Types ¶
type Host ¶
type Host interface { BlockHeight() types.BlockHeight HasSector(crypto.Hash) bool 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, sos StorageObligationSnapshot, programDataLen uint64, data io.Reader) (func(so StorageObligation) 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 { ExecutionCost types.Currency PotentialRefund types.Currency // contains filtered or unexported fields }
Output is the type of the outputs returned by a program run on the MDM.
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 { // Update updates the storage obligation. Update(sectorRoots, sectorsRemoved []crypto.Hash, sectorsGained map[crypto.Hash][]byte) error }
StorageObligation defines an interface the storage obligation must adhere to.
type StorageObligationSnapshot ¶ added in v1.4.5
type StorageObligationSnapshot interface { // ContractSize returns the current contract size of the storage obligation. ContractSize() uint64 // MerkleRoot returns the filecontract's current root. MerkleRoot() crypto.Hash // SectorRoots returns the roots of the storage obligation. SectorRoots() []crypto.Hash }
StorageObligationSnapshot defines an interface the snapshot must adhere to in order for the mdm to be able to execute a program.