Implement the TransactionExecutor caching mechanism and the InvokeContext instruction processing logic in the Solana program architecture. Your implementation should ensure effective tracking and management of instruction execution, taking into consideration cache states (dirty, updated, cached) and instruction verification.
Specific Requirements:
TransactionExecutor:
Implement the logic to handle three states of the executor:
new_cached for executors that do not need updates.
new_miss for executors that require updates after a failed instruction execution.
new_updated for executors whose state needs to be updated only if the current transaction is successful.
Provide methods in TransactionExecutor to:
Determine if the executor is dirty (is_dirty).
Clear the miss state for testing purposes (clear_miss_for_test).
InvokeContext:
Modify the existing logic in InvokeContext to correctly handle the following when processing instructions:
Ensure the instruction accounts are verified before executing programs.
Track and update the compute units through the ComputeMeter.
Record pre-instruction states and verify post-instruction results for each account involved.
Ensure that unbalanced instructions are handled properly by checking if total lamports before and after execution match.
Testing:
Implement unit tests to validate:
The different states of TransactionExecutor and their transitions.
The instruction processing logic in InvokeContext, including proper handling of compute unit consumption, account verification, and error handling for invalid operations.
The implementation must be placed in the /app/ directory and should interact seamlessly with the other components of the Solana program, as defined in the provided Rust test code.