Skip to content
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

fix: Make indexer only process the block if it completes the whole block #689

Merged
merged 1 commit into from
Jul 17, 2024
Merged
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
19 changes: 13 additions & 6 deletions chain-signatures/node/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ async fn handle_block(
mut block: near_lake_primitives::block::Block,
ctx: &Context,
) -> anyhow::Result<()> {
let mut pending_requests = Vec::new();
for action in block.actions().cloned().collect::<Vec<_>>() {
if action.receiver_id() == ctx.mpc_contract_id {
let receipt =
Expand Down Expand Up @@ -132,19 +133,14 @@ async fn handle_block(
entropy = hex::encode(entropy),
"indexed new `sign` function call"
);
let mut queue = ctx.queue.write().await;
queue.add(SignRequest {
pending_requests.push(SignRequest {
receipt_id,
request: arguments.request,
epsilon,
delta,
entropy,
time_added: Instant::now(),
});
crate::metrics::NUM_SIGN_REQUESTS
.with_label_values(&[ctx.gcp_service.account_id.as_str()])
.inc();
drop(queue);
}
}
}
Expand All @@ -162,6 +158,17 @@ async fn handle_block(
.with_label_values(&[ctx.gcp_service.account_id.as_str()])
.set(block.block_height() as i64);

// Add the requests after going through the whole block to avoid partial processing if indexer fails somewhere.
// This way we can revisit the same block if we failed while not having added the requests partially.
let mut queue = ctx.queue.write().await;
for request in pending_requests {
queue.add(request);
crate::metrics::NUM_SIGN_REQUESTS
.with_label_values(&[ctx.gcp_service.account_id.as_str()])
.inc();
}
drop(queue);

if block.block_height() % 1000 == 0 {
tracing::info!(block_height = block.block_height(), "indexed block");
}
Expand Down
Loading