mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 00:51:06 +00:00
Handle local storage race conditions better (#3177)
* Make local_storage_compare_and_set take Option for old_value * Adapt srml/im-online to API changes * Bump version * Bump version again * Replace match
This commit is contained in:
committed by
Gavin Wood
parent
af914e9f40
commit
23fba990ba
@@ -1055,14 +1055,27 @@ impl OffchainApi for () {
|
||||
}
|
||||
}
|
||||
|
||||
fn local_storage_compare_and_set(kind: offchain::StorageKind, key: &[u8], old_value: &[u8], new_value: &[u8]) -> bool {
|
||||
fn local_storage_compare_and_set(
|
||||
kind: offchain::StorageKind,
|
||||
key: &[u8],
|
||||
old_value: Option<&[u8]>,
|
||||
new_value: &[u8],
|
||||
) -> bool {
|
||||
let (ptr, len) = match old_value {
|
||||
Some(old_value) => (
|
||||
old_value.as_ptr(),
|
||||
old_value.len() as u32,
|
||||
),
|
||||
None => (0 as *const u8, u32::max_value()),
|
||||
};
|
||||
|
||||
unsafe {
|
||||
ext_local_storage_compare_and_set.get()(
|
||||
kind.into(),
|
||||
key.as_ptr(),
|
||||
key.len() as u32,
|
||||
old_value.as_ptr(),
|
||||
old_value.len() as u32,
|
||||
ptr,
|
||||
len,
|
||||
new_value.as_ptr(),
|
||||
new_value.len() as u32,
|
||||
) == 0
|
||||
|
||||
Reference in New Issue
Block a user