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

Actors v3 Setup #1001

Merged
merged 10 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 11 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion types/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ use serde::{Deserialize, Serialize};
pub enum StateTreeVersion {
/// Corresponds to actors < v2
V0,
/// Corresponds to actors >= v2
/// Corresponds to actors = v2
V1,
/// Corresponds to actors >= v3
V2,
}

#[derive(Deserialize_tuple, Serialize_tuple)]
Expand Down
2 changes: 1 addition & 1 deletion vm/actor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "forest_actor"
description = "Actors for the Filecoin protocol"
version = "1.0.0"
version = "2.0.0"
license = "MIT OR Apache-2.0"
authors = ["ChainSafe Systems <info@chainsafe.io>"]
edition = "2018"
Expand Down
2 changes: 1 addition & 1 deletion vm/actor/src/builtin/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use num_traits::FromPrimitive;
use runtime::{ActorCode, Runtime};
use vm::{actor_error, ActorError, ExitCode, MethodNum, Serialized, METHOD_CONSTRUCTOR};

// * Updated to specs-actors commit: e195950ba98adb8ce362030356bf4a3809b7ec77 (v2.3.2)
// * Updated to specs-actors commit: 845089a6d2580e46055c24415a6c32ee688e5186 (v3.0.0)

/// Account actor methods available
#[derive(FromPrimitive)]
Expand Down
24 changes: 12 additions & 12 deletions vm/actor/src/builtin/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
use cid::{multihash::MultihashDigest, Cid, Code::Identity, RAW};

lazy_static! {
pub static ref SYSTEM_ACTOR_CODE_ID: Cid = make_builtin(b"fil/2/system");
pub static ref INIT_ACTOR_CODE_ID: Cid = make_builtin(b"fil/2/init");
pub static ref CRON_ACTOR_CODE_ID: Cid = make_builtin(b"fil/2/cron");
pub static ref ACCOUNT_ACTOR_CODE_ID: Cid = make_builtin(b"fil/2/account");
pub static ref POWER_ACTOR_CODE_ID: Cid = make_builtin(b"fil/2/storagepower");
pub static ref MINER_ACTOR_CODE_ID: Cid = make_builtin(b"fil/2/storageminer");
pub static ref MARKET_ACTOR_CODE_ID: Cid = make_builtin(b"fil/2/storagemarket");
pub static ref PAYCH_ACTOR_CODE_ID: Cid = make_builtin(b"fil/2/paymentchannel");
pub static ref MULTISIG_ACTOR_CODE_ID: Cid = make_builtin(b"fil/2/multisig");
pub static ref REWARD_ACTOR_CODE_ID: Cid = make_builtin(b"fil/2/reward");
pub static ref VERIFREG_ACTOR_CODE_ID: Cid = make_builtin(b"fil/2/verifiedregistry");
pub static ref CHAOS_ACTOR_CODE_ID: Cid = make_builtin(b"fil/1/chaos");
pub static ref SYSTEM_ACTOR_CODE_ID: Cid = make_builtin(b"fil/3/system");
pub static ref INIT_ACTOR_CODE_ID: Cid = make_builtin(b"fil/3/init");
pub static ref CRON_ACTOR_CODE_ID: Cid = make_builtin(b"fil/3/cron");
pub static ref ACCOUNT_ACTOR_CODE_ID: Cid = make_builtin(b"fil/3/account");
pub static ref POWER_ACTOR_CODE_ID: Cid = make_builtin(b"fil/3/storagepower");
pub static ref MINER_ACTOR_CODE_ID: Cid = make_builtin(b"fil/3/storageminer");
pub static ref MARKET_ACTOR_CODE_ID: Cid = make_builtin(b"fil/3/storagemarket");
pub static ref PAYCH_ACTOR_CODE_ID: Cid = make_builtin(b"fil/3/paymentchannel");
pub static ref MULTISIG_ACTOR_CODE_ID: Cid = make_builtin(b"fil/3/multisig");
pub static ref REWARD_ACTOR_CODE_ID: Cid = make_builtin(b"fil/3/reward");
pub static ref VERIFREG_ACTOR_CODE_ID: Cid = make_builtin(b"fil/3/verifiedregistry");
pub static ref CHAOS_ACTOR_CODE_ID: Cid = make_builtin(b"fil/3/chaos");

/// Set of actor code types that can represent external signing parties.
pub static ref CALLER_TYPES_SIGNABLE: [Cid; 2] =
Expand Down
2 changes: 1 addition & 1 deletion vm/actor/src/builtin/cron/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use vm::{
actor_error, ActorError, ExitCode, MethodNum, Serialized, TokenAmount, METHOD_CONSTRUCTOR,
};

// * Updated to specs-actors commit: e195950ba98adb8ce362030356bf4a3809b7ec77 (v2.3.2)
// * Updated to specs-actors commit: 845089a6d2580e46055c24415a6c32ee688e5186 (v3.0.0)

/// Cron actor methods available
#[derive(FromPrimitive)]
Expand Down
2 changes: 1 addition & 1 deletion vm/actor/src/builtin/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use runtime::{ActorCode, Runtime};
use serde::{Deserialize, Serialize};
use vm::{actor_error, ActorError, ExitCode, MethodNum, Serialized, METHOD_CONSTRUCTOR};

// * Updated to specs-actors commit: e195950ba98adb8ce362030356bf4a3809b7ec77 (v2.3.2)
// * Updated to specs-actors commit: 845089a6d2580e46055c24415a6c32ee688e5186 (v3.0.0)

/// System actor methods.
#[derive(FromPrimitive)]
Expand Down
4 changes: 3 additions & 1 deletion vm/actor_interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2018"
[dependencies]
actorv0 = { package = "forest_actor", version = "0.1.3" }
actorv2 = { package = "forest_actor", version = "1.0.0" }
actorv3 = { package = "forest_actor", path = "../actor" }
fil_types = "0.1"
vm = { package = "forest_vm", version = "0.3.1" }
ipld_blockstore = "0.1"
Expand All @@ -20,7 +21,8 @@ forest_bitfield = "0.1"
num-bigint = { version = "0.1.1", package = "forest_bigint", features = ["json"] }
forest_hash_utils = "0.1"
forest_json_utils = "0.1.1"

ipld_hamt = { path = "../../ipld/hamt" }
ipld_amt = { path = "../../ipld/amt", features = ["go-interop"]}
austinabell marked this conversation as resolved.
Show resolved Hide resolved
[features]
devnet = ["actorv0/devnet", "actorv2/devnet"]
interopnet = ["actorv0/interopnet", "actorv2/interopnet"]
12 changes: 11 additions & 1 deletion vm/actor_interface/src/adt/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use std::error::Error;
pub enum Array<'a, BS, V> {
V0(actorv0::ipld_amt::Amt<'a, V, BS>),
V2(actorv2::ipld_amt::Amt<'a, V, BS>),
// TODO: Point this to the hamt from the actors v3 crate.
V3(ipld_amt::Amt<'a, V, BS>),
}

impl<'a, BS, V> Array<'a, BS, V>
Expand All @@ -21,6 +23,7 @@ where
match version {
ActorVersion::V0 => Array::V0(actorv0::ipld_amt::Amt::new(store)),
ActorVersion::V2 => Array::V2(actorv2::ipld_amt::Amt::new(store)),
ActorVersion::V3 => Array::V3(ipld_amt::Amt::new(store)),
}
}

Expand All @@ -29,6 +32,7 @@ where
match version {
ActorVersion::V0 => Ok(Array::V0(actorv0::ipld_amt::Amt::load(cid, store)?)),
ActorVersion::V2 => Ok(Array::V2(actorv2::ipld_amt::Amt::load(cid, store)?)),
ActorVersion::V3 => Ok(Array::V3(ipld_amt::Amt::load(cid, store)?)),
}
}

Expand All @@ -37,6 +41,7 @@ where
match self {
Array::V0(m) => m.count(),
Array::V2(m) => m.count(),
Array::V3(m) => m.count() as u64,
}
}

Expand All @@ -45,6 +50,7 @@ where
match self {
Array::V0(m) => Ok(m.get(i)?),
Array::V2(m) => Ok(m.get(i)?),
Array::V3(m) => Ok(m.get(i as usize)?),
}
}

Expand All @@ -53,6 +59,7 @@ where
match self {
Array::V0(m) => Ok(m.set(i, val)?),
Array::V2(m) => Ok(m.set(i, val)?),
Array::V3(m) => Ok(m.set(i as usize, val)?),
}
}

Expand All @@ -61,6 +68,7 @@ where
match self {
Array::V0(m) => Ok(m.delete(i)?),
Array::V2(m) => Ok(m.delete(i)?),
Array::V3(m) => Ok(m.delete(i as usize)?.is_some()),
}
}

Expand All @@ -69,17 +77,19 @@ where
match self {
Array::V0(m) => Ok(m.flush()?),
Array::V2(m) => Ok(m.flush()?),
Array::V3(m) => Ok(m.flush()?),
}
}

/// Iterates over each value in the `Array` and runs a function on the values.
pub fn for_each<F>(&self, f: F) -> Result<(), Box<dyn Error>>
pub fn for_each<F>(&self, mut f: F) -> Result<(), Box<dyn Error>>
where
F: FnMut(u64, &V) -> Result<(), Box<dyn Error>>,
{
match self {
Array::V0(m) => m.for_each(f),
Array::V2(m) => m.for_each(f),
Array::V3(m) => m.for_each(|k: usize, v: &V| f(k as u64, v)),
}
}
}
20 changes: 18 additions & 2 deletions vm/actor_interface/src/adt/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,24 @@ use ipld_blockstore::BlockStore;
use serde::{de::DeserializeOwned, Serialize};
use std::borrow::Borrow;
use std::error::Error;

pub enum Map<'a, BS, V> {
V0(actorv0::Map<'a, BS, V>),
V2(actorv2::Map<'a, BS, V>),
// TODO: Point this to the hamt from the actors v3 crate.
V3(ipld_hamt::Hamt<'a, BS, V>),
}

impl<'a, BS, V> Map<'a, BS, V>
where
V: Serialize + DeserializeOwned,
V: Serialize + DeserializeOwned + PartialEq,
BS: BlockStore,
{
pub fn new(store: &'a BS, version: ActorVersion) -> Self {
match version {
ActorVersion::V0 => Map::V0(actorv0::make_map(store)),
ActorVersion::V2 => Map::V2(actorv2::make_map(store)),
// TODO: Use interface from actorv3
ActorVersion::V3 => Map::V3(ipld_hamt::Hamt::new_with_bit_width(store, 5)),
}
}

Expand All @@ -31,6 +34,9 @@ where
match version {
ActorVersion::V0 => Ok(Map::V0(actorv0::make_map_with_root(cid, store)?)),
ActorVersion::V2 => Ok(Map::V2(actorv2::make_map_with_root(cid, store)?)),
ActorVersion::V3 => Ok(Map::V3(ipld_hamt::Hamt::load_with_bit_width(
cid, store, 5,
)?)),
}
}

Expand All @@ -39,6 +45,7 @@ where
match self {
Map::V0(m) => m.store(),
Map::V2(m) => m.store(),
Map::V3(m) => m.store(),
}
}

Expand All @@ -47,6 +54,10 @@ where
match self {
Map::V0(m) => Ok(m.set(key, value)?),
Map::V2(m) => Ok(m.set(key, value)?),
Map::V3(m) => {
m.set(key, value)?;
Ok(())
}
}
}

Expand All @@ -60,6 +71,7 @@ where
match self {
Map::V0(m) => Ok(m.get(k)?),
Map::V2(m) => Ok(m.get(k)?),
Map::V3(m) => Ok(m.get(k)?),
}
}

Expand All @@ -72,6 +84,7 @@ where
match self {
Map::V0(m) => Ok(m.contains_key(k)?),
Map::V2(m) => Ok(m.contains_key(k)?),
Map::V3(m) => Ok(m.contains_key(k)?),
}
}

Expand All @@ -85,6 +98,7 @@ where
match self {
Map::V0(m) => Ok(m.delete(k)?),
Map::V2(m) => Ok(m.delete(k)?),
Map::V3(m) => Ok(m.delete(k)?),
}
}

Expand All @@ -93,6 +107,7 @@ where
match self {
Map::V0(m) => Ok(m.flush()?),
Map::V2(m) => Ok(m.flush()?),
Map::V3(m) => Ok(m.flush()?),
}
}

Expand All @@ -105,6 +120,7 @@ where
match self {
Map::V0(m) => m.for_each(f),
Map::V2(m) => m.for_each(f),
Map::V3(m) => m.for_each(f),
}
}
}
7 changes: 7 additions & 0 deletions vm/actor_interface/src/builtin/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub type Method = actorv2::account::Method;
pub enum State {
V0(actorv0::account::State),
V2(actorv2::account::State),
V3(actorv3::account::State),
}

impl State {
Expand All @@ -33,6 +34,11 @@ impl State {
.get(&actor.state)?
.map(State::V2)
.ok_or("Actor state doesn't exist in store")?)
} else if actor.code == *actorv3::ACCOUNT_ACTOR_CODE_ID {
Ok(store
.get(&actor.state)?
.map(State::V3)
.ok_or("Actor state doesn't exist in store")?)
} else {
Err(format!("Unknown actor code {}", actor.code).into())
}
Expand All @@ -42,6 +48,7 @@ impl State {
match self {
State::V0(st) => st.address,
State::V2(st) => st.address,
State::V3(st) => st.address,
}
}
}
Loading