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

[x/programs] refactor init #432

Merged
merged 7 commits into from
Aug 29, 2023
Merged

[x/programs] refactor init #432

merged 7 commits into from
Aug 29, 2023

Conversation

samliok
Copy link
Contributor

@samliok samliok commented Aug 29, 2023

Removes initialize_program host function and the Program struct in Rust.

Instead we generate and initialize the programs storage and id in go and inject it into the init function.

Changes

  • Removes the Program folder
  • Removes the host function initialize_function
  • Adds a Create method to the go runtime that sets up global storage and calls init on the program
    • Create "publishes" the program, while Initialize grabs the published program.
  • Updated the expose macro to ensure the first argument is always of type Context
  • updates examples & tests

@samliok samliok linked an issue Aug 29, 2023 that may be closed by this pull request
x/programs/runtime/runtime.go Outdated Show resolved Hide resolved
x/programs/rust/examples/counter/src/lib.rs Outdated Show resolved Hide resolved
x/programs/rust/examples/token/src/lib.rs Show resolved Hide resolved
x/programs/rust/examples/token/src/lib.rs Outdated Show resolved Hide resolved
x/programs/rust/expose_macro/src/lib.rs Outdated Show resolved Hide resolved
x/programs/rust/expose_macro/src/lib.rs Show resolved Hide resolved
@patrick-ogrady patrick-ogrady merged commit 9faea85 into main Aug 29, 2023
@patrick-ogrady patrick-ogrady deleted the x/init branch August 29, 2023 21:04
@@ -8,6 +8,8 @@ import (
)

type Runtime interface {
// Create initializes and calls the init function.
Create(context.Context, []byte) (uint64, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't believe this is actually a necessary part of the runtime interface. Once the runtime is initialized then the user can make whatever call they want. My understanding is that a programID would be the result of a transaction generated by the VM.

@@ -44,6 +44,27 @@ type runtime struct {
log logging.Logger
}

func (r *runtime) Create(ctx context.Context, programBytes []byte) (uint64, error) {
err := r.Initialize(ctx, programBytes)
Copy link
Contributor

Choose a reason for hiding this comment

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

why isn't this part of Initialize Runtime?

programID := initProgramStorage()

// call initialize
result, err := r.Call(ctx, "init", uint64(programID))
Copy link
Contributor

Choose a reason for hiding this comment

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

init in this context is perhaps required by the examples as they are now but as stated above the programID is going to be the result something like a create_program action. I would like us moving towards that direction in each iteration if possible.

// Initialize the program with no fields
Program::new().into()
true
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the fact that we end up with a hard coded bool here speaks to the fact that init should not be a requirement.

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.

[x/programs] inject the program-id and pass it into the init function?
4 participants