Merge pull request #10552 from filecoin-project/asr/optimize-blockmsgsfortipset

feat: chainstore: optimize BlockMsgsForTipset
This commit is contained in:
Jiaying Wang 2023-04-04 13:53:23 -04:00 committed by GitHub
commit 522388820a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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) return nil, xerrors.Errorf("failed to load state tree at tipset %s: %w", ts, err)
} }
useIds := false
selectMsg := func(m *types.Message) (bool, error) { selectMsg := func(m *types.Message) (bool, error) {
var sender address.Address var sender address.Address
if ts.Height() >= build.UpgradeHyperdriveHeight { if ts.Height() >= build.UpgradeHyperdriveHeight {
sender, err = st.LookupID(m.From) if useIds {
if err != nil { sender, err = st.LookupID(m.From)
return false, err 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 { } else {
sender = m.From sender = m.From