Refactor to a lazy rewarding system (#1127)
* Remove eager operator and delegator rewarding * Add mixnodes snapshoting * Add Intervals map, getter and setter * Refactor reward params * Refactor MixnodeToReward * Persist node reward params and results on chain * Update cw-storage-plus to 0.12.1 * Refactor delegation storage * Compound delegator reward command * Compound delegator reward command * Add defered delegate and undelegate * Compound on behalf command * Scale calculations to epoch * Rename interval -> epoch where practical * Store epochs on chain * Cleanup first pass * Adapt reporting to lazy rewarding * make clippy --all
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use mixnet_contract_common::Interval;
|
||||
|
||||
use crate::network_monitor::monitor::summary_producer::NodeResult;
|
||||
use crate::node_status_api::models::{HistoricalUptime, Uptime};
|
||||
use crate::node_status_api::utils::ActiveNodeStatuses;
|
||||
@@ -673,18 +675,21 @@ impl StorageManager {
|
||||
///
|
||||
/// * `interval_start_timestamp`: Unix timestamp of start of this rewarding interval.
|
||||
/// * `interval_end_timestamp`: Unix timestamp of end of this rewarding interval.
|
||||
pub(super) async fn insert_new_interval_rewarding(
|
||||
pub(super) async fn insert_new_epoch_rewarding(
|
||||
&self,
|
||||
interval_start_timestamp: i64,
|
||||
interval_end_timestamp: i64,
|
||||
epoch: Interval,
|
||||
) -> Result<i64, sqlx::Error> {
|
||||
let id = epoch.id();
|
||||
let start = epoch.start_unix_timestamp();
|
||||
let end = epoch.end_unix_timestamp();
|
||||
let res = sqlx::query!(
|
||||
r#"
|
||||
INSERT INTO interval_rewarding (interval_start_timestamp, interval_end_timestamp, finished)
|
||||
VALUES (?, ?, 0)
|
||||
INSERT INTO interval_rewarding (id, interval_start_timestamp, interval_end_timestamp, finished)
|
||||
VALUES (?, ?, ?, 0)
|
||||
"#,
|
||||
interval_start_timestamp,
|
||||
interval_end_timestamp,
|
||||
id,
|
||||
start,
|
||||
end,
|
||||
)
|
||||
.execute(&self.connection_pool)
|
||||
.await?;
|
||||
@@ -697,10 +702,7 @@ impl StorageManager {
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `id`: id of the entry we want to update.
|
||||
pub(super) async fn update_finished_interval_rewarding(
|
||||
&self,
|
||||
id: i64,
|
||||
) -> Result<(), sqlx::Error> {
|
||||
pub async fn update_finished_interval_rewarding(&self, id: i64) -> Result<(), sqlx::Error> {
|
||||
sqlx::query!(
|
||||
r#"
|
||||
UPDATE interval_rewarding
|
||||
|
||||
@@ -13,6 +13,7 @@ use crate::storage::models::{
|
||||
FailedMixnodeRewardChunk, IntervalRewarding, NodeStatus, PossiblyUnrewardedMixnode,
|
||||
RewardingReport, TestingRoute,
|
||||
};
|
||||
use mixnet_contract_common::Interval;
|
||||
use rocket::fairing::{self, AdHoc};
|
||||
use rocket::{Build, Rocket};
|
||||
use sqlx::ConnectOptions;
|
||||
@@ -25,7 +26,7 @@ pub(crate) mod models;
|
||||
// note that clone here is fine as upon cloning the same underlying pool will be used
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct ValidatorApiStorage {
|
||||
manager: StorageManager,
|
||||
pub manager: StorageManager,
|
||||
}
|
||||
|
||||
impl ValidatorApiStorage {
|
||||
@@ -688,13 +689,12 @@ impl ValidatorApiStorage {
|
||||
///
|
||||
/// * `interval_start_timestamp`: Unix timestamp of start of this rewarding interval.
|
||||
/// * `interval_end_timestamp`: Unix timestamp of end of this rewarding interval.
|
||||
pub(crate) async fn insert_started_interval_rewarding(
|
||||
pub(crate) async fn insert_started_epoch_rewarding(
|
||||
&self,
|
||||
interval_start_timestamp: i64,
|
||||
interval_end_timestamp: i64,
|
||||
epoch: Interval,
|
||||
) -> Result<i64, ValidatorApiStorageError> {
|
||||
self.manager
|
||||
.insert_new_interval_rewarding(interval_start_timestamp, interval_end_timestamp)
|
||||
.insert_new_epoch_rewarding(epoch)
|
||||
.await
|
||||
.map_err(|_| ValidatorApiStorageError::InternalDatabaseError)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user