Fix Rpc inconsistencies (#7826)

* Update rpc account format: remove byte arrays

* Base58-encode pubkeys in getStoragePubkeysForSlot

* Update docs
This commit is contained in:
Tyera Eulberg
2020-01-15 15:33:53 -07:00
committed by GitHub
parent 8ffccfbaff
commit da165d6943
8 changed files with 128 additions and 75 deletions

View File

@ -12,10 +12,10 @@ use bincode::serialize;
use jsonrpc_core::{Error, Metadata, Result};
use jsonrpc_derive::rpc;
use solana_client::rpc_response::{
Response, RpcBlockCommitment, RpcBlockhashFeeCalculator, RpcConfirmedBlock, RpcContactInfo,
RpcEpochInfo, RpcKeyedAccount, RpcLeaderSchedule, RpcResponseContext, RpcSignatureConfirmation,
RpcStorageTurn, RpcTransactionEncoding, RpcVersionInfo, RpcVoteAccountInfo,
RpcVoteAccountStatus,
Response, RpcAccount, RpcBlockCommitment, RpcBlockhashFeeCalculator, RpcConfirmedBlock,
RpcContactInfo, RpcEpochInfo, RpcKeyedAccount, RpcLeaderSchedule, RpcResponseContext,
RpcSignatureConfirmation, RpcStorageTurn, RpcTransactionEncoding, RpcVersionInfo,
RpcVoteAccountInfo, RpcVoteAccountStatus,
};
use solana_faucet::faucet::request_airdrop_transaction;
use solana_ledger::{
@ -23,7 +23,6 @@ use solana_ledger::{
};
use solana_runtime::bank::Bank;
use solana_sdk::{
account::Account,
clock::{Slot, UnixTimestamp},
commitment_config::{CommitmentConfig, CommitmentLevel},
epoch_schedule::EpochSchedule,
@ -112,10 +111,10 @@ impl JsonRpcRequestProcessor {
&self,
pubkey: Result<Pubkey>,
commitment: Option<CommitmentConfig>,
) -> RpcResponse<Option<Account>> {
) -> RpcResponse<Option<RpcAccount>> {
let bank = &*self.bank(commitment);
match pubkey {
Ok(key) => new_response(bank, bank.get_account(&key)),
Ok(key) => new_response(bank, bank.get_account(&key).map(RpcAccount::encode)),
Err(e) => Err(e),
}
}
@ -141,7 +140,7 @@ impl JsonRpcRequestProcessor {
.into_iter()
.map(|(pubkey, account)| RpcKeyedAccount {
pubkey: pubkey.to_string(),
account,
account: RpcAccount::encode(account),
})
.collect())
}
@ -307,10 +306,14 @@ impl JsonRpcRequestProcessor {
Ok(self.bank(commitment).slots_per_segment())
}
fn get_storage_pubkeys_for_slot(&self, slot: Slot) -> Result<Vec<Pubkey>> {
Ok(self
fn get_storage_pubkeys_for_slot(&self, slot: Slot) -> Result<Vec<String>> {
let pubkeys: Vec<String> = self
.storage_state
.get_pubkeys_for_slot(slot, &self.bank_forks))
.get_pubkeys_for_slot(slot, &self.bank_forks)
.iter()
.map(|pubkey| pubkey.to_string())
.collect();
Ok(pubkeys)
}
pub fn validator_exit(&self) -> Result<bool> {
@ -412,7 +415,7 @@ pub trait RpcSol {
meta: Self::Metadata,
pubkey_str: String,
commitment: Option<CommitmentConfig>,
) -> RpcResponse<Option<Account>>;
) -> RpcResponse<Option<RpcAccount>>;
#[rpc(meta, name = "getProgramAccounts")]
fn get_program_accounts(
@ -548,7 +551,7 @@ pub trait RpcSol {
) -> Result<u64>;
#[rpc(meta, name = "getStoragePubkeysForSlot")]
fn get_storage_pubkeys_for_slot(&self, meta: Self::Metadata, slot: u64) -> Result<Vec<Pubkey>>;
fn get_storage_pubkeys_for_slot(&self, meta: Self::Metadata, slot: u64) -> Result<Vec<String>>;
#[rpc(meta, name = "validatorExit")]
fn validator_exit(&self, meta: Self::Metadata) -> Result<bool>;
@ -618,7 +621,7 @@ impl RpcSol for RpcSolImpl {
meta: Self::Metadata,
pubkey_str: String,
commitment: Option<CommitmentConfig>,
) -> RpcResponse<Option<Account>> {
) -> RpcResponse<Option<RpcAccount>> {
debug!("get_account_info rpc request received: {:?}", pubkey_str);
let pubkey = verify_pubkey(pubkey_str);
meta.request_processor
@ -1024,7 +1027,7 @@ impl RpcSol for RpcSolImpl {
&self,
meta: Self::Metadata,
slot: Slot,
) -> Result<Vec<Pubkey>> {
) -> Result<Vec<String>> {
meta.request_processor
.read()
.unwrap()
@ -1547,9 +1550,9 @@ pub mod tests {
"result": {
"context":{"slot":0},
"value":{
"owner": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
"owner": "11111111111111111111111111111111",
"lamports": 20,
"data": [],
"data": "",
"executable": false,
"rentEpoch": 0
},
@ -1589,9 +1592,9 @@ pub mod tests {
{{
"pubkey": "{}",
"account": {{
"owner": {:?},
"owner": "{}",
"lamports": 20,
"data": [],
"data": "",
"executable": false,
"rentEpoch": 0
}}
@ -1600,7 +1603,7 @@ pub mod tests {
"id":1}}
"#,
bob.pubkey(),
new_program_id.as_ref()
new_program_id
);
let expected: Response =
serde_json::from_str(&expected).expect("expected response deserialization");

View File

@ -4,8 +4,8 @@ use crate::rpc_subscriptions::{Confirmations, RpcSubscriptions, SlotInfo};
use jsonrpc_core::{Error, ErrorCode, Result};
use jsonrpc_derive::rpc;
use jsonrpc_pubsub::{typed::Subscriber, Session, SubscriptionId};
use solana_client::rpc_response::RpcKeyedAccount;
use solana_sdk::{account::Account, pubkey::Pubkey, signature::Signature, transaction};
use solana_client::rpc_response::{RpcAccount, RpcKeyedAccount};
use solana_sdk::{pubkey::Pubkey, signature::Signature, transaction};
use std::sync::{atomic, Arc};
// Suppress needless_return due to
@ -26,7 +26,7 @@ pub trait RpcSolPubSub {
fn account_subscribe(
&self,
meta: Self::Metadata,
subscriber: Subscriber<Account>,
subscriber: Subscriber<RpcAccount>,
pubkey_str: String,
confirmations: Option<Confirmations>,
);
@ -133,7 +133,7 @@ impl RpcSolPubSub for RpcSolPubSubImpl {
fn account_subscribe(
&self,
_meta: Self::Metadata,
subscriber: Subscriber<Account>,
subscriber: Subscriber<RpcAccount>,
pubkey_str: String,
confirmations: Option<Confirmations>,
) {
@ -467,9 +467,9 @@ mod tests {
"method": "accountNotification",
"params": {
"result": {
"owner": budget_program_id,
"owner": budget_program_id.to_string(),
"lamports": 51,
"data": expected_data,
"data": bs58::encode(expected_data).into_string(),
"executable": false,
"rentEpoch": 1,
},
@ -614,9 +614,9 @@ mod tests {
"method": "accountNotification",
"params": {
"result": {
"owner": system_program::id(),
"owner": system_program::id().to_string(),
"lamports": 100,
"data": [],
"data": "",
"executable": false,
"rentEpoch": 1,
},

View File

@ -4,7 +4,7 @@ use core::hash::Hash;
use jsonrpc_core::futures::Future;
use jsonrpc_pubsub::{typed::Sink, SubscriptionId};
use serde::Serialize;
use solana_client::rpc_response::RpcKeyedAccount;
use solana_client::rpc_response::{RpcAccount, RpcKeyedAccount};
use solana_ledger::bank_forks::BankForks;
use solana_runtime::bank::Bank;
use solana_sdk::{
@ -26,7 +26,7 @@ pub struct SlotInfo {
}
type RpcAccountSubscriptions =
RwLock<HashMap<Pubkey, HashMap<SubscriptionId, (Sink<Account>, Confirmations)>>>;
RwLock<HashMap<Pubkey, HashMap<SubscriptionId, (Sink<RpcAccount>, Confirmations)>>>;
type RpcProgramSubscriptions =
RwLock<HashMap<Pubkey, HashMap<SubscriptionId, (Sink<RpcKeyedAccount>, Confirmations)>>>;
type RpcSignatureSubscriptions = RwLock<
@ -130,13 +130,10 @@ fn check_confirmations_and_notify<K, S, F, N, X>(
}
}
fn notify_account<S>(result: Option<(S, Slot)>, sink: &Sink<S>, root: Slot)
where
S: Clone + Serialize,
{
fn notify_account(result: Option<(Account, Slot)>, sink: &Sink<RpcAccount>, root: Slot) {
if let Some((account, fork)) = result {
if fork >= root {
sink.notify(Ok(account)).wait().unwrap();
sink.notify(Ok(RpcAccount::encode(account))).wait().unwrap();
}
}
}
@ -154,7 +151,7 @@ fn notify_program(accounts: Vec<(Pubkey, Account)>, sink: &Sink<RpcKeyedAccount>
for (pubkey, account) in accounts.iter() {
sink.notify(Ok(RpcKeyedAccount {
pubkey: pubkey.to_string(),
account: account.clone(),
account: RpcAccount::encode(account.clone()),
}))
.wait()
.unwrap();
@ -237,7 +234,7 @@ impl RpcSubscriptions {
pubkey: &Pubkey,
confirmations: Option<Confirmations>,
sub_id: &SubscriptionId,
sink: &Sink<Account>,
sink: &Sink<RpcAccount>,
) {
let mut subscriptions = self.account_subscriptions.write().unwrap();
add_subscription(&mut subscriptions, pubkey, confirmations, sub_id, sink);
@ -384,7 +381,7 @@ mod tests {
let string = transport_receiver.poll();
if let Async::Ready(Some(response)) = string.unwrap() {
let expected = format!(
r#"{{"jsonrpc":"2.0","method":"accountNotification","params":{{"result":{{"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"executable":false,"lamports":1,"owner":[2,203,81,223,225,24,34,35,203,214,138,130,144,208,35,77,63,16,87,51,47,198,115,123,98,188,19,160,0,0,0,0],"rentEpoch":1}},"subscription":0}}}}"#
r#"{{"jsonrpc":"2.0","method":"accountNotification","params":{{"result":{{"data":"1111111111111111","executable":false,"lamports":1,"owner":"Budget1111111111111111111111111111111111111","rentEpoch":1}},"subscription":0}}}}"#
);
assert_eq!(expected, response);
}
@ -441,7 +438,7 @@ mod tests {
let string = transport_receiver.poll();
if let Async::Ready(Some(response)) = string.unwrap() {
let expected = format!(
r#"{{"jsonrpc":"2.0","method":"programNotification","params":{{"result":{{"account":{{"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"executable":false,"lamports":1,"owner":[2,203,81,223,225,24,34,35,203,214,138,130,144,208,35,77,63,16,87,51,47,198,115,123,98,188,19,160,0,0,0,0],"rentEpoch":1}},"pubkey":"{:?}"}},"subscription":0}}}}"#,
r#"{{"jsonrpc":"2.0","method":"programNotification","params":{{"result":{{"account":{{"data":"1111111111111111","executable":false,"lamports":1,"owner":"Budget1111111111111111111111111111111111111","rentEpoch":1}},"pubkey":"{:?}"}},"subscription":0}}}}"#,
alice.pubkey()
);
assert_eq!(expected, response);