Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

GetHashFn return two different hash values for one same block #647

Closed
KamiD opened this issue Dec 10, 2020 · 1 comment
Closed

GetHashFn return two different hash values for one same block #647

KamiD opened this issue Dec 10, 2020 · 1 comment

Comments

@KamiD
Copy link

KamiD commented Dec 10, 2020

System info: [Include Ethermint commit, operating system name, and other relevant details]
commit : 6e1c166

Steps to reproduce:

  1. [First Step]
    Calling GetHashFn(100) when current block height is 100
  2. [Second Step]
    Calling GetHashFn(100) when current block height is 101
  3. [result]
    There has two different hash value returned

Root cause:
after PR #538 merged, the hash of (height -> hash mapping) has changed from types.HashFromContext to req.Header.LastBlockId.GetHash()
But the code of GetHashFn was still using types.HashFromContext when getting hash for current block height:

func GetHashFn(ctx sdk.Context, csdb *CommitStateDB) vm.GetHashFunc {
	return func(height uint64) common.Hash {
		switch {
		case ctx.BlockHeight() == int64(height):
			// Case 1: The requested height matches the one from the context so we can retrieve the header
			// hash directly from the context.
			return HashFromContext(ctx)

		case ctx.BlockHeight() > int64(height):
			// Case 2: if the chain is not the current height we need to retrieve the hash from the store for the
			// current chain epoch. This only applies if the current height is greater than the requested height.
			return csdb.WithContext(ctx).GetHeightHash(height)

		default:
			// Case 3: heights greater than the current one returns an empty hash.
			return common.Hash{}
		}
	}
}

Expected behavior: [What you expected to happen]

Actual behavior: [What actually happened]

Additional info: [Include gist of relevant config, logs, etc.]

@KamiD
Copy link
Author

KamiD commented Dec 10, 2020

result of HashFromContext is same as req.Header.LastBlockId.GetHash(), closed

@KamiD KamiD closed this as completed Dec 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant