-
Notifications
You must be signed in to change notification settings - Fork 20.9k
core, miner: do not populate receipts field during mining #31813
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -137,16 +137,22 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg | |||
// and uses the input parameters for its environment similar to ApplyTransaction. However, | ||||
// this method takes an already created EVM instance as input. | ||||
func ApplyTransactionWithEVM(msg *Message, gp *GasPool, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64, evm *vm.EVM) (receipt *types.Receipt, err error) { | ||||
var result *ExecutionResult | ||||
if hooks := evm.Config.Tracer; hooks != nil { | ||||
if hooks.OnTxStart != nil { | ||||
hooks.OnTxStart(evm.GetVMContext(), tx, msg.From) | ||||
} | ||||
if hooks.OnTxEnd != nil { | ||||
defer func() { hooks.OnTxEnd(receipt, err) }() | ||||
defer func() { | ||||
if receipt != nil { | ||||
receipt = deriveFullReceipt(receipt, evm, result, statedb, blockNumber, blockHash, tx) | ||||
} | ||||
hooks.OnTxEnd(receipt, err) | ||||
}() | ||||
} | ||||
} | ||||
// Apply the transaction to the current state (included in the env). | ||||
result, err := ApplyMessage(evm, msg, gp) | ||||
result, err = ApplyMessage(evm, msg, gp) | ||||
if err != nil { | ||||
return nil, err | ||||
} | ||||
|
@@ -165,19 +171,28 @@ func ApplyTransactionWithEVM(msg *Message, gp *GasPool, statedb *state.StateDB, | |||
statedb.AccessEvents().Merge(evm.AccessEvents) | ||||
} | ||||
|
||||
return MakeReceipt(evm, result, statedb, blockNumber, blockHash, tx, *usedGas, root), nil | ||||
receipt = MakeReceipt(result, statedb, tx, *usedGas, root) | ||||
return receipt, nil | ||||
} | ||||
|
||||
// MakeReceipt generates the receipt object for a transaction given its execution result. | ||||
func MakeReceipt(evm *vm.EVM, result *ExecutionResult, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas uint64, root []byte) *types.Receipt { | ||||
// Create a new receipt for the transaction, storing the intermediate root and gas used | ||||
// by the tx. | ||||
// It only populates the fields strictly required for consensus. | ||||
func MakeReceipt(result *ExecutionResult, statedb *state.StateDB, tx *types.Transaction, usedGas uint64, root []byte) *types.Receipt { | ||||
receipt := &types.Receipt{Type: tx.Type(), PostState: root, CumulativeGasUsed: usedGas} | ||||
if result.Failed() { | ||||
receipt.Status = types.ReceiptStatusFailed | ||||
} else { | ||||
receipt.Status = types.ReceiptStatusSuccessful | ||||
} | ||||
receipt.Logs = statedb.GetLogs(tx.Hash()) | ||||
receipt.Bloom = types.CreateBloom(receipt) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logs constructed during the block insertion (e.g., full sync) will be emitted to the log subscribers, which assumes the logs should be fully annotated. Here, the logs are partially annotated, missing blockNumber and blockHash fields. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure? I don't see where they are emitted to the log subscribers. I only see them written to the db and later on read from the db during collectLogs and the missing fields are derived There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gary has a point. This is where the logs are being sent out to subscribers: go-ethereum/core/blockchain.go Line 1626 in 8781e93
I missed this. We don't have pending subscription anymore but the log subscription to newly mined logs is there. I think it will be tricky to derive the fields in the consumer unless we change the structure of the logsFeed. At least would need the header and unflattened logs. |
||||
return receipt | ||||
} | ||||
|
||||
// deriveFullReceipt populates non-consensus fields. | ||||
func deriveFullReceipt(receipt *types.Receipt, evm *vm.EVM, result *ExecutionResult, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction) *types.Receipt { | ||||
// Create a new receipt for the transaction, storing the intermediate root and gas used | ||||
// by the tx. | ||||
receipt.TxHash = tx.Hash() | ||||
receipt.GasUsed = result.UsedGas | ||||
|
||||
|
@@ -191,9 +206,14 @@ func MakeReceipt(evm *vm.EVM, result *ExecutionResult, statedb *state.StateDB, b | |||
receipt.ContractAddress = crypto.CreateAddress(evm.TxContext.Origin, tx.Nonce()) | ||||
} | ||||
|
||||
// Set the receipt logs and create the bloom filter. | ||||
receipt.Logs = statedb.GetLogs(tx.Hash(), blockNumber.Uint64(), blockHash) | ||||
receipt.Bloom = types.CreateBloom(receipt) | ||||
// Annotate the logs | ||||
for index, log := range receipt.Logs { | ||||
log.TxHash = tx.Hash() | ||||
log.TxIndex = uint(statedb.TxIndex()) | ||||
log.Index = uint(index) | ||||
log.BlockHash = blockHash | ||||
s1na marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
log.BlockNumber = blockNumber.Uint64() | ||||
} | ||||
receipt.BlockHash = blockHash | ||||
receipt.BlockNumber = blockNumber | ||||
receipt.TransactionIndex = uint(statedb.TxIndex()) | ||||
|
@@ -210,7 +230,7 @@ func ApplyTransaction(evm *vm.EVM, gp *GasPool, statedb *state.StateDB, header * | |||
return nil, err | ||||
} | ||||
// Create a new context to be used in the EVM environment | ||||
return ApplyTransactionWithEVM(msg, gp, statedb, header.Number, header.Hash(), tx, usedGas, evm) | ||||
return ApplyTransactionWithEVM(msg, gp, statedb, header.Number, common.Hash{}, tx, usedGas, evm) | ||||
} | ||||
|
||||
// ProcessBeaconBlockRoot applies the EIP-4788 system call to the beacon block root | ||||
|
Uh oh!
There was an error while loading. Please reload this page.