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

Extra receipt for internal EVM call when finalizing blocks #584

Merged
merged 14 commits into from
Nov 20, 2019

Conversation

mrsmkl
Copy link
Contributor

@mrsmkl mrsmkl commented Nov 13, 2019

Description

When a block is finalized, the events emitted from internal EVM calls were not stored into the block, because there was no associated transaction and receipt. This PR adds an extra receipt in the case the block finalization emits events.

Tested

Let's see if CI works.

Other changes

Related issues

Backwards compatibility

Might cause some issues, for example the events are associated to tx with hash 0x00000000.

@mrsmkl mrsmkl requested a review from asaj as a code owner November 13, 2019 15:03
@asaj
Copy link
Contributor

asaj commented Nov 14, 2019

Looks like this may have broken fast sync?

@asaj asaj assigned mrsmkl and unassigned mcortesi and asaj Nov 14, 2019
@mrsmkl mrsmkl assigned mcortesi and asaj and unassigned mrsmkl Nov 15, 2019
@mrsmkl
Copy link
Contributor Author

mrsmkl commented Nov 15, 2019

Sorry, thought it would be working because transfer tests also fast sync. But validators aren't elected there...
Anyway, now should be better.

@@ -816,6 +816,16 @@ func SetReceiptsData(config *params.ChainConfig, block *types.Block, receipts ty
logIndex++
}
}
// Handle extra receipt
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: wdyt of Handle block finalization receipt?

Copy link
Contributor

Choose a reason for hiding this comment

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

Wdyt?

@@ -84,8 +84,16 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
allLogs = append(allLogs, receipt.Logs...)
}
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
statedb.Prepare(common.Hash{}, block.Hash(), len(block.Transactions()))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When logs are added, the associated transaction will be read from the instance variables that are set by this method.

p.engine.Finalize(p.bc, header, statedb, block.Transactions(), block.Uncles(), receipts, block.Randomness())

if len(statedb.GetLogs(common.Hash{})) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not 100% clear on what's going on here. Would there be a single receipt for all blocks? If not, won't we have the null hash being mapped to many receipts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, many receipts will be associated into null hash, but they can be separated because they are contained in different blocks.

Comparison between using null and block hash

  • if block hash is used, there will be more hashes without corresponding transactions
  • if null hash is used, (tx hash, log index) pairs will no longer be unique

I'll next check that tx hash in receipt is not consensus data.

@asaj
Copy link
Contributor

asaj commented Nov 15, 2019

Thanks for working on this!

@asaj asaj assigned mrsmkl and unassigned asaj Nov 15, 2019
@mrsmkl mrsmkl assigned asaj and unassigned mrsmkl Nov 19, 2019
Copy link
Contributor

@asaj asaj left a comment

Choose a reason for hiding this comment

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

Can you add end-to-end tests in the monorepo? governance_tests.ts seems like the appropriate place

@@ -786,11 +786,11 @@ func SetReceiptsData(config *params.ChainConfig, block *types.Block, receipts ty
signer := types.MakeSigner(config, block.Number())

transactions, logIndex := block.Transactions(), uint(0)
if len(transactions) != len(receipts) {
if len(transactions) != len(receipts) && len(transactions)+1 != len(receipts) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment above this:
The receipts may include an additional "block finalization" receipt

@@ -816,6 +816,16 @@ func SetReceiptsData(config *params.ChainConfig, block *types.Block, receipts ty
logIndex++
}
}
// Handle extra receipt
Copy link
Contributor

Choose a reason for hiding this comment

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

Wdyt?

@@ -614,6 +614,9 @@ func (w *worker) resultLoop() {
// receipt/log of individual transactions were created.
for _, log := range receipt.Logs {
log.BlockHash = hash
if (log.TxHash == common.Hash{}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment Handle block finalization receipt

@asaj asaj assigned mrsmkl and unassigned asaj Nov 20, 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.

Internal EVM calls SBAT emit events
3 participants