Skip to content

Commit

Permalink
Brush up main crate (exonum#1724)
Browse files Browse the repository at this point in the history
  • Loading branch information
slowli authored and Oleksandr Anyshchenko committed Jan 23, 2020
1 parent 8f288bd commit a7645d0
Show file tree
Hide file tree
Showing 47 changed files with 514 additions and 513 deletions.
2 changes: 1 addition & 1 deletion cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use exonum::{
blockchain::{ConsensusConfig, ValidatorKeys},
exonum_merkledb::DbOptions,
keys::{read_keys_from_file, Keys},
merkledb::DbOptions,
};
use exonum_node::{
ConnectListConfig, MemoryPoolConfig, NetworkConfiguration, NodeApiConfig,
Expand Down
2 changes: 1 addition & 1 deletion cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub use structopt;

use exonum::{
blockchain::{config::GenesisConfigBuilder, config::InstanceInitParams},
exonum_merkledb::RocksDB,
merkledb::RocksDB,
runtime::{RuntimeInstance, WellKnownRuntime},
};
use exonum_explorer_service::ExplorerFactory;
Expand Down
4 changes: 1 addition & 3 deletions components/explorer/examples/explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,7 @@ fn main() {
// Determine the number of blocks proposed by a specific validator
let block_count = explorer
.blocks(Height(1)..) // skip genesis block
.filter(|block| {
block.header().get_header::<ProposerId>().unwrap().unwrap() == ValidatorId(0).into()
})
.filter(|block| block.header().get_header::<ProposerId>().unwrap() == Some(ValidatorId(0)))
.count();
assert_eq!(block_count, 1);
}
2 changes: 1 addition & 1 deletion components/explorer/tests/blockchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub fn create_block(blockchain: &mut BlockchainMut, transactions: Vec<Verified<A

let mut tx_cache = BTreeMap::new();
let (block_hash, patch) =
blockchain.create_patch(ValidatorId(0).into(), height, &tx_hashes, &mut tx_cache);
blockchain.create_patch(ValidatorId(0), height, &tx_hashes, &mut tx_cache);
let (consensus_public_key, consensus_secret_key) = consensus_keys();

let precommit = Verified::from_value(
Expand Down
14 changes: 5 additions & 9 deletions exonum-node/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use exonum::{
blockchain::{contains_transaction, Blockchain, BlockchainMut, ProposerId, Schema},
crypto::{Hash, PublicKey},
helpers::{Height, Round},
helpers::{Height, Round, ValidatorId},
merkledb::{BinaryValue, Fork, ObjectHash, Patch},
messages::{AnyTx, Precommit, SignedMessage, Verified},
};
Expand Down Expand Up @@ -1013,7 +1013,7 @@ impl NodeHandler {
/// Creates block with given transaction and returns its hash and corresponding changes.
fn create_block(
&mut self,
proposer_id: ProposerId,
proposer_id: ValidatorId,
height: Height,
tx_hashes: &[Hash],
) -> (Hash, Patch) {
Expand Down Expand Up @@ -1041,17 +1041,13 @@ impl NodeHandler {
.into_payload();

let (block_hash, patch) = self.create_block(
propose.validator.into(),
propose.validator,
propose.height,
propose.transactions.as_slice(),
);
// Save patch
self.state.add_block(
block_hash,
patch,
propose.transactions,
propose.validator.into(),
);
self.state
.add_block(block_hash, patch, propose.transactions, propose.validator);
self.state
.propose_mut(propose_hash)
.unwrap()
Expand Down
2 changes: 1 addition & 1 deletion exonum-node/src/sandbox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ impl Sandbox {
blockchain.merge(fork.into_patch()).unwrap();

let (_, patch) =
blockchain.create_patch(ValidatorId(0).into(), height, &hashes, &mut BTreeMap::new());
blockchain.create_patch(ValidatorId(0), height, &hashes, &mut BTreeMap::new());

let fork = blockchain.fork();
let mut schema = Schema::new(&fork);
Expand Down
2 changes: 1 addition & 1 deletion exonum-node/src/sandbox/sandbox_tests_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<'a> BlockBuilder<'a> {
.unwrap_or_else(|| self.sandbox.current_leader());

let mut additional_headers = self.entries.clone().unwrap_or_else(AdditionalHeaders::new);
additional_headers.insert::<ProposerId>(proposer_id.into());
additional_headers.insert::<ProposerId>(proposer_id);

Block {
height: self.height.unwrap_or_else(|| self.sandbox.current_height()),
Expand Down
2 changes: 1 addition & 1 deletion exonum-node/src/sandbox/tests/old.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn create_propose(sandbox: &Sandbox) -> Verified<Propose> {

fn create_block(sandbox: &Sandbox) -> Block {
let mut additional_headers = AdditionalHeaders::new();
additional_headers.insert::<ProposerId>(ValidatorId(2).into());
additional_headers.insert::<ProposerId>(ValidatorId(2));

Block {
height: Height(1),
Expand Down
2 changes: 1 addition & 1 deletion exonum-node/src/sandbox/tests/round_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,7 @@ fn handle_precommit_positive_scenario_commit_with_queued_precommit() {
// Precommits with this block will be received during get 1st height in
// fn add_one_height_with_transaction()
let mut first_block = sandbox.create_block(&[tx.clone()]);
first_block.add_header::<ProposerId>(ValidatorId(0).into());
first_block.add_header::<ProposerId>(ValidatorId(0));

// this propose will be used during second commit
let height_one_propose = ProposeBuilder::new(&sandbox)
Expand Down
2 changes: 1 addition & 1 deletion exonum-node/src/sandbox/tests/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ fn tx_pool_size_overflow() {
);

let mut block = sandbox.create_block(&[tx1.clone()]);
block.add_header::<ProposerId>(ValidatorId(2).into());
block.add_header::<ProposerId>(ValidatorId(2));
block.height = Height(1);

sandbox.recv(&propose);
Expand Down
2 changes: 1 addition & 1 deletion exonum-node/src/sandbox/tests/unsynchronized_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fn test_queue_propose_message_from_next_height() {
let sandbox_state = SandboxState::new();
let tx = gen_timestamping_tx();
let mut block_at_first_height = sandbox.create_block(&[tx.clone()]);
block_at_first_height.add_header::<ProposerId>(ValidatorId(0).into());
block_at_first_height.add_header::<ProposerId>(ValidatorId(0));

let future_propose = sandbox.create_propose(
ValidatorId(0),
Expand Down
8 changes: 4 additions & 4 deletions exonum-node/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use bit_vec::BitVec;
use exonum::{
blockchain::{contains_transaction, ConsensusConfig, ProposerId, ValidatorKeys},
blockchain::{contains_transaction, ConsensusConfig, ValidatorKeys},
crypto::{Hash, PublicKey},
helpers::{byzantine_quorum, Height, Milliseconds, Round, ValidatorId},
keys::Keys,
Expand Down Expand Up @@ -161,7 +161,7 @@ pub struct BlockState {
// Changes that should be made for block committing.
patch: Option<Patch>,
txs: Vec<Hash>,
proposer_id: ProposerId,
proposer_id: ValidatorId,
}

/// Incomplete block.
Expand Down Expand Up @@ -363,7 +363,7 @@ impl BlockState {
}

/// Returns id of the validator that proposed the block.
pub fn proposer_id(&self) -> ProposerId {
pub fn proposer_id(&self) -> ValidatorId {
self.proposer_id
}
}
Expand Down Expand Up @@ -1023,7 +1023,7 @@ impl State {
block_hash: Hash,
patch: Patch,
txs: Vec<Hash>,
proposer_id: ProposerId,
proposer_id: ValidatorId,
) -> Option<&BlockState> {
match self.blocks.entry(block_hash) {
Entry::Occupied(..) => None,
Expand Down
18 changes: 11 additions & 7 deletions exonum/src/blockchain/api_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use std::fmt;

use crate::messages::{AnyTx, Verified};

/// Transactions sender.
/// Asynchronous sender of messages (transactions by default). The receiver of messages is
/// usually an Exonum node, which then processes them with the consensus algorithm.
pub struct ApiSender<T = Verified<AnyTx>>(mpsc::Sender<T>);

impl<T> Clone for ApiSender<T> {
Expand All @@ -29,17 +30,17 @@ impl<T> Clone for ApiSender<T> {
}

impl<T: Send + 'static> ApiSender<T> {
/// Creates new `ApiSender` with given channel.
/// Creates new `ApiSender` with the given channel.
pub fn new(inner: mpsc::Sender<T>) -> Self {
ApiSender(inner)
}

/// Creates a dummy sender which is not connected to the node and thus cannot send messages.
/// Creates a dummy sender which is not connected to anything and thus cannot send messages.
pub fn closed() -> Self {
ApiSender(mpsc::channel(0).0)
}

/// Sends an arbitrary `ExternalMessage` to the node.
/// Sends a message to the node.
///
/// # Return value
///
Expand All @@ -54,8 +55,11 @@ impl<T: Send + 'static> ApiSender<T> {
}

impl ApiSender {
/// Broadcasts transaction to other nodes in the blockchain network. This is an asynchronous
/// operation that can take some time if the node is overloaded with requests.
/// Sends a transaction over the channel. If this sender is connected to a node,
/// this will broadcast the transaction to all nodes in the blockchain network.
///
/// This is an asynchronous operation that can take some time if the node is overloaded
/// with requests.
///
/// # Return value
///
Expand All @@ -74,7 +78,7 @@ impl<T> fmt::Debug for ApiSender<T> {
}
}

/// Errors that can occur during sending a message to the node via `ApiSender` or `ShutdownHandle`.
/// Errors that can occur during sending a message to the node via `ApiSender`.
#[derive(Debug, Fail)]
#[fail(display = "Failed to send API request to the node: the node is being shut down")]
pub struct SendError(());
Loading

0 comments on commit a7645d0

Please sign in to comment.