Skip to content

Commit

Permalink
Addres review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
fridrik01 committed May 27, 2023
1 parent 5336f33 commit 7b8c285
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
11 changes: 6 additions & 5 deletions chain/index/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
26 changes: 13 additions & 13 deletions chain/index/msgindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions chain/index/msgindex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}
Expand Down
8 changes: 4 additions & 4 deletions chain/stmgr/searchwait.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 7b8c285

Please sign in to comment.