Skip to content
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

Move address_lookup_table program id declaration to solana-program #30617

Closed

Conversation

tao-stones
Copy link
Contributor

@tao-stones tao-stones commented Mar 6, 2023

Problem

address_lookup_table_program ID is declared in its own crate, one has to pull in the program crate in order to use its id(). This would result circular dependencies if trying to use its id() from lower lever, eg. from program-runtime.

One use case is #30620 to make builtins to consume CUs at invoke_context::process_executable_chain(). I added test_define_default_cost_for_builtins to program-runtime::invoke_context to demonstrate possible use case.

Since program IDs are statically/globally declared, perhaps make sense not to encapsulate it into program crate.

Summary of Changes

  • Separate static ID decl from program crate, move declaration to solana-program alone with other native programs.
  • Program crate itself, and other call sites, both refer to solana-program for ID.
  • Add a test to demonstrate use case.

Fixes #

@tao-stones tao-stones force-pushed the move-alt-progrtam-id-to-sdk branch 3 times, most recently from 4d4894a to 9202ed8 Compare March 7, 2023 01:12
@mvines
Copy link
Member

mvines commented Mar 7, 2023

move its id declaration to sdk.

It's being moved to solana-program, not solana-sdk, though

sdk/src/lib.rs Outdated Show resolved Hide resolved
@tao-stones
Copy link
Contributor Author

move its id declaration to sdk.

It's being moved to solana-program, not solana-sdk, though

thanks for pointing it out, reworded.

@mvines mvines changed the title Move address_lookup_table program id declaration to solana_sdk Move address_lookup_table program id declaration to solana-program Mar 7, 2023
@joncinque
Copy link
Contributor

joncinque commented Mar 7, 2023

The idea of #23700 is to have less stuff in solana-sdk / solana-program. Having everything in those crates has caused unclear issues like #30515, where people got build errors for VoteState.

So in general, we should come up with a way to isolate programs in their crates rather putting more stuff in the sdk / program, same as spl program crates.

What's the motivation for moving this?

@tao-stones
Copy link
Contributor Author

The idea of #23700 is to have less stuff in solana-sdk / solana-program. Having everything in those crates has caused unclear issues like #30515, where people got build errors for VoteState.

So in general, we should come up with a way to isolate programs in their crates rather putting more stuff in the sdk / program, same as spl program crates.

What's the motivation for moving this?

@joncinque and I chatted offline, I updated PR description and added a test that demonstrate the potential use case.

@tao-stones tao-stones requested a review from joncinque March 7, 2023 18:25
// encapsulated within program-runtime, accessible to both invoke_context
// (to make builtins to consume CUs) and by runtime::cost_model.
//
lazy_static::lazy_static! {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This static HashMap currently exists in runtime, not directly accessible by program-runtime::invoke_context. IMO it makes sense to define native's default cost in program-runtime, where compute_budget declares costs for various actions. Other option is to pass the default costs HashMap from runtime via builtin programs call chain to invoke_context.

Copy link
Contributor

@joncinque joncinque Mar 7, 2023

Choose a reason for hiding this comment

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

Native programs are defined / built on top of program-runtime, so it makes more sense to me to define their costs somewhere above program-runtime.

Currently, the way it goes:

  • the compute budget defines costs for syscalls that are implemented in the program-runtime
  • the runtime defines costs for its native programs
  • the runtime passes native programs down to the invoke context

So you could even have a cost field in invoke_context::BuiltinProgram, and deduct straight from there, and that way it'll be impossible to define a new builtin program and forget to associate a cost. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so it makes more sense to me to define their costs somewhere above program-runtime.

While I think IDs can be declared elsewhere, but totally agree costs should be defined above program-runtime,

I like the idea a lot for builtin program to carry a mandatory cost field. That removes the extra HashMap<program_id, cost> which is hard to maintain separately. Also have builtin developer to identify its default cost is way better than what's been done so far. (can also promote dev to implement more complex builtins to properly consume units).

I made POC PR #30639 , is this somewhat close to what's in your mind?

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 Address-lookup-table-program is the new way to go, what's our plan for existing builtins that somewhat resides in solana-program/SDk? Will they be refactored into self-contain crate just like ALT?

Copy link
Contributor

@joncinque joncinque Mar 8, 2023

Choose a reason for hiding this comment

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

There's no plan in place just yet to move existing declarations back up, but we could:

  • deprecate native programs in solana-program and add them with crate features, which are enabled by default, ie. "stake" feature includes all of the stake program bindings
  • undeprecate their re-exports from their crates, ie. solana-stake-program becomes the place to import from
  • add the proper compile guards, just like the ALT program
  • whenever we do v2, completely move the structs / instructions / ids into their crates

It's kind of a dumpy situation (that I put us in 😓 ). it's always tougher to move something up than down, especially for people that depend on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, good to know. Thanks for the explanation!

(solana_program::bpf_loader_upgradeable::id(), 2370),
(solana_program::bpf_loader_deprecated::id(), 1140),
(solana_program::bpf_loader::id(), 570),
// inconsistent
Copy link
Contributor Author

Choose a reason for hiding this comment

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

still have two inconsistencies to address

@tao-stones tao-stones force-pushed the move-alt-progrtam-id-to-sdk branch from 2c9662e to 0ccb9f9 Compare March 7, 2023 18:46
@tao-stones
Copy link
Contributor Author

close it in favor of #30639 (discussion #30617 (comment))

@tao-stones tao-stones closed this Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants