Validates whether an incoming flashblock links to the current latest flashblock.
(
latest_block_number: u64,
latest_flashblock_index: u64,
incoming_block_number: u64,
incoming_index: u64,
incoming_prev_flashblock_id: FlashblockId,
)
| 44 | impl FlashblockSequenceValidator { |
| 45 | /// Validates whether an incoming flashblock links to the current latest flashblock. |
| 46 | pub fn validate( |
| 47 | latest_block_number: u64, |
| 48 | latest_flashblock_index: u64, |
| 49 | incoming_block_number: u64, |
| 50 | incoming_index: u64, |
| 51 | incoming_prev_flashblock_id: FlashblockId, |
| 52 | ) -> SequenceValidationResult { |
| 53 | let latest_flashblock_id = |
| 54 | FlashblockId { block_number: latest_block_number, index: latest_flashblock_index }; |
| 55 | |
| 56 | if incoming_block_number == latest_block_number && incoming_index == latest_flashblock_index |
| 57 | { |
| 58 | return SequenceValidationResult::Duplicate; |
| 59 | } |
| 60 | |
| 61 | // We can remove this `incoming_prev_flashblock_id != FlashblockId::default()` check later |
| 62 | // but it is currently necessary as client nodes may be updated before the builder is |
| 63 | // and they need to be able to handle the lack of `prev_flashblock_id` in the stream |
| 64 | if incoming_prev_flashblock_id != FlashblockId::default() |
| 65 | && incoming_prev_flashblock_id != latest_flashblock_id |
| 66 | { |
| 67 | return SequenceValidationResult::NonSequentialPredecessor { |
| 68 | expected: latest_flashblock_id, |
| 69 | actual: incoming_prev_flashblock_id, |
| 70 | }; |
| 71 | } |
| 72 | |
| 73 | let next_flashblock_index = latest_flashblock_index.saturating_add(1); |
| 74 | if incoming_block_number == latest_block_number && incoming_index == next_flashblock_index { |
| 75 | return SequenceValidationResult::NextInSequence; |
| 76 | } |
| 77 | |
| 78 | if incoming_block_number == latest_block_number + 1 && incoming_index == 0 { |
| 79 | return SequenceValidationResult::FirstOfNextBlock; |
| 80 | } |
| 81 | |
| 82 | if incoming_block_number == latest_block_number { |
| 83 | return SequenceValidationResult::NonSequentialGap { |
| 84 | expected: next_flashblock_index, |
| 85 | actual: incoming_index, |
| 86 | }; |
| 87 | } |
| 88 | |
| 89 | SequenceValidationResult::InvalidNewBlockIndex { |
| 90 | block_number: incoming_block_number, |
| 91 | index: incoming_index, |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | /// Result of a reorganization detection check. |
nothing calls this directly
no outgoing calls
no test coverage detected