From d807217be7df583427ec99227b2c6f9261b9a10f Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Wed, 12 Jun 2019 14:12:08 -0700 Subject: [PATCH] Simplify and camelCase getEpochVoteAccounts RPC API (#4658) * Simplify and camelCase getEpochVoteAccounts RPC API * Set a commission for testing --- book/src/jsonrpc-api.md | 22 +++++++------------ core/src/rpc.rs | 43 ++++++++++++++++++++++++++++---------- multinode-demo/fullnode.sh | 2 +- 3 files changed, 40 insertions(+), 27 deletions(-) diff --git a/book/src/jsonrpc-api.md b/book/src/jsonrpc-api.md index 4249fa2cef..1e855c96a9 100644 --- a/book/src/jsonrpc-api.md +++ b/book/src/jsonrpc-api.md @@ -125,7 +125,7 @@ None ##### Results: The result field will be an array of JSON objects, each with the following sub fields: -* `id` - Node identifier, as base-58 encoded string +* `pubkey` - Node public key, as base-58 encoded string * `gossip` - Gossip network address for the node * `tpu` - TPU network address for the node * `rpc` - JSON RPC network address for the node, or `null` if the JSON RPC service is not enabled @@ -136,7 +136,7 @@ The result field will be an array of JSON objects, each with the following sub f curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0", "id":1, "method":"getClusterNodes"}' http://localhost:8899 // Result -{"jsonrpc":"2.0","result":[{"gossip":"10.239.6.48:8001","id":"9QzsJf7LPLj8GkXbYT3LFDKqsj2hHG7TA3xinJHu8epQ","rpc":"10.239.6.48:8899","tpu":"10.239.6.48:8856"}],"id":1} +{"jsonrpc":"2.0","result":[{"gossip":"10.239.6.48:8001","pubkey":"9QzsJf7LPLj8GkXbYT3LFDKqsj2hHG7TA3xinJHu8epQ","rpc":"10.239.6.48:8899","tpu":"10.239.6.48:8856"}],"id":1} ``` --- @@ -282,19 +282,11 @@ Returns the account info and associated stake for all the voting accounts in the None ##### Results: -An array consisting of vote accounts: -* `string` - the vote account's Pubkey as base-58 encoded string -* `integer` - the stake, in lamports, delegated to this vote account -* `VoteState` - the vote account's state - -Each VoteState will be a JSON object with the following sub fields: - -* `votes`, array of most recent vote lockouts -* `node_pubkey`, the pubkey of the node that votes using this account -* `authorized_voter_pubkey`, the pubkey of the authorized vote signer for this account +The result field will be an array of JSON objects, each with the following sub fields: +* `votePubkey` - Vote account public key, as base-58 encoded string +* `nodePubkey` - Node public key, as base-58 encoded string +* `stake` - the stake, in lamports, delegated to this vote account * `commission`, a 32-bit integer used as a fraction (commission/MAX_U32) for rewards payout -* `root_slot`, the most recent slot this account has achieved maximum lockout -* `credits`, credits accrued by this account for reaching lockouts ##### Example: ```bash @@ -302,7 +294,7 @@ Each VoteState will be a JSON object with the following sub fields: curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1, "method":"getEpochVoteAccounts"}' http://localhost:8899 // Result -{"jsonrpc":"2.0","result":[[[84,115,89,23,41,83,221,72,58,23,53,245,195,188,140,161,242,189,200,164,139,214,12,180,84,161,28,151,24,243,159,125],10000000,{"authorized_voter_pubkey":[84,115,89,23,41,83,221,72,58,23,53,245,195,188,140,161,242,189,200,164,139,214,12,180,84,161,28,151,24,243,159,125],"commission":0,"credits":0,"node_pubkey":[49,139,227,211,47,39,69,86,131,244,160,144,228,169,84,143,142,253,83,81,212,110,254,12,242,71,219,135,30,60,157,213],"root_slot":null,"votes":[{"confirmation_count":1,"slot":0}]}]],"id":1} +{"jsonrpc":"2.0","result":[{"commission":0,"nodePubkey":"Et2RaZJdJRTzTkodUwiHr4H6sLkVmijBFv8tkd7oSSFY","stake":42,"votePubkey":"B4CdWq3NBSoH2wYsVE1CaZSWPo2ZtopE4SJipQhZ3srF"}],"id":1} ``` --- diff --git a/core/src/rpc.rs b/core/src/rpc.rs index abe28128b8..9b0592b8d2 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -100,13 +100,21 @@ impl JsonRpcRequestProcessor { Ok(self.bank().transaction_count() as u64) } - fn get_epoch_vote_accounts(&self) -> Result> { + fn get_epoch_vote_accounts(&self) -> Result> { let bank = self.bank(); Ok(bank .epoch_vote_accounts(bank.get_epoch_and_slot_index(bank.slot()).0) .ok_or_else(Error::invalid_request)? .iter() - .map(|(k, (s, a))| (*k, *s, VoteState::from(a).unwrap_or_default())) + .map(|(pubkey, (stake, account))| { + let vote_state = VoteState::from(account).unwrap_or_default(); + RpcVoteAccountInfo { + vote_pubkey: (*pubkey).to_string(), + node_pubkey: vote_state.node_pubkey.to_string(), + stake: *stake, + commission: vote_state.commission, + } + }) .collect::>()) } @@ -158,8 +166,8 @@ impl Metadata for Meta {} #[derive(Serialize, Deserialize, Clone, Debug)] pub struct RpcContactInfo { - /// Base58 id - pub id: String, + /// Pubkey of the node as a base-58 string + pub pubkey: String, /// Gossip port pub gossip: Option, /// Tpu port @@ -168,6 +176,22 @@ pub struct RpcContactInfo { pub rpc: Option, } +#[derive(Serialize, Deserialize, Clone, Debug)] +#[serde(rename_all = "camelCase")] +pub struct RpcVoteAccountInfo { + /// Vote account pubkey as base-58 encoded string + pub vote_pubkey: String, + + /// The pubkey of the node that votes using this account + pub node_pubkey: String, + + /// The current stake, in lamports, delegated to this vote account + pub stake: u64, + + /// A 32-bit integer used as a fraction (commission/MAX_U32) for rewards payout + pub commission: u32, +} + #[rpc(server)] pub trait RpcSol { type Metadata; @@ -207,7 +231,7 @@ pub trait RpcSol { fn get_slot_leader(&self, _: Self::Metadata) -> Result; #[rpc(meta, name = "getEpochVoteAccounts")] - fn get_epoch_vote_accounts(&self, _: Self::Metadata) -> Result>; + fn get_epoch_vote_accounts(&self, _: Self::Metadata) -> Result>; #[rpc(meta, name = "getStorageBlockhash")] fn get_storage_blockhash(&self, _: Self::Metadata) -> Result; @@ -280,7 +304,7 @@ impl RpcSol for RpcSolImpl { .filter_map(|(contact_info, _)| { if ContactInfo::is_valid_address(&contact_info.gossip) { Some(RpcContactInfo { - id: contact_info.id.to_string(), + pubkey: contact_info.id.to_string(), gossip: Some(contact_info.gossip), tpu: valid_address_or_none(&contact_info.tpu), rpc: valid_address_or_none(&contact_info.rpc), @@ -441,10 +465,7 @@ impl RpcSol for RpcSolImpl { .to_string()) } - fn get_epoch_vote_accounts( - &self, - meta: Self::Metadata, - ) -> Result> { + fn get_epoch_vote_accounts(&self, meta: Self::Metadata) -> Result> { meta.request_processor .read() .unwrap() @@ -575,7 +596,7 @@ mod tests { .expect("actual response deserialization"); let expected = format!( - r#"{{"jsonrpc":"2.0","result":[{{"id": "{}", "gossip": "127.0.0.1:1235", "tpu": "127.0.0.1:1234", "rpc": "127.0.0.1:8899"}}],"id":1}}"#, + r#"{{"jsonrpc":"2.0","result":[{{"pubkey": "{}", "gossip": "127.0.0.1:1235", "tpu": "127.0.0.1:1234", "rpc": "127.0.0.1:8899"}}],"id":1}}"#, leader_pubkey, ); diff --git a/multinode-demo/fullnode.sh b/multinode-demo/fullnode.sh index 664cc95841..2d4d7bc318 100755 --- a/multinode-demo/fullnode.sh +++ b/multinode-demo/fullnode.sh @@ -109,7 +109,7 @@ setup_validator_accounts() { # Fund the vote account from the node, with the node as the node_pubkey $solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" \ - create-vote-account "$vote_pubkey" "$node_pubkey" 1 || return $? + create-vote-account "$vote_pubkey" "$node_pubkey" 1 --commission 65535 || return $? # Fund the stake account from the node, with the node as the node_pubkey $solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" \