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

feat(rpc): implement Filecoin.StateListActors #4409

Merged
merged 2 commits into from
Jun 15, 2024
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
26 changes: 26 additions & 0 deletions src/rpc/methods/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,32 @@ impl RpcMethod<1> for StateListMiners {
}
}

pub enum StateListActors {}

impl RpcMethod<1> for StateListActors {
const NAME: &'static str = "Filecoin.StateListActors";
const PARAM_NAMES: [&'static str; 1] = ["tipset_key"];
const API_VERSION: ApiVersion = ApiVersion::V0;
const PERMISSION: Permission = Permission::Read;

type Params = (ApiTipsetKey,);
type Ok = Vec<Address>;

async fn handle(
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
(ApiTipsetKey(tsk),): Self::Params,
) -> Result<Self::Ok, ServerError> {
let mut actors = vec![];
let ts = ctx.chain_store.load_required_tipset_or_heaviest(&tsk)?;
let state_tree = ctx.state_manager.get_state_tree(ts.parent_state())?;
state_tree.for_each(|addr, _state| {
actors.push(addr);
Ok(())
})?;
Ok(actors)
}
}

pub enum StateMarketStorageDeal {}

impl RpcMethod<2> for StateMarketStorageDeal {
Expand Down
1 change: 1 addition & 0 deletions src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ macro_rules! for_each_method {
$callback!(crate::rpc::state::StateVerifiedClientStatus);
$callback!(crate::rpc::state::StateVMCirculatingSupplyInternal);
$callback!(crate::rpc::state::StateListMiners);
$callback!(crate::rpc::state::StateListActors);
$callback!(crate::rpc::state::StateNetworkVersion);
$callback!(crate::rpc::state::StateMarketBalance);
$callback!(crate::rpc::state::StateMarketParticipants);
Expand Down
9 changes: 7 additions & 2 deletions src/state_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,20 @@ where
&self.sync_config
}

/// Gets the state tree
pub fn get_state_tree(&self, state_cid: &Cid) -> anyhow::Result<StateTree<DB>> {
StateTree::new_from_root(self.blockstore_owned(), state_cid)
}

/// Gets actor from given [`Cid`], if it exists.
pub fn get_actor(&self, addr: &Address, state_cid: Cid) -> anyhow::Result<Option<ActorState>> {
let state = StateTree::new_from_root(self.blockstore_owned(), &state_cid)?;
let state = self.get_state_tree(&state_cid)?;
state.get_actor(addr)
}

/// Gets required actor from given [`Cid`].
pub fn get_required_actor(&self, addr: &Address, state_cid: Cid) -> anyhow::Result<ActorState> {
let state = StateTree::new_from_root(self.blockstore_owned(), &state_cid)?;
let state = self.get_state_tree(&state_cid)?;
state.get_actor(addr)?.with_context(|| {
format!("Failed to load actor with addr={addr}, state_cid={state_cid}")
})
Expand Down
1 change: 1 addition & 0 deletions src/tool/subcommands/api_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ fn state_tests_with_tipset<DB: Blockstore>(
))?),
RpcTest::identity(StateNetworkVersion::request((tipset.key().into(),))?),
RpcTest::identity(StateListMiners::request((tipset.key().into(),))?),
RpcTest::identity(StateListActors::request((tipset.key().into(),))?),
RpcTest::identity(MsigGetAvailableBalance::request((
Address::new_id(18101), // msig address id
tipset.key().into(),
Expand Down
Loading