-
Notifications
You must be signed in to change notification settings - Fork 134
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
State cleanup contract #171
Conversation
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn clean() { |
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.
There is no guarantee that this can finish within gas limit?
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 there is no guarantee here, it is necessary to first calculate the total size of the deleted data before sending the array of keys
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.
This might be a good candidate to be a no_std contract. I'll port it over as an alternative when I have free time
let input = env::input().unwrap(); | ||
let args: Args = serde_json::from_slice(&input).unwrap(); | ||
for key in args.keys.iter() { | ||
env::storage_remove(&base64::decode(key).unwrap()); |
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.
Optional, but can use the Base64VecU8
type instead of String
to just handle decoding this during deserialization
#[allow(dead_code)] | ||
#[near_bindgen] | ||
struct Contract {} |
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.
Should just be able to delete this? Or am I forgetting about some dependency from v3 or otherwise?
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.
agree i ran this code on version 3.1.0
and 4.0.0-pre.2
use near_sdk::serde::Deserialize;
use near_sdk::serde_json;
use near_sdk::env;
use near_sdk::json_types::Base64VecU8;
#[derive(Deserialize)]
#[serde(crate = "near_sdk::serde")]
struct Args {
pub keys: Vec<Base64VecU8>,
}
#[no_mangle]
pub extern "C" fn clean() {
env::setup_panic_hook();
let input = env::input().unwrap();
let args: Args = serde_json::from_slice(&input).unwrap();
for key in args.keys.iter() {
env::storage_remove(&key.0);
}
}
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.
FYI, I have no idea why that might be necessary
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.
it helped me to solve the error:
The collection is an inconsistent state. Did previous smart contract execution terminate unexpectedly?
to be more precise it helps to better understand how storage works.
I left a note for myself, it may be useful not only for me https://gist.github.com/ilyar/19bdc04d1aa09ae0fc84eb4297df1a1d#file-clear_state_of_contract_on_near_protocol-md
Howdy folks, |
Howdy! Just checking in -- is there any reason why this contract can't be used at this point? Can we get this PR merged? |
Hello all, we have another report of a user being affected by uncleared state after deleting the multisig contract. Can this be used in the wallet as per @MaximusHaximus's suggestion? |
@austinabell @ilyar @bowenwang1996 @frol any updates on whether the the status of this PR? @frol has already approved but seeing feedback from @austinabell wondering if these are nits that can be addressed in a separate PR or if these are blockers. Thanks! |
No blockers! Those are nits |
If we're feeling good about this, @austinabell, could you execute the merge? |
Opened #203 for how to optimize this in the future |
How to get all the keys for contract with large state, it gives an error |
For other people landing here: you can prevent the error State of contract _____.near is too large to be viewed when calling view-state via the JSON RPC API if you select an alternative RPC provider from this list (also works for testnet if you replace testnet with mainnet in some of the URLs): docs.near.org/api/rpc/providers I was successful with OOMNIA: endpoints.omniatech.io/v1/near/testnet/public |
Allows to cleanup state of an account without deleting it.
Deploy this contract instead of the current one, clean up state and can redeploy new contract or use account in other ways.