Skip to content

Commit f7443fb

Browse files
requested changes
1 parent fc6fd54 commit f7443fb

File tree

2 files changed

+21
-26
lines changed

2 files changed

+21
-26
lines changed

common/src/attestations/dispute_manager.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
use anyhow::Error;
45
use graphql_client::GraphQLQuery;
56
use std::time::Duration;
67
use thegraph_core::Address;
@@ -35,14 +36,11 @@ pub fn dispute_manager(
3536
let result = async {
3637
let response = network_subgraph
3738
.query::<DisputeManager, _>(dispute_manager::Variables {})
38-
.await
39-
.map_err(|e| e.to_string())?;
40-
41-
response.map_err(|e| e.to_string()).and_then(|data| {
42-
data.graph_network
43-
.map(|network| network.dispute_manager)
44-
.ok_or_else(|| "Network 1 not found in network subgraph".to_string())
45-
})
39+
.await?;
40+
response?
41+
.graph_network
42+
.map(|network| network.dispute_manager)
43+
.ok_or_else(|| Error::msg("Network 1 not found in network subgraph"))
4644
}
4745
.await;
4846

common/src/attestations/signers.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ pub fn attestation_signers(
2525
Box::leak(Box::new(Mutex::new(HashMap::new())));
2626

2727
// Whenever the indexer's active or recently closed allocations change, make sure
28-
// we have attestation signers for all of them
28+
// we have attestation signers for all of them.
2929
let (mut signers_writer, signers_reader) =
3030
Eventual::<HashMap<Address, AttestationSigner>>::new();
3131

3232
tokio::spawn(async move {
33-
//listening to the allocation eventual and converting them to reciever
34-
//using pipe for updation
35-
//for temporary pupose only
33+
// Listening to the allocation eventual and converting them to reciever.
34+
// Using pipe for updation.
35+
// For temporary pupose only.
3636
let (allocations_tx, mut allocations_rx) =
3737
watch::channel(indexer_allocations.value().await.unwrap());
3838
let _p1 = indexer_allocations.pipe(move |allocatons| {
@@ -42,25 +42,25 @@ pub fn attestation_signers(
4242
loop {
4343
select! {
4444
Ok(_)= allocations_rx.changed() =>{
45-
signers_writer = modify_sigers(
45+
modify_sigers(
4646
Arc::new(indexer_mnemonic.clone()),
4747
chain_id,
4848
attestation_signers_map,
4949
allocations_rx.clone(),
5050
dispute_manager_rx.clone(),
51-
signers_writer).await;
51+
&mut signers_writer).await;
5252
},
5353
Ok(_)= dispute_manager_rx.changed() =>{
54-
signers_writer = modify_sigers(Arc::new(indexer_mnemonic.clone()),
54+
modify_sigers(Arc::new(indexer_mnemonic.clone()),
5555
chain_id,
5656
attestation_signers_map,
5757
allocations_rx.clone(),
5858
dispute_manager_rx.clone(),
59-
signers_writer).await;
59+
&mut signers_writer).await;
6060
},
6161
else=>{
62-
//something is wrong
63-
break;
62+
// Something is wrong.
63+
panic!("dispute_manager_rx or allocations_rx was dropped");
6464
}
6565
}
6666
}
@@ -74,15 +74,13 @@ async fn modify_sigers(
7474
attestation_signers_map: &'static Mutex<HashMap<Address, AttestationSigner>>,
7575
allocations_rx: Receiver<HashMap<Address, Allocation>>,
7676
dispute_manager_rx: Receiver<Option<Address>>,
77-
mut signers_writer: EventualWriter<HashMap<Address, AttestationSigner>>,
78-
) -> EventualWriter<HashMap<Address, AttestationSigner>> {
77+
signers_writer: &mut EventualWriter<HashMap<Address, AttestationSigner>>,
78+
) {
7979
let mut signers = attestation_signers_map.lock().await;
8080
let allocations = allocations_rx.borrow().clone();
81-
let dispute_manager = *dispute_manager_rx.borrow();
82-
if dispute_manager.is_none() {
83-
return signers_writer;
84-
}
85-
let dispute_manager = dispute_manager.unwrap();
81+
let Some(dispute_manager) = *dispute_manager_rx.borrow() else {
82+
return;
83+
};
8684
// Remove signers for allocations that are no longer active or recently closed
8785
signers.retain(|id, _| allocations.contains_key(id));
8886

@@ -104,7 +102,6 @@ async fn modify_sigers(
104102
}
105103

106104
signers_writer.write(signers.clone());
107-
signers_writer
108105
}
109106

110107
#[cfg(test)]

0 commit comments

Comments
 (0)