Skip to content

Commit 50632ff

Browse files
committed
add proposer rewards and python stuff
1 parent 20c9cef commit 50632ff

File tree

18 files changed

+3236691
-54
lines changed

18 files changed

+3236691
-54
lines changed

asyncio

Lines changed: 283849 additions & 0 deletions
Large diffs are not rendered by default.

catalyst-toolbox/scripts/python/proposers_rewards.py

100644100755
File mode changed.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use std::path::PathBuf;
2+
3+
use rust_decimal::Decimal;
4+
use serde::Deserialize;
5+
6+
use crate::cli::rewards::community_advisors::{FundSettingOpt, ProposalRewardsSlotsOpt};
7+
8+
#[derive(Debug, Deserialize)]
9+
pub(super) struct Config {
10+
pub(super) inputs: Inputs,
11+
pub(super) outputs: Outputs,
12+
pub(super) params: Params,
13+
}
14+
15+
#[derive(Debug, Deserialize)]
16+
pub(super) struct Inputs {
17+
pub(super) block_file: PathBuf,
18+
pub(super) snapshot_path: PathBuf,
19+
pub(super) vote_count_path: PathBuf,
20+
pub(super) reviews_csv: PathBuf,
21+
pub(super) assessments_path: PathBuf, // is assessments the same as reviews?
22+
pub(super) proposal_bonus_output: Option<PathBuf>,
23+
pub(super) approved_proposals_path: PathBuf,
24+
pub(super) proposer_script_path: PathBuf,
25+
pub(super) active_voteplans: PathBuf,
26+
pub(super) challenges: PathBuf,
27+
pub(super) proposals_path: PathBuf,
28+
}
29+
30+
#[derive(Debug, Deserialize)]
31+
pub(super) struct Outputs {
32+
pub(super) veterans_rewards_output: PathBuf,
33+
pub(super) ca_rewards_output: PathBuf,
34+
pub(super) proposer_rewards_output: PathBuf,
35+
}
36+
37+
#[derive(Debug, Deserialize)]
38+
pub(super) struct Params {
39+
pub(super) registration_threshold: u64,
40+
pub(super) vote_threshold: u64,
41+
pub(super) total_rewards: u64,
42+
pub(super) rewards_agreement_rate_cutoffs: Vec<Decimal>,
43+
pub(super) rewards_agreement_rate_modifiers: Vec<Decimal>,
44+
pub(super) reputation_agreement_rate_cutoffs: Vec<Decimal>,
45+
pub(super) reputation_agreement_rate_modifiers: Vec<Decimal>,
46+
pub(super) min_rankings: usize,
47+
pub(super) max_rankings_reputation: usize,
48+
pub(super) max_rankings_rewards: usize,
49+
pub(super) rewards_slots: ProposalRewardsSlotsOpt,
50+
pub(super) fund_settings: FundSettingOpt,
51+
pub(super) ca_seed: String,
52+
pub(super) proposer_stake_threshold: f64,
53+
pub(super) proposer_approval_threshold: f64,
54+
}
Lines changed: 25 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
use std::{
2-
fs::File,
3-
path::{Path, PathBuf},
4-
};
1+
use std::{fs::File, path::Path};
52

63
use color_eyre::Result;
4+
use config::*;
75
use log::info;
8-
use rust_decimal::Decimal;
9-
use serde::Deserialize;
106
use serde_json::from_reader;
117

12-
use super::community_advisors::{FundSettingOpt, ProposalRewardsSlotsOpt};
8+
mod config;
9+
mod proposers;
10+
mod python;
1311

1412
pub(super) fn full_rewards(path: &Path) -> Result<()> {
1513
let config = from_reader(File::open(path)?)?;
@@ -23,11 +21,16 @@ pub(super) fn full_rewards(path: &Path) -> Result<()> {
2321
assessments_path,
2422
proposal_bonus_output,
2523
approved_proposals_path,
24+
proposer_script_path,
25+
active_voteplans,
26+
challenges,
27+
proposals_path,
2628
},
2729
outputs:
2830
Outputs {
2931
veterans_rewards_output,
3032
ca_rewards_output,
33+
proposer_rewards_output,
3134
},
3235
params:
3336
Params {
@@ -44,12 +47,14 @@ pub(super) fn full_rewards(path: &Path) -> Result<()> {
4447
rewards_slots,
4548
fund_settings,
4649
ca_seed,
50+
proposer_stake_threshold,
51+
proposer_approval_threshold,
4752
},
4853
} = config;
4954

5055
info!("calculating voter rewards");
5156
super::voters::voter_rewards(
52-
Some(block_file),
57+
&block_file,
5358
vote_count_path,
5459
snapshot_path,
5560
registration_threshold,
@@ -82,46 +87,17 @@ pub(super) fn full_rewards(path: &Path) -> Result<()> {
8287
proposal_bonus_output,
8388
)?;
8489

85-
Ok(())
86-
}
87-
88-
#[derive(Debug, Deserialize)]
89-
struct Config {
90-
inputs: Inputs,
91-
outputs: Outputs,
92-
params: Params,
93-
}
94-
95-
#[derive(Debug, Deserialize)]
96-
struct Inputs {
97-
block_file: PathBuf,
98-
snapshot_path: PathBuf,
99-
vote_count_path: PathBuf,
100-
reviews_csv: PathBuf,
101-
assessments_path: PathBuf, // is assessments the same as reviews?
102-
proposal_bonus_output: Option<PathBuf>,
103-
approved_proposals_path: PathBuf,
104-
}
105-
106-
#[derive(Debug, Deserialize)]
107-
struct Outputs {
108-
veterans_rewards_output: PathBuf,
109-
ca_rewards_output: PathBuf,
110-
}
90+
info!("calculating proposer rewards");
91+
proposers::proposers_rewards(
92+
&proposer_script_path,
93+
&block_file,
94+
&proposer_rewards_output,
95+
proposer_stake_threshold,
96+
proposer_approval_threshold,
97+
&proposals_path,
98+
&active_voteplans,
99+
&challenges,
100+
)?;
111101

112-
#[derive(Debug, Deserialize)]
113-
struct Params {
114-
registration_threshold: u64,
115-
vote_threshold: u64,
116-
total_rewards: u64,
117-
rewards_agreement_rate_cutoffs: Vec<Decimal>,
118-
rewards_agreement_rate_modifiers: Vec<Decimal>,
119-
reputation_agreement_rate_cutoffs: Vec<Decimal>,
120-
reputation_agreement_rate_modifiers: Vec<Decimal>,
121-
min_rankings: usize,
122-
max_rankings_reputation: usize,
123-
max_rankings_rewards: usize,
124-
rewards_slots: ProposalRewardsSlotsOpt,
125-
fund_settings: FundSettingOpt,
126-
ca_seed: String,
102+
Ok(())
127103
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use std::{ffi::OsStr, path::Path};
2+
3+
use color_eyre::Result;
4+
5+
use super::python::exec_python_script;
6+
7+
pub(super) fn proposers_rewards(
8+
proposer_reward_script: &Path,
9+
block0: &Path,
10+
output: &Path,
11+
stake_threshold: f64,
12+
approval_threshold: f64,
13+
proposals: &Path,
14+
active_voteplans: &Path,
15+
challenges: &Path,
16+
) -> Result<()> {
17+
exec_python_script(
18+
proposer_reward_script,
19+
[
20+
OsStr::new("--block0-path"),
21+
block0.as_ref(),
22+
OsStr::new("--output-file"),
23+
output.as_ref(),
24+
OsStr::new("--total-stake-threshold"),
25+
OsStr::new(&format!("{stake_threshold}")),
26+
OsStr::new("--approval-threshold"),
27+
OsStr::new(&format!("{approval_threshold}")),
28+
OsStr::new("--proposals-path"),
29+
proposals.as_ref(),
30+
OsStr::new("--active-voteplans-path"),
31+
active_voteplans.as_ref(),
32+
OsStr::new("--challenges-path"),
33+
challenges.as_ref(),
34+
],
35+
)
36+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use std::{ffi::OsStr, process::Command};
2+
3+
use color_eyre::eyre::Result;
4+
5+
pub(crate) fn exec_python_script(
6+
path: impl AsRef<OsStr>,
7+
args: impl IntoIterator<Item = impl AsRef<OsStr>>,
8+
) -> Result<()> {
9+
Command::new("python").arg(path).args(args).output()?;
10+
Ok(())
11+
}

catalyst-toolbox/src/bin/cli/rewards/voters.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use catalyst_toolbox::rewards::voters::{calc_voter_rewards, Rewards, VoteCount};
22
use catalyst_toolbox::snapshot::{registration::MainnetRewardAddress, Snapshot};
33
use catalyst_toolbox::utils::assert_are_close;
44

5+
use color_eyre::eyre::eyre;
56
use color_eyre::{Report, Result};
67
use jcli_lib::block::{load_block, open_block_file};
78
use jcli_lib::jcli_lib::block::{open_output, Common};
@@ -11,7 +12,7 @@ use jormungandr_lib::interfaces::Block0Configuration;
1112
use structopt::StructOpt;
1213

1314
use std::collections::BTreeMap;
14-
use std::path::PathBuf;
15+
use std::path::{Path, PathBuf};
1516

1617
#[derive(StructOpt)]
1718
#[structopt(rename_all = "kebab-case")]
@@ -69,7 +70,10 @@ impl VotersRewards {
6970
} = self;
7071

7172
voter_rewards(
72-
common.output_file,
73+
common
74+
.output_file
75+
.as_deref()
76+
.ok_or(eyre!("missing block file"))?,
7377
votes_count_path,
7478
snapshot_path,
7579
registration_threshold,
@@ -80,14 +84,14 @@ impl VotersRewards {
8084
}
8185

8286
pub fn voter_rewards(
83-
block_file: Option<PathBuf>,
87+
block_file: &Path,
8488
votes_count_path: PathBuf,
8589
snapshot_path: PathBuf,
8690
registration_threshold: u64,
8791
vote_threshold: u64,
8892
total_rewards: u64,
8993
) -> Result<()> {
90-
let block = open_block_file(&block_file)?;
94+
let block = open_block_file(&Some(block_file.to_path_buf()))?;
9195
let block = load_block(block)?;
9296

9397
let block0 = Block0Configuration::from_block(&block)?;
@@ -109,6 +113,6 @@ pub fn voter_rewards(
109113
let actual_rewards = results.values().sum::<Rewards>();
110114
assert_are_close(actual_rewards, Rewards::from(total_rewards));
111115

112-
write_rewards_results(&block_file, &results)?;
116+
write_rewards_results(&Some(block_file.to_path_buf()), &results)?;
113117
Ok(())
114118
}

0 commit comments

Comments
 (0)