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

Add new TransactionDetails level #27601

Merged
merged 4 commits into from
Sep 15, 2022

Conversation

CriesofCarrots
Copy link
Contributor

Problem

Responses for getBlock rpc requests can be huge. The TransactionDetails parameter enables reducing returned transactions to just signatures, or eliminating the details altogether. But any consumer that needs to track account balance changes in each block (an exchange, eg) has to pull the full details, even though they don't need instruction data, inner-instruction or log details, etc.

Summary of Changes

Add a new TransactionDetails level that slims each transaction in a block to just pre/postBalances (sol and token), signatures, and the list of accounts.

@CriesofCarrots
Copy link
Contributor Author

Example:

$ curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0","id":1,"method":"getBlock","params":[160257046,{"transactionDetails":"accounts","rewards":false}]}' <devnet_node> | jq

{
  "jsonrpc": "2.0",
  "result": {
    "blockHeight": 150808359,
    "blockTime": 1662485419,
    "blockhash": "CdzN3T7ERcxjqk8PxEqq7mErxDL6CoD8CDEyp78NbJz5",
    "parentSlot": 160257045,
    "previousBlockhash": "3E5Z6vt3Jvx6hHPaP15gXhJTpQo4ABTaKgHX9zAf8KkT",
    "transactions": [
      {
        "meta": {
          "err": null,
          "fee": 5000,
          "postBalances": [
            204375923219118,
            100000000000,
            1169280,
            143487360,
            1
          ],
          "postTokenBalances": [],
          "preBalances": [
            204375923224118,
            100000000000,
            1169280,
            143487360,
            1
          ],
          "preTokenBalances": [],
          "status": {
            "Ok": null
          }
        },
        "transaction": {
          "accountKeys": [
            {
              "pubkey": "dv3qDFk1DTF36Z62bNvrCXe9sKATA6xvVy6A798xxAS",
              "signer": true,
              "source": "transaction",
              "writable": true
            },
            {
              "pubkey": "vgcDar2pryHvMgPkKaZfh8pQy4BJxv7SpwUG7zinWjG",
              "signer": false,
              "source": "transaction",
              "writable": true
            },
            {
              "pubkey": "SysvarC1ock11111111111111111111111111111111",
              "signer": false,
              "source": "transaction",
              "writable": false
            },
            {
              "pubkey": "SysvarS1otHashes111111111111111111111111111",
              "signer": false,
              "source": "transaction",
              "writable": false
            },
            {
              "pubkey": "Vote111111111111111111111111111111111111111",
              "signer": false,
              "source": "transaction",
              "writable": false
            }
          ],
          "signatures": [
            "2jnhgWUBWsFk73gPwkcXBGNS2sKquivC5rjFWrxfHyXbbsxcJxLRJP3FSUwZG2KtinVytJ17sBq7Et2R6PkJHEfp"
          ]
        }
      },
      {
        "meta": {
          "err": null,
          "fee": 5000,
          "postBalances": [
            974108077111,
            23942400,
            23942400,
            23942400,
            23942400,
            23942400,
            23942400,
            23942400,
            23942400,
            1169280,
            1141440
          ],
          "postTokenBalances": [],
          "preBalances": [
            974108082111,
            23942400,
            23942400,
            23942400,
            23942400,
            23942400,
            23942400,
            23942400,
            23942400,
            1169280,
            1141440
          ],
          "preTokenBalances": [],
          "status": {
            "Ok": null
          }
        },
        "transaction": {
          "accountKeys": [
            {
              "pubkey": "5U3bH5b6XtG99aVWLqwVzYPVpQiFHytBD68Rz2eFPZd7",
              "signer": true,
              "source": "transaction",
              "writable": true
            },
            {
              "pubkey": "7csi4gj91mycrtkhjdiKjJwoxavP84PMxnrtkqGafkVZ",
              "signer": false,
              "source": "transaction",
              "writable": true
            },
            {
              "pubkey": "38xoQ4oeJCBrcVvca2cGk7iV1dAfrmTR1kmhSCJQ8Jto",
              "signer": false,
              "source": "transaction",
              "writable": true
            },
            {
              "pubkey": "JAe1wPF7HgueCbqVcM5qfjskmURgyDhptKhTnC1PahaW",
              "signer": false,
              "source": "transaction",
              "writable": true
            },
            {
              "pubkey": "AUKjh1oVPZyudi3nzYSsdZxSjq42afUCvsdbKFc5CbD",
              "signer": false,
              "source": "transaction",
              "writable": true
            },
            {
              "pubkey": "Gvm85Pbjq4Tv7qyaS4y9ZMqCdY3nynGDBFYAu7mjPoGM",
              "signer": false,
              "source": "transaction",
              "writable": true
            },
            {
              "pubkey": "4NbqLAy4LjhZ7imWbyTuHo4EMSAVWTVDFS6Kpwz15Kyc",
              "signer": false,
              "source": "transaction",
              "writable": true
            },
            {
              "pubkey": "4GqTjGm686yihQ1m1YdTsSvfm4mNfadv6xskzgCYWNC5",
              "signer": false,
              "source": "transaction",
              "writable": true
            },
            {
              "pubkey": "4L6YhY8VvUgmqG5MvJkUJATtzB2rFqdrJwQCmFLv4Jzy",
              "signer": false,
              "source": "transaction",
              "writable": true
            },
            {
              "pubkey": "SysvarC1ock11111111111111111111111111111111",
              "signer": false,
              "source": "transaction",
              "writable": false
            },
            {
              "pubkey": "gSbePebfvPy7tRqimPoVecS2UsBvYv46ynrzWocc92s",
              "signer": false,
              "source": "transaction",
              "writable": false
            }
          ],
          "signatures": [
            "2DrtzGnenMJzn6BCqMvaJHVoW6j5BSzTf7nM1tAFcRkXApNbR1uNdZyPJwYUYv92iqfiVrLnNFYaJG4z71R6C3Mi"
          ]
        }
      },
      ...
  "id": 1
}

@CriesofCarrots
Copy link
Contributor Author

Wydt about not returning the empty metadata fields? Too breaky? I split that into its own commit, so easy to revert if need be.

@jstarry
Copy link
Contributor

jstarry commented Sep 7, 2022

Wydt about not returning the empty metadata fields? Too breaky? I split that into its own commit, so easy to revert if need be.

I'm in favor of it for this new details level but it would be a breaking change if the other responses are impacted because some sdk's and clients may expect those fields to be always present (though the web3 and rust sdk's wouldn't be impacted from what I can tell)

Copy link
Contributor

@jstarry jstarry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direction looks good to me!

transaction-status/src/lib.rs Show resolved Hide resolved
transaction-status/src/lib.rs Show resolved Hide resolved
@CriesofCarrots CriesofCarrots force-pushed the tx-details branch 2 times, most recently from 7179a78 to 3bddfa1 Compare September 7, 2022 21:28
@CriesofCarrots
Copy link
Contributor Author

I'm in favor of it for this new details level but it would be a breaking change if the other responses are impacted because some sdk's and clients may expect those fields to be always present

Okay, please see the last commit for an implementation that preserve current serialization for existing parameter inputs, but only includes the necessary fields for TransactionDetails::Accounts.
I was hoping there would be some slick little way to make the skip_serializing_if conditional, but the method can only inspect the field itself, so that approach required wrapping each field in an enum and got fairly ugly.

Wdyt @jstarry?

@jstarry
Copy link
Contributor

jstarry commented Sep 7, 2022

The wrapper looks ok I think but I'm worried that approach leads to too many struct permutations if in the future we want to selectively enable / disable certain fields. It would be nice if we had more granular control over what gets serialized. What do you think about replacing some usages of Option with a new enum which has variants for skipping deserialization, returning null, and returning the value?

@CriesofCarrots
Copy link
Contributor Author

What do you think about replacing some usages of Option with a new enum which has variants for skipping deserialization, returning null, and returning the value?

Oh hmm, adding a wrapper enum and removing the Option is an interesting idea. I'll try that out and if it seems feasible, push as a separate PR to rebase this one on, so we can see what it looks like in isolation.

@willhickey
Copy link
Contributor

Updated labels to v1.13 & v1.14 which are effectively the new v1.10 and v1.11 See discussion on Discord in #releng and #proj-quic-tpu for more context.
https://discord.com/channels/428295358100013066/910937142182682656/1019051275318476881

@CriesofCarrots
Copy link
Contributor Author

Updated, needs rebase on #27676

@CriesofCarrots CriesofCarrots merged commit 973a5fb into solana-labs:master Sep 15, 2022
mergify bot pushed a commit that referenced this pull request Sep 15, 2022
* Add new transaction details level

* Dedupe common code

* Update docs

* Respect showRewards parameter in tx meta

(cherry picked from commit 973a5fb)

# Conflicts:
#	docs/src/developing/clients/jsonrpc-api.md
mergify bot pushed a commit that referenced this pull request Sep 15, 2022
* Add new transaction details level

* Dedupe common code

* Update docs

* Respect showRewards parameter in tx meta

(cherry picked from commit 973a5fb)
CriesofCarrots pushed a commit that referenced this pull request Sep 15, 2022
* Add new transaction details level

* Dedupe common code

* Update docs

* Respect showRewards parameter in tx meta

(cherry picked from commit 973a5fb)
CriesofCarrots pushed a commit to CriesofCarrots/solana that referenced this pull request Sep 15, 2022
* Add new transaction details level

* Dedupe common code

* Update docs

* Respect showRewards parameter in tx meta

(cherry picked from commit 973a5fb)
mergify bot added a commit that referenced this pull request Sep 15, 2022
* Add new TransactionDetails level (#27601)

* Add new transaction details level

* Dedupe common code

* Update docs

* Respect showRewards parameter in tx meta

(cherry picked from commit 973a5fb)

* Fix doc conflict

Co-authored-by: Tyera Eulberg <tyera@solana.com>
mergify bot added a commit that referenced this pull request Sep 15, 2022
Add new TransactionDetails level (#27601)

* Add new transaction details level

* Dedupe common code

* Update docs

* Respect showRewards parameter in tx meta

(cherry picked from commit 973a5fb)

Co-authored-by: Tyera Eulberg <tyera@solana.com>
CriesofCarrots pushed a commit that referenced this pull request Sep 15, 2022
* Add new TransactionDetails level (#27601)

* Add new transaction details level

* Dedupe common code

* Update docs

* Respect showRewards parameter in tx meta

(cherry picked from commit 973a5fb)

* Fix doc conflict
@steveluscher
Copy link
Contributor

Toss me a note (eg. #28999) whenever you see this happening so that I can update the JavaScript client API.

In the near future we're going to make this sort of thing impossible to miss by codegenerating the JS types from the Rust implementation, but until then I could use the pings! <3

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 this pull request may close these issues.

4 participants