shentufoundation/shentu

Failure to export genesis file

SphereDonout opened this issue · 1 comments

Summary of the Bug

The command export --for-zero-height is used to export the genesis file, but it fails due to an invalid validator address retrieval. The root cause lies in the incorrect validator address fetch via the addr := sdk.ValAddress(iter.Key()[1:]), which will lead to a panic error when this command is executed.

Note that the validator address is fetched via iter.Key()[1:], which excludes the ValidatorKey, but it still includes the prefix, the length of the address. This can be demonstrated in the function GetValidatorKey():

cosmos-sdk/x/staking/types/keys.go

// GetValidatorKey creates the key for the validator with the address
// VALUE: staking/Validator
func GetValidatorKey(operatorAddr sdk.ValAddress) []byte {
	return append(ValidatorsKey, address.MustLengthPrefix(operatorAddr)...)
}

Therefore, the iter.Key()[1:] returns the length of the address + address, and it cannot be correctly converted to the validator address via the function sdk.ValAddress().

Steps to Reproduce

Steps to reproduce the behavior:

  1. Start the shentu chain
  2. Stop the shentu chain
  3. Executes the command shentud export --for-zero-height > test_genesis.json
  4. See the screenshot of the error

Expected behavior

The genesis file test_genesis.json should be created.

Screenshots

Screenshot 2023-08-06 at 9 26 09 PM

Environment (please complete the following information)

  • Chain Version: 7ef6233
  • Golang Version: go1.19.4 darwin/amd64
  • OS: macOS

Additional Context

Add any other context about the problem here.


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged