anza-xyz / agave

Web-Scale Blockchain for fast, secure, scalable, decentralized apps and marketplaces.
https://www.anza.xyz/
Apache License 2.0
237 stars 100 forks source link

Compute unit exceedence throws `ProgramFailedToComplete` instead of `ComputationalBudgetExceeded` #1976

Open steveluscher opened 3 weeks ago

steveluscher commented 3 weeks ago

Problem

Consider this transaction that exceeds its compute budget of 15000 CUs:

https://explorer.solana.com/tx/inspector?signatures=%255B%25225dUfY9k28HHNUuvpSuhdzx53EteMyfGCgqF9iqMtuvRY8DcP3PxXvse1R7RfANGe7jYLejL6coxrn4EEi6C56HPZ%2522%255D&message=AQACAze8vCh%252Fupx58A684jj8N7Heb37vwHzBicyyHW7x1udtAwZGb%252BUhFzL%252F7K26csOb57yM5bvF9xJrLEObOkAAAAAFSlNamSkhBk0k6HFg2jh8fDW13bySu4HkH6hAQQVEjf3GzDQNAqXWZstR2XFW1lbegc7g9QpKLW1sb8qETlE6AwEABQKYOgAAAQAJA4gTAAAAAAAAAgAJTmVhdCDwn5O4&cluster=testnet

In simulation, I would expect that transaction to throw InstructionError::ComputationalBudgetExceeded, but instead it throws the more abstract InstructionError::ProgramFailedToComplete and appears to log the message from EbpfError::ExceededMaxInstructions from solana-labs/rbpf.

Proposed Solution

Throw InstructionError::ComputationalBudgetExceeded instead, so that applications/clients can catch that error and show mitigation advice to the user (eg. ‘you need to budget at least X CUs’) or automatically retry with a higher CU budget.

Lichtso commented 3 weeks ago

Except for SyscallError all other errors are consolidated into InstructionError::ProgramFailedToComplete here: https://github.com/anza-xyz/agave/blob/8eef73da38f36b686a42ecd081da42820551b643/program-runtime/src/invoke_context.rs#L547

Feel free to submit a PR, a feature gate is technically not necessary but I would recommend one so it becomes clear when one can start relying on it.

steveluscher commented 3 weeks ago

Thanks for that pointer! I think I will.

steveluscher commented 3 weeks ago

Was this the impetus for this test modification, @joncinque?

https://github.com/solana-labs/solana-program-library/blame/62d6a8825204dc221464d7dffde3608081f8250e/memo/program/tests/functional.rs#L147-L151

joncinque commented 1 week ago

We found that the test was flaky, and would throw one error or the other, but I never did any digging to find out exactly why that was happening.