From 7b8c2857ac3106cfdd61200f7a12e4c4ecc65439 Mon Sep 17 00:00:00 2001 From: Fridrik Asmundsson Date: Sat, 27 May 2023 15:35:12 +0000 Subject: [PATCH] Addres review comments --- chain/index/interface.go | 11 ++++++----- chain/index/msgindex.go | 26 +++++++++++++------------- chain/index/msgindex_test.go | 4 ++-- chain/stmgr/searchwait.go | 8 ++++---- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/chain/index/interface.go b/chain/index/interface.go index 239abf8fa3d..5beb5db53f3 100644 --- a/chain/index/interface.go +++ b/chain/index/interface.go @@ -20,23 +20,24 @@ type MsgInfo struct { TipSet cid.Cid // the epoch where this message was included Epoch abi.ChainEpoch + // the execution tipset of the message (if it exists) + ExTsCid cid.Cid } // MsgIndex is the interface to the message index type MsgIndex interface { - // GetMsgInfo looks up the message in index and retrieves its metadata and execution - // tipset cid. + // GetMsgInfo looks up the message in index and retrieves its metadata. // The lookup is done using the onchain message Cid; that is the signed message Cid // for SECP messages and unsigned message Cid for BLS messages. - GetMsgInfo(ctx context.Context, mCid cid.Cid) (MsgInfo, cid.Cid, error) + GetMsgInfo(ctx context.Context, m cid.Cid) (MsgInfo, error) // Close closes the index Close() error } type dummyMsgIndex struct{} -func (dummyMsgIndex) GetMsgInfo(ctx context.Context, mCid cid.Cid) (MsgInfo, cid.Cid, error) { - return MsgInfo{}, cid.Undef, ErrNotFound +func (dummyMsgIndex) GetMsgInfo(ctx context.Context, m cid.Cid) (MsgInfo, error) { + return MsgInfo{}, ErrNotFound } func (dummyMsgIndex) Close() error { diff --git a/chain/index/msgindex.go b/chain/index/msgindex.go index 5d6c5cd889a..ac00f5e317f 100644 --- a/chain/index/msgindex.go +++ b/chain/index/msgindex.go @@ -494,36 +494,36 @@ func (x *msgIndex) doApply(ctx context.Context, tx *sql.Tx, ts *types.TipSet) er } // interface -func (x *msgIndex) GetMsgInfo(ctx context.Context, mCid cid.Cid) (MsgInfo, cid.Cid, error) { +func (x *msgIndex) GetMsgInfo(ctx context.Context, m cid.Cid) (MsgInfo, error) { x.closeLk.RLock() defer x.closeLk.RUnlock() if x.closed { - return MsgInfo{}, cid.Undef, ErrClosed + return MsgInfo{}, ErrClosed } // fetch message from index (if it exists) // var tipset string var epoch int64 - err := x.selectMsgStmt.QueryRow(mCid.String()).Scan(&tipset, &epoch) + err := x.selectMsgStmt.QueryRow(m.String()).Scan(&tipset, &epoch) if err != nil { if err == sql.ErrNoRows { - // mCid not in index, its fine - return MsgInfo{}, cid.Undef, ErrNotFound + return MsgInfo{}, ErrNotFound } - return MsgInfo{}, cid.Undef, xerrors.Errorf("error querying msgindex database: %w", err) + return MsgInfo{}, xerrors.Errorf("error querying msgindex database: %w", err) } tsCid, err := cid.Decode(tipset) if err != nil { - return MsgInfo{}, cid.Undef, xerrors.Errorf("error decoding tipset cid: %w", err) + return MsgInfo{}, xerrors.Errorf("error decoding tipset cid: %w", err) } msgInfo := MsgInfo{ - Message: mCid, + Message: m, TipSet: tsCid, Epoch: abi.ChainEpoch(epoch), + ExTsCid: cid.Undef, } // fetch execution tipset of message (if it exists) @@ -533,17 +533,17 @@ func (x *msgIndex) GetMsgInfo(ctx context.Context, mCid cid.Cid) (MsgInfo, cid.C if err != nil { if err == sql.ErrNoRows { // execution tipset not in index, its fine - return msgInfo, cid.Undef, nil + return msgInfo, nil } - return MsgInfo{}, cid.Undef, xerrors.Errorf("error querying for execution tipset: %w", err) + return MsgInfo{}, xerrors.Errorf("error querying for execution tipset: %w", err) } - xtsCid, err := cid.Decode(xTipset) + msgInfo.ExTsCid, err = cid.Decode(xTipset) if err != nil { - return MsgInfo{}, cid.Undef, xerrors.Errorf("error decoding execution tipset cid: %w", err) + return MsgInfo{}, xerrors.Errorf("error decoding execution tipset cid: %w", err) } - return msgInfo, xtsCid, nil + return msgInfo, nil } func (x *msgIndex) Close() error { diff --git a/chain/index/msgindex_test.go b/chain/index/msgindex_test.go index 42d4311a9d3..bf4bc6190e8 100644 --- a/chain/index/msgindex_test.go +++ b/chain/index/msgindex_test.go @@ -158,7 +158,7 @@ func verifyIndex(t *testing.T, cs *mockChainStore, msgIndex MsgIndex) { msgs, err := cs.MessagesForTipset(context.Background(), ts) require.NoError(t, err) for _, m := range msgs { - minfo, _, err := msgIndex.GetMsgInfo(context.Background(), m.Cid()) + minfo, err := msgIndex.GetMsgInfo(context.Background(), m.Cid()) require.NoError(t, err) require.Equal(t, tsCid, minfo.TipSet) require.Equal(t, ts.Height(), minfo.Epoch) @@ -175,7 +175,7 @@ func verifyMissing(t *testing.T, cs *mockChainStore, msgIndex MsgIndex, missing msgs, err := cs.MessagesForTipset(context.Background(), ts) require.NoError(t, err) for _, m := range msgs { - _, _, err := msgIndex.GetMsgInfo(context.Background(), m.Cid()) + _, err := msgIndex.GetMsgInfo(context.Background(), m.Cid()) require.Equal(t, ErrNotFound, err) } } diff --git a/chain/stmgr/searchwait.go b/chain/stmgr/searchwait.go index 2749d3682d5..087d4238455 100644 --- a/chain/stmgr/searchwait.go +++ b/chain/stmgr/searchwait.go @@ -190,7 +190,7 @@ func (sm *StateManager) SearchForMessage(ctx context.Context, head *types.TipSet } func (sm *StateManager) searchForIndexedMsg(ctx context.Context, mcid cid.Cid, m types.ChainMsg) (*types.TipSet, *types.MessageReceipt, cid.Cid, error) { - minfo, xtsCid, err := sm.msgIndex.GetMsgInfo(ctx, mcid) + minfo, err := sm.msgIndex.GetMsgInfo(ctx, mcid) if err != nil { return nil, nil, cid.Undef, xerrors.Errorf("error looking up message in index: %w", err) } @@ -203,10 +203,10 @@ func (sm *StateManager) searchForIndexedMsg(ctx context.Context, mcid cid.Cid, m } // now get the execution tipset - var xts *types.TipSet = nil - if xtsCid != cid.Undef { + var xts *types.TipSet + if minfo.ExTsCid.Defined() { // lookup by cid which is faster - xts, err = sm.cs.GetTipSetByCid(ctx, xtsCid) + xts, err = sm.cs.GetTipSetByCid(ctx, minfo.ExTsCid) if err != nil { return nil, nil, cid.Undef, xerrors.Errorf("error calling GetTipSetByCid: %w", err) }