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.StateMarketStorageDeal #4079

Merged
merged 4 commits into from
Mar 19, 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
60 changes: 30 additions & 30 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 @@ -52,18 +52,18 @@ dialoguer = "0.11"
digest = "0.10.5"
directories = "5"
ethereum-types = "0.14.1"
fil_actor_account_state = { version = "10.0.0-dev.4" }
fil_actor_cron_state = { version = "10.0.0-dev.4" }
fil_actor_datacap_state = { version = "10.0.0-dev.4" }
fil_actor_init_state = { version = "10.0.0-dev.4" }
fil_actor_interface = { version = "10.0.0-dev.4" }
fil_actor_market_state = { version = "10.0.0-dev.4" }
fil_actor_miner_state = { version = "10.0.0-dev.4" }
fil_actor_power_state = { version = "10.0.0-dev.4" }
fil_actor_reward_state = { version = "10.0.0-dev.4" }
fil_actor_system_state = { version = "10.0.0-dev.4" }
fil_actor_verifreg_state = { version = "10.0.0-dev.4" }
fil_actors_shared = { version = "10.0.0-dev.4", features = ["json"] }
fil_actor_account_state = { version = "10.0.0-dev.5" }
fil_actor_cron_state = { version = "10.0.0-dev.5" }
fil_actor_datacap_state = { version = "10.0.0-dev.5" }
fil_actor_init_state = { version = "10.0.0-dev.5" }
fil_actor_interface = { version = "10.0.0-dev.5" }
fil_actor_market_state = { version = "10.0.0-dev.5" }
fil_actor_miner_state = { version = "10.0.0-dev.5" }
fil_actor_power_state = { version = "10.0.0-dev.5" }
fil_actor_reward_state = { version = "10.0.0-dev.5" }
fil_actor_system_state = { version = "10.0.0-dev.5" }
fil_actor_verifreg_state = { version = "10.0.0-dev.5" }
fil_actors_shared = { version = "10.0.0-dev.5", features = ["json"] }
filecoin-proofs-api = { version = "16.0", default-features = false }
flume = "0.11"
frc46_token = "10.0.0"
Expand Down
1 change: 1 addition & 0 deletions src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ where
STATE_VM_CIRCULATING_SUPPLY_INTERNAL,
state_vm_circulating_supply_internal::<DB>,
)?;
module.register_async_method(STATE_MARKET_STORAGE_DEAL, state_market_storage_deal::<DB>)?;
module.register_async_method(MSIG_GET_AVAILABLE_BALANCE, msig_get_available_balance::<DB>)?;
module.register_async_method(MSIG_GET_PENDING, msig_get_pending::<DB>)?;
// Gas API
Expand Down
37 changes: 30 additions & 7 deletions src/rpc/state_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ use crate::cid_collections::CidHashSet;
use crate::libp2p::NetworkMessage;
use crate::lotus_json::LotusJson;
use crate::rpc::error::JsonRpcError;
use crate::rpc_api::data_types::{
ApiActorState, ApiDeadline, ApiInvocResult, ApiTipsetKey, CirculatingSupply, Data, MarketDeal,
MessageFilter, MessageLookup, MinerSectors, MiningBaseInfo, RPCState, SectorOnChainInfo,
Transaction,
};
use crate::rpc_api::data_types::*;
use crate::shim::{
address::Address, clock::ChainEpoch, econ::TokenAmount, executor::Receipt,
address::Address, clock::ChainEpoch, deal::DealID, econ::TokenAmount, executor::Receipt,
state_tree::ActorState, version::NetworkVersion,
};
use crate::state_manager::chain_rand::ChainRand;
Expand All @@ -24,6 +20,7 @@ use ahash::{HashMap, HashMapExt};
use anyhow::Context as _;
use anyhow::Result;
use cid::Cid;
use fil_actor_interface::market::DealState;
use fil_actor_interface::miner::DeadlineInfo;
use fil_actor_interface::{
market, miner,
Expand Down Expand Up @@ -1009,7 +1006,7 @@ pub async fn state_list_miners<DB: Blockstore + Send + Sync + 'static>(
let actor = data
.state_manager
.get_actor(&Address::POWER_ACTOR, *ts.parent_state())?
.context("Power actor not found".to_string())?;
.context("Power actor not found")?;

let state = power::State::load(store, actor.code, actor.state)?;
let miners = state
Expand All @@ -1020,3 +1017,29 @@ pub async fn state_list_miners<DB: Blockstore + Send + Sync + 'static>(

Ok(LotusJson(miners))
}

pub async fn state_market_storage_deal<DB: Blockstore + Send + Sync + 'static>(
params: Params<'_>,
data: Data<RPCState<DB>>,
) -> Result<ApiMarketDeal, JsonRpcError> {
let LotusJson((deal_id, ApiTipsetKey(tsk))): LotusJson<(DealID, ApiTipsetKey)> =
params.parse()?;

let ts = data
.state_manager
.chain_store()
.load_required_tipset_or_heaviest(&tsk)?;
let store = data.state_manager.blockstore();
let actor = data
.state_manager
.get_actor(&Address::MARKET_ACTOR, *ts.parent_state())?
.context("Market actor not found")?;
let market_state = market::State::load(store, actor.code, actor.state)?;
let proposals = market_state.proposals(store)?;
let proposal = proposals.get(deal_id)?.ok_or_else(|| anyhow::anyhow!("deal {deal_id} not found - deal may not have completed sealing before deal proposal start epoch, or deal may have been slashed"))?;

let states = market_state.states(store)?;
let state = states.get(deal_id)?.unwrap_or_else(DealState::empty);

Ok(MarketDeal { proposal, state }.into())
}
Loading
Loading