-
Notifications
You must be signed in to change notification settings - Fork 910
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
refactor(experimental): Add getBlockProduction
API
#1263
refactor(experimental): Add getBlockProduction
API
#1263
Conversation
No dependency changes detected. Learn more about Socket for GitHub ↗︎ 👍 No dependency changes detected in pull request Pull request alert summary
|
ab6148f
to
007faa5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -6,6 +6,7 @@ export const SolanaJsonRpcErrorCode = { | |||
JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004, | |||
JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014, | |||
JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010, | |||
JSON_RPC_SERVER_ERROR_LAST_SLOT_TOO_LARGE: -32602, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That error code is actually a JSON-RPC reserved one that means ‘invalid params.’ https://www.jsonrpc.org/specification#error_object
.getBlockProduction({ | ||
range: { | ||
firstSlot: 0n, | ||
lastSlot: 2n ** 63n - 1n, // u64:MAX; safe bet it'll be too high. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason that this doesn't work is actually because the validator hasn't advanced to that slot yet. Apparently we code this as ‘invalid params (32602).’
Kind of sounds like we need an actual error code for this in the RPC, similar to JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've renamed the 32602 error to JSON_RPC_INVALID_PARAMS
for now, since that best matches the current behaviour. Would a github issue on the solana monorepo be the best place to track adding a custom error code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! Totally. That RPC method could do with throwing a more precise error.
packages/rpc-core/src/rpc-methods/__tests__/get-block-production-test.ts
Outdated
Show resolved
Hide resolved
packages/rpc-core/src/rpc-methods/__tests__/get-block-production-test.ts
Outdated
Show resolved
Hide resolved
packages/rpc-core/src/rpc-methods/__tests__/get-block-production-test.ts
Outdated
Show resolved
Hide resolved
2c5352c
to
0322ad5
Compare
Dang it, the goal with that return type for the const bp = await rpc
.getBlockProduction({
commitment,
identity: 'abc' as Base58EncodedAddress,
})
.send();
bp.value.byIdentity['def' as Base58EncodedAddress]; // SHOULD BE A TYPE ERROR …but that's not happening yet. Essentially the Think this is possible to type correctly? |
cc40bac
to
b01e07e
Compare
I think this should work with: getBlockProduction<TIdentity extends Base58EncodedAddress>(
config: Readonly<{
commitment?: Commitment;
identity: TIdentity;
range?: SlotRange;
}>
): GetBlockProductionApiResponseBase & GetBlockProductionApiResponseWithSingleIdentity<TIdentity>; My local environment has gone screwy so I need to fix that and test this a bit more locally, but I think this should be right! |
This has type errors now when you just supply |
- Add the `getBlockProduction` API + unit tests - Add jest-extended which provides some extra jest matchers ``` pnpm turbo test:unit:node test:unit:browser ```
b01e07e
to
5ccf373
Compare
Ah, thanks, fixed those up! On the second thing, it definitely should work, but also.. isn't. I don't know if some layer of indirection is throwing it here A more realistic playground using basically the same types here does work! I think it's probably worth parking for now, but it would be really nice to have that type safety! |
🎉 This PR is included in version 1.76.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Because there has been no activity on this PR for 14 days since it was merged, it has been automatically locked. Please open a new issue if it requires a follow up. |
Summary
getBlockProduction
API + unit testsTest Plan
Misc notes:
jest-extended
don't support BigInt yet (BigInt support for Number functions jest-community/jest-extended#591). Didn't affect my final tests here but worth being aware oflastSlot
too high test. Grepping thesolana
codebase doesn't show the error I'm seeing and the code isn't in https://github.com/solana-labs/solana/blob/master/rpc-client-api/src/custom_error.rs. The promise rejects withRejected to value: [SolanaJsonRpcError: JSON-RPC 2.0 error (-32602): lastSlot, 9223372036854776000, is too large; max 0]