Skip to content

Commit

Permalink
Merge branch 'main' into elmattic/state-miner-initial-pledge-collateral
Browse files Browse the repository at this point in the history
  • Loading branch information
elmattic authored May 1, 2024
2 parents 5b7e6f1 + 63d87f2 commit 74336c2
Showing 1 changed file with 11 additions and 43 deletions.
54 changes: 11 additions & 43 deletions src/rpc/methods/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ use crate::rpc::types::ApiTipsetKey;
use crate::rpc::{ApiVersion, Ctx, Permission, RpcMethod, ServerError};
use crate::shim::clock::ChainEpoch;
use crate::shim::error::ExitCode;
use crate::shim::executor::Receipt;
use crate::shim::message::Message;
use crate::utils::io::VoidAsyncWriter;
use anyhow::{Context as _, Result};
use cid::Cid;
use fil_actors_shared::fvm_ipld_amt::Amtv0 as Amt;
use fvm_ipld_blockstore::Blockstore;
use fvm_ipld_encoding::{CborStore, RawBytes};
use hex::ToHex;
Expand Down Expand Up @@ -132,40 +132,10 @@ impl RpcMethod<1> for ChainGetParentReceipts {
let block_header: CachingBlockHeader = store
.get_cbor(&block_cid)?
.with_context(|| format!("can't find block header with cid {block_cid}"))?;
let mut receipts = Vec::new();
if block_header.epoch == 0 {
return Ok(vec![]);
}

// Try Receipt_v4 first. (Receipt_v4 and Receipt_v3 are identical, use v4 here)
if let Ok(amt) =
Amt::<fvm_shared4::receipt::Receipt, _>::load(&block_header.message_receipts, store)
.map_err(|_| {
ErrorObjectOwned::owned::<()>(
1,
format!(
"failed to root: ipld: could not find {}",
block_header.message_receipts
),
None,
)
})
{
amt.for_each(|_, receipt| {
receipts.push(ApiReceipt {
exit_code: receipt.exit_code.into(),
return_data: receipt.return_data.clone(),
gas_used: receipt.gas_used,
events_root: receipt.events_root,
});
Ok(())
})?;
} else {
// Fallback to Receipt_v2.
let amt = Amt::<fvm_shared2::receipt::Receipt, _>::load(
&block_header.message_receipts,
store,
)
let receipts = Receipt::get_receipts(store, block_header.message_receipts)
.map_err(|_| {
ErrorObjectOwned::owned::<()>(
1,
Expand All @@ -175,17 +145,15 @@ impl RpcMethod<1> for ChainGetParentReceipts {
),
None,
)
})?;
amt.for_each(|_, receipt| {
receipts.push(ApiReceipt {
exit_code: receipt.exit_code.into(),
return_data: receipt.return_data.clone(),
gas_used: receipt.gas_used as _,
events_root: None,
});
Ok(())
})?;
}
})?
.iter()
.map(|r| ApiReceipt {
exit_code: r.exit_code().into(),
return_data: r.return_data(),
gas_used: r.gas_used(),
events_root: r.events_root(),
})
.collect();

Ok(receipts)
}
Expand Down

0 comments on commit 74336c2

Please sign in to comment.