Skip to content

Commit 00b3736

Browse files
committed
fix: bad inclusion logic on bounds comp idx ub
1 parent 4fb35f1 commit 00b3736

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

internal/database/dbpebble/encoders.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ import (
88
"github.com/setavenger/blindbit-lib/logging"
99
)
1010

11+
var maxTxid = [SizeTxid]byte{
12+
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
13+
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
14+
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
15+
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
16+
}
17+
1118
// ---------------- Keys ----------------
1219

1320
func KeyBlockTx(blockHash []byte, pos uint32) []byte {
@@ -160,13 +167,16 @@ func KeyComputeIndex(height uint32, txid []byte) []byte {
160167
return k
161168
}
162169

170+
// BoundsComputeIndex creates bounds for compute index keys from startHeight to endHeight (both inclusive)
163171
func BoundsComputeIndex(startHeight, endHeight uint32) (lb, ub []byte) {
164172
lb = make([]byte, 1+SizeHeight+SizeTxid)
165173
lb[0] = KComputeIndex
166174
be32(startHeight, lb[1:1+SizeHeight])
167175
ub = make([]byte, 1+SizeHeight+SizeTxid)
168176
ub[0] = KComputeIndex
169177
be32(endHeight, ub[1:1+SizeHeight])
178+
// Fill txid portion with 0xFF to include all transactions at endHeight
179+
copy(ub[1+SizeHeight:], maxTxid[:])
170180
return
171181
}
172182

@@ -177,9 +187,7 @@ func BoundsComputeIndexOneHeight(height uint32) (lb, ub []byte) {
177187
ub = make([]byte, 1+SizeHeight+SizeTxid)
178188
ub[0] = KComputeIndex
179189
be32(height, ub[1:1+SizeHeight])
180-
for i := 1 + SizeHeight; i < 1+SizeHeight+SizeTxid; i++ {
181-
ub[i] = 0xFF
182-
}
190+
copy(ub[1+SizeHeight:], maxTxid[:])
183191
return lb, ub
184192
}
185193

0 commit comments

Comments
 (0)