|
1 | | -use std::{ |
2 | | - cell::Cell, |
3 | | - collections::HashMap, |
4 | | - sync::{Arc, OnceLock}, |
5 | | -}; |
| 1 | +use std::{cell::Cell, collections::HashMap, sync::Arc}; |
6 | 2 |
|
7 | | -use dashmap::DashMap; |
8 | 3 | use itertools::Itertools; |
9 | 4 | use kaspa_consensus_core::{BlockHashMap, BlockHashSet, HashMapCustomHasher, KType}; |
10 | | -use kaspa_core::{debug, trace}; |
| 5 | +use kaspa_core::debug; |
11 | 6 | use kaspa_hashes::Hash; |
12 | 7 | use kaspa_math::Uint192; |
13 | 8 | use parking_lot::RwLock; |
@@ -87,51 +82,6 @@ use crate::{ |
87 | 82 | 3. switch GD/k-coloring to committed coloring |
88 | 83 | */ |
89 | 84 |
|
90 | | -/// TODO[DK]: If writes here are moved out or batched, revisit this |
91 | | -/// Global lock map for conflict genesis level locking |
92 | | -/// Maps conflict genesis hashes to their respective locks |
93 | | -static CONFLICT_LOCKS: OnceLock<DashMap<Hash, Arc<RwLock<()>>>> = OnceLock::new(); |
94 | | - |
95 | | -fn get_conflict_locks() -> &'static DashMap<Hash, Arc<RwLock<()>>> { |
96 | | - CONFLICT_LOCKS.get_or_init(DashMap::new) |
97 | | -} |
98 | | - |
99 | | -/// Cleans up unused locks from the global lock map. |
100 | | -/// A lock is considered unused if its Arc strong count is 1 (only the map holds a reference). |
101 | | -/// This should be called periodically or opportunistically to prevent unbounded growth. |
102 | | -pub fn cleanup_conflict_locks() { |
103 | | - let locks = get_conflict_locks(); |
104 | | - let mut to_remove = Vec::new(); |
105 | | - |
106 | | - // First pass: identify locks with no external references |
107 | | - for entry in locks.iter() { |
108 | | - let hash = *entry.key(); |
109 | | - let arc = entry.value(); |
110 | | - // If strong count is 1, only the DashMap holds a reference |
111 | | - if Arc::strong_count(arc) == 1 { |
112 | | - to_remove.push(hash); |
113 | | - } |
114 | | - } |
115 | | - |
116 | | - // Second pass: remove identified locks |
117 | | - // Note: by the time we remove, another thread might have acquired the lock, |
118 | | - // so we double-check the count before removing |
119 | | - let mut removed_count = 0; |
120 | | - for hash in to_remove { |
121 | | - if let Some(entry) = locks.get(&hash) |
122 | | - && Arc::strong_count(entry.value()) == 1 |
123 | | - { |
124 | | - drop(entry); // Release the reference before removing |
125 | | - locks.remove(&hash); |
126 | | - removed_count += 1; |
127 | | - } |
128 | | - } |
129 | | - |
130 | | - if removed_count > 0 { |
131 | | - trace!("Cleaned up {} unused conflict locks, {} remaining", removed_count, locks.len()); |
132 | | - } |
133 | | -} |
134 | | - |
135 | 85 | /// A struct encapsulating the logic and algorithms of the DAGKNIGHT protocol |
136 | 86 | #[derive(Clone)] |
137 | 87 | pub struct DagknightExecutor< |
@@ -261,9 +211,6 @@ impl< |
261 | 211 |
|
262 | 212 | debug!("dk::sp: {} | conflict_ordered_parents: {:?}", curr_subgroup[0], conflict_ordered_parents); |
263 | 213 |
|
264 | | - // Opportunistically cleanup unused locks after processing |
265 | | - cleanup_conflict_locks(); |
266 | | - |
267 | 214 | DagknightData { selected_parent: curr_subgroup[0], conflict_ordered_parents } |
268 | 215 | } |
269 | 216 |
|
@@ -505,11 +452,6 @@ impl< |
505 | 452 | reachability_service.clone(), |
506 | 453 | ); |
507 | 454 |
|
508 | | - // Acquire a lock for this conflict_genesis to prevent concurrent writes |
509 | | - let locks = get_conflict_locks(); |
510 | | - let lock_arc = locks.entry(conflict_genesis).or_insert_with(|| Arc::new(RwLock::new(()))).clone(); |
511 | | - let _lock = lock_arc.write(); |
512 | | - |
513 | 455 | conflict_zone_manager.fill_zone_data(all_tips); |
514 | 456 |
|
515 | 457 | // selected a parent in this subgroup => Conditioned upon virtual agreeing with this subgroup |
|
0 commit comments