From bb5179178641f51b2d2ddf732f3ec2d28cad028d Mon Sep 17 00:00:00 2001 From: Guillaume Potier Date: Fri, 22 Nov 2024 14:52:25 +0100 Subject: [PATCH] Add logs to EthTxReceipt (#4988) --- CHANGELOG.md | 3 +++ scripts/tests/api_compare/filter-list | 2 -- scripts/tests/api_compare/filter-list-offline | 2 -- src/rpc/methods/eth.rs | 7 ++++-- src/rpc/methods/eth/filter/mod.rs | 25 +++++++++++-------- 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ecb1b8b3da..9e3cca29174 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,9 @@ ### Fixed +- [#4988](https://github.com/ChainSafe/forest/pull/4988) Fix the `logs` member + in `EthTxReceipt` that was initialized with a default value. + ## Forest 0.22.0 "Pad Thai" Mandatory release for mainnet node operators. It sets the upgrade epoch for the diff --git a/scripts/tests/api_compare/filter-list b/scripts/tests/api_compare/filter-list index acc86400fa0..c83cd5efbdd 100644 --- a/scripts/tests/api_compare/filter-list +++ b/scripts/tests/api_compare/filter-list @@ -4,8 +4,6 @@ !Filecoin.MpoolGetNonce # CustomCheckFailed in Forest: https://github.com/ChainSafe/forest/actions/runs/9593268587/job/26453560366 !Filecoin.StateReplay -# TODO(elmattic): https://github.com/ChainSafe/forest/issues/4759 -!Filecoin.EthGetTransactionReceipt # TODO(elmattic): https://github.com/ChainSafe/forest/issues/4851 !Filecoin.EthGetLogs # TODO: https://github.com/ChainSafe/forest/issues/4968 diff --git a/scripts/tests/api_compare/filter-list-offline b/scripts/tests/api_compare/filter-list-offline index c0484263013..8a135f274d1 100644 --- a/scripts/tests/api_compare/filter-list-offline +++ b/scripts/tests/api_compare/filter-list-offline @@ -35,8 +35,6 @@ !eth_getBlockByNumber !Filecoin.ChainSetHead # TODO(elmattic): https://github.com/ChainSafe/forest/issues/4759 -!Filecoin.EthGetTransactionReceipt -# TODO(elmattic): https://github.com/ChainSafe/forest/issues/4851 !Filecoin.EthGetLogs # TODO: https://github.com/ChainSafe/forest/issues/4968 !Filecoin.StateCirculatingSupply diff --git a/src/rpc/methods/eth.rs b/src/rpc/methods/eth.rs index 7fd6f9bc5cd..f67c787ab70 100644 --- a/src/rpc/methods/eth.rs +++ b/src/rpc/methods/eth.rs @@ -23,6 +23,7 @@ use crate::lotus_json::{lotus_json_with_self, HasLotusJson}; use crate::message::{ChainMessage, Message as _, SignedMessage}; use crate::rpc::error::ServerError; use crate::rpc::types::{ApiTipsetKey, EventEntry, MessageLookup}; +use crate::rpc::EthEventHandler; use crate::rpc::{ApiPaths, Ctx, Permission, RpcMethod}; use crate::shim::actors::eam; use crate::shim::actors::is_evm_actor; @@ -1074,7 +1075,7 @@ fn new_eth_tx_from_message_lookup( }) } -async fn new_eth_tx_receipt( +async fn new_eth_tx_receipt( ctx: &Ctx, tx: &ApiEthTx, message_lookup: &MessageLookup, @@ -1132,7 +1133,9 @@ async fn new_eth_tx_receipt( receipt.contract_address = Some(ret.eth_address.into()); } - // TODO(elmattic): https://github.com/ChainSafe/forest/issues/4759 + let mut events = vec![]; + EthEventHandler::collect_events(ctx, &parent_ts, None, &mut events).await?; + receipt.logs = eth_filter_logs_from_events(ctx, &events)?; Ok(receipt) } diff --git a/src/rpc/methods/eth/filter/mod.rs b/src/rpc/methods/eth/filter/mod.rs index 7dd702f618e..62d1e4cb42e 100644 --- a/src/rpc/methods/eth/filter/mod.rs +++ b/src/rpc/methods/eth/filter/mod.rs @@ -240,10 +240,10 @@ impl EthEventHandler { match_addr && match_topics } - async fn collect_events( + pub async fn collect_events( ctx: &Ctx, tipset: &Arc, - spec: &EthFilterSpec, + spec: Option<&EthFilterSpec>, collected_events: &mut Vec, ) -> anyhow::Result<()> { let tipset_key = tipset.key().clone(); @@ -285,12 +285,17 @@ impl EthEventHandler { let entries: Vec = event.event().entries(); // dbg!(&entries); - let matched = Self::do_match(spec, ð_emitter_addr, &entries); - tracing::debug!( - "Event {} {}match filter topics", - event_idx, - if matched { "" } else { "do not " } - ); + let matched = if let Some(spec) = spec { + let matched = Self::do_match(spec, ð_emitter_addr, &entries); + tracing::debug!( + "Event {} {}match filter topics", + event_idx, + if matched { "" } else { "do not " } + ); + matched + } else { + true + }; if matched { let entries: Vec = entries .into_iter() @@ -334,7 +339,7 @@ impl EthEventHandler { ParsedFilterTipsets::Hash(block_hash) => { let tipset = get_tipset_from_hash(ctx.chain_store(), &block_hash)?; let tipset = Arc::new(tipset); - Self::collect_events(ctx, &tipset, &spec, &mut collected_events).await?; + Self::collect_events(ctx, &tipset, Some(&spec), &mut collected_events).await?; } ParsedFilterTipsets::Range(range) => { let max_height = if *range.end() == -1 { @@ -363,7 +368,7 @@ impl EthEventHandler { .take(num_tipsets) { let tipset = Arc::new(tipset); - Self::collect_events(ctx, &tipset, &spec, &mut collected_events).await?; + Self::collect_events(ctx, &tipset, Some(&spec), &mut collected_events).await?; } } }