From 96cef5260c4ed0d1b1fec9ba648f8eeea24e619e Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Tue, 25 May 2021 13:01:21 -0700 Subject: [PATCH] Add a flag to simulateTransaction to use most recent blockhash --- client/src/rpc_config.rs | 2 ++ core/src/rpc.rs | 5 ++++- docs/src/developing/clients/jsonrpc-api.md | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/client/src/rpc_config.rs b/client/src/rpc_config.rs index dba7bdd200..03c5370413 100644 --- a/client/src/rpc_config.rs +++ b/client/src/rpc_config.rs @@ -28,6 +28,8 @@ pub struct RpcSendTransactionConfig { pub struct RpcSimulateTransactionConfig { #[serde(default)] pub sig_verify: bool, + #[serde(default)] + pub use_most_recent_blockhash: bool, #[serde(flatten)] pub commitment: Option, pub encoding: Option, diff --git a/core/src/rpc.rs b/core/src/rpc.rs index 78521da701..e229563815 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -2969,7 +2969,7 @@ pub mod rpc_full { debug!("simulate_transaction rpc request received"); let config = config.unwrap_or_default(); let encoding = config.encoding.unwrap_or(UiTransactionEncoding::Base58); - let (_, transaction) = deserialize_transaction(data, encoding)?; + let (_, mut transaction) = deserialize_transaction(data, encoding)?; if config.sig_verify { if let Err(e) = verify_transaction(&transaction) { @@ -2978,6 +2978,9 @@ pub mod rpc_full { } let bank = &*meta.bank(config.commitment); + if config.use_most_recent_blockhash { + transaction.message.recent_blockhash = bank.last_blockhash(); + } let (result, logs) = bank.simulate_transaction(transaction); Ok(new_response( diff --git a/docs/src/developing/clients/jsonrpc-api.md b/docs/src/developing/clients/jsonrpc-api.md index 6fb0113e0c..67606b5ec7 100644 --- a/docs/src/developing/clients/jsonrpc-api.md +++ b/docs/src/developing/clients/jsonrpc-api.md @@ -3206,6 +3206,7 @@ Simulate sending a transaction - `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: `"finalized"`). - `encoding: ` - (optional) Encoding used for the transaction data. Either `"base58"` (*slow*, **DEPRECATED**), or `"base64"`. (default: `"base58"`). + - `useMostRecentBlockhash: ` - (optional) if true the transaction recent blockhash will be ignored and overridden with the most recent blockhash. (default: false) #### Results: