Skip to content

Commit 81c0cbd

Browse files
authored
Add voting power cap during snapshot (#135)
* Process snapshot to output VoterHIR Use VoterHIR as the output format for the snapshot tool * revert vp cap * add proptest implementation for VoterHIR * 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 doc comment * add missing import * pin Fraction to 0.10 * address review comments
1 parent 55d1572 commit 81c0cbd

File tree

10 files changed

+520
-88
lines changed

10 files changed

+520
-88
lines changed

Cargo.lock

Lines changed: 64 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

catalyst-toolbox/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ gag = "1"
6161
vit-servicing-station-lib = { git = "https://github.com/input-output-hk/vit-servicing-station.git", branch = "master" }
6262
env_logger = "0.9"
6363
voting-hir = { path = "../voting-hir", features = ["serde"] }
64+
fraction = "0.10"
6465

6566
[dev-dependencies]
6667
rand_chacha = "0.3"
@@ -71,6 +72,7 @@ chain-vote = { git = "https://github.com/input-output-hk/chain-libs.git", branch
7172
proptest = { git = "https://github.com/input-output-hk/proptest", branch = "master" }
7273
test-strategy = "0.2"
7374
serde_test = "1"
75+
voting-hir = { path = "../voting-hir", features = ["serde", "proptest"] }
7476

7577
[build-dependencies]
7678
versionisator = "1.0.3"

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use catalyst_toolbox::rewards::voters::{calc_voter_rewards, Rewards, VoteCount};
2-
use catalyst_toolbox::snapshot::{registration::MainnetRewardAddress, Snapshot};
2+
use catalyst_toolbox::snapshot::{
3+
registration::MainnetRewardAddress, voting_group::VotingGroupAssigner, Snapshot,
4+
};
35
use catalyst_toolbox::utils::assert_are_close;
46

57
use color_eyre::Report;
8+
use fraction::Fraction;
69
use jcli_lib::jcli_lib::block::Common;
7-
use jormungandr_lib::interfaces::Block0Configuration;
8-
10+
use jormungandr_lib::{crypto::account::Identifier, interfaces::Block0Configuration};
911
use structopt::StructOpt;
1012

1113
use std::collections::BTreeMap;
@@ -30,6 +32,10 @@ pub struct VotersRewards {
3032
#[structopt(long)]
3133
registration_threshold: u64,
3234

35+
/// Voting power cap for each account
36+
#[structopt(short, long)]
37+
voting_power_cap: Fraction,
38+
3339
#[structopt(long)]
3440
votes_count_path: PathBuf,
3541

@@ -64,6 +70,7 @@ impl VotersRewards {
6470
registration_threshold,
6571
votes_count_path,
6672
vote_threshold,
73+
voting_power_cap,
6774
} = self;
6875
let block = common.input.load_block()?;
6976
let block0 = Block0Configuration::from_block(&block)?;
@@ -75,7 +82,9 @@ impl VotersRewards {
7582
let snapshot = Snapshot::from_raw_snapshot(
7683
serde_json::from_reader(jcli_lib::utils::io::open_file_read(&Some(snapshot_path))?)?,
7784
registration_threshold.into(),
78-
);
85+
voting_power_cap,
86+
&DummyAssigner,
87+
)?;
7988

8089
let results = calc_voter_rewards(
8190
vote_count,
@@ -92,3 +101,10 @@ impl VotersRewards {
92101
Ok(())
93102
}
94103
}
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: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use catalyst_toolbox::snapshot::{voting_group::RepsVotersAssigner, RawSnapshot, Snapshot};
22
use color_eyre::Report;
3+
use fraction::Fraction;
34
use jcli_lib::utils::{output_file::OutputFile, output_format::OutputFormat};
45
use jormungandr_lib::interfaces::Value;
56
use std::fs::File;
67
use std::io::Write;
78
use std::path::PathBuf;
89
use structopt::StructOpt;
910

10-
const DEFAULT_DIRECT_VOTER_GROUP: &str = "voter";
11+
const DEFAULT_DIRECT_VOTER_GROUP: &str = "direct";
1112
const DEFAULT_REPRESENTATIVE_GROUP: &str = "rep";
1213

1314
/// Process raw registrations into blockchain initials
@@ -35,6 +36,10 @@ pub struct SnapshotCmd {
3536
#[structopt(long)]
3637
reps_db_api_url: reqwest::Url,
3738

39+
/// Voting power cap for each account
40+
#[structopt(short, long)]
41+
voting_power_cap: Fraction,
42+
3843
#[structopt(flatten)]
3944
output: OutputFile,
4045

@@ -52,8 +57,13 @@ impl SnapshotCmd {
5257
.representatives_group
5358
.unwrap_or_else(|| DEFAULT_REPRESENTATIVE_GROUP.into());
5459
let assigner = RepsVotersAssigner::new(direct_voter, representative, self.reps_db_api_url)?;
55-
let initials =
56-
Snapshot::from_raw_snapshot(raw_snapshot, self.threshold).to_voter_hir(&assigner);
60+
let initials = Snapshot::from_raw_snapshot(
61+
raw_snapshot,
62+
self.threshold,
63+
self.voting_power_cap,
64+
&assigner,
65+
)?
66+
.to_voter_hir();
5767
let mut out_writer = self.output.open()?;
5868
let content = self
5969
.output_format

catalyst-toolbox/src/rewards/voters.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ mod tests {
186186
use chain_impl_mockchain::chaintypes::ConsensusVersion;
187187
use chain_impl_mockchain::fee::LinearFee;
188188
use chain_impl_mockchain::tokens::{identifier::TokenIdentifier, name::TokenName};
189+
use fraction::Fraction;
189190
use jormungandr_lib::crypto::account::Identifier;
190191
use jormungandr_lib::interfaces::BlockchainConfiguration;
191192
use jormungandr_lib::interfaces::{Destination, Initial, InitialToken, InitialUTxO};
@@ -338,7 +339,13 @@ mod tests {
338339
total_stake += i;
339340
}
340341

341-
let snapshot = Snapshot::from_raw_snapshot(raw_snapshot.into(), 0.into());
342+
let snapshot = Snapshot::from_raw_snapshot(
343+
raw_snapshot.into(),
344+
0.into(),
345+
Fraction::from(1u64),
346+
&|_vk: &Identifier| String::new(),
347+
)
348+
.unwrap();
342349

343350
let initial = snapshot.to_block0_initials(Discrimination::Test);
344351
let block0 = blockchain_configuration(initial);

0 commit comments

Comments
 (0)