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

Client IPC Interface #1493

Merged
merged 38 commits into from
Jul 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
bfbcb8d
btree map serializer
NikVolf Jun 29, 2016
9aef8ba
serde tests
NikVolf Jun 29, 2016
3cca6c8
state diff serialization
NikVolf Jun 29, 2016
dec083a
basic layout
NikVolf Jun 29, 2016
562e591
more missing serializaers
NikVolf Jun 29, 2016
5337de8
uncle returns rlp
NikVolf Jun 29, 2016
f31ddec
block queue info
NikVolf Jun 29, 2016
a14f239
sorting with transaction result
NikVolf Jun 29, 2016
f6ec1ea
sorting out util imports
NikVolf Jun 29, 2016
d5be0fa
transaction import result sorting also
NikVolf Jun 29, 2016
2891b7b
sorting filters & ranges
NikVolf Jun 29, 2016
3c06185
error sorting out
NikVolf Jun 29, 2016
8fc03e2
deriving ipc service compiling
NikVolf Jun 29, 2016
ef8dd23
rpc & sync recompile
NikVolf Jun 30, 2016
95538ac
sorting rpc using uncles
NikVolf Jun 30, 2016
080b508
fix compilation
NikVolf Jun 30, 2016
97eb311
Merge branch 'master' into client-ipc-refact
NikVolf Jun 30, 2016
bad02d6
fix merging bugs
NikVolf Jun 30, 2016
cdd1c6d
fix unused imports
NikVolf Jun 30, 2016
ba38cc0
fix all warnings
NikVolf Jun 30, 2016
cfcf061
tests stub
NikVolf Jul 4, 2016
b873d3b
Merge branch 'master' into client-ipc-refact
NikVolf Jul 5, 2016
b58754c
some merge bugs
NikVolf Jul 5, 2016
a9a671d
ethcore compilation
NikVolf Jul 5, 2016
ce1a4c8
fix rpc compilation
NikVolf Jul 5, 2016
c966866
deriving attribute
NikVolf Jul 5, 2016
8052824
tests (and fixes)
NikVolf Jul 5, 2016
78e7101
rpc test working
NikVolf Jul 5, 2016
fb0076d
fix warnings again
NikVolf Jul 5, 2016
747818a
rs.in -> rs
NikVolf Jul 5, 2016
9783c93
Merge branch 'master' into client-ipc-refact
NikVolf Jul 6, 2016
b25a37e
Merge branch 'master' into client-ipc-refact
NikVolf Jul 6, 2016
baababe
missing attribute
NikVolf Jul 6, 2016
1ac2987
refactored tree changes
NikVolf Jul 6, 2016
2abf1df
Merge branch 'master' into client-ipc-refact
NikVolf Jul 6, 2016
5dd5983
paste reformat mess fix
NikVolf Jul 6, 2016
b1ca41d
pub mod actually
NikVolf Jul 6, 2016
f06cff4
intendation fix
NikVolf Jul 6, 2016
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
3 changes: 3 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions ethcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ bloomchain = "0.1"
"ethcore-ipc" = { path = "../ipc/rpc" }
rayon = "0.3.1"
ethstore = { path = "../ethstore" }
semver = "0.2"
ethcore-ipc-nano = { path = "../ipc/nano" }

[dependencies.hyper]
git = "https://github.com/ethcore/hyper"
Expand Down
14 changes: 14 additions & 0 deletions ethcore/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,18 @@ fn main() {
codegen::register(&mut registry);
registry.expand("", &src, &dst).unwrap();
}

// client interface
{
let src = Path::new("src/client/client.rs");
let intermediate = Path::new(&out_dir).join("client.intermediate.rs.in");
let mut registry = syntex::Registry::new();
codegen::register(&mut registry);
registry.expand("", &src, &intermediate).unwrap();

let dst = Path::new(&out_dir).join("client.ipc.rs");
let mut registry = syntex::Registry::new();
codegen::register(&mut registry);
registry.expand("", &intermediate, &dst).unwrap();
}
}
18 changes: 2 additions & 16 deletions ethcore/src/block_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ use service::*;
use client::BlockStatus;
use util::panics::*;

pub use types::block_queue_info::BlockQueueInfo;

known_heap_size!(0, UnverifiedBlock, VerifyingBlock, PreverifiedBlock);

const MIN_MEM_LIMIT: usize = 16384;
Expand All @@ -53,22 +55,6 @@ impl Default for BlockQueueConfig {
}
}

/// Block queue status
#[derive(Debug)]
pub struct BlockQueueInfo {
/// Number of queued blocks pending verification
pub unverified_queue_size: usize,
/// Number of verified queued blocks pending import
pub verified_queue_size: usize,
/// Number of blocks being verified
pub verifying_queue_size: usize,
/// Configured maximum number of blocks in the queue
pub max_queue_size: usize,
/// Configured maximum number of bytes to use
pub max_mem_use: usize,
/// Heap memory used in bytes
pub mem_used: usize,
}

impl BlockQueueInfo {
/// The total size of the queues.
Expand Down
42 changes: 0 additions & 42 deletions ethcore/src/blockchain/block_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
use util::numbers::{U256,H256};
use header::BlockNumber;

use util::bytes::{FromRawBytesVariable, FromBytesError, ToBytesWithMap};

/// Brief info about inserted block.
#[derive(Clone)]
pub struct BlockInfo {
Expand Down Expand Up @@ -54,43 +52,3 @@ pub struct BranchBecomingCanonChainData {
/// Hashes of the blocks which were invalidated.
pub retracted: Vec<H256>,
}

impl FromRawBytesVariable for BranchBecomingCanonChainData {
fn from_bytes_variable(bytes: &[u8]) -> Result<BranchBecomingCanonChainData, FromBytesError> {
type Tuple = (Vec<H256>, Vec<H256>, H256);
let (enacted, retracted, ancestor) = try!(Tuple::from_bytes_variable(bytes));
Ok(BranchBecomingCanonChainData { ancestor: ancestor, enacted: enacted, retracted: retracted })
}
}

impl FromRawBytesVariable for BlockLocation {
fn from_bytes_variable(bytes: &[u8]) -> Result<BlockLocation, FromBytesError> {
match bytes[0] {
0 => Ok(BlockLocation::CanonChain),
1 => Ok(BlockLocation::Branch),
2 => Ok(BlockLocation::BranchBecomingCanonChain(
try!(BranchBecomingCanonChainData::from_bytes_variable(&bytes[1..bytes.len()])))),
_ => Err(FromBytesError::UnknownMarker)
}
}
}

impl ToBytesWithMap for BranchBecomingCanonChainData {
fn to_bytes_map(&self) -> Vec<u8> {
(&self.enacted, &self.retracted, &self.ancestor).to_bytes_map()
}
}

impl ToBytesWithMap for BlockLocation {
fn to_bytes_map(&self) -> Vec<u8> {
match *self {
BlockLocation::CanonChain => vec![0u8],
BlockLocation::Branch => vec![1u8],
BlockLocation::BranchBecomingCanonChain(ref data) => {
let mut bytes = (&data.enacted, &data.retracted, &data.ancestor).to_bytes_map();
bytes.insert(0, 2u8);
bytes
}
}
}
}
69 changes: 48 additions & 21 deletions ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,35 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

//! Blockchain database client.

use std::path::PathBuf;
use std::collections::{HashSet, HashMap};
use std::ops::Deref;
use std::mem;
use std::collections::VecDeque;
use std::sync::*;
use std::path::Path;
use std::fmt;
use std::sync::atomic::{AtomicUsize, AtomicBool, Ordering as AtomicOrdering};
use std::time::Instant;
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering as AtomicOrdering};
use util::*;

// util
use util::numbers::*;
use util::panics::*;
use util::network::*;
use util::io::*;
use util::rlp;
use util::sha3::*;
use util::{Bytes};
use util::rlp::{RlpStream, Rlp, UntrustedRlp};
use util::journaldb;
use util::journaldb::JournalDB;
use util::kvdb::*;
use util::{Applyable, Stream, View, PerfTimer, Itertools, Colour};

// other
use views::BlockView;
use error::{ImportError, ExecutionError, BlockError, ImportResult};
use header::{BlockNumber};
use header::BlockNumber;
use state::State;
use spec::Spec;
use engine::Engine;
Expand All @@ -35,24 +54,29 @@ use verification::{PreverifiedBlock, Verifier};
use block::*;
use transaction::{LocalizedTransaction, SignedTransaction, Action};
use blockchain::extras::TransactionAddress;
use filter::Filter;
use types::filter::Filter;
use log_entry::LocalizedLogEntry;
use block_queue::{BlockQueue, BlockQueueInfo};
use blockchain::{BlockChain, BlockProvider, TreeRoute, ImportRoute};
use client::{BlockID, TransactionID, UncleID, TraceId, Mode, ClientConfig, DatabaseCompactionProfile,
BlockChainClient, MiningBlockChainClient, TraceFilter, CallAnalytics,
BlockImportError};
use client::{BlockID, TransactionID, UncleID, TraceId, ClientConfig,
DatabaseCompactionProfile, BlockChainClient, MiningBlockChainClient,
TraceFilter, CallAnalytics, BlockImportError, Mode};
use client::Error as ClientError;
use env_info::EnvInfo;
use executive::{Executive, Executed, TransactOptions, contract_address};
use receipt::LocalizedReceipt;
pub use blockchain::CacheSize as BlockChainCacheSize;
use trace::{TraceDB, ImportRequest as TraceImportRequest, LocalizedTrace, Database as TraceDatabase};
use trace;
pub use types::blockchain_info::BlockChainInfo;
pub use types::block_status::BlockStatus;
use evm::Factory as EvmFactory;
use miner::{Miner, MinerService};
use util::TrieFactory;
use ipc::IpcConfig;
use ipc::binary::{BinaryConvertError};

// re-export
pub use types::blockchain_info::BlockChainInfo;
pub use types::block_status::BlockStatus;
pub use blockchain::CacheSize as BlockChainCacheSize;

const MAX_TX_QUEUE_SIZE: usize = 4096;
const MAX_QUEUE_SIZE_TO_SLEEP_ON: usize = 2;
Expand Down Expand Up @@ -452,7 +476,7 @@ impl Client {
HeaderView::new(&self.best_block_header()).state_root(),
self.engine.account_start_nonce(),
self.trie_factory.clone())
.expect("State root of best block header always valid.")
.expect("State root of best block header always valid.")
}

/// Get info on the cache.
Expand All @@ -472,12 +496,12 @@ impl Client {
pub fn tick(&self) {
self.chain.collect_garbage();
self.block_queue.collect_garbage();

match self.mode {
Mode::Dark(timeout) => {
let mut ss = self.sleep_state.lock().unwrap();
if let Some(t) = ss.last_activity {
if Instant::now() > t + timeout {
if Instant::now() > t + timeout {
self.sleep();
ss.last_activity = None;
}
Expand All @@ -487,14 +511,14 @@ impl Client {
let mut ss = self.sleep_state.lock().unwrap();
let now = Instant::now();
if let Some(t) = ss.last_activity {
if now > t + timeout {
if now > t + timeout {
self.sleep();
ss.last_activity = None;
ss.last_autosleep = Some(now);
}
}
if let Some(t) = ss.last_autosleep {
if now > t + wakeup_after {
if let Some(t) = ss.last_autosleep {
if now > t + wakeup_after {
self.wake_up();
ss.last_activity = Some(now);
ss.last_autosleep = None;
Expand Down Expand Up @@ -575,6 +599,8 @@ impl Client {
}
}

#[derive(Ipc)]
#[ipc(client_ident="RemoteClient")]
impl BlockChainClient for Client {
fn call(&self, t: &SignedTransaction, analytics: CallAnalytics) -> Result<Executed, ExecutionError> {
let header = self.block_header(BlockID::Latest).unwrap();
Expand Down Expand Up @@ -811,8 +837,8 @@ impl BlockChainClient for Client {
receipt.logs.into_iter()
.enumerate()
.filter(|tuple| filter.matches(&tuple.1))
.map(|(i, log)| LocalizedLogEntry {
entry: log,
.map(|(i, log)| LocalizedLogEntry {
entry: log,
block_hash: hash.clone(),
block_number: number,
transaction_hash: hashes.get(index).cloned().unwrap_or_else(H256::new),
Expand All @@ -822,7 +848,6 @@ impl BlockChainClient for Client {
.collect::<Vec<LocalizedLogEntry>>()
})
.collect::<Vec<LocalizedLogEntry>>()

})
.collect()
}
Expand Down Expand Up @@ -966,3 +991,5 @@ impl MayPanic for Client {
self.panic_handler.on_panic(closure);
}
}

impl IpcConfig for Client { }
21 changes: 9 additions & 12 deletions ethcore/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

//! Blockchain database client.

mod client;
mod config;
mod error;
mod test_client;
Expand All @@ -27,7 +26,7 @@ pub use self::config::{Mode, ClientConfig, DatabaseCompactionProfile, BlockQueue
pub use self::error::Error;
pub use types::ids::*;
pub use self::test_client::{TestBlockChainClient, EachBlockWith};
pub use self::trace::Filter as TraceFilter;
pub use types::trace_filter::Filter as TraceFilter;
pub use executive::{Executed, Executive, TransactOptions};
pub use env_info::{LastHashes, EnvInfo};

Expand All @@ -47,23 +46,21 @@ use error::{ImportResult, ExecutionError};
use receipt::LocalizedReceipt;
use trace::LocalizedTrace;
use evm::Factory as EvmFactory;
pub use types::call_analytics::CallAnalytics;
pub use block_import_error::BlockImportError;
pub use transaction_import::TransactionImportResult;
pub use transaction_import::TransactionImportError;

/// Options concerning what analytics we run on the call.
#[derive(Eq, PartialEq, Default, Clone, Copy, Debug)]
pub struct CallAnalytics {
/// Make a transaction trace.
pub transaction_tracing: bool,
/// Make a VM trace.
pub vm_tracing: bool,
/// Make a diff.
pub state_diffing: bool,
pub mod client {
//! Blockchain database client.

#![allow(dead_code, unused_assignments, unused_variables, missing_docs)] // codegen issues
include!(concat!(env!("OUT_DIR"), "/client.ipc.rs"));
}

/// Blockchain database client. Owns and manages a blockchain and a block queue.
pub trait BlockChainClient : Sync + Send {

/// Should be called by any external-facing interface when actively using the client.
/// To minimise chatter, there's no need to call more than once every 30s.
fn keep_alive(&self) {}
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/client/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use spec::Spec;
use block_queue::BlockQueueInfo;
use block::{OpenBlock, SealedBlock};
use executive::Executed;
use error::{ExecutionError};
use error::ExecutionError;
use trace::LocalizedTrace;

/// Test client.
Expand Down
15 changes: 2 additions & 13 deletions ethcore/src/client/trace.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

//! Bridge between Tracedb and Blockchain.

use std::ops::Range;
use util::{Address, H256};
use util::{H256};
use header::BlockNumber;
use trace::DatabaseExtras as TraceDatabaseExtras;
use blockchain::{BlockChain, BlockProvider};
use blockchain::extras::TransactionAddress;
use super::BlockID;
pub use types::trace_filter::Filter;

impl TraceDatabaseExtras for BlockChain {
fn block_hash(&self, block_number: BlockNumber) -> Option<H256> {
Expand All @@ -26,13 +25,3 @@ impl TraceDatabaseExtras for BlockChain {
.map(|tx| tx.hash())
}
}

/// Easy to use trace filter.
pub struct Filter {
/// Range of filtering.
pub range: Range<BlockID>,
/// From address.
pub from_address: Vec<Address>,
/// To address.
pub to_address: Vec<Address>,
}
3 changes: 1 addition & 2 deletions ethcore/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ use util::*;
use header::BlockNumber;
use basic_types::LogBloom;
use client::Error as ClientError;
pub use types::executed::ExecutionError;
use ipc::binary::{BinaryConvertError, BinaryConvertable};
use types::block_import_error::BlockImportError;
pub use types::executed::ExecutionError;

#[derive(Debug, PartialEq, Clone)]
/// Errors concerning transaction processing.
Expand Down Expand Up @@ -327,7 +327,6 @@ binary_fixed_size!(BlockError);
binary_fixed_size!(ImportError);
binary_fixed_size!(TransactionError);


// TODO: uncomment below once https://github.com/rust-lang/rust/issues/27336 sorted.
/*#![feature(concat_idents)]
macro_rules! assimilate {
Expand Down
Loading