From fdd63039b810a8d2bad6c7615d9ca3e66c069438 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Mon, 14 Nov 2022 19:07:10 -0500 Subject: [PATCH] Market actor: Minor improvements to two exported getters (#826) * Market actor: GetDealTermExported: Return (start_epoch, duration) * Market actor: Export getter for deal total price --- actors/market/src/lib.rs | 19 +++++++++---------- actors/market/src/types.rs | 11 ++++++----- actors/market/tests/deal_api_test.rs | 12 ++++++------ 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/actors/market/src/lib.rs b/actors/market/src/lib.rs index 4e44c126b..3b429d059 100644 --- a/actors/market/src/lib.rs +++ b/actors/market/src/lib.rs @@ -81,7 +81,7 @@ pub enum Method { GetDealProviderExported = frc42_dispatch::method_hash!("GetDealProvider"), GetDealLabelExported = frc42_dispatch::method_hash!("GetDealLabel"), GetDealTermExported = frc42_dispatch::method_hash!("GetDealTerm"), - GetDealEpochPriceExported = frc42_dispatch::method_hash!("GetDealEpochPrice"), + GetDealTotalPriceExported = frc42_dispatch::method_hash!("GetDealTotalPrice"), GetDealClientCollateralExported = frc42_dispatch::method_hash!("GetDealClientCollateral"), GetDealProviderCollateralExported = frc42_dispatch::method_hash!("GetDealProviderCollateral"), GetDealVerifiedExported = frc42_dispatch::method_hash!("GetDealVerified"), @@ -869,25 +869,24 @@ impl Actor { Ok(GetDealLabelReturn { label: found.label }) } - /// Returns the start and end epochs of a deal proposal. - /// The deal term is a half-open range, exclusive of the end epoch. + /// Returns the start epoch and duration (in epochs) of a deal proposal. fn get_deal_term( rt: &mut impl Runtime, params: GetDealTermParams, ) -> Result { rt.validate_immediate_caller_accept_any()?; let found = rt.state::()?.get_proposal(rt.store(), params.id)?; - Ok(GetDealTermReturn { start: found.start_epoch, end: found.end_epoch }) + Ok(GetDealTermReturn { start: found.start_epoch, duration: found.duration() }) } /// Returns the per-epoch price of a deal proposal. - fn get_deal_epoch_price( + fn get_deal_total_price( rt: &mut impl Runtime, - params: GetDealEpochPriceParams, - ) -> Result { + params: GetDealTotalPriceParams, + ) -> Result { rt.validate_immediate_caller_accept_any()?; let found = rt.state::()?.get_proposal(rt.store(), params.id)?; - Ok(GetDealEpochPriceReturn { price_per_epoch: found.storage_price_per_epoch }) + Ok(GetDealTotalPriceReturn { total_price: found.total_storage_fee() }) } /// Returns the client collateral requirement for a deal proposal. @@ -1360,8 +1359,8 @@ impl ActorCode for Actor { let res = Self::get_deal_term(rt, cbor::deserialize_params(params)?)?; Ok(RawBytes::serialize(res)?) } - Some(Method::GetDealEpochPriceExported) => { - let res = Self::get_deal_epoch_price(rt, cbor::deserialize_params(params)?)?; + Some(Method::GetDealTotalPriceExported) => { + let res = Self::get_deal_total_price(rt, cbor::deserialize_params(params)?)?; Ok(RawBytes::serialize(res)?) } Some(Method::GetDealClientCollateralExported) => { diff --git a/actors/market/src/types.rs b/actors/market/src/types.rs index afdfa2da4..7c28f164b 100644 --- a/actors/market/src/types.rs +++ b/actors/market/src/types.rs @@ -175,14 +175,15 @@ pub struct GetDealLabelReturn { pub type GetDealTermParams = DealQueryParams; #[derive(Serialize_tuple, Deserialize_tuple, Debug, Clone, Eq, PartialEq)] pub struct GetDealTermReturn { - pub start: ChainEpoch, // First epoch for the deal (inclusive) - pub end: ChainEpoch, // Epoch at which the deal expires (i.e. exclusive). + pub start: ChainEpoch, // First epoch for the deal (inclusive) + pub duration: ChainEpoch, // Duration of the deal. } -pub type GetDealEpochPriceParams = DealQueryParams; +pub type GetDealTotalPriceParams = DealQueryParams; #[derive(Serialize_tuple, Deserialize_tuple, Debug, Clone, Eq, PartialEq)] -pub struct GetDealEpochPriceReturn { - pub price_per_epoch: TokenAmount, +#[serde(transparent)] +pub struct GetDealTotalPriceReturn { + pub total_price: TokenAmount, } pub type GetDealClientCollateralParams = DealQueryParams; diff --git a/actors/market/tests/deal_api_test.rs b/actors/market/tests/deal_api_test.rs index 4471f0f43..ca18ed999 100644 --- a/actors/market/tests/deal_api_test.rs +++ b/actors/market/tests/deal_api_test.rs @@ -4,9 +4,9 @@ use serde::de::DeserializeOwned; use fil_actor_market::{ Actor as MarketActor, DealQueryParams, GetDealClientCollateralReturn, GetDealClientReturn, - GetDealDataCommitmentReturn, GetDealEpochPriceReturn, GetDealLabelReturn, - GetDealProviderCollateralReturn, GetDealProviderReturn, GetDealTermReturn, - GetDealVerifiedReturn, Method, + GetDealDataCommitmentReturn, GetDealLabelReturn, GetDealProviderCollateralReturn, + GetDealProviderReturn, GetDealTermReturn, GetDealTotalPriceReturn, GetDealVerifiedReturn, + Method, }; use fil_actors_runtime::network::EPOCHS_IN_DAY; use fil_actors_runtime::test_utils::{MockRuntime, ACCOUNT_ACTOR_CODE_ID}; @@ -52,10 +52,10 @@ fn proposal_data() { let term: GetDealTermReturn = query_deal(&mut rt, Method::GetDealTermExported, id); assert_eq!(proposal.start_epoch, term.start); - assert_eq!(proposal.end_epoch, term.end); + assert_eq!(proposal.duration(), term.duration); - let price: GetDealEpochPriceReturn = query_deal(&mut rt, Method::GetDealEpochPriceExported, id); - assert_eq!(proposal.storage_price_per_epoch, price.price_per_epoch); + let price: GetDealTotalPriceReturn = query_deal(&mut rt, Method::GetDealTotalPriceExported, id); + assert_eq!(proposal.total_storage_fee(), price.total_price); let client_collateral: GetDealClientCollateralReturn = query_deal(&mut rt, Method::GetDealClientCollateralExported, id);