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

rpc: Add support for consensus_state endpoint #719

Merged
merged 9 commits into from
Dec 16, 2020
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 (UNSTABLE)
thanethomson marked this conversation as resolved.
Show resolved Hide resolved
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