Skip to content

Commit

Permalink
use empty hash in place of nil
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle committed Jun 28, 2024
1 parent 5a36506 commit 3f3f09c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
8 changes: 1 addition & 7 deletions core/header/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ func (i *Info) Bytes() ([]byte, error) {
binary.LittleEndian.PutUint64(heightBytes, uint64(i.Height))
buf = append(buf, heightBytes...)

if len(i.Hash) == 0 {
i.Hash = make([]byte, hashSize)
}
// Encode Hash
if len(i.Hash) != hashSize {
return nil, errors.New("invalid hash size")
Expand All @@ -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...)
Expand Down
6 changes: 5 additions & 1 deletion server/v2/cometbft/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cometbft

import (
"context"
"crypto/sha256"
"errors"
"fmt"
"sync/atomic"
Expand Down Expand Up @@ -231,10 +232,13 @@ func (c *Consensus[T]) InitChain(ctx context.Context, req *abciproto.InitChainRe
return nil, err
}

// populate hash with empty byte slice instead of nil
bz := sha256.Sum256([]byte(""))

br := &coreappmgr.BlockRequest[T]{
Height: uint64(req.InitialHeight - 1),
Time: req.Time,
Hash: nil,
Hash: bz[:],
AppHash: ci.Hash,
ChainId: req.ChainId,
ConsensusMessages: consMessages,
Expand Down

0 comments on commit 3f3f09c

Please sign in to comment.