@@ -50,6 +50,64 @@ pub struct ComputeBudgetInstructionDetails {
50
50
migrating_builtin_feature_counters : MigrationBuiltinFeatureCounter ,
51
51
}
52
52
53
+ #[ derive( Default ) ]
54
+ pub struct ComputeBudgetInstructionDetailsBuilder {
55
+ compute_budget_instruction_details : ComputeBudgetInstructionDetails ,
56
+ compute_budget_program_id_filter : ComputeBudgetProgramIdFilter ,
57
+ builtin_programs_filter : BuiltinProgramsFilter ,
58
+ }
59
+
60
+ impl ComputeBudgetInstructionDetailsBuilder {
61
+ pub fn process_instruction (
62
+ & mut self ,
63
+ program_id : & Pubkey ,
64
+ instruction : & SVMInstruction ,
65
+ ) -> Result < ( ) > {
66
+ if self
67
+ . compute_budget_program_id_filter
68
+ . is_compute_budget_program ( usize:: from ( instruction. program_id_index ) , program_id)
69
+ {
70
+ self . compute_budget_instruction_details
71
+ . process_instruction ( instruction. program_id_index , instruction) ?;
72
+ // If it is a compute budget program, which is a non-migratable builtin program,
73
+ // we can skip the builtin program filter.
74
+ self . compute_budget_instruction_details
75
+ . num_non_migratable_builtin_instructions += 1 ;
76
+ return Ok ( ( ) ) ;
77
+ } else {
78
+ self . compute_budget_instruction_details
79
+ . num_non_compute_budget_instructions += 1 ;
80
+ }
81
+
82
+ match self
83
+ . builtin_programs_filter
84
+ . get_program_kind ( usize:: from ( instruction. program_id_index ) , program_id)
85
+ {
86
+ ProgramKind :: Builtin => {
87
+ self . compute_budget_instruction_details
88
+ . num_non_migratable_builtin_instructions += 1 ;
89
+ }
90
+ ProgramKind :: NotBuiltin => {
91
+ self . compute_budget_instruction_details
92
+ . num_non_builtin_instructions += 1 ;
93
+ }
94
+ ProgramKind :: MigratingBuiltin {
95
+ core_bpf_migration_feature_index,
96
+ } => {
97
+ self . compute_budget_instruction_details
98
+ . migrating_builtin_feature_counters
99
+ . migrating_builtin [ core_bpf_migration_feature_index] += 1 ;
100
+ }
101
+ }
102
+
103
+ Ok ( ( ) )
104
+ }
105
+
106
+ pub fn build ( self ) -> ComputeBudgetInstructionDetails {
107
+ self . compute_budget_instruction_details
108
+ }
109
+ }
110
+
53
111
impl ComputeBudgetInstructionDetails {
54
112
pub fn try_from < ' a > (
55
113
instructions : impl Iterator < Item = ( & ' a Pubkey , SVMInstruction < ' a > ) > + Clone ,
0 commit comments