Skip to content

Commit

Permalink
Merge branch 'brent/cubic-slashing' into draft
Browse files Browse the repository at this point in the history
* brent/cubic-slashing:
  WIP changes from Manu and logging
  fixing `find_slashes_in_range`
  pos sm test: ease load on the CI
  changelog: #892
  fixup!: don't call `process_slashes` within `advance_epoch`
  clean up logging
  fix clippy
  remove test code until slash pool transfers are solved
  rip slash pool
  get_slashed_amount: inclusive on infraction epoch
  add cli to sdk impl for tx unjail
  make find_slashes_in_ranges inclusive on end epoch
  withdraw: fix bounds for collecting slashes for an unbond
  aesthetic cleaning
  revert bound cleaning for readability
  refactor slash lookup
  fixup! add cubic_slash_window_length to bounds (maybe still needs change)
  remove unused cubic slash function
  refactor epoch offsets with params methods
  store total bond sums of each validator for efficient computation
  pos/lib.rs: WIP fix things inside of `bonds_and_unbonds`
  fix PoS client query related functions
  fix `bond_amount`
  state machine test: add slashing
  basic nested map test
  slashing: unit and e2e tests
  Makefile and Cargo.toml
  cubic and general slashing algorithms and transactions
  format: rustfmt for incorrect sdk-wallet-force commits
  changelog: add #925, update
  ci: remove clippy-abcipp check
  changelog: add #889
  DoS checks in fee specs for fee unshielding
  Adjusts block proposer address in fee specs
  Improves unshielding tx verification in fee specs
  Updates tendermint link in fee specs
  Improves gas accounting in specs
  Updates check table in fee specs
  Misc updates to fee specs
  Fixes wal in fee specs
  Adds protocol transactions to fee specs
  Adds governance proposals to fee specs
  Fixes unshielding in fee specs
  Enforces tx type order in fee specs
  Refactors sections of fee specs
  Adds unshielding to fee specs
  Updates fee specs
  Adds fee specs
  • Loading branch information
brentstone committed Jun 1, 2023
2 parents cfd8de5 + c21b1ea commit 594f8cc
Show file tree
Hide file tree
Showing 31 changed files with 5,119 additions and 563 deletions.
5 changes: 5 additions & 0 deletions .changelog/unreleased/features/892-cubic-slashing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- The implementation of the cubic slashing system that touches virtually all
parts of the proof-of-stake system. Slashes tokens are currently kept in the
PoS address rather than being transferred to the Slash Pool address. This PR
also includes significant testing infrastructure, highlighted by the PoS state
machine test with slashing. ([#892](https://github.com/anoma/namada/pull/892))
40 changes: 39 additions & 1 deletion apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1766,6 +1766,7 @@ pub mod args {
pub const TX_WITHDRAW_WASM: &str = "tx_withdraw.wasm";
pub const TX_CHANGE_COMMISSION_WASM: &str =
"tx_change_validator_commission.wasm";
pub const TX_UNJAIL_VALIDATOR_WASM: &str = "tx_unjail_validator.wasm";

pub const ADDRESS: Arg<WalletAddress> = arg("address");
pub const ALIAS_OPT: ArgOpt<String> = ALIAS.opt();
Expand Down Expand Up @@ -3076,7 +3077,7 @@ pub mod args {
}

fn def(app: App) -> App {
app.add_args::<Query<CliTypes>>()
app.add_args::<Tx<CliTypes>>()
.arg(VALIDATOR.def().about(
"The validator's address whose commission rate to change.",
))
Expand All @@ -3088,6 +3089,43 @@ pub mod args {
}
}

impl CliToSdk<TxUnjailValidator<SdkTypes>> for TxUnjailValidator<CliTypes> {
fn to_sdk(self, ctx: &mut Context) -> TxUnjailValidator<SdkTypes> {
TxUnjailValidator {
tx: self.tx.to_sdk(ctx),
validator: ctx.get(&self.validator),
tx_code_path: self
.tx_code_path
.as_path()
.to_str()
.unwrap()
.to_string()
.into_bytes(),
}
}
}

impl Args for TxUnjailValidator<CliTypes> {
fn parse(matches: &ArgMatches) -> Self {
let tx = Tx::parse(matches);
let validator = VALIDATOR.parse(matches);
let tx_code_path = PathBuf::from(TX_UNJAIL_VALIDATOR_WASM);
Self {
tx,
validator,
tx_code_path,
}
}

fn def(app: App) -> App {
app.add_args::<Tx<CliTypes>>().arg(
VALIDATOR.def().about(
"The address of the jailed validator to re-activate.",
),
)
}
}

impl CliToSdk<QueryCommissionRate<SdkTypes>> for QueryCommissionRate<CliTypes> {
fn to_sdk(self, ctx: &mut Context) -> QueryCommissionRate<SdkTypes> {
QueryCommissionRate::<SdkTypes> {
Expand Down
14 changes: 14 additions & 0 deletions apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,20 @@ pub async fn submit_validator_commission_change<
.await
}

pub async fn submit_unjail_validator<
C: namada::ledger::queries::Client + Sync,
>(
client: &C,
mut ctx: Context,
mut args: args::TxUnjailValidator,
) -> Result<(), tx::Error> {
args.tx.chain_id = args
.tx
.chain_id
.or_else(|| Some(ctx.config.ledger.chain_id.clone()));
tx::submit_unjail_validator::<C, _>(client, &mut ctx.wallet, args).await
}

/// Submit transaction and wait for result. Returns a list of addresses
/// initialized in the transaction if any. In dry run, this is always empty.
async fn process_tx<C: namada::ledger::queries::Client + Sync>(
Expand Down
5 changes: 5 additions & 0 deletions apps/src/lib/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ pub mod genesis_config {
// light client attack.
// XXX: u64 doesn't work with toml-rs!
pub light_client_attack_min_slash_rate: Decimal,
/// Number of epochs above and below (separately) the current epoch to
/// consider when doing cubic slashing
pub cubic_slashing_window_length: u64,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down Expand Up @@ -647,6 +650,7 @@ pub mod genesis_config {
target_staked_ratio,
duplicate_vote_min_slash_rate,
light_client_attack_min_slash_rate,
cubic_slashing_window_length,
} = pos_params;
let pos_params = PosParams {
max_validator_slots,
Expand All @@ -659,6 +663,7 @@ pub mod genesis_config {
target_staked_ratio,
duplicate_vote_min_slash_rate,
light_client_attack_min_slash_rate,
cubic_slashing_window_length,
};

let mut genesis = Genesis {
Expand Down
Loading

0 comments on commit 594f8cc

Please sign in to comment.