rbpf
rbpf copied to clipboard
Interperter CUs Computation questions
Hello, I have two questions about CUs computation of the Solana interpreter, could someone please give me some suggestions?
- The Solana interpreter says the CALL_REG spends an additional CU by
self.vm.due_insn_count += 1;, why? - The interpreter does
self.vm.due_insn_count = self.vm.previous_instruction_meter - self.vm.due_insn_count;and after invoking function, doesself.vm.due_insn_count = 0;, why? Could we remove those two lines from the interpreter (and also modify the program.rs )?
// https://github.com/solana-labs/rbpf/blob/main/src/interpreter.rs#L477
self.vm.due_insn_count = self.vm.previous_instruction_meter - self.vm.due_insn_count; // removing
self.vm.registers[0..6].copy_from_slice(&self.reg[0..6]);
self.vm.invoke_function(function);
self.vm.due_insn_count = 0; // removing
https://github.com/solana-labs/rbpf/blob/main/src/program.rs#L331
vm.context_object_pointer.consume(vm.previous_instruction_meter - vm.due_insn_count); // `vm.previous_instruction_meter - vm.due_insn_count` -> `vm.due_insn_count`
...
vm.previous_instruction_meter = vm.context_object_pointer.get_remaining(); // removing
The first question can be omitted as due_insn_count +1 is in a throw_error branch.
The second is so that it is interface compatible with JIT compiled programs upon entry in a syscall. The syscall helper wrapper in program.rs does expect the CU metering to have been flushed.