-
Notifications
You must be signed in to change notification settings - Fork 17
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
clear_payloads func #551
clear_payloads func #551
Conversation
Terraform Feature Environment (dev-551)Terraform Initialization ⚙️
|
How were you using locks? Locks in contract code should not be required at all. Also, you can't serialize a lock unless it's a filelock but that shouldn't be used here in contract code either |
@ChaoticTempest yep, just looking for a reason why the counter can be off. Looks like resetting should help. |
} | ||
|
||
#[private] | ||
pub fn clean_payloads(&mut self, payloads: Vec<[u8; 32]>, counter: u32) { |
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.
why specify the payloads instead of clearing all the requests in the pending_requests? is it because of LookupMap?
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've used
#[private]
pub fn clean_payloads(&mut self) {
log!("clean_payloads");
self.pending_requests = LookupMap::new(b"m");
self.request_counter = 0;
}
to clean the payloads on dev for now.
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.
Ok, that is fine. But the old payloads are still there.
LookupMap can not clean its key-value pairs. It is optimized for storage and access speed.
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.
wait, why would the old payloads still be there? I thought self.pending_requests = LookupMap::new(b"m"); self.request_counter = 0;
will reset it?
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 is how insert and remove works in LookupMap
/// Inserts a serialized key-value pair into the map.
/// If the map did not have this key present, `None` is returned. Otherwise returns
/// a serialized value. Note, the keys that have the same hash value are undistinguished by
/// the implementation.
pub fn insert_raw(&mut self, key_raw: &[u8], value_raw: &[u8]) -> Option<Vec<u8>> {
let storage_key = self.raw_key_to_storage_key(key_raw);
if env::storage_write(&storage_key, value_raw) {
Some(env::storage_get_evicted().unwrap())
} else {
None
}
}
/// Removes a serialized key from the map, returning the serialized value at the key if the key
/// was previously in the map.
pub fn remove_raw(&mut self, key_raw: &[u8]) -> Option<Vec<u8>> {
let storage_key = self.raw_key_to_storage_key(key_raw);
if env::storage_remove(&storage_key) {
Some(env::storage_get_evicted().unwrap())
} else {
None
}
}
LookupMap is not aware of its key-value pairs. They are stored directly on the contract memory which is also a map. The key for storing values is "LopkupMap prefix + provided key". It is not possible to clear the Lookup map without passing the keys.
@ChaoticTempest @ppca ready for review |
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
use primitives::ParticipantInfo; | ||
use primitives::{CandidateInfo, Candidates, Participants, PkVotes, Votes}; | ||
use std::collections::{BTreeMap, HashSet}; | ||
|
||
const GAS_FOR_SIGN_CALL: Gas = Gas::from_gas(3 * 100_000_000_000_000); |
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.
could also just do Gas::from_tgas(300)
One of our envs is stuck because it has >8 payloads. PPPro because it had 8 payloads in the past. I've added a clean function that should be called when this new version of the contract is deployed. @ppca please, do that for all our envs. And for
v5.multichain-mpc-dev.testnet
specifically.@ChaoticTempest I've tried to add a read/write lock to requests, but borsh was not happy about that. Not sure if that is necessary at all.