We’re excited to announce the completion of the archive RPC-V2 methods, which will be included in the upcoming Polkadot 2412 release. These new methods significantly enhance developers’ capabilities for accessing and analyzing the chain state.
What’s New?
Over the past few months, we’ve made the following advancements:
-
archive_unstable_storageDiff: This provides a detailed diff of storage changes between two blocks.
-
archive_storage: Converted from a method into a subscription, enabling more dynamic interactions.
We aim to stabilize the archive methods by January, offering developers sufficient time to explore, experiment, and provide feedback before the final release. Your input is crucial to refining these methods and ensuring they meet the needs of the Polkadot ecosystem.
Detailed Overview of New Features
archive_unstable_storageDiff
The archive_unstable_storageDiff
subscription delivers a comprehensive view of storage changes between two specified blocks. This is especially valuable for chain analysis tools like indexers, enabling developers to track state evolution over time.
let mut sub = api
.subscribe_unbounded(
"archive_unstable_storageDiff",
rpc_params![
// First block hash.
"hash": "0xdeadbeef",
// (1) We are only interested in obtaining the storage difference of keys
// starting with ":A" prefix.
//
// (2) The query returns the value of keys starting with ":A".
//
// (3) If you are interested in the hash, please use `"returnType": "hash"`.
//
// (4) For child trie queries, developers can specify the `childTrieKey`.
//
// (5) If you are interested in all the keys regardless of the prefix, you can provide an empty array.
//
// (6) Developers can provide more items to the query.
"items": [
{
"key": ":A",
"returnType": "value",
"childTrieKey": null,
}
],
// Previous block hash can be omitted to compare the current block with the previous one.
"previousHash": "0xdeadbeef1",
],
);
// The subscription returns a stream of storage changes between the two specified blocks with the following formats:
// The key prefixed with `0x:AA` was added to the storage.
{
"event": "storageDiff",
"key": "0x:AA",
"value": "0x...",
"type": "added"
}
// The key prefixed with `0x:AB` was removed from the storage.
{
"event": "storageDiff",
"key": "0x:AB",
"value": "0x...",
"type": "removed"
}
// The key prefixed with `0x:AC` was modified in the storage.
{
"event": "storageDiff",
"key": "0x:AC",
"value": "0x...",
"type": "modified"
}
// This event signals the completion of the storage diff process.
{
"event": "storageDiffDone",
}
archive_storage
The archive_storage
subscription provides a snapshot of the chain’s storage at a specified block, supporting a variety of use cases:
- Fetching a specific key’s value or hash
- Iterating over keys with a common prefix to fetch values or hashes
- Finding the closest descendant merkle value of a key
let mut sub = api
.subscribe_unbounded(
"archive_unstable_storage",
rpc_params![
// First block hash.
"hash": "0xdeadbeef",
"items": [
// Fetch the value of the key ":A".
{
"key": ":A",
"type": "value",
}
// Fetch the hash of the value of key ":A".
{
"key": ":A",
"type": "hash",
}
// Iterate all the keys starting with ":B" and fetch the value.
{
"key": ":B",
"type": "descendantsValues",
}
// Iterate all the keys starting with ":C" and fetch the hash of the value.
{
"key": ":C",
"type": "descendantsHashes",
}
// Find the closest descendant merkle value of the key ":D".
{
"key": ":D",
"type": "closestDescendantMerkleValue",
}
],
// Please note that `childTrieKey` can be used to query child trie keys.
"childTrieKey": null,
],
);
// The subscription will return a stream of events with the following formats:
// Key ":A" value at the specified block.
{
"event": "storage",
"key": "0x:A",
"value": "0x...",
}
// Key ":A" hash at the specified block.
{
"event": "storage",
"key": "0x:A",
"hash": "0x...",
}
// Key ":B" descendants values at the specified block.
{
"event": "storage",
"key": "0x:B",
"value": "0x...",
}
// Key ":C" descendants hashes at the specified block.
{
"event": "storage",
"key": "0x:C",
"hash": "0x...",
}
// Closest descendant merkle value of key ":D" at the specified block.
{
"event": "storage",
"key": "0x:D",
"closestDescendantMerkleValue": "0x...",
}
Additional Methods
For a comprehensive reference, please consult the specification for the following methods:
- archive_unstable_genesisHash: Retrieves the genesis hash of the chain.
- archive_unstable_body: Returns the block body of a specified block.
- archive_unstable_header: Fetches the block header of a specified block.
- archive_unstable_finalizedHeight: Reports the finalized chain height.
- archive_unstable_call: Executes a runtime API call at a specific block.