Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

[bug] simulate transaction - return data truncates 0 trailing zero bytes #31391

Closed
ngundotra opened this issue Apr 28, 2023 · 5 comments · Fixed by #33639
Closed

[bug] simulate transaction - return data truncates 0 trailing zero bytes #31391

ngundotra opened this issue Apr 28, 2023 · 5 comments · Fixed by #33639
Assignees

Comments

@ngundotra
Copy link
Contributor

Problem

Here's the output of connection.simulateTransaction(...)

value.logs:

[
  'Program F96CHxPDRgjUypdUqpJocgT59vEPT79AFJXjtyPCBaRt invoke [1]',
 ...
  'Program return: F96CHxPDRgjUypdUqpJocgT59vEPT79AFJXjtyPCBaRt CgAAAGqESwQbOhmSyJ05YcX8yuNd0njURaxOHDYINR4MYbMsAAEojRw9Os+/4K0ZpeJWw/3v8PboPlgkFx4n0ld1IP747AABPu+weEw0Q/3awCJDGdE4AeW7NRpNrlCaBi5txpV4jTUAADIZojUTiD7oHHgzCQXAuZXenMlh3zh7I2cL6rQZ7/hBAACcte7UwJZd0Ds9bHif7Z3TAwmi3JGxths2aoEaBkaCzgABnwlgIBRezTwnbIydryTVyUOR7ZyFLFOah/zvvilCq2wAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGp9UXGHvRZjXa1ARV/cLAwSTGjyFWdaXbustfCAAAAAAABt324ddloZPZy+FGzut5rBy0he1fWzeROoz1hX7/AKkAAIyXJY9OJInxuz0QKRSODYMLWhOZ2v8QhASOe9jb6fhZAAA=',
  'Program F96CHxPDRgjUypdUqpJocgT59vEPT79AFJXjtyPCBaRt success'
] 

This is a problem because its unexpected behavior. It's not high priority because devs can just parse the 2nd to last log line for their untruncated return data.

Proposed Solution

Just return the full 1024 (MAX_CPI_DATA) slab length in RPC response value.return_data

@CriesofCarrots
Copy link
Contributor

Why would you parse the log line instead of just adding back the padding, if for some reason you need it to be 1024 bytes?

@ngundotra
Copy link
Contributor Author

That's another great alternative solution.

The issue is .value.return_data['data'] actually truncates the trailing 0s of what I put in set_return_data.

@tkporter
Copy link

Also hitting this - would love to see this fixed

@tkporter
Copy link

tkporter commented May 19, 2023

Not sure what's different about my setup but I'm not able to use the logs workaround - my logs don't show a Program return at all. This is when using a BanksClient fwiw

TransactionSimulationDetails {
  logs: ["Program 2YjtZDiUoptoSsA5eVrDCcX6wxNK6YoEVW7y82x5Z2fw invoke [1]", "Program 2YjtZDiUoptoSsA5eVrDCcX6wxNK6YoEVW7y82x5Z2fw invoke [1]", "Program 2YjtZDiUoptoSsA5eVrDCcX6wxNK6YoEVW7y82x5Z2fw success", "Program 2YjtZDiUoptoSsA5eVrDCcX6wxNK6YoEVW7y82x5Z2fw success"],
  units_consumed: 0,
  return_data: Some(TransactionReturnData { program_id: 2YjtZDiUoptoSsA5eVrDCcX6wxNK6YoEVW7y82x5Z2fw, data: [1, 0, 0, 0, 208, 33, 109, 56, 119, 42, 118, 230, 38, 41, 226, 35, 34, 241, 83, 38, 4, 160, 7, 87, 162, 113, 226, 54, 205, 242, 16, 94, 4, 142, 139, 151] })
}

My return data is truncated and ordinarily has two zero bytes at the end

@tkporter
Copy link

My sad workaround is a wrapper type like this to always ensure there are no trailing 0 bytes :(

#[derive(Debug, BorshSerialize, BorshDeserialize)]
pub struct SimulationReturnData<T>
where
    T: BorshSerialize + BorshDeserialize,
{
    pub return_data: T,
    trailing_byte: u8,
}

impl<T> SimulationReturnData<T>
where
    T: BorshSerialize + BorshDeserialize,
{
    pub fn new(return_data: T) -> Self {
        Self {
            return_data,
            trailing_byte: u8::MAX,
        }
    }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants