builders

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2021 License: Apache-2.0, Apache-2.0, MIT Imports: 84 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StagePreconditions is where the state tree is manipulated into the desired shape.
	StagePreconditions = Stage("preconditions")
	// StageApplies is where messages are accumulated.
	StageApplies = Stage("applies")
	// StageChecks is where assertions are made on receipts and state.
	StageChecks = Stage("checks")
	// StageFinished is where the test vector is finalized, ready for serialization.
	StageFinished = Stage("finished")
)
View Source
const LotusExecutionTraceV1 = "Lotus-ExecutionTrace-V1"
View Source
const (
	TestSealProofType = abi.RegisteredSealProof_StackedDrg2KiBV1
)

Variables

View Source
var (
	TotalNetworkBalance = big.Mul(big.NewInt(totalFilecoin), big.NewInt(filecoinPrecision))
	RootVerifier        = MustNewIDAddr(80)
)
View Source
var GenscriptCommit = "dirty"
View Source
var KnownProtocolVersions = []ProtocolVersion{
	{
		ID:            "genesis",
		FirstEpoch:    1,
		StateTree:     types.StateTreeVersion0,
		Network:       network.Version0,
		Actors:        actors.Version0,
		ZeroStateTree: (*StateTracker).ActorsZeroStateV0,
	},
	{
		ID:            "breeze",
		FirstEpoch:    build.UpgradeBreezeHeight + 1,
		StateTree:     types.StateTreeVersion0,
		Network:       network.Version1,
		Actors:        actors.Version0,
		ZeroStateTree: (*StateTracker).ActorsZeroStateV0,
	}, {
		ID:            "smoke",
		FirstEpoch:    build.UpgradeSmokeHeight + 1,
		StateTree:     types.StateTreeVersion0,
		Network:       network.Version2,
		Actors:        actors.Version0,
		ZeroStateTree: (*StateTracker).ActorsZeroStateV0,
	}, {
		ID:            "ignition",
		FirstEpoch:    build.UpgradeIgnitionHeight + 1,
		StateTree:     types.StateTreeVersion0,
		Network:       network.Version3,
		Actors:        actors.Version0,
		ZeroStateTree: (*StateTracker).ActorsZeroStateV0,
	}, {
		ID:            "actorsv2",
		FirstEpoch:    build.UpgradeActorsV2Height + 1,
		StateTree:     types.StateTreeVersion1,
		Network:       network.Version4,
		Actors:        actors.Version2,
		ZeroStateTree: (*StateTracker).ActorsZeroStateV2,
	},
	{
		ID:            "tape",
		FirstEpoch:    build.UpgradeTapeHeight + 1,
		StateTree:     types.StateTreeVersion1,
		Network:       network.Version5,
		Actors:        actors.Version2,
		ZeroStateTree: (*StateTracker).ActorsZeroStateV2,
	},
	{
		ID:            "liftoff",
		FirstEpoch:    build.UpgradeLiftoffHeight + 1,
		StateTree:     types.StateTreeVersion1,
		Network:       network.Version5,
		Actors:        actors.Version2,
		ZeroStateTree: (*StateTracker).ActorsZeroStateV2,
	},
}

KnownProtocolVersions enumerates the protocol versions we're capable of generating test vectors against.

Functions

func CalculateBurntGas

func CalculateBurntGas(am *ApplicableMessage) big.Int

CalculateBurntGas calculates the amount that will be burnt, a function of the gas limit and the gas actually used.

func CalculateSenderDeduction

func CalculateSenderDeduction(am *ApplicableMessage) big.Int

CalculateSenderDeduction returns the balance that shall be deducted from the sender's account as a result of applying this message.

func Deserialize

func Deserialize(b []byte, out interface{}) error

func EncodeCAR

func EncodeCAR(dagserv format.DAGService, roots ...cid.Cid) ([]byte, error)

EncodeCAR recursively writes the tree referenced by the root in CAR form into a gzipped byte buffer, and returns its bytes, ready for embedding in a test vector.

func EncodeTraces

func EncodeTraces(traces []types.ExecutionTrace) *schema.Diagnostics

EncodeTraces takes a set of serialized lotus ExecutionTraces and writes them to the test vector serialized diagnostic format.

func GetMinerReward

func GetMinerReward(am *ApplicableMessage) abi.TokenAmount

GetMinerReward returns the amount that the miner gets to keep, aka. miner tip.

func MustDeserialize

func MustDeserialize(b []byte, out interface{})

func MustIDFromAddress

func MustIDFromAddress(a address.Address) uint64

MustIDFromAddress returns the integer ID from an ID address.

func MustNewActorAddr

func MustNewActorAddr(data string) address.Address

MustNewActorAddr returns an address.Address of kind actor.

func MustNewBLSAddr

func MustNewBLSAddr(seed int64) address.Address

MustNewBLSAddr returns an address.Address of kind bls.

func MustNewIDAddr

func MustNewIDAddr(id uint64) address.Address

MustNewIDAddr returns an address.Address of kind ID.

func MustNewSECP256K1Addr

func MustNewSECP256K1Addr(pubkey string) address.Address

MustNewSECP256K1Addr returns an address.Address of kind secp256k1.

func MustNextIDAddr

func MustNextIDAddr(id address.Address) address.Address

MustNextIDAddr returns the next sequential ID address after the supplied ID address. If the argument is not an ID address, it panics.

func MustSerialize

func MustSerialize(i cbg.CBORMarshaler) []byte

func RecoverStateTree

func RecoverStateTree(ctx context.Context, raw []byte, root cid.Cid) (*state.StateTree, error)

RecoverStateTree parses a car encoding of a state tree back to a structured format

func Serialize

func Serialize(i cbg.CBORMarshaler) ([]byte, error)

Types

type Account

type Account struct {
	Handle  AddressHandle
	Initial abi.TokenAmount
}

type ActorPredicate

type ActorPredicate func(handle AddressHandle, initial *OptionalActor, final *OptionalActor, amss []*ApplicableMessage) error

ActorPredicate evaluates whether the actor that participates in the provided messages satisfies a given condition. The initial state (after preconditions) and final state (after applies) are supplied.

func BalanceUpdated

func BalanceUpdated(offset abi.TokenAmount) ActorPredicate

BalanceUpdated returns a ActorPredicate that checks whether the balance of the actor has been deducted the gas cost and the outgoing value transfers, and has been increased by the offset (or decreased, if the argument is negative).

func NonceUpdated

func NonceUpdated() ActorPredicate

NonceUpdated returns a ActorPredicate that checks whether the nonce of the actor has been updated to the nonce of the last message + 1.

type ActorState

type ActorState struct {
	Addr    address.Address
	Balance abi.TokenAmount
	Code    cid.Cid
	State   cbor.Marshaler
}

type Actors

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

Actors is an object that manages actors in the test vector.

func NewActors

func NewActors(bc *BuilderCommon, b *StateTracker) *Actors

func (*Actors) Account

func (a *Actors) Account(typ address.Protocol, balance abi.TokenAmount) AddressHandle

Account creates a single account actor of the specified kind, with the specified balance, and returns its AddressHandle.

func (*Actors) AccountHandles

func (a *Actors) AccountHandles() []AddressHandle

AccountHandles returns the AddressHandles for all registered accounts.

func (*Actors) AccountN

func (a *Actors) AccountN(typ address.Protocol, balance abi.TokenAmount, handles ...*AddressHandle)

AccountN creates many account actors of the specified kind, with the specified balance, and places their addresses in the supplied AddressHandles.

func (*Actors) Accounts

func (a *Actors) Accounts() []Account

Accounts returns all accounts that have been registered through Account() / AccountN().

Miner owner and worker accounts, despite being accounts in the strict sense of the word, are not returned here. You can get them through Miners().

Similarly, account actors registered through CreateActor() in a bare form are not returned here.

func (*Actors) Count

func (a *Actors) Count() int

Count returns the number of accounts and miners registered.

func (*Actors) HandleFor

func (a *Actors) HandleFor(addr address.Address) AddressHandle

HandleFor gets the canonical handle for a registered address, which can appear at either ID or Robust position.

func (*Actors) InitialBalance

func (a *Actors) InitialBalance(addr address.Address) abi.TokenAmount

InitialBalance returns the initial balance of an account actor that was registered during preconditions. It matches against both the ID and Robust addresses. It records an assertion failure if the actor is unknown.

func (*Actors) Miner

func (a *Actors) Miner(cfg MinerActorCfg) Miner

Miner creates an owner account, a worker account, and a miner actor with the supplied configuration.

func (*Actors) MinerN

func (a *Actors) MinerN(cfg MinerActorCfg, miners ...*Miner)

MinerN creates many miners with the specified configuration, and places the miner objects in the supplied addresses.

It is sugar for calling Miner repeatedly with the same configuration, and storing the returned miners in the provided addresses.

func (*Actors) Miners

func (a *Actors) Miners() []Miner

Miners returns all miners that have been registered through Miner() / MinerN(), along with their owner and worker account addresses.

Miners registered through CreateActor() in a bare form are not returned here.

type ActorsZeroStateFn

type ActorsZeroStateFn func(*StateTracker, schema.Selector)

ActorsZeroStateFn is the function the StateTracker will use to initialize the actors zero state.

type AddressHandle

type AddressHandle struct {
	ID, Robust address.Address
}

AddressHandle encapsulates both the ID and Robust addresses of an actor.

func (AddressHandle) IDAddr

func (ah AddressHandle) IDAddr() address.Address

func (*AddressHandle) NextActorAddress

func (ah *AddressHandle) NextActorAddress(nonce, numActorsCreated uint64) address.Address

NextActorAddress predicts the address of the next actor created by this address.

Code is adapted from vm.Runtime#NewActorAddress()

func (AddressHandle) RobustAddr

func (ah AddressHandle) RobustAddr() address.Address

func (AddressHandle) String

func (ah AddressHandle) String() string

type ApplicableMessage

type ApplicableMessage struct {
	EpochOffset abi.ChainEpoch
	Message     *types.Message
	Result      *vm.ApplyRet
	// Applied is true if this message has already been applied. Note it's
	// not safe to rely on non-nil Result as indication of application
	// since applied messages may fail without a result.
	Applied bool
	// Failed is true if this message was attempted to be applied and failed.
	// In this case ApplicableMessage.Result will be nil.
	Failed bool
	// contains filtered or unexported fields
}

ApplicableMessage represents a message to be applied on the test vector.

type ApplyRetPredicate

type ApplyRetPredicate func(ret *vm.ApplyRet) error

ApplyRetPredicate evaluates a given condition against the result of a message application.

func ExitCode

func ExitCode(expect exitcode.ExitCode) ApplyRetPredicate

ExitCode returns an ApplyRetPredicate that passes if the exit code of the message execution matches the argument.

func Failed

func Failed() ApplyRetPredicate

Failed returns an ApplyRetPredicate that passes if the message failed to be applied i.e. the receipt is nil.

func MessageReturns

func MessageReturns(expect cbg.CBORMarshaler) ApplyRetPredicate

MessageReturns returns an ApplyRetPredicate that passes if the message response matches the argument.

type Asserter

type Asserter struct {
	*require.Assertions
	// contains filtered or unexported fields
}

Asserter offers useful assertions to verify outcomes at various stages of the test vector creation.

func NewAsserter

func NewAsserter(id string, pv ProtocolVersion, lenient bool, suppliers suppliers) *Asserter

func (*Asserter) ActorExists

func (a *Asserter) ActorExists(addr address.Address)

ActorExists verifies that the actor exists in the state tree.

func (*Asserter) ActorMissing

func (a *Asserter) ActorMissing(addr address.Address)

ActorExists verifies that the actor is absent from the state tree.

func (*Asserter) AtState

func (a *Asserter) AtState(root cid.Cid) *Asserter

AtState forks this Asserter making it point to the specified state root.

func (*Asserter) BalanceEq

func (a *Asserter) BalanceEq(addr address.Address, expected abi.TokenAmount)

BalanceEq verifies that the balance of the address equals the expected one.

func (*Asserter) Errorf

func (a *Asserter) Errorf(format string, args ...interface{})

func (*Asserter) EveryMessageResultSatisfies

func (a *Asserter) EveryMessageResultSatisfies(predicate ApplyRetPredicate, except ...*ApplicableMessage)

EveryMessageResultSatisfies verifies that every message result satisfies the provided predicate.

func (*Asserter) EveryMessageSenderSatisfies

func (a *Asserter) EveryMessageSenderSatisfies(predicate ActorPredicate, except ...*ApplicableMessage)

EveryMessageSenderSatisfies is sugar for MessageSendersSatisfy(predicate, Messages.All()), but supports an exclusion set to restrict the messages that will actually be asserted.

func (*Asserter) ExitCodeEq

func (a *Asserter) ExitCodeEq(actual exitcode.ExitCode, expected exitcode.ExitCode)

ExitCodeEq verifies two exit codes are the same (and prints system codes nicely).

func (*Asserter) FailNow

func (a *Asserter) FailNow()

func (*Asserter) HeadEq

func (a *Asserter) HeadEq(addr address.Address, expected cid.Cid)

HeadEq verifies that the head of the actor equals the expected one.

func (*Asserter) In

func (a *Asserter) In(v interface{}, set ...interface{})

In is assert fluid version of require.Contains. It inverts the argument order, such that the admissible set can be supplied through assert variadic argument.

func (*Asserter) LastMessageResultSatisfies

func (a *Asserter) LastMessageResultSatisfies(predicate ApplyRetPredicate)

LastMessageResultSatisfies verifies that the last applied message result satisfies the provided predicate.

func (*Asserter) MessageSendersSatisfy

func (a *Asserter) MessageSendersSatisfy(predicate ActorPredicate, ams ...*ApplicableMessage)

EveryMessageSenderSatisfies verifies that the sender actors of the supplied messages match a condition.

This function groups ApplicableMessages by sender actor, and calls the predicate for each unique sender, passing in the initial state (when preconditions were committed), the final state (could be nil), and the ApplicableMessages themselves.

func (*Asserter) NonceEq

func (a *Asserter) NonceEq(addr address.Address, expected uint64)

NonceEq verifies that the nonce of the actor equals the expected one.

type Block

type Block = schema.Block

type Builder

type Builder interface {
	// CommitPreconditions transitions the vector from the preconditions stage
	// to the applies stage.
	CommitPreconditions()

	// CommitApplies transitions the vector from the applies stage to the
	// checks stage.
	CommitApplies()

	// Finish closes this test vector (transioning it to the terminal finished
	// stage), and returns it.
	Finish() *schema.TestVector
}

Builder is a vector builder.

It enforces a staged process for constructing a vector, starting in a "preconditions" stage, where the state tree is manipulated into the desired shape for the test to begin.

Next, the "applies" stage serves as a time to accumulate messages that will mutate the state.

Transitioning to the "checks" stage applies the messages and transitions the builder to a period where any final assertions can be made on the receipts or the state of the system.

Finally, transitioning to the "finished" stage finalizes the test vector, serializing the pre and post state trees and completing the stages.

From here the test vector can be serialized into a JSON file.

type BuilderCommon

type BuilderCommon struct {
	Stage  Stage
	Actors *Actors
	Assert *Asserter
	Wallet *Wallet

	// ProtocolVersion this vector is being built against.
	ProtocolVersion ProtocolVersion
}

BuilderCommon bundles common services and state fields that are available in all vector builder types.

type Generator

type Generator struct {
	OutputPath    string
	Mode          OverwriteMode
	IncludeFilter *regexp.Regexp
	// contains filtered or unexported fields
}

Generator is a batch generator and organizer of test vectors.

Test vector scripts are simple programs (main function). Test vector scripts can delegate to the Generator to handle the execution, reporting and capture of emitted test vectors into files.

Generator supports the following CLI flags:

 -o <directory>
		directory where test vector JSON files will be saved; if omitted,
		vectors will be written to stdout.

 -u
		update any existing test vector files in the output directory IF their
		content has changed. Note `_meta` is ignored when checking equality.

 -f
		force regeneration and overwrite any existing vectors in the output
		directory.

 -i <include regex>
		regex inclusion filter to select a subset of vectors to execute; matched
		against the vector's ID.

 TODO
 -v <protocol versions, comma-separated>
     protocol version variants to generate; if not provided, all supported
     protocol versions as declared by the vector will be attempted

Scripts can bundle test vectors into "groups". The generator will execute each group in parallel, and will write each vector in a file: <output_dir>/<group>--<vector_id>.json

func NewGenerator

func NewGenerator() *Generator

func (*Generator) Close

func (g *Generator) Close()

func (*Generator) Group

func (g *Generator) Group(group string, vectors ...*VectorDef)

type MessageVectorBuilder

type MessageVectorBuilder struct {
	*BuilderCommon

	StateTracker *StateTracker
	Messages     *Messages

	PreRoot  cid.Cid
	PostRoot cid.Cid
	// contains filtered or unexported fields
}

MessageVectorBuilder is a helper for building a message-class test vector. It enforces a staged process for constructing a vector, starting in a "preconditions" stage, where the state tree is manipulated into the desired shape for the test to begin. Next, the "applies" stage serves as a time to accumulate messages that will mutate the state. Transitioning to the "checks" stage applies the messages and transitions the builder to a period where any final assertions can be made on the receipts or the state of the system. Finally, transitioning to the "finished" stage finalizes the test vector, serializing the pre and post state trees and completing the stages. From here the test vector can be serialized into a JSON file.

TODO use stage.Surgeon with non-proxying blockstore.

func MessageVector

func MessageVector(metadata *schema.Metadata, selector schema.Selector, mode Mode, hints []string, pv ProtocolVersion) *MessageVectorBuilder

MessageVector creates a builder for a message-class vector.

func (*MessageVectorBuilder) CommitApplies

func (b *MessageVectorBuilder) CommitApplies()

CommitApplies applies all accumulated messages. For each message it records the new state root, refreshes the state tree, and updates the underlying vector with the message and its receipt.

This method progresses the builder into the "checks" stage and may only be called during the "applies" stage.

func (*MessageVectorBuilder) CommitPreconditions

func (b *MessageVectorBuilder) CommitPreconditions()

CommitPreconditions flushes the state tree, recording the new CID in the underlying test vector's precondition.

This method progesses the builder into the "applies" stage and may only be called during the "preconditions" stage.

func (*MessageVectorBuilder) Finish

func (b *MessageVectorBuilder) Finish() *schema.TestVector

Finish signals to the builder that the checks stage is complete and that the test vector can be finalized. It creates a CAR from the recorded state root in it's pre and post condition and serializes the CAR into the test vector.

This method progresses the builder into the "finished" stage and may only be called during the "checks" stage.

func (*MessageVectorBuilder) SetBaseFee

func (b *MessageVectorBuilder) SetBaseFee(basefee abi.TokenAmount)

SetBaseFee sets the base fee for this vector. If not set, the driver should use 100 attoFIL as the base fee when executing this vector.

func (*MessageVectorBuilder) SetCirculatingSupply

func (b *MessageVectorBuilder) SetCirculatingSupply(supply abi.TokenAmount)

SetCirculatingSupply sets the circulating supply for this vector. If not set, the driver should use the total maximum supply of Filecoin as specified in the protocol when executing these messages.

type Messages

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

Messages accumulates the messages to be executed within the test vector.

func NewMessages

func NewMessages(bc *BuilderCommon, st *StateTracker) *Messages

func (*Messages) All

func (m *Messages) All() []*ApplicableMessage

All returns all ApplicableMessages that have been accumulated, in the same order they were added.

func (*Messages) ApplyN

func (m *Messages) ApplyN(ams ...*ApplicableMessage)

ApplyN calls ApplyOne for the supplied messages, in the order they are passed. The constraints described in ApplyOne apply.

func (*Messages) ApplyOne

func (m *Messages) ApplyOne(am *ApplicableMessage)

ApplyOne applies the provided message. The following constraints are checked:

  • all previous messages have been applied.
  • we know about this message (i.e. it has been added through Typed, Raw or Sugar).

func (*Messages) Include

func (m *Messages) Include(msgs ...*ApplicableMessage)

Include adds messages that have already been created into this vector. It creates a shallow copy of the incoming messages, and erases any pre-existing results, prior to adding them.

func (*Messages) Message

func (m *Messages) Message(msg *types.Message, opts ...MsgOpt) *ApplicableMessage

Message adds a message using the provided *types.Message and applying the supplied opts.

func (*Messages) Raw

func (m *Messages) Raw(from, to address.Address, method abi.MethodNum, params []byte, opts ...MsgOpt) *ApplicableMessage

Raw adds a raw message to this message accumulator.

func (*Messages) SetDefaults

func (m *Messages) SetDefaults(opts ...MsgOpt) *Messages

SetDefaults sets default options for all messages.

func (*Messages) Sugar

func (m *Messages) Sugar() *sugarMsg

Sugar is the namespace for sugared message constructors.

func (*Messages) Typed

func (m *Messages) Typed(from, to address.Address, typedm TypedCall, opts ...MsgOpt) *ApplicableMessage

Typed adds a typed call to this message accumulator.

type Metadata

type Metadata = schema.Metadata

type Miner

type Miner struct {
	MinerActorAddr, OwnerAddr, WorkerAddr AddressHandle
}

type MinerActorCfg

type MinerActorCfg struct {
	SealProofType  abi.RegisteredSealProof
	PeriodBoundary abi.ChainEpoch
	OwnerBalance   abi.TokenAmount
}

type Mode

type Mode int

Mode tunes certain elements of how the generation and assertion of a test vector will be conducted, such as being lenient to assertion failures when a vector is knowingly incorrect. Refer to the Mode* constants for further information.

const (
	// ModeStandard is the implicit mode (0). In this mode, assertion failures
	// cause the vector generation to abort.
	ModeStandard Mode = iota

	// ModeLenientAssertions allows generation to proceed even if assertions
	// fail. Use it when you know that a test vector is broken in the reference
	// implementation, but want to generate it anyway.
	//
	// Consider using Hints to convey to drivers how they should treat this
	// test vector.
	ModeLenientAssertions
)

type MsgOpt

type MsgOpt func(*msgOpts)

MsgOpt is an option configuring message value, gas parameters, execution epoch, and other elements.

func EpochOffset

func EpochOffset(epoch abi.ChainEpoch) MsgOpt

EpochOffset sets the epoch offset in which a message is to be executed.

func GasFeeCap

func GasFeeCap(feeCap int64) MsgOpt

GasFeeCap sets the gas fee cap of a message.

func GasLimit

func GasLimit(limit int64) MsgOpt

GasLimit sets the gas limit of a message.

func GasPremium

func GasPremium(premium int64) MsgOpt

GasPremium sets the gas premium of a message.

func Nonce

func Nonce(n uint64) MsgOpt

Nonce sets the nonce of a message.

func Value

func Value(value big.Int) MsgOpt

Value sets a value on a message.

type OptionalActor

type OptionalActor = types.Actor

OptionalActor is a marker type to warn that the value can be nil.

type OverwriteMode

type OverwriteMode int

OverwriteMode is the mode used when overwriting existing test vector files.

const (
	// OverwriteNone will not overwrite existing test vector files.
	OverwriteNone OverwriteMode = iota
	// OverwriteUpdate will update test vector files if they're different.
	OverwriteUpdate
	// OverwriteForce will force overwrite the vector files.
	OverwriteForce
)

type ProtocolVersion

type ProtocolVersion struct {
	// ID is the code name of the version. It is output as a selector
	// on vectors.
	ID string

	// Height is the height at which the version activates. It is used to
	// calculate the variant's epoch.
	FirstEpoch abi.ChainEpoch

	// Network is the network version. It is output on the variant's epoch.
	Network network.Version

	// StateTree is the state tree version.
	StateTree types.StateTreeVersion

	// Actors is the actors version.
	Actors actors.Version

	// ZeroStateTree is the constructor of the initial state tree, including
	// singleton system actors.
	ZeroStateTree func(*StateTracker, schema.Selector)
}

ProtocolVersion represents a protocol upgrade we track.

func KnownProtocolVersionsBefore

func KnownProtocolVersionsBefore(id string) []ProtocolVersion

KnownProtocolVersionsBefore returns all protocol versions known until the protocol version with the supplied ID, it exclusive.

func KnownProtocolVersionsBetween

func KnownProtocolVersionsBetween(from, to string) []ProtocolVersion

KnownProtocolVersionsBetween returns all protocol versions known between the supplied range, both inclusive.

func KnownProtocolVersionsFrom

func KnownProtocolVersionsFrom(id string) []ProtocolVersion

KnownProtocolVersionsFrom returns all protocol versions known starting from the protocol version with the supplied ID, it inclusive.

type RewardSummary

type RewardSummary struct {
	Treasury           abi.TokenAmount
	EpochReward        abi.TokenAmount
	NextPerBlockReward abi.TokenAmount
}

RewardSummary holds the state we care about insofar rewards are concerned, at every epoch where we perform an observation.

type Rewards

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

Rewards tracks RewardSummary objects throughout chain history.

func NewRewards

func NewRewards(bc *BuilderCommon, st *StateTracker) *Rewards

NewRewards creates a new Rewards object.

func (*Rewards) ForEpochOffset

func (r *Rewards) ForEpochOffset(epochOffset int64) *RewardSummary

ForEpochOffset returns the RewardSummary (or nil) associated with the given epoch offset.

func (*Rewards) RecordAt

func (r *Rewards) RecordAt(epochOffset int64)

RecordAt records a RewardSummary associated with the supplied epoch, by accessing the latest version of the statetree.

type Stage

type Stage string

Stage is an identifier for the current stage a MessageVectorBuilder is in.

type StateTracker

type StateTracker struct {
	StateTreeVersion types.StateTreeVersion
	ActorsVersion    actors.Version

	Stores    *Stores
	StateTree *state.StateTree
	Driver    *conformance.Driver

	CurrRoot cid.Cid

	EmptyObjectCid       cid.Cid
	EmptyArrayCid        cid.Cid
	EmptyMapCid          cid.Cid
	EmptyMultiMapCid     cid.Cid
	EmptyBitfieldCid     cid.Cid
	EmptyDeadlinesCid    cid.Cid
	EmptyVestingFundsCid cid.Cid
	// contains filtered or unexported fields
}

StateTracker is an object for tracking state and mutating it by applying messages.

func NewStateTracker

func NewStateTracker(bc *BuilderCommon, selector schema.Selector, vector *schema.TestVector, stVersion types.StateTreeVersion, actorsVersion actors.Version, zeroFn ActorsZeroStateFn) *StateTracker

func (*StateTracker) ActorState

func (st *StateTracker) ActorState(addr address.Address, out cbg.CBORUnmarshaler) *types.Actor

ActorState retrieves the state of the supplied actor, and sets it in the provided object. It also returns the actor's header from the state tree.

func (*StateTracker) ActorsZeroStateV0

func (st *StateTracker) ActorsZeroStateV0(selector schema.Selector)

func (*StateTracker) ActorsZeroStateV2

func (st *StateTracker) ActorsZeroStateV2(selector schema.Selector)

func (*StateTracker) ApplyMessage

func (st *StateTracker) ApplyMessage(am *ApplicableMessage)

ApplyMessage executes the provided message via the driver, records the new root, refreshes the state tree, and updates the underlying vector with the message and its receipt.

func (*StateTracker) Balance

func (st *StateTracker) Balance(addr address.Address) abi.TokenAmount

Balance is a shortcut for Header(addr).Balance.

func (*StateTracker) Code

func (st *StateTracker) Code(addr address.Address) cid.Cid

Code is a shortcut for Header(addr).Code.

func (*StateTracker) CreateActor

func (st *StateTracker) CreateActor(code cid.Cid, addr address.Address, balance abi.TokenAmount, state cbor.Marshaler) AddressHandle

CreateActor creates an actor in the state tree, of the specified kind, with the specified address and balance, and sets its state to the supplied state.

func (*StateTracker) Flush

func (st *StateTracker) Flush() cid.Cid

Flush calls Flush on the StateTree, and records the CurrRoot.

func (*StateTracker) Fork

func (st *StateTracker) Fork(root cid.Cid) *StateTracker

Fork forks this state tracker into a new one, using the provided cid.Cid as the root CID.

func (*StateTracker) Head

func (st *StateTracker) Head(addr address.Address) cid.Cid

Head is a shortcut for Header(addr).Head.

func (*StateTracker) Header

func (st *StateTracker) Header(addr address.Address) *types.Actor

Header returns the actor's header from the state tree.

func (*StateTracker) Load

func (st *StateTracker) Load(root cid.Cid)

Load sets the state tree to the one indicated by this root.

func (*StateTracker) Nonce

func (st *StateTracker) Nonce(addr address.Address) uint64

Nonce is a shortcut for Header(addr).Nonce.

type Stores

type Stores struct {
	CBORStore    cbor.IpldStore
	ADTStore     adt.Store
	Datastore    ds.Batching
	Blockstore   blockstore.Blockstore
	BlockService blockservice.BlockService
	Exchange     exchange.Interface
	DAGService   format.DAGService
}

Stores is a collection of the different stores and services that are needed to deal with the data layer of Filecoin, conveniently interlinked with one another.

func NewLocalStores

func NewLocalStores(ctx context.Context) *Stores

NewLocalStores creates a Stores object that operates entirely in-memory with no read-through remote fetch fallback.

func NewProxyingStore

func NewProxyingStore(ctx context.Context, api api.FullNode) *Stores

NewProxyingStore is a Stores that proxies get requests for unknown CIDs to a Filecoin node, via the ChainReadObj RPC.

type Tipset

type Tipset struct {

	// PostStateRoot stores the state root CID after applying this tipset.
	// It can be used with Asserter#AtState to obtain an asserter against that
	// state root.
	PostStateRoot cid.Cid

	schema.Tipset
	// contains filtered or unexported fields
}

func (*Tipset) Block

func (ts *Tipset) Block(miner Miner, winCount int64, msgs ...*ApplicableMessage)

Block adds a new block to this tipset, produced by the indicated miner, with the supplied wincount, and containing the listed (and previously staged) msgIdx.

type TipsetSeq

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

TipsetSeq is a sequence of tipsets to be applied during the test. TipsetSeq provides methods to build a sequence of tipsets, such as adding new tipsets and null rounds.

func NewTipsetSeq

func NewTipsetSeq(initialEpoch abi.ChainEpoch) *TipsetSeq

NewTipsetSeq returns a new TipSetSeq object initialized at the provided epoch.

func (*TipsetSeq) All

func (tss *TipsetSeq) All() []*Tipset

All returns all tipsets that have been registered.

func (*TipsetSeq) Messages

func (tss *TipsetSeq) Messages() []*ApplicableMessage

Messages returns all ApplicableMessages that have been included in blocks, ordered based on inclusion in the tipset.

func (*TipsetSeq) Next

func (tss *TipsetSeq) Next(baseFee abi.TokenAmount) *Tipset

Next enrols a new Tipset, with the supplied base fee, and advances the epoch by 1.

func (*TipsetSeq) NullRounds

func (tss *TipsetSeq) NullRounds(count uint64)

NullRounds enrols as many null rounds as indicated, advancing the epoch by the count.

type TipsetVectorBuilder

type TipsetVectorBuilder struct {
	*BuilderCommon

	// StagedMessages is a staging area for messages.
	StagedMessages *Messages
	// StateTracker is used for staging messages, and it's scrapped and replaced
	// by a fork at the PreRoot when committing applies.
	StateTracker *StateTracker

	InitialEpochOffset abi.ChainEpoch

	Tipsets *TipsetSeq
	Rewards *Rewards

	PreRoot  cid.Cid
	PostRoot cid.Cid
	// contains filtered or unexported fields
}

TipsetVectorBuilder builds a tipset-class vector. It follows the same staged approach as MessageVectorBuilder.

During the precondition stage, the user sets up the pre-existing state of the system, including the miners that are going to be producing the blocks comprising the vector. If the initial epoch is different to 0, the user must also set it during the precondition stage via SetInitialEpochOffset.

During the application stage, the user stages the messages they later want to incorporate to a block in the StagedMessages object. Messages applied have no effect on the vector itself. The entire state is scrapped.

Tipsets are registered in the Tipsets object, by calling Tipset#Next. This "opens" a new tipset at the next epoch, starting at the initial epoch set by SetInitialEpochOffset, and internally incrementing the counter by one.

To register blocks on a tipset, call Tipset#Block, supplying the miner, win count, and the messages to enroll. Messages need to have been staged previously.

func TipsetVector

func TipsetVector(metadata *schema.Metadata, selector schema.Selector, mode Mode, hints []string, pv ProtocolVersion) *TipsetVectorBuilder

TipsetVector creates a new TipsetVectorBuilder. For usage details, read the godocs on that type.

func (*TipsetVectorBuilder) CommitApplies

func (b *TipsetVectorBuilder) CommitApplies()

CommitApplies applies all accumulated tipsets. It updates the vector after every tipset application, and records the Rewards state existing at that epoch under the Rewards object.

It also sets the PostStateRoot on each applied Tipset, which can be used in combination with StateTracker#Fork and Asserter#AtState to load and assert on state at an interim tipset.

This method progresses the builder into the "checks" stage and may only be called during the "applies" stage.

func (*TipsetVectorBuilder) CommitPreconditions

func (b *TipsetVectorBuilder) CommitPreconditions()

CommitPreconditions flushes the state tree, recording the new CID in the underlying test vector's precondition. It creates the StagedMessages and Tipsets object where messages will be staged, and tipsets will be registered.

This method progesses the builder into the "applies" stage and may only be called during the "preconditions" stage.

func (*TipsetVectorBuilder) Finish

func (b *TipsetVectorBuilder) Finish() *schema.TestVector

Finish signals to the builder that the checks stage is complete and that the test vector can be finalized. It writes the test vector to the supplied io.Writer.

This method progresses the builder into the "finished" stage and may only be called during the "checks" stage.

func (*TipsetVectorBuilder) SetInitialEpochOffset

func (b *TipsetVectorBuilder) SetInitialEpochOffset(epoch abi.ChainEpoch)

SetInitialEpochOffset sets the initial epoch offset of this tipset-class vector. It MUST be called during the preconditions stage.

type TypedCall

type TypedCall func(m *Messages) (method abi.MethodNum, params []byte)

TypedCall represents a call to a known built-in actor kind.

func AccountConstructor

func AccountConstructor(params *address.Address) TypedCall

func AccountPubkeyAddress

func AccountPubkeyAddress(params *abi.EmptyValue) TypedCall

func ChaosSend

func ChaosSend(args *chaos.SendArgs) TypedCall

ChaosSend is a message to a chaos actor that sends a message to another actor.

func CronConstructor

func CronConstructor(params *cron.ConstructorParams) TypedCall

func CronEpochTick

func CronEpochTick(params *abi.EmptyValue) TypedCall

func InitConstructor

func InitConstructor(params *init_.ConstructorParams) TypedCall

func InitExec

func InitExec(params *init_.ExecParams) TypedCall

func MarketActivateDeals

func MarketActivateDeals(params *market.ActivateDealsParams) TypedCall

func MarketAddBalance

func MarketAddBalance(params *address.Address) TypedCall

func MarketComputeDataCommitment

func MarketComputeDataCommitment(params *market.ComputeDataCommitmentParams) TypedCall

func MarketConstructor

func MarketConstructor(params *abi.EmptyValue) TypedCall

func MarketCronTick

func MarketCronTick(params *abi.EmptyValue) TypedCall

func MarketOnMinerSectorsTerminate

func MarketOnMinerSectorsTerminate(params *market.OnMinerSectorsTerminateParams) TypedCall

func MarketPublishStorageDeals

func MarketPublishStorageDeals(params *market.PublishStorageDealsParams) TypedCall

func MarketVerifyDealsForActivation

func MarketVerifyDealsForActivation(params *market.VerifyDealsForActivationParams) TypedCall

func MarketWithdrawBalance

func MarketWithdrawBalance(params *market.WithdrawBalanceParams) TypedCall

func MinerAddLockedFund

func MinerAddLockedFund(params *big.Int) TypedCall

func MinerChangeMultiaddrs

func MinerChangeMultiaddrs(params *miner.ChangeMultiaddrsParams) TypedCall

func MinerChangePeerID

func MinerChangePeerID(params *miner.ChangePeerIDParams) TypedCall

func MinerChangeWorkerAddress

func MinerChangeWorkerAddress(params *miner.ChangeWorkerAddressParams) TypedCall

func MinerCheckSectorProven

func MinerCheckSectorProven(params *miner.CheckSectorProvenParams) TypedCall

func MinerConfirmSectorProofsValid

func MinerConfirmSectorProofsValid(params *builtin.ConfirmSectorProofsParams) TypedCall

func MinerConstructor

func MinerConstructor(params *power.MinerConstructorParams) TypedCall

func MinerControlAddresses

func MinerControlAddresses(params *abi.EmptyValue) TypedCall

func MinerDeclareFaults

func MinerDeclareFaults(params *miner.DeclareFaultsParams) TypedCall

func MinerDeclareFaultsRecovered

func MinerDeclareFaultsRecovered(params *miner.DeclareFaultsRecoveredParams) TypedCall

func MinerExtendSectorExpiration

func MinerExtendSectorExpiration(params *miner.ExtendSectorExpirationParams) TypedCall

func MinerOnDeferredCronEvent

func MinerOnDeferredCronEvent(params *miner.CronEventPayload) TypedCall

func MinerPreCommitSector

func MinerPreCommitSector(params *miner.SectorPreCommitInfo) TypedCall

func MinerProveCommitSector

func MinerProveCommitSector(params *miner.ProveCommitSectorParams) TypedCall

func MinerReportConsensusFault

func MinerReportConsensusFault(params *miner.ReportConsensusFaultParams) TypedCall

func MinerSubmitWindowedPoSt

func MinerSubmitWindowedPoSt(params *miner.SubmitWindowedPoStParams) TypedCall

func MinerTerminateSectors

func MinerTerminateSectors(params *miner.TerminateSectorsParams) TypedCall

func MinerWithdrawBalance

func MinerWithdrawBalance(params *miner.WithdrawBalanceParams) TypedCall

func MultisigAddSigner

func MultisigAddSigner(params *multisig.AddSignerParams) TypedCall

func MultisigChangeNumApprovalsThreshold

func MultisigChangeNumApprovalsThreshold(params *multisig.ChangeNumApprovalsThresholdParams) TypedCall

func MultisigRemoveSigner

func MultisigRemoveSigner(params *multisig.RemoveSignerParams) TypedCall

func MultisigSwapSigner

func MultisigSwapSigner(params *multisig.SwapSignerParams) TypedCall

func PowerConstructor

func PowerConstructor(params *abi.EmptyValue) TypedCall

func PowerCreateMiner

func PowerCreateMiner(params *power.CreateMinerParams) TypedCall

func PowerCurrentTotalPower

func PowerCurrentTotalPower(params *abi.EmptyValue) TypedCall

func PowerEnrollCronEvent

func PowerEnrollCronEvent(params *power.EnrollCronEventParams) TypedCall

func PowerOnConsensusFault

func PowerOnConsensusFault(params *big.Int) TypedCall

func PowerOnEpochTickEnd

func PowerOnEpochTickEnd(params *abi.EmptyValue) TypedCall

func PowerSubmitPoRepForBulkVerify

func PowerSubmitPoRepForBulkVerify(params *proof.SealVerifyInfo) TypedCall

func PowerUpdateClaimedPower

func PowerUpdateClaimedPower(params *power.UpdateClaimedPowerParams) TypedCall

func PowerUpdatePledgeTotal

func PowerUpdatePledgeTotal(params *big.Int) TypedCall

func RewardAwardBlockReward

func RewardAwardBlockReward(params *reward.AwardBlockRewardParams) TypedCall

func RewardConstructor

func RewardConstructor(params *abi.EmptyValue) TypedCall

func RewardThisEpochReward

func RewardThisEpochReward(params *abi.EmptyValue) TypedCall

func RewardUpdateNetworkKPI

func RewardUpdateNetworkKPI(params *big.Int) TypedCall

func Transfer

func Transfer() TypedCall

type VectorDef

type VectorDef struct {
	Metadata *schema.Metadata
	Selector schema.Selector

	// SupportedVersions enumerates the versions this vector is supported
	// against. If nil or empty, this vector is valid for all known versions
	// (as per KnownProtocolVersions).
	SupportedVersions []ProtocolVersion

	// Hints are arbitrary flags that convey information to the driver.
	// Use hints to express facts like this vector is knowingly incorrect
	// (e.g. when the reference implementation is broken), or that drivers
	// should negate the postconditions (i.e. test that they are NOT the ones
	// expressed in the vector), etc.
	//
	// Refer to the schema.Hint* constants for common hints.
	Hints []string

	// Mode tunes certain elements of how the generation and assertion of
	// a test vector will be conducted, such as being lenient to assertion
	// failures when a vector is knowingly incorrect. Refer to the Mode*
	// constants for further information.
	Mode Mode

	// MessageFunc if non-nil, declares this vector as a message-class vector,
	// generated by the specified builder.
	MessageFunc func(v *MessageVectorBuilder)

	// TipsetFunc if non-nil, declares this vector as a tipset-class vector,
	// generated by the specified builder.
	TipsetFunc func(v *TipsetVectorBuilder)
}

type Wallet

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

func NewWallet

func NewWallet() *Wallet

func (*Wallet) NewBLSAccount

func (w *Wallet) NewBLSAccount() address.Address

func (*Wallet) NewSECP256k1Account

func (w *Wallet) NewSECP256k1Account() address.Address

func (*Wallet) Sign

func (w *Wallet) Sign(addr address.Address, data []byte) (*acrypto.Signature, error)

Jump to

Keyboard shortcuts

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