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 Filecoin.EthGetLogs #4780

Merged
merged 113 commits into from
Oct 23, 2024
Merged

feat(rpc) Implement Filecoin.EthGetLogs #4780

merged 113 commits into from
Oct 23, 2024

Conversation

elmattic
Copy link
Contributor

@elmattic elmattic commented Sep 19, 2024

Summary of changes

Changes introduced in this pull request:

  • Partially implement RPC method Filecoin.EthGetLogs
./forest-tool api compare --lotus /ip4/127.0.0.1/tcp/1234/http --forest /ip4/127.0.0.1/tcp/2345/http forest_snapshot_calibnet_2024-10-03_height_2021383.forest.car.zst --filter EthGetLogs -n 800

| RPC Method                | Forest            | Lotus |
|---------------------------|-------------------|-------|
| Filecoin.EthGetLogs (272) | CustomCheckFailed | Valid |
| Filecoin.EthGetLogs (528) | Valid             | Valid |

Reference issue to close (if applicable)

Closes

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

@elmattic
Copy link
Contributor Author

@LesnyRumcajs added a few unit tests to cover the most intricated functions

Comment on lines +306 to +307
#[derive(Clone, Debug)]
pub enum StampedEvent {
Copy link
Member

Choose a reason for hiding this comment

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

Could we add some docs on the public items such as this StampedEvent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure!

Comment on lines 329 to 332
amt.for_each(|_, event| {
events.push(event.clone().into());
Ok(())
})?;
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's just remove this. It's deadcode anyway.

Comment on lines 269 to 273
enable_event_caching: if enable_event_caching {
EventCache::Cached
} else {
EventCache::NotCached
},
Copy link
Member

Choose a reason for hiding this comment

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

Design idea - I wonder if we can make the code more straightforward by injecting an trait object of EventCache. It would be instantiated at the start of the program to either an implementation without cache or with a cache. This way, throughout the code, you wouldn't need to check if the caching is enabled or not - you'd write to it but whether it would actually happen would be completely transparent.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Excellent idea! In the future we'll likely have:

  • No cache (e.g., a node without RPC)
  • Cache Events in tipset state cache
  • Use sidecar indexer to retrieve Events

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the code to store events in a dedicated cache (with a dedicated size), avoiding the need to store unnecessary None values in the SM tipset state cache when events are not in use. This also prevents polluting the SM cache and avoids potential performance slowdowns.

As for injecting an trait object, I think it would add some complexity compared to using an enum at this stage. Let's consider that for a future PR, or once we have an indexer in place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One more thing, we can remove the --enable-event-caching flag now.

Comment on lines +2276 to +2284
fn match_key(key: &str) -> Option<usize> {
match key.get(0..2) {
Some("t1") => Some(0),
Some("t2") => Some(1),
Some("t3") => Some(2),
Some("t4") => Some(3),
_ => None,
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Will this work on mainnet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

src/rpc/methods/eth.rs Show resolved Hide resolved
@elmattic elmattic added this pull request to the merge queue Oct 23, 2024
Merged via the queue into main with commit 6a2bb45 Oct 23, 2024
34 checks passed
@elmattic elmattic deleted the elmattic/eth-get-logs branch October 23, 2024 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants