tvx: use addresses when scanning precursors.

This commit is contained in:
Raúl Kripalani 2022-03-11 18:49:07 +00:00
parent 92c9716595
commit 5434cfdaa9

View File

@ -406,33 +406,22 @@ func fetchThisAndPrevTipset(ctx context.Context, api v0api.FullNode, target type
// mode. // mode.
func findMsgAndPrecursors(ctx context.Context, mode string, msgCid cid.Cid, sender address.Address, recipient address.Address, msgs []api.Message) (related []*types.Message, found bool, err error) { func findMsgAndPrecursors(ctx context.Context, mode string, msgCid cid.Cid, sender address.Address, recipient address.Address, msgs []api.Message) (related []*types.Message, found bool, err error) {
// Resolve addresses to IDs for canonicality. // Resolve addresses to IDs for canonicality.
senderID, err := FullAPI.StateLookupID(ctx, sender, types.EmptyTSK) senderID := mustResolveAddr(ctx, sender)
if err != nil { recipientID := mustResolveAddr(ctx, recipient)
return nil, false, err
}
recipientID, err := FullAPI.StateLookupID(ctx, recipient, types.EmptyTSK)
if err != nil {
return nil, false, err
}
// Range through messages, selecting only the precursors based on selection mode. // Range through messages, selecting only the precursors based on selection mode.
for _, m := range msgs { for _, m := range msgs {
msgSenderID, err := FullAPI.StateLookupID(ctx, m.Message.From, types.EmptyTSK) msgSenderID := mustResolveAddr(ctx, m.Message.From)
if err != nil { msgRecipientID := mustResolveAddr(ctx, m.Message.To)
return nil, false, err
}
msgRecipientID, err := FullAPI.StateLookupID(ctx, m.Message.To, types.EmptyTSK)
if err != nil {
return nil, false, err
}
switch { switch {
case mode == PrecursorSelectAll: case mode == PrecursorSelectAll:
fallthrough fallthrough
case mode == PrecursorSelectParticipants && case mode == PrecursorSelectParticipants &&
msgSenderID == senderID || msgSenderID == senderID ||
msgRecipientID == recipientID || msgRecipientID == recipientID ||
msgSenderID == recipientID || msgSenderID == recipientID ||
msgRecipientID == senderID: msgRecipientID == senderID:
related = append(related, m.Message) related = append(related, m.Message)
} }
@ -447,3 +436,17 @@ func findMsgAndPrecursors(ctx context.Context, mode string, msgCid cid.Cid, send
// target). // target).
return related, false, nil return related, false, nil
} }
var addressCache = make(map[address.Address]address.Address)
func mustResolveAddr(ctx context.Context, addr address.Address) address.Address {
if resolved, ok := addressCache[addr]; ok {
return resolved
}
id, err := FullAPI.StateLookupID(ctx, addr, types.EmptyTSK)
if err != nil {
panic(fmt.Errorf("failed to resolve addr: %w", err))
}
addressCache[addr] = id
return id
}