Skip to content

Commit

Permalink
rpc: Add support for consensus_state endpoint (#719)
Browse files Browse the repository at this point in the history
* Add RPC support for consensus_state endpoint

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Add test support for consensus_state endpoint

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Add consensus state vote summary de/serialization

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Expose custom RFC3339-compatible timestamp serialization method

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Use custom RFC3339-compatible timestamp serialization

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Expand testing for consensus_state endpoint

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Rather operate on slices of deserialized string

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Fix timestamp serialization

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Remove endpoint "unstable" notice

Signed-off-by: Thane Thomson <connect@thanethomson.com>
  • Loading branch information
thanethomson authored Dec 16, 2020
1 parent 462eafc commit 11b4e87
Show file tree
Hide file tree
Showing 16 changed files with 598 additions and 8 deletions.
12 changes: 7 additions & 5 deletions proto/src/serializers/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,18 @@ where
}
match Utc.timestamp_opt(value.seconds, value.nanos as u32) {
LocalResult::None => Err(S::Error::custom("invalid time")),
LocalResult::Single(t) => Ok(to_rfc3339_custom(t)),
LocalResult::Single(t) => Ok(to_rfc3339_custom(&t)),
LocalResult::Ambiguous(_, _) => Err(S::Error::custom("ambiguous time")),
}?
.serialize(serializer)
}

// Due to incompatibilities between the way that `chrono` serializes timestamps
// and the way that Go does for RFC3339, we unfortunately need to define our
// own timestamp serialization mechanism.
fn to_rfc3339_custom(t: DateTime<Utc>) -> String {
/// Serialization helper for converting a `DateTime<Utc>` object to a string.
///
/// Due to incompatibilities between the way that `chrono` serializes timestamps
/// and the way that Go does for RFC3339, we unfortunately need to define our
/// own timestamp serialization mechanism.
pub fn to_rfc3339_custom(t: &DateTime<Utc>) -> String {
let nanos = format!(".{}", t.nanosecond());
format!(
"{:04}-{:02}-{:02}T{:02}:{:02}:{:02}{}Z",
Expand Down
4 changes: 4 additions & 0 deletions rpc-probe/src/kvstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ pub fn commit(height: u64) -> PlannedInteraction {
.into()
}

pub fn consensus_state() -> PlannedInteraction {
Request::new("consensus_state", json!({})).into()
}

pub fn genesis() -> PlannedInteraction {
Request::new("genesis", json!({})).into()
}
Expand Down
1 change: 1 addition & 0 deletions rpc-probe/src/quick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub fn quick_probe_plan(output_path: &Path, request_wait: Duration) -> Result<Pl
block_results(10).with_name("block_results_at_height_10"),
blockchain(1, 10).with_name("blockchain_from_1_to_10"),
commit(10).with_name("commit_at_height_10"),
consensus_state(),
broadcast_tx("async", "async-key", "value"),
broadcast_tx("sync", "sync-key", "value"),
broadcast_tx("commit", "commit-key", "value"),
Expand Down
5 changes: 5 additions & 0 deletions rpc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ pub trait Client {
self.perform(commit::Request::new(height.into())).await
}

/// `/consensus_state`: get current consensus state
async fn consensus_state(&self) -> Result<consensus_state::Response> {
self.perform(consensus_state::Request::new()).await
}

/// `/validators`: get validators a given height.
async fn validators<H>(&self, height: H) -> Result<validators::Response>
where
Expand Down
1 change: 1 addition & 0 deletions rpc/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod block_results;
pub mod blockchain;
pub mod broadcast;
pub mod commit;
pub mod consensus_state;
pub mod evidence;
pub mod genesis;
pub mod health;
Expand Down
Loading

0 comments on commit 11b4e87

Please sign in to comment.