-
Notifications
You must be signed in to change notification settings - Fork 124
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] serialize/deserialize using serde #388
Conversation
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.
comments on bug
The perf cost of this in non trivial
|
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.
Minor comments, feel free to open an issue to fix later if you want to get this PR landed
Co-authored-by: Richard Pringle <[email protected]> Signed-off-by: Sam Liokumovich <[email protected]>
Co-authored-by: Richard Pringle <[email protected]> Signed-off-by: Sam Liokumovich <[email protected]>
Co-authored-by: Richard Pringle <[email protected]> Signed-off-by: Sam Liokumovich <[email protected]>
Co-authored-by: Richard Pringle <[email protected]> Signed-off-by: Sam Liokumovich <[email protected]>
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.
LGTM
@@ -10,65 +9,52 @@ static TOKEN_PROGRAM_NAME: &str = "token_contract"; | |||
/// Initializes the program. | |||
#[expose] | |||
fn init_program() -> i64 { |
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.
Can we change this to init
?
Serialization using Serde
Why?
In order to support more complex data structures moving across the WASM boundary we would need to define our own ways to convert them to/from bytes. This is what
ProgramValues
were used for.ProgramValue's
implemented theStore
trait with methodsas_bytes
,from_bytes
&as_tag
. Crates likeSerde
&serde_bare
manage & implement these methods for us, and for more complex structs. This PR uses thefrom_slice
andto_vec
functions from theserde_bare
crate to serialize/deserialize objects.Advantages
Serde's
serialization types which are much more expansive thanProgramValues
TokenProgram
went from ~228kb to ~222kb.Disadvantages
Argument
trait. So far these areProgramContext
,i64
,Bytes32
, andAddress
. The reason for this is b/c when we invoke an external program, we need to serialize all params into one byte array. Then in go we need to deserialize in order to pass on the parameters to the desired external function.Performance costs see @hexfusion's commentsee performance sectionChanges
ProgramValue
,Store
and related stufffrom_slice
andto_vec
functions from theserde_bare
crate to serialize/deserialize objects.Get
andStore
functions take in a param that implementsSerialize
orDeserializedOwned
Argument
trait, used duringprogram_invoke
Pokemon
example to show usingserde
for custom structsProgramContext
->Context
Pokemon
andLottery
examples.Performance
Compiling Rust using
./scripts/build.sh
Running test with
go test -v -timeout 30s -run ^TestTokenProgram$ github.com/ava-labs/hypersdk/x/programs/examples --count 1
Before
After