From e5eebeebf1aad9a1c5a518b28ebcb9776b7fdfb5 Mon Sep 17 00:00:00 2001 From: andymck Date: Tue, 25 Apr 2023 15:52:08 +0100 Subject: [PATCH] commit file sinks after rewards db purged (#486) --- iot_verifier/src/rewarder.rs | 32 ++++++++++++++------------------ mobile_verifier/src/verifier.rs | 24 +++++++++++------------- 2 files changed, 25 insertions(+), 31 deletions(-) diff --git a/iot_verifier/src/rewarder.rs b/iot_verifier/src/rewarder.rs index 4c78d7e3b..47581bf30 100644 --- a/iot_verifier/src/rewarder.rs +++ b/iot_verifier/src/rewarder.rs @@ -88,28 +88,11 @@ impl Rewarder { .await? // Await the returned oneshot to ensure we wrote the file .await??; - let written_files = self.rewards_sink.commit().await?.await??; - // Write the rewards manifest for the completed period - self.reward_manifests_sink - .write( - RewardManifest { - start_timestamp: scheduler.reward_period.start.encode_timestamp(), - end_timestamp: scheduler.reward_period.end.encode_timestamp(), - written_files, - }, - [], - ) - .await? - .await??; - - self.reward_manifests_sink.commit().await?; let mut transaction = self.pool.begin().await?; - // Clear gateway shares table period to end of reward period GatewayShares::clear_rewarded_shares(&mut transaction, scheduler.reward_period.end).await?; - save_rewarded_timestamp( "last_rewarded_end_time", &scheduler.reward_period.end, @@ -122,9 +105,22 @@ impl Rewarder { &mut transaction, ) .await?; - transaction.commit().await?; + // now that the db has been purged, safe to write out the manifest + self.reward_manifests_sink + .write( + RewardManifest { + start_timestamp: scheduler.reward_period.start.encode_timestamp(), + end_timestamp: scheduler.reward_period.end.encode_timestamp(), + written_files, + }, + [], + ) + .await? + .await??; + self.reward_manifests_sink.commit().await?; + Ok(()) } } diff --git a/mobile_verifier/src/verifier.rs b/mobile_verifier/src/verifier.rs index 86a8fd058..3ffd5888e 100644 --- a/mobile_verifier/src/verifier.rs +++ b/mobile_verifier/src/verifier.rs @@ -170,7 +170,17 @@ impl VerifierDaemon { let written_files = self.mobile_rewards.commit().await?.await??; - // Write out the manifest file + let mut transaction = self.pool.begin().await?; + // Clear the heartbeats table: + sqlx::query("TRUNCATE TABLE heartbeats;") + .execute(&mut transaction) + .await?; + + save_last_rewarded_end_time(&mut transaction, &scheduler.reward_period.end).await?; + save_next_rewarded_end_time(&mut transaction, &scheduler.next_reward_period().end).await?; + transaction.commit().await?; + + // now that the db has been purged, safe to write out the manifest self.reward_manifests .write( RewardManifest { @@ -185,18 +195,6 @@ impl VerifierDaemon { self.reward_manifests.commit().await?; - let mut transaction = self.pool.begin().await?; - - // Clear the heartbeats table: - sqlx::query("TRUNCATE TABLE heartbeats;") - .execute(&mut transaction) - .await?; - - save_last_rewarded_end_time(&mut transaction, &scheduler.reward_period.end).await?; - save_next_rewarded_end_time(&mut transaction, &scheduler.next_reward_period().end).await?; - - transaction.commit().await?; - Ok(()) } }