-
Notifications
You must be signed in to change notification settings - Fork 111
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
create TypeID for Actions/Auths + delete reflection in Registry #297
Conversation
examples/tokenvm/actions/common.go
Outdated
package actions | ||
|
||
const ( | ||
burnAssetID uint8 = iota |
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.
Please list these out explicitly. iota
will do the job but find it is much more delicate.
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.
If there is duplicated id created manually, the registry will return the error 👍
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.
May be worth adding that as a comment just for other contributors to keep in mind.
Reviewing now...this is exactly what I had in mind ❤️ . I didn't realize the function signatures would be so much cleaner, which is awesome. |
chain/transaction.go
Outdated
@@ -334,22 +329,14 @@ func (t *Transaction) Payer() string { | |||
|
|||
func (t *Transaction) Marshal( |
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: make this 1 line
chain/transaction.go
Outdated
t.Action.Marshal(p) | ||
p.PackByte(authByte) | ||
p.PackByte(authID) | ||
t.Auth.Marshal(p) | ||
return p.Err() | ||
} | ||
|
||
func MarshalTxs( |
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: make this 1 line
Ran the CI to give you a read on what's remaining to change 👍 |
// LookupType returns the index, decoder function and the success of lookup of | ||
// type [o] from Typeparser [p]. | ||
func (p *TypeParser[T, X, Y]) LookupType(o T) (uint8, func(*Packer, X) (T, error), Y, bool) { | ||
index, ok := p.typeToIndex[fmt.Sprintf("%T", o)] |
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.
❤️
package actions | ||
|
||
const ( | ||
// IDs explicitly listed. Registry will avoid usage of duplicated IDs by returning an error when occurs |
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 (for all):
// Note: Registry will error during initialization if a duplicate ID is assigned. We explicitly assign IDs to avoid accidental remapping.
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.
You can also put this just above const
@najeal VERY close! just 1-2 small nits. Kicking off full CI rn. |
Would be good future work to convert this to use hypersdk/examples/tokenvm/controller/controller.go Lines 177 to 211 in 51cee4e
|
Looks like full CI passed, as soon as nits are pushed should be good to merge. |
(no need to update branch to main...will merge as soon as the sync tests pass) |
You want the same switch but on the TypeID instead? |
Yeah, the idea is to remove all use of reflect, especially in the "hot path". Do you want to do that here or in a separate PR? |
@patrick-ogrady I will do it in another PR. I will also pick another issue in the list. |
Closes #228
This PR adds
GetTypeID
method to the Action & Auth interfaces.Now we register directly an ID instead of a Type in Registry.
Using a TypeID tied to the Action/Auth struct makes the reflection mechanism "legacy". Therefore it has been cleaned.
@patrick-ogrady is it what you expected?