diff --git a/core/state_processor.go b/core/state_processor.go index 9297992232b0b..fbef1751f39ba 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -18,6 +18,10 @@ package core import ( "fmt" + "math/big" + "strconv" + "time" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/consensus/misc" @@ -26,7 +30,6 @@ import ( "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/params" - "math/big" ) // StateProcessor is a basic Processor, which takes care of transitioning @@ -56,6 +59,9 @@ func NewStateProcessor(config *params.ChainConfig, bc *BlockChain, engine consen // returns the amount of gas that was used in the process. If any of the // transactions failed to execute due to insufficient gas it will return an error. func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, []*types.Log, uint64, error) { + defer func(start time.Time) { + fmt.Printf("Execution state_process, block_number = %v ,cost time = %v\n", strconv.FormatUint(block.NumberU64(), 10), time.Since(start)) + }(time.Now()) var ( receipts types.Receipts usedGas = new(uint64) @@ -65,7 +71,6 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg allLogs []*types.Log gp = new(GasPool).AddGas(block.GasLimit()) ) - vm.BlockDumpLogger(block, 10000, 100) parityLogContext := vm.ParityLogContext{ @@ -98,6 +103,7 @@ 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) // Iterate over and process the individual transactions + var totalts time.Duration = 0.0 for i, tx := range block.Transactions() { parityLogContext.TxPos = i parityLogContext.TxHash = tx.Hash() @@ -111,12 +117,19 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg if err != nil { return nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err) } + + txstart := time.Now() if err := txLogger.Dump(i, tx, receipt); err != nil { return nil, nil, 0, fmt.Errorf("could not dump tx %d [%v] logger: %w", i, tx.Hash().Hex(), err) } + + totalts += time.Since(txstart) + receipts = append(receipts, receipt) allLogs = append(allLogs, receipt.Logs...) } + + fmt.Printf("Dump transaction, block_number = %v ,cost time = %v\n", strconv.FormatUint(block.NumberU64(), 10), totalts.Seconds()) // Finalize the block, applying any consensus engine specific extras (e.g. block rewards) p.engine.Finalize(p.bc, header, statedb, block.Transactions(), block.Uncles()) vm.ReceiptDumpLogger(block.NumberU64(), 10000, 100, receipts) diff --git a/core/vm/dump_logger.go b/core/vm/dump_logger.go index 4e42f0d374ea9..9f8b117ad81c1 100644 --- a/core/vm/dump_logger.go +++ b/core/vm/dump_logger.go @@ -238,6 +238,9 @@ func (l *ParityLogger) CaptureExit(output []byte, gasUsed uint64, err error) { } func ReceiptDumpLogger(blockNumber uint64, perFolder, perFile uint64, receipts types.Receipts) error { + defer func(start time.Time) { + fmt.Printf("Dump receipt, block_number = %v ,cost time = %v\n", strconv.FormatUint(blockNumber, 10), time.Since(start)) + }(time.Now()) file, err := getFile("receipts", blockNumber, perFolder, perFile) if err != nil { return err @@ -330,6 +333,9 @@ func (t *TxLogger) Close() error { } func BlockDumpLogger(block *types.Block, perFolder, perFile uint64) error { + defer func(start time.Time) { + fmt.Printf("Dump blocks, block_number = %v ,cost time = %v\n", strconv.FormatUint(block.NumberU64(), 10), time.Since(start)) + }(time.Now()) file, err := getFile("blocks", block.NumberU64(), perFolder, perFile) if err != nil { return err