Skip to content

Commit

Permalink
remove format! in async workaround (see github.com/rust-lang/rust/iss…
Browse files Browse the repository at this point in the history
  • Loading branch information
Thegaram committed Mar 2, 2020
1 parent 1940560 commit 2eb8409
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 61 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 15 additions & 59 deletions core/src/light_protocol/query_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,9 @@ impl QueryService {
) -> Result<StateRoot, String> {
trace!("retrieve_state_root epoch = {}", epoch);

// We cannot await in scope that contains call to format!
// This is likely to be fixed in a future compiler version.
// See: https://github.com/rust-lang/rust/issues/64960
let msg =
format!("Timeout while retrieving state root for epoch {}", epoch);

with_timeout(
*MAX_POLL_TIME, /* timeout */
msg, /* error */
*MAX_POLL_TIME,
format!("Timeout while retrieving state root for epoch {}", epoch),
self.with_io(|io| self.handler.state_roots.request_now(io, epoch)),
)
.await
Expand All @@ -135,35 +129,20 @@ impl QueryService {
) -> Result<Option<Vec<u8>>, String> {
trace!("retrieve_state_entry epoch = {}, key = {:?}", epoch, key);

// We cannot await in scope that contains call to format!
// This is likely to be fixed in a future compiler version.
// See: https://github.com/rust-lang/rust/issues/64960
let msg = format!(
"Timeout while retrieving state entry for epoch {} with key {:?}",
epoch, key
);

with_timeout(
*MAX_POLL_TIME, /* timeout */
msg, /* error */
self.with_io(|io| {
self.handler.state_entries.request_now(io, epoch, key)
}),
*MAX_POLL_TIME,
format!("Timeout while retrieving state entry for epoch {} with key {:?}", epoch, key),
self.with_io(|io| self.handler.state_entries.request_now(io, epoch, key)),
)
.await
}

async fn retrieve_bloom(&self, epoch: u64) -> Result<(u64, Bloom), String> {
trace!("retrieve_bloom epoch = {}", epoch);

// We cannot await in scope that contains call to format!
// This is likely to be fixed in a future compiler version.
// See: https://github.com/rust-lang/rust/issues/64960
let msg = format!("Timeout while retrieving bloom for epoch {}", epoch);

with_timeout(
*MAX_POLL_TIME, /* timeout */
msg, /* error */
*MAX_POLL_TIME,
format!("Timeout while retrieving bloom for epoch {}", epoch),
self.handler.blooms.request(epoch),
)
.await
Expand All @@ -175,15 +154,9 @@ impl QueryService {
) -> Result<(u64, Vec<Vec<Receipt>>), String> {
trace!("retrieve_receipts epoch = {}", epoch);

// We cannot await in scope that contains call to format!
// This is likely to be fixed in a future compiler version.
// See: https://github.com/rust-lang/rust/issues/64960
let msg =
format!("Timeout while retrieving receipts for epoch {}", epoch);

with_timeout(
*MAX_POLL_TIME, /* timeout */
msg, /* error */
*MAX_POLL_TIME,
format!("Timeout while retrieving receipts for epoch {}", epoch),
self.handler.receipts.request(epoch),
)
.await
Expand All @@ -196,15 +169,9 @@ impl QueryService {
trace!("retrieve_block_txs log = {:?}", log);
let hash = log.block_hash;

// We cannot await in scope that contains call to format!
// This is likely to be fixed in a future compiler version.
// See: https://github.com/rust-lang/rust/issues/64960
let msg =
format!("Timeout while retrieving block txs for block {}", hash);

with_timeout(
*MAX_POLL_TIME, /* timeout */
msg, /* error */
*MAX_POLL_TIME,
format!("Timeout while retrieving block txs for block {}", hash),
self.handler.block_txs.request(hash),
)
.await
Expand All @@ -216,14 +183,9 @@ impl QueryService {
) -> Result<(SignedTransaction, Receipt, TransactionAddress), String> {
trace!("retrieve_tx_info hash = {:?}", hash);

// We cannot await in scope that contains call to format!
// This is likely to be fixed in a future compiler version.
// See: https://github.com/rust-lang/rust/issues/64960
let msg = format!("Timeout while retrieving tx info for tx {}", hash);

with_timeout(
*MAX_POLL_TIME, /* timeout */
msg, /* error */
*MAX_POLL_TIME,
format!("Timeout while retrieving tx info for tx {}", hash),
self.with_io(|io| self.handler.tx_infos.request_now(io, hash)),
)
.await
Expand Down Expand Up @@ -374,15 +336,9 @@ impl QueryService {
) -> Result<SignedTransaction, String> {
info!("get_tx hash={:?}", hash);

// We cannot await in scope that contains call to format!
// This is likely to be fixed in a future compiler version.
// See: https://github.com/rust-lang/rust/issues/64960
let msg =
format!("Timeout while retrieving transaction with hash {}", hash);

with_timeout(
*MAX_POLL_TIME, /* timeout */
msg, /* error */
*MAX_POLL_TIME,
format!("Timeout while retrieving transaction with hash {}", hash),
self.with_io(|io| self.handler.txs.request_now(io, hash)),
)
.await
Expand Down

0 comments on commit 2eb8409

Please sign in to comment.