How to Use getBlockProduction
Learn getBlockProduction use cases, code examples, request parameters, response structure, and tips.
The getBlockProduction
RPC method provides information about block production in the current epoch or a specified slot range. It can be used to retrieve data for all validators or for a specific validator identity. This is valuable for monitoring validator performance and understanding block production patterns on the network.
Common Use Cases
- Monitoring Validator Performance: Track the number of blocks produced and leader slots for a specific validator.
- Analyzing Epoch Performance: Get an overview of block production across all validators in the current or a past epoch.
- Identifying Missed Slots: See if validators are missing their assigned leader slots.
- Network Health Checks: Gather data on overall block production efficiency.
Request Parameters
The getBlockProduction
method accepts an optional configuration object with the following parameters:
commitment
(string, optional): Specifies the commitment level to use for the query. If omitted, the default commitment of the node is used.range
(object, optional): Defines a slot range to query.firstSlot
(u64): The first slot to fetch block production information for (inclusive).lastSlot
(u64, optional): The last slot to fetch block production information for (inclusive). If omitted, the current epoch’s block production up to the current slot will be returned.
identity
(string, optional): A base58-encoded public key of a validator identity. If provided, the response will only include block production information for this specific validator. If omitted, information for all validators in the specified range (or current epoch) is returned.
Note: At least one of identity
or range.firstSlot
must be provided. If identity
is not provided, the range
parameter is required.
Response Structure
The result
field of the JSON-RPC response will be an object containing:
context
(object):slot
(u64): The slot at which the information was retrieved.
value
(object):byIdentity
(object): An object where keys are validator identity strings (base58-encoded public keys), and values are objects containing:leaderSlots
(u64): The number of leader slots assigned to this validator in the queried range/epoch.blocksProduced
(u64): The number of blocks produced by this validator in the queried range/epoch.
range
(object):firstSlot
(u64): The first slot of the queried range.lastSlot
(u64): The last slot of the queried range.
Developer Tips
- Understand Epoch Boundaries: When querying by
identity
without arange
, the data returned is for the current epoch up to the latest processed slot by the node. If you need data for a full past epoch for a specific validator, you’ll need to determine thefirstSlot
andlastSlot
for that epoch. - Node Data Availability: The range of historical block production data can vary between RPC nodes. Very old slot ranges might not be available on all nodes.
- Performance Monitoring:
getBlockProduction
is key for building dashboards or alerts related to validator uptime and block production success rates. - Combining with
getLeaderSchedule
: For deeper analysis, you can correlategetBlockProduction
data with the output ofgetLeaderSchedule
to see which specific leader slots were made or missed. - Identity vs. All Validators: Querying without an
identity
can return a large amount of data, especially if norange
or a widerange
is specified. Be mindful of response sizes and processing requirements.
Examples
1. Get Block Production for the Current Epoch (All Validators)
This example fetches block production data for all validators in the current epoch.
2. Get Block Production for a Specific Validator in the Current Epoch
This example fetches block production for a specific validator identity in the current epoch.
3. Get Block Production for a Specific Slot Range and Validator
This example fetches block production data for a specific validator within a defined slot range.
This guide should give you a solid understanding of how to use the getBlockProduction
RPC method to analyze block production on Solana.