Commit Graph

126 Commits

Author SHA1 Message Date
Alexander Meißner 24a87f33a8
Refactor - Cleanup error handling in program runtime (#30693)
* Moves stable_log::program_invoke(), stable_log::program_success() and stable_log::program_failure() calls from bpf_loader into InvokeContext::process_executable_chain().

* Turns result of ProcessInstructionWithContext from InstructionError into Box<dyn std::error::Error>.

* Bump to solana_rbpf v0.3.0

* Removes Result from return type of EbpfVm::new().

* Turns EbpfError into Box<dyn std::error::Error>.

* Removes BpfError.

* Removes SyscallError::InstructionError.

* Adds a type alias for Box<dyn std::error::Error> in syscalls.
2023-04-05 15:50:34 +02:00
Alexander Meißner a0c7fde90e
Cleanup - mock InvokeContext (#31007)
* Turns with_mock_invoke_context() into a macro.

* Removes prepare_mock_invoke_context().

* Replaces InvokeContext::new_mock() with with_mock_invoke_context().

* Removes InvokeContext::new_mock().

* Removes Cow from InvokeContext::sysvar_cache.

* Removes override parameters from mock_process_instruction().

* cargo fmt
2023-04-03 17:23:24 +02:00
Tao Zhu 3e500d9e92
Feature gate builtin consumes static units during processing instruction (#30702)
* add feature gate
* builtins consume statically defined units at beginning of process_instruction()
* Add new instructionError; return error if builtin did not consume units to enforce builtin to consume units;
* updated related tests
* updated ProgramTest with deactivated native_programs_consume_cu feature to continue support existing mock/test programs that do not consume units
2023-03-24 11:31:01 -05:00
Alexander Meißner 38e74325e3
Refactor - Remove `process_instruction` parameter `first_instruction_account` (#30579)
* Stops using first_instruction_account parameter in bpf_loader.

* Removes first_instruction_account parameter from process_instruction().
2023-03-06 17:37:37 +01:00
behzad nouri 12da2da389
fixes errors from clippy::redundant_clone (#29536)
https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
2023-01-05 18:42:19 +00:00
Alexander Meißner 12d2147efa
Adds `IndexOfAccount` type (#27599)
Adds the type `IndexOfAccount`.
2022-09-06 11:31:40 +02:00
Alexander Meißner 6f2e556b16
Cleanup: `TransactionContext` (#27595)
* Lets instruction_accounts_lamport_sum() have the &InstructionContext as parameter directly.

* Updates docu comments.

* Uses accessors methods instead of accessing private properties of other structs.

* Adds #![deny(clippy::indexing_slicing)].

* Has get_signers() return a Result instead of using unwrap().

* Removes InvokeContext::get_key_of_account_at_index().
2022-09-05 16:29:02 +02:00
Michael Vines ccfbc54195 Move vote program state and instructions to solana-program 2022-08-09 20:52:47 -07:00
Tyera Eulberg 2481ebb150
Add explicit comment about get_stake_account to StakeInstruction enum (#26824)
Add explicit comment about get_stake_account
2022-07-27 20:44:52 -06:00
Michael Vines 48862c575a Add StakeInstruction::Redelegate 2022-07-27 20:24:25 -06:00
Alexander Meißner 075a5ac44e
Removes `AccountSharedData` from `SysvarCache`. (#26712)
* Removes AccountSharedData from SysvarCache.

* Fixes incorrect transaction account index in stake_instruction::test_set_lockup().
2022-07-21 18:32:28 +02:00
Brooks Prumo ef30f1729c
Cleanup stake_instruction tests (#26393) 2022-07-06 16:15:01 -05:00
Alexander Meißner c01a8f271e
Prepare built-in program tests to deal with stricter account modification checks (#26314)
* Fixes test_vote_state_withdraw().

* Set is_writable to true where needed.
2022-06-29 19:29:12 +02:00
Alexander Meißner bf9ca9827e
Refactor: instruction account index (#25825)
* Adds methods based on instruction_account_index to InstructionContext.
Removes methods which are based on index_in_instruction.

* Adjusts program-runtime.

* Adjusts runtime.

* Adjusts bpf loader.

* Adjusts built-in programs.

* Adjusts program-test and bpf tests.
2022-06-16 18:46:17 +02:00
bji cbb0f07d54
Award one credit per dequeued vote when processing VoteStateUpdate in… (#25743)
* Award one credit per dequeued vote when processing VoteStateUpdate instruction,
to match vote rewards of Vote instruction.

* Update feature pubkey to one owned by cc (ashwin)

Co-authored-by: Ashwin Sekar <ashwin@solana.com>
2022-06-06 16:37:03 -07:00
Brooks Prumo 0b2d5291f8
Add new error if stake delegation is below the minimum (#25709) 2022-06-01 20:29:57 -05:00
Brooks Prumo e6c02f30dd
Raise minimum stake delegation to 1 SOL (#24603) 2022-05-07 19:01:05 -04:00
Jon Cinque 326e53be97
stake: Allow initialized stakes to be below the min delegation (#24670)
* stake: Allow initialized stakes to be below the min delegation

* Add PR number in feature

* Fixup RPC subscription test

* Address feedback pt 1

* Address feedback pt 2

* Update FrozenAbi Digest

* Address feedback: no new error type, more comments
2022-05-04 12:17:29 +02:00
Justin Starry 2ad1baa753
Add const fn StakeState::size_of and static assertion (#24416) 2022-04-20 01:04:12 +08:00
Brooks Prumo f33ad34531
Add feature_set_override parameter to mock_process_instruction() (#24386) 2022-04-15 13:43:04 -05:00
Brooks Prumo 34418cb848
Stake tests use get_minimum_delegation() (#24382) 2022-04-15 18:30:45 +00:00
Brooks Prumo 7cf80a3f62
Fix test to use correct/updated account in transaction (#24363) 2022-04-15 05:15:02 -05:00
Michael Vines 57ff7371b4 Add StakeInstruction::DeactivateDelinquent 2022-04-14 01:49:22 -04:00
Brooks Prumo f7b00ada1b
GetMinimumDelegation does not require a stake account (#24192) 2022-04-11 16:26:36 -05:00
Alexander Meißner bf13fb4c4b
Remove `KeyedAccount` in builtin program "stake" (#24210)
* Inline keyed_account_at_index() in all instructions of stake
which have more than one KeyedAccount parameter,
because these could cause a borrow collision.

* Uses transaction_context.get_key_of_account_at_index() in stake.

* Refactors stake::config::from to use BorrowedAccount instead of ReadableAccount.

* Replaces KeyedAccount by BorrowedAccount in stake.
2022-04-10 09:55:37 +02:00
Alexander Meißner cb1507126f
Fixes check_number_of_instruction_accounts() in StakeInstruction::Authorize. (#24172) 2022-04-08 12:43:55 +02:00
Brooks Prumo a100b32b37
Add test for GetMinimumDelegation stake instruction (#24158) 2022-04-07 11:54:15 -05:00
Alexander Meißner efb9cbd8e7
Refactor: Remove `trait` from stake keyed account (#24148)
Removes trait from StakeAccount.
2022-04-06 22:58:09 +02:00
Alexander Meißner 07f4a9040a
Removes KeyedAccount from tests in stake instruction. (Part 4) (#24124)
* Moves tests from stake state to stake instruction.

* Migrates test_merge.

* Migrates test_merge_self_fails.

* Migrates test_merge_incorrect_authorized_staker.

* Migrates test_merge_invalid_account_data.

* Migrates test_merge_fake_stake_source.

* Migrates test_merge_active_stake.
2022-04-06 12:04:35 +02:00
Alexander Meißner e051c7c162
Removes KeyedAccount from tests in stake instruction. (Part 3) (#24110)
* Moves test from stake state to stake instruction.

* Migrates test_split_source_uninitialized.

* Migrates test_split_split_not_uninitialized.

* Migrates test_split_more_than_staked.

* Migrates test_split_with_rent.

* Migrates test_split_to_account_with_rent_exempt_reserve.

* Migrates test_split_from_larger_sized_account.

* Migrates test_split_from_smaller_sized_account.

* Migrates test_split_100_percent_of_source.

* Migrates test_split_100_percent_of_source_to_account_with_lamports.

* Migrates test_split_rent_exemptness.
2022-04-05 12:36:01 +02:00
Brooks Prumo 2af6753808
Add GetMinimumDelegation stake program instruction (#24020) 2022-04-02 05:11:10 +00:00
Alexander Meißner 8a18c48e47
Removes `KeyedAccount` from tests in stake instruction. (Part 2) (#24053)
* Migrates test_initialize_minimum_stake_delegation.

* Migrates test_delegate_minimum_stake_delegation.

* Migrates test_split_minimum_stake_delegation.

* Migrates test_split_full_amount_minimum_stake_delegation.

* Migrates test_split_destination_minimum_stake_delegation.

* Migrates test_withdraw_minimum_stake_delegation.

* Migrates test_behavior_withdrawal_then_redelegate_with_less_than_minimum_stake_delegation.
2022-04-02 01:08:55 +02:00
Alexander Meißner 1b45c509c3
Refactor: Use `InstructionContext::get_instruction_data()` (#24014)
* Adds transaction_context and instruction_context where invoke_context.get_keyed_accounts() is used.

* Use instruction_context.get_instruction_data() instead of an explicit parameter.

* Removes instruction_data parameter from Executor::execute().

* Removes instruction_data parameter from ProcessInstructionWithContext.
2022-04-01 15:48:05 +02:00
Justin Starry cb5e67d327
Use Rent sysvar directly for stake split instruction (#24008)
* Use Rent sysvar directly for stake split ix

* Add feature to gate rent sysvar change

* fix tests

* cargo clippy
2022-03-31 16:46:35 +08:00
Alexander Meißner 794645d092
Adds check_number_of_instruction_accounts() to all builtin programs except for the address-lookup-table. (#23984) 2022-03-29 19:06:50 +02:00
Alexander Meißner 140c8dd01f
Refactor: Replaces KeyedAccount in_get_sysvar_with_account_check (#23905)
* Replaces all use sites of get_sysvar_with_account_check by get_sysvar_with_account_check2.

* Removes get_sysvar_with_account_check.

* Renames get_sysvar_with_account_check2 to get_sysvar_with_account_check.
2022-03-24 19:30:42 +01:00
Alexander Meißner 91c2729856
Replaces keyed_account get_signers() by InstructionContext::get_signers(). (#23863) 2022-03-24 12:57:51 +01:00
Brooks Prumo 18bddbc730
Stake tests respect MINIMUM_STAKE_DELEGATION (#23426) 2022-03-16 16:36:23 -05:00
Alexander Meißner 584ac80b1e
Revert: `KeyedAccount` refactoings in builtin programs (#23649)
* Revert "Replaces KeyedAccount by BorrowedAccount in the BPF loader. (#23056)"

6c56eb9663

* Revert "Replaces `KeyedAccount` by `BorrowedAccount` in `system_instruction_processor`. (#23217)"

ee7e411d68

* Revert "Replaces `KeyedAccount` by `BorrowedAccount` in `nonce_keyed_account`. (#23214)"

1a68f81f89

* Revert "Replaces KeyedAccount by BorrowedAccount in the config processor. (#23302)"

a14c7c37ee

* Revert "Replaces `KeyedAccount` by `BorrowedAccount` in vote processor (#23348)"

e2fa6a0f7a

* Revert "Refactor: Prepare stake_instruction.rs to remove `KeyedAccount`s (#23375)"

ee3fc39f1c
2022-03-16 11:30:01 +01:00
Alexander Meißner e9040d2766
Adds a missing check_number_of_instruction_accounts() in StakeInstruction::Authorize. (#23672) 2022-03-15 15:53:11 +01:00
Alexander Meißner e60c9b97c9
Removes `KeyedAccount` from tests in stake instruction. (Part 1) (#23473)
* Migrates test_stake_delegate().

* Migrates test_stake_initialize().

* Migrates test_initialize_incorrect_account_sizes().

* Migrates test_authorize().

* Migrates test_authorize_lockup().

* Migrates test_authorize_override().

* Migrates test_authorize_with_seed().

* Migrates test_split().

* Migrates test_split_fake_stake_dest().

* Migrates test_deactivate().

* Migrates test_set_lockup().

* Migrates test_optional_lockup_for_stake_program().

* Migrates test_withdraw_stake().

* Migrates test_withdraw_stake_invalid_state().

* Migrates test_withdraw_stake_before_warmup().

* Migrates test_withdraw_lockup().

* Migrates test_withdraw_identical_authorities().

* Migrates test_withdraw_rent_exempt().

* Migrates test_authorize_delegated_stake().

* Migrates test_redelegate_consider_balance_changes().
2022-03-09 23:48:10 +01:00
Alexander Meißner ee3fc39f1c
Refactor: Prepare stake_instruction.rs to remove `KeyedAccount`s (#23375)
* Adds instruction_account_indices to stake instruction.

* Uses instruction_account_indices in stake instruction.

* Replaces get_sysvar_with_account_check by get_sysvar_with_account_check2 in stake instruction.

* Adds check_number_of_instruction_accounts().
2022-02-28 16:24:40 +01:00
Alexander Meißner 569d531573
Code cleanup: In vote and stake processor (#23353)
* Enable benchmarks of vote processor.

* Inlines from_keyed_account() in stake instruction.
2022-02-25 21:05:05 +01:00
Alexander Meißner c16cf9cf8a
Refactor: Use `SysvarCache` in all builtin programs (#22864)
* Replaces from_keyed_account() by SysvarCache in stake instruction.

* Replaces from_keyed_account() by SysvarCache in system instruction processor.

* Removes from_keyed_account().
Moves check_sysvar_keyed_account() into sysvar_cache.rs

* Removes tests which test for incorrectly serialized sysvars.
2022-02-03 13:03:50 +01:00
Alexander Meißner bc800a8d5a
Refactor: Unify `SysvarCache` (#22843)
* Unifies SysvarCache filling in the runtime and tests.
Removes new_mock_with_sysvars_and_features()
Removes mock_process_instruction_with_sysvars().
Replaces from_keyed_account() by SysvarCache in vote processor.

* Replaces from_keyed_account() by SysvarCache in BPF loader.
2022-01-31 17:53:50 +01:00
Brooks Prumo a7f2fff219
Remove active features stake program v3 and v4 (#22612)
Co-authored-by: Jon Cinque <jon.cinque@gmail.com>
2022-01-21 19:27:53 -06:00
Justin Starry 2370e61431
Perf: Store deserialized sysvars in the sysvars cache (#22455)
* Perf: Store deserialized sysvars in sysvars cache

* add bench
2022-01-13 05:36:21 +00:00
Justin Starry 7171c95bdd Refactor: move sysvar cache to new module 2022-01-12 12:35:28 -07:00
Alexander Meißner 66fa8f9667
Refactor: Removes `Rc` from `Refcell<AccountSharedData>` in the program-runtime (#21927)
* Removes Rc from Rc<RefCell<AccountSharedData>> in the program-runtime.

* Adjusts tests in bpf_loader, system_instruction_processor, config_processor, vote_instruction and stake_instruction
2021-12-17 14:01:12 +01:00
Alexander Meißner 1df88837c8
- Implicitly fixes invoke_context.return_data not being reset between instructions in process_message. (#21671)
- Lets InvokeContext::process_cross_program_instruction() handle the first invocation depth too.
- Marks InvokeContext::verify(), InvokeContext::verify_and_update() and InvokeContext::process_executable_chain() private.
- Renames InvokeContext::process_cross_program_instruction() to InvokeContext::process_instruction().
- Removes InvokeContext::new_mock_with_sysvars().
2021-12-07 23:00:04 +01:00