vm

package
v5.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: Apache-2.0, MIT Imports: 55 Imported by: 1

Documentation

Index

Constants

View Source
const CurrentStateTreeVersion = 3
View Source
const RandString = "i_am_random_____i_am_random_____"

This is set to match the test vector default randomness value. If set differently it will cause all generated conformance tests over randomness syscalls to fail. https://github.com/filecoin-project/test-vectors/blob/master/schema/schema_randomness.go#L76

Variables

View Source
var EmptyObjectCid cid.Cid
View Source
var ExpectOK = &okExitCode
View Source
var FIL = big.NewInt(1e18)
View Source
var UnsealedCIDPrefix = cid.Prefix{
	Version:  1,
	Codec:    cid.FilCommitmentUnsealed,
	MhType:   mh.POSEIDON_BLS12_381_A1_FC1,
	MhLength: 32,
}

Prefix for testing unsealed sector CIDs (CommD).

View Source
var VerifregRoot address.Address

Functions

func ApplyOk

func ApplyOk(t *testing.T, v *VM, from, to address.Address, value abi.TokenAmount, method abi.MethodNum, params interface{}) cbor.Marshaler

func CreateAccounts

func CreateAccounts(ctx context.Context, t testing.TB, vm *VM, n int, balance abi.TokenAmount, seed int64) []address.Address

Creates n account actors in the VM with the given balance

func ExpectAttoFil

func ExpectAttoFil(amount big.Int) *big.Int

helpers to simplify pointer creation

func ExpectBytes

func ExpectBytes(b []byte) *objectExpectation

func ExpectExitCode

func ExpectExitCode(code exitcode.ExitCode) *exitcode.ExitCode

func ExpectObject

func ExpectObject(v cbor.Marshaler) *objectExpectation

func GetDealState

func GetDealState(t *testing.T, vm *VM, dealID abi.DealID) (*market.DealState, bool)

func MinerDLInfo

func MinerDLInfo(t *testing.T, v *VM, minerIDAddr address.Address) *dline.Info

func MinerPower

func MinerPower(t *testing.T, vm *VM, minerIdAddr address.Address) miner.PowerPair

func NextMinerDLInfo

func NextMinerDLInfo(t *testing.T, v *VM, minerIDAddr address.Address) *dline.Info

func ParamsForInvocation

func ParamsForInvocation(t *testing.T, vm *VM, idxs ...int) interface{}

func PowerForMinerSector

func PowerForMinerSector(t *testing.T, vm *VM, minerIdAddr address.Address, sectorNumber abi.SectorNumber) miner.PowerPair

func SectorDeadline

func SectorDeadline(t *testing.T, v *VM, minerIDAddress address.Address, sectorNumber abi.SectorNumber) (uint64, uint64)

find the proving deadline and partition index of a miner's sector

func ValueForInvocation

func ValueForInvocation(t *testing.T, vm *VM, idxs ...int) abi.TokenAmount

Types

type ActorImplLookup

type ActorImplLookup vm2.ActorImplLookup

type ActorImplLookup map[cid.Cid]runtime.VMActor

type CallStats

type CallStats = vm2.CallStats
	startReads      uint64
	startWrites     uint64
	startReadBytes  uint64
	startWriteBytes uint64
}

type ChainMessage

type ChainMessage struct {
	Version uint64

	To   address.Address
	From address.Address

	Nonce uint64

	Value abi.TokenAmount

	GasLimit   int64
	GasFeeCap  abi.TokenAmount
	GasPremium abi.TokenAmount

	Method abi.MethodNum
	Params []byte
}

func (*ChainMessage) MarshalCBOR

func (t *ChainMessage) MarshalCBOR(w io.Writer) error

func (*ChainMessage) UnmarshalCBOR

func (t *ChainMessage) UnmarshalCBOR(r io.Reader) error

type ExpectInvocation

type ExpectInvocation struct {
	To     address.Address
	Method abi.MethodNum

	// optional
	Exitcode       exitcode.ExitCode
	From           address.Address
	Value          *abi.TokenAmount
	Params         *objectExpectation
	Ret            *objectExpectation
	SubInvocations []ExpectInvocation
}

ExpectInvocation is a pattern for a message invocation within the VM. The To and Method fields must be supplied. Exitcode defaults to exitcode.Ok. All other field are optional, where a nil or Undef value indicates that any value will match. SubInvocations will be matched recursively.

func (ExpectInvocation) Matches

func (ei ExpectInvocation) Matches(t *testing.T, invocations *Invocation)

type GasCharge

type GasCharge struct {
	Name  string
	Extra interface{}

	ComputeGas int64
	StorageGas int64

	VirtualCompute int64
	VirtualStorage int64
}

func (GasCharge) Total

func (g GasCharge) Total() int64

func (GasCharge) WithExtra

func (g GasCharge) WithExtra(extra interface{}) GasCharge

func (GasCharge) WithVirtual

func (g GasCharge) WithVirtual(compute, storage int64) GasCharge

type InternalMessage

type InternalMessage struct {
	// contains filtered or unexported fields
}

func (InternalMessage) Caller

func (msg InternalMessage) Caller() address.Address

Caller implements runtime.MessageInfo.

func (InternalMessage) Receiver

func (msg InternalMessage) Receiver() address.Address

Receiver implements runtime.MessageInfo.

func (InternalMessage) ValueReceived

func (msg InternalMessage) ValueReceived() abi.TokenAmount

ValueReceived implements runtime.MessageInfo.

type Invocation

type Invocation struct {
	Msg            *InternalMessage
	Exitcode       exitcode.ExitCode
	Ret            cbor.Marshaler
	SubInvocations []*Invocation
}

type MessageResult

type MessageResult struct {
	Ret        cbor.Marshaler
	Code       exitcode.ExitCode
	GasCharged int64
}

func RequireApplyMessage added in v5.0.1

func RequireApplyMessage(t *testing.T, v *VM, from, to address.Address, value abi.TokenAmount, method abi.MethodNum, params interface{}, name string) MessageResult

type MethodKey

type MethodKey = vm2.MethodKey
type MethodKey struct {
	Code   cid.Cid
	Method abi.MethodNum
}

type MinerBalances

type MinerBalances struct {
	AvailableBalance abi.TokenAmount
	VestingBalance   abi.TokenAmount
	InitialPledge    abi.TokenAmount
	PreCommitDeposit abi.TokenAmount
}

func GetMinerBalances

func GetMinerBalances(t *testing.T, vm *VM, minerIdAddr address.Address) MinerBalances

type NetworkStats

type NetworkStats struct {
	power.State
	TotalRawBytePower             abi.StoragePower
	TotalBytesCommitted           abi.StoragePower
	TotalQualityAdjPower          abi.StoragePower
	TotalQABytesCommitted         abi.StoragePower
	TotalPledgeCollateral         abi.TokenAmount
	ThisEpochRawBytePower         abi.StoragePower
	ThisEpochQualityAdjPower      abi.StoragePower
	ThisEpochPledgeCollateral     abi.TokenAmount
	MinerCount                    int64
	MinerAboveMinPowerCount       int64
	ThisEpochReward               abi.TokenAmount
	ThisEpochRewardSmoothed       smoothing.FilterEstimate
	ThisEpochBaselinePower        abi.StoragePower
	TotalStoragePowerReward       abi.TokenAmount
	TotalClientLockedCollateral   abi.TokenAmount
	TotalProviderLockedCollateral abi.TokenAmount
	TotalClientStorageFee         abi.TokenAmount
}

func GetNetworkStats

func GetNetworkStats(t *testing.T, vm *VM) NetworkStats

type Option added in v5.0.1

type Option func(tv *testVector) error

func SetCircSupply added in v5.0.1

func SetCircSupply(circSupply big.Int) Option

func SetEndStateTree added in v5.0.1

func SetEndStateTree(rawRoot cid.Cid, store adt.Store) Option

func SetEpoch added in v5.0.1

func SetEpoch(e abi.ChainEpoch) Option

func SetID added in v5.0.1

func SetID(id string) Option

func SetMessage added in v5.0.1

func SetMessage(from, to address.Address, nonce uint64, value big.Int, method abi.MethodNum, params interface{}) Option

func SetNetworkVersion added in v5.0.1

func SetNetworkVersion(nv network.Version) Option

func SetReceipt added in v5.0.1

func SetReceipt(res MessageResult) Option

func SetStartState added in v5.0.1

func SetStartState(v *VM) Option

func StartConditions added in v5.0.1

func StartConditions(v *VM, id string) []Option

type Pricelist

type Pricelist interface {
	// OnChainMessage returns the gas used for storing a message of a given size in the chain.
	OnChainMessage(msgSize int) GasCharge
	// OnChainReturnValue returns the gas used for storing the response of a message in the chain.
	OnChainReturnValue(dataSize int) GasCharge

	// OnMethodInvocation returns the gas used when invoking a method.
	OnMethodInvocation(value abi.TokenAmount, methodNum abi.MethodNum) GasCharge

	// OnIpldGet returns the gas used for storing an object
	OnIpldGet() GasCharge
	// OnIpldPut returns the gas used for storing an object
	OnIpldPut(dataSize int) GasCharge

	// OnCreateActor returns the gas used for creating an actor
	OnCreateActor() GasCharge
	// OnDeleteActor returns the gas used for deleting an actor
	OnDeleteActor() GasCharge

	OnVerifySignature(sigType crypto.SigType, planTextSize int) (GasCharge, error)
	OnHashing(dataSize int) GasCharge
	OnComputeUnsealedSectorCid(proofType abi.RegisteredSealProof, pieces []abi.PieceInfo) GasCharge
	OnVerifySeal(info proof.SealVerifyInfo) GasCharge
	OnVerifyPost(info proof.WindowPoStVerifyInfo) GasCharge
	OnVerifyConsensusFault() GasCharge
}

type StateInfo0 added in v5.0.1

type StateInfo0 struct{}

func (*StateInfo0) MarshalCBOR added in v5.0.1

func (t *StateInfo0) MarshalCBOR(w io.Writer) error

func (*StateInfo0) UnmarshalCBOR added in v5.0.1

func (t *StateInfo0) UnmarshalCBOR(r io.Reader) error

type StateRoot added in v5.0.1

type StateRoot struct {
	// State tree version.
	Version StateTreeVersion
	// Actors tree. The structure depends on the state root version.
	Actors cid.Cid
	// Info. The structure depends on the state root version.
	Info cid.Cid
}

func (*StateRoot) MarshalCBOR added in v5.0.1

func (t *StateRoot) MarshalCBOR(w io.Writer) error

func (*StateRoot) UnmarshalCBOR added in v5.0.1

func (t *StateRoot) UnmarshalCBOR(r io.Reader) error

type StateTreeVersion added in v5.0.1

type StateTreeVersion uint64

type StatsByCall

type StatsByCall = vm2.StatsByCall

type StatsByCall map[MethodKey]*CallStats

type StatsSource

type StatsSource = vm2.StatsSource
type StatsSource interface {
	WriteCount() uint64
	ReadCount() uint64
	WriteSize() uint64
	ReadSize() uint64
}

type VM

type VM struct {
	ActorImpls ActorImplLookup
	// contains filtered or unexported fields
}

VM is a simplified message execution framework for the purposes of testing inter-actor communication. The VM maintains actor state and can be used to simulate message validation for a single block or tipset. The VM does not track gas charges, provide working syscalls, validate message nonces and many other things that a compliant VM needs to do.

func AdvanceByDeadline

func AdvanceByDeadline(t *testing.T, v *VM, minerIDAddr address.Address, predicate advanceDeadlinePredicate) (*VM, *dline.Info)

AdvanceByDeadline creates a new VM advanced to an epoch specified by the predicate while keeping the miner state upu-to-date by running a cron at the end of each deadline period.

func AdvanceByDeadlineTillEpoch

func AdvanceByDeadlineTillEpoch(t *testing.T, v *VM, minerIDAddr address.Address, e abi.ChainEpoch) (*VM, *dline.Info)

Advances by deadline until e is contained within the deadline period represented by the returned deadline info. The VM returned will be set to the last deadline close, not at e.

func AdvanceByDeadlineTillIndex

func AdvanceByDeadlineTillIndex(t *testing.T, v *VM, minerIDAddr address.Address, i uint64) (*VM, *dline.Info)

Advances by deadline until the deadline index matches the given index. The vm returned will be set to the close epoch of the previous deadline.

func AdvanceTillProvingDeadline

func AdvanceTillProvingDeadline(t *testing.T, v *VM, minerIDAddress address.Address, sectorNumber abi.SectorNumber) (*dline.Info, uint64, *VM)

Advance to the epoch when the sector is due to be proven. Returns the deadline info for proving deadline for sector, partition index of sector, and a VM at the opening of the deadline (ready for SubmitWindowedPoSt).

func NewVM

func NewVM(ctx context.Context, actorImpls ActorImplLookup, store adt.Store) *VM

NewVM creates a new runtime for executing messages.

func NewVMAtEpoch

func NewVMAtEpoch(ctx context.Context, actorImpls ActorImplLookup, store adt.Store, stateRoot cid.Cid, epoch abi.ChainEpoch) (*VM, error)

NewVM creates a new runtime for executing messages.

func NewVMWithSingletons

func NewVMWithSingletons(ctx context.Context, t testing.TB, bs ipldcbor.IpldBlockstore) *VM

Creates a new VM and initializes all singleton actors plus a root verifier account.

func (*VM) Abortf

func (vm *VM) Abortf(errExitCode exitcode.ExitCode, msg string, args ...interface{})

func (*VM) ApplyMessage

func (vm *VM) ApplyMessage(from, to address.Address, value abi.TokenAmount, method abi.MethodNum, params interface{}, info string) (MessageResult, error)

ApplyMessage applies the message to the current state. It returns result of message application and any internal vm errors. If test-vector environment variables are set this method generates tests-vectors as a side effect

func (*VM) GetActor

func (vm *VM) GetActor(a address.Address) (*states.Actor, bool, error)

func (*VM) GetActorImpls

func (vm *VM) GetActorImpls() map[cid.Cid]rt.VMActor

func (*VM) GetCallStats

func (vm *VM) GetCallStats() map[MethodKey]*CallStats

Get call stats

func (*VM) GetCirculatingSupply

func (vm *VM) GetCirculatingSupply() abi.TokenAmount

Set the FIL circulating supply passed to actors through runtime

func (*VM) GetEpoch

func (vm *VM) GetEpoch() abi.ChainEpoch

Get the chain epoch for this vm

func (*VM) GetLogs

func (vm *VM) GetLogs() []string

func (*VM) GetState

func (vm *VM) GetState(addr address.Address, out cbor.Unmarshaler) error

func (*VM) GetStateTree

func (vm *VM) GetStateTree() (*states.Tree, error)

func (*VM) GetStatsSource

func (vm *VM) GetStatsSource() StatsSource

func (*VM) GetTotalActorBalance

func (vm *VM) GetTotalActorBalance() (abi.TokenAmount, error)

func (*VM) Invocations

func (vm *VM) Invocations() []*Invocation

func (*VM) LastInvocation

func (vm *VM) LastInvocation() *Invocation

func (*VM) Log

func (vm *VM) Log(_ rt.LogLevel, msg string, args ...interface{})

func (*VM) NormalizeAddress

func (vm *VM) NormalizeAddress(addr address.Address) (address.Address, bool)

func (*VM) SetActorState

func (vm *VM) SetActorState(ctx context.Context, key address.Address, state cbor.Marshaler) error

SetActorState stores the state and updates the addressed actor

func (*VM) SetCirculatingSupply

func (vm *VM) SetCirculatingSupply(supply abi.TokenAmount)

Set the FIL circulating supply passed to actors through runtime

func (*VM) SetStatsSource

func (vm *VM) SetStatsSource(s StatsSource)

func (*VM) StateRoot

func (vm *VM) StateRoot() cid.Cid

func (*VM) Store

func (vm *VM) Store() adt.Store

func (*VM) StoreReadBytes

func (vm *VM) StoreReadBytes() uint64

func (*VM) StoreReads

func (vm *VM) StoreReads() uint64

func (*VM) StoreWriteBytes

func (vm *VM) StoreWriteBytes() uint64

func (*VM) StoreWrites

func (vm *VM) StoreWrites() uint64

func (*VM) WithEpoch

func (vm *VM) WithEpoch(epoch abi.ChainEpoch) (*VM, error)

func (*VM) WithNetworkVersion

func (vm *VM) WithNetworkVersion(nv network.Version) (*VM, error)

Jump to

Keyboard shortcuts

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