Skip to content

Commit

Permalink
Merge branch 'master' into feat/remove-mocktime-generic-blockstore
Browse files Browse the repository at this point in the history
  • Loading branch information
aarshkshah1992 authored Oct 18, 2023
2 parents b59b9b8 + b136ad8 commit 638f4d0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 40 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions state/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ frc46_token = { workspace = true }
fvm_shared = { workspace = true }
fvm_ipld_encoding = { workspace = true }
fvm_ipld_blockstore = { workspace = true }
vm_api = { workspace = true }

num-traits = { workspace = true }
anyhow = { workspace = true }
bimap = { workspace = true }
Expand Down
37 changes: 7 additions & 30 deletions state/src/check.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::fmt::Debug;

use anyhow::anyhow;
use anyhow::bail;
use cid::Cid;
use fil_actor_account::State as AccountState;
Expand All @@ -20,26 +20,20 @@ use fil_actor_power::testing::MinerCronEvent;
use fil_actor_power::State as PowerState;
use fil_actor_reward::State as RewardState;
use fil_actor_verifreg::{DataCap, State as VerifregState};

use fil_actors_runtime::runtime::Policy;
use fil_actors_runtime::DEFAULT_HAMT_CONFIG;
use fil_actors_runtime::VERIFIED_REGISTRY_ACTOR_ADDR;

use fil_actors_runtime::Map;
use fil_actors_runtime::MessageAccumulator;
use fil_actors_runtime::DEFAULT_HAMT_CONFIG;
use fil_actors_runtime::VERIFIED_REGISTRY_ACTOR_ADDR;
use fvm_ipld_blockstore::Blockstore;
use fvm_ipld_encoding::from_slice;
use fvm_ipld_encoding::CborStore;
use fvm_shared::address::Address;
use fvm_shared::address::Protocol;

use fvm_shared::clock::ChainEpoch;
use fvm_shared::econ::TokenAmount;
use num_traits::Zero;

use anyhow::anyhow;
use fvm_ipld_encoding::tuple::*;

use fil_actor_account::testing as account;
use fil_actor_cron::testing as cron;
use fil_actor_datacap::testing as datacap;
Expand All @@ -52,31 +46,14 @@ use fil_actor_power::testing as power;
use fil_actor_reward::testing as reward;
use fil_actor_verifreg::testing as verifreg;
use fil_actors_runtime::runtime::builtins::Type;

/// Value type of the top level of the state tree.
/// Represents the on-chain state of a single actor.
#[derive(Serialize_tuple, Deserialize_tuple, Clone, PartialEq, Eq, Debug)]
pub struct Actor {
/// CID representing the code associated with the actor
pub code: Cid,
/// CID of the head state object for the actor
pub head: Cid,
/// `call_seq_num` for the next message to be received by the actor (non-zero for accounts only)
pub call_seq_num: u64,
/// Token balance of the actor
pub balance: TokenAmount,
/// The actor's "predictable" address, if assigned.
///
/// This field is set on actor creation and never modified.
pub address: Option<Address>,
}
use vm_api::ActorState;

/// A specialization of a map of ID-addresses to actor heads.
pub struct Tree<'a, BS>
where
BS: Blockstore,
{
pub map: Map<'a, BS, Actor>,
pub map: Map<'a, BS, ActorState>,
pub store: &'a BS,
}

Expand All @@ -90,7 +67,7 @@ impl<'a, BS: Blockstore> Tree<'a, BS> {

pub fn for_each<F>(&self, mut f: F) -> anyhow::Result<()>
where
F: FnMut(&Address, &Actor) -> anyhow::Result<()>,
F: FnMut(&Address, &ActorState) -> anyhow::Result<()>,
{
self.map
.for_each(|key, val| {
Expand All @@ -105,7 +82,7 @@ macro_rules! get_state {
($tree:ident, $actor:ident, $state:ty) => {
$tree
.store
.get_cbor::<$state>(&$actor.head)?
.get_cbor::<$state>(&$actor.state)?
.ok_or_else(|| anyhow!("{} is empty", stringify!($state)))?
};
}
Expand Down
14 changes: 4 additions & 10 deletions vm_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,12 @@ pub struct ActorState {

pub fn new_actor(
code: Cid,
head: Cid,
call_seq_num: u64,
state: Cid,
sequence: u64,
balance: TokenAmount,
predictable_address: Option<Address>,
delegated_address: Option<Address>,
) -> ActorState {
ActorState {
code,
state: head,
sequence: call_seq_num,
balance,
delegated_address: predictable_address,
}
ActorState { code, state, sequence, balance, delegated_address }
}

/// Pure functions implemented as primitives by the runtime.
Expand Down

0 comments on commit 638f4d0

Please sign in to comment.