Skip to content

Commit

Permalink
Add logs to EthTxReceipt (#4988)
Browse files Browse the repository at this point in the history
  • Loading branch information
elmattic authored Nov 22, 2024
1 parent ccd16c6 commit bb51791
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions scripts/tests/api_compare/filter-list
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions scripts/tests/api_compare/filter-list-offline
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 5 additions & 2 deletions src/rpc/methods/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1074,7 +1075,7 @@ fn new_eth_tx_from_message_lookup<DB: Blockstore>(
})
}

async fn new_eth_tx_receipt<DB: Blockstore>(
async fn new_eth_tx_receipt<DB: Blockstore + Send + Sync + 'static>(
ctx: &Ctx<DB>,
tx: &ApiEthTx,
message_lookup: &MessageLookup,
Expand Down Expand Up @@ -1132,7 +1133,9 @@ async fn new_eth_tx_receipt<DB: Blockstore>(
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)
}
Expand Down
25 changes: 15 additions & 10 deletions src/rpc/methods/eth/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,10 @@ impl EthEventHandler {
match_addr && match_topics
}

async fn collect_events<DB: Blockstore + Send + Sync + 'static>(
pub async fn collect_events<DB: Blockstore + Send + Sync + 'static>(
ctx: &Ctx<DB>,
tipset: &Arc<Tipset>,
spec: &EthFilterSpec,
spec: Option<&EthFilterSpec>,
collected_events: &mut Vec<CollectedEvent>,
) -> anyhow::Result<()> {
let tipset_key = tipset.key().clone();
Expand Down Expand Up @@ -285,12 +285,17 @@ impl EthEventHandler {
let entries: Vec<crate::shim::executor::Entry> = event.event().entries();
// dbg!(&entries);

let matched = Self::do_match(spec, &eth_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, &eth_emitter_addr, &entries);
tracing::debug!(
"Event {} {}match filter topics",
event_idx,
if matched { "" } else { "do not " }
);
matched
} else {
true
};
if matched {
let entries: Vec<EventEntry> = entries
.into_iter()
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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?;
}
}
}
Expand Down

0 comments on commit bb51791

Please sign in to comment.