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

Fix slow balances #6471

Merged
merged 40 commits into from
Sep 10, 2017
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
4ac0a11
Update token updates
ngotchac Aug 28, 2017
a52399b
Update token info fetching
ngotchac Aug 29, 2017
2b81b98
Update logger
ngotchac Aug 29, 2017
5294ef3
Minor fixes to updates and notifications for balances
ngotchac Aug 29, 2017
7e7b86e
Use Pubsub
tomusdrw Aug 29, 2017
093cf4d
Merge branch 'ng-update-token-updates' of github.com:paritytech/parit…
tomusdrw Aug 29, 2017
0132793
Merge branch 'master' into ng-update-token-updates
ngotchac Aug 30, 2017
7a0e821
Fix timeout.
tomusdrw Aug 30, 2017
0578866
Use pubsub for status.
tomusdrw Aug 30, 2017
e67d25b
Fix signer subscription.
tomusdrw Aug 30, 2017
910c548
Process tokens in chunks.
tomusdrw Aug 30, 2017
4efff64
Fix tokens loaded by chunks
ngotchac Aug 31, 2017
c6319e3
Linting
ngotchac Aug 31, 2017
6125e46
Dispatch tokens asap
ngotchac Aug 31, 2017
89211c2
Fix chunks processing.
tomusdrw Aug 31, 2017
cc5a219
Merge branch 'ng-update-token-updates' of github.com:paritytech/parit…
tomusdrw Aug 31, 2017
0859435
Better filter options
ngotchac Sep 1, 2017
670e725
Parallel log fetching.
tomusdrw Sep 1, 2017
c34379a
Merge branch 'master' into ng-update-token-updates
tomusdrw Sep 1, 2017
620462d
Fix signer polling.
tomusdrw Sep 1, 2017
6c1b842
Fix initial block query.
tomusdrw Sep 1, 2017
27387e7
Merge branch 'ng-update-token-updates' of github.com:paritytech/parit…
ngotchac Sep 1, 2017
3904e6e
Token balances updates : the right(er) way
ngotchac Sep 5, 2017
976e9f5
Better tokens info fetching
ngotchac Sep 5, 2017
c17bb50
Fixes in token data fetching
ngotchac Sep 5, 2017
2f41a90
Only fetch what's needed (tokens)
ngotchac Sep 5, 2017
ca4bea1
Fix linting issues
ngotchac Sep 5, 2017
8f96415
Revert "Transaction permissioning (#6441)"
tomusdrw Sep 5, 2017
bdc69bc
Merge branch 'master' into ng-update-token-updates
tomusdrw Sep 5, 2017
abdb8c7
Revert "Revert "Transaction permissioning (#6441)""
tomusdrw Sep 6, 2017
526aa06
Update wasm-tests.
tomusdrw Sep 6, 2017
60bbb2d
Merge branch 'master' into ng-update-token-updates
ngotchac Sep 6, 2017
b7b299d
Merge branch 'ng-update-token-updates' of github.com:paritytech/parit…
ngotchac Sep 6, 2017
6403b09
Fixing balances fetching
ngotchac Sep 6, 2017
60e1f0f
Fix requests tracking in UI
ngotchac Sep 6, 2017
7ddbc6c
Fix request watching
ngotchac Sep 6, 2017
b91df86
Update the Logger
ngotchac Sep 7, 2017
6cbf481
PR Grumbles Fixes
ngotchac Sep 7, 2017
74c6ac6
PR Grumbles fixes
ngotchac Sep 7, 2017
6c30927
Linting...
ngotchac Sep 7, 2017
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
52 changes: 35 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ethcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ num = "0.1"
num_cpus = "1.2"
parking_lot = "0.4"
price-info = { path = "../price-info" }
rayon = "0.8"
rand = "0.3"
rlp = { path = "../util/rlp" }
rlp_derive = { path = "../util/rlp_derive" }
Expand Down
83 changes: 45 additions & 38 deletions ethcore/src/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use db::{self, Writable, Readable, CacheUpdatePolicy};
use cache_manager::CacheManager;
use encoded;
use engines::epoch::{Transition as EpochTransition, PendingTransition as PendingEpochTransition};
use rayon::prelude::*;
use ansi_term::Colour;

const LOG_BLOOMS_LEVELS: usize = 3;
Expand Down Expand Up @@ -152,7 +153,7 @@ pub trait BlockProvider {

/// Returns logs matching given filter.
fn logs<F>(&self, blocks: Vec<BlockNumber>, matches: F, limit: Option<usize>) -> Vec<LocalizedLogEntry>
where F: Fn(&LogEntry) -> bool, Self: Sized;
where F: Fn(&LogEntry) -> bool + Send + Sync, Self: Sized;
}

macro_rules! otry {
Expand Down Expand Up @@ -363,50 +364,56 @@ impl BlockProvider for BlockChain {
}

fn logs<F>(&self, mut blocks: Vec<BlockNumber>, matches: F, limit: Option<usize>) -> Vec<LocalizedLogEntry>
where F: Fn(&LogEntry) -> bool, Self: Sized {
where F: Fn(&LogEntry) -> bool + Send + Sync, Self: Sized {
// sort in reverse order
blocks.sort_by(|a, b| b.cmp(a));

let mut log_index = 0;
let mut logs = blocks.into_iter()
.filter_map(|number| self.block_hash(number).map(|hash| (number, hash)))
.filter_map(|(number, hash)| self.block_receipts(&hash).map(|r| (number, hash, r.receipts)))
.filter_map(|(number, hash, receipts)| self.block_body(&hash).map(|ref b| (number, hash, receipts, b.transaction_hashes())))
.flat_map(|(number, hash, mut receipts, mut hashes)| {
if receipts.len() != hashes.len() {
warn!("Block {} ({}) has different number of receipts ({}) to transactions ({}). Database corrupt?", number, hash, receipts.len(), hashes.len());
assert!(false);
}
log_index = receipts.iter().fold(0, |sum, receipt| sum + receipt.logs.len());

let receipts_len = receipts.len();
hashes.reverse();
receipts.reverse();
receipts.into_iter()
.map(|receipt| receipt.logs)
.zip(hashes)
.enumerate()
.flat_map(move |(index, (mut logs, tx_hash))| {
let current_log_index = log_index;
let no_of_logs = logs.len();
log_index -= no_of_logs;

logs.reverse();
logs.into_iter()
let mut logs = blocks
.chunks(128)
.flat_map(move |blocks_chunk| {
blocks_chunk.into_par_iter()
.filter_map(|number| self.block_hash(*number).map(|hash| (*number, hash)))
.filter_map(|(number, hash)| self.block_receipts(&hash).map(|r| (number, hash, r.receipts)))
.filter_map(|(number, hash, receipts)| self.block_body(&hash).map(|ref b| (number, hash, receipts, b.transaction_hashes())))
.flat_map(|(number, hash, mut receipts, mut hashes)| {
if receipts.len() != hashes.len() {
warn!("Block {} ({}) has different number of receipts ({}) to transactions ({}). Database corrupt?", number, hash, receipts.len(), hashes.len());
assert!(false);
}
let mut log_index = receipts.iter().fold(0, |sum, receipt| sum + receipt.logs.len());

let receipts_len = receipts.len();
hashes.reverse();
receipts.reverse();
receipts.into_iter()
.map(|receipt| receipt.logs)
.zip(hashes)
.enumerate()
.map(move |(i, log)| LocalizedLogEntry {
entry: log,
block_hash: hash,
block_number: number,
transaction_hash: tx_hash,
// iterating in reverse order
transaction_index: receipts_len - index - 1,
transaction_log_index: no_of_logs - i - 1,
log_index: current_log_index - i - 1,
.flat_map(move |(index, (mut logs, tx_hash))| {
let current_log_index = log_index;
let no_of_logs = logs.len();
log_index -= no_of_logs;

logs.reverse();
logs.into_iter()
.enumerate()
.map(move |(i, log)| LocalizedLogEntry {
entry: log,
block_hash: hash,
block_number: number,
transaction_hash: tx_hash,
// iterating in reverse order
transaction_index: receipts_len - index - 1,
transaction_log_index: no_of_logs - i - 1,
log_index: current_log_index - i - 1,
})
})
.filter(|log_entry| matches(&log_entry.entry))
.take(limit.unwrap_or(::std::usize::MAX))
.collect::<Vec<_>>()
})
.collect::<Vec<_>>()
})
.filter(|log_entry| matches(&log_entry.entry))
.take(limit.unwrap_or(::std::usize::MAX))
.collect::<Vec<LocalizedLogEntry>>();
logs.reverse();
Expand Down
37 changes: 21 additions & 16 deletions ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ impl Client {
_ => {},
}

let block_number = match self.block_number(id.clone()) {
let block_number = match self.block_number(id) {
Some(num) => num,
None => return None,
};
Expand Down Expand Up @@ -1155,6 +1155,16 @@ impl Client {
(false, false) => call(state, env_info, engine, state_diff, t, TransactOptions::with_no_tracing()),
}
}

fn block_number_ref(&self, id: &BlockId) -> Option<BlockNumber> {
match *id {
BlockId::Number(number) => Some(number),
BlockId::Hash(ref hash) => self.chain.read().block_number(hash),
BlockId::Earliest => Some(0),
BlockId::Latest => Some(self.chain.read().best_block_number()),
BlockId::Pending => Some(self.chain.read().best_block_number() + 1),
}
}
}

impl snapshot::DatabaseRestore for Client {
Expand Down Expand Up @@ -1364,13 +1374,7 @@ impl BlockChainClient for Client {
}

fn block_number(&self, id: BlockId) -> Option<BlockNumber> {
match id {
BlockId::Number(number) => Some(number),
BlockId::Hash(ref hash) => self.chain.read().block_number(hash),
BlockId::Earliest => Some(0),
BlockId::Latest => Some(self.chain.read().best_block_number()),
BlockId::Pending => Some(self.chain.read().best_block_number() + 1),
}
self.block_number_ref(&id)
}

fn block_body(&self, id: BlockId) -> Option<encoded::Body> {
Expand Down Expand Up @@ -1651,16 +1655,17 @@ impl BlockChainClient for Client {
self.engine.additional_params().into_iter().collect()
}

fn blocks_with_bloom(&self, bloom: &H2048, from_block: BlockId, to_block: BlockId) -> Option<Vec<BlockNumber>> {
match (self.block_number(from_block), self.block_number(to_block)) {
(Some(from), Some(to)) => Some(self.chain.read().blocks_with_bloom(bloom, from, to)),
_ => None
}
}

fn logs(&self, filter: Filter) -> Vec<LocalizedLogEntry> {
let (from, to) = match (self.block_number_ref(&filter.from_block), self.block_number_ref(&filter.to_block)) {
(Some(from), Some(to)) => (from, to),
_ => return Vec::new(),
};

let chain = self.chain.read();
let blocks = filter.bloom_possibilities().iter()
.filter_map(|bloom| self.blocks_with_bloom(bloom, filter.from_block.clone(), filter.to_block.clone()))
.map(move |bloom| {
chain.blocks_with_bloom(bloom, from, to)
})
.flat_map(|m| m)
// remove duplicate elements
.collect::<HashSet<u64>>()
Expand Down
6 changes: 1 addition & 5 deletions ethcore/src/client/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use itertools::Itertools;
use rustc_hex::FromHex;
use hash::keccak;
use bigint::prelude::U256;
use bigint::hash::{H256, H2048};
use bigint::hash::H256;
use parking_lot::RwLock;
use util::*;
use rlp::*;
Expand Down Expand Up @@ -508,10 +508,6 @@ impl BlockChainClient for TestBlockChainClient {
self.receipts.read().get(&id).cloned()
}

fn blocks_with_bloom(&self, _bloom: &H2048, _from_block: BlockId, _to_block: BlockId) -> Option<Vec<BlockNumber>> {
unimplemented!();
}

fn logs(&self, filter: Filter) -> Vec<LocalizedLogEntry> {
let mut logs = self.logs.read().clone();
let len = logs.len();
Expand Down
5 changes: 1 addition & 4 deletions ethcore/src/client/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use transaction::{LocalizedTransaction, PendingTransaction, SignedTransaction};
use verification::queue::QueueInfo as BlockQueueInfo;

use bigint::prelude::U256;
use bigint::hash::{H256, H2048};
use bigint::hash::H256;
use util::{Address, Bytes};
use util::hashdb::DBValue;

Expand Down Expand Up @@ -181,9 +181,6 @@ pub trait BlockChainClient : Sync + Send {
/// Get the best block header.
fn best_block_header(&self) -> encoded::Header;

/// Returns numbers of blocks containing given bloom.
fn blocks_with_bloom(&self, bloom: &H2048, from_block: BlockId, to_block: BlockId) -> Option<Vec<BlockNumber>>;

/// Returns logs matching given filter.
fn logs(&self, filter: Filter) -> Vec<LocalizedLogEntry>;

Expand Down
1 change: 1 addition & 0 deletions ethcore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ extern crate num;
extern crate parking_lot;
extern crate price_info;
extern crate rand;
extern crate rayon;
extern crate rlp;
extern crate hash;
extern crate heapsize;
Expand Down
5 changes: 2 additions & 3 deletions ethcore/src/verification/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,15 +392,14 @@ mod tests {
self.numbers.get(&index).cloned()
}

fn blocks_with_bloom(&self, _bloom: &H2048, _from_block: BlockNumber, _to_block: BlockNumber) -> Vec<BlockNumber> {
fn block_receipts(&self, _hash: &H256) -> Option<BlockReceipts> {
unimplemented!()
}

fn block_receipts(&self, _hash: &H256) -> Option<BlockReceipts> {
fn blocks_with_bloom(&self, _bloom: &H2048, _from_block: BlockNumber, _to_block: BlockNumber) -> Vec<BlockNumber> {
unimplemented!()
}


fn logs<F>(&self, _blocks: Vec<BlockNumber>, _matches: F, _limit: Option<usize>) -> Vec<LocalizedLogEntry>
where F: Fn(&LogEntry) -> bool, Self: Sized {
unimplemented!()
Expand Down
Loading