From 050096d8687216b49ccdf3d9b34ed30ea5ac0984 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 27 Mar 2023 16:02:18 +0200 Subject: [PATCH] fix(db): off by one receipts insert (#1993) --- crates/storage/provider/src/post_state.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/crates/storage/provider/src/post_state.rs b/crates/storage/provider/src/post_state.rs index 39f35fd01d..95ddb82576 100644 --- a/crates/storage/provider/src/post_state.rs +++ b/crates/storage/provider/src/post_state.rs @@ -576,12 +576,19 @@ impl PostState { bytecodes_cursor.upsert(hash, bytecode)?; } - // write receipts + // write the receipts of the transactions let mut receipts_cursor = tx.cursor_write::()?; - let mut tx_num = receipts_cursor.last()?.map(|(tx_num, _)| tx_num).unwrap_or_default(); + + let mut next_tx_num = + if let Some(last_tx) = receipts_cursor.last()?.map(|(tx_num, _)| tx_num) { + last_tx + 1 + } else { + // the very first tx + 0 + }; for receipt in self.receipts.into_iter() { - tx_num += 1; - receipts_cursor.append(tx_num, receipt)? + receipts_cursor.append(next_tx_num, receipt)?; + next_tx_num += 1; } Ok(())