@@ -20,6 +20,7 @@ import (
20
20
"errors"
21
21
"fmt"
22
22
"math/big"
23
+ "time"
23
24
24
25
"github.com/scroll-tech/go-ethereum/common"
25
26
"github.com/scroll-tech/go-ethereum/consensus"
@@ -28,10 +29,20 @@ import (
28
29
"github.com/scroll-tech/go-ethereum/core/types"
29
30
"github.com/scroll-tech/go-ethereum/core/vm"
30
31
"github.com/scroll-tech/go-ethereum/crypto"
32
+ "github.com/scroll-tech/go-ethereum/metrics"
31
33
"github.com/scroll-tech/go-ethereum/params"
32
34
"github.com/scroll-tech/go-ethereum/rollup/fees"
33
35
)
34
36
37
+ var (
38
+ processorBlockTransactionGauge = metrics .NewRegisteredGauge ("processor/block/transactions" , nil )
39
+ processBlockTimer = metrics .NewRegisteredTimer ("processor/block/process" , nil )
40
+ finalizeBlockTimer = metrics .NewRegisteredTimer ("processor/block/finalize" , nil )
41
+ applyTransactionTimer = metrics .NewRegisteredTimer ("processor/tx/apply" , nil )
42
+ applyMessageTimer = metrics .NewRegisteredTimer ("processor/tx/msg/apply" , nil )
43
+ updateStatedbTimer = metrics .NewRegisteredTimer ("processor/tx/statedb/update" , nil )
44
+ )
45
+
35
46
// StateProcessor is a basic Processor, which takes care of transitioning
36
47
// state from one point to another.
37
48
//
@@ -59,6 +70,10 @@ func NewStateProcessor(config *params.ChainConfig, bc *BlockChain, engine consen
59
70
// returns the amount of gas that was used in the process. If any of the
60
71
// transactions failed to execute due to insufficient gas it will return an error.
61
72
func (p * StateProcessor ) Process (block * types.Block , statedb * state.StateDB , cfg vm.Config ) (types.Receipts , []* types.Log , uint64 , error ) {
73
+ defer func (t0 time.Time ) {
74
+ processBlockTimer .Update (time .Since (t0 ))
75
+ }(time .Now ())
76
+
62
77
var (
63
78
receipts types.Receipts
64
79
usedGas = new (uint64 )
@@ -84,6 +99,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
84
99
if beaconRoot := block .BeaconRoot (); beaconRoot != nil {
85
100
ProcessBeaconBlockRoot (* beaconRoot , vmenv , statedb )
86
101
}
102
+ processorBlockTransactionGauge .Update (int64 (block .Transactions ().Len ()))
87
103
// Iterate over and process the individual transactions
88
104
for i , tx := range block .Transactions () {
89
105
msg , err := TransactionToMessage (tx , signer , header .BaseFee )
@@ -104,12 +120,18 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
104
120
return nil , nil , 0 , errors .New ("withdrawals before shanghai" )
105
121
}
106
122
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
123
+ finalizeBlockStartTime := time .Now ()
107
124
p .engine .Finalize (p .bc , header , statedb , block .Transactions (), block .Uncles (), withdrawals )
125
+ finalizeBlockTimer .Update (time .Since (finalizeBlockStartTime ))
108
126
109
127
return receipts , allLogs , * usedGas , nil
110
128
}
111
129
112
130
func applyTransaction (msg * Message , config * params.ChainConfig , gp * GasPool , statedb * state.StateDB , blockNumber * big.Int , blockHash common.Hash , tx * types.Transaction , usedGas * uint64 , evm * vm.EVM ) (* types.Receipt , error ) {
131
+ defer func (t0 time.Time ) {
132
+ applyTransactionTimer .Update (time .Since (t0 ))
133
+ }(time .Now ())
134
+
113
135
// Create a new context to be used in the EVM environment.
114
136
txContext := NewEVMTxContext (msg )
115
137
evm .Reset (txContext , statedb )
@@ -120,18 +142,22 @@ func applyTransaction(msg *Message, config *params.ChainConfig, gp *GasPool, sta
120
142
}
121
143
122
144
// Apply the transaction to the current state (included in the env).
145
+ applyMessageStartTime := time .Now ()
123
146
result , err := ApplyMessage (evm , msg , gp , l1DataFee )
147
+ applyMessageTimer .Update (time .Since (applyMessageStartTime ))
124
148
if err != nil {
125
149
return nil , err
126
150
}
127
151
128
152
// Update the state with pending changes.
129
153
var root []byte
154
+ updateStatedbStartTime := time .Now ()
130
155
if config .IsByzantium (blockNumber ) {
131
156
statedb .Finalise (true )
132
157
} else {
133
158
root = statedb .IntermediateRoot (config .IsEIP158 (blockNumber )).Bytes ()
134
159
}
160
+ updateStatedbTimer .Update (time .Since (updateStatedbStartTime ))
135
161
* usedGas += result .UsedGas
136
162
137
163
// Create a new receipt for the transaction, storing the intermediate root and gas used
0 commit comments