From d026d276fb4e8ed88285b7e8ae5f164fc5ea9ef3 Mon Sep 17 00:00:00 2001 From: hanabi1224 Date: Tue, 17 Dec 2024 23:17:51 +0800 Subject: [PATCH] fix(rpc): error in StateMarketDeals and StateMarketStorageDeal (#5089) --- scripts/tests/api_compare/filter-list | 3 -- scripts/tests/api_compare/filter-list-offline | 3 -- src/rpc/methods/state.rs | 1 + src/rpc/types/deal_impl.rs | 2 + src/rpc/types/mod.rs | 1 + src/shim/actors/builtin/market/mod.rs | 51 ++++++++++++++++--- 6 files changed, 47 insertions(+), 14 deletions(-) diff --git a/scripts/tests/api_compare/filter-list b/scripts/tests/api_compare/filter-list index 231e30d975e9..84b89d014258 100644 --- a/scripts/tests/api_compare/filter-list +++ b/scripts/tests/api_compare/filter-list @@ -11,6 +11,3 @@ !Filecoin.EthGetTransactionReceiptLimited # TODO: https://github.com/ChainSafe/forest/issues/5006 !Filecoin.EthGetBlockReceipts -# TODO: https://github.com/ChainSafe/forest/issues/5085 -!Filecoin.StateMarketDeals -!Filecoin.StateMarketStorageDeal diff --git a/scripts/tests/api_compare/filter-list-offline b/scripts/tests/api_compare/filter-list-offline index ce5125318fda..e88dfbaf4d42 100644 --- a/scripts/tests/api_compare/filter-list-offline +++ b/scripts/tests/api_compare/filter-list-offline @@ -41,6 +41,3 @@ !Filecoin.EthGetTransactionReceiptLimited # TODO: https://github.com/ChainSafe/forest/issues/5006 !Filecoin.EthGetBlockReceipts -# TODO: https://github.com/ChainSafe/forest/issues/5085 -!Filecoin.StateMarketDeals -!Filecoin.StateMarketStorageDeal diff --git a/src/rpc/methods/state.rs b/src/rpc/methods/state.rs index 9c8da95cd5c9..4631a5c5ba60 100644 --- a/src/rpc/methods/state.rs +++ b/src/rpc/methods/state.rs @@ -465,6 +465,7 @@ impl RpcMethod<1> for StateMarketDeals { last_updated_epoch: -1, slash_epoch: -1, verified_claim: 0, + sector_number: 0, }); out.insert( deal_id.to_string(), diff --git a/src/rpc/types/deal_impl.rs b/src/rpc/types/deal_impl.rs index d8abe3014f8f..0f67266115c2 100644 --- a/src/rpc/types/deal_impl.rs +++ b/src/rpc/types/deal_impl.rs @@ -10,12 +10,14 @@ impl From for ApiDealState { last_updated_epoch, slash_epoch, verified_claim, + sector_number, } = s; Self { sector_start_epoch, last_updated_epoch, slash_epoch, verified_claim, + sector_number, } } } diff --git a/src/rpc/types/mod.rs b/src/rpc/types/mod.rs index 24b9c32fe265..879a0cbb3446 100644 --- a/src/rpc/types/mod.rs +++ b/src/rpc/types/mod.rs @@ -62,6 +62,7 @@ pub struct ApiDealState { pub slash_epoch: ChainEpoch, #[serde(skip)] pub verified_claim: AllocationID, + pub sector_number: u64, } lotus_json_with_self!(ApiDealState); diff --git a/src/shim/actors/builtin/market/mod.rs b/src/shim/actors/builtin/market/mod.rs index 25f3525dbeb5..aa26fcb1e0f2 100644 --- a/src/shim/actors/builtin/market/mod.rs +++ b/src/shim/actors/builtin/market/mod.rs @@ -434,7 +434,10 @@ impl TryFrom<&fil_actor_market_state::v9::DealProposal> for DealProposal { provider: deal_proposal.provider, label: match &deal_proposal.label { fil_actor_market_state::v9::Label::String(s) => s.clone(), - fil_actor_market_state::v9::Label::Bytes(b) => String::from_utf8(b.clone())?, + fil_actor_market_state::v9::Label::Bytes(b) if b.is_empty() => Default::default(), + fil_actor_market_state::v9::Label::Bytes(b) => { + String::from_utf8(b.clone()).unwrap_or_default() + } }, start_epoch: deal_proposal.start_epoch, end_epoch: deal_proposal.end_epoch, @@ -459,7 +462,10 @@ impl TryFrom<&fil_actor_market_state::v10::DealProposal> for DealProposal { provider: from_address_v3_to_v2(deal_proposal.provider), label: match &deal_proposal.label { fil_actor_market_state::v10::Label::String(s) => s.clone(), - fil_actor_market_state::v10::Label::Bytes(b) => String::from_utf8(b.clone())?, + fil_actor_market_state::v10::Label::Bytes(b) if b.is_empty() => Default::default(), + fil_actor_market_state::v10::Label::Bytes(b) => { + String::from_utf8(b.clone()).unwrap_or_default() + } }, start_epoch: deal_proposal.start_epoch, end_epoch: deal_proposal.end_epoch, @@ -484,7 +490,10 @@ impl TryFrom<&fil_actor_market_state::v11::DealProposal> for DealProposal { provider: from_address_v3_to_v2(deal_proposal.provider), label: match &deal_proposal.label { fil_actor_market_state::v11::Label::String(s) => s.clone(), - fil_actor_market_state::v11::Label::Bytes(b) => String::from_utf8(b.clone())?, + fil_actor_market_state::v11::Label::Bytes(b) if b.is_empty() => Default::default(), + fil_actor_market_state::v11::Label::Bytes(b) => { + String::from_utf8(b.clone()).unwrap_or_default() + } }, start_epoch: deal_proposal.start_epoch, end_epoch: deal_proposal.end_epoch, @@ -509,7 +518,10 @@ impl TryFrom<&fil_actor_market_state::v12::DealProposal> for DealProposal { provider: from_address_v4_to_v2(deal_proposal.provider), label: match &deal_proposal.label { fil_actor_market_state::v12::Label::String(s) => s.clone(), - fil_actor_market_state::v12::Label::Bytes(b) => String::from_utf8(b.clone())?, + fil_actor_market_state::v12::Label::Bytes(b) if b.is_empty() => Default::default(), + fil_actor_market_state::v12::Label::Bytes(b) => { + String::from_utf8(b.clone()).unwrap_or_default() + } }, start_epoch: deal_proposal.start_epoch, end_epoch: deal_proposal.end_epoch, @@ -534,7 +546,10 @@ impl TryFrom<&fil_actor_market_state::v13::DealProposal> for DealProposal { 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())?, + fil_actor_market_state::v13::Label::Bytes(b) if b.is_empty() => Default::default(), + fil_actor_market_state::v13::Label::Bytes(b) => { + String::from_utf8(b.clone()).unwrap_or_default() + } }, start_epoch: deal_proposal.start_epoch, end_epoch: deal_proposal.end_epoch, @@ -559,7 +574,10 @@ impl TryFrom<&fil_actor_market_state::v14::DealProposal> for DealProposal { provider: from_address_v4_to_v2(deal_proposal.provider), label: match &deal_proposal.label { fil_actor_market_state::v14::Label::String(s) => s.clone(), - fil_actor_market_state::v14::Label::Bytes(b) => String::from_utf8(b.clone())?, + fil_actor_market_state::v14::Label::Bytes(b) if b.is_empty() => Default::default(), + fil_actor_market_state::v14::Label::Bytes(b) => { + String::from_utf8(b.clone()).unwrap_or_default() + } }, start_epoch: deal_proposal.start_epoch, end_epoch: deal_proposal.end_epoch, @@ -584,7 +602,10 @@ impl TryFrom<&fil_actor_market_state::v15::DealProposal> for DealProposal { provider: from_address_v4_to_v2(deal_proposal.provider), label: match &deal_proposal.label { fil_actor_market_state::v15::Label::String(s) => s.clone(), - fil_actor_market_state::v15::Label::Bytes(b) => String::from_utf8(b.clone())?, + fil_actor_market_state::v15::Label::Bytes(b) if b.is_empty() => Default::default(), + fil_actor_market_state::v15::Label::Bytes(b) => { + String::from_utf8(b.clone()).unwrap_or_default() + } }, start_epoch: deal_proposal.start_epoch, end_epoch: deal_proposal.end_epoch, @@ -609,7 +630,10 @@ impl TryFrom<&fil_actor_market_state::v16::DealProposal> for DealProposal { provider: from_address_v4_to_v2(deal_proposal.provider), label: match &deal_proposal.label { fil_actor_market_state::v16::Label::String(s) => s.clone(), - fil_actor_market_state::v16::Label::Bytes(b) => String::from_utf8(b.clone())?, + fil_actor_market_state::v16::Label::Bytes(b) if b.is_empty() => Default::default(), + fil_actor_market_state::v16::Label::Bytes(b) => { + String::from_utf8(b.clone()).unwrap_or_default() + } }, start_epoch: deal_proposal.start_epoch, end_epoch: deal_proposal.end_epoch, @@ -643,54 +667,63 @@ where last_updated_epoch: deal_state.last_updated_epoch, slash_epoch: deal_state.slash_epoch, verified_claim: deal_state.verified_claim, + sector_number: 0, })), DealStates::V9(deal_array) => Ok(deal_array.get(key)?.map(|deal_state| DealState { 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, + sector_number: 0, })), DealStates::V10(deal_array) => Ok(deal_array.get(key)?.map(|deal_state| DealState { 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, + sector_number: 0, })), DealStates::V11(deal_array) => Ok(deal_array.get(key)?.map(|deal_state| DealState { 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, + sector_number: 0, })), DealStates::V12(deal_array) => Ok(deal_array.get(key)?.map(|deal_state| DealState { 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, + sector_number: 0, })), DealStates::V13(deal_array) => Ok(deal_array.get(key)?.map(|deal_state| DealState { sector_start_epoch: deal_state.sector_start_epoch, last_updated_epoch: deal_state.last_updated_epoch, slash_epoch: deal_state.slash_epoch, verified_claim: 0, + sector_number: deal_state.sector_number, })), DealStates::V14(deal_array) => Ok(deal_array.get(key)?.map(|deal_state| DealState { sector_start_epoch: deal_state.sector_start_epoch, last_updated_epoch: deal_state.last_updated_epoch, slash_epoch: deal_state.slash_epoch, verified_claim: 0, + sector_number: deal_state.sector_number, })), DealStates::V15(deal_array) => Ok(deal_array.get(key)?.map(|deal_state| DealState { sector_start_epoch: deal_state.sector_start_epoch, last_updated_epoch: deal_state.last_updated_epoch, slash_epoch: deal_state.slash_epoch, verified_claim: 0, + sector_number: deal_state.sector_number, })), DealStates::V16(deal_array) => Ok(deal_array.get(key)?.map(|deal_state| DealState { sector_start_epoch: deal_state.sector_start_epoch, last_updated_epoch: deal_state.last_updated_epoch, slash_epoch: deal_state.slash_epoch, verified_claim: 0, + sector_number: deal_state.sector_number, })), } } @@ -703,6 +736,7 @@ pub struct DealState { pub last_updated_epoch: ChainEpoch, // -1 if deal state never updated pub slash_epoch: ChainEpoch, // -1 if deal never slashed pub verified_claim: AllocationID, // ID of the verified registry allocation/claim for this deal's data (0 if none). + pub sector_number: u64, // 0 if not yet included in proven sector (0 is also a valid sector number) } impl DealState { @@ -713,6 +747,7 @@ impl DealState { last_updated_epoch: -1, slash_epoch: -1, verified_claim: 0, + sector_number: 0, } } }