Skip to content
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

commit file sinks after rewards db purged #486

Merged
merged 1 commit into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions iot_verifier/src/rewarder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(())
}
}
Expand Down
24 changes: 11 additions & 13 deletions mobile_verifier/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(())
}
}
Expand Down