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

Program config storage #593

Merged
merged 14 commits into from
Jan 18, 2024
Merged

Program config storage #593

merged 14 commits into from
Jan 18, 2024

Conversation

JesseAbram
Copy link
Member

@JesseAbram JesseAbram commented Jan 16, 2024

This adds the storage for program config see.

  • program_type_definition added to Program Info
  • programs_data (program_pointer, program_config) added to user's RegisteredInfo

Copy link

vercel bot commented Jan 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
entropy-core ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 18, 2024 4:28pm

Copy link
Contributor

@ameba23 ameba23 left a comment

Choose a reason for hiding this comment

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

If i've understood right, the idea here is to add the storage logic for program config in this PR, and the actual evaluating a program together with its config will be done separately once entropyxyz/programs#56 is merged.

Anyway this looks great. Personally i would use Option rather than an empty vector to represent no program config, as in the programs PR evaluate takes an Option<Vec<u8>> for the configuration. And generally i think it makes it more explicit - but this works as it is.

Probably more of an issue for Programs, but it would be nice to have a way to ensure that programs which require a configuration are given a valid configuration at the point of registration / updating, rather than at the point of requesting a signature. I'm not sure if that will be too difficult - as in is there a way that given a ProgramData, we can tell whether the configuration is valid for the program, without actually evaluating it with a message.

I'm not sure if ProgramData is the best name, but i don't have a better proposal.

Generally, i think its going be hard for devs to figure out the difference between auxiliary data and configuration, be nice to have names which make it obvious that auxiliary data can vary for each message whereas configuration only varies for each user.

So thumbs up but leaving this as comment for now as not sure if its still WIP, and changelog needs updating.

@JesseAbram JesseAbram marked this pull request as ready for review January 17, 2024 13:46
@JesseAbram
Copy link
Member Author

If i've understood right, the idea here is to add the storage logic for program config in this PR, and the actual evaluating a program together with its config will be done separately once entropyxyz/programs#56 is merged.

yup exactly

Anyway this looks great. Personally i would use Option rather than an empty vector to represent no program config, as in the programs PR evaluate takes an Option<Vec<u8>> for the configuration. And generally i think it makes it more explicit - but this works as it is.

mmm I debated this, I just went for consistency here, Im ok with either but if so then this and pointer should be like this

Probably more of an issue for Programs, but it would be nice to have a way to ensure that programs which require a configuration are given a valid configuration at the point of registration / updating, rather than at the point of requesting a signature. I'm not sure if that will be too difficult - as in is there a way that given a ProgramData, we can tell whether the configuration is valid for the program, without actually evaluating it with a message.

I talked about this with jake, it is on the roadmap but a little more complicated and not getting done soon

I'm not sure if ProgramData is the best name, but i don't have a better proposal.

im sure hernando or jake will come up with something

Generally, i think its going be hard for devs to figure out the difference between auxiliary data and configuration, be nice to have names which make it obvious that auxiliary data can vary for each message whereas configuration only varies for each user.

yeee I mean let's get people using it and then we can tweek, doc etc

So thumbs up but leaving this as comment for now as not sure if its still WIP, and changelog needs updating.

Copy link
Collaborator

@HCastano HCastano left a comment

Choose a reason for hiding this comment

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

The big question for me here is the type_definition in the Programs pallet, and what it's role is

Comment on lines +99 to +100
/// The type definition of the program
pub program_type_definition: Vec<u8>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's a type definition in this context? I haven't seen this term used in the issue or in Jake's PR

Copy link
Member Author

Choose a reason for hiding this comment

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

pretty much it is the serialized json input that the program expects for the config input

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 called something like "serialized_config" to corospond to the optional config parameter of evaluate of type Option<Vec<u8>>. Programs are not required to have a config, and "type definition" doesn't really make semantic sense

Copy link
Contributor

Choose a reason for hiding this comment

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

or if this is what describes in JSON what kind of JSON interface a program might take, we should remove this for now as wit-generation from types doesn't exist yet and unlikely going in anytime soon.

I've got a few solutions to check that a JSON config is valid, but the solutions are ugly and they deserve more though first. I suspect there will be a new function on the Program that takes the JSON config as an input string and returns Result<(), Error>.

Copy link
Member Author

Choose a reason for hiding this comment

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

Im not sure I understand, we talked about this and about how currently a program owner would self set this option so the front end can know and understand what needs to be set as config when registering (or choosing their program)

@@ -88,12 +88,19 @@ pub mod pallet {
}
pub type ProgramPointers<Hash, MaxProgramHashes> = BoundedVec<Hash, MaxProgramHashes>;

#[derive(Clone, Encode, Decode, Eq, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo)]
#[scale_info(skip_type_params(T))]
pub struct ProgramData<T: Config> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suggest changing this to ProgramInstance. An instance is made up of code + configuration.

There can be a separation of responsibilities here too. While the Programs pallet manages and tracks bytecode, and the Relayer (or Registry) pallet manages and tracks instances.

Copy link
Member Author

Choose a reason for hiding this comment

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

ya that works for me

#[scale_info(skip_type_params(T))]
pub struct ProgramData<T: Config> {
pub program_pointer: T::Hash,
pub program_config: Vec<u8>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

While I generally I agree with Peg here in that this should be more explicit as an Option - the Programs pallet already accepts empty programs with just an empty vector, and this kinda matches that API.

Maybe the best people to answer this will actually be on the SDK side. Which of the two options makes their code easier to serialize correctly?

cc @jawndiego @frankiebee ?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes I also heavily lean towards symmetry on this one as in whatever we decide they both should do it, so no matter what is decided I feel like it should be handled in a follow up PR

Comment on lines 183 to 184
/// An account hash changed their program pointers [who, new_programs_data]
ProgramPointerChanged(T::AccountId, BoundedVec<ProgramData<T>, T::MaxProgramHashes>),
Copy link
Collaborator

Choose a reason for hiding this comment

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

This'll have to be updated to mention instances, or at least the config side of this too

) -> anyhow::Result<<EntropyConfig as Config>::Hash> {
let update_program_tx = entropy::tx().programs().set_program(program);
let update_program_tx = entropy::tx().programs().set_program(program, program_config);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah so this is defined as type_definition in the Programs pallet but it's a config here. So what is it supposed to be?

@JesseAbram JesseAbram requested a review from HCastano January 18, 2024 15:34
@JesseAbram JesseAbram merged commit 9458361 into master Jan 18, 2024
10 checks passed
@JesseAbram JesseAbram deleted the program-config-storage branch January 18, 2024 16:39
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.

4 participants