diff --git a/packages/rpc-core/src/rpc-methods/__tests__/get-block-production-test.ts b/packages/rpc-core/src/rpc-methods/__tests__/get-block-production-test.ts index 073a856ec115..533e37a83517 100644 --- a/packages/rpc-core/src/rpc-methods/__tests__/get-block-production-test.ts +++ b/packages/rpc-core/src/rpc-methods/__tests__/get-block-production-test.ts @@ -6,7 +6,7 @@ import { createSolanaRpcApi, SolanaRpcMethods } from '../../index'; import { Commitment } from '../common'; import { Base58EncodedAddress } from '@solana/keys'; -describe('getBalance', () => { +describe('getBlockProduction', () => { let rpc: Rpc; beforeEach(() => { fetchMock.resetMocks(); @@ -35,10 +35,8 @@ describe('getBalance', () => { it('has the latest context slot as the last slot', async () => { expect.assertions(1); - const blockProductionPromise = rpc.getBlockProduction({ commitment }).send(); - await expect(blockProductionPromise).resolves.toSatisfy( - rpcResponse => rpcResponse.context.slot === rpcResponse.value.range.lastSlot - ); + const blockProduction = await rpc.getBlockProduction({ commitment }).send(); + expect(blockProduction.value.range.lastSlot).toBe(blockProduction.context.slot); }); }); }); @@ -72,7 +70,7 @@ describe('getBalance', () => { }) .send(); await expect(blockProductionPromise).rejects.toMatchObject({ - code: -32602 satisfies (typeof SolanaJsonRpcErrorCode)['JSON_RPC_SERVER_ERROR_LAST_SLOT_TOO_LARGE'], + code: -32602 satisfies (typeof SolanaJsonRpcErrorCode)['JSON_RPC_INVALID_PARAMS'], message: expect.any(String), name: 'SolanaJsonRpcError', }); diff --git a/packages/rpc-core/src/rpc-methods/getBlockProduction.ts b/packages/rpc-core/src/rpc-methods/getBlockProduction.ts index 8216ff69d046..e76b94a326fc 100644 --- a/packages/rpc-core/src/rpc-methods/getBlockProduction.ts +++ b/packages/rpc-core/src/rpc-methods/getBlockProduction.ts @@ -1,30 +1,46 @@ import { Base58EncodedAddress } from '@solana/keys'; import { Commitment, RpcResponse, U64UnsafeBeyond2Pow53Minus1 } from './common'; -type NumberOfLeaderSlots = number; -type NumberOfBlocksProduced = number; +type NumberOfLeaderSlots = U64UnsafeBeyond2Pow53Minus1; +type NumberOfBlocksProduced = U64UnsafeBeyond2Pow53Minus1; -type Range = Readonly<{ +type SlotRange = Readonly<{ firstSlot: U64UnsafeBeyond2Pow53Minus1; lastSlot: U64UnsafeBeyond2Pow53Minus1; }>; -type GetBlockProductionApiResponse = RpcResponse<{ - byIdentity: Readonly<{ - [address: string]: [NumberOfLeaderSlots, NumberOfBlocksProduced]; +type GetBlockProductionApiConfigBase = Readonly<{ + commitment?: Commitment; + range?: SlotRange; +}>; + +type GetBlockProductionApiResponseBase = RpcResponse<{ + range: SlotRange; +}>; + +type GetBlockProductionApiResponseWithAllIdentities = Readonly<{ + value: Readonly<{ + byIdentity: Record; + }>; +}>; + +type GetBlockProductionApiResponseWithSingleIdentity = Readonly<{ + value: Readonly<{ + byIdentity: Readonly<{ [TAddress in TIdentity]?: [NumberOfLeaderSlots, NumberOfBlocksProduced] }>; }>; - range: Range; }>; export interface GetBlockProductionApi { /** * Returns recent block production information from the current or previous epoch. */ + getBlockProduction( + config: GetBlockProductionApiConfigBase & + Readonly<{ + identity: TIdentity; + }> + ): GetBlockProductionApiResponseBase & GetBlockProductionApiResponseWithSingleIdentity; getBlockProduction( - config?: Readonly<{ - commitment?: Commitment; - identity?: Base58EncodedAddress; - range?: Range; - }> - ): GetBlockProductionApiResponse; + config?: GetBlockProductionApiConfigBase + ): GetBlockProductionApiResponseBase & GetBlockProductionApiResponseWithAllIdentities; } diff --git a/packages/rpc-transport/src/json-rpc-errors.ts b/packages/rpc-transport/src/json-rpc-errors.ts index 9aff6cf70c23..1d5c57df9a71 100644 --- a/packages/rpc-transport/src/json-rpc-errors.ts +++ b/packages/rpc-transport/src/json-rpc-errors.ts @@ -1,12 +1,12 @@ // Keep in sync with https://github.com/solana-labs/solana/blob/master/rpc-client-api/src/custom_error.rs // Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/ export const SolanaJsonRpcErrorCode = { + JSON_RPC_INVALID_PARAMS: -32602, JSON_RPC_SCAN_ERROR: -32012, JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001, 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, JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009, JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016, JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,