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

Add subscriptions support #225

Merged
merged 122 commits into from
May 23, 2020

Conversation

zmanian
Copy link
Contributor

@zmanian zmanian commented Apr 17, 2020

To do

  • integration tests
  • Typed events
  • Referenced an issue explaining the need for the change
  • Updated all relevant documentation in docs
  • Updated all code comments where relevant
  • Wrote tests
  • Updated CHANGES.md

Shivani912 and others added 30 commits March 17, 2020 17:52
* initial new commit struct

* update functions

* fixed deserialization for new commit struct

* updated links to generator + val_set_test file

* Update tendermint/src/account.rs

Co-Authored-By: Ismail Khoffi <Ismail.Khoffi@gmail.com>

* fmt

* clippy

* rpc tests: grab latest example fro commit:
 - use https://docs.tendermint.com/master/rpc/#/Info/commit
 - update chain_id: cosmoshub-1 to cosmoshub-2 everywhere else
 - manually kept `id` a string in JSONrpc responses

* Actually let's go cosmoshub-3:

 - grabbed from: https://rpc.cosmos.network/commit?height=2

* Fix commit test

- regenerated commit.json via
`curl -X GET "http://localhost:26657/commit?height=10" -H "accept: application/json"`

* Fix block test

- "regenerated" block.json via
`curl -X GET "http://localhost:26657/block?height=10" -H "accept: application/json"`

* Fix first_block test

- "regenerated" block.json via
`curl -X GET "http://localhost:26657/block?height=1" -H "accept: application/json" `

Co-authored-by: Shivani Joshi <joshi.shivani912@gmail.com>
Co-authored-by: Shivani Joshi <46731446+Shivani912@users.noreply.github.com>
fix /abci_info & /genesis:
 - add app_version & use #[serde(default)] to deal with omitted fields in JSON
 - make app_state in /genesis reply optional
 - fix string in abci_info test (kvstore wont reply with "GaiaApp")

 verify tests pass via running `tendermint node --proxy_app=kvstore` and
 `cargo test -- --nocapture --ignored
Comment on lines 77 to 98
match serde_json::from_str::<JsonRPCBlockResult>(&msg.to_string()) {
Ok(data) => {
if let Some(block_result) = data.0.result {
Ok(Event::JsonRPCBlockResult(Box::new(block_result)))
} else {
// The Websocket should never send an empty block
panic!("Websocket sent us an empty block")
}
}
Err(_) => match serde_json::from_str::<JsonRPCTransactionResult>(&msg.to_string()) {
Ok(data) => {
if let Some(tx_result) = data.0.result {
Ok(Event::JsonRPCTransactionResult(Box::new(tx_result)))
} else {
// The Websocket should never send an empty transaction
panic!("Websocket sent us an empty transaction")
}
}
Err(_) => match serde_json::from_str::<serde_json::Value>(&msg.to_string()) {
Ok(json_value) => Ok(Event::GenericJSONEvent(json_value)),
Err(_) => Ok(Event::GenericStringEvent(msg.to_string())),
},
Copy link
Member

Choose a reason for hiding this comment

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

I'm pretty sure this can be simplified in a way that serde returns the correct Event enum variant and you don't need matching here again. Non-blocking for merging this PR though.

@liamsi
Copy link
Member

liamsi commented May 23, 2020

Any idea why the integration test receives a GenericJSONEvent (which basically looks like a JsonRPCBlockResult)?
https://github.com/informalsystems/tendermint-rs/pull/225/checks?check_run_id=701830448#step:5:266

You were saying that this does not fail against your local gaia build? Which (tendermint) version does that use?

@liamsi
Copy link
Member

liamsi commented May 23, 2020

I'll try to figure out what is going on with the integration test this afternoon and we should be ready to merge.

@zmanian
Copy link
Contributor Author

zmanian commented May 23, 2020

So the integration test fails if Serde fails to deserialize the Block event as a expected type and instead falls through to a Generic JSON event.

@zmanian
Copy link
Contributor Author

zmanian commented May 23, 2020

The GOZ code is running

gaiad tendermint version
tendermint: 0.33.4
abci: 0.16.2
blockprotocol: 10
p2pprotocol: 7

and the integration test appears to pass with this version.

@liamsi
Copy link
Member

liamsi commented May 23, 2020

So the integration test fails if Serde fails to deserialize the Block event as a expected type and instead falls through to a Generic JSON event.

Exactly. The reason why it's falling through is Error("missing field events", line: 61, column: 32). But interestingly, the JSON payload has that field 🤔

I doubt this has anything to do with different tendermint versions.

Comment on lines 84 to 87
dbg!("Error:");
dbg!(e);
dbg!("msg:");
dbg!(&msg.to_string());
Copy link
Member

Choose a reason for hiding this comment

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

These lines should be removed before merging.

Suggested change
dbg!("Error:");
dbg!(e);
dbg!("msg:");
dbg!(&msg.to_string());

Comment on lines 78 to 97
match serde_json::from_str::<JsonRPCBlockResult>(&msg.to_string()) {
Ok(data) => {
let block_result = data.into_result()?;
Ok(Event::JsonRPCBlockResult(Box::new(block_result)))
}
Err(e) => {
dbg!("Error:");
dbg!(e);
dbg!("msg:");
dbg!(&msg.to_string());
match serde_json::from_str::<JsonRPCTransactionResult>(&msg.to_string()) {
Ok(data) => {
let tx_result = data.into_result()?;
Ok(Event::JsonRPCTransactionResult(Box::new(tx_result)))
}
Err(_) => match serde_json::from_str::<serde_json::Value>(&msg.to_string()) {
Ok(json_value) => Ok(Event::GenericJSONEvent(json_value)),
Err(_) => Ok(Event::GenericStringEvent(msg.to_string())),
},
}
Copy link
Member

Choose a reason for hiding this comment

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

I think ideally, we would not match case a lot here but instead of jsonrpc wrapping JsonRPCBlockResult, JsonRPCTransactionResult separately, we should wrap the whole Event enum and make it impl response::Response. serde can very well deal with enums so there is no need to try each variant separately. No need to block this PR on this though.

Copy link
Member

@liamsi liamsi left a comment

Choose a reason for hiding this comment

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

Let's merge this and deal with these in followup issues:

https://github.com/informalsystems/tendermint-rs/pull/225/files#r429444086
#225 (comment)
#225 (comment)

Thanks @zmanian 💪 Thanks @greg-szabo for helping with the debugging too!

@liamsi liamsi merged commit d28c4b1 into informalsystems:master May 23, 2020
@liamsi liamsi deleted the zaki-event-subscribe branch May 23, 2020 16:17
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