From b1669235f7645d20b5e93124230c7149035e2eb5 Mon Sep 17 00:00:00 2001 From: Aayush Date: Thu, 23 Mar 2023 11:57:26 -0400 Subject: [PATCH] feat: chainstore: optimize BlockMsgsForTipset --- chain/store/messages.go | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/chain/store/messages.go b/chain/store/messages.go index c39cb3f9b9d..ee37b4855ea 100644 --- a/chain/store/messages.go +++ b/chain/store/messages.go @@ -114,12 +114,35 @@ func (cs *ChainStore) BlockMsgsForTipset(ctx context.Context, ts *types.TipSet) return nil, xerrors.Errorf("failed to load state tree at tipset %s: %w", ts, err) } + useIds := false selectMsg := func(m *types.Message) (bool, error) { var sender address.Address if ts.Height() >= build.UpgradeHyperdriveHeight { - sender, err = st.LookupID(m.From) - if err != nil { - return false, err + if useIds { + sender, err = st.LookupID(m.From) + if err != nil { + return false, xerrors.Errorf("failed to resolve sender: %w", err) + } + } else { + if m.From.Protocol() != address.ID { + // we haven't been told to use IDs, just use the robust addr + sender = m.From + } else { + // uh-oh, we actually have an ID-sender! + useIds = true + for robust, nonce := range applied { + resolved, err := st.LookupID(robust) + if err != nil { + return false, xerrors.Errorf("failed to resolve sender: %w", err) + } + applied[resolved] = nonce + } + + sender, err = st.LookupID(m.From) + if err != nil { + return false, xerrors.Errorf("failed to resolve sender: %w", err) + } + } } } else { sender = m.From