@@ -13,8 +13,10 @@ use crate::metadata::{
13
13
} ;
14
14
use crate :: state_cache:: { PutStateOutcome , StateCache } ;
15
15
use crate :: {
16
- get_data_column_key, metrics, parse_data_column_key, BlobSidecarListFromRoot , DBColumn ,
17
- DatabaseBlock , Error , ItemStore , KeyValueStoreOp , StoreItem , StoreOp ,
16
+ get_data_column_key,
17
+ metrics:: { self , COLD_METRIC , HOT_METRIC } ,
18
+ parse_data_column_key, BlobSidecarListFromRoot , DBColumn , DatabaseBlock , Error , ItemStore ,
19
+ KeyValueStoreOp , StoreItem , StoreOp ,
18
20
} ;
19
21
use itertools:: { process_results, Itertools } ;
20
22
use lru:: LruCache ;
@@ -1567,15 +1569,24 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
1567
1569
from_root : Hash256 ,
1568
1570
ops : & mut Vec < KeyValueStoreOp > ,
1569
1571
) -> Result < ( ) , Error > {
1570
- let base_buffer = self . load_hot_hdiff_buffer ( from_root) . map_err ( |e| {
1571
- Error :: LoadingHotHdiffBufferError (
1572
- format ! ( "store state as diff {state_root:?} {}" , state. slot( ) ) ,
1573
- from_root,
1574
- e. into ( ) ,
1575
- )
1576
- } ) ?;
1572
+ let base_buffer = {
1573
+ let _t = metrics:: start_timer_vec (
1574
+ & metrics:: BEACON_HDIFF_BUFFER_LOAD_BEFORE_STORE_TIME ,
1575
+ HOT_METRIC ,
1576
+ ) ;
1577
+ self . load_hot_hdiff_buffer ( from_root) . map_err ( |e| {
1578
+ Error :: LoadingHotHdiffBufferError (
1579
+ format ! ( "store state as diff {state_root:?} {}" , state. slot( ) ) ,
1580
+ from_root,
1581
+ e. into ( ) ,
1582
+ )
1583
+ } ) ?
1584
+ } ;
1577
1585
let target_buffer = HDiffBuffer :: from_state ( state. clone ( ) ) ;
1578
- let diff = HDiff :: compute ( & base_buffer, & target_buffer, & self . config ) ?;
1586
+ let diff = {
1587
+ let _timer = metrics:: start_timer_vec ( & metrics:: BEACON_HDIFF_COMPUTE_TIME , HOT_METRIC ) ;
1588
+ HDiff :: compute ( & base_buffer, & target_buffer, & self . config ) ?
1589
+ } ;
1579
1590
let diff_bytes = diff. as_ssz_bytes ( ) ;
1580
1591
ops. push ( KeyValueStoreOp :: PutKeyValue (
1581
1592
DBColumn :: BeaconStateHotDiff ,
@@ -1669,7 +1680,11 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
1669
1680
)
1670
1681
} ) ?;
1671
1682
let diff = self . load_hot_hdiff ( state_root) ?;
1672
- diff. apply ( & mut buffer, & self . config ) ?;
1683
+ {
1684
+ let _timer =
1685
+ metrics:: start_timer_vec ( & metrics:: BEACON_HDIFF_APPLY_TIME , HOT_METRIC ) ;
1686
+ diff. apply ( & mut buffer, & self . config ) ?;
1687
+ }
1673
1688
Ok ( buffer)
1674
1689
}
1675
1690
StorageStrategy :: ReplayFrom ( from_slot) => {
@@ -1687,13 +1702,13 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
1687
1702
1688
1703
fn load_hot_hdiff ( & self , state_root : Hash256 ) -> Result < HDiff , Error > {
1689
1704
let bytes = {
1690
- let _t = metrics:: start_timer ( & metrics:: BEACON_HOT_HDIFF_READ_TIMES ) ;
1705
+ let _t = metrics:: start_timer_vec ( & metrics:: BEACON_HDIFF_READ_TIME , HOT_METRIC ) ;
1691
1706
self . hot_db
1692
1707
. get_bytes ( DBColumn :: BeaconStateHotDiff , state_root. as_slice ( ) ) ?
1693
1708
. ok_or ( HotColdDBError :: MissingHotHDiff ( state_root) ) ?
1694
1709
} ;
1695
1710
let hdiff = {
1696
- let _t = metrics:: start_timer ( & metrics:: BEACON_HOT_HDIFF_DECODE_TIMES ) ;
1711
+ let _t = metrics:: start_timer_vec ( & metrics:: BEACON_HDIFF_DECODE_TIME , HOT_METRIC ) ;
1697
1712
HDiff :: from_ssz_bytes ( & bytes) ?
1698
1713
} ;
1699
1714
Ok ( hdiff)
@@ -1721,13 +1736,18 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
1721
1736
{
1722
1737
let mut state = match self . hot_storage_strategy ( slot) ? {
1723
1738
strat @ StorageStrategy :: Snapshot | strat @ StorageStrategy :: DiffFrom ( _) => {
1739
+ let buffer_timer = metrics:: start_timer_vec (
1740
+ & metrics:: BEACON_HDIFF_BUFFER_LOAD_TIME ,
1741
+ HOT_METRIC ,
1742
+ ) ;
1724
1743
let buffer = self . load_hot_hdiff_buffer ( * state_root) . map_err ( |e| {
1725
1744
Error :: LoadingHotHdiffBufferError (
1726
1745
format ! ( "load state {strat:?} {slot}" ) ,
1727
1746
* state_root,
1728
1747
e. into ( ) ,
1729
1748
)
1730
1749
} ) ?;
1750
+ drop ( buffer_timer) ;
1731
1751
let mut state = buffer. as_state ( & self . spec ) ?;
1732
1752
1733
1753
// Immediately rebase the state from diffs on the finalized state so that we
@@ -2006,12 +2026,15 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
2006
2026
) -> Result < ( ) , Error > {
2007
2027
// Load diff base state bytes.
2008
2028
let ( _, base_buffer) = {
2009
- let _t = metrics:: start_timer ( & metrics:: STORE_BEACON_HDIFF_BUFFER_LOAD_FOR_STORE_TIME ) ;
2029
+ let _t = metrics:: start_timer_vec (
2030
+ & metrics:: BEACON_HDIFF_BUFFER_LOAD_BEFORE_STORE_TIME ,
2031
+ COLD_METRIC ,
2032
+ ) ;
2010
2033
self . load_hdiff_buffer_for_slot ( from_slot) ?
2011
2034
} ;
2012
2035
let target_buffer = HDiffBuffer :: from_state ( state. clone ( ) ) ;
2013
2036
let diff = {
2014
- let _timer = metrics:: start_timer ( & metrics:: STORE_BEACON_HDIFF_BUFFER_COMPUTE_TIME ) ;
2037
+ let _timer = metrics:: start_timer_vec ( & metrics:: BEACON_HDIFF_COMPUTE_TIME , COLD_METRIC ) ;
2015
2038
HDiff :: compute ( & base_buffer, & target_buffer, & self . config ) ?
2016
2039
} ;
2017
2040
let diff_bytes = diff. as_ssz_bytes ( ) ;
@@ -2070,7 +2093,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
2070
2093
match self . cold_storage_strategy ( slot) ? {
2071
2094
StorageStrategy :: Snapshot | StorageStrategy :: DiffFrom ( _) => {
2072
2095
let buffer_timer =
2073
- metrics:: start_timer ( & metrics:: STORE_BEACON_HDIFF_BUFFER_LOAD_TIME ) ;
2096
+ metrics:: start_timer_vec ( & metrics:: BEACON_HDIFF_BUFFER_LOAD_TIME , COLD_METRIC ) ;
2074
2097
let ( _, buffer) = self . load_hdiff_buffer_for_slot ( slot) ?;
2075
2098
drop ( buffer_timer) ;
2076
2099
let state = buffer. as_state ( & self . spec ) ?;
@@ -2139,13 +2162,13 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
2139
2162
2140
2163
fn load_hdiff_for_slot ( & self , slot : Slot ) -> Result < HDiff , Error > {
2141
2164
let bytes = {
2142
- let _t = metrics:: start_timer ( & metrics:: BEACON_COLD_HDIFF_READ_TIMES ) ;
2165
+ let _t = metrics:: start_timer_vec ( & metrics:: BEACON_HDIFF_READ_TIME , COLD_METRIC ) ;
2143
2166
self . cold_db
2144
2167
. get_bytes ( DBColumn :: BeaconStateDiff , & slot. as_u64 ( ) . to_be_bytes ( ) ) ?
2145
2168
. ok_or ( HotColdDBError :: MissingHDiff ( slot) ) ?
2146
2169
} ;
2147
2170
let hdiff = {
2148
- let _t = metrics:: start_timer ( & metrics:: BEACON_COLD_HDIFF_DECODE_TIMES ) ;
2171
+ let _t = metrics:: start_timer_vec ( & metrics:: BEACON_HDIFF_DECODE_TIME , COLD_METRIC ) ;
2149
2172
HDiff :: from_ssz_bytes ( & bytes) ?
2150
2173
} ;
2151
2174
Ok ( hdiff)
@@ -2196,7 +2219,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
2196
2219
let diff = self . load_hdiff_for_slot ( slot) ?;
2197
2220
{
2198
2221
let _timer =
2199
- metrics:: start_timer ( & metrics:: STORE_BEACON_HDIFF_BUFFER_APPLY_TIME ) ;
2222
+ metrics:: start_timer_vec ( & metrics:: BEACON_HDIFF_APPLY_TIME , COLD_METRIC ) ;
2200
2223
diff. apply ( & mut buffer, & self . config ) ?;
2201
2224
}
2202
2225
0 commit comments