-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor - LoadedProgramType::Loaded
and LoadedProgramOwner
#606
Conversation
4514047
to
9aa7c05
Compare
4199d18
to
26e2adf
Compare
Could you, please, explain in plain English what this means? |
What I meant is that instead of a generic
we instead have a combined one (basically a form of monomorphization):
So whenever you want to get the contained
|
26e2adf
to
8261960
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #606 +/- ##
=========================================
- Coverage 81.9% 81.9% -0.1%
=========================================
Files 851 851
Lines 231209 231288 +79
=========================================
+ Hits 189495 189536 +41
- Misses 41714 41752 +38 |
#[cfg(test)] | ||
TestLoaded(ProgramRuntimeEnvironment), | ||
/// Verified and compiled program | ||
Loaded(Executable<InvokeContext<'static>>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe not to address in this PR, but I think the enum name is misnomer. A LoadedProgramType value can be 'Loaded', 'Unloaded', or something else. It doesn't make sense when a 'loaded program' is in fact 'unloaded'. It also doesn't make sense that for a LoadedProgramType you add an enum value 'Loaded'. If only 'Loaded' programs are loaded, then what are other 'LoadedProgramType' values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you are right, it evolved over time and we never adjusted the naming.
How about renaming (in a different PR):
LoadedProgram
=>ProgramCacheEntry
LoadedProgramType
=>ProgramCacheEntryType
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely, sounds better. I don't insist that these name changes should be in this PR. It's up to you.
Thanks for the explanation. I'm not convinced that monomorphization is applicable nomenclature in this situation. As far as I understand monomorphization is performed by compiler if a trait can be resolved to a concrete type at compile time, when static dispatch is used. |
It might be a generous view of what "monomorphization" includes, but IMO it means instantiating generics by giving them a distinct code path each. And because the enum items have individual code paths it made sense to me. |
3339803
to
cf8f6ba
Compare
Merges LoadedProgramTypes LegacyV0, LegacyV1, Typed and TestLoaded into Loaded.
cf8f6ba
to
1e59c45
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry it took so long to review!
I love this, we're testing more, code looks better and logic is simpler. Thanks a lot for doing it.
I only left a few nits, otherwise looks great.
LoadedProgramType::LegacyV0(executable) | ||
} else if bpf_loader::check_id(loader_key) || bpf_loader_upgradeable::check_id(loader_key) { | ||
LoadedProgramType::LegacyV1(executable) | ||
let account_owner = if bpf_loader_deprecated::check_id(loader_key) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this is LoadedProgramOwner::try_from(loader_key)
@@ -393,6 +391,7 @@ impl LoadedProgram { | |||
} | |||
Some(Self { | |||
program: LoadedProgramType::Unloaded(self.program.get_environment()?.clone()), | |||
account_owner: self.account_owner.clone(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: the owner type should probably be Copy?
@@ -464,6 +469,16 @@ impl LoadedProgram { | |||
let decaying_for = std::cmp::min(63, now.saturating_sub(last_access)); | |||
self.tx_usage_counter.load(Ordering::Relaxed) >> decaying_for | |||
} | |||
|
|||
pub fn account_owner(&self) -> Pubkey { | |||
match self.account_owner { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this is Into for LoadedProgramOwner
Some((*id, program.clone())) | ||
LoadedProgramType::Loaded(_) => { | ||
let include = | ||
if let LoadedProgramOwner::LoaderV4 = program.account_owner { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: if you implement Eq for LoadedProgramOwner then I think this can become one
if with LoaderV4 && include_program_runtime_v2 { .. } else if
include_program_runtime_v1 { ... }
ff96903
to
235c54b
Compare
235c54b
to
e4aaf05
Compare
…-xyz#606) * Adds LoadedProgram::account_owner() and LoadedProgramOwner. Merges LoadedProgramTypes LegacyV0, LegacyV1, Typed and TestLoaded into Loaded. * Review feedback.
Problems
LoadedProgramType::TestLoaded
) instead of the production code.LegacyV0
,LegacyV1
andTyped
, which has to be undone everywhere the carried executable is needed. It should be a separate field ofLoadedProgram
instead and that could also be used by otherLoadedProgramType
s.Summary of Changes
LoadedProgramType
sLegacyV0
,LegacyV1
,Typed
andTestLoaded
intoLoaded
.LoadedProgram::account_owner()
andLoadedProgramOwner
. Using the pubkey of the loader directly was also an option, but I didn't see any reason to waste storing and comparing 256 bits when there can be at mostlog_2(5)
~ 2.3219 bits of entropy.