Skip to content

Commit 1d21368

Browse files
Jason Yellickguoger
authored andcommitted
FAB-16353 Don't waste memory in computing txid
The compute txid concatenates two byte slices and then computes the hash. The duplication of memory can be avoided by simply building the hash iteratively. This CR makes this small optimization. Change-Id: Ibcd6d80e814099212b381b78432e1e4988ed6d41 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent ef043e7 commit 1d21368

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

protoutil/proputils.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,10 @@ func createProposalFromCDS(chainID string, msg proto.Message, creator []byte, pr
366366
func ComputeTxID(nonce, creator []byte) string {
367367
// TODO: Get the Hash function to be used from
368368
// channel configuration
369-
digest := sha256.Sum256(append(nonce, creator...))
370-
return hex.EncodeToString(digest[:])
369+
hasher := sha256.New()
370+
hasher.Write(nonce)
371+
hasher.Write(creator)
372+
return hex.EncodeToString(hasher.Sum(nil))
371373
}
372374

373375
// CheckTxID checks that txid is equal to the Hash computed

0 commit comments

Comments
 (0)