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

feat(worker): seal block early if we're over target block time #706

Merged
merged 4 commits into from
Apr 18, 2024

Conversation

Thegaram
Copy link

1. Purpose or design rationale of this PR

If we're over the target block time, short-circuit block packing and leave transactions to the next block.

This is a short-term fix to make the fork block more predictable.

2. PR title

Your PR title must follow conventional commits (as we are doing squash merge for each PR), so it must start with one of the following types:

  • feat: A new feature

3. Deployment tag versioning

Has the version in params/version.go been updated?

  • This PR doesn't involve a new deployment, git tag, docker image tag, and it doesn't affect traces
  • Yes

4. Breaking change label

Does this PR have the breaking-change label?

  • This PR is not a breaking change
  • Yes

omerfirmak
omerfirmak previously approved these changes Apr 17, 2024
miner/worker.go Outdated Show resolved Hide resolved
miner/worker.go Outdated Show resolved Hide resolved
miner/worker.go Outdated Show resolved Hide resolved
HAOYUatHZ
HAOYUatHZ previously approved these changes Apr 17, 2024
georgehao
georgehao previously approved these changes Apr 17, 2024
@omerfirmak
Copy link

Small q; do empty blocks need any special treatment?

@HAOYUatHZ
Copy link
Member

we return instead of break in the loop. are we comfortable with skipping

	if !w.isRunning() && len(coalescedLogs) > 0 {
		// We don't push the pendingLogsEvent while we are mining. The reason is that
		// when we are mining, the worker will regenerate a mining block every 3 seconds.
		// In order to avoid pushing the repeated pendingLog, we disable the pending log pushing.

		// make a copy, the state caches the logs and these logs get "upgraded" from pending to mined
		// logs by filling in the block hash when the block was mined by the local miner. This can
		// cause a race condition if a log was "upgraded" before the PendingLogsEvent is processed.
		cpy := make([]*types.Log, len(coalescedLogs))
		for i, l := range coalescedLogs {
			cpy[i] = new(types.Log)
			*cpy[i] = *l
		}
		w.pendingLogsFeed.Send(cpy)
	}
	// Notify resubmit loop to decrease resubmitting interval if current interval is larger
	// than the user-specified one.
	if interrupt != nil {
		w.resubmitAdjustCh <- &intervalAdjust{inc: false}
	}
	return false, circuitCapacityReached

@Thegaram Thegaram dismissed stale reviews from georgehao and HAOYUatHZ via 91627fb April 18, 2024 02:36
@Thegaram
Copy link
Author

we return instead of break in the loop. are we comfortable with skipping

Good question. This code does not seem super relevant, but skipping it might return in some difference in how we expose pending blocks. Changed to break in 91627fb to be more consistent with the original behaviour.

Small q; do empty blocks need any special treatment?

I added the w.current.tcount > 0 condition to make sure we always make some progress processing transactions. It is possible that we keep processing and skipping transactions, but this does not seem to happen often in practice.

@Thegaram Thegaram merged commit 62926d4 into develop Apr 18, 2024
7 checks passed
@Thegaram Thegaram deleted the feat-seal-block-early branch April 18, 2024 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants