keymigrate: fix decoding of block-hash row keys (#8294)

This commit is contained in:
M. J. Fromberger
2022-04-09 07:20:08 -07:00
committed by GitHub
parent 26b5672a54
commit 322bb460dd
3 changed files with 8 additions and 3 deletions

View File

@@ -83,3 +83,4 @@ Special thanks to external contributors on this release:
- [light] \#7641 Light Client: fix querying against the latest height (@ashcherbakov)
- [cli] [#7837](https://github.com/tendermint/tendermint/pull/7837) fix app hash in state rollback. (@yihuang)
- [cli] \#8276 scmigrate: ensure target key is correctly renamed. (@creachadair)
- [cli] \#8294 keymigrate: ensure block hash keys are correctly translated. (@creachadair)

View File

@@ -138,12 +138,16 @@ func migrateKey(key keyID) (keyID, error) {
return orderedcode.Append(nil, int64(3), int64(val))
case bytes.HasPrefix(key, keyID("BH:")):
val, err := strconv.Atoi(string(key[3:]))
hash := string(key[3:])
if len(hash)%2 == 1 {
hash = "0" + hash
}
val, err := hex.DecodeString(hash)
if err != nil {
return nil, err
}
return orderedcode.Append(nil, int64(4), int64(val))
return orderedcode.Append(nil, int64(4), string(val))
case bytes.HasPrefix(key, keyID("validatorsKey:")):
val, err := strconv.Atoi(string(key[14:]))
if err != nil {

View File

@@ -27,7 +27,7 @@ func getLegacyPrefixKeys(val int) map[string][]byte {
"BlockPartTwo": []byte(fmt.Sprintf("P:%d:%d", val+2, val+val)),
"BlockCommit": []byte(fmt.Sprintf("C:%d", val)),
"SeenCommit": []byte(fmt.Sprintf("SC:%d", val)),
"BlockHeight": []byte(fmt.Sprintf("BH:%d", val)),
"BlockHeight": []byte(fmt.Sprintf("BH:%x", val)),
"Validators": []byte(fmt.Sprintf("validatorsKey:%d", val)),
"ConsensusParams": []byte(fmt.Sprintf("consensusParamsKey:%d", val)),
"ABCIResponse": []byte(fmt.Sprintf("abciResponsesKey:%d", val)),