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 GetBestMiningCandidate bug #3444

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ func (m *Miner) GetBestMiningCandidate(ctx context.Context) (*MiningBase, error)
}
ltsw, err := m.api.ChainTipSetWeight(ctx, m.lastWork.TipSet.Key())
if err != nil {
m.lastWork = nil
Copy link
Member

Choose a reason for hiding this comment

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

Whats the actual bug being fixed here? Shouldnt we also have the same line copied a few lines up?

Copy link
Author

Choose a reason for hiding this comment

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

lotus/miner/miner.go

func (m *Miner) mine(ctx context.Context) {
	...
	for {
		prebase, err := m.GetBestMiningCandidate(ctx)
		// If an error occurs in GetBestMiningCandidate, it will wait 5 seconds to retry GetBestMiningCandidate
		if err != nil {
			log.Errorf("failed to get best mining candidate: %s", err)
			m.niceSleep(time.Second * 5)
			continue
		}
		...
	}
	...
}

func (m *Miner) GetBestMiningCandidate(ctx context.Context) (*MiningBase, error) {
	...
	if m.lastWork != nil {
		if m.lastWork.TipSet.Equals(bts) {
			return m.lastWork, nil
		}

		btsw, err := m.api.ChainTipSetWeight(ctx, bts.Key())
		if err != nil {
			return nil, err
		}
		ltsw, err := m.api.ChainTipSetWeight(ctx, m.lastWork.TipSet.Key())
		// If lastWork is using an incorrect TipSet, an error is received and returned here, 
		// for example i have got: blockstore: block not found. 
		// There is no modification lastWork here, so if you try it again, you will get the same error here. 
		// In the mine() function above, it tries again and again, but always got this error
		if err != nil {
			return nil, err
		}
		...
	}
	...
}

Copy link
Member

Choose a reason for hiding this comment

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

Ah! Thank you for that. This makes sense

return nil, err
}

Expand Down