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

add RegistryFactory and deprecate global action, auth and output registries in VMs #1624

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

tsachiherman
Copy link
Contributor

What ?

add RegistryFactory and deprecate global action, auth and output registries in VMs

Why ?

Avoid creation of global registries and pass these along the call stack as part of the server context.

@tsachiherman tsachiherman self-assigned this Oct 2, 2024
@tsachiherman tsachiherman marked this pull request as ready for review October 2, 2024 16:31
Copy link
Collaborator

@richardpringle richardpringle left a comment

Choose a reason for hiding this comment

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

Looks better than before, but I think types where order doesn't matter are typically less error-prone (struct over tuple).

@@ -287,3 +287,6 @@ type AuthFactory interface {
MaxUnits() (bandwidth uint64, compute uint64)
Address() codec.Address
}

// RegistryFactory is the factory function, provided to the VM initializer that provides the registries for teh actions, auth and output.
type RegistryFactory func() (actionRegistry ActionRegistry, authRegistry AuthRegistry, outputRegistry OutputRegistry)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be better to have a struct here?

type Registry struct {
    action ActionRegistry
    auth   AuthRegistry
    output OutputRegistry
}
Suggested change
type RegistryFactory func() (actionRegistry ActionRegistry, authRegistry AuthRegistry, outputRegistry OutputRegistry)
type RegistryFactory func() Registry

I'm not sure if we plan on extending this, but I think backwards-compatible changes would be easier with a struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 291 to 298
type Registry struct {
Action ActionRegistry
Auth AuthRegistry
Output OutputRegistry
}

// RegistryFactory is the factory function, provided to the VM initializer that provides the registries for the actions, auth and output.
type RegistryFactory func() Registry
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we change from an interface returning a struct of all of these types to an interface that supports ActionRegistry(), AuthRegistry(), and OutputRegistry() individually?

We can have a struct that implements that interface and takes the exact same fields, that way we can pass it around more easily and call a single function on the interface to get the value we care about.

This will also make it more ergonomic when we have a type that needs only the one of those values. The callee can then declare its own dependency and the caller can pass in the existing interface.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

Comment on lines +8 to +14
type Registry struct {
actionRegistry chain.ActionRegistry
authRegistry chain.AuthRegistry
outputRegistry chain.OutputRegistry
}

func NewRegistry(action chain.ActionRegistry, auth chain.AuthRegistry, output chain.OutputRegistry) *Registry {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we define the struct implementing next to the interface in the chain package?

Comment on lines +165 to +168
Registry: *NewRegistry(
registry.ActionRegistry(),
registry.AuthRegistry(),
registry.OutputRegistry()),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why create a registry from the existing registry? Can we just set the registry to the chain.Registry value that was passed in?

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