@@ -19,6 +19,7 @@ package core
19
19
import (
20
20
"fmt"
21
21
"math/big"
22
+ "time"
22
23
23
24
"github.com/scroll-tech/go-ethereum/common"
24
25
"github.com/scroll-tech/go-ethereum/consensus"
@@ -32,7 +33,14 @@ import (
32
33
"github.com/scroll-tech/go-ethereum/rollup/fees"
33
34
)
34
35
35
- var processorBlockTransactionGauge = metrics .NewRegisteredGauge ("processor/block/transactions" , nil )
36
+ var (
37
+ processorBlockTransactionGauge = metrics .NewRegisteredGauge ("processor/block/transactions" , nil )
38
+ processBlockTimer = metrics .NewRegisteredTimer ("processor/block/process" , nil )
39
+ finalizeBlockTimer = metrics .NewRegisteredTimer ("processor/block/finalize" , nil )
40
+ applyTransactionTimer = metrics .NewRegisteredTimer ("processor/tx/apply" , nil )
41
+ applyMessageTimer = metrics .NewRegisteredTimer ("processor/tx/msg/apply" , nil )
42
+ updateStatedbTimer = metrics .NewRegisteredTimer ("processor/tx/statedb/update" , nil )
43
+ )
36
44
37
45
// StateProcessor is a basic Processor, which takes care of transitioning
38
46
// state from one point to another.
@@ -61,6 +69,10 @@ func NewStateProcessor(config *params.ChainConfig, bc *BlockChain, engine consen
61
69
// returns the amount of gas that was used in the process. If any of the
62
70
// transactions failed to execute due to insufficient gas it will return an error.
63
71
func (p * StateProcessor ) Process (block * types.Block , statedb * state.StateDB , cfg vm.Config ) (types.Receipts , []* types.Log , uint64 , error ) {
72
+ defer func (t0 time.Time ) {
73
+ processBlockTimer .Update (time .Since (t0 ))
74
+ }(time .Now ())
75
+
64
76
var (
65
77
receipts types.Receipts
66
78
usedGas = new (uint64 )
@@ -92,12 +104,18 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
92
104
allLogs = append (allLogs , receipt .Logs ... )
93
105
}
94
106
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
107
+ finalizeBlockStartTime := time .Now ()
95
108
p .engine .Finalize (p .bc , header , statedb , block .Transactions (), block .Uncles ())
109
+ finalizeBlockTimer .Update (time .Since (finalizeBlockStartTime ))
96
110
97
111
return receipts , allLogs , * usedGas , nil
98
112
}
99
113
100
114
func applyTransaction (msg types.Message , config * params.ChainConfig , bc ChainContext , author * common.Address , gp * GasPool , statedb * state.StateDB , blockNumber * big.Int , blockHash common.Hash , tx * types.Transaction , usedGas * uint64 , evm * vm.EVM ) (* types.Receipt , error ) {
115
+ defer func (t0 time.Time ) {
116
+ applyTransactionTimer .Update (time .Since (t0 ))
117
+ }(time .Now ())
118
+
101
119
// Create a new context to be used in the EVM environment.
102
120
txContext := NewEVMTxContext (msg )
103
121
evm .Reset (txContext , statedb )
@@ -108,18 +126,22 @@ func applyTransaction(msg types.Message, config *params.ChainConfig, bc ChainCon
108
126
}
109
127
110
128
// Apply the transaction to the current state (included in the env).
129
+ applyMessageStartTime := time .Now ()
111
130
result , err := ApplyMessage (evm , msg , gp , l1DataFee )
131
+ applyMessageTimer .Update (time .Since (applyMessageStartTime ))
112
132
if err != nil {
113
133
return nil , err
114
134
}
115
135
116
136
// Update the state with pending changes.
117
137
var root []byte
138
+ updateStatedbStartTime := time .Now ()
118
139
if config .IsByzantium (blockNumber ) {
119
140
statedb .Finalise (true )
120
141
} else {
121
142
root = statedb .IntermediateRoot (config .IsEIP158 (blockNumber )).Bytes ()
122
143
}
144
+ updateStatedbTimer .Update (time .Since (updateStatedbStartTime ))
123
145
* usedGas += result .UsedGas
124
146
125
147
// If the result contains a revert reason, return it.
0 commit comments