diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 37bf8aeac5cc02..0129f609c1dd4f 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -4951,7 +4951,7 @@ impl Bank { let ExecutionRecord { accounts, - mut return_data, + return_data, touched_account_count, accounts_resize_delta, } = transaction_context.into(); @@ -4981,14 +4981,8 @@ impl Bank { accounts_data_len_delta = status.as_ref().map_or(0, |_| accounts_resize_delta); } - let return_data = if enable_return_data_recording { - if let Some(end_index) = return_data.data.iter().rposition(|&x| x != 0) { - let end_index = end_index.saturating_add(1); - return_data.data.truncate(end_index); - Some(return_data) - } else { - None - } + let return_data = if enable_return_data_recording && !return_data.data.is_empty() { + Some(return_data) } else { None }; diff --git a/runtime/src/bank/tests.rs b/runtime/src/bank/tests.rs index 37dbcd7bc04ad7..a45e16dec58542 100644 --- a/runtime/src/bank/tests.rs +++ b/runtime/src/bank/tests.rs @@ -9712,9 +9712,9 @@ fn test_tx_return_data() { let mut return_data = [0u8; MAX_RETURN_DATA]; if !instruction_data.is_empty() { let index = usize::from_le_bytes(instruction_data.try_into().unwrap()); - return_data[index] = 1; + return_data[index / 2] = 1; transaction_context - .set_return_data(mock_program_id, return_data.to_vec()) + .set_return_data(mock_program_id, return_data[..index + 1].to_vec()) .unwrap(); } Ok(()) @@ -9766,8 +9766,9 @@ fn test_tx_return_data() { if let Some(index) = index { let return_data = return_data.unwrap(); assert_eq!(return_data.program_id, mock_program_id); - let mut expected_data = vec![0u8; index]; - expected_data.push(1u8); + let mut expected_data = vec![0u8; index + 1]; + // include some trailing zeros + expected_data[index / 2] = 1; assert_eq!(return_data.data, expected_data); } else { assert!(return_data.is_none());