Skip to content

Commit

Permalink
commit file sinks after rewards db purged
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Apr 24, 2023
1 parent 9913e1f commit 6a9a26d
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions iot_verifier/src/rewarder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,27 +89,9 @@ impl Rewarder {
// 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 +104,24 @@ impl Rewarder {
&mut transaction,
)
.await?;

transaction.commit().await?;

// now that the db has been purged, safe to commit the rewards related sinks
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?;

Ok(())
}
}
Expand Down

0 comments on commit 6a9a26d

Please sign in to comment.