nautilus_blockchain/cache/
consistency.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16/// Represents the consistency status of cached blockchain blocks, tracking gaps in the block sequence.
17///
18/// This struct helps determine the optimal sync strategy by comparing the highest cached block
19/// with the last continuous block number. When these values differ, it indicates gaps exist
20/// in the cached data that require special handling during synchronization.
21#[derive(Debug, Clone)]
22pub struct CachedBlocksConsistencyStatus {
23    /// The highest block number present in the cache
24    pub max_block: u64,
25    /// The highest block number in a continuous sequence from the beginning
26    pub last_continuous_block: u64,
27}
28
29impl CachedBlocksConsistencyStatus {
30    #[must_use]
31    pub const fn new(max_block: u64, last_continuous_block: u64) -> Self {
32        Self {
33            max_block,
34            last_continuous_block,
35        }
36    }
37
38    /// Returns true if the cached blocks form a continuous sequence without gaps.
39    #[must_use]
40    pub const fn is_consistent(&self) -> bool {
41        self.max_block == self.last_continuous_block
42    }
43}