-
Notifications
You must be signed in to change notification settings - Fork 231
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
Fix panic in evidence serialization #798
Conversation
Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #798 +/- ##
======================================
Coverage 55.7% 55.7%
======================================
Files 198 198
Lines 14063 14068 +5
Branches 3696 3692 -4
======================================
+ Hits 7834 7840 +6
+ Misses 5897 5896 -1
Partials 332 332
Continue to review full report at Codecov.
|
Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a good fix!
But I wonder if we actually need this whole custom serializer at all?
Disclaimer: It's 2am here and I am likely missing something, so please bear with me :)
It seems to me that this custom EvidenceVariant
is defined the very same way as its counterpart in the generated code.
Custom EvidenceVariant
:
#[derive(Clone, PartialEq, ::serde::Deserialize, ::serde::Serialize)]
#[serde(tag = "type", content = "value")]
pub enum EvidenceVariant {
#[serde(rename = "tendermint/DuplicateVoteEvidence")]
DuplicateVoteEvidence(crate::tendermint::types::DuplicateVoteEvidence),
#[serde(rename = "tendermint/LightClientAttackEvidence")]
LightClientAttackEvidence(crate::tendermint::types::LightClientAttackEvidence),
}
Generated code in proto/src/prost/tendermint.types.rs
#[derive(Clone, PartialEq, ::prost::Oneof, ::serde::Deserialize, ::serde::Serialize)]
#[serde(tag = "type", content = "value")]
pub enum Sum {
#[prost(message, tag = "1")]
#[serde(rename = "tendermint/DuplicateVoteEvidence")]
DuplicateVoteEvidence(super::DuplicateVoteEvidence),
#[prost(message, tag = "2")]
#[serde(rename = "tendermint/LightClientAttackEvidence")]
LightClientAttackEvidence(super::LightClientAttackEvidence),
}
Could we instead simply remove the #[serde(from = "crate::serializers::evidence::EvidenceVariant", into = "crate::serializers::evidence::EvidenceVariant")]
annotation from the generated Evidence
type and get the very same behavior wrt. to serialization without having to introduce these weird From
instances?
Okay, apparently it's not as simple as I though since my branch where I implemented the changes suggested above fails to deserialize the evidence: https://github.com/informalsystems/tendermint-rs/runs/1811124652
It's still not clear to me why this fails, so I would be grateful if someone can enlighten me :)
Oh I think I got it: the RPC endpoint actually returns the Yep, that's it. Confirmed by modifying |
Signed-off-by: Thane Thomson <[email protected]>
I still wonder if there's not another way to work around this discrepancy between the Protobuf definition and the JSON format returned via RPC. Would it help if we made Evidence into a DomainType, like we do for other datatypes? |
Yeah the whole reason for this custom serializer is because of how Protobuf wraps its Technically, we should never really encounter an instance where we receive evidence where the
We do actually have a domain type for it in the I have to say, it looks like the dream of a single set of data structures is quite far off. Part of this has to do with the annoying way in which prost generates If we were separating things "properly", we'd have one set of dedicated Protobuf types, one set of JSON types, and one set of domain types. But the sheer amount of manual code and maintenance required for that doesn't really seem justified, especially since so much of it's boilerplate. On a separate note, it looks like the |
Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
Closes #782