chore: set empty hash to hash of nothing (#20775)

This commit is contained in:
Marko
2024-07-02 14:15:44 +00:00
committed by GitHub
parent 1bc857c417
commit 4e6507462e
5 changed files with 67 additions and 60 deletions
+2 -8
View File
@@ -33,14 +33,11 @@ func (i *Info) Bytes() ([]byte, error) {
binary.LittleEndian.PutUint64(heightBytes, uint64(i.Height))
buf = append(buf, heightBytes...)
// TODO; permit empty hash OK for genesis block?
if len(i.Hash) == 0 {
i.Hash = make([]byte, hashSize)
}
// Encode Hash
if len(i.Hash) != hashSize {
return nil, errors.New("invalid hash size")
}
buf = append(buf, i.Hash...)
// Encode Time
@@ -48,11 +45,8 @@ func (i *Info) Bytes() ([]byte, error) {
binary.LittleEndian.PutUint64(timeBytes, uint64(i.Time.Unix()))
buf = append(buf, timeBytes...)
if len(i.AppHash) == 0 {
i.AppHash = make([]byte, hashSize)
}
// Encode AppHash
if len(i.Hash) != hashSize {
if len(i.AppHash) != hashSize {
return nil, errors.New("invalid hash size")
}
buf = append(buf, i.AppHash...)