Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
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: restructure into nested structs
  • Loading branch information
octol committed Apr 27, 2020
commit a8109a204d195f87c686c8870968832b130143ab
92 changes: 65 additions & 27 deletions client/finality-grandpa/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type FutureResult<T> = Box<dyn jsonrpc_core::futures::Future<Item = T, Error = E
#[rpc]
pub trait GrandpaApi {
#[rpc(name = "grandpa_roundState")]
fn grandpa_round_state(&self) -> FutureResult<RoundState>;
fn round_state(&self) -> FutureResult<ReportedRoundStates>;
}

pub struct GrandpaRpcHandler<Hash, Block> {
Expand All @@ -51,20 +51,66 @@ impl<Hash, Block> GrandpaRpcHandler<Hash, Block> {
}

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Prevotes {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are Prevotes, Precommits, RoundState and all their fields public?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good point. I went through and removed pub in a number of places!

pub current_weight: u64,
pub missing: HashSet<AuthorityId>,
}

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

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RoundState {
pub set_id: u64,
pub round: u64,
pub total_weight: u64,
pub threshold_weight: u64,
pub prevotes: Prevotes,
pub precommits: Precommits,
}

impl RoundState {
pub fn from(
round: u64,
round_state: voter::report::RoundState<AuthorityId>,
voters: HashSet<AuthorityId>
) -> Self {
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();

pub prevote_current_weight: u64,
pub prevote_missing: HashSet<AuthorityId>,
Self {
round,
total_weight: round_state.total_weight,
threshold_weight: round_state.threshold_weight,
prevotes: Prevotes {
current_weight: round_state.prevote_current_weight,
missing: missing_prevotes,
},
precommits: Precommits {
current_weight: round_state.precommit_current_weight,
missing: missing_precommits,
}
}
}
}

pub precommit_current_weight: u64,
pub precommit_missing: HashSet<AuthorityId>,
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ReportedRoundStates {
pub set_id: u64,
pub best: RoundState,
// pub background,
}

impl RoundState {
impl ReportedRoundStates {
pub fn from<Hash, Block>(
voter_state: &SharedVoterState<AuthorityId>,
authority_set: &SharedAuthoritySet<Hash, Block>
Expand All @@ -80,35 +126,27 @@ impl RoundState {
let current_authorities = authority_set.current_authorities();
let voters: HashSet<AuthorityId> = current_authorities.voters().iter().map(|p| p.0.clone()).collect();

let prevotes = voter_state.best_round.1.prevote_ids;
let missing_prevotes = voters.difference(&prevotes).cloned().collect();

let precommits = voter_state.best_round.1.precommit_ids;
let missing_precommits = voters.difference(&precommits).cloned().collect();
let set_id = voter_state.best_round.0;
let best = {
let (round, round_state) = voter_state.best_round;
RoundState::from(round, round_state, voters)
};

Self {
set_id: authority_set.set_id(),
round: voter_state.best_round.0,
total_weight: voter_state.best_round.1.total_weight,
threshold_weight: voter_state.best_round.1.threshold_weight,

prevote_current_weight: voter_state.best_round.1.prevote_current_weight,
prevote_missing: missing_prevotes,

precommit_current_weight: voter_state.best_round.1.precommit_current_weight,
precommit_missing: missing_precommits,
}
Self { set_id, best }
}
}

impl<Hash, Block: Send + Sync> GrandpaApi for GrandpaRpcHandler<Hash, Block> where
Hash: Debug + Clone + Eq + Send + Sync + 'static,
Block: BlockNumberOps + Send + Sync + 'static,
{
fn grandpa_round_state(&self) -> FutureResult<RoundState> {
let round_state = RoundState::from(&self.shared_voter_state, &self.shared_authority_set);
fn round_state(&self) -> FutureResult<ReportedRoundStates> {
let round_states = ReportedRoundStates::from(
&self.shared_voter_state,
&self.shared_authority_set
);
let future = async move {
Ok(round_state)
Ok(round_states)
}.boxed();
Box::new(future.compat())
}
Expand Down