Merge branch 'master' into accountdb_migration
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
"durationLimit": "0x0d",
|
||||
"blockReward": "0x4563918244F40000",
|
||||
"registrar" : "0xc6d9d2cd449a754c494264e1809c50e34d64562b",
|
||||
"frontierCompatibilityModeLimit": "0x118c30",
|
||||
"daoRescueSoftFork": false
|
||||
"frontierCompatibilityModeLimit": "0x118c30"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -9,8 +9,7 @@
|
||||
"durationLimit": "0x0d",
|
||||
"blockReward": "0x4563918244F40000",
|
||||
"registrar" : "0xc6d9d2cd449a754c494264e1809c50e34d64562b",
|
||||
"frontierCompatibilityModeLimit": "0x118c30",
|
||||
"daoRescueSoftFork": false
|
||||
"frontierCompatibilityModeLimit": "0x118c30"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
"durationLimit": "0x0d",
|
||||
"blockReward": "0x4563918244F40000",
|
||||
"registrar" : "0xc6d9d2cd449a754c494264e1809c50e34d64562b",
|
||||
"frontierCompatibilityModeLimit": "0x118c30",
|
||||
"daoRescueSoftFork": true
|
||||
"frontierCompatibilityModeLimit": "0x118c30"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
"durationLimit": "0x0d",
|
||||
"blockReward": "0x4563918244F40000",
|
||||
"registrar" : "0xc6d9d2cd449a754c494264e1809c50e34d64562b",
|
||||
"frontierCompatibilityModeLimit": "0xffffffffffffffff",
|
||||
"daoRescueSoftFork": false
|
||||
"frontierCompatibilityModeLimit": "0xffffffffffffffff"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
"durationLimit": "0x0d",
|
||||
"blockReward": "0x4563918244F40000",
|
||||
"registrar" : "0xc6d9d2cd449a754c494264e1809c50e34d64562b",
|
||||
"frontierCompatibilityModeLimit": 0,
|
||||
"daoRescueSoftFork": false
|
||||
"frontierCompatibilityModeLimit": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
"durationLimit": "0x0d",
|
||||
"blockReward": "0x4563918244F40000",
|
||||
"registrar" : "0xc6d9d2cd449a754c494264e1809c50e34d64562b",
|
||||
"frontierCompatibilityModeLimit": 0,
|
||||
"daoRescueSoftFork": true
|
||||
"frontierCompatibilityModeLimit": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
"durationLimit": "0x0d",
|
||||
"blockReward": "0x4563918244F40000",
|
||||
"registrar": "",
|
||||
"frontierCompatibilityModeLimit": "0x789b0",
|
||||
"daoRescueSoftFork": false
|
||||
"frontierCompatibilityModeLimit": "0x789b0"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
"durationLimit": "0x08",
|
||||
"blockReward": "0x14D1120D7B160000",
|
||||
"registrar": "5e70c0bbcd5636e0f9f9316e9f8633feb64d4050",
|
||||
"frontierCompatibilityModeLimit": "0xffffffffffffffff",
|
||||
"daoRescueSoftFork": false
|
||||
"frontierCompatibilityModeLimit": "0xffffffffffffffff"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -203,7 +203,6 @@ mod tests {
|
||||
timestamp: 0,
|
||||
difficulty: 0.into(),
|
||||
last_hashes: vec![],
|
||||
dao_rescue_block_gas_limit: None,
|
||||
gas_used: 0.into(),
|
||||
gas_limit: 0.into(),
|
||||
});
|
||||
@@ -254,7 +253,7 @@ mod tests {
|
||||
spec.ensure_db_good(db.as_hashdb_mut());
|
||||
let last_hashes = vec![genesis_header.hash()];
|
||||
let vm_factory = Default::default();
|
||||
let b = OpenBlock::new(engine.deref(), &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, None, addr, (3141562.into(), 31415620.into()), vec![]).unwrap();
|
||||
let b = OpenBlock::new(engine.deref(), &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, addr, (3141562.into(), 31415620.into()), vec![]).unwrap();
|
||||
let b = b.close_and_lock();
|
||||
let seal = engine.generate_seal(b.block(), Some(&tap)).unwrap();
|
||||
assert!(b.try_seal(engine.deref(), seal).is_ok());
|
||||
|
||||
@@ -183,7 +183,6 @@ pub struct OpenBlock<'x> {
|
||||
engine: &'x Engine,
|
||||
vm_factory: &'x EvmFactory,
|
||||
last_hashes: LastHashes,
|
||||
dao_rescue_block_gas_limit: Option<U256>,
|
||||
}
|
||||
|
||||
/// Just like `OpenBlock`, except that we've applied `Engine::on_close_block`, finished up the non-seal header fields,
|
||||
@@ -195,7 +194,6 @@ pub struct ClosedBlock {
|
||||
block: ExecutedBlock,
|
||||
uncle_bytes: Bytes,
|
||||
last_hashes: LastHashes,
|
||||
dao_rescue_block_gas_limit: Option<U256>,
|
||||
unclosed_state: State,
|
||||
}
|
||||
|
||||
@@ -227,7 +225,6 @@ impl<'x> OpenBlock<'x> {
|
||||
db: Box<JournalDB>,
|
||||
parent: &Header,
|
||||
last_hashes: LastHashes,
|
||||
dao_rescue_block_gas_limit: Option<U256>,
|
||||
author: Address,
|
||||
gas_range_target: (U256, U256),
|
||||
extra_data: Bytes,
|
||||
@@ -238,7 +235,6 @@ impl<'x> OpenBlock<'x> {
|
||||
engine: engine,
|
||||
vm_factory: vm_factory,
|
||||
last_hashes: last_hashes,
|
||||
dao_rescue_block_gas_limit: dao_rescue_block_gas_limit,
|
||||
};
|
||||
|
||||
r.block.base.header.parent_hash = parent.hash();
|
||||
@@ -295,7 +291,6 @@ impl<'x> OpenBlock<'x> {
|
||||
/// Get the environment info concerning this block.
|
||||
pub fn env_info(&self) -> EnvInfo {
|
||||
// TODO: memoise.
|
||||
const SOFT_FORK_BLOCK: u64 = 1_800_000;
|
||||
EnvInfo {
|
||||
number: self.block.base.header.number,
|
||||
author: self.block.base.header.author.clone(),
|
||||
@@ -304,7 +299,6 @@ impl<'x> OpenBlock<'x> {
|
||||
last_hashes: self.last_hashes.clone(), // TODO: should be a reference.
|
||||
gas_used: self.block.receipts.last().map_or(U256::zero(), |r| r.gas_used),
|
||||
gas_limit: self.block.base.header.gas_limit.clone(),
|
||||
dao_rescue_block_gas_limit: if self.block.base.header.number == SOFT_FORK_BLOCK { Some(self.block.base.header.gas_limit) } else { self.dao_rescue_block_gas_limit },
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,7 +345,6 @@ impl<'x> OpenBlock<'x> {
|
||||
block: s.block,
|
||||
uncle_bytes: uncle_bytes,
|
||||
last_hashes: s.last_hashes,
|
||||
dao_rescue_block_gas_limit: s.dao_rescue_block_gas_limit,
|
||||
unclosed_state: unclosed_state,
|
||||
}
|
||||
}
|
||||
@@ -411,7 +404,6 @@ impl ClosedBlock {
|
||||
engine: engine,
|
||||
vm_factory: vm_factory,
|
||||
last_hashes: self.last_hashes,
|
||||
dao_rescue_block_gas_limit: self.dao_rescue_block_gas_limit,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -481,7 +473,6 @@ pub fn enact(
|
||||
db: Box<JournalDB>,
|
||||
parent: &Header,
|
||||
last_hashes: LastHashes,
|
||||
dao_rescue_block_gas_limit: Option<U256>,
|
||||
vm_factory: &EvmFactory,
|
||||
trie_factory: TrieFactory,
|
||||
) -> Result<LockedBlock, Error> {
|
||||
@@ -492,7 +483,7 @@ pub fn enact(
|
||||
}
|
||||
}
|
||||
|
||||
let mut b = try!(OpenBlock::new(engine, vm_factory, trie_factory, tracing, db, parent, last_hashes, dao_rescue_block_gas_limit, header.author().clone(), (3141562.into(), 31415620.into()), header.extra_data().clone()));
|
||||
let mut b = try!(OpenBlock::new(engine, vm_factory, trie_factory, tracing, db, parent, last_hashes, header.author().clone(), (3141562.into(), 31415620.into()), header.extra_data().clone()));
|
||||
b.set_difficulty(*header.difficulty());
|
||||
b.set_gas_limit(*header.gas_limit());
|
||||
b.set_timestamp(header.timestamp());
|
||||
@@ -510,13 +501,12 @@ pub fn enact_bytes(
|
||||
db: Box<JournalDB>,
|
||||
parent: &Header,
|
||||
last_hashes: LastHashes,
|
||||
dao_rescue_block_gas_limit: Option<U256>,
|
||||
vm_factory: &EvmFactory,
|
||||
trie_factory: TrieFactory,
|
||||
) -> Result<LockedBlock, Error> {
|
||||
let block = BlockView::new(block_bytes);
|
||||
let header = block.header();
|
||||
enact(&header, &block.transactions(), &block.uncles(), engine, tracing, db, parent, last_hashes, dao_rescue_block_gas_limit, vm_factory, trie_factory)
|
||||
enact(&header, &block.transactions(), &block.uncles(), engine, tracing, db, parent, last_hashes, vm_factory, trie_factory)
|
||||
}
|
||||
|
||||
/// Enact the block given by `block_bytes` using `engine` on the database `db` with given `parent` block header
|
||||
@@ -528,12 +518,11 @@ pub fn enact_verified(
|
||||
db: Box<JournalDB>,
|
||||
parent: &Header,
|
||||
last_hashes: LastHashes,
|
||||
dao_rescue_block_gas_limit: Option<U256>,
|
||||
vm_factory: &EvmFactory,
|
||||
trie_factory: TrieFactory,
|
||||
) -> Result<LockedBlock, Error> {
|
||||
let view = BlockView::new(&block.bytes);
|
||||
enact(&block.header, &block.transactions, &view.uncles(), engine, tracing, db, parent, last_hashes, dao_rescue_block_gas_limit, vm_factory, trie_factory)
|
||||
enact(&block.header, &block.transactions, &view.uncles(), engine, tracing, db, parent, last_hashes, vm_factory, trie_factory)
|
||||
}
|
||||
|
||||
/// Enact the block given by `block_bytes` using `engine` on the database `db` with given `parent` block header. Seal the block aferwards
|
||||
@@ -545,12 +534,11 @@ pub fn enact_and_seal(
|
||||
db: Box<JournalDB>,
|
||||
parent: &Header,
|
||||
last_hashes: LastHashes,
|
||||
dao_rescue_block_gas_limit: Option<U256>,
|
||||
vm_factory: &EvmFactory,
|
||||
trie_factory: TrieFactory,
|
||||
) -> Result<SealedBlock, Error> {
|
||||
let header = BlockView::new(block_bytes).header_view();
|
||||
Ok(try!(try!(enact_bytes(block_bytes, engine, tracing, db, parent, last_hashes, dao_rescue_block_gas_limit, vm_factory, trie_factory)).seal(engine, header.seal())))
|
||||
Ok(try!(try!(enact_bytes(block_bytes, engine, tracing, db, parent, last_hashes, vm_factory, trie_factory)).seal(engine, header.seal())))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -570,7 +558,7 @@ mod tests {
|
||||
spec.ensure_db_good(db.as_hashdb_mut());
|
||||
let last_hashes = vec![genesis_header.hash()];
|
||||
let vm_factory = Default::default();
|
||||
let b = OpenBlock::new(engine.deref(), &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, None, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap();
|
||||
let b = OpenBlock::new(engine.deref(), &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap();
|
||||
let b = b.close_and_lock();
|
||||
let _ = b.seal(engine.deref(), vec![]);
|
||||
}
|
||||
@@ -586,7 +574,7 @@ mod tests {
|
||||
let mut db = db_result.take();
|
||||
spec.ensure_db_good(db.as_hashdb_mut());
|
||||
let vm_factory = Default::default();
|
||||
let b = OpenBlock::new(engine.deref(), &vm_factory, Default::default(), false, db, &genesis_header, vec![genesis_header.hash()], None, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap()
|
||||
let b = OpenBlock::new(engine.deref(), &vm_factory, Default::default(), false, db, &genesis_header, vec![genesis_header.hash()], Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap()
|
||||
.close_and_lock().seal(engine.deref(), vec![]).unwrap();
|
||||
let orig_bytes = b.rlp_bytes();
|
||||
let orig_db = b.drain();
|
||||
@@ -594,7 +582,7 @@ mod tests {
|
||||
let mut db_result = get_temp_journal_db();
|
||||
let mut db = db_result.take();
|
||||
spec.ensure_db_good(db.as_hashdb_mut());
|
||||
let e = enact_and_seal(&orig_bytes, engine.deref(), false, db, &genesis_header, vec![genesis_header.hash()], None, &Default::default(), Default::default()).unwrap();
|
||||
let e = enact_and_seal(&orig_bytes, engine.deref(), false, db, &genesis_header, vec![genesis_header.hash()], &Default::default(), Default::default()).unwrap();
|
||||
|
||||
assert_eq!(e.rlp_bytes(), orig_bytes);
|
||||
|
||||
@@ -614,7 +602,7 @@ mod tests {
|
||||
let mut db = db_result.take();
|
||||
spec.ensure_db_good(db.as_hashdb_mut());
|
||||
let vm_factory = Default::default();
|
||||
let mut open_block = OpenBlock::new(engine.deref(), &vm_factory, Default::default(), false, db, &genesis_header, vec![genesis_header.hash()], None, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap();
|
||||
let mut open_block = OpenBlock::new(engine.deref(), &vm_factory, Default::default(), false, db, &genesis_header, vec![genesis_header.hash()], Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap();
|
||||
let mut uncle1_header = Header::new();
|
||||
uncle1_header.extra_data = b"uncle1".to_vec();
|
||||
let mut uncle2_header = Header::new();
|
||||
@@ -629,7 +617,7 @@ mod tests {
|
||||
let mut db_result = get_temp_journal_db();
|
||||
let mut db = db_result.take();
|
||||
spec.ensure_db_good(db.as_hashdb_mut());
|
||||
let e = enact_and_seal(&orig_bytes, engine.deref(), false, db, &genesis_header, vec![genesis_header.hash()], None, &Default::default(), Default::default()).unwrap();
|
||||
let e = enact_and_seal(&orig_bytes, engine.deref(), false, db, &genesis_header, vec![genesis_header.hash()], &Default::default(), Default::default()).unwrap();
|
||||
|
||||
let bytes = e.rlp_bytes();
|
||||
assert_eq!(bytes, orig_bytes);
|
||||
|
||||
@@ -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;
|
||||
@@ -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.
|
||||
|
||||
@@ -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 {
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -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, TransactionImportError,
|
||||
BlockImportError, TransactionImportResult};
|
||||
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;
|
||||
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;
|
||||
use evm::Factory as EvmFactory;
|
||||
use miner::{Miner, MinerService, AccountDetails};
|
||||
pub use blockchain::CacheSize as BlockChainCacheSize;
|
||||
|
||||
const MAX_TX_QUEUE_SIZE: usize = 4096;
|
||||
const MAX_QUEUE_SIZE_TO_SLEEP_ON: usize = 2;
|
||||
@@ -119,6 +143,7 @@ pub struct Client {
|
||||
liveness: AtomicBool,
|
||||
io_channel: IoChannel<NetSyncMessage>,
|
||||
queue_transactions: AtomicUsize,
|
||||
previous_enode: Mutex<Option<String>>,
|
||||
}
|
||||
|
||||
const HISTORY: u64 = 1200;
|
||||
@@ -204,6 +229,7 @@ impl Client {
|
||||
miner: miner,
|
||||
io_channel: message_channel,
|
||||
queue_transactions: AtomicUsize::new(0),
|
||||
previous_enode: Mutex::new(None),
|
||||
};
|
||||
Ok(Arc::new(client))
|
||||
}
|
||||
@@ -258,7 +284,7 @@ impl Client {
|
||||
let last_hashes = self.build_last_hashes(header.parent_hash.clone());
|
||||
let db = self.state_db.lock().unwrap().boxed_clone();
|
||||
|
||||
let enact_result = enact_verified(&block, engine, self.tracedb.tracing_enabled(), db, &parent, last_hashes, self.dao_rescue_block_gas_limit(header.parent_hash.clone()), &self.vm_factory, self.trie_factory.clone());
|
||||
let enact_result = enact_verified(&block, engine, self.tracedb.tracing_enabled(), db, &parent, last_hashes, &self.vm_factory, self.trie_factory.clone());
|
||||
if let Err(e) = enact_result {
|
||||
warn!(target: "client", "Block import failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e);
|
||||
return Err(());
|
||||
@@ -409,12 +435,8 @@ impl Client {
|
||||
pub fn import_queued_transactions(&self, transactions: &[Bytes]) -> usize {
|
||||
let _timer = PerfTimer::new("import_queued_transactions");
|
||||
self.queue_transactions.fetch_sub(transactions.len(), AtomicOrdering::SeqCst);
|
||||
let fetch_account = |a: &Address| AccountDetails {
|
||||
nonce: self.latest_nonce(a),
|
||||
balance: self.latest_balance(a),
|
||||
};
|
||||
let tx = transactions.iter().filter_map(|bytes| UntrustedRlp::new(&bytes).as_val().ok()).collect();
|
||||
let results = self.miner.import_transactions(self, tx, fetch_account);
|
||||
let txs = transactions.iter().filter_map(|bytes| UntrustedRlp::new(&bytes).as_val().ok()).collect();
|
||||
let results = self.miner.import_external_transactions(self, txs);
|
||||
results.len()
|
||||
}
|
||||
|
||||
@@ -454,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.
|
||||
@@ -474,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;
|
||||
}
|
||||
@@ -489,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;
|
||||
@@ -563,8 +585,22 @@ impl Client {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Notify us that the network has been started.
|
||||
pub fn network_started(&self, url: &String) {
|
||||
let mut previous_enode = self.previous_enode.lock().unwrap();
|
||||
if let Some(ref u) = *previous_enode {
|
||||
if u == url {
|
||||
return;
|
||||
}
|
||||
}
|
||||
*previous_enode = Some(url.clone());
|
||||
info!(target: "mode", "Public node URL: {}", url.apply(Colour::White.bold()));
|
||||
}
|
||||
}
|
||||
|
||||
#[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();
|
||||
@@ -578,7 +614,6 @@ impl BlockChainClient for Client {
|
||||
last_hashes: last_hashes,
|
||||
gas_used: U256::zero(),
|
||||
gas_limit: U256::max_value(),
|
||||
dao_rescue_block_gas_limit: self.dao_rescue_block_gas_limit(view.parent_hash()),
|
||||
};
|
||||
// that's just a copy of the state.
|
||||
let mut state = self.state();
|
||||
@@ -802,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),
|
||||
@@ -813,7 +848,6 @@ impl BlockChainClient for Client {
|
||||
.collect::<Vec<LocalizedLogEntry>>()
|
||||
})
|
||||
.collect::<Vec<LocalizedLogEntry>>()
|
||||
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
@@ -862,18 +896,6 @@ impl BlockChainClient for Client {
|
||||
self.build_last_hashes(self.chain.best_block_hash())
|
||||
}
|
||||
|
||||
fn import_transactions(&self, transactions: Vec<SignedTransaction>) -> Vec<Result<TransactionImportResult, TransactionImportError>> {
|
||||
let fetch_account = |a: &Address| AccountDetails {
|
||||
nonce: self.latest_nonce(a),
|
||||
balance: self.latest_balance(a),
|
||||
};
|
||||
|
||||
self.miner.import_transactions(self, transactions, &fetch_account)
|
||||
.into_iter()
|
||||
.map(|res| res.map_err(|e| e.into()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn queue_transactions(&self, transactions: Vec<Bytes>) {
|
||||
if self.queue_transactions.load(AtomicOrdering::Relaxed) > MAX_TX_QUEUE_SIZE {
|
||||
debug!("Ignoring {} transactions: queue is full", transactions.len());
|
||||
@@ -908,7 +930,6 @@ impl MiningBlockChainClient for Client {
|
||||
self.state_db.lock().unwrap().boxed_clone(),
|
||||
&self.chain.block_header(&h).expect("h is best block hash: so it's header must exist: qed"),
|
||||
self.build_last_hashes(h.clone()),
|
||||
self.dao_rescue_block_gas_limit(h.clone()),
|
||||
author,
|
||||
gas_range_target,
|
||||
extra_data,
|
||||
@@ -970,3 +991,5 @@ impl MayPanic for Client {
|
||||
self.panic_handler.on_panic(closure);
|
||||
}
|
||||
}
|
||||
|
||||
impl IpcConfig for Client { }
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
//! Blockchain database client.
|
||||
|
||||
mod client;
|
||||
mod config;
|
||||
mod error;
|
||||
mod test_client;
|
||||
@@ -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};
|
||||
|
||||
@@ -42,28 +41,26 @@ use header::{BlockNumber};
|
||||
use transaction::{LocalizedTransaction, SignedTransaction};
|
||||
use log_entry::LocalizedLogEntry;
|
||||
use filter::Filter;
|
||||
use views::{HeaderView, BlockView};
|
||||
use views::{BlockView};
|
||||
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, TransactionImportError};
|
||||
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) {}
|
||||
@@ -192,9 +189,6 @@ pub trait BlockChainClient : Sync + Send {
|
||||
/// Get last hashes starting from best block.
|
||||
fn last_hashes(&self) -> LastHashes;
|
||||
|
||||
/// import transactions from network/other 3rd party
|
||||
fn import_transactions(&self, transactions: Vec<SignedTransaction>) -> Vec<Result<TransactionImportResult, TransactionImportError>>;
|
||||
|
||||
/// Queue transactions for importing.
|
||||
fn queue_transactions(&self, transactions: Vec<Bytes>);
|
||||
|
||||
@@ -226,28 +220,6 @@ pub trait BlockChainClient : Sync + Send {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Get `Some` gas limit of SOFT_FORK_BLOCK, or `None` if chain is not yet that long.
|
||||
fn dao_rescue_block_gas_limit(&self, chain_hash: H256) -> Option<U256> {
|
||||
const SOFT_FORK_BLOCK: u64 = 1800000;
|
||||
// shortcut if the canon chain is already known.
|
||||
if self.chain_info().best_block_number > SOFT_FORK_BLOCK + 1000 {
|
||||
return self.block_header(BlockID::Number(SOFT_FORK_BLOCK)).map(|header| HeaderView::new(&header).gas_limit());
|
||||
}
|
||||
// otherwise check according to `chain_hash`.
|
||||
if let Some(mut header) = self.block_header(BlockID::Hash(chain_hash)) {
|
||||
if HeaderView::new(&header).number() < SOFT_FORK_BLOCK {
|
||||
None
|
||||
} else {
|
||||
while HeaderView::new(&header).number() != SOFT_FORK_BLOCK {
|
||||
header = self.block_header(BlockID::Hash(HeaderView::new(&header).parent_hash())).expect("chain is complete; parent of chain entry must be in chain; qed");
|
||||
}
|
||||
Some(HeaderView::new(&header).gas_limit())
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Extended client interface used for mining
|
||||
|
||||
@@ -22,7 +22,7 @@ use transaction::{Transaction, LocalizedTransaction, SignedTransaction, Action};
|
||||
use blockchain::TreeRoute;
|
||||
use client::{BlockChainClient, MiningBlockChainClient, BlockChainInfo, BlockStatus, BlockID,
|
||||
TransactionID, UncleID, TraceId, TraceFilter, LastHashes, CallAnalytics,
|
||||
TransactionImportError, BlockImportError};
|
||||
BlockImportError};
|
||||
use header::{Header as BlockHeader, BlockNumber};
|
||||
use filter::Filter;
|
||||
use log_entry::LocalizedLogEntry;
|
||||
@@ -36,11 +36,9 @@ use spec::Spec;
|
||||
use block_queue::BlockQueueInfo;
|
||||
use block::{OpenBlock, SealedBlock};
|
||||
use executive::Executed;
|
||||
use error::{ExecutionError};
|
||||
use error::ExecutionError;
|
||||
use trace::LocalizedTrace;
|
||||
|
||||
use miner::{TransactionImportResult, AccountDetails};
|
||||
|
||||
/// Test client.
|
||||
pub struct TestBlockChainClient {
|
||||
/// Blocks.
|
||||
@@ -275,6 +273,10 @@ impl BlockChainClient for TestBlockChainClient {
|
||||
}
|
||||
}
|
||||
|
||||
fn latest_nonce(&self, address: &Address) -> U256 {
|
||||
self.nonce(address, BlockID::Latest).unwrap()
|
||||
}
|
||||
|
||||
fn code(&self, address: &Address) -> Option<Bytes> {
|
||||
self.code.read().unwrap().get(address).cloned()
|
||||
}
|
||||
@@ -287,6 +289,10 @@ impl BlockChainClient for TestBlockChainClient {
|
||||
}
|
||||
}
|
||||
|
||||
fn latest_balance(&self, address: &Address) -> U256 {
|
||||
self.balance(address, BlockID::Latest).unwrap()
|
||||
}
|
||||
|
||||
fn storage_at(&self, address: &Address, position: &H256, id: BlockID) -> Option<H256> {
|
||||
if let BlockID::Latest = id {
|
||||
Some(self.storage.read().unwrap().get(&(address.clone(), position.clone())).cloned().unwrap_or_else(H256::new))
|
||||
@@ -488,24 +494,10 @@ impl BlockChainClient for TestBlockChainClient {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn import_transactions(&self, transactions: Vec<SignedTransaction>) -> Vec<Result<TransactionImportResult, TransactionImportError>> {
|
||||
let nonces = self.nonces.read().unwrap();
|
||||
let balances = self.balances.read().unwrap();
|
||||
let fetch_account = |a: &Address| AccountDetails {
|
||||
nonce: nonces[a],
|
||||
balance: balances[a],
|
||||
};
|
||||
|
||||
self.miner.import_transactions(self, transactions, &fetch_account)
|
||||
.into_iter()
|
||||
.map(|res| res.map_err(|e| e.into()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn queue_transactions(&self, transactions: Vec<Bytes>) {
|
||||
// import right here
|
||||
let tx = transactions.into_iter().filter_map(|bytes| UntrustedRlp::new(&bytes).as_val().ok()).collect();
|
||||
self.import_transactions(tx);
|
||||
let txs = transactions.into_iter().filter_map(|bytes| UntrustedRlp::new(&bytes).as_val().ok()).collect();
|
||||
self.miner.import_external_transactions(self, txs);
|
||||
}
|
||||
|
||||
fn pending_transactions(&self) -> Vec<SignedTransaction> {
|
||||
|
||||
@@ -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> {
|
||||
@@ -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>,
|
||||
}
|
||||
|
||||
@@ -39,9 +39,6 @@ pub struct EnvInfo {
|
||||
pub last_hashes: LastHashes,
|
||||
/// The gas used.
|
||||
pub gas_used: U256,
|
||||
|
||||
/// Block gas limit at DAO rescue block SOFT_FORK_BLOCK or None if not yet there.
|
||||
pub dao_rescue_block_gas_limit: Option<U256>,
|
||||
}
|
||||
|
||||
impl Default for EnvInfo {
|
||||
@@ -54,7 +51,6 @@ impl Default for EnvInfo {
|
||||
gas_limit: 0.into(),
|
||||
last_hashes: vec![],
|
||||
gas_used: 0.into(),
|
||||
dao_rescue_block_gas_limit: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,7 +66,6 @@ impl From<ethjson::vm::Env> for EnvInfo {
|
||||
timestamp: e.timestamp.into(),
|
||||
last_hashes: (1..cmp::min(number + 1, 257)).map(|i| format!("{}", number - i).as_bytes().sha3()).collect(),
|
||||
gas_used: U256::zero(),
|
||||
dao_rescue_block_gas_limit: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -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 {
|
||||
|
||||
@@ -39,8 +39,6 @@ pub struct EthashParams {
|
||||
pub registrar: Address,
|
||||
/// Homestead transition block number.
|
||||
pub frontier_compatibility_mode_limit: u64,
|
||||
/// Enable the soft-fork logic.
|
||||
pub dao_rescue_soft_fork: bool,
|
||||
}
|
||||
|
||||
impl From<ethjson::spec::EthashParams> for EthashParams {
|
||||
@@ -53,7 +51,6 @@ impl From<ethjson::spec::EthashParams> for EthashParams {
|
||||
block_reward: p.block_reward.into(),
|
||||
registrar: p.registrar.into(),
|
||||
frontier_compatibility_mode_limit: p.frontier_compatibility_mode_limit.into(),
|
||||
dao_rescue_soft_fork: p.dao_rescue_soft_fork.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,11 +99,7 @@ impl Engine for Ethash {
|
||||
if env_info.number < self.ethash_params.frontier_compatibility_mode_limit {
|
||||
Schedule::new_frontier()
|
||||
} else {
|
||||
let mut s = Schedule::new_homestead();
|
||||
if self.ethash_params.dao_rescue_soft_fork {
|
||||
s.reject_dao_transactions = env_info.dao_rescue_block_gas_limit.map_or(false, |x| x <= 4_000_000.into());
|
||||
}
|
||||
s
|
||||
Schedule::new_homestead()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,7 +318,7 @@ mod tests {
|
||||
spec.ensure_db_good(db.as_hashdb_mut());
|
||||
let last_hashes = vec![genesis_header.hash()];
|
||||
let vm_factory = Default::default();
|
||||
let b = OpenBlock::new(engine.deref(), &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, None, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap();
|
||||
let b = OpenBlock::new(engine.deref(), &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap();
|
||||
let b = b.close();
|
||||
assert_eq!(b.state().balance(&Address::zero()), U256::from_str("4563918244f40000").unwrap());
|
||||
}
|
||||
@@ -340,7 +333,7 @@ mod tests {
|
||||
spec.ensure_db_good(db.as_hashdb_mut());
|
||||
let last_hashes = vec![genesis_header.hash()];
|
||||
let vm_factory = Default::default();
|
||||
let mut b = OpenBlock::new(engine.deref(), &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, None, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap();
|
||||
let mut b = OpenBlock::new(engine.deref(), &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap();
|
||||
let mut uncle = Header::new();
|
||||
let uncle_author = address_from_hex("ef2d6d194084c2de36e0dabfce45d046b37d1106");
|
||||
uncle.author = uncle_author.clone();
|
||||
@@ -369,7 +362,6 @@ mod tests {
|
||||
last_hashes: vec![],
|
||||
gas_used: 0.into(),
|
||||
gas_limit: 0.into(),
|
||||
dao_rescue_block_gas_limit: None,
|
||||
});
|
||||
|
||||
assert!(schedule.stack_limit > 0);
|
||||
@@ -382,7 +374,6 @@ mod tests {
|
||||
last_hashes: vec![],
|
||||
gas_used: 0.into(),
|
||||
gas_limit: 0.into(),
|
||||
dao_rescue_block_gas_limit: None,
|
||||
});
|
||||
|
||||
assert!(!schedule.have_delegate_call);
|
||||
|
||||
@@ -33,11 +33,8 @@ use super::spec::*;
|
||||
pub fn new_olympic() -> Spec { Spec::load(include_bytes!("../../res/ethereum/olympic.json")) }
|
||||
|
||||
/// Create a new Frontier mainnet chain spec.
|
||||
pub fn new_frontier(dao_rescue: bool) -> Spec {
|
||||
Spec::load(match dao_rescue {
|
||||
true => include_bytes!("../../res/ethereum/frontier_dao_rescue.json"),
|
||||
false => include_bytes!("../../res/ethereum/frontier.json"),
|
||||
})
|
||||
pub fn new_frontier() -> Spec {
|
||||
Spec::load(include_bytes!("../../res/ethereum/frontier.json"))
|
||||
}
|
||||
|
||||
/// Create a new Frontier chain spec as though it never changes to Homestead.
|
||||
@@ -89,7 +86,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn frontier() {
|
||||
let frontier = new_frontier(true);
|
||||
let frontier = new_frontier();
|
||||
|
||||
assert_eq!(frontier.state_root(), H256::from_str("d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544").unwrap());
|
||||
let genesis = frontier.genesis_block();
|
||||
|
||||
@@ -319,7 +319,6 @@ mod tests {
|
||||
last_hashes: vec![],
|
||||
gas_used: 0.into(),
|
||||
gas_limit: 0.into(),
|
||||
dao_rescue_block_gas_limit: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,6 +95,8 @@ extern crate rayon;
|
||||
extern crate hyper;
|
||||
extern crate ethash;
|
||||
pub extern crate ethstore;
|
||||
extern crate semver;
|
||||
extern crate ethcore_ipc_nano as nanoipc;
|
||||
|
||||
#[cfg(test)] extern crate ethcore_devtools as devtools;
|
||||
#[cfg(feature = "jit" )] extern crate evmjit;
|
||||
@@ -106,7 +108,6 @@ pub mod block_queue;
|
||||
pub mod client;
|
||||
pub mod error;
|
||||
pub mod ethereum;
|
||||
pub mod filter;
|
||||
pub mod header;
|
||||
pub mod service;
|
||||
pub mod trace;
|
||||
|
||||
@@ -20,7 +20,6 @@ use std::time::{Instant, Duration};
|
||||
|
||||
use util::*;
|
||||
use util::using_queue::{UsingQueue, GetAction};
|
||||
use util::Colour::White;
|
||||
use account_provider::AccountProvider;
|
||||
use views::{BlockView, HeaderView};
|
||||
use client::{MiningBlockChainClient, Executive, Executed, EnvInfo, TransactOptions, BlockID, CallAnalytics};
|
||||
@@ -316,6 +315,19 @@ impl Miner {
|
||||
!have_work
|
||||
}
|
||||
|
||||
fn add_transactions_to_queue(&self, chain: &MiningBlockChainClient, transactions: Vec<SignedTransaction>, origin: TransactionOrigin, transaction_queue: &mut TransactionQueue) ->
|
||||
Vec<Result<TransactionImportResult, Error>> {
|
||||
|
||||
let fetch_account = |a: &Address| AccountDetails {
|
||||
nonce: chain.latest_nonce(a),
|
||||
balance: chain.latest_balance(a),
|
||||
};
|
||||
|
||||
transactions.into_iter()
|
||||
.map(|tx| transaction_queue.add(tx, &fetch_account, origin))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Are we allowed to do a non-mandatory reseal?
|
||||
fn tx_reseal_allowed(&self) -> bool { Instant::now() > *self.next_allowed_reseal.lock().unwrap() }
|
||||
}
|
||||
@@ -356,7 +368,6 @@ impl MinerService for Miner {
|
||||
last_hashes: last_hashes,
|
||||
gas_used: U256::zero(),
|
||||
gas_limit: U256::max_value(),
|
||||
dao_rescue_block_gas_limit: chain.dao_rescue_block_gas_limit(header.parent_hash().clone()),
|
||||
};
|
||||
// that's just a copy of the state.
|
||||
let mut state = block.state().clone();
|
||||
@@ -479,27 +490,24 @@ impl MinerService for Miner {
|
||||
self.gas_range_target.read().unwrap().1
|
||||
}
|
||||
|
||||
fn import_transactions<T>(&self, chain: &MiningBlockChainClient, transactions: Vec<SignedTransaction>, fetch_account: T) ->
|
||||
Vec<Result<TransactionImportResult, Error>>
|
||||
where T: Fn(&Address) -> AccountDetails {
|
||||
let results: Vec<Result<TransactionImportResult, Error>> = {
|
||||
let mut transaction_queue = self.transaction_queue.lock().unwrap();
|
||||
transactions.into_iter()
|
||||
.map(|tx| transaction_queue.add(tx, &fetch_account, TransactionOrigin::External))
|
||||
.collect()
|
||||
};
|
||||
if !results.is_empty() && self.options.reseal_on_external_tx && self.tx_reseal_allowed() {
|
||||
fn import_external_transactions(&self, chain: &MiningBlockChainClient, transactions: Vec<SignedTransaction>) ->
|
||||
Vec<Result<TransactionImportResult, Error>> {
|
||||
|
||||
let mut transaction_queue = self.transaction_queue.lock().unwrap();
|
||||
let results = self.add_transactions_to_queue(chain, transactions, TransactionOrigin::External,
|
||||
&mut transaction_queue);
|
||||
|
||||
if !results.is_empty() && self.options.reseal_on_external_tx && self.tx_reseal_allowed() {
|
||||
self.update_sealing(chain);
|
||||
}
|
||||
results
|
||||
}
|
||||
|
||||
fn import_own_transaction<T>(
|
||||
fn import_own_transaction(
|
||||
&self,
|
||||
chain: &MiningBlockChainClient,
|
||||
transaction: SignedTransaction,
|
||||
fetch_account: T
|
||||
) -> Result<TransactionImportResult, Error> where T: Fn(&Address) -> AccountDetails {
|
||||
) -> Result<TransactionImportResult, Error> {
|
||||
|
||||
let hash = transaction.hash();
|
||||
trace!(target: "own_tx", "Importing transaction: {:?}", transaction);
|
||||
@@ -507,7 +515,7 @@ impl MinerService for Miner {
|
||||
let imported = {
|
||||
// Be sure to release the lock before we call enable_and_prepare_sealing
|
||||
let mut transaction_queue = self.transaction_queue.lock().unwrap();
|
||||
let import = transaction_queue.add(transaction, &fetch_account, TransactionOrigin::Local);
|
||||
let import = self.add_transactions_to_queue(chain, vec![transaction], TransactionOrigin::Local, &mut transaction_queue).pop().unwrap();
|
||||
|
||||
match import {
|
||||
Ok(ref res) => {
|
||||
@@ -646,7 +654,7 @@ impl MinerService for Miner {
|
||||
let n = sealed.header().number();
|
||||
let h = sealed.header().hash();
|
||||
try!(chain.import_sealed_block(sealed));
|
||||
info!(target: "miner", "Mined block imported OK. #{}: {}", paint(White.bold(), format!("{}", n)), paint(White.bold(), h.hex()));
|
||||
info!(target: "miner", "Mined block imported OK. #{}: {}", format!("{}", n).apply(Colour::White.bold()), h.hex().apply(Colour::White.bold()));
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
@@ -658,7 +666,12 @@ impl MinerService for Miner {
|
||||
// Client should send message after commit to db and inserting to chain.
|
||||
.expect("Expected in-chain blocks.");
|
||||
let block = BlockView::new(&block);
|
||||
block.transactions()
|
||||
let txs = block.transactions();
|
||||
// populate sender
|
||||
for tx in &txs {
|
||||
let _sender = tx.sender();
|
||||
}
|
||||
txs
|
||||
}
|
||||
|
||||
// 1. We ignore blocks that were `imported` (because it means that they are not in canon-chain, and transactions
|
||||
@@ -675,14 +688,10 @@ impl MinerService for Miner {
|
||||
.par_iter()
|
||||
.map(|h| fetch_transactions(chain, h));
|
||||
out_of_chain.for_each(|txs| {
|
||||
// populate sender
|
||||
for tx in &txs {
|
||||
let _sender = tx.sender();
|
||||
}
|
||||
let _ = self.import_transactions(chain, txs, |a| AccountDetails {
|
||||
nonce: chain.latest_nonce(a),
|
||||
balance: chain.latest_balance(a),
|
||||
});
|
||||
let mut transaction_queue = self.transaction_queue.lock().unwrap();
|
||||
let _ = self.add_transactions_to_queue(
|
||||
chain, txs, TransactionOrigin::External, &mut transaction_queue
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
//! use ethcore::miner::{Miner, MinerService};
|
||||
//!
|
||||
//! fn main() {
|
||||
//! let miner: Miner = Miner::with_spec(ethereum::new_frontier(true));
|
||||
//! let miner: Miner = Miner::with_spec(ethereum::new_frontier());
|
||||
//! // get status
|
||||
//! assert_eq!(miner.status().transactions_in_pending_queue, 0);
|
||||
//!
|
||||
@@ -107,14 +107,12 @@ pub trait MinerService : Send + Sync {
|
||||
fn set_tx_gas_limit(&self, limit: U256);
|
||||
|
||||
/// Imports transactions to transaction queue.
|
||||
fn import_transactions<T>(&self, chain: &MiningBlockChainClient, transactions: Vec<SignedTransaction>, fetch_account: T) ->
|
||||
Vec<Result<TransactionImportResult, Error>>
|
||||
where T: Fn(&Address) -> AccountDetails, Self: Sized;
|
||||
fn import_external_transactions(&self, chain: &MiningBlockChainClient, transactions: Vec<SignedTransaction>) ->
|
||||
Vec<Result<TransactionImportResult, Error>>;
|
||||
|
||||
/// Imports own (node owner) transaction to queue.
|
||||
fn import_own_transaction<T>(&self, chain: &MiningBlockChainClient, transaction: SignedTransaction, fetch_account: T) ->
|
||||
Result<TransactionImportResult, Error>
|
||||
where T: Fn(&Address) -> AccountDetails, Self: Sized;
|
||||
fn import_own_transaction(&self, chain: &MiningBlockChainClient, transaction: SignedTransaction) ->
|
||||
Result<TransactionImportResult, Error>;
|
||||
|
||||
/// Returns hashes of transactions currently in pending
|
||||
fn pending_transactions_hashes(&self) -> Vec<H256>;
|
||||
|
||||
@@ -198,6 +198,7 @@ struct VerifiedTransaction {
|
||||
/// transaction origin
|
||||
origin: TransactionOrigin,
|
||||
}
|
||||
|
||||
impl VerifiedTransaction {
|
||||
fn new(transaction: SignedTransaction, origin: TransactionOrigin) -> Result<Self, Error> {
|
||||
try!(transaction.sender());
|
||||
|
||||
@@ -72,7 +72,7 @@ impl fmt::Display for PodState {
|
||||
|
||||
/// Calculate and return diff between `pre` state and `post` state.
|
||||
pub fn diff_pod(pre: &PodState, post: &PodState) -> StateDiff {
|
||||
StateDiff(pre.get().keys().merge(post.get().keys()).filter_map(|acc| pod_account::diff_pod(pre.get().get(acc), post.get().get(acc)).map(|d|(acc.clone(), d))).collect())
|
||||
StateDiff { raw: pre.get().keys().merge(post.get().keys()).filter_map(|acc| pod_account::diff_pod(pre.get().get(acc), post.get().get(acc)).map(|d|(acc.clone(), d))).collect() }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -86,22 +86,22 @@ mod test {
|
||||
#[test]
|
||||
fn create_delete() {
|
||||
let a = PodState::from(map![ 1.into() => PodAccount::new(69.into(), 0.into(), vec![], map![]) ]);
|
||||
assert_eq!(super::diff_pod(&a, &PodState::new()), StateDiff(map![
|
||||
assert_eq!(super::diff_pod(&a, &PodState::new()), StateDiff { raw: map![
|
||||
1.into() => AccountDiff{
|
||||
balance: Diff::Died(69.into()),
|
||||
nonce: Diff::Died(0.into()),
|
||||
code: Diff::Died(vec![]),
|
||||
storage: map![],
|
||||
}
|
||||
]));
|
||||
assert_eq!(super::diff_pod(&PodState::new(), &a), StateDiff(map![
|
||||
]});
|
||||
assert_eq!(super::diff_pod(&PodState::new(), &a), StateDiff{ raw: map![
|
||||
1.into() => AccountDiff{
|
||||
balance: Diff::Born(69.into()),
|
||||
nonce: Diff::Born(0.into()),
|
||||
code: Diff::Born(vec![]),
|
||||
storage: map![],
|
||||
}
|
||||
]));
|
||||
]});
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -111,22 +111,22 @@ mod test {
|
||||
1.into() => PodAccount::new(69.into(), 0.into(), vec![], map![]),
|
||||
2.into() => PodAccount::new(69.into(), 0.into(), vec![], map![])
|
||||
]);
|
||||
assert_eq!(super::diff_pod(&a, &b), StateDiff(map![
|
||||
assert_eq!(super::diff_pod(&a, &b), StateDiff { raw: map![
|
||||
2.into() => AccountDiff{
|
||||
balance: Diff::Born(69.into()),
|
||||
nonce: Diff::Born(0.into()),
|
||||
code: Diff::Born(vec![]),
|
||||
storage: map![],
|
||||
}
|
||||
]));
|
||||
assert_eq!(super::diff_pod(&b, &a), StateDiff(map![
|
||||
]});
|
||||
assert_eq!(super::diff_pod(&b, &a), StateDiff { raw: map![
|
||||
2.into() => AccountDiff{
|
||||
balance: Diff::Died(69.into()),
|
||||
nonce: Diff::Died(0.into()),
|
||||
code: Diff::Died(vec![]),
|
||||
storage: map![],
|
||||
}
|
||||
]));
|
||||
]});
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -139,14 +139,14 @@ mod test {
|
||||
1.into() => PodAccount::new(69.into(), 1.into(), vec![], map![]),
|
||||
2.into() => PodAccount::new(69.into(), 0.into(), vec![], map![])
|
||||
]);
|
||||
assert_eq!(super::diff_pod(&a, &b), StateDiff(map![
|
||||
assert_eq!(super::diff_pod(&a, &b), StateDiff { raw: map![
|
||||
1.into() => AccountDiff{
|
||||
balance: Diff::Same,
|
||||
nonce: Diff::Changed(0.into(), 1.into()),
|
||||
code: Diff::Same,
|
||||
storage: map![],
|
||||
}
|
||||
]));
|
||||
]});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
//! Creates and registers client and network services.
|
||||
|
||||
use util::*;
|
||||
use util::Colour::{Yellow, White};
|
||||
use util::panics::*;
|
||||
use spec::Spec;
|
||||
use error::*;
|
||||
@@ -72,7 +71,7 @@ impl ClientService {
|
||||
try!(net_service.start());
|
||||
}
|
||||
|
||||
info!("Configured for {} using {} engine", paint(White.bold(), spec.name.clone()), paint(Yellow.bold(), spec.engine.name().to_owned()));
|
||||
info!("Configured for {} using {} engine", spec.name.clone().apply(Colour::White.bold()), spec.engine.name().apply(Colour::Yellow.bold()));
|
||||
let client = try!(Client::new(config, spec, db_path, miner, net_service.io().channel()));
|
||||
panic_handler.forward_from(client.deref());
|
||||
let client_io = Arc::new(ClientIoHandler {
|
||||
@@ -135,16 +134,14 @@ impl IoHandler<NetSyncMessage> for ClientIoHandler {
|
||||
|
||||
#[cfg_attr(feature="dev", allow(single_match))]
|
||||
fn message(&self, io: &IoContext<NetSyncMessage>, net_message: &NetSyncMessage) {
|
||||
if let UserMessage(ref message) = *net_message {
|
||||
match *message {
|
||||
SyncMessage::BlockVerified => {
|
||||
self.client.import_verified_blocks(&io.channel());
|
||||
},
|
||||
SyncMessage::NewTransactions(ref transactions) => {
|
||||
self.client.import_queued_transactions(&transactions);
|
||||
},
|
||||
_ => {}, // ignore other messages
|
||||
}
|
||||
match *net_message {
|
||||
UserMessage(ref message) => match *message {
|
||||
SyncMessage::BlockVerified => { self.client.import_verified_blocks(&io.channel()); }
|
||||
SyncMessage::NewTransactions(ref transactions) => { self.client.import_queued_transactions(&transactions); }
|
||||
_ => {} // ignore other messages
|
||||
},
|
||||
NetworkIoMessage::NetworkStarted(ref url) => { self.client.network_started(url); }
|
||||
_ => {} // ignore other messages
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +180,6 @@ pub fn generate_dummy_client_with_spec_and_data<F>(get_test_spec: F, block_numbe
|
||||
db,
|
||||
&last_header,
|
||||
last_hashes.clone(),
|
||||
None,
|
||||
author.clone(),
|
||||
(3141562.into(), 31415620.into()),
|
||||
vec![]
|
||||
|
||||
@@ -15,4 +15,5 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
pub mod helpers;
|
||||
mod client;
|
||||
mod client;
|
||||
mod rpc;
|
||||
|
||||
71
ethcore/src/tests/rpc.rs
Normal file
71
ethcore/src/tests/rpc.rs
Normal file
@@ -0,0 +1,71 @@
|
||||
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Client RPC tests
|
||||
|
||||
use nanoipc;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{Ordering, AtomicBool};
|
||||
use client::{Client, BlockChainClient, ClientConfig, RemoteClient, BlockID};
|
||||
use tests::helpers::*;
|
||||
use devtools::*;
|
||||
use miner::Miner;
|
||||
use crossbeam;
|
||||
use common::IoChannel;
|
||||
|
||||
pub fn run_test_worker(scope: &crossbeam::Scope, stop: Arc<AtomicBool>, socket_path: &str) {
|
||||
let socket_path = socket_path.to_owned();
|
||||
scope.spawn(move || {
|
||||
let temp = RandomTempPath::create_dir();
|
||||
let client = Client::new(
|
||||
ClientConfig::default(),
|
||||
get_test_spec(),
|
||||
temp.as_path(),
|
||||
Arc::new(Miner::with_spec(get_test_spec())),
|
||||
IoChannel::disconnected()).unwrap();
|
||||
let mut worker = nanoipc::Worker::new(&client);
|
||||
worker.add_reqrep(&socket_path).unwrap();
|
||||
while !stop.load(Ordering::Relaxed) {
|
||||
worker.poll();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_handshake() {
|
||||
crossbeam::scope(|scope| {
|
||||
let stop_guard = StopGuard::new();
|
||||
let socket_path = "ipc:///tmp/parity-client-rpc-10.ipc";
|
||||
run_test_worker(scope, stop_guard.share(), socket_path);
|
||||
let remote_client = nanoipc::init_client::<RemoteClient<_>>(socket_path).unwrap();
|
||||
|
||||
assert!(remote_client.handshake().is_ok());
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_query_block() {
|
||||
crossbeam::scope(|scope| {
|
||||
let stop_guard = StopGuard::new();
|
||||
let socket_path = "ipc:///tmp/parity-client-rpc-20.ipc";
|
||||
run_test_worker(scope, stop_guard.share(), socket_path);
|
||||
let remote_client = nanoipc::init_client::<RemoteClient<_>>(socket_path).unwrap();
|
||||
|
||||
let non_existant_block = remote_client.block_header(BlockID::Number(999));
|
||||
|
||||
assert!(non_existant_block.is_none());
|
||||
})
|
||||
}
|
||||
@@ -16,11 +16,17 @@
|
||||
|
||||
//! Diff between two accounts.
|
||||
|
||||
use util::*;
|
||||
use util::numbers::*;
|
||||
use std::cmp::*;
|
||||
use std::fmt;
|
||||
use ipc::binary::{BinaryConvertError, BinaryConvertable};
|
||||
use util::Bytes;
|
||||
use std::collections::{VecDeque, BTreeMap};
|
||||
use std::mem;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Binary)]
|
||||
/// Diff type for specifying a change (or not).
|
||||
pub enum Diff<T> where T: Eq {
|
||||
pub enum Diff<T> where T: Eq + BinaryConvertable {
|
||||
/// Both sides are the same.
|
||||
Same,
|
||||
/// Left (pre, source) side doesn't include value, right side (post, destination) does.
|
||||
@@ -31,7 +37,7 @@ pub enum Diff<T> where T: Eq {
|
||||
Died(T),
|
||||
}
|
||||
|
||||
impl<T> Diff<T> where T: Eq {
|
||||
impl<T> Diff<T> where T: Eq + BinaryConvertable {
|
||||
/// Construct new object with given `pre` and `post`.
|
||||
pub fn new(pre: T, post: T) -> Self { if pre == post { Diff::Same } else { Diff::Changed(pre, post) } }
|
||||
|
||||
@@ -45,7 +51,7 @@ impl<T> Diff<T> where T: Eq {
|
||||
pub fn is_same(&self) -> bool { match *self { Diff::Same => true, _ => false }}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Binary)]
|
||||
/// Account diff.
|
||||
pub struct AccountDiff {
|
||||
/// Change in balance, allowed to be `Diff::Same`.
|
||||
@@ -58,8 +64,8 @@ pub struct AccountDiff {
|
||||
pub storage: BTreeMap<H256, Diff<H256>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
/// Change in existance type.
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Binary)]
|
||||
/// Change in existance type.
|
||||
// TODO: include other types of change.
|
||||
pub enum Existance {
|
||||
/// Item came into existance.
|
||||
@@ -94,6 +100,8 @@ impl AccountDiff {
|
||||
|
||||
// TODO: refactor into something nicer.
|
||||
fn interpreted_hash(u: &H256) -> String {
|
||||
use util::bytes::*;
|
||||
|
||||
if u <= &H256::from(0xffffffff) {
|
||||
format!("{} = 0x{:x}", U256::from(u.as_slice()).low_u32(), U256::from(u.as_slice()).low_u32())
|
||||
} else if u <= &H256::from(u64::max_value()) {
|
||||
@@ -107,6 +115,8 @@ fn interpreted_hash(u: &H256) -> String {
|
||||
|
||||
impl fmt::Display for AccountDiff {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
use util::bytes::*;
|
||||
|
||||
match self.nonce {
|
||||
Diff::Born(ref x) => try!(write!(f, " non {}", x)),
|
||||
Diff::Changed(ref pre, ref post) => try!(write!(f, "#{} ({} {} {})", post, pre, if pre > post {"-"} else {"+"}, *max(pre, post) - * min(pre, post))),
|
||||
|
||||
38
ethcore/src/types/block_queue_info.rs
Normal file
38
ethcore/src/types/block_queue_info.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Block queue info types
|
||||
|
||||
use std::mem;
|
||||
use ipc::binary::BinaryConvertError;
|
||||
use std::collections::VecDeque;
|
||||
|
||||
/// Block queue status
|
||||
#[derive(Debug, Binary)]
|
||||
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,
|
||||
}
|
||||
32
ethcore/src/types/call_analytics.rs
Normal file
32
ethcore/src/types/call_analytics.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Call analytics related types
|
||||
|
||||
use std::mem;
|
||||
use ipc::binary::{BinaryConvertError};
|
||||
use std::collections::VecDeque;
|
||||
|
||||
/// Options concerning what analytics we run on the call.
|
||||
#[derive(Eq, PartialEq, Default, Clone, Copy, Debug, Binary)]
|
||||
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,
|
||||
}
|
||||
@@ -27,7 +27,7 @@ use std::mem;
|
||||
use std::collections::VecDeque;
|
||||
|
||||
/// Transaction execution receipt.
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[derive(Debug, PartialEq, Clone, Binary)]
|
||||
pub struct Executed {
|
||||
/// Gas paid up front for execution of transaction.
|
||||
pub gas: U256,
|
||||
|
||||
@@ -20,8 +20,12 @@ use util::hash::*;
|
||||
use util::sha3::*;
|
||||
use client::BlockID;
|
||||
use log_entry::LogEntry;
|
||||
use ipc::binary::BinaryConvertError;
|
||||
use std::mem;
|
||||
use std::collections::VecDeque;
|
||||
|
||||
/// Blockchain Filter.
|
||||
#[derive(Binary)]
|
||||
pub struct Filter {
|
||||
/// Blockchain will be searched from this block.
|
||||
pub from_block: BlockID,
|
||||
@@ -29,22 +33,27 @@ pub struct Filter {
|
||||
/// Till this block.
|
||||
pub to_block: BlockID,
|
||||
|
||||
/// Search addresses.
|
||||
///
|
||||
/// Search addresses.
|
||||
///
|
||||
/// If None, match all.
|
||||
/// If specified, log must be produced by one of these addresses.
|
||||
pub address: Option<Vec<Address>>,
|
||||
|
||||
/// Search topics.
|
||||
///
|
||||
///
|
||||
/// If None, match all.
|
||||
/// If specified, log must contain one of these topics.
|
||||
pub topics: [Option<Vec<H256>>; 4],
|
||||
pub topics: Vec<Option<Vec<H256>>>,
|
||||
}
|
||||
|
||||
impl Clone for Filter {
|
||||
fn clone(&self) -> Self {
|
||||
let mut topics = [None, None, None, None];
|
||||
let mut topics = [
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
];
|
||||
for i in 0..4 {
|
||||
topics[i] = self.topics[i].clone();
|
||||
}
|
||||
@@ -53,13 +62,13 @@ impl Clone for Filter {
|
||||
from_block: self.from_block.clone(),
|
||||
to_block: self.to_block.clone(),
|
||||
address: self.address.clone(),
|
||||
topics: topics
|
||||
topics: topics[..].to_vec()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Filter {
|
||||
/// Returns combinations of each address and topic.
|
||||
/// Returns combinations of each address and topic.
|
||||
pub fn bloom_possibilities(&self) -> Vec<H2048> {
|
||||
let blooms = match self.address {
|
||||
Some(ref addresses) if !addresses.is_empty() =>
|
||||
@@ -71,7 +80,7 @@ impl Filter {
|
||||
_ => vec![H2048::new()]
|
||||
};
|
||||
|
||||
self.topics.iter().fold(blooms, | bs, topic | match *topic {
|
||||
self.topics.iter().fold(blooms, |bs, topic| match *topic {
|
||||
None => bs,
|
||||
Some(ref topics) => bs.into_iter().flat_map(|bloom| {
|
||||
topics.into_iter().map(|topic| {
|
||||
@@ -111,7 +120,7 @@ mod tests {
|
||||
from_block: BlockID::Earliest,
|
||||
to_block: BlockID::Latest,
|
||||
address: None,
|
||||
topics: [None, None, None, None]
|
||||
topics: vec![None, None, None, None],
|
||||
};
|
||||
|
||||
let possibilities = none_filter.bloom_possibilities();
|
||||
@@ -126,9 +135,11 @@ mod tests {
|
||||
from_block: BlockID::Earliest,
|
||||
to_block: BlockID::Latest,
|
||||
address: Some(vec![Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5d").unwrap()]),
|
||||
topics: [
|
||||
topics: vec![
|
||||
Some(vec![H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap()]),
|
||||
None, None, None
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
]
|
||||
};
|
||||
|
||||
@@ -142,10 +153,11 @@ mod tests {
|
||||
from_block: BlockID::Earliest,
|
||||
to_block: BlockID::Latest,
|
||||
address: Some(vec![Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5d").unwrap()]),
|
||||
topics: [
|
||||
topics: vec![
|
||||
Some(vec![H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap()]),
|
||||
Some(vec![H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap()]),
|
||||
None, None
|
||||
None,
|
||||
None,
|
||||
]
|
||||
};
|
||||
|
||||
@@ -162,7 +174,7 @@ mod tests {
|
||||
Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5d").unwrap(),
|
||||
Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5d").unwrap(),
|
||||
]),
|
||||
topics: [
|
||||
topics: vec![
|
||||
Some(vec![
|
||||
H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap(),
|
||||
H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap()
|
||||
@@ -188,10 +200,11 @@ mod tests {
|
||||
from_block: BlockID::Earliest,
|
||||
to_block: BlockID::Latest,
|
||||
address: Some(vec![Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5d").unwrap()]),
|
||||
topics: [
|
||||
topics: vec![
|
||||
Some(vec![H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap()]),
|
||||
Some(vec![H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23fa").unwrap()]),
|
||||
None, None
|
||||
None,
|
||||
None,
|
||||
]
|
||||
};
|
||||
|
||||
@@ -47,6 +47,7 @@ pub enum TransactionID {
|
||||
}
|
||||
|
||||
/// Uniquely identifies Trace.
|
||||
#[derive(Binary)]
|
||||
pub struct TraceId {
|
||||
/// Transaction
|
||||
pub transaction: TransactionID,
|
||||
|
||||
@@ -25,5 +25,9 @@ pub mod executed;
|
||||
pub mod block_status;
|
||||
pub mod account_diff;
|
||||
pub mod state_diff;
|
||||
pub mod block_queue_info;
|
||||
pub mod filter;
|
||||
pub mod trace_filter;
|
||||
pub mod call_analytics;
|
||||
pub mod transaction_import;
|
||||
pub mod block_import_error;
|
||||
|
||||
@@ -16,24 +16,32 @@
|
||||
|
||||
//! State diff module.
|
||||
|
||||
use util::*;
|
||||
use util::numbers::*;
|
||||
use account_diff::*;
|
||||
use ipc::binary::BinaryConvertError;
|
||||
use std::mem;
|
||||
use std::fmt;
|
||||
use std::ops::*;
|
||||
use std::collections::{VecDeque, BTreeMap};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Binary)]
|
||||
/// Expression for the delta between two system states. Encoded the
|
||||
/// delta of every altered account.
|
||||
pub struct StateDiff (pub BTreeMap<Address, AccountDiff>);
|
||||
pub struct StateDiff {
|
||||
/// Raw diff key-value
|
||||
pub raw: BTreeMap<Address, AccountDiff>
|
||||
}
|
||||
|
||||
impl StateDiff {
|
||||
/// Get the actual data.
|
||||
pub fn get(&self) -> &BTreeMap<Address, AccountDiff> {
|
||||
&self.0
|
||||
&self.raw
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for StateDiff {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
for (add, acc) in &self.0 {
|
||||
for (add, acc) in &self.raw {
|
||||
try!(write!(f, "{} {}: {}", acc.existance(), add, acc));
|
||||
}
|
||||
Ok(())
|
||||
@@ -44,6 +52,6 @@ impl Deref for StateDiff {
|
||||
type Target = BTreeMap<Address, AccountDiff>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
&self.raw
|
||||
}
|
||||
}
|
||||
|
||||
35
ethcore/src/types/trace_filter.rs
Normal file
35
ethcore/src/types/trace_filter.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Trace filter related types
|
||||
|
||||
use std::mem;
|
||||
use ipc::binary::{BinaryConvertError};
|
||||
use std::collections::VecDeque;
|
||||
use std::ops::Range;
|
||||
use util::{Address};
|
||||
use types::ids::BlockID;
|
||||
|
||||
/// Easy to use trace filter.
|
||||
#[derive(Binary)]
|
||||
pub struct Filter {
|
||||
/// Range of filtering.
|
||||
pub range: Range<BlockID>,
|
||||
/// From address.
|
||||
pub from_address: Vec<Address>,
|
||||
/// To address.
|
||||
pub to_address: Vec<Address>,
|
||||
}
|
||||
@@ -17,9 +17,12 @@
|
||||
//! Tree route info type definition
|
||||
|
||||
use util::numbers::H256;
|
||||
use ipc::BinaryConvertError;
|
||||
use std::collections::VecDeque;
|
||||
use std::mem;
|
||||
|
||||
/// Represents a tree route between `from` block and `to` block:
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Binary)]
|
||||
pub struct TreeRoute {
|
||||
/// A vector of hashes of all blocks, ordered from `from` to `to`.
|
||||
pub blocks: Vec<H256>,
|
||||
|
||||
Reference in New Issue
Block a user