Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rpc): implement EthGetTransactionByBlockNumberAndIndex #5030

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
- [#4701](https://github.com/ChainSafe/forest/issues/4701) Add support for the
`Filecoin.EthGetTransactionByBlockHashAndIndex` RPC method.

- [#5020](https://github.com/ChainSafe/forest/issues/5020) Add support for the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this needs to be moved to under Forest unreleased section

`Filecoin.EthGetTransactionByBlockNumberAndIndex` RPC method.

### Changed

### Removed
Expand Down
1 change: 0 additions & 1 deletion scripts/tests/api_compare/filter-list
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
# TODO: https://github.com/ChainSafe/forest/issues/4996
!Filecoin.EthGetTransactionReceipt
!Filecoin.EthGetTransactionReceiptLimited
!Filecoin.EthGetTransactionByBlockNumberAndIndex
# TODO: https://github.com/ChainSafe/forest/issues/5006
!Filecoin.EthGetBlockReceipts
1 change: 0 additions & 1 deletion scripts/tests/api_compare/filter-list-offline
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,5 @@
# TODO: https://github.com/ChainSafe/forest/issues/4996
!Filecoin.EthGetTransactionReceipt
!Filecoin.EthGetTransactionReceiptLimited
!Filecoin.EthGetTransactionByBlockNumberAndIndex
# TODO: https://github.com/ChainSafe/forest/issues/5006
!Filecoin.EthGetBlockReceipts
42 changes: 37 additions & 5 deletions src/rpc/methods/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2015,19 +2015,51 @@ pub enum EthGetTransactionByBlockNumberAndIndex {}
impl RpcMethod<2> for EthGetTransactionByBlockNumberAndIndex {
const NAME: &'static str = "Filecoin.EthGetTransactionByBlockNumberAndIndex";
const NAME_ALIAS: Option<&'static str> = Some("eth_getTransactionByBlockNumberAndIndex");
const PARAM_NAMES: [&'static str; 2] = ["p1", "p2"];
const PARAM_NAMES: [&'static str; 2] = ["block_number", "tx_index"];
const API_PATHS: ApiPaths = ApiPaths::V1;
const PERMISSION: Permission = Permission::Read;

type Params = (EthUint64, EthUint64);
type Ok = Option<ApiEthTx>;

async fn handle(
_ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
(_p1, _p2): Self::Params,
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
(block_number, tx_index): Self::Params,
) -> Result<Self::Ok, ServerError> {
// Lotus doesn't support this method (v1.29.0), so do we.
Err(ServerError::unsupported_method())
let height = block_number.0 as ChainEpoch;
let head = ctx.chain_store().heaviest_tipset();

if height > head.epoch() {
elmattic marked this conversation as resolved.
Show resolved Hide resolved
return Err(anyhow::anyhow!("requested a future epoch (beyond \"latest\")").into());
}

let ts = ctx
.chain_index()
.tipset_by_height(height, head, ResolveNullTipset::TakeOlder)?;

let messages = ctx.chain_store().messages_for_tipset(&ts)?;
elmattic marked this conversation as resolved.
Show resolved Hide resolved

let EthUint64(index) = tx_index;
let msg = messages.get(index as usize).with_context(|| {
format!(
"index {} out of range: tipset contains {} messages",
index,
messages.len()
)
})?;

let state = StateTree::new_from_root(ctx.store_owned(), ts.parent_state())?;

let tx = new_eth_tx(
&ctx,
&state,
ts.epoch(),
&ts.key().cid()?,
&msg.cid(),
index,
)?;

Ok(Some(tx))
}
}

Expand Down
Loading