Skip to content

Commit e8d79ab

Browse files
authored
Fix: get correctly unfiltered transactions (#149)
When there are transactions on genesis, and no filter is applied, take into account the max toTxIndex range when filtering the out results. This functionality can be deleted in the future, when we delete deprecated graphql queries. Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
1 parent 24d4ee5 commit e8d79ab

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

storage/pebble.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,6 @@ func (s *Pebble) loadTxIterator(
214214
) (*pebble.Iterator, *pebble.Snapshot, error) {
215215
fromKey := keyTx(fromBlockNum, fromTxIndex)
216216

217-
if toBlockNum == 0 {
218-
toBlockNum = math.MaxInt64
219-
}
220-
221-
if toTxIndex == 0 {
222-
toTxIndex = math.MaxUint32
223-
}
224-
225217
toKey := keyTx(toBlockNum, toTxIndex)
226218

227219
snap := s.db.NewSnapshot()
@@ -243,6 +235,14 @@ func (s *Pebble) TxIterator(
243235
fromTxIndex,
244236
toTxIndex uint32,
245237
) (Iterator[*types.TxResult], error) {
238+
if toBlockNum == 0 {
239+
toBlockNum = math.MaxInt64
240+
}
241+
242+
if toTxIndex == 0 {
243+
toTxIndex = math.MaxUint32
244+
}
245+
246246
it, snap, err := s.loadTxIterator(fromBlockNum, toBlockNum, fromTxIndex, toTxIndex)
247247
if err != nil {
248248
return nil, err
@@ -264,6 +264,14 @@ func (s *Pebble) TxReverseIterator(
264264
fromTxIndex,
265265
toTxIndex uint32,
266266
) (Iterator[*types.TxResult], error) {
267+
if toBlockNum == 0 {
268+
toBlockNum = math.MaxInt64
269+
}
270+
271+
if toTxIndex == 0 {
272+
toTxIndex = math.MaxUint32
273+
}
274+
267275
it, snap, err := s.loadTxIterator(fromBlockNum, toBlockNum, fromTxIndex, toTxIndex)
268276
if err != nil {
269277
return nil, err

storage/pebble_test.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,36 @@ func TestStorageIters(t *testing.T) {
183183
break
184184
}
185185

186-
_, err := it.Value()
186+
_, err = it.Value()
187187
require.NoError(t, err)
188188
require.NoError(t, it.Error())
189189

190190
txCount++
191191
}
192192

193193
require.Equal(t, 0, txCount)
194+
195+
// corner case: get all transactions from genesis
196+
it, err = s.TxIterator(0, 0, 0, 0)
197+
require.NoError(t, err)
198+
199+
txCount = 0
200+
201+
for {
202+
if !it.Next() {
203+
require.NoError(t, it.Error())
204+
205+
break
206+
}
207+
208+
_, err := it.Value()
209+
require.NoError(t, err)
210+
require.NoError(t, it.Error())
211+
212+
txCount++
213+
}
214+
215+
require.Equal(t, 100, txCount)
194216
}
195217

196218
// generateRandomBlocks generates dummy blocks

0 commit comments

Comments
 (0)