Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection.getBlock return types are missing the blockHeight field #1969

Open
jeff-delonge opened this issue Dec 14, 2023 · 3 comments
Open
Labels
bug Something isn't working

Comments

@jeff-delonge
Copy link

jeff-delonge commented Dec 14, 2023

Overview

In 1.87.6, the return types of Connection.getBlock such as VersionedBlockResponse and BlockResponse omit the blockHeight field. If Connection.getBlock returns a non-null value, the returned object includes this field.

The types should be updated to include the blockHeight field.

Steps to reproduce

    const connection = new Connection("https://api.mainnet-beta.solana.com", "finalized");
    const latestBlockhashResult = await connection.getLatestBlockhashAndContext("finalized");
    const block = await connection.getBlock(latestBlockhashResult.context.slot, {
        commitment: "finalized",
        maxSupportedTransactionVersion: undefined,
        rewards: false,
        transactionDetails: "none",
    });
    console.log("latestBlockhashResult", latestBlockhashResult);
    console.log("block", block);

Description of bug

The above logs something like the following. Note that the block includes the blockHeight field.

latestBlockhashResult {
  context: { apiVersion: '1.16.18', slot: 235912008 },
  value: {
    blockhash: 'D7Qr3rwEbYKh9cYvV25wmXCcvzJqHxixnZs91tL1Rvsa',
    lastValidBlockHeight: 217323342
  }
}
block {
  blockHeight: 217323042,
  blockTime: 1702587441,
  blockhash: 'D7Qr3rwEbYKh9cYvV25wmXCcvzJqHxixnZs91tL1Rvsa',
  parentSlot: 235912007,
  previousBlockhash: '7vXphDU9znbs6SNBqiyPSEkvJtiZE5D5g55mxw5NKSZk',
  rewards: undefined
}

If instead I try to build the following code (note the const blockHeight = block?.blockHeight), TypeScript will complain because the blockHeight field is missing from the VersionedBlockResponse type in @solana/web3.js:

    const connection = new Connection("https://api.mainnet-beta.solana.com", "finalized");
    const latestBlockhashResult = await connection.getLatestBlockhashAndContext("finalized");
    const block = await connection.getBlock(latestBlockhashResult.context.slot, {
        commitment: "finalized",
        maxSupportedTransactionVersion: undefined,
        rewards: false,
        transactionDetails: "none",
    });
    const blockHeight = block?.blockHeight;
    console.log("latestBlockhashResult", latestBlockhashResult);
    console.log("block", block);

The type error is:

error TS2339: Property 'blockHeight' does not exist on type 'VersionedBlockResponse'.

37     const blockHeight = block?.blockHeight;
@jeff-delonge jeff-delonge added the bug Something isn't working label Dec 14, 2023
@steveluscher
Copy link
Collaborator

Thanks! In the meantime, you might be interested in using the new @solana/web3.js that gets this typespec right.

https://stackblitz.com/edit/typescript-gnvm4e?devToolsHeight=33&file=index.ts

More: https://github.com/solana-labs/solana-web3.js/blob/2ac1df6b886bcf335c35651445bd384222cae752/packages/library/README.md

@RaghavenderSingh
Copy link

Hey, I'm interested in working on this one

@buffalojoec
Copy link
Collaborator

Hey, I'm interested in working on this one

Please do! Note this is in the legacy library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants