Skip to content

Commit

Permalink
Merge pull request iotaledger#548 from iotaledger/timeout-before-request
Browse files Browse the repository at this point in the history
retry request for sent message multiple times
  • Loading branch information
bingyanglin authored May 7, 2021
2 parents ee7245d + 27da766 commit cea6f56
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions iota-client/src/api/message_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ use bee_rest_api::types::{
responses::OutputResponse,
};
use crypto::keys::slip10::{Chain, Curve, Seed};
#[cfg(not(feature = "wasm"))]
use tokio::time::sleep;

use std::{
collections::{HashMap, HashSet},
ops::Range,
str::FromStr,
time::Duration,
};

// https://github.com/GalRogozinski/protocol-rfcs/blob/dust/text/0032-dust-protection/0032-dust-protection.md
Expand Down Expand Up @@ -641,12 +644,23 @@ impl<'a> ClientMessageBuilder<'a> {

let msg_id = self.client.post_message(&final_message).await?;
// Get message if we use remote PoW, because the node will change parents and nonce
let msg = match self.client.get_local_pow().await {
true => final_message,
false => self.client.get_message().data(&msg_id).await?,
};

Ok(msg)
match self.client.get_local_pow().await {
true => Ok(final_message),
false => {
// Request message multiple times because the node maybe didn't process it completely in this time
// or a node balancer could be used which forwards the request to different node than we published
for time in 1..3 {
if let Ok(message) = self.client.get_message().data(&msg_id).await {
return Ok(message);
}
#[cfg(not(feature = "wasm"))]
sleep(Duration::from_millis(time * 50)).await;
#[cfg(feature = "wasm")]
std::thread::sleep(Duration::from_millis(time * 50));
}
self.client.get_message().data(&msg_id).await
}
}
}
}

Expand Down

0 comments on commit cea6f56

Please sign in to comment.