Skip to content

Commit f4dbd88

Browse files
fix: ChainIndexer#GetMsgInfo returns an ErrNotFound when there are no rows (#12680)
1 parent 467c6ff commit f4dbd88

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
- Make `EthTraceFilter` / `trace_filter` skip null rounds instead of erroring. ([filecoin-project/lotus#12702](https://github.com/filecoin-project/lotus/pull/12702))
1313
- Event APIs (`GetActorEventsRaw`, `SubscribeActorEventsRaw`, `eth_getLogs`, `eth_newFilter`, etc.) will now return an error when a request matches more than `MaxFilterResults` (default: 10,000) rather than silently truncating the results. Also apply an internal event matcher for `eth_getLogs` (etc.) to avoid builtin actor events on database query so as not to include them in `MaxFilterResults` calculation. ([filecoin-project/lotus#12671](https://github.com/filecoin-project/lotus/pull/12671))
14+
- `ChainIndexer#GetMsgInfo` returns an `ErrNotFound` when there are no rows. ([filecoin-project/lotus#12680](https://github.com/filecoin-project/lotus/pull/12680))
1415

1516
## New Features
1617

chain/index/read.go

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ func (si *SqliteIndexer) GetMsgInfo(ctx context.Context, messageCid cid.Cid) (*M
4949
var height int64
5050

5151
if err := si.queryMsgInfo(ctx, messageCid, &tipsetKeyCidBytes, &height); err != nil {
52+
if err == sql.ErrNoRows {
53+
return nil, ErrNotFound
54+
}
5255
return nil, err
5356
}
5457

chain/index/read_test.go

+25-14
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,34 @@ func TestGetMsgInfo(t *testing.T) {
5757
t.Logf("seed: %d", seed)
5858
rng := pseudo.New(pseudo.NewSource(seed))
5959
s, _, _ := setupWithHeadIndexed(t, 10, rng)
60-
msgCid := randomCid(t, rng)
61-
msgCidBytes := msgCid.Bytes()
62-
tsKeyCid := randomCid(t, rng)
6360

64-
insertTipsetMessage(t, s, tipsetMessage{
65-
tipsetKeyCid: tsKeyCid.Bytes(),
66-
height: uint64(1),
67-
reverted: false,
68-
messageCid: msgCidBytes,
69-
messageIndex: 1,
61+
t.Run("message exists", func(t *testing.T) {
62+
msgCid := randomCid(t, rng)
63+
msgCidBytes := msgCid.Bytes()
64+
tsKeyCid := randomCid(t, rng)
65+
66+
insertTipsetMessage(t, s, tipsetMessage{
67+
tipsetKeyCid: tsKeyCid.Bytes(),
68+
height: uint64(1),
69+
reverted: false,
70+
messageCid: msgCidBytes,
71+
messageIndex: 1,
72+
})
73+
74+
mi, err := s.GetMsgInfo(ctx, msgCid)
75+
require.NoError(t, err)
76+
require.Equal(t, msgCid, mi.Message)
77+
require.Equal(t, tsKeyCid, mi.TipSet)
78+
require.Equal(t, abi.ChainEpoch(1), mi.Epoch)
7079
})
7180

72-
mi, err := s.GetMsgInfo(ctx, msgCid)
73-
require.NoError(t, err)
74-
require.Equal(t, msgCid, mi.Message)
75-
require.Equal(t, tsKeyCid, mi.TipSet)
76-
require.Equal(t, abi.ChainEpoch(1), mi.Epoch)
81+
t.Run("message not found", func(t *testing.T) {
82+
nonExistentMsgCid := randomCid(t, rng)
83+
mi, err := s.GetMsgInfo(ctx, nonExistentMsgCid)
84+
require.Error(t, err)
85+
require.ErrorIs(t, err, ErrNotFound)
86+
require.Nil(t, mi)
87+
})
7788
}
7889

7990
func setupWithHeadIndexed(t *testing.T, headHeight abi.ChainEpoch, rng *pseudo.Rand) (*SqliteIndexer, *types.TipSet, *dummyChainStore) {

0 commit comments

Comments
 (0)