@@ -35,7 +35,7 @@ use ethportal_api::{
35
35
OverlayContentKey , RawContentKey , RawContentValue ,
36
36
} ;
37
37
use futures:: { channel:: oneshot, future:: join_all, prelude:: * } ;
38
- use parking_lot:: RwLock ;
38
+ use parking_lot:: { Mutex , RwLock } ;
39
39
use rand:: Rng ;
40
40
use smallvec:: SmallVec ;
41
41
use ssz:: Encode ;
@@ -121,7 +121,7 @@ impl<
121
121
#[ allow( clippy:: too_many_arguments) ]
122
122
pub async fn spawn (
123
123
discovery : Arc < Discovery > ,
124
- store : Arc < RwLock < TStore > > ,
124
+ store : Arc < Mutex < TStore > > ,
125
125
kbuckets : SharedKBucketsTable ,
126
126
bootnode_enrs : Vec < Enr > ,
127
127
ping_queue_interval : Option < Duration > ,
@@ -376,7 +376,7 @@ impl<
376
376
/// This requires store lock and can block the thread, so it shouldn't be called other lock is
377
377
/// already held.
378
378
pub ( super ) fn data_radius ( & self ) -> Distance {
379
- self . store . read ( ) . radius ( )
379
+ self . store . lock ( ) . radius ( )
380
380
}
381
381
382
382
/// Maintains the routing table.
@@ -928,7 +928,7 @@ impl<
928
928
}
929
929
} ;
930
930
match (
931
- self . store . read ( ) . get ( & content_key) ,
931
+ self . store . lock ( ) . get ( & content_key) ,
932
932
self . utp_controller . get_outbound_semaphore ( ) ,
933
933
) {
934
934
( Ok ( Some ( content) ) , Some ( permit) ) => {
@@ -1045,7 +1045,7 @@ impl<
1045
1045
// Accept content if within radius and not already present in the data store.
1046
1046
let mut accept = self
1047
1047
. store
1048
- . read ( )
1048
+ . lock ( )
1049
1049
. is_key_within_radius_and_unavailable ( key)
1050
1050
. map ( |value| matches ! ( value, ShouldWeStoreContent :: Store ) )
1051
1051
. map_err ( |err| {
@@ -1552,15 +1552,11 @@ impl<
1552
1552
// already stored.
1553
1553
let key_desired = utp_processing
1554
1554
. store
1555
- . read ( )
1555
+ . lock ( )
1556
1556
. is_key_within_radius_and_unavailable ( & key) ;
1557
1557
match key_desired {
1558
1558
Ok ( ShouldWeStoreContent :: Store ) => {
1559
- match utp_processing
1560
- . store
1561
- . write ( )
1562
- . put ( key. clone ( ) , & content_value)
1563
- {
1559
+ match utp_processing. store . lock ( ) . put ( key. clone ( ) , & content_value) {
1564
1560
Ok ( dropped_content) => {
1565
1561
if !dropped_content. is_empty ( ) && utp_processing. gossip_dropped {
1566
1562
// add dropped content to validation result, so it will be propagated
@@ -1755,7 +1751,7 @@ impl<
1755
1751
) {
1756
1752
let mut content = content;
1757
1753
// Operate under assumption that all content in the store is valid
1758
- let local_value = utp_processing. store . read ( ) . get ( & content_key) ;
1754
+ let local_value = utp_processing. store . lock ( ) . get ( & content_key) ;
1759
1755
if let Ok ( Some ( val) ) = local_value {
1760
1756
// todo validate & replace content value if different & punish bad peer
1761
1757
content = val;
@@ -1796,7 +1792,7 @@ impl<
1796
1792
let should_store = validation_result. valid_for_storing
1797
1793
&& utp_processing
1798
1794
. store
1799
- . read ( )
1795
+ . lock ( )
1800
1796
. is_key_within_radius_and_unavailable ( & content_key)
1801
1797
. map_or_else (
1802
1798
|err| {
@@ -1808,7 +1804,7 @@ impl<
1808
1804
if should_store {
1809
1805
match utp_processing
1810
1806
. store
1811
- . write ( )
1807
+ . lock ( )
1812
1808
. put ( content_key. clone ( ) , content. clone ( ) )
1813
1809
{
1814
1810
Ok ( dropped_content) => {
@@ -1889,7 +1885,7 @@ impl<
1889
1885
1890
1886
/// Provide the requested content key and content value for the acceptor
1891
1887
fn provide_requested_content (
1892
- store : Arc < RwLock < TStore > > ,
1888
+ store : Arc < Mutex < TStore > > ,
1893
1889
accept_message : & Accept ,
1894
1890
content_keys_offered : Vec < RawContentKey > ,
1895
1891
) -> anyhow:: Result < Vec < RawContentValue > > {
@@ -1910,7 +1906,7 @@ impl<
1910
1906
. zip ( content_keys_offered. iter ( ) )
1911
1907
{
1912
1908
if i {
1913
- match store. read ( ) . get ( key) {
1909
+ match store. lock ( ) . get ( key) {
1914
1910
Ok ( content) => match content {
1915
1911
Some ( content) => content_items. push ( content) ,
1916
1912
None => return Err ( anyhow ! ( "Unable to read offered content!" ) ) ,
@@ -2198,7 +2194,7 @@ impl<
2198
2194
debug ! ( "Starting query for content key: {}" , target) ;
2199
2195
2200
2196
// Lookup content locally before querying the network.
2201
- if let Ok ( Some ( content) ) = self . store . read ( ) . get ( & target) {
2197
+ if let Ok ( Some ( content) ) = self . store . lock ( ) . get ( & target) {
2202
2198
let local_enr = self . local_enr ( ) ;
2203
2199
let mut query_trace = QueryTrace :: new ( & local_enr, target. content_id ( ) . into ( ) ) ;
2204
2200
query_trace. node_responded_with_content ( & local_enr) ;
@@ -2369,7 +2365,7 @@ where
2369
2365
TStore : ContentStore < Key = TContentKey > ,
2370
2366
{
2371
2367
validator : Arc < TValidator > ,
2372
- store : Arc < RwLock < TStore > > ,
2368
+ store : Arc < Mutex < TStore > > ,
2373
2369
metrics : OverlayMetricsReporter ,
2374
2370
kbuckets : SharedKBucketsTable ,
2375
2371
command_tx : UnboundedSender < OverlayCommand < TContentKey > > ,
@@ -2462,6 +2458,7 @@ mod tests {
2462
2458
portal_wire:: { Ping , Pong , MAINNET } ,
2463
2459
} ;
2464
2460
use kbucket:: KBucketsTable ;
2461
+ use parking_lot:: lock_api:: Mutex ;
2465
2462
use rstest:: * ;
2466
2463
use serial_test:: serial;
2467
2464
use tokio:: {
@@ -2524,7 +2521,7 @@ mod tests {
2524
2521
2525
2522
let node_id = discovery. local_enr ( ) . node_id ( ) ;
2526
2523
let store = MemoryContentStore :: new ( node_id, DistanceFunction :: Xor ) ;
2527
- let store = Arc :: new ( RwLock :: new ( store) ) ;
2524
+ let store = Arc :: new ( Mutex :: new ( store) ) ;
2528
2525
2529
2526
let overlay_config = OverlayConfig :: default ( ) ;
2530
2527
let kbuckets = SharedKBucketsTable :: new ( KBucketsTable :: new (
0 commit comments