Skip to content

Commit

Permalink
chore: make unused block hashes in testing header creation explicit (c…
Browse files Browse the repository at this point in the history
…osmos#5857)

* Make unused block hashes in testing header creation explicit

* lint

* nit: make unusedHash a private var

---------

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
Co-authored-by: DimitrisJim <d.f.hilliard@gmail.com>
  • Loading branch information
3 people authored Feb 20, 2024
1 parent d266170 commit 72e2b6b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 5 additions & 5 deletions testing/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ func (chain *TestChain) CurrentTMClientHeader() *ibctm.Header {
// be used to sign over the proposed header.
func CommitHeader(proposedHeader cmttypes.Header, valSet *cmttypes.ValidatorSet, signers map[string]cmttypes.PrivValidator) (*cmtproto.SignedHeader, error) {
hhash := proposedHeader.Hash()
blockID := MakeBlockID(hhash, 3, tmhash.Sum([]byte("part_set")))
blockID := MakeBlockID(hhash, 3, unusedHash)
voteSet := cmttypes.NewVoteSet(proposedHeader.ChainID, proposedHeader.Height, 1, cmtproto.PrecommitType, valSet)

// MakeExtCommit expects a signer array in the same order as the validator array.
Expand Down Expand Up @@ -512,13 +512,13 @@ func (chain *TestChain) CreateTMClientHeader(chainID string, blockHeight int64,
Time: timestamp,
LastBlockID: MakeBlockID(make([]byte, tmhash.Size), 10_000, make([]byte, tmhash.Size)),
LastCommitHash: chain.App.LastCommitID().Hash,
DataHash: tmhash.Sum([]byte("data_hash")),
DataHash: unusedHash,
ValidatorsHash: cmtValSet.Hash(),
NextValidatorsHash: nextVals.Hash(),
ConsensusHash: tmhash.Sum([]byte("consensus_hash")),
ConsensusHash: unusedHash,
AppHash: chain.ProposedHeader.AppHash,
LastResultsHash: tmhash.Sum([]byte("last_results_hash")),
EvidenceHash: tmhash.Sum([]byte("evidence_hash")),
LastResultsHash: unusedHash,
EvidenceHash: unusedHash,
ProposerAddress: cmtValSet.Proposer.Address, //nolint:staticcheck
}

Expand Down
4 changes: 4 additions & 0 deletions testing/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cometbft/cometbft/crypto/tmhash"

ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types"
Expand Down Expand Up @@ -67,4 +69,6 @@ var (
MockRecvCanaryCapabilityName = mock.MockRecvCanaryCapabilityName

prefix = commitmenttypes.NewMerklePrefix([]byte("ibc"))
// unusedHash is a placeholder hash used for testing.
unusedHash = tmhash.Sum([]byte{0x00})
)

0 comments on commit 72e2b6b

Please sign in to comment.