From 8ed097db747de77621a69e4b4a1e7fe8b718ec5c Mon Sep 17 00:00:00 2001 From: James Bayly Date: Mon, 10 Jun 2024 14:57:01 +0800 Subject: [PATCH] POI --- docs/.vuepress/sidebar.ts | 1 + .../introduction/proof-of-index.md | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 docs/subquery_network/introduction/proof-of-index.md diff --git a/docs/.vuepress/sidebar.ts b/docs/.vuepress/sidebar.ts index 00a3d1588be..2047449d7d9 100644 --- a/docs/.vuepress/sidebar.ts +++ b/docs/.vuepress/sidebar.ts @@ -571,6 +571,7 @@ export const getSidebar = (locale: string) => `${locale}/subquery_network/introduction/design-philosophy.md`, `${locale}/subquery_network/introduction/era.md`, `${locale}/subquery_network/introduction/payment-methods.md`, + `${locale}/subquery_network/introduction/proof-of-index.md`, ], }, { diff --git a/docs/subquery_network/introduction/proof-of-index.md b/docs/subquery_network/introduction/proof-of-index.md new file mode 100644 index 00000000000..2f4a1b9be26 --- /dev/null +++ b/docs/subquery_network/introduction/proof-of-index.md @@ -0,0 +1,25 @@ +# Proof of Index + +Proof of Index (PoI) refers to a mechanism where the SubQuery Data Indexing SDK records the actions of updating, writing, and deleting data in the database during the indexing process. For each processed block height, these actions and the processed data are hashed in a specific order, resulting in a deterministic unique hash value. This hash value serves as proof that the node has completed the full data indexing process. + +**Proof of Indexes are only used for data indexing, they do not apply to data nodes or RPC nodes. + +## Why do we need a Proof of Index? + +In the SubQuery network, multiple Node Operators provide indexed data for the same project. + +For a given project (identified by a fixed IPFS CID), we expect all Node Operators to ensure data quality by adhering to CIA principles (Consistency, Integrity, and Accuracy). When multiple Node Operators provide indexed data for the same project, maintaining the CIA of indexed data becomes a challenge. By comparing the PoI hash values at specified block heights, we can verify the trustworthiness of the data up to that height. + +If all Node Operator's PoI values match, we can consider that they have reached consensus and we can guarantee that their data is the same. + +## Is there a possibility of data tampering or deception in Proof of Index? + +Unless Node Operators maliciously modify the data in the database, PoI can greatly ensure the CIA of the data. When generating the PoI for block height `n`, the PoI for height `n-1` is also hashed, similar to the design of blockchain. If the data is incomplete or maliciously modified, we can detect forks in the PoI hash results. By repeatedly verifying the results of these forks, we can ultimately achieve data consensus. + +## How do we calculate the PoI? + +Users and Node Operators do not need to manually calculate PoI. PoI is automatically generated by SubQuery nodes during the indexing process based on the type of actions processed and the data. Users only need to be concerned with the result of PoI, such as the PoI `hash` and its `parentHash`, indexed block hash, operation hash. Logic/code can be found in [poi/PoiBlock.ts](https://github.com/subquery/subql/blob/main/packages/node-core/src/indexer/poi/PoiBlock.ts). + +PoI: The PoI is obtained by combining various block attributes (such as block ID, on-chain block hash, `operationHashRoot`, project ID, and parent PoI hash) and performing a hash operation on them. This ensures that the hash generated with the same data is unique. + +`operationHashRoot`: Records a hash of database mutations of indexed data generated from the Merkle tree. The `operationHashRoot` is generated by converting each store/database operation into a `Uint8Array` and adding it to the Merkle tree; the final `operationHashRoot` is generated from the tree. This keep the integrity and order of all operations.