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

Open
wants to merge 108 commits into
base: main
Choose a base branch
from
Open

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 |

This PR introduces a new flag/configuration setting (enable_event_caching) to retain events in the Tipset cache.

If neither the RPC API nor the methods related to events are used, a value of false can be passed.

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

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.

Comment on lines +2651 to +2654
value: vec![
226, 71, 32, 244, 92, 183, 79, 45, 85, 241, 222, 235, 182, 9, 143, 80, 241, 11,
81, 29, 171, 138, 125, 71, 196, 129, 154, 8, 220, 208, 184, 149,
]
Copy link
Member

Choose a reason for hiding this comment

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

It'd be great to document where those test vectors come from.

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