Skip to content

Commit

Permalink
fix: ChainIndexer#GetMsgInfo returns an ErrNotFound when there ar…
Browse files Browse the repository at this point in the history
…e no rows (#12680)
  • Loading branch information
virajbhartiya authored Nov 21, 2024
1 parent 467c6ff commit f4dbd88
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

- Make `EthTraceFilter` / `trace_filter` skip null rounds instead of erroring. ([filecoin-project/lotus#12702](https://github.com/filecoin-project/lotus/pull/12702))
- 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))
- `ChainIndexer#GetMsgInfo` returns an `ErrNotFound` when there are no rows. ([filecoin-project/lotus#12680](https://github.com/filecoin-project/lotus/pull/12680))

## New Features

Expand Down
3 changes: 3 additions & 0 deletions chain/index/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ func (si *SqliteIndexer) GetMsgInfo(ctx context.Context, messageCid cid.Cid) (*M
var height int64

if err := si.queryMsgInfo(ctx, messageCid, &tipsetKeyCidBytes, &height); err != nil {
if err == sql.ErrNoRows {
return nil, ErrNotFound
}
return nil, err
}

Expand Down
39 changes: 25 additions & 14 deletions chain/index/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,34 @@ func TestGetMsgInfo(t *testing.T) {
t.Logf("seed: %d", seed)
rng := pseudo.New(pseudo.NewSource(seed))
s, _, _ := setupWithHeadIndexed(t, 10, rng)
msgCid := randomCid(t, rng)
msgCidBytes := msgCid.Bytes()
tsKeyCid := randomCid(t, rng)

insertTipsetMessage(t, s, tipsetMessage{
tipsetKeyCid: tsKeyCid.Bytes(),
height: uint64(1),
reverted: false,
messageCid: msgCidBytes,
messageIndex: 1,
t.Run("message exists", func(t *testing.T) {
msgCid := randomCid(t, rng)
msgCidBytes := msgCid.Bytes()
tsKeyCid := randomCid(t, rng)

insertTipsetMessage(t, s, tipsetMessage{
tipsetKeyCid: tsKeyCid.Bytes(),
height: uint64(1),
reverted: false,
messageCid: msgCidBytes,
messageIndex: 1,
})

mi, err := s.GetMsgInfo(ctx, msgCid)
require.NoError(t, err)
require.Equal(t, msgCid, mi.Message)
require.Equal(t, tsKeyCid, mi.TipSet)
require.Equal(t, abi.ChainEpoch(1), mi.Epoch)
})

mi, err := s.GetMsgInfo(ctx, msgCid)
require.NoError(t, err)
require.Equal(t, msgCid, mi.Message)
require.Equal(t, tsKeyCid, mi.TipSet)
require.Equal(t, abi.ChainEpoch(1), mi.Epoch)
t.Run("message not found", func(t *testing.T) {
nonExistentMsgCid := randomCid(t, rng)
mi, err := s.GetMsgInfo(ctx, nonExistentMsgCid)
require.Error(t, err)
require.ErrorIs(t, err, ErrNotFound)
require.Nil(t, mi)
})
}

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

0 comments on commit f4dbd88

Please sign in to comment.