mdm

package
v1.5.9 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyProgram is returned if the program doesn't contain any instructions.
	ErrEmptyProgram = errors.New("can't execute program without instructions")

	// 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 FnFinalize

type FnFinalize func(StorageObligation) error

FnFinalize is the type of a function returned by ExecuteProgram to finalize the changes made by the program.

type Host

type Host interface {
	BlockHeight() types.BlockHeight
	HasSector(crypto.Hash) bool
	ReadSector(sectorRoot crypto.Hash) ([]byte, error)
	RegistryUpdate(rv modules.SignedRegistryValue, pubKey types.SiaPublicKey, expiry types.BlockHeight) (modules.SignedRegistryValue, error)
	RegistryGet(sid modules.RegistryEntryID) (types.SiaPublicKey, modules.SignedRegistryValue, bool)
}

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, p modules.Program, budget *modules.RPCBudget, collateralBudget types.Currency, sos StorageObligationSnapshot, duration types.BlockHeight, programDataLen uint64, data io.Reader) (_ FnFinalize, _ <-chan Output, err 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 {

	// Batch indicates whether or not the caller is recommended to hold off on
	// sending the output over the wire in favor of batching the writes with the
	// result of the next instruction.
	Batch bool
	// ExecutionCost contains the running program value for the execution cost.
	ExecutionCost types.Currency
	// AdditionalCollateral contains the running program value for the
	// additional collateral.
	AdditionalCollateral types.Currency
	// FailureRefund is the amount of money that gets refunded should the
	// program execution fail.
	FailureRefund types.Currency
	// contains filtered or unexported fields
}

Output is the type of the outputs returned by a program run on the MDM.

type StorageObligation

type StorageObligation interface {
	// Update updates the storage obligation.
	Update(sectorRoots []crypto.Hash, sectorsRemoved map[crypto.Hash]struct{}, sectorsGained map[crypto.Hash][]byte) error
}

StorageObligation defines an interface the storage obligation must adhere to.

type StorageObligationSnapshot

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
	// RecentRevision returns the recent revision at the time the snapshot was
	// taken.
	RecentRevision() types.FileContractRevision
	// RevisionTxn returns the recent revision txn of the so.
	RevisionTxn() types.Transaction
	// 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.

Jump to

Keyboard shortcuts

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