Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Address review comments: docs and logs
Browse files Browse the repository at this point in the history
  • Loading branch information
afck committed Jan 29, 2020
1 parent 3b52afa commit cc755bf
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ethcore/engines/authority-round/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ impl AuthorityRound {
fn run_posdao(&self, block: &ExecutedBlock, nonce: Option<U256>) -> Result<Vec<SignedTransaction>, Error> {
// Skip the rest of the function unless there has been a transition to POSDAO AuRa.
if self.posdao_transition.map_or(true, |posdao_block| block.header.number() < posdao_block) {
trace!(target: "engine", "Skipping calls to POSDAO randomness and validator set contracts");
trace!(target: "engine", "Skipping POSDAO calls to validator set contracts");
return Ok(Vec::new());
}

Expand Down
2 changes: 1 addition & 1 deletion ethcore/engines/validator-set/res/validator_report.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[
{"constant":false,"inputs":[{"name":"validator","type":"address"},{"name":"blockNumber","type":"uint256"},{"name":"proof","type":"bytes"}],"name":"reportMalicious","outputs":[],"payable":false,"type":"function"},
{"constant":false,"inputs":[{"name":"validator","type":"address"},{"name":"blockNumber","type":"uint256"}],"name":"reportBenign","outputs":[],"payable":false,"type":"function"},
{ "constant": true, "inputs": [ { "name": "validator", "type": "address" }, { "name": "blockNum", "type": "uint256" } ], "name": "maliceReportedForBlock", "outputs": [ { "name": "", "type": "address[]" } ], "payable": false, "stateMutability": "view", "type": "function" }
{"constant": true, "inputs": [ { "name": "validator", "type": "address" }, { "name": "blockNum", "type": "uint256" } ], "name": "maliceReportedForBlock", "outputs": [ { "name": "", "type": "address[]" } ], "payable": false, "stateMutability": "view", "type": "function" }
]
6 changes: 5 additions & 1 deletion ethcore/engines/validator-set/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::sync::Weak;
use parity_bytes::Bytes;
use ethabi_contract::use_contract;
use ethereum_types::{H256, U256, Address};
use log::{warn, trace};
use log::{info, warn, trace};
use machine::Machine;
use parking_lot::RwLock;
use common_types::{
Expand Down Expand Up @@ -165,13 +165,17 @@ impl ValidatorSet for ValidatorContract {
fn report_malicious(&self, address: &Address, _set_block: BlockNumber, block: BlockNumber, proof: Bytes) {
if let Err(s) = self.do_report_malicious(address, block, proof) {
warn!(target: "engine", "Validator {} could not be reported ({}) on block {}", address, s, block);
} else {
info!(target: "engine", "Reporting malicious validator {} on block {}", address, block);
}
}

fn report_benign(&self, address: &Address, _set_block: BlockNumber, block: BlockNumber) {
trace!(target: "engine", "validator set recording benign misbehaviour at block #{} by {:#x}", block, address);
if let Err(s) = self.do_report_benign(address, block) {
warn!(target: "engine", "Validator {} could not be reported ({}) on block {}", address, s, block);
} else {
info!(target: "engine", "Reporting validator {} on block {} (benign fault)", address, block);
}
}

Expand Down
11 changes: 10 additions & 1 deletion ethcore/engines/validator-set/src/safe_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ use_contract!(validator_set, "res/validator_set.json");
const MAX_QUEUED_REPORTS: usize = 10;
/// The maximum number of malice reports to include when creating a new block.
const MAX_REPORTS_PER_BLOCK: usize = 10;
/// Don't re-send malice reports every block. Skip this many before retrying.
const REPORTS_SKIP_BLOCKS: u64 = 1;

const MEMOIZE_CAPACITY: usize = 500;

Expand Down Expand Up @@ -233,6 +235,13 @@ impl ValidatorSafeContract {
}
}

/// Puts a malice report into the queue for later resending.
///
/// # Arguments
///
/// * `addr` - The address of the misbehaving validator.
/// * `block` - The block number at which the misbehavior occurred.
/// * `data` - The call data for the `reportMalicious` contract call.
pub(crate) fn enqueue_report(&self, addr: Address, block: BlockNumber, data: Vec<u8>) {
// Skip the rest of the function unless there has been a transition to POSDAO AuRa.
if self.posdao_transition.map_or(true, |block_num| block < block_num) {
Expand Down Expand Up @@ -388,7 +397,7 @@ impl ValidatorSet for ValidatorSafeContract {
let mut resent_reports_in_block = self.resent_reports_in_block.lock();

// Skip at least one block after sending malicious reports last time.
if header.number() > *resent_reports_in_block + 1 {
if header.number() > *resent_reports_in_block + REPORTS_SKIP_BLOCKS {
*resent_reports_in_block = header.number();
let mut nonce = client.latest_nonce(our_address);
for (address, block, data) in report_queue.iter() {
Expand Down

0 comments on commit cc755bf

Please sign in to comment.