|
|
@@ -390,9 +390,14 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
|
|
|
blockContext := NewEVMBlockContext(header, p.bc, nil)
|
|
|
vmenv := vm.NewEVM(blockContext, vm.TxContext{}, statedb, p.config, cfg)
|
|
|
|
|
|
+ txNum := len(block.Transactions())
|
|
|
// Iterate over and process the individual transactions
|
|
|
posa, isPoSA := p.engine.(consensus.PoSA)
|
|
|
- commonTxs := make([]*types.Transaction, 0, len(block.Transactions()))
|
|
|
+ commonTxs := make([]*types.Transaction, 0, txNum)
|
|
|
+
|
|
|
+ // initilise bloom processors
|
|
|
+ bloomProcessors := NewAsyncReceiptBloomGenerator(txNum)
|
|
|
+
|
|
|
// usually do have two tx, one for validator set contract, another for system reward contract.
|
|
|
systemTxs := make([]*types.Transaction, 0, 2)
|
|
|
for i, tx := range block.Transactions() {
|
|
|
@@ -410,7 +415,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
|
|
|
return statedb, nil, nil, 0, err
|
|
|
}
|
|
|
statedb.Prepare(tx.Hash(), block.Hash(), i)
|
|
|
- receipt, err := applyTransaction(msg, p.config, p.bc, nil, gp, statedb, header, tx, usedGas, vmenv)
|
|
|
+ receipt, err := applyTransaction(msg, p.config, p.bc, nil, gp, statedb, header, tx, usedGas, vmenv, bloomProcessors)
|
|
|
if err != nil {
|
|
|
return statedb, nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
|
|
|
}
|
|
|
@@ -418,6 +423,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
|
|
|
commonTxs = append(commonTxs, tx)
|
|
|
receipts = append(receipts, receipt)
|
|
|
}
|
|
|
+ bloomProcessors.Close()
|
|
|
|
|
|
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
|
|
|
err := p.engine.Finalize(p.bc, header, statedb, &commonTxs, block.Uncles(), &receipts, &systemTxs, usedGas)
|
|
|
@@ -431,7 +437,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
|
|
|
return statedb, receipts, allLogs, *usedGas, nil
|
|
|
}
|
|
|
|
|
|
-func applyTransaction(msg types.Message, config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, evm *vm.EVM) (*types.Receipt, error) {
|
|
|
+func applyTransaction(msg types.Message, config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, evm *vm.EVM, receiptProcessors ...ReceiptProcessor) (*types.Receipt, error) {
|
|
|
// Create a new context to be used in the EVM environment.
|
|
|
txContext := NewEVMTxContext(msg)
|
|
|
evm.Reset(txContext, statedb)
|
|
|
@@ -469,10 +475,12 @@ func applyTransaction(msg types.Message, config *params.ChainConfig, bc ChainCon
|
|
|
|
|
|
// Set the receipt logs and create the bloom filter.
|
|
|
receipt.Logs = statedb.GetLogs(tx.Hash())
|
|
|
- receipt.Bloom = types.CreateBloom(types.Receipts{receipt})
|
|
|
receipt.BlockHash = statedb.BlockHash()
|
|
|
receipt.BlockNumber = header.Number
|
|
|
receipt.TransactionIndex = uint(statedb.TxIndex())
|
|
|
+ for _, receiptProcessor := range receiptProcessors {
|
|
|
+ receiptProcessor.Apply(receipt)
|
|
|
+ }
|
|
|
return receipt, err
|
|
|
}
|
|
|
|
|
|
@@ -480,7 +488,7 @@ func applyTransaction(msg types.Message, config *params.ChainConfig, bc ChainCon
|
|
|
// and uses the input parameters for its environment. It returns the receipt
|
|
|
// for the transaction, gas used and an error if the transaction failed,
|
|
|
// indicating the block was invalid.
|
|
|
-func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config) (*types.Receipt, error) {
|
|
|
+func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config, receiptProcessors ...ReceiptProcessor) (*types.Receipt, error) {
|
|
|
msg, err := tx.AsMessage(types.MakeSigner(config, header.Number))
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
@@ -493,5 +501,5 @@ func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *commo
|
|
|
vm.EVMInterpreterPool.Put(ite)
|
|
|
vm.EvmPool.Put(vmenv)
|
|
|
}()
|
|
|
- return applyTransaction(msg, config, bc, author, gp, statedb, header, tx, usedGas, vmenv)
|
|
|
+ return applyTransaction(msg, config, bc, author, gp, statedb, header, tx, usedGas, vmenv, receiptProcessors...)
|
|
|
}
|