fix(storage): only delete static file if last_block is on a previous static file (#11029)

Co-authored-by: Alexgao001 <alex.g@nodereal.io>
This commit is contained in:
joshieDo
2024-09-25 18:38:29 +02:00
committed by GitHub
parent 1d56382b8d
commit 4070498a1d
4 changed files with 123 additions and 33 deletions

View File

@ -122,6 +122,12 @@ impl StaticFileSegment {
pub const fn is_receipts(&self) -> bool {
matches!(self, Self::Receipts)
}
/// Returns `true` if the segment is `StaticFileSegment::Receipts` or
/// `StaticFileSegment::Transactions`.
pub const fn is_tx_based(&self) -> bool {
matches!(self, Self::Receipts | Self::Transactions)
}
}
/// A segment header that contains information common to all segments. Used for storage.
@ -239,7 +245,7 @@ impl SegmentHeader {
match self.segment {
StaticFileSegment::Headers => {
if let Some(range) = &mut self.block_range {
if num > range.end {
if num > range.end - range.start {
self.block_range = None;
} else {
range.end = range.end.saturating_sub(num);
@ -248,7 +254,7 @@ impl SegmentHeader {
}
StaticFileSegment::Transactions | StaticFileSegment::Receipts => {
if let Some(range) = &mut self.tx_range {
if num > range.end {
if num > range.end - range.start {
self.tx_range = None;
} else {
range.end = range.end.saturating_sub(num);