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

Commit 17c3a3b

Browse files
committed
Merge branch 'master' into dp/chore/remove-rust-crypto-from-devp2p
* master: updater: fix static id hashes initialization (#10755) Use fewer threads for snapshotting (#10752) Die error_chain, die (#10747) Fix deprectation warnings on nightly (#10746) fix docker tags for publishing (#10741) DevP2p: Get node IP address and udp port from Socket, if not included in PING packet (#10705) ethcore: enable ECIP-1054 for classic (#10731) Stop breaking out of loop if a non-canonical hash is found (#10729) Refactor Clique stepping (#10691) Use RUSTFLAGS to set the optimization level (#10719) SecretStore: non-blocking wait of session completion (#10303) removed secret_store folder (#10722) SecretStore: expose restore_key_public in HTTP API (#10241) Revert "enable lto for release builds (#10717)" (#10721) enable lto for release builds (#10717) Merge `Notifier` and `TransactionsPoolNotifier` (#10591)
2 parents 0ae675b + 35c607f commit 17c3a3b

File tree

123 files changed

+2296
-2475
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+2296
-2475
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,9 @@ path = "parity/lib.rs"
117117
path = "parity/main.rs"
118118
name = "parity"
119119

120-
[profile.dev]
121-
122120
[profile.release]
123121
debug = false
122+
lto = true
124123

125124
[workspace]
126125
# This should only list projects that are not

ethcore/benches/builtin.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use criterion::{Criterion, Bencher};
2929
use bytes::BytesRef;
3030
use ethcore::builtin::Builtin;
3131
use ethcore::machine::EthereumMachine;
32-
use ethereum_types::U256;
32+
use ethereum_types::H160;
3333
use ethcore::ethereum::new_byzantium_test_machine;
3434
use rustc_hex::FromHex;
3535

@@ -46,8 +46,9 @@ struct BuiltinBenchmark<'a> {
4646
impl<'a> BuiltinBenchmark<'a> {
4747
fn new(builtin_address: &'static str, input: &str, expected: &str) -> BuiltinBenchmark<'a> {
4848
let builtins = BYZANTIUM_MACHINE.builtins();
49-
50-
let builtin = builtins.get(&builtin_address.into()).unwrap().clone();
49+
use std::str::FromStr;
50+
let addr = H160::from_str(builtin_address).unwrap();
51+
let builtin = builtins.get(&addr).unwrap().clone();
5152
let input = FromHex::from_hex(input).unwrap();
5253
let expected = FromHex::from_hex(expected).unwrap();
5354

@@ -56,10 +57,6 @@ impl<'a> BuiltinBenchmark<'a> {
5657
}
5758
}
5859

59-
fn gas_cost(&self) -> U256 {
60-
self.builtin.cost(&self.input)
61-
}
62-
6360
fn run(&self, b: &mut Bencher) {
6461
let mut output = vec![0; self.expected.len()];
6562

ethcore/blockchain/src/blockchain.rs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use crate::{CacheSize, ImportRoute, Config};
5757
/// Database backing `BlockChain`.
5858
pub trait BlockChainDB: Send + Sync {
5959
/// Generic key value store.
60-
fn key_value(&self) -> &Arc<KeyValueDB>;
60+
fn key_value(&self) -> &Arc<dyn KeyValueDB>;
6161

6262
/// Header blooms database.
6363
fn blooms(&self) -> &blooms_db::Database;
@@ -85,7 +85,7 @@ pub trait BlockChainDB: Send + Sync {
8585
/// predefined config.
8686
pub trait BlockChainDBHandler: Send + Sync {
8787
/// Open the predefined key-value database.
88-
fn open(&self, path: &Path) -> io::Result<Arc<BlockChainDB>>;
88+
fn open(&self, path: &Path) -> io::Result<Arc<dyn BlockChainDB>>;
8989
}
9090

9191
/// Interface for querying blocks by hash and by number.
@@ -228,7 +228,7 @@ pub struct BlockChain {
228228
transaction_addresses: RwLock<HashMap<H256, TransactionAddress>>,
229229
block_receipts: RwLock<HashMap<H256, BlockReceipts>>,
230230

231-
db: Arc<BlockChainDB>,
231+
db: Arc<dyn BlockChainDB>,
232232

233233
cache_man: Mutex<CacheManager<CacheId>>,
234234

@@ -481,7 +481,7 @@ impl<'a> Iterator for AncestryWithMetadataIter<'a> {
481481
/// Returns epoch transitions.
482482
pub struct EpochTransitionIter<'a> {
483483
chain: &'a BlockChain,
484-
prefix_iter: Box<Iterator<Item=(Box<[u8]>, Box<[u8]>)> + 'a>,
484+
prefix_iter: Box<dyn Iterator<Item=(Box<[u8]>, Box<[u8]>)> + 'a>,
485485
}
486486

487487
impl<'a> Iterator for EpochTransitionIter<'a> {
@@ -521,7 +521,7 @@ impl<'a> Iterator for EpochTransitionIter<'a> {
521521

522522
impl BlockChain {
523523
/// Create new instance of blockchain from given Genesis.
524-
pub fn new(config: Config, genesis: &[u8], db: Arc<BlockChainDB>) -> BlockChain {
524+
pub fn new(config: Config, genesis: &[u8], db: Arc<dyn BlockChainDB>) -> BlockChain {
525525
// 400 is the average size of the key
526526
let cache_man = CacheManager::new(config.pref_cache_size, config.max_cache_size, 400);
527527

@@ -963,6 +963,7 @@ impl BlockChain {
963963
/// Iterate over all epoch transitions.
964964
/// This will only return transitions within the canonical chain.
965965
pub fn epoch_transitions(&self) -> EpochTransitionIter {
966+
trace!(target: "blockchain", "Iterating over all epoch transitions");
966967
let iter = self.db.key_value().iter_from_prefix(db::COL_EXTRA, &EPOCH_KEY_PREFIX[..]);
967968
EpochTransitionIter {
968969
chain: self,
@@ -988,7 +989,9 @@ impl BlockChain {
988989
pub fn epoch_transition_for(&self, parent_hash: H256) -> Option<EpochTransition> {
989990
// slow path: loop back block by block
990991
for hash in self.ancestry_iter(parent_hash)? {
992+
trace!(target: "blockchain", "Got parent hash {} from ancestry_iter", hash);
991993
let details = self.block_details(&hash)?;
994+
trace!(target: "blockchain", "Block #{}: Got block details", details.number);
992995

993996
// look for transition in database.
994997
if let Some(transition) = self.epoch_transition(details.number, hash) {
@@ -1000,11 +1003,22 @@ impl BlockChain {
10001003
//
10011004
// if `block_hash` is canonical it will only return transitions up to
10021005
// the parent.
1003-
if self.block_hash(details.number)? == hash {
1004-
return self.epoch_transitions()
1005-
.map(|(_, t)| t)
1006-
.take_while(|t| t.block_number <= details.number)
1007-
.last()
1006+
match self.block_hash(details.number) {
1007+
Some(h) if h == hash => {
1008+
return self.epoch_transitions()
1009+
.map(|(_, t)| t)
1010+
.take_while(|t| t.block_number <= details.number)
1011+
.last()
1012+
},
1013+
Some(h) => {
1014+
warn!(target: "blockchain", "Block #{}: Found non-canonical block hash {} (expected {})", details.number, h, hash);
1015+
1016+
trace!(target: "blockchain", "Block #{} Mismatched hashes. Ancestor {} != Own {} – Own block #{}", details.number, hash, h, self.block_number(&h).unwrap_or_default() );
1017+
trace!(target: "blockchain", " Ancestor {}: #{:#?}", hash, self.block_details(&hash));
1018+
trace!(target: "blockchain", " Own {}: #{:#?}", h, self.block_details(&h));
1019+
1020+
},
1021+
None => trace!(target: "blockchain", "Block #{}: hash {} not found in cache or DB", details.number, hash),
10081022
}
10091023
}
10101024

@@ -1578,11 +1592,11 @@ mod tests {
15781592
_trace_blooms_dir: TempDir,
15791593
blooms: blooms_db::Database,
15801594
trace_blooms: blooms_db::Database,
1581-
key_value: Arc<KeyValueDB>,
1595+
key_value: Arc<dyn KeyValueDB>,
15821596
}
15831597

15841598
impl BlockChainDB for TestBlockChainDB {
1585-
fn key_value(&self) -> &Arc<KeyValueDB> {
1599+
fn key_value(&self) -> &Arc<dyn KeyValueDB> {
15861600
&self.key_value
15871601
}
15881602

@@ -1596,7 +1610,7 @@ mod tests {
15961610
}
15971611

15981612
/// Creates new test instance of `BlockChainDB`
1599-
pub fn new_db() -> Arc<BlockChainDB> {
1613+
pub fn new_db() -> Arc<dyn BlockChainDB> {
16001614
let blooms_dir = TempDir::new("").unwrap();
16011615
let trace_blooms_dir = TempDir::new("").unwrap();
16021616

@@ -1611,15 +1625,15 @@ mod tests {
16111625
Arc::new(db)
16121626
}
16131627

1614-
fn new_chain(genesis: encoded::Block, db: Arc<BlockChainDB>) -> BlockChain {
1628+
fn new_chain(genesis: encoded::Block, db: Arc<dyn BlockChainDB>) -> BlockChain {
16151629
BlockChain::new(Config::default(), genesis.raw(), db)
16161630
}
16171631

1618-
fn insert_block(db: &Arc<BlockChainDB>, bc: &BlockChain, block: encoded::Block, receipts: Vec<Receipt>) -> ImportRoute {
1632+
fn insert_block(db: &Arc<dyn BlockChainDB>, bc: &BlockChain, block: encoded::Block, receipts: Vec<Receipt>) -> ImportRoute {
16191633
insert_block_commit(db, bc, block, receipts, true)
16201634
}
16211635

1622-
fn insert_block_commit(db: &Arc<BlockChainDB>, bc: &BlockChain, block: encoded::Block, receipts: Vec<Receipt>, commit: bool) -> ImportRoute {
1636+
fn insert_block_commit(db: &Arc<dyn BlockChainDB>, bc: &BlockChain, block: encoded::Block, receipts: Vec<Receipt>, commit: bool) -> ImportRoute {
16231637
let mut batch = db.key_value().transaction();
16241638
let res = insert_block_batch(&mut batch, bc, block, receipts);
16251639
db.key_value().write(batch).unwrap();

ethcore/light/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ authors = ["Parity Technologies <[email protected]>"]
1010
log = "0.4"
1111
parity-bytes = "0.1"
1212
common-types = { path = "../types" }
13+
derive_more = "0.14.0"
1314
ethcore = { path = ".."}
1415
ethcore-db = { path = "../db" }
1516
ethcore-blockchain = { path = "../blockchain" }

ethcore/light/src/client/header_chain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ impl HeaderChain {
260260
let best_block = {
261261
let era = match candidates.get(&curr.best_num) {
262262
Some(era) => era,
263-
None => bail!("Database corrupt: highest block referenced but no data."),
263+
None => return Err("Database corrupt: highest block referenced but no data.".into()),
264264
};
265265

266266
let best = &era.candidates[0];
@@ -582,7 +582,7 @@ impl HeaderChain {
582582
} else {
583583
let msg = format!("header of block #{} not found in DB ; database in an \
584584
inconsistent state", h_num);
585-
bail!(msg);
585+
return Err(msg.into());
586586
};
587587

588588
let decoded = header.decode().expect("decoding db value failed");

ethcore/light/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ extern crate keccak_hash as hash;
8686
extern crate triehash_ethereum as triehash;
8787
extern crate kvdb;
8888
extern crate memory_cache;
89-
#[macro_use]
90-
extern crate error_chain;
89+
extern crate derive_more;
9190

9291
#[cfg(test)]
9392
extern crate kvdb_memorydb;

ethcore/light/src/on_demand/mod.rs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,32 +66,31 @@ pub const DEFAULT_NUM_CONSECUTIVE_FAILED_REQUESTS: usize = 1;
6666

6767
/// OnDemand related errors
6868
pub mod error {
69-
// Silence: `use of deprecated item 'std::error::Error::cause': replaced by Error::source, which can support downcasting`
70-
// https://github.com/paritytech/parity-ethereum/issues/10302
71-
#![allow(deprecated)]
72-
7369
use futures::sync::oneshot::Canceled;
7470

75-
error_chain! {
76-
77-
foreign_links {
78-
ChannelCanceled(Canceled) #[doc = "Canceled oneshot channel"];
79-
}
80-
81-
errors {
82-
#[doc = "Timeout bad response"]
83-
BadResponse(err: String) {
84-
description("Max response evaluation time exceeded")
85-
display("{}", err)
86-
}
71+
/// OnDemand Error
72+
#[derive(Debug, derive_more::Display, derive_more::From)]
73+
pub enum Error {
74+
/// Canceled oneshot channel
75+
ChannelCanceled(Canceled),
76+
/// Timeout bad response
77+
BadResponse(String),
78+
/// OnDemand requests limit exceeded
79+
#[display(fmt = "OnDemand request maximum backoff iterations exceeded")]
80+
RequestLimit,
81+
}
8782

88-
#[doc = "OnDemand requests limit exceeded"]
89-
RequestLimit {
90-
description("OnDemand request maximum backoff iterations exceeded")
91-
display("OnDemand request maximum backoff iterations exceeded")
83+
impl std::error::Error for Error {
84+
fn source(&self) -> Option<&(std::error::Error + 'static)> {
85+
match self {
86+
Error::ChannelCanceled(err) => Some(err),
87+
_ => None,
9288
}
9389
}
9490
}
91+
92+
/// OnDemand Result
93+
pub type Result<T> = std::result::Result<T, Error>;
9594
}
9695

9796
/// Public interface for performing network requests `OnDemand`
@@ -272,15 +271,15 @@ impl Pending {
272271
response_err
273272
);
274273

275-
let err = self::error::ErrorKind::BadResponse(err);
274+
let err = self::error::Error::BadResponse(err);
276275
if self.sender.send(Err(err.into())).is_err() {
277276
debug!(target: "on_demand", "Dropped oneshot channel receiver on no response");
278277
}
279278
}
280279

281280
// returning a peer discovery timeout during query attempts
282281
fn request_limit_reached(self) {
283-
let err = self::error::ErrorKind::RequestLimit;
282+
let err = self::error::Error::RequestLimit;
284283
if self.sender.send(Err(err.into())).is_err() {
285284
debug!(target: "on_demand", "Dropped oneshot channel receiver on time out");
286285
}

ethcore/light/src/transaction_queue.rs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,23 +129,22 @@ pub enum ImportDestination {
129129
Future,
130130
}
131131

132-
type Listener = Box<Fn(&[H256]) + Send + Sync>;
133-
134132
/// Light transaction queue. See module docs for more details.
135133
#[derive(Default)]
136134
pub struct TransactionQueue {
137135
by_account: HashMap<Address, AccountTransactions>,
138136
by_hash: H256FastMap<PendingTransaction>,
139-
listeners: Vec<Listener>,
140-
tx_statuses_listeners: Vec<mpsc::UnboundedSender<Arc<Vec<(H256, TxStatus)>>>>,
137+
pending_listeners: Vec<mpsc::UnboundedSender<Arc<Vec<H256>>>>,
138+
full_listeners: Vec<mpsc::UnboundedSender<Arc<Vec<(H256, TxStatus)>>>>,
141139
}
142140

143141
impl fmt::Debug for TransactionQueue {
144142
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
145143
fmt.debug_struct("TransactionQueue")
146144
.field("by_account", &self.by_account)
147145
.field("by_hash", &self.by_hash)
148-
.field("listeners", &self.listeners.len())
146+
.field("pending_listeners", &self.pending_listeners.len())
147+
.field("full_listeners", &self.pending_listeners.len())
149148
.finish()
150149
}
151150
}
@@ -360,30 +359,40 @@ impl TransactionQueue {
360359
}
361360

362361
/// Add a transaction queue listener.
363-
pub fn add_listener(&mut self, f: Listener) {
364-
self.listeners.push(f);
362+
pub fn pending_transactions_receiver(&mut self) -> mpsc::UnboundedReceiver<Arc<Vec<H256>>> {
363+
let (sender, receiver) = mpsc::unbounded();
364+
self.pending_listeners.push(sender);
365+
receiver
365366
}
366367

367368
/// Add a transaction queue listener.
368-
pub fn tx_statuses_receiver(&mut self) -> mpsc::UnboundedReceiver<Arc<Vec<(H256, TxStatus)>>> {
369+
pub fn full_transactions_receiver(&mut self) -> mpsc::UnboundedReceiver<Arc<Vec<(H256, TxStatus)>>> {
369370
let (sender, receiver) = mpsc::unbounded();
370-
self.tx_statuses_listeners.push(sender);
371+
self.full_listeners.push(sender);
371372
receiver
372373
}
373374

374375
/// Notifies all listeners about new pending transaction.
375376
fn notify(&mut self, hashes: &[H256], status: TxStatus) {
376-
for listener in &self.listeners {
377-
listener(hashes)
377+
if status == TxStatus::Added {
378+
let to_pending_send: Arc<Vec<H256>> = Arc::new(
379+
hashes
380+
.into_iter()
381+
.map(|hash| hash.clone())
382+
.collect()
383+
);
384+
self.pending_listeners.retain(|listener| listener.unbounded_send(to_pending_send.clone()).is_ok());
385+
378386
}
379387

380-
let to_send: Arc<Vec<(H256, TxStatus)>> = Arc::new(
388+
let to_full_send: Arc<Vec<(H256, TxStatus)>> = Arc::new(
381389
hashes
382390
.into_iter()
383-
.map(|hash| (hash.clone(), status)).collect()
391+
.map(|hash| (hash.clone(), status))
392+
.collect()
384393
);
385394

386-
self.tx_statuses_listeners.retain(| listener| listener.unbounded_send(to_send.clone()).is_ok());
395+
self.full_listeners.retain(|listener| listener.unbounded_send(to_full_send.clone()).is_ok());
387396
}
388397
}
389398

ethcore/private-tx/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616

1717
//! Private transactions module.
1818
19-
// Recursion limit required because of
20-
// error_chain foreign_links.
21-
#![recursion_limit="256"]
22-
2319
mod encryptor;
2420
mod key_server_keys;
2521
mod private_transactions;

0 commit comments

Comments
 (0)