@@ -207,9 +207,9 @@ type BlockChain struct {
207
207
procInterrupt atomic.Bool // interrupt signaler for block processing
208
208
209
209
engine consensus.Engine
210
- validator Validator // Block and state validator interface
211
- prefetcher Prefetcher // Block state prefetcher interface
212
- processor Processor // Block transaction processor interface
210
+ validator Validator // Block and state validator interface
211
+ prefetcher Prefetcher
212
+ processor Processor // Block transaction processor interface
213
213
vmConfig vm.Config
214
214
215
215
IPCEndpoint string
@@ -1723,6 +1723,9 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
1723
1723
if err != nil {
1724
1724
return it .index , events , coalescedLogs , err
1725
1725
}
1726
+ // Enable prefetching to pull in trie node paths while processing transactions
1727
+ statedb .StartPrefetcher ("chain" )
1728
+ defer statedb .StopPrefetcher () // stopped on write anyway, defer meant to catch early error returns
1726
1729
1727
1730
// If we have a followup block, run that against the current state to pre-cache
1728
1731
// transactions and probabilistically some of the account/storage trie nodes.
@@ -1740,9 +1743,8 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
1740
1743
}(time .Now ())
1741
1744
}
1742
1745
}
1743
-
1744
1746
// Process block using the parent state as reference point.
1745
- t0 := time .Now ()
1747
+ substart := time .Now ()
1746
1748
isTIPXDCXReceiver := bc .Config ().IsTIPXDCXReceiver (block .Number ())
1747
1749
tradingState , lendingState , err := bc .processTradingAndLendingStates (isTIPXDCXReceiver , block , parent , statedb )
1748
1750
if err != nil {
@@ -1752,47 +1754,50 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
1752
1754
}
1753
1755
feeCapacity := state .GetTRC21FeeCapacityFromStateWithCache (parent .Root , statedb )
1754
1756
receipts , logs , usedGas , err := bc .processor .Process (block , statedb , tradingState , bc .vmConfig , feeCapacity )
1755
- t1 := time .Now ()
1756
1757
if err != nil {
1757
1758
bc .reportBlock (block , receipts , err )
1758
1759
followupInterrupt .Store (true )
1759
1760
return it .index , events , coalescedLogs , err
1760
1761
}
1762
+ // Update the metrics touched during block processing
1763
+ accountReadTimer .Update (statedb .AccountReads ) // Account reads are complete, we can mark them
1764
+ storageReadTimer .Update (statedb .StorageReads ) // Storage reads are complete, we can mark them
1765
+ accountUpdateTimer .Update (statedb .AccountUpdates ) // Account updates are complete, we can mark them
1766
+ storageUpdateTimer .Update (statedb .StorageUpdates ) // Storage updates are complete, we can mark them
1767
+ triehash := statedb .AccountHashes + statedb .StorageHashes // Save to not double count in validation
1768
+ trieproc := statedb .AccountReads + statedb .AccountUpdates
1769
+ trieproc += statedb .StorageReads + statedb .StorageUpdates
1770
+
1771
+ blockExecutionTimer .Update (time .Since (substart ) - trieproc - triehash )
1772
+
1761
1773
// Validate the state using the default validator
1774
+ substart = time .Now ()
1762
1775
err = bc .validator .ValidateState (block , statedb , receipts , usedGas )
1763
1776
if err != nil {
1764
1777
bc .reportBlock (block , receipts , err )
1765
1778
return it .index , events , coalescedLogs , err
1766
1779
}
1767
- t2 := time .Now ()
1768
1780
proctime := time .Since (start )
1769
1781
1782
+ // Update the metrics touched during block validation
1783
+ accountHashTimer .Update (statedb .AccountHashes ) // Account hashes are complete, we can mark them
1784
+ storageHashTimer .Update (statedb .StorageHashes ) // Storage hashes are complete, we can mark them
1785
+
1786
+ blockValidationTimer .Update (time .Since (substart ) - (statedb .AccountHashes + statedb .StorageHashes - triehash ))
1787
+
1770
1788
// Write the block to the chain and get the status.
1789
+ substart = time .Now ()
1771
1790
status , err := bc .writeBlockWithState (block , receipts , statedb , tradingState , lendingState )
1772
- t3 := time .Now ()
1773
1791
followupInterrupt .Store (true )
1774
1792
if err != nil {
1775
1793
return it .index , events , coalescedLogs , err
1776
1794
}
1795
+ // Update the metrics touched during block commit
1796
+ accountCommitTimer .Update (statedb .AccountCommits ) // Account commits are complete, we can mark them
1797
+ storageCommitTimer .Update (statedb .StorageCommits ) // Storage commits are complete, we can mark them
1777
1798
1778
- // Update the metrics subsystem with all the measurements
1779
- accountReadTimer .Update (statedb .AccountReads )
1780
- accountHashTimer .Update (statedb .AccountHashes )
1781
- accountUpdateTimer .Update (statedb .AccountUpdates )
1782
- accountCommitTimer .Update (statedb .AccountCommits )
1783
-
1784
- storageReadTimer .Update (statedb .StorageReads )
1785
- storageHashTimer .Update (statedb .StorageHashes )
1786
- storageUpdateTimer .Update (statedb .StorageUpdates )
1787
- storageCommitTimer .Update (statedb .StorageCommits )
1788
-
1789
- trieAccess := statedb .AccountReads + statedb .AccountHashes + statedb .AccountUpdates + statedb .AccountCommits
1790
- trieAccess += statedb .StorageReads + statedb .StorageHashes + statedb .StorageUpdates + statedb .StorageCommits
1791
-
1799
+ blockWriteTimer .Update (time .Since (substart ) - statedb .AccountCommits - statedb .StorageCommits )
1792
1800
blockInsertTimer .UpdateSince (start )
1793
- blockExecutionTimer .Update (t1 .Sub (t0 ) - trieAccess )
1794
- blockValidationTimer .Update (t2 .Sub (t1 ))
1795
- blockWriteTimer .Update (t3 .Sub (t2 ))
1796
1801
1797
1802
switch status {
1798
1803
case CanonStatTy :
@@ -1816,7 +1821,6 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
1816
1821
events = append (events , ChainSideEvent {block })
1817
1822
bc .UpdateBlocksHashCache (block )
1818
1823
}
1819
- blockInsertTimer .UpdateSince (start )
1820
1824
stats .processed ++
1821
1825
stats .usedGas += usedGas
1822
1826
0 commit comments