Documentation ¶
Index ¶
- Variables
- func BlockstoreCopy(from, to cbor.IpldBlockstore, root cid.Cid) (blocks uint64, copySize uint64, err error)
- func CreateMinerParamsV2(worker, owner address.Address, sealProof abi.RegisteredSealProof) (interface{}, error)
- func CreateMinerParamsV3(worker, owner address.Address, sealProof abi.RegisteredSealProof) (interface{}, error)
- func PopRandom(list []uint64, rnd *rand.Rand) (uint64, []uint64)
- func WinCount(minerPower abi.StoragePower, totalPower abi.StoragePower, random float64) uint64
- type Agent
- type DeadlineStateV2
- type DeadlineStateV3
- type DealClientAgent
- type DealClientConfig
- type DealProvider
- type MinerAgent
- func (ma *MinerAgent) Address() address.Address
- func (ma *MinerAgent) AvailableCollateral() abi.TokenAmount
- func (ma *MinerAgent) CreateDeal(proposal market.ClientDealProposal)
- func (ma *MinerAgent) DealRange(currentEpoch abi.ChainEpoch) (abi.ChainEpoch, abi.ChainEpoch)
- func (ma *MinerAgent) Tick(s SimState) ([]message, error)
- type MinerAgentConfig
- type MinerGenerator
- type MinerStateV2
- func (m *MinerStateV2) DeadlineInfo(store adt.Store, currEpoch abi.ChainEpoch) (*dline.Info, error)
- func (m *MinerStateV2) FeeDebt(store adt.Store) (abi.TokenAmount, error)
- func (m *MinerStateV2) FindSector(store adt.Store, sectorNo abi.SectorNumber) (uint64, uint64, error)
- func (m *MinerStateV2) HasSectorNo(store adt.Store, sectorNo abi.SectorNumber) (bool, error)
- func (m *MinerStateV2) LoadDeadlineState(store adt.Store, dlIdx uint64) (SimDeadlineState, error)
- func (m *MinerStateV2) LoadSectorInfo(store adt.Store, sectorNo uint64) (SimSectorInfo, error)
- func (m *MinerStateV2) ProvingPeriodStart(store adt.Store) (abi.ChainEpoch, error)
- type MinerStateV3
- func (m *MinerStateV3) DeadlineInfo(store adt.Store, currEpoch abi.ChainEpoch) (*dline.Info, error)
- func (m *MinerStateV3) FeeDebt(store adt.Store) (abi.TokenAmount, error)
- func (m *MinerStateV3) FindSector(store adt.Store, sectorNo abi.SectorNumber) (uint64, uint64, error)
- func (m *MinerStateV3) HasSectorNo(store adt.Store, sectorNo abi.SectorNumber) (bool, error)
- func (m *MinerStateV3) LoadDeadlineState(store adt.Store, dlIdx uint64) (SimDeadlineState, error)
- func (m *MinerStateV3) LoadSectorInfo(store adt.Store, sectorNo uint64) (SimSectorInfo, error)
- func (m *MinerStateV3) ProvingPeriodStart(store adt.Store) (abi.ChainEpoch, error)
- type PartitionStateV2
- type PartitionStateV3
- type PowerTable
- type RateIterator
- type SectorInfoV2
- type SectorInfoV3
- type Sim
- func (s *Sim) AddAgent(a Agent)
- func (s *Sim) AddDealProvider(d DealProvider)
- func (s *Sim) ChooseDealProvider() DealProvider
- func (s *Sim) CreateMinerParams(worker, owner address.Address, sealProof abi.RegisteredSealProof) (interface{}, error)
- func (s *Sim) GetCallStats() map[vm.MethodKey]*vm.CallStats
- func (s *Sim) GetEpoch() abi.ChainEpoch
- func (s *Sim) GetState(addr address.Address, out cbor.Unmarshaler) error
- func (s *Sim) GetVM() SimVM
- func (s *Sim) MinerState(addr address.Address) (SimMinerState, error)
- func (s *Sim) NetworkCirculatingSupply() abi.TokenAmount
- func (s *Sim) Store() adt.Store
- func (s *Sim) SwapVM(v SimVM, vmFactory VMFactoryFunc, ...)
- func (s *Sim) Tick() error
- type SimConfig
- type SimDeadlineState
- type SimMinerState
- type SimPartitionState
- type SimSectorInfo
- type SimState
- type SimVM
- type VMFactoryFunc
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func BlockstoreCopy ¶
func CreateMinerParamsV2 ¶ added in v3.1.0
func CreateMinerParamsV2(worker, owner address.Address, sealProof abi.RegisteredSealProof) (interface{}, error)
func CreateMinerParamsV3 ¶ added in v3.1.0
func CreateMinerParamsV3(worker, owner address.Address, sealProof abi.RegisteredSealProof) (interface{}, error)
func WinCount ¶
func WinCount(minerPower abi.StoragePower, totalPower abi.StoragePower, random float64) uint64
This is the Filecoin algorithm for winning a ticket within a block with the tickets replaced with random numbers. It lets miners win according to a Poisson distribution with rate proportional to the miner's fraction of network power.
Types ¶
type DeadlineStateV2 ¶ added in v3.1.0
type DeadlineStateV2 struct {
// contains filtered or unexported fields
}
func (*DeadlineStateV2) LoadPartition ¶ added in v3.1.0
func (d *DeadlineStateV2) LoadPartition(store adt.Store, partIdx uint64) (SimPartitionState, error)
type DeadlineStateV3 ¶ added in v3.1.0
type DeadlineStateV3 struct {
// contains filtered or unexported fields
}
func (*DeadlineStateV3) LoadPartition ¶ added in v3.1.0
func (d *DeadlineStateV3) LoadPartition(store adt.Store, partIdx uint64) (SimPartitionState, error)
type DealClientAgent ¶
type DealClientAgent struct { DealCount int // contains filtered or unexported fields }
func AddDealClientsForAccounts ¶
func AddDealClientsForAccounts(s SimState, accounts []address.Address, seed int64, config DealClientConfig) []*DealClientAgent
func NewDealClientAgent ¶
func NewDealClientAgent(account address.Address, seed int64, config DealClientConfig) *DealClientAgent
func (*DealClientAgent) Tick ¶
func (dca *DealClientAgent) Tick(s SimState) ([]message, error)
type DealClientConfig ¶
type DealClientConfig struct { DealRate float64 // deals made per epoch MinPieceSize uint64 // minimum piece size (actual piece size be rounded up to power of 2) MaxPieceSize uint64 // maximum piece size MinStoragePrice abi.TokenAmount // minimum price per epoch a client will pay for storage (may be zero) MaxStoragePrice abi.TokenAmount // maximum price per epoch a client will pay for storage MinMarketBalance abi.TokenAmount // balance below which client will top up funds in market actor MaxMarketBalance abi.TokenAmount // balance to which client will top up funds in market actor }
type DealProvider ¶
type DealProvider interface { Address() address.Address DealRange(currentEpoch abi.ChainEpoch) (start abi.ChainEpoch, end abi.ChainEpoch) CreateDeal(proposal market.ClientDealProposal) AvailableCollateral() abi.TokenAmount }
type MinerAgent ¶
type MinerAgent struct { Config MinerAgentConfig // parameters used to define miner prior to creation Owner address.Address Worker address.Address IDAddress address.Address RobustAddress address.Address // Stats UpgradedSectors uint64 // contains filtered or unexported fields }
func NewMinerAgent ¶
func NewMinerAgent(owner address.Address, worker address.Address, idAddress address.Address, robustAddress address.Address, rndSeed int64, config MinerAgentConfig, ) *MinerAgent
func (*MinerAgent) Address ¶
func (ma *MinerAgent) Address() address.Address
func (*MinerAgent) AvailableCollateral ¶
func (ma *MinerAgent) AvailableCollateral() abi.TokenAmount
func (*MinerAgent) CreateDeal ¶
func (ma *MinerAgent) CreateDeal(proposal market.ClientDealProposal)
func (*MinerAgent) DealRange ¶
func (ma *MinerAgent) DealRange(currentEpoch abi.ChainEpoch) (abi.ChainEpoch, abi.ChainEpoch)
func (*MinerAgent) Tick ¶
func (ma *MinerAgent) Tick(s SimState) ([]message, error)
type MinerAgentConfig ¶
type MinerAgentConfig struct { PrecommitRate float64 // average number of PreCommits per epoch ProofType abi.RegisteredSealProof // seal proof type for this miner StartingBalance abi.TokenAmount // initial actor balance for miner actor FaultRate float64 // rate at which committed sectors go faulty (faults per committed sector per epoch) RecoveryRate float64 // rate at which faults are recovered (recoveries per fault per epoch) MinMarketBalance abi.TokenAmount // balance below which miner will top up funds in market actor MaxMarketBalance abi.TokenAmount // balance to which miner will top up funds in market actor UpgradeSectors bool // if true, miner will replace sectors without deals with sectors that do }
type MinerGenerator ¶
type MinerGenerator struct {
// contains filtered or unexported fields
}
MinerGenerator adds miner agents to the simulation at a configured rate. When triggered to add a new miner, it: * Selects the next owner address from the accounts it has been given. * Sends a createMiner message from that account * Handles the response by creating a MinerAgent with MinerAgentConfig and registering it in the sim.
func NewMinerGenerator ¶
func NewMinerGenerator(accounts []address.Address, config MinerAgentConfig, createMinerRate float64, rndSeed int64) *MinerGenerator
func (*MinerGenerator) Tick ¶
func (mg *MinerGenerator) Tick(s SimState) ([]message, error)
type MinerStateV2 ¶ added in v3.1.0
type MinerStateV2 struct { Root cid.Cid Ctx context.Context // contains filtered or unexported fields }
func (*MinerStateV2) DeadlineInfo ¶ added in v3.1.0
func (m *MinerStateV2) DeadlineInfo(store adt.Store, currEpoch abi.ChainEpoch) (*dline.Info, error)
func (*MinerStateV2) FeeDebt ¶ added in v3.1.0
func (m *MinerStateV2) FeeDebt(store adt.Store) (abi.TokenAmount, error)
func (*MinerStateV2) FindSector ¶ added in v3.1.0
func (m *MinerStateV2) FindSector(store adt.Store, sectorNo abi.SectorNumber) (uint64, uint64, error)
func (*MinerStateV2) HasSectorNo ¶ added in v3.1.0
func (m *MinerStateV2) HasSectorNo(store adt.Store, sectorNo abi.SectorNumber) (bool, error)
func (*MinerStateV2) LoadDeadlineState ¶ added in v3.1.0
func (m *MinerStateV2) LoadDeadlineState(store adt.Store, dlIdx uint64) (SimDeadlineState, error)
func (*MinerStateV2) LoadSectorInfo ¶ added in v3.1.0
func (m *MinerStateV2) LoadSectorInfo(store adt.Store, sectorNo uint64) (SimSectorInfo, error)
func (*MinerStateV2) ProvingPeriodStart ¶ added in v3.1.0
func (m *MinerStateV2) ProvingPeriodStart(store adt.Store) (abi.ChainEpoch, error)
type MinerStateV3 ¶ added in v3.1.0
type MinerStateV3 struct { Root cid.Cid Ctx context.Context // contains filtered or unexported fields }
func (*MinerStateV3) DeadlineInfo ¶ added in v3.1.0
func (m *MinerStateV3) DeadlineInfo(store adt.Store, currEpoch abi.ChainEpoch) (*dline.Info, error)
func (*MinerStateV3) FeeDebt ¶ added in v3.1.0
func (m *MinerStateV3) FeeDebt(store adt.Store) (abi.TokenAmount, error)
func (*MinerStateV3) FindSector ¶ added in v3.1.0
func (m *MinerStateV3) FindSector(store adt.Store, sectorNo abi.SectorNumber) (uint64, uint64, error)
func (*MinerStateV3) HasSectorNo ¶ added in v3.1.0
func (m *MinerStateV3) HasSectorNo(store adt.Store, sectorNo abi.SectorNumber) (bool, error)
func (*MinerStateV3) LoadDeadlineState ¶ added in v3.1.0
func (m *MinerStateV3) LoadDeadlineState(store adt.Store, dlIdx uint64) (SimDeadlineState, error)
func (*MinerStateV3) LoadSectorInfo ¶ added in v3.1.0
func (m *MinerStateV3) LoadSectorInfo(store adt.Store, sectorNo uint64) (SimSectorInfo, error)
func (*MinerStateV3) ProvingPeriodStart ¶ added in v3.1.0
func (m *MinerStateV3) ProvingPeriodStart(store adt.Store) (abi.ChainEpoch, error)
type PartitionStateV2 ¶ added in v3.1.0
type PartitionStateV2 struct {
// contains filtered or unexported fields
}
func (*PartitionStateV2) Terminated ¶ added in v3.1.0
func (p *PartitionStateV2) Terminated() bitfield.BitField
type PartitionStateV3 ¶ added in v3.1.0
type PartitionStateV3 struct {
// contains filtered or unexported fields
}
func (*PartitionStateV3) Terminated ¶ added in v3.1.0
func (p *PartitionStateV3) Terminated() bitfield.BitField
type PowerTable ¶ added in v3.1.0
type PowerTable struct {
// contains filtered or unexported fields
}
func ComputePowerTableV2 ¶ added in v3.1.0
func ComputePowerTableV2(v SimVM, agents []Agent) (PowerTable, error)
func ComputePowerTableV3 ¶ added in v3.1.0
func ComputePowerTableV3(v SimVM, agents []Agent) (PowerTable, error)
type RateIterator ¶
type RateIterator struct {
// contains filtered or unexported fields
}
RateIterator can be used to model poisson process (a process with discreet events occurring at arbitrary times with a specified average rate). It's Tick function must be called at regular intervals with a function that will be called zero or more times to produce the event distribution at the correct rate.
func NewRateIterator ¶
func NewRateIterator(rate float64, seed int64) *RateIterator
func (*RateIterator) Tick ¶
func (ri *RateIterator) Tick(f func() error) error
simulate random occurrences by calling the given function once for each event that would land in this epoch. The function will be called `rate` times on average, but may be called zero or many times in any Tick.
func (*RateIterator) TickWithRate ¶
func (ri *RateIterator) TickWithRate(rate float64, f func() error) error
TickWithRate permits a variable rate. If the rate has changed, it will compute a new next occurrence before running tick. This prevents having to wait a long time to recognize a change from a very slow rate to a higher one.
type SectorInfoV2 ¶ added in v3.1.0
type SectorInfoV2 struct {
// contains filtered or unexported fields
}
func (*SectorInfoV2) Expiration ¶ added in v3.1.0
func (s *SectorInfoV2) Expiration() abi.ChainEpoch
type SectorInfoV3 ¶ added in v3.1.0
type SectorInfoV3 struct {
// contains filtered or unexported fields
}
func (*SectorInfoV3) Expiration ¶ added in v3.1.0
func (s *SectorInfoV3) Expiration() abi.ChainEpoch
type Sim ¶
type Sim struct { Config SimConfig Agents []Agent DealProviders []DealProvider WinCount uint64 MessageCount uint64 ComputePowerTable func(SimVM, []Agent) (PowerTable, error) CreateMinerParamsFunc func(address.Address, address.Address, abi.RegisteredSealProof) (interface{}, error) // contains filtered or unexported fields }
Sim is a simulation framework to exercise actor code in a network-like environment. It's goal is to simulate realistic call sequences and interactions to perform invariant analysis and test performance assumptions prior to shipping actor code out to implementations. The model is that the simulation will "Tick" once per epoch. Within this tick: * It will first compute winning tickets from previous state for miners to simulate block mining. * It will create any agents it is configured to create and generate messages to create their associated actors. * It will call tick on all it agents. This call will return messages that will get added to the simulated "tipset". * Messages will be shuffled to simulate network entropy. * Messages will be applied and an new VM will be created from the resulting state tree for the next tick.
func NewSimWithVM ¶ added in v3.1.0
func NewSimWithVM(ctx context.Context, t testing.TB, v SimVM, vmFactory VMFactoryFunc, computePowerTable func(SimVM, []Agent) (PowerTable, error), blkStore ipldcbor.IpldBlockstore, blockstoreFactory func() ipldcbor.IpldBlockstore, minerStateFactory func(context.Context, cid.Cid) (SimMinerState, error), config SimConfig, createMinerParams func(address.Address, address.Address, abi.RegisteredSealProof) (interface{}, error), ) *Sim
func (*Sim) AddDealProvider ¶
func (s *Sim) AddDealProvider(d DealProvider)
func (*Sim) ChooseDealProvider ¶
func (s *Sim) ChooseDealProvider() DealProvider
func (*Sim) CreateMinerParams ¶ added in v3.1.0
func (s *Sim) CreateMinerParams(worker, owner address.Address, sealProof abi.RegisteredSealProof) (interface{}, error)
func (*Sim) GetEpoch ¶
func (s *Sim) GetEpoch() abi.ChainEpoch
func (*Sim) MinerState ¶ added in v3.1.0
func (s *Sim) MinerState(addr address.Address) (SimMinerState, error)
func (*Sim) NetworkCirculatingSupply ¶
func (s *Sim) NetworkCirculatingSupply() abi.TokenAmount
func (*Sim) SwapVM ¶ added in v3.1.0
func (s *Sim) SwapVM(v SimVM, vmFactory VMFactoryFunc, minerStateFactory func(context.Context, cid.Cid) (SimMinerState, error), computePowerTable func(SimVM, []Agent) (PowerTable, error), createMinerParams func(address.Address, address.Address, abi.RegisteredSealProof) (interface{}, error), )
type SimDeadlineState ¶ added in v3.1.0
type SimDeadlineState interface {
LoadPartition(adt.Store, uint64) (SimPartitionState, error)
}
type SimMinerState ¶ added in v3.1.0
type SimMinerState interface { HasSectorNo(adt.Store, abi.SectorNumber) (bool, error) FindSector(adt.Store, abi.SectorNumber) (uint64, uint64, error) ProvingPeriodStart(adt.Store) (abi.ChainEpoch, error) LoadSectorInfo(adt.Store, uint64) (SimSectorInfo, error) DeadlineInfo(adt.Store, abi.ChainEpoch) (*dline.Info, error) FeeDebt(adt.Store) (abi.TokenAmount, error) LoadDeadlineState(adt.Store, uint64) (SimDeadlineState, error) }
type SimPartitionState ¶ added in v3.1.0
type SimPartitionState interface {
Terminated() bitfield.BitField
}
type SimSectorInfo ¶ added in v3.1.0
type SimSectorInfo interface {
Expiration() abi.ChainEpoch
}
type SimState ¶
type SimState interface { GetEpoch() abi.ChainEpoch GetState(addr address.Address, out cbor.Unmarshaler) error Store() adt.Store AddAgent(a Agent) AddDealProvider(d DealProvider) NetworkCirculatingSupply() abi.TokenAmount MinerState(addr address.Address) (SimMinerState, error) CreateMinerParams(worker, owner address.Address, sealProof abi.RegisteredSealProof) (interface{}, error) // randomly select an agent capable of making deals. // Returns nil if no providers exist. ChooseDealProvider() DealProvider }
type SimVM ¶ added in v3.1.0
type SimVM interface { ApplyMessage(from, to address.Address, value abi.TokenAmount, method abi.MethodNum, params interface{}) (cbor.Marshaler, exitcode.ExitCode) GetCirculatingSupply() abi.TokenAmount GetLogs() []string GetState(addr address.Address, out cbor.Unmarshaler) error SetStatsSource(stats vm2.StatsSource) GetCallStats() map[vm2.MethodKey]*vm2.CallStats GetEpoch() abi.ChainEpoch Store() adt2.Store GetActor(addr address.Address) (*states.Actor, bool, error) SetCirculatingSupply(supply big.Int) GetActorImpls() map[cid.Cid]rt.VMActor StateRoot() cid.Cid GetStatsSource() vm2.StatsSource GetTotalActorBalance() (abi.TokenAmount, error) }
VM interface allowing a simulation to operate over multiple VM versions