Skip to content

Commit 0d1b857

Browse files
authored
Merge pull request #1406 from cffls/accurate_chain_execution
Make block execution timer more accurate
2 parents 62e7448 + 99be105 commit 0d1b857

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

consensus/bor/bor.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,7 @@ func (c *Bor) Finalize(chain consensus.ChainHeaderReader, header *types.Header,
832832
}
833833

834834
if IsSprintStart(headerNumber, c.config.CalculateSprint(headerNumber)) {
835+
start := time.Now()
835836
ctx := context.Background()
836837
cx := statefull.ChainContext{Chain: chain, Bor: c}
837838
// check and commit span
@@ -848,6 +849,8 @@ func (c *Bor) Finalize(chain consensus.ChainHeaderReader, header *types.Header,
848849
return
849850
}
850851
}
852+
853+
state.BorConsensusTime = time.Since(start)
851854
}
852855

853856
if err = c.changeContractCodeIfNeeded(headerNumber, state); err != nil {

core/blockchain.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ var (
8282
snapshotStorageReadTimer = metrics.NewRegisteredResettingTimer("chain/snapshot/storage/reads", nil)
8383
snapshotCommitTimer = metrics.NewRegisteredResettingTimer("chain/snapshot/commits", nil)
8484

85+
borConsensusTime = metrics.NewRegisteredTimer("chain/bor/consensus", nil)
86+
8587
blockImportTimer = metrics.NewRegisteredMeter("chain/imports", nil)
8688
triedbCommitTimer = metrics.NewRegisteredTimer("chain/triedb/commits", nil)
8789

@@ -2355,7 +2357,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
23552357
bc.stateSyncFeed.Send(StateSyncEvent{Data: data})
23562358
}
23572359
// BOR
2358-
ptime := time.Since(pstart) - vtime
2360+
ptime := time.Since(pstart) - vtime - statedb.BorConsensusTime
23592361

23602362
proctime := time.Since(start) // processing + validation
23612363

@@ -2374,7 +2376,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
23742376
trieRead += statedb.SnapshotStorageReads + statedb.StorageReads // The time spent on storage read
23752377
blockExecutionTimer.Update(ptime - trieRead) // The time spent on EVM processing
23762378
blockValidationTimer.Update(vtime - (triehash + trieUpdate)) // The time spent on block validation
2377-
2379+
borConsensusTime.Update(statedb.BorConsensusTime) // The time spent on bor consensus (span + state sync)
23782380
// Write the block to the chain and get the status.
23792381
var (
23802382
wstart = time.Now()

core/state/statedb.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ type StateDB struct {
174174
SnapshotCommits time.Duration
175175
TrieDBCommits time.Duration
176176

177+
// Bor metrics
178+
BorConsensusTime time.Duration
179+
177180
AccountUpdated int
178181
StorageUpdated atomic.Int64
179182
AccountDeleted int

0 commit comments

Comments
 (0)