From de14687a0dc22a4d0e72989bbacd16383d12a5a4 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Sat, 25 Nov 2023 04:07:31 -0500 Subject: [PATCH] Fix the processor's Monero time monotonicity Monero doesn't assert the time increases with each block, solely that it doesn't decrease. Now, the block number is added to the time to ensure it increases. --- processor/src/networks/monero.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/processor/src/networks/monero.rs b/processor/src/networks/monero.rs index cbc6ac53..7bcf8097 100644 --- a/processor/src/networks/monero.rs +++ b/processor/src/networks/monero.rs @@ -207,10 +207,12 @@ impl BlockTrait for Block { let b = timestamps[n]; #[rustfmt::skip] // Enables Ctrl+F'ing for everything after the `= ` let res = (a/2) + (b/2) + ((a - 2*(a/2)) + (b - 2*(b/2)))/2; - // Techniaslly, res may be 1 if all prior blocks had a timestamp by 0, which would break + // Technically, res may be 1 if all prior blocks had a timestamp by 0, which would break // monotonicity with our above definition of height as time - // Ensure monotonicity by increasing this value by the window size - res + BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW + // Monero also solely requires the block's time not be less than the median, it doesn't ensure + // it advances the median forward + // Ensure monotonicity despite both these issues by adding the block number to the median time + res + u64::try_from(self.number()).unwrap() } } @@ -692,7 +694,7 @@ impl Network for Monero { // https://github.com/serai-dex/serai/issues/198 sleep(std::time::Duration::from_millis(100)).await; - #[derive(serde::Deserialize, Debug)] + #[derive(Debug, serde::Deserialize)] struct EmptyResponse {} let _: EmptyResponse = self .rpc