diff --git a/CHANGELOG.md b/CHANGELOG.md index 8eb4b41371..6ec6743106 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,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 diff --git a/chain/index/read.go b/chain/index/read.go index d7c00bd35c..b075429fde 100644 --- a/chain/index/read.go +++ b/chain/index/read.go @@ -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 } diff --git a/chain/index/read_test.go b/chain/index/read_test.go index ebb6d1acf4..4f8b4699c0 100644 --- a/chain/index/read_test.go +++ b/chain/index/read_test.go @@ -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) {