From fcd17cea479fcb1cf6eb5c0541cc9585b97004f1 Mon Sep 17 00:00:00 2001 From: Connor Barr Date: Mon, 18 Nov 2024 13:49:18 +0000 Subject: [PATCH] fix: copy TxIndex TxBytes value (#150) * fix: copy TxIndex TxBytes value * chore: changelog --- CHANGELOG.md | 1 + state/txindex/kv/kv.go | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37cebbf8535..652941b92de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ This v0.38.12 branch was created at the [cf7836ad7b63bc1421deed23beb8630a3705b5d * [#142](https://github.com/osmosis-labs/cometbft/pull/142) feat(p2p): render HasChannel(chID) is a public p2p.Peer method (#3510) #142 * [#143](https://github.com/osmosis-labs/cometbft/pull/143) fix: comment out expensive debug logs #143 * [#f2f9426](https://github.com/osmosis-labs/cometbft/commit/f2f9426c6985f2ea63ceb879c26858cf7f42f186) perf(blocksync): Parallelize logic for receiving a block from a peer. (backport cometbft#3554) (cometbft#3592) +* [#150](https://github.com/osmosis-labs/cometbft/pull/150) fix: copy TxIndex TxBytes value ## v26 diff --git a/state/txindex/kv/kv.go b/state/txindex/kv/kv.go index d305acbdd23..e7881a79fe4 100644 --- a/state/txindex/kv/kv.go +++ b/state/txindex/kv/kv.go @@ -396,12 +396,17 @@ type TxInfo struct { } func (*TxIndex) setTmpHashes(tmpHeights map[string]TxInfo, key, value []byte, height int64) { + // value comes from cometbft-db Iterator interface Value() API. + // Therefore, we must make a copy before storing references to it. + valueCp := make([]byte, len(value)) + copy(valueCp, value) + eventSeq := extractEventSeqFromKey(key) txInfo := TxInfo{ - TxBytes: value, + TxBytes: valueCp, Height: height, } - tmpHeights[string(value)+eventSeq] = txInfo + tmpHeights[string(valueCp)+eventSeq] = txInfo } // match returns all matching txs by hash that meet a given condition and start