Skip to content

Commit d260af9

Browse files
authored
Update rewards (#141)
* Process snapshot to output VoterHIR Use VoterHIR as the output format for the snapshot tool * Add cap for voting influence in snapshot Limit overall influence of actors in an election by capping their maximum voting power at arbitrary levels. Since a lot of configurations are going in the snapshot process, I'm thinking of having it output two different artifacts: the list of VoterHIRs, as already proposed, and another one which is a light wrapper around VoterHIR which contains contributions from snapshot, to be used for the reward process. I'm proposing to keep the separate because the first one is more general, while the second one is tied to our current deployment and more likely to change. * update rewards * add test for representatives * add missing cli options * simplify direct voter rewards * remove unused import
1 parent 2478556 commit d260af9

File tree

6 files changed

+139
-247
lines changed

6 files changed

+139
-247
lines changed

catalyst-toolbox/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ image = "0.23.12"
5858
qrcode = "0.12"
5959
quircs = "0.10.0"
6060
symmetric-cipher = { git = "https://github.com/input-output-hk/chain-wallet-libs.git", branch = "master" }
61-
graphql_client = "0.10"
61+
graphql_client = { version = "0.10" }
6262
gag = "1"
6363
vit-servicing-station-lib = { git = "https://github.com/input-output-hk/vit-servicing-station.git", branch = "master" }
6464
env_logger = "0.9"
Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
use catalyst_toolbox::rewards::voters::{calc_voter_rewards, Rewards, VoteCount};
2-
use catalyst_toolbox::snapshot::{
3-
registration::MainnetRewardAddress, voting_group::VotingGroupAssigner, Snapshot,
4-
};
2+
use catalyst_toolbox::snapshot::{registration::MainnetRewardAddress, SnapshotInfo};
53
use catalyst_toolbox::utils::assert_are_close;
64

75
use color_eyre::Report;
8-
use fraction::Fraction;
96
use jcli_lib::jcli_lib::block::Common;
10-
use jormungandr_lib::{crypto::account::Identifier, interfaces::Block0Configuration};
117
use structopt::StructOpt;
128

139
use std::collections::BTreeMap;
@@ -22,19 +18,9 @@ pub struct VotersRewards {
2218
#[structopt(long)]
2319
total_rewards: u64,
2420

25-
/// Path to raw snapshot
21+
/// Path to a json encoded list of `SnapshotInfo`
2622
#[structopt(long)]
27-
snapshot_path: PathBuf,
28-
29-
/// Stake threshold to be able to participate in a Catalyst sidechain
30-
/// Registrations with less than the threshold associated to the stake address
31-
/// will be ignored
32-
#[structopt(long)]
33-
registration_threshold: u64,
34-
35-
/// Voting power cap for each account
36-
#[structopt(short, long)]
37-
voting_power_cap: Fraction,
23+
snapshot_info_path: PathBuf,
3824

3925
#[structopt(long)]
4026
votes_count_path: PathBuf,
@@ -66,30 +52,22 @@ impl VotersRewards {
6652
let VotersRewards {
6753
common,
6854
total_rewards,
69-
snapshot_path,
70-
registration_threshold,
55+
snapshot_info_path,
7156
votes_count_path,
7257
vote_threshold,
73-
voting_power_cap,
7458
} = self;
75-
let block = common.input.load_block()?;
76-
let block0 = Block0Configuration::from_block(&block)?;
7759

7860
let vote_count: VoteCount = serde_json::from_reader(jcli_lib::utils::io::open_file_read(
7961
&Some(votes_count_path),
8062
)?)?;
8163

82-
let snapshot = Snapshot::from_raw_snapshot(
83-
serde_json::from_reader(jcli_lib::utils::io::open_file_read(&Some(snapshot_path))?)?,
84-
registration_threshold.into(),
85-
voting_power_cap,
86-
&DummyAssigner,
64+
let snapshot: Vec<SnapshotInfo> = serde_json::from_reader(
65+
jcli_lib::utils::io::open_file_read(&Some(snapshot_info_path))?,
8766
)?;
8867

8968
let results = calc_voter_rewards(
9069
vote_count,
9170
vote_threshold,
92-
&block0,
9371
snapshot,
9472
Rewards::from(total_rewards),
9573
)?;
@@ -101,10 +79,3 @@ impl VotersRewards {
10179
Ok(())
10280
}
10381
}
104-
105-
struct DummyAssigner;
106-
impl VotingGroupAssigner for DummyAssigner {
107-
fn assign(&self, _vk: &Identifier) -> String {
108-
unimplemented!()
109-
}
110-
}

catalyst-toolbox/src/bin/cli/snapshot/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct SnapshotCmd {
2020
snapshot: PathBuf,
2121
/// Registrations voting power threshold for eligibility
2222
#[structopt(short, long)]
23-
threshold: Value,
23+
min_stake_threshold: Value,
2424

2525
/// Voter group to assign direct voters to.
2626
/// If empty, defaults to "voter"
@@ -59,7 +59,7 @@ impl SnapshotCmd {
5959
let assigner = RepsVotersAssigner::new(direct_voter, representative, self.reps_db_api_url)?;
6060
let initials = Snapshot::from_raw_snapshot(
6161
raw_snapshot,
62-
self.threshold,
62+
self.min_stake_threshold,
6363
self.voting_power_cap,
6464
&assigner,
6565
)?

0 commit comments

Comments
 (0)