@@ -22,9 +22,6 @@ use dashcore::blockdata::block::Header;
2222use dashcore:: network:: message_headers2:: { CompressedHeader , CompressionState , DecompressionError } ;
2323use std:: collections:: HashMap ;
2424
25- /// Size of an uncompressed block header in bytes
26- const UNCOMPRESSED_HEADER_SIZE : usize = 80 ;
27-
2825/// Error types for headers2 processing
2926#[ derive( Debug , Clone ) ]
3027pub enum ProcessError {
@@ -54,23 +51,13 @@ impl std::error::Error for ProcessError {}
5451pub struct Headers2StateManager {
5552 /// Compression state per peer
5653 peer_states : HashMap < PeerId , CompressionState > ,
57-
58- /// Statistics
59- pub total_headers_received : u64 ,
60- pub compressed_headers_received : u64 ,
61- pub bytes_saved : u64 ,
62- pub total_bytes_received : u64 ,
6354}
6455
6556impl Headers2StateManager {
6657 /// Create a new Headers2StateManager
6758 pub fn new ( ) -> Self {
6859 Self {
6960 peer_states : HashMap :: new ( ) ,
70- total_headers_received : 0 ,
71- compressed_headers_received : 0 ,
72- bytes_saved : 0 ,
73- total_bytes_received : 0 ,
7461 }
7562 }
7663
@@ -117,15 +104,6 @@ impl Headers2StateManager {
117104
118105 // Process headers and collect statistics
119106 for ( i, compressed) in headers. iter ( ) . enumerate ( ) {
120- // Update statistics
121- self . total_headers_received += 1 ;
122- self . total_bytes_received += compressed. encoded_size ( ) as u64 ;
123-
124- if compressed. is_compressed ( ) {
125- self . compressed_headers_received += 1 ;
126- self . bytes_saved += compressed. bytes_saved ( ) as u64 ;
127- }
128-
129107 // Get state and decompress
130108 let state = self . get_state ( peer_id) ;
131109 let header =
@@ -141,58 +119,6 @@ impl Headers2StateManager {
141119 pub fn reset_peer ( & mut self , peer_id : PeerId ) {
142120 self . peer_states . remove ( & peer_id) ;
143121 }
144-
145- /// Get compression ratio
146- pub fn compression_ratio ( & self ) -> f64 {
147- if self . total_headers_received == 0 {
148- 0.0
149- } else {
150- self . compressed_headers_received as f64 / self . total_headers_received as f64
151- }
152- }
153-
154- /// Get bandwidth savings percentage
155- pub fn bandwidth_savings ( & self ) -> f64 {
156- if self . total_bytes_received == 0 {
157- 0.0
158- } else {
159- let uncompressed_size = self . total_headers_received as usize * UNCOMPRESSED_HEADER_SIZE ;
160- let savings = ( uncompressed_size - self . total_bytes_received as usize ) as f64 ;
161- ( savings / uncompressed_size as f64 ) * 100.0
162- }
163- }
164-
165- /// Get detailed statistics
166- pub fn get_stats ( & self ) -> Headers2Stats {
167- Headers2Stats {
168- total_headers : self . total_headers_received ,
169- compressed_headers : self . compressed_headers_received ,
170- bytes_saved : self . bytes_saved ,
171- total_bytes_received : self . total_bytes_received ,
172- compression_ratio : self . compression_ratio ( ) ,
173- bandwidth_savings : self . bandwidth_savings ( ) ,
174- active_peers : self . peer_states . len ( ) ,
175- }
176- }
177- }
178-
179- /// Statistics about headers2 compression
180- #[ derive( Debug , Clone ) ]
181- pub struct Headers2Stats {
182- /// Total number of headers received
183- pub total_headers : u64 ,
184- /// Number of headers that were compressed
185- pub compressed_headers : u64 ,
186- /// Bytes saved through compression
187- pub bytes_saved : u64 ,
188- /// Total bytes received (compressed)
189- pub total_bytes_received : u64 ,
190- /// Ratio of compressed to total headers
191- pub compression_ratio : f64 ,
192- /// Bandwidth savings percentage
193- pub bandwidth_savings : f64 ,
194- /// Number of peers with active compression state
195- pub active_peers : usize ,
196122}
197123
198124#[ cfg( test) ]
@@ -236,11 +162,6 @@ mod tests {
236162 assert_eq ! ( decompressed. len( ) , 2 ) ;
237163 assert_eq ! ( decompressed[ 0 ] , header1) ;
238164 assert_eq ! ( decompressed[ 1 ] , header2) ;
239-
240- // Check statistics
241- assert_eq ! ( manager. total_headers_received, 2 ) ;
242- assert ! ( manager. compressed_headers_received > 0 ) ;
243- assert ! ( manager. bytes_saved > 0 ) ;
244165 }
245166
246167 #[ test]
@@ -277,15 +198,4 @@ mod tests {
277198 manager. reset_peer ( peer_id) ;
278199 assert_eq ! ( manager. peer_states. len( ) , 0 ) ;
279200 }
280-
281- #[ test]
282- fn test_statistics ( ) {
283- let manager = Headers2StateManager :: new ( ) ;
284- let stats = manager. get_stats ( ) ;
285-
286- assert_eq ! ( stats. total_headers, 0 ) ;
287- assert_eq ! ( stats. compression_ratio, 0.0 ) ;
288- assert_eq ! ( stats. bandwidth_savings, 0.0 ) ;
289- assert_eq ! ( stats. active_peers, 0 ) ;
290- }
291201}
0 commit comments