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

Commit

Permalink
aura: fix panic on extra_info with unsealed block (#9755)
Browse files Browse the repository at this point in the history
* aura: fix panic when unsealed block passed to extra_info

* aura: use hex formatting for EmptyStep hashes

* aura: add test for extra_info
  • Loading branch information
andresilva committed Oct 15, 2018
1 parent d16c4da commit 644852e
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion ethcore/src/engines/authority_round/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ impl EmptyStep {

impl fmt::Display for EmptyStep {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(f, "({}, {}, {})", self.signature, self.step, self.parent_hash)
write!(f, "({:x}, {}, {:x})", self.signature, self.step, self.parent_hash)
}
}

Expand Down Expand Up @@ -829,6 +829,10 @@ impl Engine<EthereumMachine> for AuthorityRound {

/// Additional engine-specific information for the user/developer concerning `header`.
fn extra_info(&self, header: &Header) -> BTreeMap<String, String> {
if header.seal().len() < header_expected_seal_fields(header, self.empty_steps_transition) {
return BTreeMap::default();
}

let step = header_step(header, self.empty_steps_transition).as_ref().map(ToString::to_string).unwrap_or("".into());
let signature = header_signature(header, self.empty_steps_transition).as_ref().map(ToString::to_string).unwrap_or("".into());

Expand Down Expand Up @@ -1403,10 +1407,12 @@ impl Engine<EthereumMachine> for AuthorityRound {

#[cfg(test)]
mod tests {
use std::collections::BTreeMap;
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering};
use hash::keccak;
use ethereum_types::{Address, H520, H256, U256};
use ethkey::Signature;
use header::Header;
use rlp::encode;
use block::*;
Expand Down Expand Up @@ -2072,4 +2078,40 @@ mod tests {
addr1_balance + (1000 + 0) + (1000 + 2),
)
}

#[test]
fn extra_info_from_seal() {
let (spec, tap, accounts) = setup_empty_steps();
let engine = &*spec.engine;

let addr1 = accounts[0];
engine.set_signer(tap.clone(), addr1, "1".into());

let mut header: Header = Header::default();
let empty_step = empty_step(engine, 1, &header.parent_hash());
let sealed_empty_step = empty_step.sealed();

header.set_number(2);
header.set_seal(vec![
encode(&2usize).to_vec(),
encode(&H520::default()).to_vec(),
::rlp::encode_list(&vec![sealed_empty_step]).to_vec(),
]);

let info = engine.extra_info(&header);

let mut expected = BTreeMap::default();
expected.insert("step".into(), "2".into());
expected.insert("signature".into(), Signature::from(H520::default()).to_string());
expected.insert("emptySteps".into(), format!("[{}]", empty_step));

assert_eq!(info, expected);

header.set_seal(vec![]);

assert_eq!(
engine.extra_info(&header),
BTreeMap::default(),
);
}
}

0 comments on commit 644852e

Please sign in to comment.