Actors are smart contracts that run on the Filecoin virtual machine (FVM) and are used to manage, query, and update the state of the Filecoin network. Smart contracts are small, self-executing blocks.
Built-in actors are how the Filecoin network manages and updates global state. The global state of the network at a given epoch can be thought of as the set of blocks agreed upon via network consensus in that epoch. This global state is represented as a state tree, which maps an actor to an actor state. An actor state describes the current conditions for an individual actor, such as its FIL balance and its nonce. In Filecoin, actors trigger a state transition by sending a message. Each block in the chain can be thought of as a proposed global state, where the block selected by network consensus sets the new global state. Each block contains a series of messages and a checkpoint of the current global state after the application of those messages. The Filecoin Virtual Machine (FVM) is the Filecoin network component that is in charge of the execution of all actor code.
A basic example of how actors are used in Filecoin is the process by which storage providers prove storage and are subsequently rewarded. The process is as follows:
- 2.The storage provider is awarded storage power based on whether the proof is valid or not.
Each block in the Filecoin chain contains the following:
- Inline data such as current block height.
- A pointer to the current state tree.
- A pointer to the set of messages that, when applied to the network, generated the current state tree.
- Actors, like FIL balance, nonce, and a pointer (CID) to actor state data.
- Messages in the current block
Like the state tree, a Merkle Directed Acyclic Graph (Merkle DAG) is used to map the set of messages for a given block. Nodes in the messages may contain information on:
- The actor the message was sent to
- The actor that sent the message
- Target method to call on the actor being sent the message
- A cryptographic signature for verification
- The amount of FIL transferred between actors
The code that defines an actor in the Filecoin network is separated into different methods. Messages sent to an actor contain information on which method(s) to call and the input parameters for those methods. Additionally, actor code interacts with a runtime object, which contains information on the general state of the network, such as the current epoch, cryptographic signatures, and proof validations. Like smart contracts in other blockchains, actors must pay a gas fee, which is some predetermined amount of FIL to offset the cost (network resources used, etc.) of a transaction. Every actor has a Filecoin balance attributed to it, a state pointer, a code that tells the system what type of actor it is, and a nonce, which tracks the number of messages sent by this actor.
The 11 different types of built-in actors are as follows:
CronActorsends messages to the
StorageMarketActorat the end of each epoch. The messages sent by
CronActorindicate to StoragePowerActor and StorageMarketActor how they should maintain the internal state and process deferred events. This system actor is instantiated in the genesis block and interacts directly with the FVM.
InitActorcan initialize new actors on the Filecoin network. This system actor is instantiated in the genesis block and maintains a table resolving a public key and temporary actor addresses to their canonical ID addresses. The
InitActorinteracts directly with the FVM.
AccountActoris responsible for user accounts. Account actors are not created by the
InitActorbut by sending a message to a public-key style address. The account actor updates the state tree with a new actor address and interacts directly with the FVM.
RewardActormanages unminted Filecoin tokens and distributes rewards directly to miner actors, where they are locked for vesting. The reward value used for the current epoch is updated at the end of an epoch. The
RewardActorinteracts directly with the FVM.
StorageMarketActoris responsible for processing and managing on-chain deals. This is also the entry point of all storage deals and data into the system. This actor keeps track of storage deals and the locked balances of both the client storing data and the storage provider. When a deal is posted on-chain through the
StorageMarketActor, the actor will first check if both transacting parties have sufficient balances locked up and include the deal on-chain. Additionally, the
StorageMarketActorholds Storage Deal Collateral provided by the storage provider to collateralize deals. This collateral is returned to the storage provider when all deals in the sector successfully conclude. This actor does not interact directly with the FVM.
StorageMinerActoris created by the
StoragePowerActorand is responsible for storage mining operations and the collection of mining proofs. This actor is a key part of the Filecoin storage mining subsystem, which ensures a storage miner can effectively commit storage to Filecoin and handles the following:
- Committing new storage
- Continuously proving storage
- Declaring storage faults
- Recovering from storage faults
This actor does not interact directly with the FVM.
MultisigActoris responsible for dealing with operations involving the Filecoin wallet and represents a group of transaction signers with a maximum of 256. Signers may be external users or the
MultisigActoritself. This actor does not interact directly with the FVM.
PaymentChannelActorcreates and manages payment channels, a mechanism for off-chain microtransactions for Filecoin dApps to be reconciled on-chain at a later time with less overhead than a standard on-chain transaction and no gas costs. Payment channels are uni-directional and can be funded by adding to their balance. To create a payment channel and deposit fund, a user calls the
PaymentChannelActor. This actor does not interact directly with the FVM.
StoragePowerActoris responsible for keeping track of the storage power allocated to each storage miner and has the ability to create a
StorageMinerActor. This actor does not interact directly with the FVM.
VerifiedRegistryActoris responsible for managing Filecoin Plus (Fil+) clients. This actor can add a verified client to the Fil+ program, remove and reclaim expired DataCap allocations, and manage claims. This actor does not interact directly with the FVM.
A user actor is code defined by any developer that can interact with the FVM, otherwise known as a smart contract.
A smart contract is a small, self-executing block of custom code that runs on other blockchains, like Ethereum. In the Filecoin network, the term is a synonym for user actor. You may see the term smart contract used in tandem with user actor, but there is no difference between the two.
With the FVM, actors can be written in Solidity. In future updates, any language that compiles to WASM will be supported. With user actors, users can create and enforce custom rules for storing and accessing data on the network. The FVM is responsible for actors and ensuring that they are executed correctly and securely.