4 releases (2 breaking)
|0.3.0||Oct 25, 2023|
|0.2.0||Oct 1, 2023|
|0.1.1||Aug 9, 2023|
|0.1.0||Aug 1, 2023|
32 downloads per month
Substrate event indexer.
Development of this tool was funded by a grant from the Web3 Foundation.
Hybrid takes a unique, partially decentralized approach that improves two major problems with current open source Substrate block explorers: centralization and huge hosting requirements.
A fully centralized block explorer typically populates an SQL database with the entirety of an archive node and stores additional data to index everything. Operating such a database reliably requires huge system resources and expense.
When querying block information, or the chain state at any block height, the Hybrid dapp will use the Substrate Connect light client from within the browser. Alternatively, these queries can be made directly to an archive node via WSS.
For event search functionality, the Hybrid indexer efficiently indexes events in all blocks so they can be found with a simple WSS query. For example, to find all events connected with a specific
This architecture has three main advantages:
- state queries are fully decentralized - you don't have to trust an RPC provider not to lie to you
- 100% availability - the light client doesn't depend on any centralized service that may not always be available
- the Hybrid indexer has significantly lower system requirements - it doesn't need to store all chain history
Eventually, Hybrid will use this centralized / decentralized approach as the basis for an ink! contract explorer.
Because Substrate is a federated platform, it will be possible browse multiple chains from the Hybrid dapp.
The Hybrid indexer is written in Rust. It can be configured to connect to any Substrate chain.
Events that have identifying parameters will be indexed. For example the Transfer event in the Balances pallet is identifiable by the
AccountId of both
Hybrid has built-in indexing macros for the following Substrate pallets: System, Preimage, Indices, Balances, Transaction Payment, Staking, Session, Democracy, Collective, Elections Phragmen, Treasury, Vesting, Identity, Proxy, Multisig, Fast Unstake, Election Provider Multi-phase, Tips, Bounties, Child Bounties, Bags List, Nomination Pools.
Hybrid currently supports indexing of the following event parameters:
Additionally, all events are indexed by event variant. This means that, for example, a list of all balance transfers for all accounts can be obtained.
To index a block, first a query has to be made to determine the hash from the block number. Then a second query for the metadata version. Finally the block itself is downloaded. In order to ensure throughput is as high as possible, multiple blocks are indexed simultaneously to counteract the round-trip delay.
In the same manner that each Substrate chain is a separate Rust build that uses Substrate crates, each chain will need a separate Hybrid Indexer build that is configured to index the correct pallets.
When a chain is going to potentially perform a runtime upgrade, the Hybrid Indexer for the chain will need a new release with any updated events. If an instance of the indexer is not updated before the runtime upgrade occurs, it can be restarted with the new version at the correct block number.
WSS queries are handled via the highly scalable tokio_tungstenite Rust library.
Consumers will be able to subscribe for new events that match a query.
The database keys are constructed in such a way so that events can be found using iterators starting at a specific block number. For example, for for the AccountId keyspace:
Database entries are key-only. No value is stored. The blocknumber and event index are all that need to be returned for each event found. This reduces the size of the index database and increases decentralization. The frontend can query the chain in a decentralized manner to retrieve the event.