From 9c64e5e3b1ea1dd7c753485280d3cba86ef5d568 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 8 Sep 2020 09:40:47 +0000 Subject: [PATCH] Fix RPC transaction method options serialization (bp #12100) (#12101) * Fix RPC transaction method configs serialization (#12100) (cherry picked from commit 9940870c89b322f2160c571fd77de661acece13f) # Conflicts: # core/src/rpc.rs * Update rpc.rs Co-authored-by: Justin Starry --- client/src/rpc_config.rs | 10 ++++++++-- core/src/rpc.rs | 5 ++++- docs/src/apps/jsonrpc-api.md | 14 +++++++------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/client/src/rpc_config.rs b/client/src/rpc_config.rs index 4c11b2170d..a62a620883 100644 --- a/client/src/rpc_config.rs +++ b/client/src/rpc_config.rs @@ -1,6 +1,9 @@ use crate::rpc_filter::RpcFilterType; use solana_account_decoder::{UiAccountEncoding, UiDataSliceConfig}; -use solana_sdk::{clock::Epoch, commitment_config::CommitmentConfig}; +use solana_sdk::{ + clock::Epoch, + commitment_config::{CommitmentConfig, CommitmentLevel}, +}; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] @@ -11,14 +14,17 @@ pub struct RpcSignatureStatusConfig { #[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct RpcSendTransactionConfig { + #[serde(default)] pub skip_preflight: bool, - pub preflight_commitment: Option, + pub preflight_commitment: Option, } #[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct RpcSimulateTransactionConfig { + #[serde(default)] pub sig_verify: bool, + #[serde(flatten)] pub commitment: Option, } diff --git a/core/src/rpc.rs b/core/src/rpc.rs index 3a944245f4..7c392815e3 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -2150,7 +2150,10 @@ impl RpcSol for RpcSolImpl { .into()); } - let preflight_bank = &*meta.bank(config.preflight_commitment)?; + let preflight_commitment = config + .preflight_commitment + .map(|commitment| CommitmentConfig { commitment }); + let preflight_bank = &*meta.bank(preflight_commitment)?; if let (Err(err), _log_output) = run_transaction_simulation(&preflight_bank, transaction.clone()) { diff --git a/docs/src/apps/jsonrpc-api.md b/docs/src/apps/jsonrpc-api.md index 868a7c4093..459843405c 100644 --- a/docs/src/apps/jsonrpc-api.md +++ b/docs/src/apps/jsonrpc-api.md @@ -111,10 +111,10 @@ Requests can be sent in batches by sending an array of JSON-RPC request objects Solana nodes choose which bank state to query based on a commitment requirement set by the client. Clients may specify either: -- `{"commitment":"max"}` - the node will query the most recent bank confirmed by the cluster as having reached `MAX_LOCKOUT_HISTORY` confirmations -- `{"commitment":"root"}` - the node will query the most recent bank having reached `MAX_LOCKOUT_HISTORY` confirmations on this node -- `{"commitment":"single"}` - the node will query the most recent bank having reached 1 confirmation -- `{"commitment":"recent"}` - the node will query its most recent bank +- `"max"` - the node will query the most recent bank confirmed by the cluster as having reached `MAX_LOCKOUT_HISTORY` confirmations +- `"root"` - the node will query the most recent bank having reached `MAX_LOCKOUT_HISTORY` confirmations on this node +- `"single"` - the node will query the most recent bank having reached 1 confirmation +- `"recent"` - the node will query its most recent bank The commitment parameter should be included as the last element in the `params` array: @@ -124,7 +124,7 @@ curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0", "id":1, " #### Default: -If commitment configuration is not provided, the node will default to `"commitment":"max"` +If commitment configuration is not provided, the node will default to `"max"` commitment Only methods that query bank state accept the commitment parameter. They are indicated in the API Reference below. @@ -1397,7 +1397,7 @@ Before submitting, the following preflight checks are performed: - `` - fully-signed Transaction, as base-58 encoded string - `` - (optional) Configuration object containing the following field: - `skipPreflight: ` - if true, skip the preflight transaction checks (default: false) - - `preflightCommitment: ` - (optional) [Commitment](jsonrpc-api.md#configuring-state-commitment) level to use for preflight (default: max). + - `preflightCommitment: ` - (optional) [Commitment](jsonrpc-api.md#configuring-state-commitment) level to use for preflight (default: `"max"`). #### Results: @@ -1422,7 +1422,7 @@ Simulate sending a transaction - `` - Transaction, as base-58 encoded string. The transaction must have a valid blockhash, but is not required to be signed. - `` - (optional) Configuration object containing the following field: - `sigVerify: ` - if true the transaction signatures will be verified (default: false) - - `commitment: ` - (optional) [Commitment](jsonrpc-api.md#configuring-state-commitment) level to simulate the transaction at (default: max). + - `commitment: ` - (optional) [Commitment](jsonrpc-api.md#configuring-state-commitment) level to simulate the transaction at (default: `"max"`). #### Results: