Skip to content

Commit

Permalink
assigns 'span' at the top of the call methods
Browse files Browse the repository at this point in the history
  • Loading branch information
arya2 committed Mar 16, 2023
1 parent 63b30c6 commit 18e6c85
Showing 1 changed file with 8 additions and 24 deletions.
32 changes: 8 additions & 24 deletions zebra-state/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@ impl Service<Request> for StateService {
fn call(&mut self, req: Request) -> Self::Future {
req.count_metric();
let timer = CodeTimer::start();
let span = Span::current();

match req {
// Uses queued_non_finalized_blocks and pending_utxos in the StateService
Expand All @@ -915,7 +916,7 @@ impl Service<Request> for StateService {
// there shouldn't be any other code running in the same task,
// so we don't need to worry about blocking it:
// https://docs.rs/tokio/latest/tokio/task/fn.block_in_place.html
let span = Span::current();

let rsp_rx = tokio::task::block_in_place(move || {
span.in_scope(|| self.queue_and_commit_non_finalized(prepared))
});
Expand Down Expand Up @@ -970,7 +971,6 @@ impl Service<Request> for StateService {
// The work is all done, the future just waits on a channel for the result
timer.finish(module_path!(), line!(), "CommitFinalizedBlock");

let span = Span::current();
async move {
rsp_rx
.await
Expand All @@ -996,7 +996,7 @@ impl Service<Request> for StateService {
let response_fut = self.pending_utxos.queue(outpoint);
// Only instrument `response_fut`, the ReadStateService already
// instruments its requests with the same span.
let span = Span::current();

let response_fut = response_fut.instrument(span).boxed();

// Check the non-finalized block queue outside the returned future,
Expand Down Expand Up @@ -1147,13 +1147,13 @@ impl Service<ReadRequest> for ReadStateService {
fn call(&mut self, req: ReadRequest) -> Self::Future {
req.count_metric();
let timer = CodeTimer::start();
let span = Span::current();

match req {
// Used by the StateService.
ReadRequest::Tip => {
let state = self.clone();

let span = Span::current();
tokio::task::spawn_blocking(move || {
span.in_scope(move || {
let tip = state.non_finalized_state_receiver.with_watch_data(
Expand All @@ -1176,7 +1176,6 @@ impl Service<ReadRequest> for ReadStateService {
ReadRequest::Depth(hash) => {
let state = self.clone();

let span = Span::current();
tokio::task::spawn_blocking(move || {
span.in_scope(move || {
let depth = state.non_finalized_state_receiver.with_watch_data(
Expand All @@ -1199,7 +1198,6 @@ impl Service<ReadRequest> for ReadStateService {
ReadRequest::BestChainNextMedianTimePast => {
let state = self.clone();

let span = Span::current();
tokio::task::spawn_blocking(move || {
span.in_scope(move || {
let non_finalized_state = state.latest_non_finalized_state();
Expand All @@ -1226,7 +1224,6 @@ impl Service<ReadRequest> for ReadStateService {
ReadRequest::Block(hash_or_height) => {
let state = self.clone();

let span = Span::current();
tokio::task::spawn_blocking(move || {
span.in_scope(move || {
let block = state.non_finalized_state_receiver.with_watch_data(
Expand All @@ -1253,7 +1250,6 @@ impl Service<ReadRequest> for ReadStateService {
ReadRequest::Transaction(hash) => {
let state = self.clone();

let span = Span::current();
tokio::task::spawn_blocking(move || {
span.in_scope(move || {
let transaction_and_height = state
Expand All @@ -1276,7 +1272,6 @@ impl Service<ReadRequest> for ReadStateService {
ReadRequest::TransactionIdsForBlock(hash_or_height) => {
let state = self.clone();

let span = Span::current();
tokio::task::spawn_blocking(move || {
span.in_scope(move || {
let transaction_ids = state.non_finalized_state_receiver.with_watch_data(
Expand Down Expand Up @@ -1308,7 +1303,6 @@ impl Service<ReadRequest> for ReadStateService {
ReadRequest::UnspentBestChainUtxo(outpoint) => {
let state = self.clone();

let span = Span::current();
tokio::task::spawn_blocking(move || {
span.in_scope(move || {
let utxo = state.non_finalized_state_receiver.with_watch_data(
Expand All @@ -1335,7 +1329,6 @@ impl Service<ReadRequest> for ReadStateService {
ReadRequest::AnyChainUtxo(outpoint) => {
let state = self.clone();

let span = Span::current();
tokio::task::spawn_blocking(move || {
span.in_scope(move || {
let utxo = state.non_finalized_state_receiver.with_watch_data(
Expand All @@ -1358,7 +1351,6 @@ impl Service<ReadRequest> for ReadStateService {
ReadRequest::BlockLocator => {
let state = self.clone();

let span = Span::current();
tokio::task::spawn_blocking(move || {
span.in_scope(move || {
let block_locator = state.non_finalized_state_receiver.with_watch_data(
Expand All @@ -1383,7 +1375,6 @@ impl Service<ReadRequest> for ReadStateService {
ReadRequest::FindBlockHashes { known_blocks, stop } => {
let state = self.clone();

let span = Span::current();
tokio::task::spawn_blocking(move || {
span.in_scope(move || {
let block_hashes = state.non_finalized_state_receiver.with_watch_data(
Expand Down Expand Up @@ -1412,7 +1403,6 @@ impl Service<ReadRequest> for ReadStateService {
ReadRequest::FindBlockHeaders { known_blocks, stop } => {
let state = self.clone();

let span = Span::current();
tokio::task::spawn_blocking(move || {
span.in_scope(move || {
let block_headers = state.non_finalized_state_receiver.with_watch_data(
Expand Down Expand Up @@ -1445,7 +1435,6 @@ impl Service<ReadRequest> for ReadStateService {
ReadRequest::SaplingTree(hash_or_height) => {
let state = self.clone();

let span = Span::current();
tokio::task::spawn_blocking(move || {
span.in_scope(move || {
let sapling_tree = state.non_finalized_state_receiver.with_watch_data(
Expand All @@ -1471,7 +1460,6 @@ impl Service<ReadRequest> for ReadStateService {
ReadRequest::OrchardTree(hash_or_height) => {
let state = self.clone();

let span = Span::current();
tokio::task::spawn_blocking(move || {
span.in_scope(move || {
let orchard_tree = state.non_finalized_state_receiver.with_watch_data(
Expand All @@ -1498,7 +1486,6 @@ impl Service<ReadRequest> for ReadStateService {
ReadRequest::AddressBalance(addresses) => {
let state = self.clone();

let span = Span::current();
tokio::task::spawn_blocking(move || {
span.in_scope(move || {
let balance = state.non_finalized_state_receiver.with_watch_data(
Expand Down Expand Up @@ -1528,7 +1515,6 @@ impl Service<ReadRequest> for ReadStateService {
} => {
let state = self.clone();

let span = Span::current();
tokio::task::spawn_blocking(move || {
span.in_scope(move || {
let tx_ids = state.non_finalized_state_receiver.with_watch_data(
Expand Down Expand Up @@ -1562,7 +1548,6 @@ impl Service<ReadRequest> for ReadStateService {
ReadRequest::UtxosByAddresses(addresses) => {
let state = self.clone();

let span = Span::current();
tokio::task::spawn_blocking(move || {
span.in_scope(move || {
let utxos = state.non_finalized_state_receiver.with_watch_data(
Expand All @@ -1589,7 +1574,6 @@ impl Service<ReadRequest> for ReadStateService {
ReadRequest::CheckBestChainTipNullifiersAndAnchors(unmined_tx) => {
let state = self.clone();

let span = Span::current();
tokio::task::spawn_blocking(move || {
span.in_scope(move || {
let latest_non_finalized_best_chain =
Expand Down Expand Up @@ -1631,7 +1615,7 @@ impl Service<ReadRequest> for ReadStateService {
// # Performance
//
// Allow other async tasks to make progress while concurrently reading blocks from disk.
let span = Span::current();

tokio::task::spawn_blocking(move || {
span.in_scope(move || {
let hash = state.non_finalized_state_receiver.with_watch_data(
Expand Down Expand Up @@ -1663,7 +1647,7 @@ impl Service<ReadRequest> for ReadStateService {
// # Performance
//
// Allow other async tasks to make progress while concurrently reading blocks from disk.
let span = Span::current();

tokio::task::spawn_blocking(move || {
span.in_scope(move || {
// # Correctness
Expand Down Expand Up @@ -1702,7 +1686,7 @@ impl Service<ReadRequest> for ReadStateService {
// # Performance
//
// Allow other async tasks to make progress while concurrently reading blocks from disk.
let span = Span::current();

tokio::task::spawn_blocking(move || {
span.in_scope(move || {
let latest_non_finalized_state = state.latest_non_finalized_state();
Expand Down Expand Up @@ -1755,7 +1739,7 @@ impl Service<ReadRequest> for ReadStateService {
// # Performance
//
// Allow other async tasks to make progress while concurrently reading blocks from disk.
let span = Span::current();

tokio::task::spawn_blocking(move || {
span.in_scope(move || {
tracing::info!("attempting to validate and commit block proposal onto a cloned non-finalized state");
Expand Down

0 comments on commit 18e6c85

Please sign in to comment.