mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-25 02:31:46 +00:00
Make txs and evidencelist use merkle.SimpleHashFromBytes to create hash (#2635)
This is a performance regression, but will also spare the types directory from knowing about RFC 6962, which is a more correct abstraction. For txs this performance hit will be fixed soon with #2603. For evidence, the performance impact is negligible due to it being capped at a small number.
This commit is contained in:
17
types/tx.go
17
types/tx.go
@ -31,18 +31,13 @@ type Txs []Tx
|
||||
|
||||
// Hash returns the simple Merkle root hash of the transactions.
|
||||
func (txs Txs) Hash() []byte {
|
||||
// Recursive impl.
|
||||
// Copied from tendermint/crypto/merkle to avoid allocations
|
||||
switch len(txs) {
|
||||
case 0:
|
||||
return nil
|
||||
case 1:
|
||||
return txs[0].Hash()
|
||||
default:
|
||||
left := Txs(txs[:(len(txs)+1)/2]).Hash()
|
||||
right := Txs(txs[(len(txs)+1)/2:]).Hash()
|
||||
return merkle.SimpleHashFromTwoHashes(left, right)
|
||||
// These allocations will be removed once Txs is switched to [][]byte,
|
||||
// ref #2603. This is because golang does not allow type casting slices without unsafe
|
||||
txBzs := make([][]byte, len(txs))
|
||||
for i := 0; i < len(txs); i++ {
|
||||
txBzs[i] = txs[i]
|
||||
}
|
||||
return merkle.SimpleHashFromByteSlices(txBzs)
|
||||
}
|
||||
|
||||
// Index returns the index of this transaction in the list, or -1 if not found
|
||||
|
Reference in New Issue
Block a user