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

Improve api compare ergonomics #4018

Merged
merged 21 commits into from
Mar 19, 2024
Merged

Improve api compare ergonomics #4018

merged 21 commits into from
Mar 19, 2024

Conversation

elmattic
Copy link
Contributor

@elmattic elmattic commented Mar 1, 2024

Summary of changes

Changes introduced in this pull request:

  • Add debug trace with the request's response
  • Derive communication protocols from ApiInfos and check that:
    • Forest and Lotus protocol should match
    • Protocol should either be /http or /ws
  • Remove forest-tool api compare --ws flag

Usage examples:

$ RUST_LOG=forest_filecoin::rpc_client=debug ./forest-tool api compare forest_snapshot_calibnet_2024-03-18_height_1448006.forest.car.zst --filter EthGasPrice 
2024-03-18T18:03:19.494692Z DEBUG forest_filecoin::rpc_client: Using JSON-RPC v2 HTTP URL: http://127.0.0.1:2345/rpc/v1
2024-03-18T18:03:21.694154Z DEBUG forest_filecoin::rpc_client: Response: Ok(String("0x0"))
2024-03-18T18:03:21.694480Z DEBUG forest_filecoin::rpc_client: Using JSON-RPC v2 HTTP URL: http://127.0.0.1:1234/rpc/v1
2024-03-18T18:03:21.697877Z DEBUG forest_filecoin::rpc_client: Response: Ok(String("0x4e99f2f5"))
| RPC Method           | Forest | Lotus |
|----------------------|--------|-------|
| Filecoin.EthGasPrice | Valid  | Valid |

$ RUST_LOG=forest_filecoin::rpc_client=debug ./forest-tool api compare --lotus /ip4/127.0.0.1/tcp/1234/ws --forest /ip4/127.0.0.1/tcp/2345/http forest_snapshot_calibnet_2024-03-18_height_1448006.forest.car.zst --filter EthGasPrice
Error: communication protocols mismatch: Some("http") (Forest) is different from Some("ws") (Lotus)

$ RUST_LOG=forest_filecoin::rpc_client=debug ./forest-tool api compare --lotus /ip4/127.0.0.1/tcp/1234/ws --forest /ip4/127.0.0.1/tcp/2345/ws forest_snapshot_calibnet_2024-03-18_height_1448006.forest.car.zst --filter EthGasPrice
2024-03-18T18:15:42.306023Z DEBUG forest_filecoin::rpc_client: Using JSON-RPC v2 WS URL: ws://127.0.0.1:2345/rpc/v1
2024-03-18T18:15:43.929513Z DEBUG forest_filecoin::rpc_client: Response: Ok(String("0x0"))
2024-03-18T18:15:43.929617Z DEBUG forest_filecoin::rpc_client: Using JSON-RPC v2 WS URL: ws://127.0.0.1:1234/rpc/v1
2024-03-18T18:15:43.933110Z DEBUG forest_filecoin::rpc_client: Response: Ok(String("0x30c04"))

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,
  • 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.

src/rpc_client/mod.rs Outdated Show resolved Hide resolved
@elmattic elmattic marked this pull request as ready for review March 1, 2024 13:23
@elmattic elmattic requested a review from a team as a code owner March 1, 2024 13:23
@elmattic elmattic requested review from hanabi1224 and LesnyRumcajs and removed request for a team March 1, 2024 13:23
src/rpc_client/mod.rs Outdated Show resolved Hide resolved
src/tool/subcommands/api_cmd.rs Outdated Show resolved Hide resolved
src/tool/subcommands/api_cmd.rs Outdated Show resolved Hide resolved
src/tool/subcommands/api_cmd.rs Outdated Show resolved Hide resolved
src/rpc_client/mod.rs Outdated Show resolved Hide resolved
src/tool/subcommands/api_cmd.rs Outdated Show resolved Hide resolved
src/rpc_client/mod.rs Outdated Show resolved Hide resolved
src/rpc_client/mod.rs Outdated Show resolved Hide resolved
Comment on lines +1246 to +1267
fn test_derive_protocol() {
let forest = ApiInfo::from_str("/ip4/127.0.0.1/tcp/2345/http").expect("infallible");
let lotus = ApiInfo::from_str("/ip4/127.0.0.1/tcp/1234/http").expect("infallible");
assert!(matches!(
derive_protocol(&forest, &lotus),
Ok(CommunicationProtocol::Http)
));

let forest = ApiInfo::from_str("/ip4/127.0.0.1/tcp/2345/ws").expect("infallible");
let lotus = ApiInfo::from_str("/ip4/127.0.0.1/tcp/1234/ws").expect("infallible");
assert!(matches!(
derive_protocol(&forest, &lotus),
Ok(CommunicationProtocol::Ws)
));

let forest = ApiInfo::from_str("/ip4/127.0.0.1/tcp/2345/http").expect("infallible");
let lotus = ApiInfo::from_str("/ip4/127.0.0.1/tcp/1234/ws").expect("infallible");
assert!(derive_protocol(&forest, &lotus).is_err());

let forest = ApiInfo::from_str("/ip4/127.0.0.1/tcp/2345/wss").expect("infallible");
let lotus = ApiInfo::from_str("/ip4/127.0.0.1/tcp/1234/wss").expect("infallible");
assert!(derive_protocol(&forest, &lotus).is_err());
Copy link
Member

Choose a reason for hiding this comment

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

nit: I'd unwrap on those, infallible doesn't bring any more context, and these are tests anyway

@elmattic elmattic added this pull request to the merge queue Mar 19, 2024
Merged via the queue into main with commit d44ae18 Mar 19, 2024
28 checks passed
@elmattic elmattic deleted the elmattic/api-compare-checks branch March 19, 2024 17:45
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.

None yet

3 participants