Skip to content

Commit

Permalink
Make indexer only process the block if it completes the whole block
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaoticTempest committed Jul 17, 2024
1 parent 7277413 commit b16dbc2
Showing 1 changed file with 13 additions and 6 deletions.
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

0 comments on commit b16dbc2

Please sign in to comment.