Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Problem: (CRO-498) No events for punishments (jailing/slashing) #504

Merged
merged 1 commit into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 22 additions & 2 deletions chain-abci/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,35 @@ impl<T: EnclaveProxy> abci::Application for ChainNodeApp<T> {
accounts_to_jail.push(non_live_address)
}

let mut jailing_event = Event::new();
jailing_event.field_type = TendermintEventType::JailValidators.to_string();

for account_address in accounts_to_jail {
let mut kvpair = KVPair::new();
kvpair.key = b"account".to_vec();
kvpair.value = account_address.to_string().into_bytes();

jailing_event.attributes.push(kvpair);

self.jail_account(account_address)
.expect("Unable to jail account in begin block");
}

self.slash_eligible_accounts()
let slashing_event = self
.slash_eligible_accounts()
.expect("Unable to slash accounts in slashing queue");

ResponseBeginBlock::new()
let mut response = ResponseBeginBlock::new();

if !jailing_event.attributes.is_empty() {
response.events.push(jailing_event);
}

if !slashing_event.attributes.is_empty() {
response.events.push(slashing_event);
}

response
}

/// Consensus Connection: Actually processing the transaction, performing some form of a
Expand Down
16 changes: 14 additions & 2 deletions chain-abci/src/app/slash_accounts.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use abci::{Event, KVPair};

use chain_core::common::TendermintEventType;
use chain_core::state::account::StakedStateAddress;
use chain_tx_validation::Error;

Expand All @@ -7,7 +10,7 @@ use crate::storage::tx::get_account;

impl<T: EnclaveProxy> ChainNodeApp<T> {
/// Slashes all the eligible accounts currently in slashing queue
pub fn slash_eligible_accounts(&mut self) -> Result<(), Error> {
pub fn slash_eligible_accounts(&mut self) -> Result<Event, Error> {
let last_state = self
.last_state
.as_mut()
Expand All @@ -28,7 +31,16 @@ impl<T: EnclaveProxy> ChainNodeApp<T> {
})
.collect();

let mut slashing_event = Event::new();
slashing_event.field_type = TendermintEventType::SlashValidators.to_string();

for staking_address in accounts_to_slash {
let mut kvpair = KVPair::new();
kvpair.key = b"account".to_vec();
kvpair.value = staking_address.to_string().into_bytes();

slashing_event.attributes.push(kvpair);

let mut account = get_account(
&staking_address,
&self.uncommitted_account_root_hash,
Expand Down Expand Up @@ -61,6 +73,6 @@ impl<T: EnclaveProxy> ChainNodeApp<T> {
self.uncommitted_account_root_hash = new_root;
}

Ok(())
Ok(slashing_event)
}
}
4 changes: 4 additions & 0 deletions chain-core/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ pub type H512 = [u8; HASH_SIZE_256 * 2];
pub enum TendermintEventType {
ValidTransactions,
BlockFilter,
JailValidators,
SlashValidators,
}

impl fmt::Display for TendermintEventType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TendermintEventType::ValidTransactions => write!(f, "valid_txs"),
TendermintEventType::BlockFilter => write!(f, "block_filter"),
TendermintEventType::JailValidators => write!(f, "jail_validators"),
TendermintEventType::SlashValidators => write!(f, "slash_validators"),
}
}
}