Skip to content

Commit 79af905

Browse files
committed
merge rust rewards script
1 parent 4ee02f6 commit 79af905

File tree

5 files changed

+43
-113
lines changed

5 files changed

+43
-113
lines changed

catalyst-toolbox/src/bin/cli/rewards/full/config.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ pub(super) struct Inputs {
1818
pub(super) snapshot_path: PathBuf,
1919
pub(super) vote_count_path: PathBuf,
2020
pub(super) reviews_csv: PathBuf,
21-
pub(super) assessments_path: PathBuf, // is assessments the same as reviews?
21+
pub(super) assessments_path: PathBuf,
2222
pub(super) proposal_bonus_output: Option<PathBuf>,
2323
pub(super) approved_proposals_path: PathBuf,
24-
pub(super) proposer_script_path: PathBuf,
25-
pub(super) csv_merger_script_path: PathBuf,
2624
pub(super) active_voteplans: PathBuf,
2725
pub(super) challenges: PathBuf,
2826
pub(super) proposals_path: PathBuf,
27+
pub(super) committee_keys: PathBuf,
28+
pub(super) excluded_proposals: Option<PathBuf>,
2929
}
3030

3131
#[derive(Debug, Deserialize)]
@@ -48,15 +48,12 @@ pub(super) struct Params {
4848
pub(super) struct VoterParams {
4949
pub(super) total_rewards: u64,
5050
pub(super) vote_threshold: u64,
51-
pub(super) registration_threshold: u64,
5251
}
5352

5453
#[derive(Debug, Deserialize)]
5554
pub(super) struct ProposerParams {
56-
pub(super) total_rewards: u64,
5755
pub(super) stake_threshold: f64,
5856
pub(super) approval_threshold: f64,
59-
pub(super) pattern: String,
6057
}
6158

6259
#[derive(Debug, Deserialize)]

catalyst-toolbox/src/bin/cli/rewards/full/mod.rs

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
use std::{fs::File, path::Path};
22

3+
use catalyst_toolbox::{
4+
http::HttpClient,
5+
rewards::proposers::{OutputFormat, ProposerRewards},
6+
};
37
use color_eyre::Result;
48
use config::*;
59
use log::info;
610
use serde_json::from_reader;
711

812
mod config;
9-
mod proposers;
10-
mod python;
1113

1214
pub(super) fn full_rewards(path: &Path) -> Result<()> {
1315
let config = from_reader(File::open(path)?)?;
@@ -21,11 +23,11 @@ pub(super) fn full_rewards(path: &Path) -> Result<()> {
2123
assessments_path,
2224
proposal_bonus_output,
2325
approved_proposals_path,
24-
proposer_script_path,
25-
csv_merger_script_path,
2626
active_voteplans,
2727
challenges,
2828
proposals_path,
29+
committee_keys,
30+
excluded_proposals,
2931
},
3032
outputs:
3133
Outputs {
@@ -45,11 +47,9 @@ pub(super) fn full_rewards(path: &Path) -> Result<()> {
4547

4648
info!("calculating voter rewards");
4749
super::voters::voter_rewards(
48-
&block_file,
4950
&voter_rewards_output,
5051
&vote_count_path,
5152
&snapshot_path,
52-
voter_params.registration_threshold,
5353
voter_params.vote_threshold,
5454
voter_params.total_rewards,
5555
)?;
@@ -80,18 +80,33 @@ pub(super) fn full_rewards(path: &Path) -> Result<()> {
8080
)?;
8181

8282
info!("calculating proposer rewards");
83-
proposers::proposers_rewards(
84-
&proposer_script_path,
85-
&csv_merger_script_path,
86-
&block_file,
87-
&proposer_rewards_output,
88-
proposer_params.stake_threshold,
89-
proposer_params.approval_threshold,
90-
&proposals_path,
91-
&challenges,
92-
&active_voteplans,
93-
&proposer_params.pattern,
83+
super::proposers::rewards(
84+
&ProposerRewards {
85+
output: proposer_rewards_output,
86+
block0: block_file,
87+
total_stake_threshold: proposer_params.stake_threshold,
88+
approval_threshold: proposer_params.approval_threshold,
89+
proposals: Some(proposals_path),
90+
active_voteplans: Some(active_voteplans),
91+
challenges: Some(challenges),
92+
committee_keys: Some(committee_keys),
93+
excluded_proposals,
94+
output_format: OutputFormat::Csv,
95+
vit_station_url: "not used".into(),
96+
},
97+
&PanickingHttpClient,
9498
)?;
9599

96100
Ok(())
97101
}
102+
103+
struct PanickingHttpClient;
104+
105+
impl HttpClient for PanickingHttpClient {
106+
fn get<T>(&self, _path: &str) -> Result<catalyst_toolbox::http::HttpResponse<T>>
107+
where
108+
T: for<'a> serde::Deserialize<'a>,
109+
{
110+
unimplemented!("this implementation always panics");
111+
}
112+
}

catalyst-toolbox/src/bin/cli/rewards/full/proposers.rs

Lines changed: 0 additions & 54 deletions
This file was deleted.

catalyst-toolbox/src/bin/cli/rewards/full/python.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.

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

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@ use catalyst_toolbox::utils::assert_are_close;
44

55
use color_eyre::eyre::eyre;
66
use color_eyre::{Report, Result};
7-
use jcli_lib::block::{load_block, open_block_file};
8-
use jcli_lib::jcli_lib::block::{open_output, Common};
9-
use jcli_lib::utils::io::open_file_read;
10-
use jormungandr_lib::interfaces::Block0Configuration;
11-
12-
use color_eyre::Report;
7+
use jcli_lib::block::open_output;
138
use jcli_lib::jcli_lib::block::Common;
9+
1410
use structopt::StructOpt;
1511

1612
use std::collections::BTreeMap;
@@ -65,48 +61,35 @@ impl VotersRewards {
6561
} = self;
6662

6763
voter_rewards(
68-
common
69-
.input
70-
.input_file
71-
.as_deref()
72-
.ok_or(eyre!("missing block file"))?,
7364
common
7465
.output_file
7566
.as_deref()
7667
.ok_or(eyre!("missing output file"))?,
7768
&votes_count_path,
78-
&snapshot_path,
79-
registration_threshold,
69+
&snapshot_info_path,
8070
vote_threshold,
8171
total_rewards,
8272
)
8373
}
8474
}
8575

8676
pub fn voter_rewards(
87-
block_file: &Path,
8877
output: &Path,
8978
votes_count_path: &Path,
9079
snapshot_path: &Path,
91-
registration_threshold: u64,
9280
vote_threshold: u64,
9381
total_rewards: u64,
9482
) -> Result<()> {
95-
let block = open_block_file(&Some(block_file.to_path_buf()))?;
96-
let block = load_block(block)?;
97-
98-
let block0 = Block0Configuration::from_block(&block)?;
83+
let vote_count: VoteCount = serde_json::from_reader(jcli_lib::utils::io::open_file_read(
84+
&Some(votes_count_path),
85+
)?)?;
9986

100-
let vote_count: VoteCount = serde_json::from_reader(open_file_read(&Some(votes_count_path))?)?;
101-
let snapshot = Snapshot::from_raw_snapshot(
102-
serde_json::from_reader(open_file_read(&Some(snapshot_path))?)?,
103-
registration_threshold.into(),
104-
);
87+
let snapshot: Vec<SnapshotInfo> =
88+
serde_json::from_reader(jcli_lib::utils::io::open_file_read(&Some(snapshot_path))?)?;
10589

10690
let results = calc_voter_rewards(
10791
vote_count,
10892
vote_threshold,
109-
&block0,
11093
snapshot,
11194
Rewards::from(total_rewards),
11295
)?;

0 commit comments

Comments
 (0)