core

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2018 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package core contains common definitions used by other modules.

Index

Constants

View Source
const (
	NoRole = JetRole(iota)
	VirtualExecutor
	VirtualValidator
	HeavyExecutor
	LightExecutor
	LightValidator
)
View Source
const (
	// RecordIDSize is relative record address.
	RecordIDSize = 32
	// RecordRefSize is absolute records address (including domain ID).
	RecordRefSize = RecordIDSize * 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Arguments

type Arguments []byte

Arguments is a dedicated type for arguments, that represented as bynary cbored blob

type ArtifactManager

type ArtifactManager interface {
	// RootRef returns the root record reference.
	//
	// Root record is the parent for all top-level records.
	RootRef() *RecordRef

	// SetArchPref stores a list of preferred VM architectures memory.
	//
	// When returning classes storage will return compiled code according to this preferences. VM is responsible for
	// calling this method before fetching object in a new process. If preference is not provided, object getters will
	// return an error.
	SetArchPref(pref []MachineType)

	// GetCode returns code from code record by provided reference.
	//
	// This method is used by VM to fetch code for execution.
	GetCode(code RecordRef) (CodeDescriptor, error)

	// GetLatestClass returns descriptor for latest state of the class known to storage.
	// If the class is deactivated, an error should be returned.
	//
	// Returned descriptor will provide methods for fetching all related data.
	GetLatestClass(head RecordRef) (ClassDescriptor, error)

	// GetLatestObj returns descriptor for latest state of the object known to storage.
	// If the object or the class is deactivated, an error should be returned.
	//
	// Returned descriptor will provide methods for fetching all related data.
	GetLatestObj(head RecordRef) (ObjectDescriptor, error)

	// GetObjChildren returns provided object's children references.
	GetObjChildren(head RecordRef) (RefIterator, error)

	// GetObjDelegate returns provided object's delegate reference for provided class.
	//
	// Object delegate should be previously created for this object. If object delegate does not exist, an error will
	// be returned.
	GetObjDelegate(head, asClass RecordRef) (*RecordRef, error)

	// DeclareType creates new type record in storage.
	//
	// Type is a contract interface. It contains one method signature.
	DeclareType(domain, request RecordRef, typeDec []byte) (*RecordRef, error)

	// DeployCode creates new code record in storage.
	//
	// Code records are used to activate class or as migration code for an object.
	DeployCode(domain, request RecordRef, codeMap map[MachineType][]byte) (*RecordRef, error)

	// ActivateClass creates activate class record in storage. Provided code reference will be used as a class code.
	//
	// Activation reference will be this class'es identifier and referred as "class head".
	ActivateClass(domain, request RecordRef) (*RecordRef, error)

	// DeactivateClass creates deactivate record in storage. Provided reference should be a reference to the head of
	// the class. If class is already deactivated, an error should be returned.
	//
	// Deactivated class cannot be changed or instantiate objects.
	DeactivateClass(domain, request, class RecordRef) (*RecordRef, error)

	// UpdateClass creates amend class record in storage. Provided reference should be a reference to the head of
	// the class. Migrations are references to code records.
	//
	// Returned reference will be the latest class state (exact) reference. Migration code will be executed by VM to
	// migrate objects memory in the order they appear in provided slice.
	UpdateClass(domain, request, class, code RecordRef, migrationRefs []RecordRef) (*RecordRef, error)

	// ActivateObj creates activate object record in storage. Provided class reference will be used as object's class.
	// If memory is not provided, the class default memory will be used.
	//
	// Activation reference will be this object's identifier and referred as "object head".
	ActivateObj(domain, request, class, parent RecordRef, memory []byte) (*RecordRef, error)

	// ActivateObjDelegate is similar to ActivateObj but it created object will be parent's delegate of provided class.
	ActivateObjDelegate(domain, request, class, parent RecordRef, memory []byte) (*RecordRef, error)

	// DeactivateObj creates deactivate object record in storage. Provided reference should be a reference to the head
	// of the object. If object is already deactivated, an error should be returned.
	//
	// Deactivated object cannot be changed.
	DeactivateObj(domain, request, obj RecordRef) (*RecordRef, error)

	// UpdateObj creates amend object record in storage. Provided reference should be a reference to the head of the
	// object. Provided memory well be the new object memory.
	//
	// Returned reference will be the latest object state (exact) reference.
	UpdateObj(domain, request, obj RecordRef, memory []byte) (*RecordRef, error)
}

ArtifactManager is a high level storage interface.

type ClassDescriptor

type ClassDescriptor interface {
	// HeadRef returns head reference to represented class record.
	HeadRef() *RecordRef

	// StateRef returns reference to represented class state record.
	StateRef() *RecordRef

	// CodeDescriptor returns descriptor for fetching class's code data.
	CodeDescriptor() (CodeDescriptor, error)
}

ClassDescriptor represents meta info required to fetch all object data.

type CodeDescriptor

type CodeDescriptor interface {
	// Ref returns reference to represented code record.
	Ref() *RecordRef

	// MachineType fetches code from storage and returns first available machine type according to architecture
	// preferences.
	//
	// Code for returned machine type will be fetched by Code method.
	MachineType() (MachineType, error)

	// Code fetches code from storage. Code will be fetched according to architecture preferences
	// set via SetArchPref in artifact manager. If preferences are not provided, an error will be returned.
	Code() ([]byte, error)
}

CodeDescriptor represents meta info required to fetch all code data.

type Component

type Component interface {
	Start(components Components) error
	Stop() error
}

type Components

type Components map[string]Component

type JetCoordinator added in v0.0.6

type JetCoordinator interface {
	Component
	// AmI Checks Me for role on concrete pulse for this address
	AmI(role JetRole, ref RecordRef, number PulseNumber) bool
	IsIt(role JetRole, ref RecordRef, number PulseNumber) bool

	GetVirtualExecutor(pulse PulseNumber, ref RecordRef) NetworkAddress
	GetVirtualValidators(pulse PulseNumber, ref RecordRef) []NetworkAddress

	// TODO: calc JetID from RecordRef inside
	GetLightExecutor(pulse PulseNumber, ref RecordRef) NetworkAddress
	GetLightValidators(pulse PulseNumber, ref RecordRef) []NetworkAddress

	// TODO: calc JetID from RecordRef inside
	GetHeavyExecutor(pulse PulseNumber, ref RecordRef) NetworkAddress
}

type JetID added in v0.0.6

type JetID RecordRef

type JetRole added in v0.0.6

type JetRole int

type Ledger

type Ledger interface {
	// GetManager returns artifact manager to work with.
	GetManager() ArtifactManager
}

Ledger is the global ledger handler. Other system parts communicate with ledger through it.

type Logger added in v0.0.6

type Logger interface {
	// SetLevel sets log level
	SetLevel(string) error

	// Debug logs a message at level Debug.
	Debug(...interface{})
	// Debugln logs a message at level Debug.
	Debugln(...interface{})

	// Info logs a message at level Info.
	Info(...interface{})
	// Infoln logs a message at level Info.
	Infoln(...interface{})

	// Warn logs a message at level Warn.
	Warn(...interface{})
	// Warnln logs a message at level Warn.
	Warnln(...interface{})

	// Error logs a message at level Error.
	Error(...interface{})
	// Errorln logs a message at level Error.
	Errorln(...interface{})

	// Fatal logs a message at level Fatal and than call os.exit().
	Fatal(...interface{})
	// Fatalln logs a message at level Fatal and than call os.exit().
	Fatalln(...interface{})

	// Panic logs a message at level Panic and than call panic().
	Panic(...interface{})
	// Panicln logs a message at level Panic and than call panic().
	Panicln(...interface{})
}

Logger is the interface for loggers used in the Insolar components.

type LogicCallContext added in v0.0.6

type LogicCallContext struct {
	Callee *RecordRef // Contract that was called
	Class  *RecordRef // Class of the callee
	Parent *RecordRef // Parent of the callee
	Caller *RecordRef // Contract that made the call
	Time   time.Time  // Time when call was made
	Pulse  uint64     // Number of the pulse
}

LogicCallContext is a context of contract execution

type LogicRunner

type LogicRunner interface {
	Execute(msg Message) (res *Response)
}

LogicRunner is an interface that should satisfy logic executor

type MachineLogicExecutor

type MachineLogicExecutor interface {
	CallMethod(ctx *LogicCallContext, code RecordRef, data []byte, method string, args Arguments) (newObjectState []byte, methodResults Arguments, err error)
	CallConstructor(ctx *LogicCallContext, code RecordRef, name string, args Arguments) (objectState []byte, err error)
	Stop() error
}

MachineLogicExecutor is an interface for implementers of one particular machine type

type MachineType

type MachineType int

MachineType is a type of virtual machine

const (
	MachineTypeNotExist             = 0
	MachineTypeBuiltin  MachineType = iota + 1
	MachineTypeGoPlugin

	MachineTypesLastID
)

Real constants of MachineType

type Message

type Message interface {
	Serialize() (io.Reader, error)
	GetReference() RecordRef
}

Message is a routable packet, ATM just a method call

type MessageRouter

type MessageRouter interface {
	Route(msg Message) (resp Response, err error)
}

MessageRouter interface

type Network

type Network interface {
	// SendMessage sends a message.
	SendMessage(method string, msg Message) ([]byte, error)
	// GetAddress returns an origin address.
	GetAddress() string
	// RemoteProcedureRegister is remote procedure register func.
	RemoteProcedureRegister(name string, method RemoteProcedure)
}

Network is interface for network modules facade.

type NetworkAddress added in v0.0.6

type NetworkAddress string

type ObjectDescriptor

type ObjectDescriptor interface {
	// HeadRef returns head reference to represented object record.
	HeadRef() *RecordRef

	// StateRef returns reference to object state record.
	StateRef() *RecordRef

	// Memory fetches object memory from storage.
	Memory() ([]byte, error)

	// CodeDescriptor returns descriptor for fetching object's code data.
	CodeDescriptor() (CodeDescriptor, error)

	// ClassDescriptor returns descriptor for fetching object's class data.
	ClassDescriptor() (ClassDescriptor, error)
}

ObjectDescriptor represents meta info required to fetch all object data.

type PulseNumber added in v0.0.6

type PulseNumber uint32

type RecordRef

type RecordRef [RecordRefSize]byte

RecordRef is unified record reference.

func String2Ref

func String2Ref(str string) RecordRef

String2Ref deserializes reference from base58 encoded string.

func (RecordRef) Domain

func (ref RecordRef) Domain() [RecordIDSize]byte

Domain returns domain ID part of reference.

func (RecordRef) Equal

func (ref RecordRef) Equal(other RecordRef) bool

Equal checks if reference points to the same record.

func (RecordRef) String

func (ref RecordRef) String() string

type RefIterator added in v0.0.6

type RefIterator interface {
	Next() (RecordRef, error)
	HasNext() bool
}

type RemoteProcedure

type RemoteProcedure func(args [][]byte) ([]byte, error)

RemoteProcedure is remote procedure call function.

type Response

type Response struct {
	Data   []byte
	Result []byte
	Error  error
}

Response to a `Message`

Jump to

Keyboard shortcuts

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