Hi, I am using ExperimentalStableMemory to create an “on demand” memory increasing actor class that I will refer to as storage canister.
The logic involving this canister is as follows
-canister X calls storage canister and asks to store a blob with store() func
-storage canister checks if there is sufficient memory left to store
-if not then it .grows() by the bit-width of the blob / 65536 (to get the amount of required pages)
-storage calls .storeBlob function where the offset is equal to zero initially and then is incremented by bit-width for the next call
The result of this flow is that .storeBlob traps with “StableMemory range out of bounds” .
What do you think it could cause this? Thank you
Also I have this flag set in my dfx.json
"packtool": "vessel sources"
Can you share a bit more of the code, including the call to storeBlob?
Or, even better, produce a small repro in the Motoko playground?
Sure Claudio, here it is:
You first need to call the changeoffset function with the actual size of what you are going to store, then call the put function with 0 as offset and blob as data. Thank you!
I don’t think
--max-stable-pages should be more than 2*65536-1, should it?
Maybe remove the flag and see if it works and then try a more reasonable value strictly below 2*65536 (8GB).
Indeed, it should not. I tried removing the flag entirely and run the code, then try it again with a value of 40 to be precise. And the same error occurred both of the times.
Edit: I saw that I was missing to increment offset in addmorememorypages function but that Is not having any impact on this issue (in case your were looking for the offset)
Hmm, I have to step out for a few hours to take my dad to a medical appointment. Keep me posted and if you don’t resolve the issue, I’ll investigate when I return.
This is version I was playing with. I added a putN function to avoid passing a large blob and removed the assert (owner == caller)
I cannot reproduce the failure you are seeing for some reason.
I called changeOffset(65536) and then putN(0,65536) followed by get(0,65536) and I think it worked.
Update: just double-checked that it does.
Indeed your usecase works in the playground. I copied it on my local machine and it throws the error. exactly the same code. Am I missing some configs here? I just use the local dfx network and I install the storage actor by doing
let _storage = await Storage.Storage();
CYCLE_SHARE = 300_000_000_000
which version of dfx? I wonder if it maybe the replica shipped with dfx is old.
Anyway, really got to go now…
0.10.0 . If the version would’ve been wrong and stable memory is not supported then it should’ve say something at compile time, right?
Btw thank you for trying to help, really appreciate it.
All right, I reinstalled dfx and I no longer face this issue. basically it works I don’t know why, it doesn’t work I don’t know why type of situation .
Odd. Sorry for the confusion.