Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: message pool may panic caused by access a nil pointer #5454

Merged

Conversation

zl03jsj
Copy link
Contributor

@zl03jsj zl03jsj commented Nov 4, 2022

改动 (Proposed Changes)

修复一个venus可能会崩溃的bug。
在通过地址删除 消息池消息时, 直接设置了memset为nil, 在这里:

func (mp *MessagePool) DeleteByAdress(address address.Address) error {
mp.lk.Lock()
defer mp.lk.Unlock()
if mp.pending != nil {
mp.pending[address] = nil
}
return nil

在后续, 如果有推送这个地址的消息时, 会间接调用:getPendigMessage, 返回值为:{nil, true, nil}, 最终,导致使用为nil的memset导致崩溃:
func (mp *MessagePool) checkBalance(ctx context.Context, m *types.SignedMessage, curTS *types.TipSet) error {
balance, err := mp.getStateBalance(ctx, m.Message.From, curTS)
if err != nil {
return fmt.Errorf("failed to check sender balance: %s: %w", err, ErrSoftValidationFailure)
}
requiredFunds := m.Message.RequiredFunds()
if big.Cmp(balance, requiredFunds) < 0 {
return fmt.Errorf("not enough funds (required: %s, balance: %s): %v", types.FIL(requiredFunds), types.FIL(balance), ErrNotEnoughFunds)
}
// add Value for soft failure check
// requiredFunds = types.BigAdd(requiredFunds, m.Message.Value)
mset, ok, err := mp.getPendingMset(ctx, m.Message.From)
if err != nil {
log.Debugf("mpoolcheckbalance failed to get pending mset: %s", err)
return err
}
if ok {
requiredFunds = types.BigAdd(requiredFunds, mset.getRequiredFunds(m.Message.Nonce))
}
if big.Cmp(balance, requiredFunds) < 0 {

附注 (Additional Info)

自查清单 (Checklist)

在你认为本 PR 满足被审阅的标准之前,需要确保 / Before you mark the PR ready for review, please make sure that:

  • 符合Venus项目管理规范中关于PR的相关标准 / The PR follows the PR standards set out in the Venus project management guidelines
  • 具有清晰明确的commit message / All commits have a clear commit message.
  • 包含相关的的测试用例或者不需要新增测试用例 / This PR has tests for new functionality or change in behaviour or not need to add new tests.
  • 包含相关的的指南以及文档或者不需要新增文档 / This PR has updated usage guidelines and documentation or not need
  • 通过必要的检查项 / All checks are green

Copy link
Collaborator

@simlecode simlecode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+LGTM

@codecov-commenter
Copy link

Codecov Report

Merging #5454 (931c8e1) into master (44e1cf8) will decrease coverage by 0%.
The diff coverage is 0%.

Additional details and impacted files
@@          Coverage Diff           @@
##           master   #5454   +/-   ##
======================================
- Coverage      24%     24%   -1%     
======================================
  Files         605     605           
  Lines       67852   67857    +5     
======================================
- Hits        16893   16886    -7     
- Misses      48773   48782    +9     
- Partials     2186    2189    +3     

@hunjixin hunjixin merged commit c53c9f9 into master Nov 7, 2022
@hunjixin hunjixin deleted the fix/messagepool-may-panic-caused-by-access-nil-pointer branch November 7, 2022 01:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants