Stop using rewarding reports as a source of truth for whether mixnodes got rewards (#3227)
use contract information instead
This commit is contained in:
committed by
GitHub
parent
1a4e7433b2
commit
134ab2f0d6
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::node_status_api::models::NymApiStorageError;
|
||||
use nym_mixnet_contract_common::EpochState;
|
||||
use nym_mixnet_contract_common::{EpochState, MixId};
|
||||
use thiserror::Error;
|
||||
use validator_client::nyxd::error::NyxdError;
|
||||
use validator_client::nyxd::AccountId;
|
||||
@@ -22,6 +22,9 @@ pub enum RewardingError {
|
||||
operation: String,
|
||||
},
|
||||
|
||||
#[error("it seems the current epoch is in mid-rewarding state (last rewarded is {last_rewarded}). With our current nym-api this shouldn't have been possible. Manual intervention is required.")]
|
||||
MidMixRewarding { last_rewarded: MixId },
|
||||
|
||||
// #[error("There were no mixnodes to reward (network is dead)")]
|
||||
// NoMixnodesToReward,
|
||||
#[error("Failed to execute the smart contract - {0}")]
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::epoch_operations::error::RewardingError;
|
||||
use crate::support::storage::models::RewardingReport;
|
||||
use crate::RewardedSetUpdater;
|
||||
use nym_mixnet_contract_common::reward_params::Performance;
|
||||
use nym_mixnet_contract_common::{EpochState, ExecuteMsg, Interval, MixId};
|
||||
@@ -42,8 +41,15 @@ impl RewardedSetUpdater {
|
||||
warn!("we seem to have crashed mid epoch operations... no need to reward mixnodes as we've already done that! (or this could be a false positive if there were no nodes to reward - to fix this warning later)");
|
||||
Ok(())
|
||||
}
|
||||
EpochState::Rewarding { .. } => {
|
||||
EpochState::Rewarding { last_rewarded, .. } => {
|
||||
log::info!("Rewarding the current rewarded set...");
|
||||
|
||||
// with how the nym-api is currently coded, this should never happen as we're always
|
||||
// rewarding ALL mixnodes at once, but who knows what we might decide to do in the future...
|
||||
if last_rewarded != 0 {
|
||||
return Err(RewardingError::MidMixRewarding { last_rewarded });
|
||||
}
|
||||
|
||||
if let Err(err) = self._reward_current_rewarded_set(current_interval).await {
|
||||
log::error!("FAILED to reward rewarded set - {err}");
|
||||
Err(err)
|
||||
@@ -62,17 +68,8 @@ impl RewardedSetUpdater {
|
||||
let mut to_reward = self.nodes_to_reward(current_interval).await;
|
||||
to_reward.sort_by_key(|a| a.mix_id);
|
||||
|
||||
if let Some(existing_report) = self
|
||||
.storage
|
||||
.get_rewarding_report(current_interval.current_epoch_absolute_id())
|
||||
.await?
|
||||
{
|
||||
warn!("We have already rewarded mixnodes for this rewarding epoch ({}). {} nodes should have gotten rewards", existing_report.absolute_epoch_id, existing_report.eligible_mixnodes);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if to_reward.is_empty() {
|
||||
info!("There are no nodes to reward in this epoch");
|
||||
error!("There are no nodes to reward in this epoch - we shouldn't have been in the 'Rewarding' state!");
|
||||
} else if let Err(err) = self.nyxd_client.send_rewarding_messages(&to_reward).await {
|
||||
error!(
|
||||
"failed to perform mixnode rewarding for epoch {}! Error encountered: {err}",
|
||||
@@ -83,15 +80,6 @@ impl RewardedSetUpdater {
|
||||
|
||||
log::info!("rewarded {} mixnodes...", to_reward.len());
|
||||
|
||||
let rewarding_report = RewardingReport {
|
||||
absolute_epoch_id: current_interval.current_epoch_absolute_id(),
|
||||
eligible_mixnodes: to_reward.len() as u32,
|
||||
};
|
||||
|
||||
self.storage
|
||||
.insert_rewarding_report(rewarding_report)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -867,6 +867,7 @@ impl StorageManager {
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `report`: report to insert into the database
|
||||
#[allow(unused)]
|
||||
pub(crate) async fn insert_rewarding_report(
|
||||
&self,
|
||||
report: RewardingReport,
|
||||
@@ -885,6 +886,7 @@ impl StorageManager {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub(crate) async fn get_rewarding_report(
|
||||
&self,
|
||||
absolute_epoch_id: EpochId,
|
||||
|
||||
@@ -9,8 +9,8 @@ use crate::node_status_api::models::{
|
||||
};
|
||||
use crate::node_status_api::{ONE_DAY, ONE_HOUR};
|
||||
use crate::storage::manager::StorageManager;
|
||||
use crate::storage::models::{NodeStatus, RewardingReport, TestingRoute};
|
||||
use nym_mixnet_contract_common::{EpochId, MixId};
|
||||
use crate::storage::models::{NodeStatus, TestingRoute};
|
||||
use nym_mixnet_contract_common::MixId;
|
||||
use rocket::fairing::AdHoc;
|
||||
use sqlx::ConnectOptions;
|
||||
use std::path::PathBuf;
|
||||
@@ -717,26 +717,6 @@ impl NymApiStorage {
|
||||
.map_err(|err| err.into())
|
||||
}
|
||||
|
||||
pub(crate) async fn insert_rewarding_report(
|
||||
&self,
|
||||
report: RewardingReport,
|
||||
) -> Result<(), NymApiStorageError> {
|
||||
self.manager
|
||||
.insert_rewarding_report(report)
|
||||
.await
|
||||
.map_err(|err| err.into())
|
||||
}
|
||||
|
||||
pub(crate) async fn get_rewarding_report(
|
||||
&self,
|
||||
absolute_epoch_id: EpochId,
|
||||
) -> Result<Option<RewardingReport>, NymApiStorageError> {
|
||||
self.manager
|
||||
.get_rewarding_report(absolute_epoch_id)
|
||||
.await
|
||||
.map_err(|err| err.into())
|
||||
}
|
||||
|
||||
pub(crate) async fn get_blinded_signature_response(
|
||||
&self,
|
||||
tx_hash: &str,
|
||||
|
||||
@@ -41,6 +41,8 @@ pub(crate) struct TestingRoute {
|
||||
pub(crate) monitor_run_db_id: i64,
|
||||
}
|
||||
|
||||
// for now let's leave it here to have a data model to use with existing database tables
|
||||
#[allow(unused)]
|
||||
pub(crate) struct RewardingReport {
|
||||
// references particular interval_rewarding
|
||||
pub(crate) absolute_epoch_id: u32,
|
||||
|
||||
Reference in New Issue
Block a user