Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix minor regression in txnMerkleToRaw #3608

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions data/bookkeeping/txn_merkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type txnMerkleElem struct {
stib transactions.SignedTxnInBlock
}

func txnMerkleToRaw(txid []byte, stib []byte) (buf []byte) {
func txnMerkleToRaw(txid [crypto.DigestSize]byte, stib [crypto.DigestSize]byte) (buf []byte) {
buf = make([]byte, 2*crypto.DigestSize)
copy(buf[:], txid[:])
copy(buf[crypto.DigestSize:], stib[:])
Expand All @@ -84,7 +84,7 @@ func (tme *txnMerkleElem) ToBeHashed() (protocol.HashID, []byte) {
txid := tme.txn.ID()
stib := tme.stib.Hash()

return protocol.TxnMerkleLeaf, txnMerkleToRaw(txid[:], stib[:])
return protocol.TxnMerkleLeaf, txnMerkleToRaw(txid, stib)
}

// Hash implements an optimized version of crypto.HashObj(tme).
Expand All @@ -99,6 +99,6 @@ func (tme *txnMerkleElem) HashRepresentation() []byte {
var buf [len(protocol.TxnMerkleLeaf) + 2*crypto.DigestSize]byte
s := buf[:0]
s = append(s, protocol.TxnMerkleLeaf...)
s = append(s, txnMerkleToRaw(txid[:], stib[:])...)
s = append(s, txnMerkleToRaw(txid, stib)...)
return s
}
14 changes: 7 additions & 7 deletions data/bookkeeping/txn_merkle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,23 +143,23 @@ func BenchmarkTxnRoots(b *testing.B) {
_ = r
}

func txnMerkleToRawAppend(txid [crypto.DigestSize]byte, stib [crypto.DigestSize]byte) []byte {
buf := make([]byte, 0, 2*crypto.DigestSize)
buf = append(buf, txid[:]...)
return append(buf, stib[:]...)
}
func BenchmarkTxnMerkleToRaw(b *testing.B) {
digest1 := crypto.Hash([]byte{1, 2, 3})
digest2 := crypto.Hash([]byte{4, 5, 6})
txnMerkleToRawAppend := func(txid []byte, stib []byte) []byte {
buf := make([]byte, 0, 2*crypto.DigestSize)
buf = append(buf, txid...)
return append(buf, stib...)
}

b.Run("copy", func(b *testing.B) {
for i := 0; i < b.N; i++ {
txnMerkleToRaw(digest1[:], digest2[:])
txnMerkleToRaw(digest1, digest2)
}
})
b.Run("append", func(b *testing.B) {
for i := 0; i < b.N; i++ {
txnMerkleToRawAppend(digest1[:], digest2[:])
txnMerkleToRawAppend(digest1, digest2)
}
})
}
9 changes: 5 additions & 4 deletions test/e2e-go/features/transactions/proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ import (

// TxnMerkleElemRaw this struct helps creates a hashable struct from the bytes
type TxnMerkleElemRaw struct {
Txn []byte // txn id
Stib []byte // hash value of transactions.SignedTxnInBlock
Txn crypto.Digest // txn id
Stib crypto.Digest // hash value of transactions.SignedTxnInBlock
}

func txnMerkleToRaw(txid []byte, stib []byte) (buf []byte) {
func txnMerkleToRaw(txid [crypto.DigestSize]byte, stib [crypto.DigestSize]byte) (buf []byte) {
buf = make([]byte, 2*crypto.DigestSize)
copy(buf[:], txid[:])
copy(buf[crypto.DigestSize:], stib[:])
Expand Down Expand Up @@ -121,7 +121,8 @@ func TestTxnMerkleProof(t *testing.T) {
blk, err := client.BookkeepingBlock(confirmedTx.ConfirmedRound)
a.NoError(err)

element := TxnMerkleElemRaw{Txn: txid[:], Stib: proofresp.Stibhash}
element := TxnMerkleElemRaw{Txn: crypto.Digest(txid)}
copy(element.Stib[:], proofresp.Stibhash[:])

elems := make(map[uint64]crypto.Hashable)

Expand Down