Skip to content
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
6 changes: 0 additions & 6 deletions core/src/consensus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ impl EngineType {

/// A consensus mechanism for the chain.
pub trait ConsensusEngine: Sync + Send {
/// The name of this engine.
fn name(&self) -> &str;

/// The number of additional header fields required for this engine.
fn seal_fields(&self, _header: &Header) -> usize {
0
Expand Down Expand Up @@ -171,9 +168,6 @@ pub trait ConsensusEngine: Sync + Send {
/// Called when the step is not changed in time
fn on_timeout(&self, _token: usize) {}

/// Stops any services that the may hold the Engine and makes it safe to drop.
fn stop(&self) {}

/// Block transformation functions, before the transactions.
fn on_open_block(&self, _block: &mut ExecutedBlock) -> Result<(), Error> {
Ok(())
Expand Down
4 changes: 0 additions & 4 deletions core/src/consensus/null_engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ use ckey::Address;
pub struct NullEngine;

impl ConsensusEngine for NullEngine {
fn name(&self) -> &str {
"NullEngine"
}

fn seals_internally(&self) -> bool {
true
}
Expand Down
4 changes: 0 additions & 4 deletions core/src/consensus/solo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ impl Solo {
}

impl ConsensusEngine for Solo {
fn name(&self) -> &str {
"Solo"
}

fn seals_internally(&self) -> bool {
true
}
Expand Down
6 changes: 0 additions & 6 deletions core/src/consensus/tendermint/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ use std::sync::atomic::Ordering as AtomicOrdering;
use std::sync::{Arc, Weak};

impl ConsensusEngine for Tendermint {
fn name(&self) -> &str {
"Tendermint"
}

/// (consensus view, proposal signature, authority signatures)
fn seal_fields(&self, _header: &Header) -> usize {
SEAL_FIELDS
Expand Down Expand Up @@ -111,8 +107,6 @@ impl ConsensusEngine for Tendermint {
self.inner.send(worker::Event::OnTimeout(token)).unwrap();
}

fn stop(&self) {}

/// Block transformation functions, before the transactions.
fn on_open_block(&self, block: &mut ExecutedBlock) -> Result<(), Error> {
let mut current_validators = CurrentValidators::load_from_state(block.state())?;
Expand Down
93 changes: 1 addition & 92 deletions core/src/consensus/tendermint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ mod tests {
use super::message::VoteStep;
use crate::account_provider::AccountProvider;
use crate::client::TestBlockChainClient;
use crate::consensus::{EngineError, Seal};
use crate::consensus::Seal;
use crate::error::BlockError;
use crate::error::Error;
use crate::scheme::Scheme;
Expand All @@ -165,18 +165,6 @@ mod tests {
addr
}

#[test]
fn has_valid_metadata() {
use std::time::Duration;
let engine = Scheme::new_test_tendermint().engine;
let time_gap_params = TimeGapParams {
allowed_past_gap: Duration::from_millis(30000),
allowed_future_gap: Duration::from_millis(5000),
};
engine.register_time_gap_config_to_worker(time_gap_params);
assert!(!engine.name().is_empty());
}

#[test]
#[ignore] // FIXME
fn verification_fails_on_short_seal() {
Expand Down Expand Up @@ -227,83 +215,4 @@ mod tests {
println!(".....");
assert!(engine.verify_block_external(&header).is_err());
}

#[test]
#[ignore] // FIXME
fn seal_signatures_checking() {
let (spec, tap, c) = setup();
let engine = spec.engine;

let validator0 = insert_and_unlock(&tap, "0");
let validator1 = insert_and_unlock(&tap, "1");
let validator2 = insert_and_unlock(&tap, "2");
let validator3 = insert_and_unlock(&tap, "3");

let block1_hash = c.add_block_with_author(Some(validator1), 1, 1);

let mut header = Header::default();
header.set_number(2);
let proposer = validator2;
header.set_author(proposer);
header.set_parent_hash(block1_hash);

let vote_info = VoteOn {
step: VoteStep::new(1, 0, Step::Precommit),
block_hash: Some(*header.parent_hash()),
};
let signature2 = tap.get_account(&proposer, None).unwrap().sign(&vote_info.hash()).unwrap();

let seal = Seal::Tendermint {
prev_view: 0,
cur_view: 0,
precommits: vec![signature2],
precommit_bitset: BitSet::new_with_indices(&[2]),
}
.seal_fields()
.unwrap();
header.set_seal(seal);

// One good signature is not enough.
match engine.verify_block_external(&header) {
Err(Error::Engine(EngineError::BadSealFieldSize(_))) => {}
_ => panic!(),
}

let voter = validator3;
let signature3 = tap.get_account(&voter, None).unwrap().sign(&vote_info.hash()).unwrap();
let voter = validator0;
let signature0 = tap.get_account(&voter, None).unwrap().sign(&vote_info.hash()).unwrap();

let seal = Seal::Tendermint {
prev_view: 0,
cur_view: 0,
precommits: vec![signature0, signature2, signature3],
precommit_bitset: BitSet::new_with_indices(&[0, 2, 3]),
}
.seal_fields()
.unwrap();
header.set_seal(seal);

assert!(engine.verify_block_external(&header).is_ok());

let bad_voter = insert_and_unlock(&tap, "101");
let bad_signature = tap.get_account(&bad_voter, None).unwrap().sign(&vote_info.hash()).unwrap();

let seal = Seal::Tendermint {
prev_view: 0,
cur_view: 0,
precommits: vec![signature0, signature2, bad_signature],
precommit_bitset: BitSet::new_with_indices(&[0, 2, 3]),
}
.seal_fields()
.unwrap();
header.set_seal(seal);

// Two good and one bad signature.
match engine.verify_block_external(&header) {
Err(Error::Engine(EngineError::BlockNotAuthorized(_))) => {}
_ => panic!(),
};
engine.stop();
}
}
11 changes: 0 additions & 11 deletions core/src/miner/mem_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,17 +768,6 @@ impl MemPool {
Ok(())
}

/// Removes all elements (in any state) from the pool
#[allow(dead_code)]
pub fn clear(&mut self) {
self.current.clear();
self.future.clear();
self.by_signer_public.clear();
self.by_hash.clear();
self.first_seqs.clear();
self.next_seqs.clear();
}

/// Returns top transactions whose timestamp are in the given range from the pool ordered by priority.
// FIXME: current_timestamp should be `u64`, not `Option<u64>`.
// FIXME: if range_contains becomes stable, use range.contains instead of inequality.
Expand Down
13 changes: 0 additions & 13 deletions core/src/tests/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::scheme::Scheme;
use crate::transaction::VerifiedTransaction;
use ctypes::{BlockHash, Header};
use primitives::Bytes;
use rlp::RlpStream;
Expand All @@ -27,18 +26,6 @@ pub fn create_test_block(header: &Header) -> Bytes {
rlp.out()
}

#[allow(dead_code)]
pub fn create_test_block_with_data(header: &Header, txs: &[VerifiedTransaction], uncles: &[Header]) -> Bytes {
let mut rlp = RlpStream::new_list(3);
rlp.append(header);
rlp.begin_list(txs.len());
for t in txs {
rlp.append_raw(&rlp::encode(t), 1);
}
rlp.append_list(&uncles);
rlp.out()
}

pub fn get_good_dummy_block() -> Bytes {
let (_, bytes) = get_good_dummy_block_hash();
bytes
Expand Down
6 changes: 0 additions & 6 deletions core/src/verification/queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ pub struct VerificationQueue<K: Kind> {
processing: RwLock<HashSet<BlockHash>>, // hash to block number
deleting: Arc<AtomicBool>,
ready_signal: Arc<QueueSignal>,
#[allow(dead_code)]
empty: Arc<SCondvar>,
more_to_verify: Arc<SCondvar>,
verifier_handles: Vec<JoinHandle<()>>,
max_queue_size: usize,
Expand Down Expand Up @@ -133,7 +131,6 @@ impl<K: Kind> VerificationQueue<K> {
verified: AtomicUsize::new(0),
},
check_seal,
empty_mutex: SMutex::new(()),
more_to_verify_mutex: SMutex::new(()),
});
let deleting = Arc::new(AtomicBool::new(false));
Expand Down Expand Up @@ -179,7 +176,6 @@ impl<K: Kind> VerificationQueue<K> {
processing: RwLock::new(HashSet::new()),
deleting,
ready_signal,
empty,
more_to_verify,
verifier_handles,
max_queue_size: cmp::max(config.max_queue_size, MIN_QUEUE_LIMIT),
Expand Down Expand Up @@ -491,8 +487,6 @@ struct Verification<K: Kind> {
bad: Mutex<HashSet<BlockHash>>,
sizes: Sizes,
check_seal: bool,
#[allow(dead_code)]
empty_mutex: SMutex<()>,
more_to_verify_mutex: SMutex<()>,
}

Expand Down
5 changes: 0 additions & 5 deletions state/src/cache/top_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@ impl TopCache {
self.module.get_mut(a, db)
}

#[allow(dead_code)]
pub fn remove_shard(&self, address: &ShardAddress) {
self.shard.remove(address)
}

pub fn action_data(&self, a: &H256, db: &dyn Trie) -> TrieResult<Option<ActionData>> {
self.action_data.get(a, db)
}
Expand Down
2 changes: 0 additions & 2 deletions sync/src/block/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,8 +713,6 @@ impl Extension {
.map(|hash| self.client.block_header(&BlockId::Hash(hash)).expect("Enacted header must exist"))
.collect();
headers_to_download.sort_unstable_by_key(EncodedHeader::number);
#[allow(clippy::redundant_closure)]
// False alarm. https://github.com/rust-lang/rust-clippy/issues/1439
headers_to_download.dedup_by_key(|h| h.hash());

let headers: Vec<_> = headers_to_download
Expand Down
3 changes: 0 additions & 3 deletions types/src/common_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ impl From<Params> for CommonParams {

impl From<CommonParams> for Params {
fn from(p: CommonParams) -> Params {
#[allow(deprecated)]
let mut result: Params = Params {
max_extra_data_size: p.max_extra_data_size().into(),
network_id: p.network_id(),
Expand Down Expand Up @@ -307,7 +306,6 @@ mod tests {
}

#[test]
#[allow(clippy::cognitive_complexity)]
fn params_from_json_with_stake_params() {
let s = r#"{
"maxExtraDataSize": "0x20",
Expand Down Expand Up @@ -346,7 +344,6 @@ mod tests {
}

#[test]
#[allow(clippy::cognitive_complexity)]
fn params_from_json_with_era() {
let s = r#"{
"maxExtraDataSize": "0x20",
Expand Down