Move obsolete rpc endpoints to separate api for removal (#16500)

* Move obsolete rpc methods to separate api for removal

* Remove obsolete method from docs

* Fix test using obs method
This commit is contained in:
Tyera Eulberg 2021-04-12 20:33:40 -06:00 committed by GitHub
parent 05ad979a2d
commit 70f3f7e679
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 160 additions and 309 deletions

View File

@ -124,6 +124,7 @@ pub struct JsonRpcConfig {
pub rpc_threads: usize,
pub rpc_bigtable_timeout: Option<Duration>,
pub minimal_api: bool,
pub obsolete_v1_7_api: bool,
}
#[derive(Clone)]
@ -2220,33 +2221,6 @@ pub mod rpc_full {
pub trait Full {
type Metadata;
// DEPRECATED
#[rpc(meta, name = "confirmTransaction")]
fn confirm_transaction(
&self,
meta: Self::Metadata,
signature_str: String,
commitment: Option<CommitmentConfig>,
) -> Result<RpcResponse<bool>>;
// DEPRECATED
#[rpc(meta, name = "getSignatureStatus")]
fn get_signature_status(
&self,
meta: Self::Metadata,
signature_str: String,
commitment: Option<CommitmentConfig>,
) -> Result<Option<transaction::Result<()>>>;
// DEPRECATED (used by Trust Wallet)
#[rpc(meta, name = "getSignatureConfirmation")]
fn get_signature_confirmation(
&self,
meta: Self::Metadata,
signature_str: String,
commitment: Option<CommitmentConfig>,
) -> Result<Option<RpcSignatureConfirmation>>;
#[rpc(meta, name = "getAccountInfo")]
fn get_account_info(
&self,
@ -2362,14 +2336,6 @@ pub mod rpc_full {
#[rpc(meta, name = "getMaxShredInsertSlot")]
fn get_max_shred_insert_slot(&self, meta: Self::Metadata) -> Result<Slot>;
// DEPRECATED
#[rpc(meta, name = "getTotalSupply")]
fn get_total_supply(
&self,
meta: Self::Metadata,
commitment: Option<CommitmentConfig>,
) -> Result<u64>;
#[rpc(meta, name = "getLargestAccounts")]
fn get_largest_accounts(
&self,
@ -2465,16 +2431,6 @@ pub mod rpc_full {
config: Option<RpcEncodingConfigWrapper<RpcConfirmedTransactionConfig>>,
) -> Result<Option<EncodedConfirmedTransaction>>;
// DEPRECATED
#[rpc(meta, name = "getConfirmedSignaturesForAddress")]
fn get_confirmed_signatures_for_address(
&self,
meta: Self::Metadata,
pubkey_str: String,
start_slot: Slot,
end_slot: Slot,
) -> Result<Vec<String>>;
#[rpc(meta, name = "getConfirmedSignaturesForAddress2")]
fn get_confirmed_signatures_for_address2(
&self,
@ -2545,17 +2501,6 @@ pub mod rpc_full {
impl Full for FullImpl {
type Metadata = JsonRpcRequestProcessor;
fn confirm_transaction(
&self,
meta: Self::Metadata,
id: String,
commitment: Option<CommitmentConfig>,
) -> Result<RpcResponse<bool>> {
debug!("confirm_transaction rpc request received: {:?}", id);
let signature = verify_signature(&id)?;
Ok(meta.confirm_transaction(&signature, commitment))
}
fn get_account_info(
&self,
meta: Self::Metadata,
@ -2786,34 +2731,6 @@ pub mod rpc_full {
Ok(meta.get_fee_rate_governor())
}
fn get_signature_confirmation(
&self,
meta: Self::Metadata,
signature_str: String,
commitment: Option<CommitmentConfig>,
) -> Result<Option<RpcSignatureConfirmation>> {
debug!(
"get_signature_confirmation rpc request received: {:?}",
signature_str
);
let signature = verify_signature(&signature_str)?;
Ok(meta.get_signature_confirmation_status(signature, commitment))
}
fn get_signature_status(
&self,
meta: Self::Metadata,
signature_str: String,
commitment: Option<CommitmentConfig>,
) -> Result<Option<transaction::Result<()>>> {
debug!(
"get_signature_status rpc request received: {:?}",
signature_str
);
let signature = verify_signature(&signature_str)?;
Ok(meta.get_signature_status(signature, commitment))
}
fn get_signature_statuses(
&self,
meta: Self::Metadata,
@ -2847,15 +2764,6 @@ pub mod rpc_full {
Ok(meta.get_max_shred_insert_slot())
}
fn get_total_supply(
&self,
meta: Self::Metadata,
commitment: Option<CommitmentConfig>,
) -> Result<u64> {
debug!("get_total_supply rpc request received");
Ok(meta.get_total_supply(commitment))
}
fn get_largest_accounts(
&self,
meta: Self::Metadata,
@ -3151,37 +3059,6 @@ pub mod rpc_full {
meta.get_confirmed_transaction(signature, config)
}
fn get_confirmed_signatures_for_address(
&self,
meta: Self::Metadata,
pubkey_str: String,
start_slot: Slot,
end_slot: Slot,
) -> Result<Vec<String>> {
debug!(
"get_confirmed_signatures_for_address rpc request received: {:?} {:?}-{:?}",
pubkey_str, start_slot, end_slot
);
let pubkey = verify_pubkey(pubkey_str)?;
if end_slot < start_slot {
return Err(Error::invalid_params(format!(
"start_slot {} must be less than or equal to end_slot {}",
start_slot, end_slot
)));
}
if end_slot - start_slot > MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS_SLOT_RANGE {
return Err(Error::invalid_params(format!(
"Slot range too large; max {}",
MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS_SLOT_RANGE
)));
}
Ok(meta
.get_confirmed_signatures_for_address(pubkey, start_slot, end_slot)
.iter()
.map(|signature| signature.to_string())
.collect())
}
fn get_confirmed_signatures_for_address2(
&self,
meta: Self::Metadata,
@ -3330,6 +3207,144 @@ pub mod rpc_full {
}
}
// Obsolete RPC methods, collected for easy deactivation and removal
pub mod rpc_obsolete_v1_7 {
use super::*;
#[rpc]
pub trait ObsoleteV1_7 {
type Metadata;
// DEPRECATED
#[rpc(meta, name = "confirmTransaction")]
fn confirm_transaction(
&self,
meta: Self::Metadata,
signature_str: String,
commitment: Option<CommitmentConfig>,
) -> Result<RpcResponse<bool>>;
// DEPRECATED
#[rpc(meta, name = "getSignatureStatus")]
fn get_signature_status(
&self,
meta: Self::Metadata,
signature_str: String,
commitment: Option<CommitmentConfig>,
) -> Result<Option<transaction::Result<()>>>;
// DEPRECATED (used by Trust Wallet)
#[rpc(meta, name = "getSignatureConfirmation")]
fn get_signature_confirmation(
&self,
meta: Self::Metadata,
signature_str: String,
commitment: Option<CommitmentConfig>,
) -> Result<Option<RpcSignatureConfirmation>>;
// DEPRECATED
#[rpc(meta, name = "getTotalSupply")]
fn get_total_supply(
&self,
meta: Self::Metadata,
commitment: Option<CommitmentConfig>,
) -> Result<u64>;
// DEPRECATED
#[rpc(meta, name = "getConfirmedSignaturesForAddress")]
fn get_confirmed_signatures_for_address(
&self,
meta: Self::Metadata,
pubkey_str: String,
start_slot: Slot,
end_slot: Slot,
) -> Result<Vec<String>>;
}
pub struct ObsoleteV1_7Impl;
impl ObsoleteV1_7 for ObsoleteV1_7Impl {
type Metadata = JsonRpcRequestProcessor;
fn confirm_transaction(
&self,
meta: Self::Metadata,
id: String,
commitment: Option<CommitmentConfig>,
) -> Result<RpcResponse<bool>> {
debug!("confirm_transaction rpc request received: {:?}", id);
let signature = verify_signature(&id)?;
Ok(meta.confirm_transaction(&signature, commitment))
}
fn get_signature_status(
&self,
meta: Self::Metadata,
signature_str: String,
commitment: Option<CommitmentConfig>,
) -> Result<Option<transaction::Result<()>>> {
debug!(
"get_signature_status rpc request received: {:?}",
signature_str
);
let signature = verify_signature(&signature_str)?;
Ok(meta.get_signature_status(signature, commitment))
}
fn get_signature_confirmation(
&self,
meta: Self::Metadata,
signature_str: String,
commitment: Option<CommitmentConfig>,
) -> Result<Option<RpcSignatureConfirmation>> {
debug!(
"get_signature_confirmation rpc request received: {:?}",
signature_str
);
let signature = verify_signature(&signature_str)?;
Ok(meta.get_signature_confirmation_status(signature, commitment))
}
fn get_total_supply(
&self,
meta: Self::Metadata,
commitment: Option<CommitmentConfig>,
) -> Result<u64> {
debug!("get_total_supply rpc request received");
Ok(meta.get_total_supply(commitment))
}
fn get_confirmed_signatures_for_address(
&self,
meta: Self::Metadata,
pubkey_str: String,
start_slot: Slot,
end_slot: Slot,
) -> Result<Vec<String>> {
debug!(
"get_confirmed_signatures_for_address rpc request received: {:?} {:?}-{:?}",
pubkey_str, start_slot, end_slot
);
let pubkey = verify_pubkey(pubkey_str)?;
if end_slot < start_slot {
return Err(Error::invalid_params(format!(
"start_slot {} must be less than or equal to end_slot {}",
start_slot, end_slot
)));
}
if end_slot - start_slot > MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS_SLOT_RANGE {
return Err(Error::invalid_params(format!(
"Slot range too large; max {}",
MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS_SLOT_RANGE
)));
}
Ok(meta
.get_confirmed_signatures_for_address(pubkey, start_slot, end_slot)
.iter()
.map(|signature| signature.to_string())
.collect())
}
}
}
const WORST_CASE_BASE58_TX: usize = 1683; // Golden, bump if PACKET_DATA_SIZE changes
const WORST_CASE_BASE64_TX: usize = 1644; // Golden, bump if PACKET_DATA_SIZE changes
fn deserialize_transaction(
@ -3868,31 +3883,6 @@ pub mod tests {
assert_eq!(expected, result);
}
#[test]
fn test_rpc_get_total_supply() {
let bob_pubkey = solana_sdk::pubkey::new_rand();
let RpcHandler { io, meta, .. } = start_rpc_handler_with_tx(&bob_pubkey);
let req = r#"{"jsonrpc":"2.0","id":1,"method":"getTotalSupply"}"#;
let rep = io.handle_request_sync(&req, meta);
let res: Response = serde_json::from_str(&rep.expect("actual response"))
.expect("actual response deserialization");
let supply: u64 = if let Response::Single(res) = res {
if let Output::Success(res) = res {
if let Value::Number(num) = res.result {
num.as_u64().unwrap()
} else {
panic!("Expected number");
}
} else {
panic!("Expected success");
}
} else {
panic!("Expected single response");
};
assert!(supply >= TEST_MINT_LAMPORTS);
}
#[test]
fn test_get_supply() {
let bob_pubkey = solana_sdk::pubkey::new_rand();
@ -4725,108 +4715,6 @@ pub mod tests {
let _ = io.handle_request_sync(&req, meta);
}
#[test]
fn test_rpc_confirm_tx() {
let bob_pubkey = solana_sdk::pubkey::new_rand();
let RpcHandler {
io,
meta,
blockhash,
alice,
..
} = start_rpc_handler_with_tx(&bob_pubkey);
let tx = system_transaction::transfer(&alice, &bob_pubkey, 20, blockhash);
let req = format!(
r#"{{"jsonrpc":"2.0","id":1,"method":"confirmTransaction","params":["{}"]}}"#,
tx.signatures[0]
);
let res = io.handle_request_sync(&req, meta);
let expected = json!({
"jsonrpc": "2.0",
"result": {
"context":{"slot":0},
"value":true,
},
"id": 1,
});
let expected: Response =
serde_json::from_value(expected).expect("expected response deserialization");
let result: Response = serde_json::from_str(&res.expect("actual response"))
.expect("actual response deserialization");
assert_eq!(expected, result);
}
#[test]
fn test_rpc_get_signature_status() {
let bob_pubkey = solana_sdk::pubkey::new_rand();
let RpcHandler {
io,
meta,
blockhash,
alice,
..
} = start_rpc_handler_with_tx(&bob_pubkey);
let tx = system_transaction::transfer(&alice, &bob_pubkey, 20, blockhash);
let req = format!(
r#"{{"jsonrpc":"2.0","id":1,"method":"getSignatureStatus","params":["{}"]}}"#,
tx.signatures[0]
);
let res = io.handle_request_sync(&req, meta.clone());
let expected_res: Option<transaction::Result<()>> = Some(Ok(()));
let expected = json!({
"jsonrpc": "2.0",
"result": expected_res,
"id": 1
});
let expected: Response =
serde_json::from_value(expected).expect("expected response deserialization");
let result: Response = serde_json::from_str(&res.expect("actual response"))
.expect("actual response deserialization");
assert_eq!(expected, result);
// Test getSignatureStatus request on unprocessed tx
let tx = system_transaction::transfer(&alice, &bob_pubkey, 10, blockhash);
let req = format!(
r#"{{"jsonrpc":"2.0","id":1,"method":"getSignatureStatus","params":["{}"]}}"#,
tx.signatures[0]
);
let res = io.handle_request_sync(&req, meta.clone());
let expected_res: Option<String> = None;
let expected = json!({
"jsonrpc": "2.0",
"result": expected_res,
"id": 1
});
let expected: Response =
serde_json::from_value(expected).expect("expected response deserialization");
let result: Response = serde_json::from_str(&res.expect("actual response"))
.expect("actual response deserialization");
assert_eq!(expected, result);
// Test getSignatureStatus request on a TransactionError
let tx = system_transaction::transfer(&alice, &bob_pubkey, std::u64::MAX, blockhash);
let req = format!(
r#"{{"jsonrpc":"2.0","id":1,"method":"getSignatureStatus","params":["{}"]}}"#,
tx.signatures[0]
);
let res = io.handle_request_sync(&req, meta);
let expected_res: Option<transaction::Result<()>> = Some(Err(
TransactionError::InstructionError(0, InstructionError::Custom(1)),
));
let expected = json!({
"jsonrpc": "2.0",
"result": expected_res,
"id": 1
});
let expected: Response =
serde_json::from_value(expected).expect("expected response deserialization");
let result: Response = serde_json::from_str(&res.expect("actual response"))
.expect("actual response deserialization");
assert_eq!(expected, result);
}
#[test]
fn test_rpc_get_signature_statuses() {
let bob_pubkey = solana_sdk::pubkey::new_rand();

View File

@ -6,7 +6,7 @@ use crate::{
max_slots::MaxSlots,
optimistically_confirmed_bank_tracker::OptimisticallyConfirmedBank,
poh_recorder::PohRecorder,
rpc::{rpc_full::*, rpc_minimal::*, *},
rpc::{rpc_full::*, rpc_minimal::*, rpc_obsolete_v1_7::*, *},
rpc_health::*,
send_transaction_service::{LeaderInfo, SendTransactionService},
validator::ValidatorExit,
@ -341,6 +341,7 @@ impl JsonRpcService {
};
let minimal_api = config.minimal_api;
let obsolete_v1_7_api = config.obsolete_v1_7_api;
let (request_processor, receiver) = JsonRpcRequestProcessor::new(
config,
snapshot_config.clone(),
@ -403,6 +404,9 @@ impl JsonRpcService {
if !minimal_api {
io.extend_with(rpc_full::FullImpl.to_delegate());
}
if obsolete_v1_7_api {
io.extend_with(rpc_obsolete_v1_7::ObsoleteV1_7Impl.to_delegate());
}
let request_middleware = RpcRequestMiddleware::new(
ledger_path,

View File

@ -18,6 +18,7 @@ use solana_sdk::{
system_transaction,
transaction::Transaction,
};
use solana_transaction_status::TransactionStatus;
use std::{
collections::HashSet,
net::UdpSocket,
@ -79,14 +80,18 @@ fn test_rpc_send_tx() {
let mut confirmed_tx = false;
let request = json_req!("confirmTransaction", [signature]);
let request = json_req!("getSignatureStatuses", [[signature]]);
for _ in 0..solana_sdk::clock::DEFAULT_TICKS_PER_SLOT {
let json = post_rpc(request.clone(), &rpc_url);
if true == json["result"]["value"] {
confirmed_tx = true;
break;
let result: Option<TransactionStatus> =
serde_json::from_value(json["result"]["value"][0].clone()).unwrap();
if let Some(result) = result.as_ref() {
if result.err.is_none() {
confirmed_tx = true;
break;
}
}
sleep(Duration::from_millis(500));

View File

@ -26,7 +26,6 @@ gives a convenient interface for the RPC methods.
- [getConfirmedBlock](jsonrpc-api.md#getconfirmedblock)
- [getConfirmedBlocks](jsonrpc-api.md#getconfirmedblocks)
- [getConfirmedBlocksWithLimit](jsonrpc-api.md#getconfirmedblockswithlimit)
- [getConfirmedSignaturesForAddress](jsonrpc-api.md#getconfirmedsignaturesforaddress)
- [getConfirmedSignaturesForAddress2](jsonrpc-api.md#getconfirmedsignaturesforaddress2)
- [getConfirmedTransaction](jsonrpc-api.md#getconfirmedtransaction)
- [getEpochInfo](jsonrpc-api.md#getepochinfo)
@ -740,58 +739,6 @@ Result:
{"jsonrpc":"2.0","result":[5,6,7],"id":1}
```
### getConfirmedSignaturesForAddress
**DEPRECATED: Please use getConfirmedSignaturesForAddress2 instead**
Returns a list of all the confirmed signatures for transactions involving an
address, within a specified Slot range. Max range allowed is 10,000 Slots
#### Parameters:
- `<string>` - account address as base-58 encoded string
- `<u64>` - start slot, inclusive
- `<u64>` - end slot, inclusive
#### Results:
The result field will be an array of:
- `<string>` - transaction signature as base-58 encoded string
The signatures will be ordered based on the Slot in which they were confirmed in, from lowest to highest Slot
#### Example:
Request:
```bash
curl http://localhost:8899 -X POST -H "Content-Type: application/json" -d '
{
"jsonrpc": "2.0",
"id": 1,
"method": "getConfirmedSignaturesForAddress",
"params": [
"6H94zdiaYfRfPfKjYLjyr2VFBg6JHXygy84r3qhc3NsC",
0,
100
]
}
'
```
Result:
```json
{
"jsonrpc": "2.0",
"result": [
"35YGay1Lwjwgxe9zaH6APSHbt9gYQUCtBWTNL3aVwVGn9xTFw2fgds7qK5AL29mP63A9j3rh8KpN1TgSR62XCaby",
"4bJdGN8Tt2kLWZ3Fa1dpwPSEkXWWTSszPSf1rRVsCwNjxbbUdwTeiWtmi8soA26YmwnKD4aAxNp8ci1Gjpdv4gsr",
"4LQ14a7BYY27578Uj8LPCaVhSdJGLn9DJqnUJHpy95FMqdKf9acAhUhecPQNjNUy6VoNFUbvwYkPociFSf87cWbG"
],
"id": 1
}
```
### getConfirmedSignaturesForAddress2
Returns confirmed signatures for transactions involving an

View File

@ -1163,6 +1163,12 @@ pub fn main() {
.takes_value(false)
.help("Only expose the RPC methods required to serve snapshots to other nodes"),
)
.arg(
Arg::with_name("obsolete_v1_7_rpc_api")
.long("--enable-rpc-obsolete_v1_7")
.takes_value(false)
.help("Enable the obsolete RPC methods removed in v1.7"),
)
.arg(
Arg::with_name("private_rpc")
.long("--private-rpc")
@ -2064,6 +2070,7 @@ pub fn main() {
solana_net_utils::parse_host_port(address).expect("failed to parse faucet address")
}),
minimal_api: matches.is_present("minimal_rpc_api"),
obsolete_v1_7_api: matches.is_present("obsolete_v1_7_rpc_api"),
max_multiple_accounts: Some(value_t_or_exit!(
matches,
"rpc_max_multiple_accounts",