Skip to content

Commit

Permalink
fix(rpc): error in StateMarketDeals and StateMarketStorageDeal (#5089)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanabi1224 authored Dec 17, 2024
1 parent 68b13b6 commit d026d27
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 14 deletions.
3 changes: 0 additions & 3 deletions scripts/tests/api_compare/filter-list
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 0 additions & 3 deletions scripts/tests/api_compare/filter-list-offline
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/rpc/methods/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 2 additions & 0 deletions src/rpc/types/deal_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ impl From<DealState> 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,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/rpc/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
51 changes: 43 additions & 8 deletions src/shim/actors/builtin/market/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
})),
}
}
Expand All @@ -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 {
Expand All @@ -713,6 +747,7 @@ impl DealState {
last_updated_epoch: -1,
slash_epoch: -1,
verified_claim: 0,
sector_number: 0,
}
}
}
Expand Down

0 comments on commit d026d27

Please sign in to comment.