From 1651009c191bc5ba4e7cf394f15d7209302f3221 Mon Sep 17 00:00:00 2001 From: Roman Krasiuk Date: Sun, 30 Apr 2023 15:32:45 +0300 Subject: [PATCH] fix(stages): transaction block lookup (#2481) --- crates/stages/src/stages/bodies.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/crates/stages/src/stages/bodies.rs b/crates/stages/src/stages/bodies.rs index 9ab00d0379..f9ea757307 100644 --- a/crates/stages/src/stages/bodies.rs +++ b/crates/stages/src/stages/bodies.rs @@ -83,7 +83,7 @@ impl Stage for BodyStage { let (from_block, to_block) = range.into_inner(); // Cursors used to write bodies, ommers and transactions - let mut block_meta_cursor = tx.cursor_write::()?; + let mut block_indices_cursor = tx.cursor_write::()?; let mut tx_cursor = tx.cursor_write::()?; let mut tx_block_cursor = tx.cursor_write::()?; let mut ommers_cursor = tx.cursor_write::()?; @@ -106,14 +106,18 @@ impl Stage for BodyStage { // Write block let block_number = response.block_number(); - let first_tx_num = next_tx_num; - let mut tx_count = 0; + let block_indices = StoredBlockBodyIndices { + first_tx_num: next_tx_num, + tx_count: match &response { + BlockResponse::Full(block) => block.body.len() as u64, + BlockResponse::Empty(_) => 0, + }, + }; match response { BlockResponse::Full(block) => { - tx_count = block.body.len() as u64; // write transaction block index if !block.body.is_empty() { - tx_block_cursor.append(first_tx_num, block.number)?; + tx_block_cursor.append(block_indices.last_tx_num(), block.number)?; } // Write transactions @@ -142,8 +146,7 @@ impl Stage for BodyStage { }; // insert block meta - block_meta_cursor - .append(block_number, StoredBlockBodyIndices { first_tx_num, tx_count })?; + block_indices_cursor.append(block_number, block_indices)?; highest_block = block_number; }