Skip to main content

jito_bundle/bundler/
types.rs

1use crate::constants::MAX_BUNDLE_TRANSACTIONS;
2use solana_instruction::Instruction;
3
4/// Fixed-size instruction slots aligned with Jito's max bundle size.
5pub type BundleInstructionSlots = [Option<Vec<Instruction>>; MAX_BUNDLE_TRANSACTIONS];
6
7/// Indicates how the tip was placed in the built bundle.
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum TipMode {
10    /// Tip is appended as a dedicated final transaction.
11    SeparateTx,
12    /// Tip is appended to the last existing transaction.
13    InlineLastTx,
14}
15
16/// Shared view over fixed instruction slots.
17pub trait BundleSlotView {
18    /// Returns the underlying fixed instruction slots.
19    fn instruction_slots(&self) -> &BundleInstructionSlots;
20
21    /// Counts non-empty instruction slots.
22    fn populated_count(&self) -> usize {
23        self.instruction_slots()
24            .iter()
25            .filter(|slot| slot.is_some())
26            .count()
27    }
28
29    /// Returns the index of the last non-empty slot.
30    fn last_populated_index(&self) -> Option<usize> {
31        self.instruction_slots()
32            .iter()
33            .rposition(|slot| slot.is_some())
34    }
35}
36
37/// Creates an empty fixed-size slot array.
38pub fn empty_instruction_slots() -> BundleInstructionSlots {
39    std::array::from_fn(|_| None)
40}