Skip to content

[Persistence] First Implementation of the StateHash (#284)#285

Merged
Olshansk merged 275 commits intomainfrom
issues/284/statehash_impl
Nov 30, 2022
Merged

[Persistence] First Implementation of the StateHash (#284)#285
Olshansk merged 275 commits intomainfrom
issues/284/statehash_impl

Conversation

@Olshansk
Copy link
Collaborator

@Olshansk Olshansk commented Oct 5, 2022

Description

The first implementation of the

Issue

Fixes #284 with follow up work in #361.

Type of change

Please mark the relevant option(s):

  • New feature, functionality or library
  • Bug fix
  • Code health or cleanup
  • Major breaking change
  • Documentation
  • Other

List of changes

Persistence - Core Changes for SMT

  • Introduced & defined for block_persistence.proto
    • A persistence specific protobuf for the Block stored in the BlockStore
  • On Commit, prepare and store a persistence block in the KV Store, SQL Store
  • Replace IndexTransactions (plural) to IndexTransaction (singular)
  • Maintaining a list of StateTrees using Celestia’s SMT and badger as the KV store to compute the state hash
  • Implemented ComputeStateHash to update the global state based on:
    • Validators
    • Applications
    • Servicers
    • Fisherman
    • Accounts
    • Pools
    • Transactions
    • Added a placeholder for params and flags
  • Added a benchmarking and a determinism test suite to validate this

Persistence - General module changes

  • Implemented GetAccountsUpdated, GetPoolsUpdated and GetActorsUpdated functions
  • Removed GetPrevAppHash and indexTransactions functions
  • Removed blockProtoBytes and txResults from the local state and added quorumCert
  • Consolidate all resetContext related operations into a single function
  • Implemented ReleaseWriteContext
  • Implemented ability to ClearAllState and ResetToGenesis for debugging & testing purposes
  • Added unit tests for all of the supporting SQL functions implemented
  • Some improvements in unit test preparation & cleanup (limited to this PR's functionality)

Persistence - KVStore changes

  • Renamed Put to Set
  • Embedded smt.MapStore in the interface containing Get, Set and Delete
  • Implemented Delete
  • Modified GetAll to return both keys and values
  • Turned off badger logging options since it’s noisy

Persistence - Module Interface changes

  • Removed GetPrevHash and just using GetBlockHash instead
  • Removed blockProtoBz from SetProposalBlock interface
  • Removed GetLatestBlockTxs and SetLatestTxResults in exchange for IndexTransaction
  • Removed SetTxResults
  • Renamed UpdateAppHash to ComputeStateHash
  • Removed some getters related to the proposal block (GetBlockTxs, GetBlockHash, etc…)

Consensus

  • Propagate highPrepareQC if available to the block being created
  • Remove blockProtoBytes from propagation in SetProposalBlock
  • Guarantee that writeContext is released when refreshing the utilityContext
  • Use GetBlockHash(height) instead of GetPrevAppHash to be more explicit
  • Use the real quorumCert when preparing a new block

Configs

  • Updated the test generator to produce deterministic keys
  • Added trees_store_dir to persistence configs
  • Updated LocalNet configs to have an empty tx_indexer_path and trees_store_dir

Makefile changes

  • Added db_cli_node
  • Added db_show_schemas
  • Added test_persistence_state_hash
  • Added benchmark_persistence_state_hash

Debug

  • ResetToGenesis - Added the ability to reset the state to genesis
  • ClearState - Added the ability to clear the state completely (height 0 without genesis data)

Testing

New:

Existing:

  • make develop_test
  • LocalNet w/ all of the steps outlined in the README

Required Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have tested my changes using the available tooling
  • I have updated the corresponding CHANGELOG

If Applicable Checklist

  • I have updated the corresponding README(s); local and/or global
  • I have added tests that prove my fix is effective or that my feature works
  • I have added, or updated, mermaid.js diagrams in the corresponding README(s)
  • I have added, or updated, documentation and mermaid.js diagrams in shared/docs/* if I updated shared/*README(s)

@Olshansk Olshansk requested a review from okdas November 30, 2022 03:11
@Olshansk
Copy link
Collaborator Author

@deblasis Tests are passing! #285

tl;dr Loading state from disk (i.e. when we don't load genesis) was an issue in a remote environment. The shouldHydrateGenesisDb function is something we need to revisit, but all I did was make sure to clear the SQL DB if we need to load the genesis state.

Copy link
Contributor

@deblasis deblasis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, solid work

Anything else, let's iterate on it.

I'd still like @okdas 👀 before merging

@andrewnguyen22 andrewnguyen22 removed their assignment Nov 30, 2022
@andrewnguyen22 andrewnguyen22 removed their request for review November 30, 2022 18:18
Copy link
Contributor

@okdas okdas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UPD: welp, should've taken more time looking.

Copy link
Contributor

@okdas okdas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 sweet green them test results

@Olshansk Olshansk merged commit 9a2f643 into main Nov 30, 2022
@Olshansk Olshansk deleted the issues/284/statehash_impl branch November 30, 2022 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core infrastructure - protocol related persistence Persistence specific changes utility Utility specific changes

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Persistence] First Implementation of the StateHash

6 participants