-
Notifications
You must be signed in to change notification settings - Fork 2
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
Replace timestamp with block number #866
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.
🥇
use std::time::{Duration, UNIX_EPOCH}; | ||
UNIX_EPOCH + Duration::from_secs(js_sys::Date::now() as u64) | ||
} | ||
#[cfg(not(feature = "full-client-wasm"))] |
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.
Ah good that we no longer need to worry about the system clock on different platforms here
@@ -48,7 +48,7 @@ use crate::{ | |||
#[derive(Debug, Deserialize, Serialize, Clone)] | |||
pub struct Keys { | |||
pub keys: Vec<String>, | |||
pub timestamp: SystemTime, | |||
pub block_number: BlockNumber, |
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.
Ah so we also change this in the sync_kvdb
payload
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.
ya cuz it shares the check_stale function but I wouldn't worry to much, gonna need a whole re write when we go to threshold
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.
👍
let block_difference = if chain_block_number > user_block_number { | ||
chain_block_number.checked_sub(user_block_number).ok_or(ValidationErr::StaleMessage)? | ||
} else { | ||
user_block_number.checked_sub(chain_block_number).ok_or(ValidationErr::StaleMessage)? | ||
}; |
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.
We can use u32::abs_diff
here to simplify this logic
@@ -206,7 +208,7 @@ async fn test_sync_kvdb() { | |||
assert_eq!(result_4.status(), 500); | |||
assert_eq!(result_4.text().await.unwrap(), "Forbidden Key"); | |||
|
|||
keys.timestamp = keys.timestamp.checked_sub(TIME_BUFFER).unwrap(); | |||
keys.block_number = keys.block_number + BLOCK_BUFFER + 10; |
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 do we add an extra 10
here if we already have the BLOCK_BUFFER
?
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 need a plus 1 to put it over the buffer, and idk I just made it 10
@@ -235,6 +242,7 @@ pub async fn get_and_store_values( | |||
recip_server_info: ServerInfo<subxt::utils::AccountId32>, | |||
signer: &PairSigner<EntropyConfig, sr25519::Pair>, | |||
x25519_secret: &StaticSecret, | |||
rpc: &LegacyRpcMethods<EntropyConfig>, |
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.
Would be nice to not need to pass this in, but 🤷♂️
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.
ya but wouldn't worry about it, all this is gonna need a re write when we go to threshold
Closes #857