Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 34 additions & 29 deletions monad-archive/src/workers/index_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,37 +193,42 @@ async fn handle_block(
}

// Check 1 key
if let Some(tx) = first {
let tx = tx.tx;
let key = tx.tx_hash();
match tx_index_archiver.get_tx_indexed_data(key).await {
Ok(Some(resp)) => {
if resp.header_subset.block_number != block_num
|| Some(&resp.receipt) != first_rx.as_ref()
|| Some(&resp.trace) != first_trace.as_ref()
{
warn!(
key = key.encode_hex(),
block_num,
?resp,
"Returned index not as expected"
);
} else {
info!(
tokio::spawn({
let tx_index_archiver = tx_index_archiver.clone();
async move {
Comment on lines +196 to +198
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spawned task does not handle potential panics or task failures. Consider using a named task handle or adding error logging if the spawned task fails, as errors in detached tasks can be silently lost.

Copilot uses AI. Check for mistakes.
if let Some(tx) = first {
Comment on lines +196 to +199
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spawned task captures first by move, but first may be used after this point in the parent function. Verify that first is not accessed after line 231, or clone it before spawning if needed.

Suggested change
tokio::spawn({
let tx_index_archiver = tx_index_archiver.clone();
async move {
if let Some(tx) = first {
let first_for_spawn = first.clone();
tokio::spawn({
let tx_index_archiver = tx_index_archiver.clone();
async move {
if let Some(tx) = first_for_spawn {

Copilot uses AI. Check for mistakes.
let tx = tx.tx;
let key = tx.tx_hash();
match tx_index_archiver.get_tx_indexed_data(key).await {
Ok(Some(resp)) => {
if resp.header_subset.block_number != block_num
|| Some(&resp.receipt) != first_rx.as_ref()
|| Some(&resp.trace) != first_trace.as_ref()
{
warn!(
key = key.encode_hex(),
block_num,
?resp,
"Returned index not as expected"
);
} else {
info!(
key = key.encode_hex(),
block_num, "Index spot-check successful"
);
}
}
Ok(None) => {
warn!(key = key.encode_hex(), block_num, "No index found");
}
Err(e) => warn!(
key = key.encode_hex(),
block_num, "Index spot-check successful"
);
}
}
Ok(None) => {
warn!(key = key.encode_hex(), block_num, "No index found");
block_num, "Error while checking: {e:?}"
),
};
}
Err(e) => warn!(
key = key.encode_hex(),
block_num, "Error while checking: {e}"
),
};
}
}
});

Ok(num_txs)
}
Expand Down
Loading