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

consensus,core,miner: avoid overhead of creating a new block #19301

Merged
merged 3 commits into from
Apr 30, 2019

Conversation

holiman
Copy link
Contributor

@holiman holiman commented Mar 19, 2019

This PR removes some overhead work done during block import, where we uselessly assemble a block which is then thrown away.

In state processor

	// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
	p.engine.Finalize(p.bc, header, statedb, block.Transactions(), block.Uncles(), receipts)

ethash/consensus.go:

// Finalize implements consensus.Engine, accumulating the block and uncle rewards,
// setting the final state and assembling the block.
func (ethash *Ethash) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) {
	// Accumulate any block and uncle rewards and commit the final state root
	accumulateRewards(chain.Config(), state, header, uncles)
	header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))

	// Header seems complete, assemble into a block and return
	return types.NewBlock(header, txs, uncles, receipts), nil
}

The Finalize returns a new types.Block, which copies the entire block and recalculates the transcation hash, unclehash, receipt hash and log bloom. The returned new block is totally ignored by the state processor, however.

This PR skips that recalculation. That calculation of hashes and verification against the given block is (already) performed later, in ValidateState.

@holiman holiman requested a review from karalabe as a code owner March 19, 2019 14:06
consensus/consensus.go Outdated Show resolved Hide resolved
@karalabe karalabe added this to the 1.9.0 milestone Mar 20, 2019
Copy link
Member

@karalabe karalabe left a comment

Choose a reason for hiding this comment

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

LGTM

@karalabe karalabe merged commit 4c90efd into ethereum:master Apr 30, 2019
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.

2 participants