mdm

package
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 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)
}

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 ScPrime 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 {

	// 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
	// AdditionalStorageCost contains the running program value for the cost of additional
	// storage used after executing it.
	AdditionalStorageCost 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