Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Refactor - LoadedPrograms::assign_program() #35233

Merged

Conversation

Lichtso
Copy link
Contributor

@Lichtso Lichtso commented Feb 19, 2024

Problem

Summary of Changes

  • Forbids all program replacements except for reloads and builtins.
  • Removes test_assign_program_tombstones()
  • Adds test_assign_program_failure() and test_assign_program_success().

Copy link

codecov bot commented Feb 19, 2024

Codecov Report

Attention: Patch coverage is 92.59259% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 81.6%. Comparing base (537c3d8) to head (89b434d).
Report is 9 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##           master   #35233     +/-   ##
=========================================
- Coverage    81.6%    81.6%   -0.1%     
=========================================
  Files         834      834             
  Lines      224798   224829     +31     
=========================================
+ Hits       183485   183499     +14     
- Misses      41313    41330     +17     

@pgarg66
Copy link
Contributor

pgarg66 commented Feb 22, 2024

LGTM. @alessandrod, are you planning to review as well?

@alessandrod
Copy link
Contributor

Yep going to review today

(LoadedProgramType::Unloaded(_), LoadedProgramType::TestLoaded(_)) => {}
_ => {
// Something is wrong, I can feel it ...
debug_assert!(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we should log::error! and print existing and entry here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: pass a panic message to debug_assert and test for it in should_panic in tests

existing.ix_usage_counter.load(Ordering::Relaxed),
Ordering::Relaxed,
);
*existing = entry.clone();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be Arc::clone(&entry)

Ordering::Relaxed,
);
*existing = entry.clone();
self.stats.reloads.fetch_add(1, Ordering::Relaxed);
}
Err(index) => {
self.stats.insertions.fetch_add(1, Ordering::Relaxed);
slot_versions.insert(index, entry.clone());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arc::clone too.

And shouldn't we also assert which entry types can't get inserted here? Like DelayVisibility

LoadedProgramType::Builtin(BuiltinProgram::new_mock()),
LoadedProgramType::Builtin(BuiltinProgram::new_mock())
)]
fn test_assign_program_success(old: LoadedProgramType, new: LoadedProgramType) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about LegacyV*? We have some elf files in the monorepo can't we test those?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do that I want to do it for the entire file in a separate PR and get rid of TestLoaded entirely.

program-runtime/src/loaded_programs.rs Show resolved Hide resolved
@Lichtso Lichtso force-pushed the refactor/loaded_programs_assign_program branch 2 times, most recently from e178517 to ab0509f Compare February 23, 2024 11:16
@Lichtso Lichtso force-pushed the refactor/loaded_programs_assign_program branch from ab0509f to 89b434d Compare February 23, 2024 11:19
@Lichtso Lichtso requested a review from alessandrod February 26, 2024 13:58
Copy link
Contributor

@alessandrod alessandrod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, keeping in mind this needs to be done #35233 (comment)

@Lichtso Lichtso merged commit e6f8cdc into solana-labs:master Feb 28, 2024
46 checks passed
@Lichtso Lichtso deleted the refactor/loaded_programs_assign_program branch February 28, 2024 08:20
buffalojoec added a commit to solana-program/address-lookup-table that referenced this pull request Mar 13, 2024
This PR introduces the Core BPF implementation of Address Lookup Table.

There are a few caveats with the implementation so far. You can find them in the
source code by searching for comments prefixed with:

```
[Core BPF]:
```

The following caveats will be solved in the next Solana release, and a
discussion can be had for backporting any of these changes:

- `InstructionError::Immutable` has no `ProgramError` counterpart
  ([#35113](solana-labs/solana#35113)).
- `InstructionError::IncorrectAuthority` has no `ProgramError` counterpart
  ([#35113](solana-labs/solana#35113)).
- `solana-program-test` will not overwrite a builtin if the BPF program you've
  provided shares the same address as an existing builtin
  ([#35233](solana-labs/solana#35233)).

The following caveat seems to be unavoidable:

- The `build.rs` script and annotations in `lib.rs` are required for 
  `solana-frozen-abi-macro` (See #3).

Finally, I've implemented a cooldown period based on `Clock`, but this will
likely not be sufficient. I think we should consider merging this initial
implementation and leaving #1 unfinished until the proper research is completed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants