Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(content): filecoin VM interface update #1056

Merged
merged 4 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions content/systems/filecoin_vm/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,43 @@ description: VM - Virtual Machine
bookCollapseSection: true
weight: 3
dashboardWeight: 2
dashboardState: wip
dashboardState: incomplete
dashboardAudit: 0
dashboardTests: 0
---

# VM - Virtual Machine
---

{{<embed src="vm.id" lang="go" >}}
An Actor in the Filecoin Blockchain is the equivalent of the smart contract in the Ethereum Virtual Machine. Actors carry the logic needed in order to submit transactions, proofs and blocks, among other things, to the Filecoin blockchain. Every actor is identified by a unique address.

The Filecoin Virtual Machine (VM) is the system component that is in charge of execution of all actors code. Execution of actors on the Filecoin VM (i.e., on-chain executions) incur a gas cost.

Any operation applied (i.e., executed) on the Filecoin VM produces an output in the form of a _State Tree_ (discussed below). The latest _State Tree_ is the current source of truth in the Filecoin Blockchain. The _State Tree_ is identified by a CID, which is stored in the IPLD store.

```go
type VM struct {
## The current State Tree
cstate *state.StateTree

## The CID (i.e., identifier) of the current State Tree
base cid.Cid

## The IPLD store of the CID (of the current State Tree)
cst *cbor.BasicIpldStore

## Current BlockStore
buf *bufbstore.BufferedBS

## The epoch number where the VM has been called
blockHeight abi.ChainEpoch

## The method invoking a State Tree change
inv *Invoker

## Randomness included in messages submitted to the VM
rand Rand

Syscalls runtime.Syscalls
yiannisbot marked this conversation as resolved.
Show resolved Hide resolved
}
```
58 changes: 55 additions & 3 deletions content/systems/filecoin_vm/actor/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,67 @@
title: Actor
weight: 1
dashboardWeight: 2
dashboardState: incorrect
dashboardState: incomplete
dashboardAudit: 0
dashboardTests: 0
---

# VM Actor Interface
---

As mentioned above, Actors are the Filecoin equivalent of smart contracts in the Ethereum Virtual Machine. As such, Actors are very central components of the system. Any change to the current state of the Filecoin blockchain has to be triggered through an actor method invocation.

{{<embed src="actor.id" lang="go" >}}
This sub-section describes the _interface_ between Actors and the Filecoin Virtual Machine. This means that most of what is described below does not strictly belong to the VM. Instead it is logic that sits on the interface between the VM and Actors logic.

{{<embed src="actor.go" lang="go" >}}
There are eleven (11) types of _builtin_ Actors in total, not all of which interact with the VM. Some Actors do not invoke changes to the StateTree of the blockchain and as such do not need to have an interface to the VM. We discuss the details of all System Actors later on in the System Actors subsection.
yiannisbot marked this conversation as resolved.
Show resolved Hide resolved

Every Actor is identified by a Code ID (CID), not to be confused with the traditional, IPFS-style Content Identifier (also CID). The builtin actor structure is composed of the `abi.Infokee` of the actor and the actor's CID.

```go
var _ abi.Invokee = BuiltinActor{}

type BuiltinActor struct {
actor abi.Invokee
code cid.Cid
}

// Code is the CodeID (cid) of the actor.
func (b BuiltinActor) Code() cid.Cid {
return b.code
}

// Exports returns a slice of callable Actor methods.
func (b BuiltinActor) Exports() []interface{} {
return b.actor.Exports()
}
```

The `ActorState` structure is composed of the actor's balance, in terms of tokens held by this actor, as well as a group of state methors used to query, inspect and interact with chain state. All methods take a TipSetKey as a parameter. The state looked up is the state at that tipset. A nil TipSetKey can be provided as a param, this will cause the heaviest tipset in the chain to be used.

```go
type ActorState struct {
Balance types.BigInt
State interface{}
}
```

```go

// FullNode API is a low-level interface to the Filecoin network full node
type FullNode interface {
yiannisbot marked this conversation as resolved.
Show resolved Hide resolved
Common

...

// StateCall runs the given message and returns its result without any persisted changes.
StateCall(context.Context, *types.Message, types.TipSetKey) (*InvocResult, error)
// StateReplay returns the result of executing the indicated message, assuming it was executed in the indicated tipset.
StateReplay(context.Context, types.TipSetKey, cid.Cid) (*InvocResult, error)
// StateGetActor returns the indicated actor's nonce and balance.
StateGetActor(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*types.Actor, error)
// StateReadState returns the indicated actor's state.
StateReadState(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*ActorState, error)
// StateListMessages looks back and returns all messages with a matching to or from address, stopping at the given height.
StateListMessages(ctx context.Context, match *types.Message, tsk types.TipSetKey, toht abi.ChainEpoch) ([]cid.Cid, error)
}
yiannisbot marked this conversation as resolved.
Show resolved Hide resolved
```