Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tc for working hash #83

Merged
merged 4 commits into from
Jul 29, 2024
Merged

add tc for working hash #83

merged 4 commits into from
Jul 29, 2024

Conversation

zsystm
Copy link

@zsystm zsystm commented Jul 29, 2024

Description

  • Before IAVL v1.1.4, calculating working hash at Init Genesis phase was in-correct. (for detail: debug notes)
    • expected: calculate working hash with initial height of Genesis.
    • real(bug): calculate working hash with zero.
  • Added test case for checking calculating working hash at Init Genesis phase is correct.
    • Initially, I attempted to write test code for the following scenario, but encountered some trial and error and realized it would take more time. Therefore, I decided to hardcode the values (check below figure) obtained by running the node with a fixed genesis which has initial height 4 to perform the test.
      1. Create an app with LevelDB.
      2. Proceed through some heights to make the initialHeight of the genesis greater than 0.
      3. Calculate and record the working hash of each module just before exporting.
      4. Export the genesis.
      5. Import the genesis.
      6. Calculate the working hash of each module.
      7. Compare the values with those calculated just before exporting.

The values on the left side of the image are the working hashes of each module obtained when using the buggy version of IAVL, while the ones on the right are the correctly calculated working hashes after the patch.

image


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • included the necessary unit and integration tests
  • reviewed "Files changed" and left comments if necessary

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@zsystm zsystm self-assigned this Jul 29, 2024
@zsystm zsystm requested review from dongsam, dudong2 and poorphd July 29, 2024 07:48
@zsystm zsystm marked this pull request as ready for review July 29, 2024 07:51
}

for _, key := range storeKeys {
if key != nil && matchAny(key.Name()) {
Copy link

Choose a reason for hiding this comment

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

Suggested change
if key != nil && matchAny(key.Name()) {
if matchAny(key.Name()) {

key is not pointer, so i think you no need to nil check

Copy link
Author

@zsystm zsystm Jul 29, 2024

Choose a reason for hiding this comment

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

@dudong2
key can be nil, it is declared as interface. I ran the following code and the result was 0x19.

	counter := 0
	for _, key := range storeKeys {
		if key == nil {
			counter++
		}
		if key != nil && matchAny(key.Name()) {
			kvstore := app.CommitMultiStore().GetCommitKVStore(key)
			require.Equal(t, storetypes.StoreTypeIAVL, kvstore.GetStoreType())
			iavlStore, ok := kvstore.(*iavl.Store)
			require.True(t, ok)
			workingHash := hex.EncodeToString(iavlStore.WorkingHash())
			require.NotEqual(t, workingHashWithZeroInitialHeight[key.Name()], workingHash)
			require.Equal(t, workingHashWithCorrectInitialHeight[key.Name()], workingHash)
		}
	}
	fmt.Println(counter)

Copy link

@dudong2 dudong2 left a comment

Choose a reason for hiding this comment

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

LGTM

@zsystm zsystm merged commit 3e05f76 into v8/develop Jul 29, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants