Skip to content

Commit 21e2cd6

Browse files
committed
ref: simplify some idioms and add some comments on retrieval timeouts
1 parent 4b7e68c commit 21e2cd6

File tree

7 files changed

+20
-8
lines changed

7 files changed

+20
-8
lines changed

net/src/client/http/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ pub struct WitnetHttpClient {
1414

1515
impl WitnetHttpClient {
1616
/// Simple wrapper around `isahc::HttpClient::send_async`.
17+
///
18+
/// Opinionated in only one thing: if a timeout is not specified, it uses a 10 seconds timeout.
1719
pub async fn send(
1820
&self,
1921
request: reqwest::RequestBuilder,
2022
timeout: Option<Duration>,
2123
) -> Result<WitnetHttpResponse, WitnetHttpError> {
22-
let req = match request.timeout(timeout.unwrap_or(Duration::new(10, 0))).build() {
24+
let timeout = timeout.unwrap_or(Duration::from_secs(10));
25+
let req = match request.timeout(timeout).build() {
2326
Ok(req) => req,
2427
Err(e) => return Err(WitnetHttpError::HttpRequestError { msg: e.to_string() }),
2528
};

node/src/actors/chain_manager/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3784,6 +3784,8 @@ pub fn run_dr_locally(dr: &DataRequestOutput) -> Result<RadonTypes, anyhow::Erro
37843784
retrieve,
37853785
active_wips.clone(),
37863786
protocol_version,
3787+
// TODO: decide whether to enable custom timeouts for this type of local execution
3788+
None,
37873789
))
37883790
};
37893791

rad/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,15 @@ pub async fn run_paranoid_retrieval(
557557
) -> Result<RadonReport<RadonTypes>> {
558558
// We can skip paranoid checks for retrieval types that don't use networking (e.g. RNG)
559559
if !retrieve.kind.is_http() {
560-
return run_retrieval_report(retrieve, settings, active_wips, protocol_version, None, timeout).await;
560+
return run_retrieval_report(
561+
retrieve,
562+
settings,
563+
active_wips,
564+
protocol_version,
565+
None,
566+
timeout,
567+
)
568+
.await;
561569
}
562570

563571
let futures: Result<Vec<_>> = witnessing

toolkit/src/cli/arguments.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub(crate) struct TryDataRequest {
3030
)]
3131
pub full_trace: Option<bool>,
3232
#[structopt(
33-
long,
33+
long,
3434
help = "Maximum amount of seconds to wait for a data source to respond."
3535
)]
3636
pub timeout: Option<u64>,

toolkit/src/cli/data_requests.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,7 @@ pub(crate) fn try_from_args(
4343
args: arguments::TryDataRequest,
4444
) -> Result<RADRequestExecutionReport, Error> {
4545
let full_trace = args.full_trace.unwrap_or(true);
46-
let timeout: Option<Duration> = if let Some(timeout) = args.timeout {
47-
Some(Duration::from_secs(timeout))
48-
} else {
49-
None
50-
};
46+
let timeout = args.timeout.map(Duration::from_secs);
5147
let request = decode_from_args(args.into())?.data_request;
5248
witnet_toolkit::data_requests::try_data_request(&request, full_trace, timeout)
5349
}

wallet/src/actors/worker/methods.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ impl Worker {
5858
None,
5959
Some(self.params.witnessing.clone()),
6060
false,
61+
// TODO: decide whether to enable custom timeouts for this type of execution
62+
None,
6163
)
6264
}
6365

wallet/tests/data_requests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ fn test_data_request_report_json_serialization() {
110110
Some(&inputs),
111111
None,
112112
false,
113+
None,
113114
);
114115

115116
// Number of retrieval reports should match number of sources

0 commit comments

Comments
 (0)