Skip to content

Commit

Permalink
[Feature] Filecoin.StateGetAllClaims and Filecoin.StateGetAllAllocati…
Browse files Browse the repository at this point in the history
…ons RPC. (#4545)
  • Loading branch information
ruseinov authored Jul 17, 2024
1 parent 195b283 commit aea54e7
Show file tree
Hide file tree
Showing 9 changed files with 341 additions and 42 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@

### Added

- [#4545](https://github.com/ChainSafe/forest/pull/4545) Add support for the
`Filecoin.StateGetAllClaims` RPC method.

- [#4545](https://github.com/ChainSafe/forest/pull/4545) Add support for the
`Filecoin.StateGetAllAllocations` RPC method.

- [#4503](https://github.com/ChainSafe/forest/pull/4503) Add support for the
`Filecoin.StateMinerAllocated` RPC method.

Expand Down
56 changes: 28 additions & 28 deletions Cargo.lock

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

24 changes: 12 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ digest = "0.10"
directories = "5"
displaydoc = "0.2"
ethereum-types = "0.14"
fil_actor_account_state = { version = "15.1" }
fil_actor_cron_state = { version = "15.1" }
fil_actor_datacap_state = { version = "15.1" }
fil_actor_init_state = { version = "15.1" }
fil_actor_interface = { version = "15.1" }
fil_actor_market_state = { version = "15.1" }
fil_actor_miner_state = { version = "15.1" }
fil_actor_power_state = { version = "15.1" }
fil_actor_reward_state = { version = "15.1" }
fil_actor_system_state = { version = "15.1" }
fil_actor_verifreg_state = { version = "15.1" }
fil_actors_shared = { version = "15.1", features = ["json"] }
fil_actor_account_state = { version = "15.2" }
fil_actor_cron_state = { version = "15.2" }
fil_actor_datacap_state = { version = "15.2" }
fil_actor_init_state = { version = "15.2" }
fil_actor_interface = { version = "15.2" }
fil_actor_market_state = { version = "15.2" }
fil_actor_miner_state = { version = "15.2" }
fil_actor_power_state = { version = "15.2" }
fil_actor_reward_state = { version = "15.2" }
fil_actor_system_state = { version = "15.2" }
fil_actor_verifreg_state = { version = "15.2" }
fil_actors_shared = { version = "15.2", features = ["json"] }
flume = "0.11"
fs_extra = "1"
futures = "0.3"
Expand Down
40 changes: 40 additions & 0 deletions src/rpc/methods/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2170,6 +2170,26 @@ impl StateGetClaims {
}
}

pub enum StateGetAllClaims {}

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

type Params = (ApiTipsetKey,);
type Ok = HashMap<ClaimID, Claim>;

async fn handle(
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
(ApiTipsetKey(tsk),): Self::Params,
) -> Result<Self::Ok, ServerError> {
let ts = ctx.chain_store.load_required_tipset_or_heaviest(&tsk)?;
Ok(ctx.state_manager.get_all_claims(&ts)?)
}
}

pub enum StateGetAllocation {}

impl RpcMethod<3> for StateGetAllocation {
Expand Down Expand Up @@ -2340,6 +2360,26 @@ impl StateGetAllocations {
}
}

pub enum StateGetAllAllocations {}

impl RpcMethod<1> for crate::rpc::prelude::StateGetAllAllocations {
const NAME: &'static str = "Filecoin.StateGetAllAllocations";
const PARAM_NAMES: [&'static str; 1] = ["tipset_key"];
const API_PATHS: ApiPaths = ApiPaths::V0;
const PERMISSION: Permission = Permission::Read;

type Params = (ApiTipsetKey,);
type Ok = HashMap<AllocationID, Allocation>;

async fn handle(
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
(ApiTipsetKey(tsk),): Self::Params,
) -> Result<Self::Ok, ServerError> {
let ts = ctx.chain_store.load_required_tipset_or_heaviest(&tsk)?;
Ok(ctx.state_manager.get_all_allocations(&ts)?)
}
}

pub enum StateGetAllocationIdForPendingDeal {}

impl RpcMethod<2> for StateGetAllocationIdForPendingDeal {
Expand Down
2 changes: 2 additions & 0 deletions src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,10 @@ macro_rules! for_each_method {
$callback!(crate::rpc::state::StateVerifierStatus);
$callback!(crate::rpc::state::StateGetClaim);
$callback!(crate::rpc::state::StateGetClaims);
$callback!(crate::rpc::state::StateGetAllClaims);
$callback!(crate::rpc::state::StateGetAllocation);
$callback!(crate::rpc::state::StateGetAllocations);
$callback!(crate::rpc::state::StateGetAllAllocations);
$callback!(crate::rpc::state::StateGetAllocationIdForPendingDeal);
$callback!(crate::rpc::state::StateGetAllocationForPendingDeal);
$callback!(crate::rpc::state::StateSectorExpiration);
Expand Down
8 changes: 8 additions & 0 deletions src/shim/actors/verifreg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@ pub trait VerifiedRegistryStateExt {
address: &Address,
) -> anyhow::Result<HashMap<AllocationID, Allocation>>;

fn get_all_allocations<BS: Blockstore>(
&self,
store: &BS,
) -> anyhow::Result<HashMap<AllocationID, Allocation>>;

fn get_claims<BS: Blockstore>(
&self,
store: &BS,
provider_id_address: &Address,
) -> anyhow::Result<HashMap<ClaimID, Claim>>;

fn get_all_claims<BS: Blockstore>(&self, store: &BS)
-> anyhow::Result<HashMap<ClaimID, Claim>>;
}
Loading

0 comments on commit aea54e7

Please sign in to comment.