database.md

September 28, 2021 ยท View on GitHub

Index Schema

The DPS uses BadgerDB to store datasets of state changes and block information to build all the indexes required for random protocol and execution state access.

First Height

The value under this key keeps track of the first finalized block.

Length (bytes)1
Typebyte
DescriptionIndex type prefix
Example Value1

The value stored (only once) is the height of the first indexed block.

Last Height

The value under this key keeps track of the last finalized block.

Length (bytes)1
Typebyte
DescriptionIndex type prefix
Example Value2

The value stored (updated each indexed block) is the height of the last indexed block.

Header Index

In order to provide an efficient implementation of the Rosetta API, this index maps block heights to block headers. The header contains the metadata for a block as well as a hash representing the combined payload of the entire block.

Length (bytes)18
Typeuintuint64
DescriptionIndex type prefixBlock Height
Example Value3425

The value stored at that key is the height of the referenced state commitment's block.

Commit Index

In this index, keys map the block height to the state commitment hash.

Length (bytes)18
Typebyteuint64
DescriptionIndex type prefixBlock Height
Example Value4425

The value stored at that key is the state commitment of the referenced block height.

Events Index

The events index indexes events grouped by block height and transaction type. The block height is first in the index so that we can look through all events at a given height regardless of type using a key prefix.

Length (bytes)1864
Typeuintuint64hex string
DescriptionIndex type prefixBlock HeightTransaction Type (xxHashed)
Example Value542545D66Q565F5DEDB[...]

The value stored at the key is the a compressed slice of all events at the given height and given type. It is compressed using CBOR compression.

Path Deltas Index

This index maps a block ID to all the paths that are changed within its state updates.

Length (bytes)1pathfinder.PathByteSize8
Typeuintstringuint64
DescriptionIndex type prefixRegister pathBlock Height
Example Value6/0//1//2/uuid425

The value stored at that key is the compressed payload of the payload at the given height and given path. It is compressed using CBOR compression.

Block Height Index

In this index, keys map the block IDs to their height.

Length (bytes)164
Typebyteflow.Identifier
DescriptionIndex type prefixBlock ID
Example Value745D66Q565F5DEDB[...]

The value stored at that key is the block height of the referenced block ID.

Transaction Records

In this record, transactions are mapped by their IDs.

Length (bytes)164
Typebyteflow.Identifier
DescriptionIndex type prefixTransaction ID
Example Value845D66Q565F5DEDB[...]

The value stored at that key is the CBOR-encoded flow.TransactionBody with the referenced ID.

Block Transaction Index

In this index, block IDs are mapped to the IDs of the transactions within their block.

Length (bytes)164
Typebyteflow.Identifier
DescriptionIndex type prefixBlock ID
Example Value945D66Q565F5DEDB[...]

The value stored at that key is the CBOR-encoded slice of flow.Identifier for the transactions within the referenced block.

Collection Index

In this record, collections are mapped by their IDs.

Length (bytes)164
Typebyteflow.Identifier
DescriptionIndex type prefixCollection ID
Example Value1045D66Q565F5DEDB[...]

The value stored at that key is the CBOR-encoded flow.LightCollection with the referenced ID.

Collection Guarantee Index

In this record, collections guarantees are mapped by their collection IDs.

Length (bytes)164
Typebyteflow.Identifier
DescriptionIndex type prefixCollection ID
Example Value1045D66Q565F5DEDB[...]

The value stored at that key is the CBOR-encoded flow.CollectionGuarantee with the referenced ID.

Block Collection Index

In this index, block IDs are mapped to the IDs of the collections within that block.

Length (bytes)164
Typebyteflow.Identifier
DescriptionIndex type prefixBlock ID
Example Value1145D66Q565F5DEDB[...]

The value stored at that key is the CBOR-encoded slice of flow.Identifier for the collections within the referenced block.

Transaction Result Index

In this index, transaction IDs are mapped to their results.

Length (bytes)164
Typebyteflow.Identifier
DescriptionIndex type prefixTransaction ID
Example Value1245D66Q565F5DEDB[...]

The value stored at that key is the CBOR-encoded flow.TransactionResult for the referenced transaction.

Seals Index

In this index, seals are mapped by their IDs.

Length (bytes)164
Typebyteflow.Identifier
DescriptionIndex type prefixSeal ID
Example Value1445D66Q565F5DEDB[...]

The value stored at that key is the CBOR-encoded flow.Seal with the referenced ID.

Block Seals Index

In this index, heights are mapped to the IDs of the seals at that height.

Length (bytes)18
Typebyteuint64
DescriptionIndex type prefixBlock Height
Example Value15425

Transaction Height Index

In this index, keys map the transaction IDs to their height.

Length (bytes)164
Typebyteflow.Identifier
DescriptionIndex type prefixTransaction ID
Example Value1645D66Q565F5DEDB[...]

The value stored at that key is the block height of the referenced transaction ID.