mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
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:
@ -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);
|
||||
|
||||
Reference in New Issue
Block a user