Skip to content

[Persistence] Change the state root hash computation mechanism #834

@h5law

Description

@h5law

Objective

The way the root hash is currently computed is as follows:

stateHash := sha256.Sum256(appTreeHash + transactionsTreeHash + ... + flagsTreeHash)

This requires the order of the sub tree hashes to be known in order to calculate the state hash, and therefore to prove the inclusion of a specific tree in the state hash calculation this order must be known throughout the codebase.

This should instead be as follows:

  1. Create a rootTree object in the TreeStore module
  2. Fill this tree with the following key-value pairings
    • "app": appTree.Root()
    • "transactions": transactionsTree.Root()
    • ...
  3. Calculate the overall state hash by rootTree.Root()

This allows for the computation of the state hash in a deterministic manner as the SMT is not order dependent in its updates, thus removing the need to know the tree orders as they are no longer needed. It also allows for the generation of proofs determining whether a state tree hash was included in the root hash - this will be needed for the IBC module's light clients.

Origin Document

Screenshot 2023-06-16 at 18 49 08 Screenshot 2023-06-16 at 18 49 41

Goals

  • Create a rootTree in the TreeStore
  • Change the logic for state hash computation to insert the different sub trees hashes into the rootTree and generate the root this way
  • Update the pokt-network/pocket-network-protocol documentation to reflect this change

Deliverable

  • Update state hash calculation to be done via the new rootTree SMT
  • Update tests to use the new hashes
  • Update documentation

Non-goals / Non-deliverables

  • Change any other logic in the TreeStore module

General issue deliverables

  • Update the appropriate CHANGELOG(s)
  • Update any relevant local/global README(s)
  • Update relevant source code tree explanations
  • Add or update any relevant or supporting mermaid diagrams

Testing Methodology

  • Task specific tests or benchmarks: make ...
  • New tests or benchmarks: make ...
  • All tests: make test_all
  • LocalNet: verify a LocalNet is still functioning correctly by following the instructions at docs/development/README.md
  • k8s LocalNet: verify a k8s LocalNet is still functioning correctly by following the instructions here

Creator: @h5law
Co-Owners: @dylanlott

Metadata

Metadata

Assignees

Labels

persistencePersistence specific changes

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions