-
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] Refactor SDK storage #499
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.
LGTM just some thoughts
In terms of actual design feedback, I'm not caught up enough to provide a clear opinion. But the proposed design seems reasonable, and importantly, simple to understand. So that's good. |
In Stellar they use |
I think we started there and have changed a few times. I think |
a306079
to
ba39f34
Compare
Signed-off-by: Sam Batschelet <[email protected]>
Signed-off-by: Sam Batschelet <[email protected]>
Signed-off-by: Sam Batschelet <[email protected]>
Signed-off-by: Sam Batschelet <[email protected]>
Signed-off-by: Sam Batschelet <[email protected]>
Signed-off-by: Sam Batschelet <[email protected]>
Signed-off-by: Sam Batschelet <[email protected]>
Signed-off-by: Sam Batschelet <[email protected]>
Signed-off-by: Sam Batschelet <[email protected]>
Signed-off-by: Sam Batschelet <[email protected]>
Signed-off-by: Sam Batschelet <[email protected]>
Signed-off-by: Sam Batschelet <[email protected]>
Signed-off-by: Sam Batschelet <[email protected]>
Signed-off-by: Sam Batschelet <[email protected]>
ff7d4b3
to
7f69fd6
Compare
Signed-off-by: Sam Batschelet <[email protected]>
Signed-off-by: Sam Batschelet <[email protected]>
Signed-off-by: Sam Batschelet <[email protected]>
|
Yeah I realized after the fact that I was making some assumptions in the memory module so added some tests. |
Signed-off-by: Sam Batschelet <[email protected]>
Signed-off-by: Sam Batschelet <[email protected]>
Signed-off-by: Sam Batschelet <[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.
Looking good! Majority of my comments are more thoughts for the future.
Signed-off-by: Sam Batschelet <[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.
🚀
offset, _ := memory.Alloc(bytesLen) | ||
|
||
// copy bytes into memory allocation | ||
_ = memory.Write(offset, bytes) |
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.
Do we need to ensure that the amount written is equal to bytesLen
?
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.
the runtime implementation handles all this maybe the example is more confusing than helpful.
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.
I think we should just be clearer about expectations to safely use. I think the example is nice.
bytesLen := uint64(len(bytes)) | ||
|
||
// create a memory allocation | ||
offset, _ := memory.Alloc(bytesLen) |
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.
Is there some error we should be checking here? (maybe out of scope for readme)
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.
yeah just example usage error removed for brevity.
``` | ||
|
||
Each `Memory` is tightly bound to the lifecycle of the module. For this reason, | ||
`Memory` is non durable and can not be relied upon outside the scope of a `#[public]` function. |
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: non-durable
type ProposalId = [u8; 8]; | ||
|
||
#[state_keys] | ||
enum StateKeys { |
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.
❤️
# codegen-units = 1 | ||
# overflow-checks = true | ||
# # https://doc.rust-lang.org/book/ch09-01-unrecoverable-errors-with-panic.html#unwinding-the-stack-or-aborting-in-response-to-a-panic | ||
# panic = 'abort' |
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.
is this considered an optimization or required?
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.
panic=abort is the default for the wasm32-unknown-unknown
target which is now our default target. So this is just visibility to the default in case we wanted to changed it. I do have a question of how well the memory is cleaned up in this case by the OS.
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.
The rust book describes this as well as says "dont panic" :)
Ultimately, panics translate into aborts in wasm32-unknown-unknown anyways, so this gives you the same behavior but without the code bloat.
ref. https://rustwasm.github.io/docs/book/reference/code-size.html?highlight=panic#avoid-panicking
The current host module
map
was a POC example of storing data on the host. In order to integrate programs into aVM
we need to refactorProgram
storage. This PR proposes a new host module calledstate_keys
and changes to the SDK to provide clear separation between interactions with moduleMemory
and the hostsState
.State
toProgram
Program
state schema which emulates HyperSDK.Memory
andState
state_keys
which implementsStateKeys
for the user and helps to standardize the format.cargo expand for new
state_key
macro shows its implementation