Add more data in ephemera blocks

This commit is contained in:
Bogdan-Ștefan Neacșu
2023-07-20 15:33:12 +03:00
parent 98e3dd9ae0
commit c67b09d107
6 changed files with 46 additions and 10 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ COCONUT_BANDWIDTH_CONTRACT_ADDRESS=n1x22q8lfhz7qcvtzs0dakhgx2th64l79kepjujhhxk5x
GROUP_CONTRACT_ADDRESS=n1g4xlpqy29m50j5y69reguae328tc9y83l4299pf2wmjn0xczq5js3704ql
MULTISIG_CONTRACT_ADDRESS=n1p54qvfde6mpnqvz3dnpa78x2qyyr5k4sgw9qr97mxjgklc5gze9sv6t964
COCONUT_DKG_CONTRACT_ADDRESS=n1xqkp8x4gqwjnhemtemc5dqhwll6w6rrgpywvhka7sh8vz8swul9sp3lv3w
EPHEMERA_CONTRACT_ADDRESS=n1fc7nakzuyfn2qzkclafcsc54asamnclg064962lwne40w2lq558qftzjza
EPHEMERA_CONTRACT_ADDRESS=n1tdxl4uv6fg3ke52n0umhv96648ttmwtg0u6uujmv5cuvjktg6qvq4mlzeg
REWARDING_VALIDATOR_ADDRESS=n1547eraje66h9mf99fm50mea04n9mrzsc8c23r5
NAME=n1uz24lsnwxvhep8m3gjec7ev86twlhlqrf5rphlgn3rda3zu048ssjqr5w9
SERVICE_PROVICER=n1nhdr07kmjns2x8dnp53tdk4qxreze8zdxj6xucyvkdj9tta73rjqa96wps
+1 -1
View File
@@ -67,7 +67,7 @@ zeroize = { workspace = true }
## ephemera-specific
actix-web = "4"
array-bytes = "6.0.0"
chrono = { version = "0.4.24", default-features = false, features = ["clock"] }
chrono = { version = "0.4.24", default-features = false, features = ["clock", "serde"] }
futures-util = "0.3.25"
serde_derive = "1.0.149"
tempfile = "3.3.0"
+2 -3
View File
@@ -12,9 +12,8 @@ use crate::ephemera::epoch::Epoch;
use crate::ephemera::peers::members::MembersProvider;
use crate::ephemera::peers::{NymApiEphemeraPeerInfo, NymPeer};
use crate::ephemera::reward::aggregator::RewardsAggregator;
use crate::ephemera::reward::{EphemeraAccess, RewardManager};
use crate::ephemera::reward::{EphemeraAccess, EphemeraData, RewardManager};
use crate::ephemera::Args;
use crate::epoch_operations::MixnodeWithPerformance;
use crate::support::nyxd;
use ephemera::crypto::{EphemeraKeypair, EphemeraPublicKey, Keypair};
use ephemera::ephemera_api::CommandExecutor;
@@ -164,7 +163,7 @@ impl Application for RewardsEphemeraApplication {
/// - Check that the transaction has a valid signature, we don't want to accept garbage messages
/// or messages from unknown peers
fn check_tx(&self, tx: ApiEphemeraMessage) -> ApplicationResult<bool> {
if serde_json::from_slice::<Vec<MixnodeWithPerformance>>(&tx.data).is_err() {
if serde_json::from_slice::<EphemeraData>(&tx.data).is_err() {
error!("Message is not a valid Reward message");
return Ok(false);
}
+21 -5
View File
@@ -1,8 +1,10 @@
use async_trait::async_trait;
use log::{debug, info, trace};
use serde_derive::{Deserialize, Serialize};
use std::time::Duration;
use crate::epoch_operations::MixnodeWithPerformance;
use crate::wireguard::WireguardKey;
use ephemera::{
crypto::Keypair,
ephemera_api::{self, ApiBlock, ApiEphemeraMessage, ApiError, CommandExecutor},
@@ -109,6 +111,12 @@ pub(crate) trait EpochOperations {
) -> anyhow::Result<Vec<MixnodeWithPerformance>>;
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub(crate) struct EphemeraData {
pub rewards: Vec<MixnodeWithPerformance>,
pub wireguard_key: WireguardKey,
}
pub(crate) struct RewardManager {
pub epoch: Epoch,
pub args: Args,
@@ -200,7 +208,8 @@ where
&self,
rewards: Vec<MixnodeWithPerformance>,
) -> anyhow::Result<()> {
let ephemera_msg = self.create_ephemera_message(rewards)?;
let wg_key = crate::wireguard::WireguardKey::new();
let ephemera_msg = self.create_ephemera_message(rewards, wg_key)?;
debug!("Sending rewards to ephemera: {:?}", ephemera_msg);
let access = self
@@ -215,6 +224,7 @@ where
fn create_ephemera_message(
&self,
rewards: Vec<MixnodeWithPerformance>,
wireguard_key: crate::wireguard::WireguardKey,
) -> anyhow::Result<ApiEphemeraMessage> {
let keypair = &self
.ephemera_access
@@ -223,7 +233,10 @@ where
.key_pair;
let label = self.epoch.current_epoch_numer().to_string();
let data = serde_json::to_vec(&rewards)?;
let data = serde_json::to_vec(&EphemeraData {
rewards,
wireguard_key,
})?;
let raw_message = ephemera_api::RawApiEphemeraMessage::new(label, data);
let certificate = ephemera_api::ApiCertificate::prepare(keypair, &raw_message)?;
@@ -246,9 +259,12 @@ where
for message in block.messages {
trace!("Message: {}", message);
let mix_node_reward: Vec<MixnodeWithPerformance> =
serde_json::from_slice(&message.data)?;
mix_node_rewards.push(mix_node_reward);
let EphemeraData {
rewards,
wireguard_key,
} = serde_json::from_slice(&message.data)?;
debug!("Got wireguard key {:?}", wireguard_key);
mix_node_rewards.push(rewards);
}
let aggregated_rewards = self.aggregator().aggregate(mix_node_rewards)?;
+1
View File
@@ -35,6 +35,7 @@ mod network_monitor;
pub(crate) mod node_status_api;
pub(crate) mod nym_contract_cache;
pub(crate) mod support;
pub(crate) mod wireguard;
struct ShutdownHandles {
task_manager_handle: TaskManager,
+20
View File
@@ -0,0 +1,20 @@
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct WireguardKey {
pub_key: [u8; 32],
valid_until: DateTime<Utc>,
}
impl WireguardKey {
pub fn new() -> Self {
WireguardKey {
pub_key: [0u8; 32],
valid_until: DateTime::default(),
}
}
}