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

core: panic if txs and receipts don't match in types.NewBlock(..) #29501

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lightclient
Copy link
Member

Fixes a TODO in types.NewBlock.

@lightclient lightclient changed the title core: panic if tx and receipt don't match in types.NewBlock(..) core: panic if txs and receipts don't match in types.NewBlock(..) Apr 10, 2024
@@ -221,9 +221,12 @@ type extblock struct {
// are ignored and set to values derived from the given txs, uncles
// and receipts.
func NewBlock(header *Header, txs []*Transaction, uncles []*Header, receipts []*Receipt, hasher TrieHasher) *Block {
if len(txs) != len(receipts) {
panic("cannot make new block with mismatched number of txs and receipts")
Copy link
Member

Choose a reason for hiding this comment

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

We've been discussing that this feels a bit drastic, given that we use the method in multiple places. Whilst this should not really happen - and a panic might be warranted in the miner or such packages - in other places it's less drastic (e.g. network piecing together bits and bobs of a block). Whilst true that it should not call with junk params, it's less clear that a hard panic would be the best course of action...

CC @fjl?

Copy link
Member

Choose a reason for hiding this comment

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

We could soften it with a log.Error, but yeah, we should decide if we really want to go nuclear here and if we feel confident about not blowing up anywhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense to me! Fine either way.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should not panic here. It might be useful, e.g. for creating blocks in various test-scenarios, to have mismatched txs/receipts (but still correctly derived receiptsroot etc). So 👍 on "stern warning" but from me 👎 on "hard crash"

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.

None yet

3 participants