diff --git a/fil_actor_interface/src/builtin/market/mod.rs b/fil_actor_interface/src/builtin/market/mod.rs index 3bfceaee..fda36a86 100644 --- a/fil_actor_interface/src/builtin/market/mod.rs +++ b/fil_actor_interface/src/builtin/market/mod.rs @@ -13,6 +13,8 @@ use fil_actor_market_state::v11::DealArray as V11DealArray; use fil_actor_market_state::v11::DealMetaArray as V11DealMetaArray; use fil_actor_market_state::v12::DealArray as V12DealArray; use fil_actor_market_state::v12::DealMetaArray as V12DealMetaArray; +use fil_actor_market_state::v13::DealArray as V13DealArray; +use fil_actor_market_state::v13::DealMetaArray as V13DealMetaArray; use fil_actor_market_state::v9::DealArray as V9DealArray; use fil_actor_market_state::v9::DealMetaArray as V9DealMetaArray; use fil_actors_shared::v10::AsActorError as V10AsActorError; @@ -141,8 +143,7 @@ impl State { State::V10(st) => Ok(DealProposals::V10(st.get_proposal_array(store)?)), State::V11(st) => Ok(DealProposals::V11(st.get_proposal_array(store)?)), State::V12(st) => Ok(DealProposals::V12(st.get_proposal_array(store)?)), - // `get_proposal_array` does not exist for V13 - State::V13(_st) => anyhow::bail!("unimplemented"), + State::V13(st) => Ok(DealProposals::V13(st.load_proposals(store)?)), } } @@ -175,7 +176,7 @@ impl State { "failed to load deal state array", )?)), State::V13(st) => Ok(DealStates::V13(V13AsActorError::context_code( - V12DealMetaArray::load(&st.states, store), + V13DealMetaArray::load(&st.states, store), FVM4ExitCode::USR_ILLEGAL_STATE, "failed to load deal state array", )?)), @@ -204,17 +205,17 @@ pub enum DealProposals<'bs, BS> { V10(V10DealArray<'bs, BS>), V11(V11DealArray<'bs, BS>), V12(V12DealArray<'bs, BS>), - V13(V12DealArray<'bs, BS>), + V13(V13DealArray<'bs, BS>), } -impl DealProposals<'_, BS> { +impl DealProposals<'_, BS> +where + BS: Blockstore, +{ pub fn for_each( &self, mut f: impl FnMut(u64, Result) -> anyhow::Result<(), anyhow::Error>, - ) -> anyhow::Result<()> - where - BS: Blockstore, - { + ) -> anyhow::Result<()> { match self { DealProposals::V9(deal_array) => Ok(deal_array .for_each(|key, deal_proposal| f(key, DealProposal::try_from(deal_proposal)))?), @@ -228,6 +229,17 @@ impl DealProposals<'_, BS> { .for_each(|key, deal_proposal| f(key, DealProposal::try_from(deal_proposal)))?), } } + + pub fn get(&self, key: u64) -> anyhow::Result> { + match self { + DealProposals::V9(deal_array) => deal_array.get(key)?.map(TryFrom::try_from), + DealProposals::V10(deal_array) => deal_array.get(key)?.map(TryFrom::try_from), + DealProposals::V11(deal_array) => deal_array.get(key)?.map(TryFrom::try_from), + DealProposals::V12(deal_array) => deal_array.get(key)?.map(TryFrom::try_from), + DealProposals::V13(deal_array) => deal_array.get(key)?.map(TryFrom::try_from), + } + .transpose() + } } #[derive(Clone, Serialize, Deserialize, PartialEq)] @@ -354,13 +366,40 @@ impl TryFrom<&fil_actor_market_state::v12::DealProposal> for DealProposal { } } +impl TryFrom<&fil_actor_market_state::v13::DealProposal> for DealProposal { + type Error = anyhow::Error; + + fn try_from( + deal_proposal: &fil_actor_market_state::v13::DealProposal, + ) -> Result { + Ok(Self { + piece_cid: deal_proposal.piece_cid, + piece_size: from_padded_piece_size_v4_to_v2(deal_proposal.piece_size), + verified_deal: deal_proposal.verified_deal, + client: from_address_v4_to_v2(deal_proposal.client), + provider: from_address_v4_to_v2(deal_proposal.provider), + label: match &deal_proposal.label { + fil_actor_market_state::v13::Label::String(s) => s.clone(), + fil_actor_market_state::v13::Label::Bytes(b) => String::from_utf8(b.clone())?, + }, + start_epoch: deal_proposal.start_epoch, + end_epoch: deal_proposal.end_epoch, + storage_price_per_epoch: from_token_v4_to_v2( + deal_proposal.storage_price_per_epoch.clone(), + ), + provider_collateral: from_token_v4_to_v2(deal_proposal.provider_collateral.clone()), + client_collateral: from_token_v4_to_v2(deal_proposal.client_collateral.clone()), + }) + } +} + pub enum DealStates<'bs, BS> { V8(V9DealMetaArray<'bs, BS>), V9(V9DealMetaArray<'bs, BS>), V10(V10DealMetaArray<'bs, BS>), V11(V11DealMetaArray<'bs, BS>), V12(V12DealMetaArray<'bs, BS>), - V13(V12DealMetaArray<'bs, BS>), + V13(V13DealMetaArray<'bs, BS>), } impl DealStates<'_, BS> @@ -403,7 +442,7 @@ where sector_start_epoch: deal_state.sector_start_epoch, last_updated_epoch: deal_state.last_updated_epoch, slash_epoch: deal_state.slash_epoch, - verified_claim: deal_state.verified_claim, + verified_claim: 0, })), } } @@ -418,6 +457,18 @@ pub struct DealState { pub verified_claim: AllocationID, // ID of the verified registry allocation/claim for this deal's data (0 if none). } +impl DealState { + /// Empty deal state + pub const fn empty() -> Self { + Self { + sector_start_epoch: -1, + last_updated_epoch: -1, + slash_epoch: -1, + verified_claim: 0, + } + } +} + impl BalanceTable<'_, BS> where BS: Blockstore, diff --git a/forest b/forest index b7ac4035..95090c0f 160000 --- a/forest +++ b/forest @@ -1 +1 @@ -Subproject commit b7ac40354c713ef2e087a6e4c1f0c59c61a28bef +Subproject commit 95090c0f0d1ede238727c5df5fc0a20a49bfadcb