@@ -42,9 +42,10 @@ type BlockValidator struct {
4242 engine consensus.Engine // Consensus engine used for validating
4343
4444 // circuit capacity checker related fields
45- checkCircuitCapacity bool // whether enable circuit capacity check
46- db ethdb.Database // db to store row consumption
47- cMu sync.Mutex // mutex for circuit capacity checker
45+ checkCircuitCapacity bool // whether enable circuit capacity check
46+ db ethdb.Database // TODO: remove this and use bc.db
47+ cMu sync.Mutex // mutex for circuit capacity checker
48+ tracer tracerWrapper
4849 circuitCapacityChecker * circuitcapacitychecker.CircuitCapacityChecker // circuit capacity checker instance
4950}
5051
@@ -62,6 +63,17 @@ func NewBlockValidator(config *params.ChainConfig, blockchain *BlockChain, engin
6263 return validator
6364}
6465
66+ type tracerWrapper interface {
67+ CreateTraceEnvAndGetBlockTrace (* params.ChainConfig , ChainContext , consensus.Engine , ethdb.Database , * state.StateDB , * types.Block , * types.Block , bool ) (* types.BlockTrace , error )
68+ }
69+
70+ func (v * BlockValidator ) SetupTracerAndCircuitCapacityChecker (tracer tracerWrapper ) {
71+ v .checkCircuitCapacity = true
72+ v .tracer = tracer
73+ v .circuitCapacityChecker = circuitcapacitychecker .NewCircuitCapacityChecker (true )
74+ log .Info ("created new BlockValidator" , "CircuitCapacityChecker ID" , v .circuitCapacityChecker .ID )
75+ }
76+
6577// ValidateBody validates the given block's uncles and verifies the block
6678// header's transaction and uncle roots. The headers are assumed to be already
6779// validated at this point.
@@ -260,7 +272,7 @@ func CalcGasLimit(parentGasLimit, desiredLimit uint64) uint64 {
260272 return limit
261273}
262274
263- func (v * BlockValidator ) createTraceEnv (block * types.Block ) (* TraceEnv , error ) {
275+ func (v * BlockValidator ) createTraceEnvAndGetBlockTrace (block * types.Block ) (* types. BlockTrace , error ) {
264276 parent := v .bc .GetBlock (block .ParentHash (), block .NumberU64 ()- 1 )
265277 if parent == nil {
266278 return nil , errors .New ("validateCircuitRowConsumption: no parent block found" )
@@ -271,7 +283,7 @@ func (v *BlockValidator) createTraceEnv(block *types.Block) (*TraceEnv, error) {
271283 return nil , err
272284 }
273285
274- return CreateTraceEnv (v .config , v .bc , v .engine , v .db , statedb , parent , block , true )
286+ return v . tracer . CreateTraceEnvAndGetBlockTrace (v .config , v .bc , v .engine , v .db , statedb , parent , block , true )
275287}
276288
277289func (v * BlockValidator ) validateCircuitRowConsumption (block * types.Block ) (* types.RowConsumption , error ) {
@@ -283,12 +295,7 @@ func (v *BlockValidator) validateCircuitRowConsumption(block *types.Block) (*typ
283295 "len(txs)" , block .Transactions ().Len (),
284296 )
285297
286- env , err := v .createTraceEnv (block )
287- if err != nil {
288- return nil , err
289- }
290-
291- traces , err := env .GetBlockTrace (block )
298+ traces , err := v .createTraceEnvAndGetBlockTrace (block )
292299 if err != nil {
293300 return nil , err
294301 }
0 commit comments