Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement cubic slashing #892

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
178f293
cubic and general slashing algorithms and transactions
brentstone May 26, 2023
8099d27
Makefile and Cargo.toml
brentstone May 26, 2023
365fbdb
slashing: unit and e2e tests
brentstone May 26, 2023
cdedbd2
basic nested map test
brentstone May 26, 2023
5fbd90f
state machine test: add slashing
brentstone May 26, 2023
5d007be
fix `bond_amount`
brentstone May 11, 2023
27290f1
fix PoS client query related functions
brentstone May 11, 2023
3dde190
pos/lib.rs: WIP fix things inside of `bonds_and_unbonds`
brentstone May 16, 2023
7dcd4b0
store total bond sums of each validator for efficient computation
brentstone May 23, 2023
3591284
refactor epoch offsets with params methods
tzemanovic May 23, 2023
e3782ad
remove unused cubic slash function
brentstone May 24, 2023
ffead5f
fixup! add cubic_slash_window_length to bounds (maybe still needs cha…
brentstone May 24, 2023
b2fb2dc
refactor slash lookup
tzemanovic May 24, 2023
d8f7a50
revert bound cleaning for readability
brentstone May 25, 2023
8da2849
aesthetic cleaning
brentstone May 25, 2023
0ae4157
withdraw: fix bounds for collecting slashes for an unbond
brentstone May 25, 2023
c4eb55e
make find_slashes_in_ranges inclusive on end epoch
tzemanovic May 25, 2023
69e52c8
add cli to sdk impl for tx unjail
tzemanovic May 25, 2023
0f41f7a
get_slashed_amount: inclusive on infraction epoch
tzemanovic May 25, 2023
9543ff4
rip slash pool
tzemanovic May 25, 2023
ade6b00
remove test code until slash pool transfers are solved
brentstone May 25, 2023
e1e1501
fix clippy
brentstone May 25, 2023
fdec51e
clean up logging
brentstone May 25, 2023
ecd8517
fixup!: don't call `process_slashes` within `advance_epoch`
brentstone May 26, 2023
1361f65
fixup! rip slash pool
tzemanovic May 26, 2023
c09ff8b
fixup! cubic and general slashing algorithms and transactions
tzemanovic May 26, 2023
2bc8ec3
changelog: #892
brentstone May 26, 2023
2936909
pos sm test: ease load on the CI
brentstone May 30, 2023
9702079
fixing `find_slashes_in_range`
brentstone May 30, 2023
40f6019
WIP changes from Manu and logging
brentstone May 31, 2023
424abc4
fix wasm tx tests
brentstone Jun 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1684,6 +1684,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 @@ -3015,7 +3016,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 @@ -3027,6 +3028,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 @@ -990,6 +990,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,
brentstone marked this conversation as resolved.
Show resolved Hide resolved
}

#[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