Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5f6bb70
grandpa: wire up basic RPC call
octol Apr 1, 2020
4ef39fa
grandpa: make it compile against GRANDPA with expose round state
andresilva Apr 1, 2020
eea294d
grandpa: use shared voter state to expose RPC endpoint
octol Apr 7, 2020
a8109a2
grandpa: restructure into nested structs
octol Apr 7, 2020
04fca7e
grandpa: return background rounds too
octol Apr 8, 2020
627c7a8
grandpa: return error when endpoint not ready
octol Apr 8, 2020
123e249
grandpa: collect grandpa rpc deps
octol Apr 8, 2020
10b3266
grandpa: decide to use concrete AuthorityId in finality-grandpa-rpc
octol Apr 17, 2020
eb5d87d
grandpa: remove unncessary type annotation
octol Apr 23, 2020
6edfa13
grandpa: move error code to const
octol Apr 23, 2020
bcb206d
grandpa: remove unnecessary WIP comment
octol Apr 23, 2020
4ca212d
grandpa: remove Id type parameter for SharedVoterState
octol Apr 23, 2020
b2af4f7
grandpa: update tests to add shared_voter_state in parameters
octol Apr 23, 2020
b04616f
grandpa: remove old deprecated test
octol Apr 23, 2020
c9bcbf8
grandpa: fix getting the correct set_id
octol Apr 24, 2020
fedfdcc
grandpa: make SharedVoterState a struct
octol Apr 24, 2020
4e75855
grandpa: wrap shared_voter_state in rpc_setup
octol Apr 24, 2020
f4140b6
grandpa: replace spaces with tabs
octol Apr 24, 2020
7586652
grandpa: limit RwLock write attempt to 1 sec
octol Apr 24, 2020
3d6f1c2
grandpa: add missing doc comments and remove some pub
octol Apr 27, 2020
4872fcb
Apply suggestions from code review
Demi-Marie Apr 28, 2020
75efc8e
grandpa: update function name call after change in finality-grandpa
octol Apr 29, 2020
26b0959
grandpa: group pub use and only export voter::report
octol Apr 29, 2020
9c55fa5
grandpa: add missing docs
octol Apr 29, 2020
d636c28
grandpa: extract out structs used for json serialization
octol Apr 29, 2020
e63c3be
grandpa: stick to u32 for fields intended for js
octol Apr 29, 2020
c02211c
grandpa: move Error type to its own file
octol Apr 29, 2020
fef11d3
grandpa: group pub use better
octol Apr 30, 2020
f1c2103
Apply code review suggestion
octol Apr 30, 2020
bc68092
Merge 'upstream/master' into jon/issue-4921-expose-grandpa-round-stat…
octol Apr 30, 2020
b809ee1
grandpa: use correct version of finality-granpda in rpc crate
octol Apr 30, 2020
988bbee
grandpa: add back basic rpc unit test
octol Apr 29, 2020
f9d9b1c
grandpa: replace SharedVoterState::new() with empty()
andresilva Apr 30, 2020
9eb5fa3
node: cleanup grandpa::SharedVoterState usage in macro
andresilva Apr 30, 2020
12004bc
grandpa: remove VoterState error variant
andresilva Apr 30, 2020
1ef01df
grandpa: enable missing futures compat feature
andresilva Apr 30, 2020
a97bb87
grandpa: fix typo in error variant
andresilva May 1, 2020
7aed9bb
grandpa: remove test_utils
andresilva May 1, 2020
65f8674
grandpa: allow mocking rpc handler components
andresilva May 1, 2020
a3e477d
grandpa: rename serialized to report in rpc module
andresilva May 1, 2020
23536a0
grandpa: add proper test for RPC
andresilva May 1, 2020
aabacb8
grandpa: update to finality-grandpa v0.12.1
andresilva May 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
grandpa: stick to u32 for fields intended for js
  • Loading branch information
octol committed Apr 29, 2020
commit e63c3be764632e0630fced272f27554f94e04aa9
12 changes: 12 additions & 0 deletions client/finality-grandpa/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ pub enum Error {
/// The GRANDPA RPC endpoint is not ready.
#[display(fmt = "GRANDPA RPC endpoint not ready")]
EndpointNotReady,
/// GRANDPA reports the authority set id to be larger than 32-bits.
#[display(fmt = "GRANDPA reports authority set id unreasonably large")]
AuthoritySetIdReportedasUnreasonablyLarge,
/// GRANDPA reports voter state with round id or weights larger than 32-bits.
#[display(fmt = "GRANDPA reports voter state as unreasonably large")]
VoterStateReportsUnreasonablyLargeNumbers,
}

impl From<Error> for jsonrpc_core::Error {
Expand All @@ -51,6 +57,12 @@ impl From<Error> for jsonrpc_core::Error {
}
}

impl From<std::num::TryFromIntError> for Error {
fn from(_error: std::num::TryFromIntError) -> Self {
Error::VoterStateReportsUnreasonablyLargeNumbers
}
}

/// Provides RPC methods for interacting with GRANDPA.
#[rpc]
pub trait GrandpaApi {
Expand Down
41 changes: 24 additions & 17 deletions client/finality-grandpa/rpc/src/serialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ use crate::Error;
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct Prevotes {
current_weight: u64,
current_weight: u32,
missing: HashSet<AuthorityId>,
}

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct Precommits {
current_weight: u64,
current_weight: u32,
missing: HashSet<AuthorityId>,
}

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct RoundState {
round: u64,
total_weight: u64,
threshold_weight: u64,
round: u32,
total_weight: u32,
threshold_weight: u32,
prevotes: Prevotes,
precommits: Precommits,
}
Expand All @@ -50,26 +50,28 @@ impl RoundState {
round: u64,
round_state: &report::RoundState<AuthorityId>,
voters: &HashSet<AuthorityId>,
) -> Self {
) -> Result<Self, Error> {
use std::convert::TryInto;

let prevotes = &round_state.prevote_ids;
let missing_prevotes = voters.difference(&prevotes).cloned().collect();

let precommits = &round_state.precommit_ids;
let missing_precommits = voters.difference(&precommits).cloned().collect();

Self {
round,
total_weight: round_state.total_weight,
threshold_weight: round_state.threshold_weight,
Ok(Self {
round: round.try_into()?,
total_weight: round_state.total_weight.try_into()?,
threshold_weight: round_state.threshold_weight.try_into()?,
prevotes: Prevotes {
current_weight: round_state.prevote_current_weight,
current_weight: round_state.prevote_current_weight.try_into()?,
missing: missing_prevotes,
},
precommits: Precommits {
current_weight: round_state.precommit_current_weight,
current_weight: round_state.precommit_current_weight.try_into()?,
missing: missing_precommits,
},
}
})
}
}

Expand All @@ -78,7 +80,7 @@ impl RoundState {
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ReportedRoundStates {
set_id: u64,
set_id: u32,
best: RoundState,
background: Vec<RoundState>,
}
Expand All @@ -92,6 +94,8 @@ impl ReportedRoundStates {
Hash: Debug + Clone + Eq + Send + Sync + 'static,
Block: BlockNumberOps + Send + Sync + 'static,
{
use std::convert::TryFrom;

let voter_state = voter_state
.voter_state()
.ok_or(Error::EndpointNotReady)?;
Expand All @@ -103,19 +107,22 @@ impl ReportedRoundStates {
.map(|p| p.0.clone())
.collect();

let set_id = u32::try_from(authority_set.set_id())
.map_err(|_| Error::AuthoritySetIdReportedasUnreasonablyLarge)?;

let best = {
let (round, round_state) = voter_state.best_round;
RoundState::from(round, &round_state, &current_voters)
RoundState::from(round, &round_state, &current_voters)?
};

let background = voter_state
.background_rounds
.iter()
.map(|(round, round_state)| RoundState::from(*round, round_state, &current_voters))
.collect();
.collect::<Result<Vec<_>, Error>>()?;

Ok(Self {
set_id: authority_set.set_id(),
set_id,
best,
background,
})
Expand Down