Simplify and camelCase getEpochVoteAccounts RPC API (#4658)
* Simplify and camelCase getEpochVoteAccounts RPC API * Set a commission for testing
This commit is contained in:
@ -125,7 +125,7 @@ None
|
|||||||
|
|
||||||
##### Results:
|
##### Results:
|
||||||
The result field will be an array of JSON objects, each with the following sub fields:
|
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
|
* `gossip` - Gossip network address for the node
|
||||||
* `tpu` - TPU 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
|
* `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
|
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0", "id":1, "method":"getClusterNodes"}' http://localhost:8899
|
||||||
|
|
||||||
// Result
|
// 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
|
None
|
||||||
|
|
||||||
##### Results:
|
##### Results:
|
||||||
An array consisting of vote accounts:
|
The result field will be an array of JSON objects, each with the following sub fields:
|
||||||
* `string` - the vote account's Pubkey as base-58 encoded string
|
* `votePubkey` - Vote account public key, as base-58 encoded string
|
||||||
* `integer` - the stake, in lamports, delegated to this vote account
|
* `nodePubkey` - Node public key, as base-58 encoded string
|
||||||
* `VoteState` - the vote account's state
|
* `stake` - the stake, in lamports, delegated to this vote account
|
||||||
|
|
||||||
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
|
|
||||||
* `commission`, a 32-bit integer used as a fraction (commission/MAX_U32) for rewards payout
|
* `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:
|
##### Example:
|
||||||
```bash
|
```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
|
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1, "method":"getEpochVoteAccounts"}' http://localhost:8899
|
||||||
|
|
||||||
// Result
|
// 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}
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@ -100,13 +100,21 @@ impl JsonRpcRequestProcessor {
|
|||||||
Ok(self.bank().transaction_count() as u64)
|
Ok(self.bank().transaction_count() as u64)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_epoch_vote_accounts(&self) -> Result<Vec<(Pubkey, u64, VoteState)>> {
|
fn get_epoch_vote_accounts(&self) -> Result<Vec<RpcVoteAccountInfo>> {
|
||||||
let bank = self.bank();
|
let bank = self.bank();
|
||||||
Ok(bank
|
Ok(bank
|
||||||
.epoch_vote_accounts(bank.get_epoch_and_slot_index(bank.slot()).0)
|
.epoch_vote_accounts(bank.get_epoch_and_slot_index(bank.slot()).0)
|
||||||
.ok_or_else(Error::invalid_request)?
|
.ok_or_else(Error::invalid_request)?
|
||||||
.iter()
|
.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::<Vec<_>>())
|
.collect::<Vec<_>>())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,8 +166,8 @@ impl Metadata for Meta {}
|
|||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
pub struct RpcContactInfo {
|
pub struct RpcContactInfo {
|
||||||
/// Base58 id
|
/// Pubkey of the node as a base-58 string
|
||||||
pub id: String,
|
pub pubkey: String,
|
||||||
/// Gossip port
|
/// Gossip port
|
||||||
pub gossip: Option<SocketAddr>,
|
pub gossip: Option<SocketAddr>,
|
||||||
/// Tpu port
|
/// Tpu port
|
||||||
@ -168,6 +176,22 @@ pub struct RpcContactInfo {
|
|||||||
pub rpc: Option<SocketAddr>,
|
pub rpc: Option<SocketAddr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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)]
|
#[rpc(server)]
|
||||||
pub trait RpcSol {
|
pub trait RpcSol {
|
||||||
type Metadata;
|
type Metadata;
|
||||||
@ -207,7 +231,7 @@ pub trait RpcSol {
|
|||||||
fn get_slot_leader(&self, _: Self::Metadata) -> Result<String>;
|
fn get_slot_leader(&self, _: Self::Metadata) -> Result<String>;
|
||||||
|
|
||||||
#[rpc(meta, name = "getEpochVoteAccounts")]
|
#[rpc(meta, name = "getEpochVoteAccounts")]
|
||||||
fn get_epoch_vote_accounts(&self, _: Self::Metadata) -> Result<Vec<(Pubkey, u64, VoteState)>>;
|
fn get_epoch_vote_accounts(&self, _: Self::Metadata) -> Result<Vec<RpcVoteAccountInfo>>;
|
||||||
|
|
||||||
#[rpc(meta, name = "getStorageBlockhash")]
|
#[rpc(meta, name = "getStorageBlockhash")]
|
||||||
fn get_storage_blockhash(&self, _: Self::Metadata) -> Result<String>;
|
fn get_storage_blockhash(&self, _: Self::Metadata) -> Result<String>;
|
||||||
@ -280,7 +304,7 @@ impl RpcSol for RpcSolImpl {
|
|||||||
.filter_map(|(contact_info, _)| {
|
.filter_map(|(contact_info, _)| {
|
||||||
if ContactInfo::is_valid_address(&contact_info.gossip) {
|
if ContactInfo::is_valid_address(&contact_info.gossip) {
|
||||||
Some(RpcContactInfo {
|
Some(RpcContactInfo {
|
||||||
id: contact_info.id.to_string(),
|
pubkey: contact_info.id.to_string(),
|
||||||
gossip: Some(contact_info.gossip),
|
gossip: Some(contact_info.gossip),
|
||||||
tpu: valid_address_or_none(&contact_info.tpu),
|
tpu: valid_address_or_none(&contact_info.tpu),
|
||||||
rpc: valid_address_or_none(&contact_info.rpc),
|
rpc: valid_address_or_none(&contact_info.rpc),
|
||||||
@ -441,10 +465,7 @@ impl RpcSol for RpcSolImpl {
|
|||||||
.to_string())
|
.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_epoch_vote_accounts(
|
fn get_epoch_vote_accounts(&self, meta: Self::Metadata) -> Result<Vec<RpcVoteAccountInfo>> {
|
||||||
&self,
|
|
||||||
meta: Self::Metadata,
|
|
||||||
) -> Result<Vec<(Pubkey, u64, VoteState)>> {
|
|
||||||
meta.request_processor
|
meta.request_processor
|
||||||
.read()
|
.read()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -575,7 +596,7 @@ mod tests {
|
|||||||
.expect("actual response deserialization");
|
.expect("actual response deserialization");
|
||||||
|
|
||||||
let expected = format!(
|
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,
|
leader_pubkey,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ setup_validator_accounts() {
|
|||||||
|
|
||||||
# Fund the vote account from the node, with the node as the node_pubkey
|
# 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" \
|
$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
|
# 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" \
|
$solana_wallet --keypair "$node_keypair_path" --url "http://$entrypoint_ip:8899" \
|
||||||
|
Reference in New Issue
Block a user