From 54284955ded0e90ee10478f6d923e9e523b7a49c Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Thu, 8 Sep 2022 09:17:02 -0700 Subject: [PATCH] Respect rewards parameter in getBlock transaction-level rewards (#27655) * Respect options.show_rewards in UiTransactionStatusMeta * Fixup docs --- docs/src/developing/clients/jsonrpc-api.md | 14 ++++++++-- ledger-tool/src/bigtable.rs | 2 +- transaction-status/src/lib.rs | 31 ++++++++++++++++------ 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/docs/src/developing/clients/jsonrpc-api.md b/docs/src/developing/clients/jsonrpc-api.md index 755eaebb35254e..04a15199804476 100644 --- a/docs/src/developing/clients/jsonrpc-api.md +++ b/docs/src/developing/clients/jsonrpc-api.md @@ -437,6 +437,12 @@ The result field will be an object with the following fields: - `preTokenBalances: ` - List of [token balances](#token-balances-structure) from before the transaction was processed or omitted if token balance recording was not yet enabled during this transaction - `postTokenBalances: ` - List of [token balances](#token-balances-structure) from after the transaction was processed or omitted if token balance recording was not yet enabled during this transaction - `logMessages: ` - array of string log messages or `null` if log message recording was not enabled during this transaction + - `rewards: ` - transaction-level rewards, populated if rewards are requested; an array of JSON objects containing: + - `pubkey: ` - The public key, as base-58 encoded string, of the account that received the reward + - `lamports: `- number of reward lamports credited or debited by the account, as a i64 + - `postBalance: ` - account balance in lamports after the reward was applied + - `rewardType: ` - type of reward: "fee", "rent", "voting", "staking" + - `commission: ` - vote account commission when the reward was credited, only present for voting and staking rewards - DEPRECATED: `status: ` - Transaction status - `"Ok": ` - Transaction was successful - `"Err": ` - Transaction failed with TransactionError @@ -445,7 +451,7 @@ The result field will be an object with the following fields: - `readonly: ` - Ordered list of base-58 encoded addresses for readonly loaded accounts - `version: <"legacy"|number|undefined>` - Transaction version. Undefined if `maxSupportedTransactionVersion` is not set in request params. - `signatures: ` - present if "signatures" are requested for transaction details; an array of signatures strings, corresponding to the transaction order in the block - - `rewards: ` - present if rewards are requested; an array of JSON objects containing: + - `rewards: ` - block-level rewards, present if rewards are requested; an array of JSON objects containing: - `pubkey: ` - The public key, as base-58 encoded string, of the account that received the reward - `lamports: `- number of reward lamports credited or debited by the account, as a i64 - `postBalance: ` - account balance in lamports after the reward was applied @@ -486,6 +492,7 @@ Result: "postTokenBalances": [], "preBalances": [499998937500, 26858640, 1, 1, 1], "preTokenBalances": [], + "rewards": null, "status": { "Ok": null } @@ -557,6 +564,7 @@ Result: "postTokenBalances": [], "preBalances": [499998937500, 26858640, 1, 1, 1], "preTokenBalances": [], + "rewards": [], "status": { "Ok": null } @@ -3036,7 +3044,7 @@ Returns transaction details for a confirmed transaction - DEPRECATED: `status: ` - Transaction status - `"Ok": ` - Transaction was successful - `"Err": ` - Transaction failed with TransactionError - - `rewards: ` - present if rewards are requested; an array of JSON objects containing: + - `rewards: ` - transaction-level rewards, populated if rewards are requested; an array of JSON objects containing: - `pubkey: ` - The public key, as base-58 encoded string, of the account that received the reward - `lamports: `- number of reward lamports credited or debited by the account, as a i64 - `postBalance: ` - account balance in lamports after the reward was applied @@ -3079,6 +3087,7 @@ Result: "postTokenBalances": [], "preBalances": [499998937500, 26858640, 1, 1, 1], "preTokenBalances": [], + "rewards": [], "status": { "Ok": null } @@ -3149,6 +3158,7 @@ Result: "postTokenBalances": [], "preBalances": [499998937500, 26858640, 1, 1, 1], "preTokenBalances": [], + "rewards": null, "status": { "Ok": null } diff --git a/ledger-tool/src/bigtable.rs b/ledger-tool/src/bigtable.rs index 1b93f15b600777..c9b3a5188463da 100644 --- a/ledger-tool/src/bigtable.rs +++ b/ledger-tool/src/bigtable.rs @@ -213,7 +213,7 @@ async fn confirm( let decoded_tx = confirmed_tx.get_transaction(); let encoded_tx_with_meta = confirmed_tx .tx_with_meta - .encode(UiTransactionEncoding::Json, Some(0)) + .encode(UiTransactionEncoding::Json, Some(0), true) .map_err(|_| "Failed to encode transaction in block".to_string())?; transaction = Some(CliTransaction { transaction: encoded_tx_with_meta.transaction, diff --git a/transaction-status/src/lib.rs b/transaction-status/src/lib.rs index ff08dd65c09100..2e17bc5415f06b 100644 --- a/transaction-status/src/lib.rs +++ b/transaction-status/src/lib.rs @@ -358,7 +358,7 @@ impl From<&LoadedAddresses> for UiLoadedAddresses { } impl UiTransactionStatusMeta { - fn parse(meta: TransactionStatusMeta, static_keys: &[Pubkey]) -> Self { + fn parse(meta: TransactionStatusMeta, static_keys: &[Pubkey], show_rewards: bool) -> Self { let account_keys = AccountKeys::new(static_keys, Some(&meta.loaded_addresses)); Self { err: meta.status.clone().err(), @@ -378,7 +378,7 @@ impl UiTransactionStatusMeta { post_token_balances: meta .post_token_balances .map(|balance| balance.into_iter().map(Into::into).collect()), - rewards: meta.rewards, + rewards: if show_rewards { meta.rewards } else { None }, loaded_addresses: None, return_data: meta.return_data, compute_units_consumed: meta.compute_units_consumed, @@ -540,7 +540,11 @@ impl ConfirmedBlock { self.transactions .into_iter() .map(|tx_with_meta| { - tx_with_meta.encode(encoding, options.max_supported_transaction_version) + tx_with_meta.encode( + encoding, + options.max_supported_transaction_version, + options.show_rewards, + ) }) .collect::, _>>()?, ), @@ -659,6 +663,7 @@ impl TransactionWithStatusMeta { self, encoding: UiTransactionEncoding, max_supported_transaction_version: Option, + show_rewards: bool, ) -> Result { match self { Self::MissingMetadata(ref transaction) => Ok(EncodedTransactionWithStatusMeta { @@ -667,7 +672,7 @@ impl TransactionWithStatusMeta { meta: None, }), Self::Complete(tx_with_meta) => { - tx_with_meta.encode(encoding, max_supported_transaction_version) + tx_with_meta.encode(encoding, max_supported_transaction_version, show_rewards) } } } @@ -685,6 +690,7 @@ impl VersionedTransactionWithStatusMeta { self, encoding: UiTransactionEncoding, max_supported_transaction_version: Option, + show_rewards: bool, ) -> Result { let version = match ( max_supported_transaction_version, @@ -711,8 +717,15 @@ impl VersionedTransactionWithStatusMeta { UiTransactionEncoding::JsonParsed => UiTransactionStatusMeta::parse( self.meta, self.transaction.message.static_account_keys(), + show_rewards, ), - _ => UiTransactionStatusMeta::from(self.meta), + _ => { + let mut meta = UiTransactionStatusMeta::from(self.meta); + if !show_rewards { + meta.rewards = None; + } + meta + } }), version, }) @@ -757,9 +770,11 @@ impl ConfirmedTransactionWithStatusMeta { ) -> Result { Ok(EncodedConfirmedTransactionWithStatusMeta { slot: self.slot, - transaction: self - .tx_with_meta - .encode(encoding, max_supported_transaction_version)?, + transaction: self.tx_with_meta.encode( + encoding, + max_supported_transaction_version, + true, + )?, block_time: self.block_time, }) }