-
Notifications
You must be signed in to change notification settings - Fork 326
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 client queries to the relayer #38
Changes from all commits
efbb695
7de4896
b528dc6
b783baa
3f4afdb
9b9917e
1558935
b603ccc
7da6712
ab168d8
5d5d988
46f70ce
a9b9b53
b1dd6ee
b5bc847
b68bff6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,82 @@ | ||||||||
use crate::ics02_client::client_type::ClientType; | ||||||||
use crate::ics23_commitment::CommitmentRoot; | ||||||||
|
||||||||
use crate::ics07_tendermint::header::Header; | ||||||||
use crate::ics24_host::client::ClientId; | ||||||||
use serde_derive::{Deserialize, Serialize}; | ||||||||
use std::time::Duration; | ||||||||
use tendermint::lite::Header as liteHeader; | ||||||||
|
||||||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||||||||
pub struct ClientState { | ||||||||
id: String, | ||||||||
trusting_period: Duration, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note (mostly to myself): in the go code, // A Duration represents the elapsed time between two instants
// as an int64 nanosecond count. The representation limits the
// largest representable duration to approximately 290 years.
type Duration int64 while rust's /// A `Duration` type to represent a span of time, typically used for system
/// timeouts.
///
/// Each `Duration` is composed of a whole number of seconds and a fractional part
/// represented in nanoseconds. If the underlying system does not support
/// nanosecond-level precision, APIs binding a system timeout will typically round up
/// the number of nanoseconds.
/// [...]
pub struct Duration {
secs: u64,
nanos: u32, // Always 0 <= nanos < NANOS_PER_SEC
} Same for the So for deserialization (independent from amino or not) we need to translate between the two. ref #45 |
||||||||
unbonding_period: Duration, | ||||||||
frozen_height: crate::Height, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The order in the go-code is different (latest header should be last):
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oy! good catch! thx, just changed. The problem is that we cannot test properly with SDK since we don't deserialize yet. Once we move to protobuf and we do the decoding we will catch more of these. |
||||||||
latest_header: Header, | ||||||||
} | ||||||||
|
||||||||
impl ClientState { | ||||||||
pub fn new( | ||||||||
id: String, | ||||||||
trusting_period: Duration, | ||||||||
unbonding_period: Duration, | ||||||||
latest_header: Header, | ||||||||
frozen_height: crate::Height, | ||||||||
) -> Self { | ||||||||
Self { | ||||||||
id, | ||||||||
trusting_period, | ||||||||
unbonding_period, | ||||||||
latest_header, | ||||||||
frozen_height, | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
impl crate::ics02_client::state::ClientState for ClientState { | ||||||||
type ValidationError = crate::ics07_tendermint::error::Error; | ||||||||
|
||||||||
fn client_id(&self) -> ClientId { | ||||||||
self.id.parse().unwrap() | ||||||||
} | ||||||||
|
||||||||
fn client_type(&self) -> ClientType { | ||||||||
ClientType::Tendermint | ||||||||
} | ||||||||
|
||||||||
fn get_latest_height(&self) -> crate::Height { | ||||||||
self.latest_header.signed_header.header.height() | ||||||||
} | ||||||||
|
||||||||
fn is_frozen(&self) -> bool { | ||||||||
false | ||||||||
} | ||||||||
|
||||||||
fn verify_client_consensus_state( | ||||||||
&self, | ||||||||
_root: &CommitmentRoot, | ||||||||
) -> Result<(), Self::ValidationError> { | ||||||||
unimplemented!() | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
#[cfg(test)] | ||||||||
mod tests { | ||||||||
use crate::test::test_serialization_roundtrip; | ||||||||
use tendermint::rpc::endpoint::abci_query::AbciQuery; | ||||||||
|
||||||||
#[test] | ||||||||
fn serialization_roundtrip_no_proof() { | ||||||||
let json_data = include_str!("../tests/query/serialization/client_state.json"); | ||||||||
println!("json_data: {:?}", json_data); | ||||||||
test_serialization_roundtrip::<AbciQuery>(json_data); | ||||||||
} | ||||||||
|
||||||||
#[test] | ||||||||
fn serialization_roundtrip_with_proof() { | ||||||||
let json_data = include_str!("../tests/query/serialization/client_state_proof.json"); | ||||||||
println!("json_data: {:?}", json_data); | ||||||||
test_serialization_roundtrip::<AbciQuery>(json_data); | ||||||||
} | ||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
//! ICS 07: Tendermint Client | ||
|
||
pub mod client_state; | ||
pub mod consensus_state; | ||
pub mod error; | ||
pub mod header; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
use serde_derive::{Deserialize, Serialize}; | ||
|
||
use crate::path::Path; | ||
use tendermint::abci; | ||
|
||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
pub struct CommitmentRoot; | ||
|
@@ -17,11 +18,11 @@ impl CommitmentPath { | |
} | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
pub struct CommitmentProof; | ||
|
||
pub type CommitmentProof = abci::Proof; | ||
/* | ||
impl CommitmentProof { | ||
pub fn from_bytes(_bytes: &[u8]) -> Self { | ||
todo!() | ||
} | ||
} | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we delete this but but extend the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but will do in a separate issue/PR |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use serde::{de::DeserializeOwned, Serialize}; | ||
use std::fmt::Debug; | ||
|
||
/// Test that a struct `T` can be: | ||
/// | ||
/// - parsed out of the provided JSON data | ||
/// - serialized back to JSON | ||
/// - parsed back from the serialized JSON of the previous step | ||
/// - that the two parsed structs are equal according to their `PartialEq` impl | ||
pub fn test_serialization_roundtrip<T>(json_data: &str) | ||
where | ||
T: Debug + Serialize + DeserializeOwned, | ||
{ | ||
let parsed0 = serde_json::from_str::<T>(json_data); | ||
assert!(parsed0.is_ok()); | ||
let parsed0 = parsed0.unwrap(); | ||
|
||
let serialized = serde_json::to_string(&parsed0); | ||
assert!(serialized.is_ok()); | ||
let serialized = serialized.unwrap(); | ||
|
||
let parsed1 = serde_json::from_str::<T>(&serialized); | ||
assert!(parsed1.is_ok()); | ||
let parsed1 = parsed1.unwrap(); | ||
println!("json_data0: {:?}", parsed0); | ||
println!("json_data1: {:?}", parsed1); | ||
|
||
// TODO - fix PartialEq bound issue in AbciQuery | ||
//assert_eq!(parsed0, parsed1); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"code": 0, | ||
"log": "", | ||
"info": "", | ||
"index": "0", | ||
"key": "Y2xpZW50U3RhdGUvaWJjb25lY2xpZW50", | ||
"value": "rwUhoYiWCgxpYmNvbmVjbGllbnQQgIDIkv+DkwIYgIDs2/7FnAMqiAUKgAQKxQIKAggKEgRpYmMxGBYiCwjMvIL0BRDIu58kKkgKICyeWhXpKZwrrUlzbaZ0DQnPqzkdNc8+k9eOogSLx43aEiQIARIgCFeoy6YD9BwuE0C1AU9BdEa2V51Cs28MXKewBA1rNtMyIBNgBAObhFbZAWB4KQGBQaC7Z/azZUkkSj2hMdZFFFppQiDses9b3+5uOFW4wZL6WWA0xtv9hTPe3Ib6BA7pzYQySUog7HrPW9/ubjhVuMGS+llgNMbb/YUz3tyG+gQO6c2EMklSIASAkbx93Cg/d7+/kdc8RNpYw9+KnLyGdAXYt/ParaIvWiBq+Q9GJMZNlWMQCpPikuUo+bJNzOKyjZSthVT8qdTQRmIgbjQLnP+zepicpUTmu3gKLHiQHT+zNzh2hRGjBhevoB1yFPbqil8EwnDU5G93rMLZvekApgKBErUBCBYaSAogZik4C8oy55EdSL4OhMTIAy8jsDvCYiK6ZYH58Wv6Q88SJAgBEiBIpIMYxWV2OFZh72/ooILjIPvaHEMZ008+w1h+rpi7WiJnCAISFPbqil8EwnDU5G93rMLZvekApgKBGgsIzbyC9AUQqI/hRyJAbloumBKmq9nNQ22y/XoogOCrp33xeHjzA2JyuxpR2oAtL+8KGwKbcCJvAZjwpqOEEiRdXJnQ1rHrubVJhg3WBRKCAQo/ChT26opfBMJw1ORvd6zC2b3pAKYCgRIlFiTeZCBdmybLcqCWKo8EBc9ZOM+rYKVUx4QmxhMYv93tBdcNDxhkEj8KFPbqil8EwnDU5G93rMLZvekApgKBEiUWJN5kIF2bJstyoJYqjwQFz1k4z6tgpVTHhCbGExi/3e0F1w0PGGQ=", | ||
"proof": null, | ||
"height": "100", | ||
"codespace": "" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"code": 0, | ||
"log": "", | ||
"info": "", | ||
"index": "0", | ||
"key": "Y2xpZW50U3RhdGUvaWJjb25lY2xpZW50", | ||
"value": "rwUhoYiWCgxpYmNvbmVjbGllbnQQgIDIkv+DkwIYgIDs2/7FnAMqiAUKgAQKxQIKAggKEgRpYmMxGBYiCwjMvIL0BRDIu58kKkgKICyeWhXpKZwrrUlzbaZ0DQnPqzkdNc8+k9eOogSLx43aEiQIARIgCFeoy6YD9BwuE0C1AU9BdEa2V51Cs28MXKewBA1rNtMyIBNgBAObhFbZAWB4KQGBQaC7Z/azZUkkSj2hMdZFFFppQiDses9b3+5uOFW4wZL6WWA0xtv9hTPe3Ib6BA7pzYQySUog7HrPW9/ubjhVuMGS+llgNMbb/YUz3tyG+gQO6c2EMklSIASAkbx93Cg/d7+/kdc8RNpYw9+KnLyGdAXYt/ParaIvWiBq+Q9GJMZNlWMQCpPikuUo+bJNzOKyjZSthVT8qdTQRmIgbjQLnP+zepicpUTmu3gKLHiQHT+zNzh2hRGjBhevoB1yFPbqil8EwnDU5G93rMLZvekApgKBErUBCBYaSAogZik4C8oy55EdSL4OhMTIAy8jsDvCYiK6ZYH58Wv6Q88SJAgBEiBIpIMYxWV2OFZh72/ooILjIPvaHEMZ008+w1h+rpi7WiJnCAISFPbqil8EwnDU5G93rMLZvekApgKBGgsIzbyC9AUQqI/hRyJAbloumBKmq9nNQ22y/XoogOCrp33xeHjzA2JyuxpR2oAtL+8KGwKbcCJvAZjwpqOEEiRdXJnQ1rHrubVJhg3WBRKCAQo/ChT26opfBMJw1ORvd6zC2b3pAKYCgRIlFiTeZCBdmybLcqCWKo8EBc9ZOM+rYKVUx4QmxhMYv93tBdcNDxhkEj8KFPbqil8EwnDU5G93rMLZvekApgKBEiUWJN5kIF2bJstyoJYqjwQFz1k4z6tgpVTHhCbGExi/3e0F1w0PGGQ=", | ||
"proof": { | ||
"ops": [ | ||
{ | ||
"type": "iavl:v", | ||
"key": "Y2xpZW50U3RhdGUvaWJjb25lY2xpZW50", | ||
"data": "6wEK6AEKKAgIEAwYHCogr722bXSL9572EU1Jgdz6re1sVtpscxSW4cjaLrCtKPoKKAgGEAcYHCIg1wO/S0DOyBX5/zwOTIQt5lY7SkEJUORfEfZtHH6ZcLcKKAgEEAQYHCIgvBVVJn1U3LKVuitwm6hAvnwujQDcyMOOp5YdNbwdyTEKKAgCEAIYFyIgcuZfF//lb+VDAKtkXsR/J2/QPYlaw8HvrSmNqDf1iVYaPgoYY2xpZW50U3RhdGUvaWJjb25lY2xpZW50EiDV6DHA5N7GJNbSj0hzc586MXPwXDj4H57rYWZesk2XjRgX" | ||
}, | ||
{ | ||
"type": "multistore", | ||
"key": "aWJj", | ||
"data": "CtUECi4KBGJhbmsSJgokCGQSIPfIBFZd98DupWwTml7I8kZFWKgF8ZTlslblitSLTJjqCi0KA2FjYxImCiQIZBIg3ZgdzN65c2/J62tIVCmQJwnN8Ho9dULDSL9dKEyA+cgKDwoHdXBncmFkZRIECgIIZAoxCgdzdGFraW5nEiYKJAhkEiCWTzW3aCWkLAyuZxi9z2CSXhmtmcRWEKi6K9ywkrVZMwoyCghzbGFzaGluZxImCiQIZBIgj6AcKVZzEJeL1r3wf9Qi5B53bjomfcn3g76fvuJn/FkKMAoGc3VwcGx5EiYKJAhkEiCRsUBZCybnNEYnaNqDTOO1pNEuAfGgY7pQMrgLCyUWBQotCgNnb3YSJgokCGQSIGDNE3wZYuysYWOJ1oA0gz8pIVCcLShapfUVOZfOlop0Ci0KA2liYxImCiQIZBIgWnpokBJ4idAoXzLzbjOOaBwU5E3oz4QJuAV8mShsqzwKLgoEbWFpbhImCiQIZBIgsZzwmLQ7PH1UeZ/vCUSqlQmfgt3CGfoMgJLkUqKCv0EKMAoGcGFyYW1zEiYKJAhkEiB8VIzExUHX+SvHZFz/P9NM9THnw/gTDDLVReuZX8htLgo2CgxkaXN0cmlidXRpb24SJgokCGQSIMaSvcpnTBH1nyPp/m3Ab+A/fowTOIWmuMtlbCda/2SsChAKCHRyYW5zZmVyEgQKAghkChAKCGV2aWRlbmNlEgQKAghkCi4KBG1pbnQSJgokCGQSIPvdoKLt1qhBYkRKjo39yCkQ0c1pOYM0kohjsVVGx9ae" | ||
} | ||
] | ||
}, | ||
"height": "100", | ||
"codespace": "" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"code": 0, | ||
"log": "", | ||
"info": "", | ||
"index": "0", | ||
"key": "Y29uc2Vuc3VzU3RhdGUvaWJjb25lY2xpZW50LzIy", | ||
"value": "wAE7xH38CgsIzLyC9AUQyLufJBImzXAxMQogavkPRiTGTZVjEAqT4pLlKPmyTcziso2UrYVU/KnU0EYYFiKCAQo/ChT26opfBMJw1ORvd6zC2b3pAKYCgRIlFiTeZCBdmybLcqCWKo8EBc9ZOM+rYKVUx4QmxhMYv93tBdcNDxhkEj8KFPbqil8EwnDU5G93rMLZvekApgKBEiUWJN5kIF2bJstyoJYqjwQFz1k4z6tgpVTHhCbGExi/3e0F1w0PGGQ=", | ||
"proof": null, | ||
"height": "60295", | ||
"codespace": "" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"code": 0, | ||
"log": "", | ||
"info": "", | ||
"index": "0", | ||
"key": "Y29uc2Vuc3VzU3RhdGUvaWJjb25lY2xpZW50LzIy", | ||
"value": "wAE7xH38CgsIzLyC9AUQyLufJBImzXAxMQogavkPRiTGTZVjEAqT4pLlKPmyTcziso2UrYVU/KnU0EYYFiKCAQo/ChT26opfBMJw1ORvd6zC2b3pAKYCgRIlFiTeZCBdmybLcqCWKo8EBc9ZOM+rYKVUx4QmxhMYv93tBdcNDxhkEj8KFPbqil8EwnDU5G93rMLZvekApgKBEiUWJN5kIF2bJstyoJYqjwQFz1k4z6tgpVTHhCbGExi/3e0F1w0PGGQ=", | ||
"proof": { | ||
"ops": [ | ||
{ | ||
"type": "iavl:v", | ||
"key": "Y29uc2Vuc3VzU3RhdGUvaWJjb25lY2xpZW50LzIy", | ||
"data": "8QEK7gEKKAgIEAwYHCIgG9RAkJgHlxNjmyzOW6bUAidhiRSja0x6+GXCVENPG1oKKAgGEAUYFyIgwRns+dJvjf1Zk2BaFrXz8inPbvYHB7xx2HCy9ima5f8KKAgEEAMYFyogOr8EGajEV6fG5fzJ2fAAvVMgRLhdMJTzCPlogl9rxlIKKAgCEAIYFyIgcjzX/a+2bFbnNldpawQqZ+kYhIwz5r4wCUzuu1IFW04aRAoeY29uc2Vuc3VzU3RhdGUvaWJjb25lY2xpZW50LzIyEiAZ1uuG60K4NHJZZMuS9QX6o4eEhica5jIHYwflRiYkDBgX" | ||
}, | ||
{ | ||
"type": "multistore", | ||
"key": "aWJj", | ||
"data": "CvEECjAKBGJhbmsSKAomCIjYAxIg2MEyyonbZButYnvSRkf2bPQg+nqA+Am1MeDxG6F4p1UKLwoDYWNjEigKJgiI2AMSIN2YHczeuXNvyetrSFQpkCcJzfB6PXVCw0i/XShMgPnIChEKB3VwZ3JhZGUSBgoECIjYAwovCgNnb3YSKAomCIjYAxIgYM0TfBli7KxhY4nWgDSDPykhUJwtKFql9RU5l86WinQKLwoDaWJjEigKJgiI2AMSIFp6aJASeInQKF8y824zjmgcFORN6M+ECbgFfJkobKs8CjAKBG1haW4SKAomCIjYAxIgsZzwmLQ7PH1UeZ/vCUSqlQmfgt3CGfoMgJLkUqKCv0EKMwoHc3Rha2luZxIoCiYIiNgDEiCiBZoBLyDGj5euy3n33ik+SpqYK9eB5xbI+iY8ycYVbwo0CghzbGFzaGluZxIoCiYIiNgDEiAJz3gEYuIhdensHU3b5qH5ons2quepd6EaRgCHXab6PQoyCgZzdXBwbHkSKAomCIjYAxIglWLA5/THPTiTxAlaLHOBYFIzEJTmKPznItUwAc8zD+AKEgoIZXZpZGVuY2USBgoECIjYAwowCgRtaW50EigKJgiI2AMSIMS8dZ1j8F6JVVv+hB1rHBZC+gIFJxHan2hM8qDC64n/CjIKBnBhcmFtcxIoCiYIiNgDEiB8VIzExUHX+SvHZFz/P9NM9THnw/gTDDLVReuZX8htLgo4CgxkaXN0cmlidXRpb24SKAomCIjYAxIg3u/Nd4L+8LT8OXJCh14o8PHIJ/GLQwsmE7KYIl1GdSYKEgoIdHJhbnNmZXISBgoECIjYAw==" | ||
} | ||
] | ||
}, | ||
"height": "60424", | ||
"codespace": "" | ||
} |
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.
I guess the other state verification functions are not included on purpose?
https://github.com/cosmos/cosmos-sdk/blob/b5a658729170e577b0e6e809e73d5e0756b90e07/x/ibc/02-client/exported/exported.go#L26-L92
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.
Yes, a bit more work to get there :)