-
Notifications
You must be signed in to change notification settings - Fork 255
fix: potential cache issues #7623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| // Copyright 2025 The Tari Project | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| use std::{fmt::Display, sync::Arc}; | ||
| use std::{cmp, fmt::Display, sync::Arc}; | ||
|
|
||
| use axum::{ | ||
| extract::Query, | ||
|
|
@@ -87,6 +87,7 @@ pub async fn handle<B: BlockchainBackend + 'static>( | |
| let tip_info = query_service.get_tip_info().await.map_err(error_handler_with_message)?; | ||
| let tip_height = tip_info.metadata.map(|m| m.best_block_height()).unwrap_or(0); | ||
| let height; | ||
| let exclude_spent = request.exclude_spent; | ||
| let mut response = match request.version { | ||
| 0 => { | ||
| let response = query_service | ||
|
|
@@ -107,7 +108,14 @@ pub async fn handle<B: BlockchainBackend + 'static>( | |
| body.into_response() | ||
| }, | ||
| }; | ||
| let last_height = height.unwrap_or(0); | ||
| let last_height = if let true = exclude_spent { | ||
| // if we're excluding spent outputs we cannot cache for longer than a day, so we force the "height" so that the | ||
| // caching will only be a max of 1 day. Wallets will sent full without excluding spends the last 1000 blocks so | ||
| // this leaves a margin for wallets to get data if it changed. | ||
| cmp::min(height.unwrap_or(0), tip_height.saturating_add(2500)) | ||
| } else { | ||
| height.unwrap_or(0) | ||
| }; | ||
|
Comment on lines
+111
to
+118
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Find the apply_cache_control function and surrounding context
fd -e rs -x grep -l "apply_cache_control" {}Repository: tari-project/tari Length of output: 178 🏁 Script executed: #!/bin/bash
# Search for apply_cache_control implementation
rg -n "fn apply_cache_control" -A 25 -B 2 --type rustRepository: tari-project/tari Length of output: 178 🏁 Script executed: #!/bin/bash
# Search for how tip_height and last_height are used in cache calculations
rg -n "cache.*control|max-age|Cache-Control" -A 5 -B 5 --type rustRepository: tari-project/tari Length of output: 178 🏁 Script executed: #!/bin/bash
# Get the full context of the sync_utxos_by_block.rs file around the flagged section
wc -l applications/minotari_node/src/http/handler/sync_utxos_by_block.rsRepository: tari-project/tari Length of output: 178 Fix inverted clamping logic in cache control calculation. The current code clamps cmp::min(height.unwrap_or(0), tip_height.saturating_add(2500))In typical operation where To limit cache to approximately 1 day when cmp::max(height.unwrap_or(0), tip_height.saturating_sub(2500))This ensures old blocks are treated as closer to the tip, reducing cache TTL as intended. Also simplify the condition: replace 🤖 Prompt for AI Agents |
||
|
|
||
| apply_cache_control( | ||
| response.headers_mut(), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix comment typo and clarify block count.
The comment has a grammatical error and an inconsistency:
Please clarify whether 2500 blocks is correct (approximately 1 day) and update the comment accordingly.
🤖 Prompt for AI Agents