From 3650f2d51c1e7eeb019f4094bd3c373c247e185d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Fri, 4 Jan 2019 14:05:46 +0100 Subject: [PATCH] Extract blockchain from ethcore (#10114) * Split blockchain & db from ethcore. * Clean up blockchain deps. * Missing docs. * Fix blockchain tests. * Make other crates compile. * Remove some re-exports. * Remove types re-export from ethcore. * Remove EVM dependency from transaction. * Merge ethcore-transaction with common-types. * Clean-up ethcore deps a bit. * remove ethcore from cargo.toml * Update ethcore/blockchain/src/lib.rs Co-Authored-By: tomusdrw * Address review comments. * Update DB comment. * Add tracking issue to the TODO and fix typo. * Common naming for common types. * Update ethcore/db/src/keys.rs Co-Authored-By: tomusdrw * Update ethcore/blockchain/src/generator.rs Co-Authored-By: tomusdrw * Try to fix beta tests. --- Cargo.lock | 101 +++++++----- Cargo.toml | 5 +- ethcore/Cargo.toml | 88 +++++----- ethcore/blockchain/Cargo.toml | 33 ++++ .../src}/best_block.rs | 4 +- .../src}/block_info.rs | 2 +- .../src}/blockchain.rs | 156 +++++++++--------- .../blockchain => blockchain/src}/cache.rs | 0 .../blockchain => blockchain/src}/config.rs | 0 .../src}/generator.rs | 34 +++- .../src}/import_route.rs | 7 +- .../mod.rs => blockchain/src/lib.rs} | 8 +- .../blockchain => blockchain/src}/update.rs | 13 +- ethcore/db/Cargo.toml | 17 ++ ethcore/{ => db}/src/cache_manager.rs | 5 + ethcore/{ => db}/src/db.rs | 0 .../blockchain/extras.rs => db/src/keys.rs} | 18 +- ethcore/db/src/lib.rs | 26 +++ ethcore/light/Cargo.toml | 6 +- ethcore/light/src/cache.rs | 12 +- ethcore/light/src/cht.rs | 2 +- ethcore/light/src/client/fetch.rs | 8 +- ethcore/light/src/client/header_chain.rs | 16 +- ethcore/light/src/client/mod.rs | 11 +- ethcore/light/src/client/service.rs | 3 +- ethcore/light/src/lib.rs | 4 +- ethcore/light/src/net/mod.rs | 3 +- ethcore/light/src/net/tests/mod.rs | 14 +- ethcore/light/src/on_demand/request.rs | 16 +- ethcore/light/src/on_demand/tests.rs | 4 +- ethcore/light/src/provider.rs | 12 +- ethcore/light/src/transaction_queue.rs | 4 +- ethcore/light/src/types/request/mod.rs | 34 ++-- ethcore/private-tx/Cargo.toml | 8 +- ethcore/private-tx/src/error.rs | 2 +- ethcore/private-tx/src/lib.rs | 16 +- ethcore/private-tx/src/messages.rs | 2 +- .../private-tx/src/private_transactions.rs | 2 +- ethcore/private-tx/tests/private_contract.rs | 12 +- ethcore/service/Cargo.toml | 2 + ethcore/service/src/lib.rs | 6 +- ethcore/service/src/service.rs | 4 +- ethcore/src/account_provider/mod.rs | 2 +- ethcore/src/block.rs | 116 +++++-------- ethcore/src/client/ancient_import.rs | 6 +- ethcore/src/client/chain_notify.rs | 2 +- ethcore/src/client/client.rs | 64 ++++--- ethcore/src/client/evm_test_client.rs | 3 +- ethcore/src/client/test_client.rs | 71 ++++---- ethcore/src/client/trace.rs | 7 +- ethcore/src/client/traits.rs | 51 +++--- ethcore/src/engines/authority_round/mod.rs | 7 +- ethcore/src/engines/basic_authority.rs | 4 +- ethcore/src/engines/instant_seal.rs | 2 +- ethcore/src/engines/mod.rs | 23 +-- ethcore/src/engines/null_engine.rs | 4 +- ethcore/src/engines/validator_set/contract.rs | 9 +- ethcore/src/engines/validator_set/mod.rs | 11 +- ethcore/src/engines/validator_set/multi.rs | 11 +- .../engines/validator_set/safe_contract.rs | 32 ++-- .../src/engines/validator_set/simple_list.rs | 5 +- ethcore/src/engines/validator_set/test.rs | 10 +- ethcore/src/error.rs | 23 +-- ethcore/src/ethereum/ethash.rs | 23 +-- ethcore/src/ethereum/mod.rs | 3 +- ethcore/src/executed.rs | 4 +- ethcore/src/executive.rs | 7 +- ethcore/src/externalities.rs | 4 +- ethcore/src/json_tests/difficulty.rs | 2 +- ethcore/src/json_tests/state.rs | 2 +- ethcore/src/json_tests/transaction.rs | 7 +- ethcore/src/lib.rs | 75 ++++----- ethcore/src/machine.rs | 23 +-- ethcore/src/miner/miner.rs | 25 +-- ethcore/src/miner/mod.rs | 14 +- ethcore/src/miner/pool_client.rs | 5 +- .../src/miner/service_transaction_checker.rs | 2 +- ethcore/src/snapshot/account.rs | 4 +- ethcore/src/snapshot/block.rs | 21 +-- ethcore/src/snapshot/consensus/authority.rs | 21 ++- ethcore/src/snapshot/consensus/work.rs | 4 +- ethcore/src/snapshot/error.rs | 2 +- ethcore/src/snapshot/mod.rs | 4 +- ethcore/src/snapshot/service.rs | 2 +- ethcore/src/snapshot/tests/helpers.rs | 4 +- .../src/snapshot/tests/proof_of_authority.rs | 2 +- ethcore/src/snapshot/tests/service.rs | 6 +- ethcore/src/snapshot/tests/state.rs | 2 +- ethcore/src/snapshot/watcher.rs | 2 +- ethcore/src/spec/spec.rs | 10 +- ethcore/src/state/account.rs | 2 +- ethcore/src/state/mod.rs | 6 +- ethcore/src/state/substate.rs | 4 +- ethcore/src/state_db.rs | 5 +- ethcore/src/test_helpers.rs | 37 +++-- ethcore/src/tests/blockchain.rs | 61 +++++++ ethcore/src/tests/client.rs | 30 ++-- ethcore/src/tests/evm.rs | 2 +- ethcore/src/tests/mod.rs | 1 + ethcore/src/tests/trace.rs | 7 +- ethcore/src/trace/db.rs | 17 +- ethcore/src/trace/import.rs | 3 +- ethcore/src/trace/mod.rs | 2 +- ethcore/src/trace/types/localized.rs | 2 +- ethcore/src/transaction_ext.rs | 44 +++++ ethcore/src/tx_filter.rs | 4 +- ethcore/src/verification/canon_verifier.rs | 2 +- ethcore/src/verification/noop_verifier.rs | 2 +- ethcore/src/verification/queue/kind.rs | 6 +- ethcore/src/verification/queue/mod.rs | 9 +- ethcore/src/verification/verification.rs | 26 ++- ethcore/src/verification/verifier.rs | 2 +- ethcore/sync/Cargo.toml | 24 +-- ethcore/sync/src/api.rs | 8 +- ethcore/sync/src/block_sync.rs | 6 +- ethcore/sync/src/blocks.rs | 6 +- ethcore/sync/src/chain/handler.rs | 8 +- ethcore/sync/src/chain/mod.rs | 6 +- ethcore/sync/src/chain/propagator.rs | 11 +- ethcore/sync/src/chain/requester.rs | 2 +- ethcore/sync/src/chain/supplier.rs | 4 +- ethcore/sync/src/lib.rs | 16 +- ethcore/sync/src/light_sync/mod.rs | 2 +- ethcore/sync/src/light_sync/response.rs | 6 +- ethcore/sync/src/light_sync/sync_round.rs | 4 +- ethcore/sync/src/sync_io.rs | 2 +- ethcore/sync/src/tests/consensus.rs | 2 +- ethcore/sync/src/tests/helpers.rs | 2 +- ethcore/sync/src/tests/private.rs | 2 +- ethcore/sync/src/tests/snapshot.rs | 2 +- ethcore/sync/src/transactions_stats.rs | 2 +- ethcore/transaction/Cargo.toml | 21 --- ethcore/types/Cargo.toml | 11 +- ethcore/types/src/block.rs | 77 +++++++++ ethcore/types/src/block_status.rs | 2 + ethcore/{ => types}/src/encoded.rs | 3 +- ethcore/{ => types}/src/engines/epoch.rs | 0 ethcore/types/src/engines/mod.rs | 29 ++++ ethcore/{ => types}/src/header.rs | 10 +- ethcore/types/src/lib.rs | 37 ++++- .../src => types/src/transaction}/error.rs | 0 .../lib.rs => types/src/transaction/mod.rs} | 16 +- .../src/transaction}/transaction.rs | 19 +-- ethcore/{ => types}/src/views/block.rs | 4 +- ethcore/{ => types}/src/views/body.rs | 21 ++- ethcore/{ => types}/src/views/header.rs | 10 +- ethcore/{ => types}/src/views/mod.rs | 0 ethcore/{ => types}/src/views/transaction.rs | 9 +- ethcore/{ => types}/src/views/view_rlp.rs | 0 ethcore/vm/Cargo.toml | 1 - ethcore/vm/src/env_info.rs | 3 +- ethcore/vm/src/lib.rs | 1 - evmbin/Cargo.toml | 6 +- evmbin/src/info.rs | 2 +- evmbin/src/main.rs | 2 +- miner/Cargo.toml | 4 +- miner/local-store/Cargo.toml | 4 +- miner/local-store/src/lib.rs | 16 +- miner/src/lib.rs | 4 +- miner/src/pool/client.rs | 2 +- miner/src/pool/listener.rs | 2 +- miner/src/pool/local_transactions.rs | 2 +- miner/src/pool/mod.rs | 2 +- miner/src/pool/queue.rs | 2 +- miner/src/pool/ready.rs | 2 +- miner/src/pool/tests/client.rs | 2 +- miner/src/pool/tests/mod.rs | 4 +- miner/src/pool/tests/tx.rs | 2 +- miner/src/pool/verifier.rs | 2 +- parity/account.rs | 8 +- parity/blockchain.rs | 4 +- parity/configuration.rs | 2 +- parity/db/rocksdb/helpers.rs | 2 +- parity/db/rocksdb/migration.rs | 4 +- parity/db/rocksdb/mod.rs | 5 +- parity/export_hardcoded_sync.rs | 2 +- parity/informant.rs | 2 +- parity/lib.rs | 4 +- parity/light_helpers/epoch_fetch.rs | 6 +- parity/presale.rs | 4 +- parity/run.rs | 12 +- parity/snapshot.rs | 2 +- rpc/Cargo.toml | 2 +- rpc/src/lib.rs | 2 +- rpc/src/v1/helpers/dispatch.rs | 6 +- rpc/src/v1/helpers/errors.rs | 4 +- rpc/src/v1/helpers/fake_sign.rs | 2 +- rpc/src/v1/helpers/light_fetch.rs | 12 +- rpc/src/v1/helpers/poll_filter.rs | 2 +- rpc/src/v1/impls/debug.rs | 2 +- rpc/src/v1/impls/eth.rs | 16 +- rpc/src/v1/impls/eth_filter.rs | 4 +- rpc/src/v1/impls/eth_pubsub.rs | 14 +- rpc/src/v1/impls/light/eth.rs | 12 +- rpc/src/v1/impls/light/parity.rs | 2 +- rpc/src/v1/impls/parity.rs | 12 +- rpc/src/v1/impls/personal.rs | 2 +- rpc/src/v1/impls/private.rs | 2 +- rpc/src/v1/impls/signer.rs | 2 +- rpc/src/v1/impls/traces.rs | 2 +- rpc/src/v1/tests/eth.rs | 8 +- rpc/src/v1/tests/helpers/miner_service.rs | 14 +- rpc/src/v1/tests/mocked/eth.rs | 16 +- rpc/src/v1/tests/mocked/eth_pubsub.rs | 4 +- rpc/src/v1/tests/mocked/parity.rs | 6 +- rpc/src/v1/tests/mocked/parity_set.rs | 2 +- rpc/src/v1/tests/mocked/personal.rs | 2 +- rpc/src/v1/tests/mocked/signer.rs | 2 +- rpc/src/v1/tests/mocked/signing.rs | 2 +- rpc/src/v1/types/block.rs | 6 +- rpc/src/v1/types/filter.rs | 15 +- rpc/src/v1/types/log.rs | 2 +- rpc/src/v1/types/receipt.rs | 2 +- rpc/src/v1/types/trace.rs | 14 +- rpc/src/v1/types/transaction.rs | 2 +- rpc/src/v1/types/transaction_condition.rs | 2 +- secret-store/Cargo.toml | 2 +- secret-store/src/lib.rs | 8 +- secret-store/src/listener/service_contract.rs | 2 +- secret-store/src/trusted_client.rs | 2 +- updater/Cargo.toml | 21 +-- updater/src/lib.rs | 5 +- updater/src/updater.rs | 4 +- 223 files changed, 1428 insertions(+), 1058 deletions(-) create mode 100644 ethcore/blockchain/Cargo.toml rename ethcore/{src/blockchain => blockchain/src}/best_block.rs (95%) rename ethcore/{src/blockchain => blockchain/src}/block_info.rs (98%) rename ethcore/{src/blockchain => blockchain/src}/blockchain.rs (97%) rename ethcore/{src/blockchain => blockchain/src}/cache.rs (100%) rename ethcore/{src/blockchain => blockchain/src}/config.rs (100%) rename ethcore/{src/blockchain => blockchain/src}/generator.rs (83%) rename ethcore/{src/blockchain => blockchain/src}/import_route.rs (94%) rename ethcore/{src/blockchain/mod.rs => blockchain/src/lib.rs} (88%) rename ethcore/{src/blockchain => blockchain/src}/update.rs (86%) create mode 100644 ethcore/db/Cargo.toml rename ethcore/{ => db}/src/cache_manager.rs (94%) rename ethcore/{ => db}/src/db.rs (100%) rename ethcore/{src/blockchain/extras.rs => db/src/keys.rs} (92%) create mode 100644 ethcore/db/src/lib.rs create mode 100644 ethcore/src/tests/blockchain.rs create mode 100644 ethcore/src/transaction_ext.rs delete mode 100644 ethcore/transaction/Cargo.toml create mode 100644 ethcore/types/src/block.rs rename ethcore/{ => types}/src/encoded.rs (99%) rename ethcore/{ => types}/src/engines/epoch.rs (100%) create mode 100644 ethcore/types/src/engines/mod.rs rename ethcore/{ => types}/src/header.rs (98%) rename ethcore/{transaction/src => types/src/transaction}/error.rs (100%) rename ethcore/{transaction/src/lib.rs => types/src/transaction/mod.rs} (73%) rename ethcore/{transaction/src => types/src/transaction}/transaction.rs (97%) rename ethcore/{ => types}/src/views/block.rs (98%) rename ethcore/{ => types}/src/views/body.rs (92%) rename ethcore/{ => types}/src/views/header.rs (98%) rename ethcore/{ => types}/src/views/mod.rs (100%) rename ethcore/{ => types}/src/views/transaction.rs (96%) rename ethcore/{ => types}/src/views/view_rlp.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 5dfa0acdc..dec069ec6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -291,12 +291,15 @@ version = "0.1.0" dependencies = [ "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethjson 0.1.0", + "ethkey 0.3.0", "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-machine 0.1.0", "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp_derive 0.1.0", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unexpected 0.1.0", ] [[package]] @@ -583,15 +586,6 @@ dependencies = [ "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "env_logger" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "env_logger" version = "0.5.13" @@ -693,18 +687,19 @@ dependencies = [ "common-types 0.1.0", "criterion 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethabi 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethabi-contract 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethabi-derive 6.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "ethash 1.12.0", + "ethcore-blockchain 0.1.0", "ethcore-bloom-journal 0.1.0", + "ethcore-db 0.1.0", "ethcore-io 1.12.0", "ethcore-logger 1.12.0", "ethcore-miner 1.12.0", "ethcore-stratum 1.12.0", - "ethcore-transaction 0.1.0", "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethjson 0.1.0", "ethkey 0.3.0", @@ -756,6 +751,33 @@ dependencies = [ "wasm 0.1.0", ] +[[package]] +name = "ethcore-blockchain" +version = "0.1.0" +dependencies = [ + "ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", + "blooms-db 0.1.0", + "common-types 0.1.0", + "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", + "ethcore-db 0.1.0", + "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethkey 0.3.0", + "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "kvdb-memorydb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp_compress 0.1.0", + "rlp_derive 0.1.0", + "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "ethcore-bloom-journal" version = "0.1.0" @@ -763,6 +785,19 @@ dependencies = [ "siphasher 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ethcore-db" +version = "0.1.0" +dependencies = [ + "common-types 0.1.0", + "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp_derive 0.1.0", +] + [[package]] name = "ethcore-io" version = "1.12.0" @@ -785,11 +820,13 @@ name = "ethcore-light" version = "1.12.0" dependencies = [ "bincode 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "common-types 0.1.0", "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.12.0", + "ethcore-blockchain 0.1.0", + "ethcore-db 0.1.0", "ethcore-io 1.12.0", "ethcore-network 1.12.0", - "ethcore-transaction 0.1.0", "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "failsafe 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "fastmap 0.1.0", @@ -840,10 +877,10 @@ name = "ethcore-miner" version = "1.12.0" dependencies = [ "ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", + "common-types 0.1.0", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethash 1.12.0", - "ethcore-transaction 0.1.0", "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethkey 0.3.0", "fetch 0.1.0", @@ -919,6 +956,7 @@ dependencies = [ name = "ethcore-private-tx" version = "1.0.0" dependencies = [ + "common-types 0.1.0", "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethabi 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethabi-contract 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -927,7 +965,6 @@ dependencies = [ "ethcore-io 1.12.0", "ethcore-logger 1.12.0", "ethcore-miner 1.12.0", - "ethcore-transaction 0.1.0", "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethjson 0.1.0", "ethkey 0.3.0", @@ -958,13 +995,13 @@ name = "ethcore-secretstore" version = "1.0.0" dependencies = [ "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "common-types 0.1.0", "ethabi 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethabi-contract 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethabi-derive 6.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.12.0", "ethcore-logger 1.12.0", "ethcore-sync 1.12.0", - "ethcore-transaction 0.1.0", "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethkey 0.3.0", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", @@ -997,6 +1034,8 @@ dependencies = [ "ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.12.0", + "ethcore-blockchain 0.1.0", + "ethcore-db 0.1.0", "ethcore-io 1.12.0", "ethcore-private-tx 1.0.0", "ethcore-sync 1.12.0", @@ -1037,9 +1076,9 @@ dependencies = [ "ethcore-network 1.12.0", "ethcore-network-devp2p 1.12.0", "ethcore-private-tx 1.0.0", - "ethcore-transaction 0.1.0", "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethkey 0.3.0", + "ethstore 0.2.0", "fastmap 0.1.0", "hashdb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1058,21 +1097,6 @@ dependencies = [ "triehash-ethereum 0.2.0", ] -[[package]] -name = "ethcore-transaction" -version = "0.1.0" -dependencies = [ - "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethjson 0.1.0", - "ethkey 0.3.0", - "evm 0.1.0", - "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "unexpected 0.1.0", -] - [[package]] name = "ethereum-types" version = "0.4.0" @@ -1205,10 +1229,10 @@ dependencies = [ name = "evmbin" version = "0.1.0" dependencies = [ + "common-types 0.1.0", "docopt 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.12.0", - "ethcore-transaction 0.1.0", "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethjson 0.1.0", "evm 0.1.0", @@ -2357,12 +2381,15 @@ dependencies = [ "blooms-db 0.1.0", "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "cli-signer 1.4.0", + "common-types 0.1.0", "ctrlc 1.1.1 (git+https://github.com/paritytech/rust-ctrlc.git)", "daemonize 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "dir 0.1.2", "docopt 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.12.0", + "ethcore-blockchain 0.1.0", + "ethcore-db 0.1.0", "ethcore-io 1.12.0", "ethcore-light 1.12.0", "ethcore-logger 1.12.0", @@ -2372,9 +2399,9 @@ dependencies = [ "ethcore-secretstore 1.0.0", "ethcore-service 0.1.0", "ethcore-sync 1.12.0", - "ethcore-transaction 0.1.0", "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethkey 0.3.0", + "ethstore 0.2.0", "fake-fetch 0.0.1", "fdlimit 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2461,9 +2488,8 @@ dependencies = [ name = "parity-local-store" version = "0.1.0" dependencies = [ - "ethcore 1.12.0", + "common-types 0.1.0", "ethcore-io 1.12.0", - "ethcore-transaction 0.1.0", "ethkey 0.3.0", "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb-memorydb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2513,6 +2539,7 @@ version = "1.12.0" dependencies = [ "ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "cid 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "common-types 0.1.0", "eip-712 0.1.0", "ethash 1.12.0", "ethcore 1.12.0", @@ -2523,7 +2550,6 @@ dependencies = [ "ethcore-network 1.12.0", "ethcore-private-tx 1.0.0", "ethcore-sync 1.12.0", - "ethcore-transaction 0.1.0", "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethjson 0.1.0", "ethkey 0.3.0", @@ -2635,6 +2661,7 @@ dependencies = [ name = "parity-updater" version = "1.12.0" dependencies = [ + "common-types 0.1.0", "ethabi 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethabi-contract 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethabi-derive 6.0.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4131,7 +4158,6 @@ name = "vm" version = "0.1.0" dependencies = [ "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "common-types 0.1.0", "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethjson 0.1.0", "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4393,7 +4419,6 @@ dependencies = [ "checksum edit-distance 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3bd26878c3d921f89797a4e1a1711919f999a9f6946bb6f5a4ffda126d297b7e" "checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0" "checksum elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "88d4851b005ef16de812ea9acdb7bece2f0a40dd86c07b85631d7dafa54537bb" -"checksum env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3ddf21e73e016298f5cb37d6ef8e8da8e39f91f9ec8b0df44b7deb16a9f8cd5b" "checksum env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)" = "15b0a4d2e39f8420210be8b27eeda28029729e2fd4291019455016c348240c38" "checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02" "checksum eth-secp256k1 0.5.7 (git+https://github.com/paritytech/rust-secp256k1)" = "" diff --git a/Cargo.toml b/Cargo.toml index 498694554..b4499ae19 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,9 @@ ctrlc = { git = "https://github.com/paritytech/rust-ctrlc.git" } jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-2.2" } ethcore = { path = "ethcore", features = ["parity"] } parity-bytes = "0.1" +common-types = { path = "ethcore/types" } +ethcore-blockchain = { path = "ethcore/blockchain" } +ethcore-db = { path = "ethcore/db" } ethcore-io = { path = "util/io" } ethcore-light = { path = "ethcore/light" } ethcore-logger = { path = "logger" } @@ -41,7 +44,7 @@ ethcore-network = { path = "util/network" } ethcore-private-tx = { path = "ethcore/private-tx" } ethcore-service = { path = "ethcore/service" } ethcore-sync = { path = "ethcore/sync" } -ethcore-transaction = { path = "ethcore/transaction" } +ethstore = { path = "accounts/ethstore" } ethereum-types = "0.4" node-filter = { path = "ethcore/node-filter" } ethkey = { path = "accounts/ethkey" } diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index 8eb132014..5013821ab 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -8,68 +8,68 @@ authors = ["Parity Technologies "] [dependencies] ansi_term = "0.10" -blooms-db = { path = "../util/blooms-db" } +blooms-db = { path = "../util/blooms-db", optional = true } bn = { git = "https://github.com/paritytech/bn", default-features = false } byteorder = "1.0" common-types = { path = "types" } crossbeam = "0.4" -ethash = { path = "../ethash" } -ethcore-bloom-journal = { path = "../util/bloom" } -parity-bytes = "0.1" -hashdb = "0.3.0" -memorydb = "0.3.0" -patricia-trie = "0.3.0" -patricia-trie-ethereum = { path = "../util/patricia-trie-ethereum" } -parity-crypto = "0.2" error-chain = { version = "0.12", default-features = false } +ethabi = "6.0" +ethabi-contract = "6.0" +ethabi-derive = "6.0" +ethash = { path = "../ethash" } +ethcore-blockchain = { path = "./blockchain" } +ethcore-bloom-journal = { path = "../util/bloom" } +ethcore-db = { path = "./db" } ethcore-io = { path = "../util/io" } -ethcore-logger = { path = "../logger" } +ethcore-logger = { path = "../logger", optional = true } ethcore-miner = { path = "../miner" } ethcore-stratum = { path = "../miner/stratum", optional = true } -ethcore-transaction = { path = "./transaction" } ethereum-types = "0.4" -memory-cache = { path = "../util/memory-cache" } -ethabi = "6.0" -ethabi-derive = "6.0" -ethabi-contract = "6.0" ethjson = { path = "../json" } ethkey = { path = "../accounts/ethkey" } ethstore = { path = "../accounts/ethstore" } evm = { path = "evm" } +hashdb = "0.3.0" heapsize = "0.4" itertools = "0.5" -lazy_static = "1.0" -log = "0.4" -lru-cache = "0.1" -num = { version = "0.1", default-features = false, features = ["bigint"] } -num_cpus = "1.2" -parity-machine = { path = "../machine" } -parking_lot = "0.7" -rayon = "1.0" -rand = "0.4" -rlp = { version = "0.3.0", features = ["ethereum"] } -rlp_compress = { path = "../util/rlp-compress" } -rlp_derive = { path = "../util/rlp-derive" } +journaldb = { path = "../util/journaldb" } +keccak-hash = "0.1" +keccak-hasher = { path = "../util/keccak-hasher" } kvdb = "0.1" kvdb-memorydb = "0.1" -parity-snappy = "0.1" +kvdb-rocksdb = { version = "0.1.3", optional = true } +lazy_static = "1.0" +len-caching-lock = { path = "../util/len-caching-lock" } +log = "0.4" +lru-cache = "0.1" macros = { path = "../util/macros" } +memory-cache = { path = "../util/memory-cache" } +memorydb = "0.3.0" +num = { version = "0.1", default-features = false, features = ["bigint"] } +num_cpus = "1.2" +parity-bytes = "0.1" +parity-crypto = "0.2" +parity-machine = { path = "../machine" } +parity-snappy = "0.1" +parking_lot = "0.7" +patricia-trie = "0.3.0" +patricia-trie-ethereum = { path = "../util/patricia-trie-ethereum" } +rand = "0.4" +rayon = "1.0" +rlp = { version = "0.3.0", features = ["ethereum"] } +rlp_derive = { path = "../util/rlp-derive" } rustc-hex = "1.0" +serde = "1.0" +serde_derive = "1.0" stats = { path = "../util/stats" } +tempdir = {version="0.3", optional = true} trace-time = "0.1" +triehash-ethereum = { version = "0.2", path = "../util/triehash-ethereum" } +unexpected = { path = "../util/unexpected" } using_queue = { path = "../miner/using-queue" } vm = { path = "vm" } wasm = { path = "wasm" } -keccak-hash = "0.1" -triehash-ethereum = { version = "0.2", path = "../util/triehash-ethereum" } -unexpected = { path = "../util/unexpected" } -journaldb = { path = "../util/journaldb" } -keccak-hasher = { path = "../util/keccak-hasher" } -kvdb-rocksdb = "0.1.3" -serde = "1.0" -serde_derive = "1.0" -tempdir = {version="0.3", optional = true} -len-caching-lock = { path = "../util/len-caching-lock" } [target.'cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android"))'.dependencies] hardware-wallet = { path = "../accounts/hw" } @@ -78,10 +78,14 @@ hardware-wallet = { path = "../accounts/hw" } fake-hardware-wallet = { path = "../accounts/fake-hardware-wallet" } [dev-dependencies] -env_logger = "0.4" +blooms-db = { path = "../util/blooms-db" } +criterion = "0.2" +env_logger = "0.5" +ethcore-logger = { path = "../logger" } +kvdb-rocksdb = "0.1.3" +rlp_compress = { path = "../util/rlp-compress" } tempdir = "0.3" trie-standardmap = "0.1" -criterion = "0.2" [features] parity = ["work-notify", "price-info", "stratum"] @@ -105,13 +109,13 @@ evm-debug-tests = ["evm-debug", "evm/evm-debug-tests"] # EVM debug traces are printed. slow-blocks = [] # Run JSON consensus tests. -json-tests = ["ethcore-transaction/json-tests", "test-helpers", "tempdir", "to-pod-full"] +json-tests = ["ethcore-logger", "test-helpers", "tempdir", "to-pod-full"] # Skip JSON consensus tests with pending issues. ci-skip-issue = [] # Run memory/cpu heavy tests. test-heavy = [] # Compile test helpers -test-helpers = ["tempdir"] +test-helpers = ["tempdir", "kvdb-rocksdb", "blooms-db"] # Enables slow 'to-pod-full' method for use in tests and evmbin. to-pod-full = [] diff --git a/ethcore/blockchain/Cargo.toml b/ethcore/blockchain/Cargo.toml new file mode 100644 index 000000000..a26369757 --- /dev/null +++ b/ethcore/blockchain/Cargo.toml @@ -0,0 +1,33 @@ +[package] +description = "Ethcore blockchain database" +homepage = "http://parity.io" +license = "GPL-3.0" +name = "ethcore-blockchain" +version = "0.1.0" +authors = ["Parity Technologies "] +edition = "2018" + +[dependencies] +ansi_term = "0.10" +blooms-db = { path = "../../util/blooms-db" } +common-types = { path = "../types" } +ethcore-db = { path = "../db" } +ethereum-types = "0.4" +heapsize = "0.4" +itertools = "0.5" +kvdb = "0.1" +log = "0.4" +parity-bytes = "0.1" +parking_lot = "0.7" +rayon = "1.0" +rlp = { version = "0.3.0", features = ["ethereum"] } +rlp_compress = { path = "../../util/rlp-compress" } +rlp_derive = { path = "../../util/rlp-derive" } + +[dev-dependencies] +env_logger = "0.5" +ethkey = { path = "../../accounts/ethkey" } +keccak-hash = "0.1" +rustc-hex = "1.0" +tempdir = "0.3" +kvdb-memorydb = "0.1" diff --git a/ethcore/src/blockchain/best_block.rs b/ethcore/blockchain/src/best_block.rs similarity index 95% rename from ethcore/src/blockchain/best_block.rs rename to ethcore/blockchain/src/best_block.rs index adfaf68aa..f73caa5fb 100644 --- a/ethcore/src/blockchain/best_block.rs +++ b/ethcore/blockchain/src/best_block.rs @@ -16,8 +16,8 @@ use ethereum_types::{H256, U256}; -use encoded; -use header::{Header, BlockNumber}; +use common_types::{encoded, BlockNumber}; +use common_types::header::Header; /// Contains information on a best block that is specific to the consensus engine. /// diff --git a/ethcore/src/blockchain/block_info.rs b/ethcore/blockchain/src/block_info.rs similarity index 98% rename from ethcore/src/blockchain/block_info.rs rename to ethcore/blockchain/src/block_info.rs index 6a48e9244..cbf7ad9d6 100644 --- a/ethcore/src/blockchain/block_info.rs +++ b/ethcore/blockchain/src/block_info.rs @@ -15,7 +15,7 @@ // along with Parity. If not, see . use ethereum_types::{H256, U256}; -use header::BlockNumber; +use common_types::BlockNumber; /// Brief info about inserted block. #[derive(Clone)] diff --git a/ethcore/src/blockchain/blockchain.rs b/ethcore/blockchain/src/blockchain.rs similarity index 97% rename from ethcore/src/blockchain/blockchain.rs rename to ethcore/blockchain/src/blockchain.rs index 4286dc414..2d7d129e8 100644 --- a/ethcore/src/blockchain/blockchain.rs +++ b/ethcore/blockchain/src/blockchain.rs @@ -22,34 +22,37 @@ use std::path::Path; use std::sync::Arc; use ansi_term::Colour; -use blockchain::{CacheSize, ImportRoute, Config}; -use blockchain::best_block::{BestBlock, BestAncientBlock}; -use blockchain::block_info::{BlockInfo, BlockLocation, BranchBecomingCanonChainData}; -use blockchain::extras::{BlockReceipts, BlockDetails, TransactionAddress, EPOCH_KEY_PREFIX, EpochTransitions}; -use blockchain::update::{ExtrasUpdate, ExtrasInsert}; use blooms_db; -use bytes::Bytes; -use cache_manager::CacheManager; -use db::{self, Writable, Readable, CacheUpdatePolicy}; -use encoded; -use engines::epoch::{Transition as EpochTransition, PendingTransition as PendingEpochTransition}; -use engines::ForkChoice; +use common_types::BlockNumber; +use common_types::blockchain_info::BlockChainInfo; +use common_types::encoded; +use common_types::engines::ForkChoice; +use common_types::engines::epoch::{Transition as EpochTransition, PendingTransition as PendingEpochTransition}; +use common_types::header::{Header, ExtendedHeader}; +use common_types::log_entry::{LogEntry, LocalizedLogEntry}; +use common_types::receipt::Receipt; +use common_types::transaction::LocalizedTransaction; +use common_types::tree_route::TreeRoute; +use common_types::view; +use common_types::views::{BlockView, HeaderView}; +use ethcore_db::cache_manager::CacheManager; +use ethcore_db::keys::{BlockReceipts, BlockDetails, TransactionAddress, EPOCH_KEY_PREFIX, EpochTransitions}; +use ethcore_db::{self as db, Writable, Readable, CacheUpdatePolicy}; use ethereum_types::{H256, Bloom, BloomRef, U256}; -use error::Error as EthcoreError; -use header::*; use heapsize::HeapSizeOf; use itertools::Itertools; use kvdb::{DBTransaction, KeyValueDB}; -use log_entry::{LogEntry, LocalizedLogEntry}; +use log::{trace, warn, info}; +use parity_bytes::Bytes; use parking_lot::{Mutex, RwLock}; use rayon::prelude::*; -use receipt::Receipt; -use rlp_compress::{compress, decompress, blocks_swapper}; use rlp::RlpStream; -use transaction::*; -use types::blockchain_info::BlockChainInfo; -use types::tree_route::TreeRoute; -use views::{BlockView, HeaderView}; +use rlp_compress::{compress, decompress, blocks_swapper}; + +use crate::best_block::{BestBlock, BestAncientBlock}; +use crate::block_info::{BlockInfo, BlockLocation, BranchBecomingCanonChainData}; +use crate::update::{ExtrasUpdate, ExtrasInsert}; +use crate::{CacheSize, ImportRoute, Config}; /// Database backing `BlockChain`. pub trait BlockChainDB: Send + Sync { @@ -63,7 +66,7 @@ pub trait BlockChainDB: Send + Sync { fn trace_blooms(&self) -> &blooms_db::Database; /// Restore the DB from the given path - fn restore(&self, new_db: &str) -> Result<(), EthcoreError> { + fn restore(&self, new_db: &str) -> Result<(), io::Error> { // First, close the Blooms databases self.blooms().close()?; self.trace_blooms().close()?; @@ -1549,25 +1552,55 @@ impl BlockChain { #[cfg(test)] mod tests { + use super::*; + use std::iter; - use std::sync::Arc; - use rustc_hex::FromHex; - use hash::keccak; - use kvdb::DBTransaction; - use ethereum_types::*; - use receipt::{Receipt, TransactionOutcome}; - use blockchain::{BlockProvider, BlockChain, BlockChainDB, Config, ImportRoute}; - use test_helpers::{ - generate_dummy_blockchain, generate_dummy_blockchain_with_extra, - generate_dummy_empty_blockchain - }; - use blockchain::generator::{BlockGenerator, BlockBuilder, BlockOptions}; - use blockchain::extras::TransactionAddress; - use transaction::{Transaction, Action}; - use log_entry::{LogEntry, LocalizedLogEntry}; + + use common_types::receipt::{Receipt, TransactionOutcome}; + use common_types::transaction::{Transaction, Action}; + use crate::generator::{BlockGenerator, BlockBuilder, BlockOptions}; use ethkey::Secret; - use test_helpers::new_db; - use encoded; + use keccak_hash::keccak; + use rustc_hex::FromHex; + use tempdir::TempDir; + + struct TestBlockChainDB { + _blooms_dir: TempDir, + _trace_blooms_dir: TempDir, + blooms: blooms_db::Database, + trace_blooms: blooms_db::Database, + key_value: Arc, + } + + impl BlockChainDB for TestBlockChainDB { + fn key_value(&self) -> &Arc { + &self.key_value + } + + fn blooms(&self) -> &blooms_db::Database { + &self.blooms + } + + fn trace_blooms(&self) -> &blooms_db::Database { + &self.trace_blooms + } + } + + /// Creates new test instance of `BlockChainDB` + pub fn new_db() -> Arc { + let blooms_dir = TempDir::new("").unwrap(); + let trace_blooms_dir = TempDir::new("").unwrap(); + + let db = TestBlockChainDB { + blooms: blooms_db::Database::open(blooms_dir.path()).unwrap(), + trace_blooms: blooms_db::Database::open(trace_blooms_dir.path()).unwrap(), + _blooms_dir: blooms_dir, + _trace_blooms_dir: trace_blooms_dir, + key_value: Arc::new(kvdb_memorydb::create(ethcore_db::NUM_COLUMNS.unwrap())) + }; + + Arc::new(db) + } fn new_chain(genesis: encoded::Block, db: Arc) -> BlockChain { BlockChain::new(Config::default(), genesis.raw(), db) @@ -1588,7 +1621,7 @@ mod tests { } fn insert_block_batch(batch: &mut DBTransaction, bc: &BlockChain, block: encoded::Block, receipts: Vec) -> ImportRoute { - use blockchain::ExtrasInsert; + use crate::ExtrasInsert; let fork_choice = { let header = block.header_view(); @@ -1596,9 +1629,9 @@ mod tests { let parent_details = bc.block_details(&parent_hash).unwrap_or_else(|| panic!("Invalid parent hash: {:?}", parent_hash)); let block_total_difficulty = parent_details.total_difficulty + header.difficulty(); if block_total_difficulty > bc.best_block_total_difficulty() { - ::engines::ForkChoice::New + common_types::engines::ForkChoice::New } else { - ::engines::ForkChoice::Old + common_types::engines::ForkChoice::Old } }; @@ -2012,43 +2045,6 @@ mod tests { } } - #[test] - fn can_contain_arbitrary_block_sequence() { - let bc = generate_dummy_blockchain(50); - assert_eq!(bc.best_block_number(), 49); - } - - #[test] - fn can_collect_garbage() { - let bc = generate_dummy_blockchain(3000); - - assert_eq!(bc.best_block_number(), 2999); - let best_hash = bc.best_block_hash(); - let mut block_header = bc.block_header_data(&best_hash); - - while !block_header.is_none() { - block_header = bc.block_header_data(&block_header.unwrap().parent_hash()); - } - assert!(bc.cache_size().blocks > 1024 * 1024); - - for _ in 0..2 { - bc.collect_garbage(); - } - assert!(bc.cache_size().blocks < 1024 * 1024); - } - - #[test] - fn can_contain_arbitrary_block_sequence_with_extra() { - let bc = generate_dummy_blockchain_with_extra(25); - assert_eq!(bc.best_block_number(), 24); - } - - #[test] - fn can_contain_only_genesis_block() { - let bc = generate_dummy_empty_blockchain(); - assert_eq!(bc.best_block_number(), 0); - } - #[test] fn find_transaction_by_hash() { let genesis = "f901fcf901f7a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0af81e09f8c46ca322193edfda764fa7e88e81923f802f1d325ec0b0308ac2cd0a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830200008083023e38808454c98c8142a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421880102030405060708c0c0".from_hex().unwrap(); @@ -2369,7 +2365,7 @@ mod tests { #[test] fn epoch_transitions_iter() { - use ::engines::EpochTransition; + use common_types::engines::epoch::Transition as EpochTransition; let genesis = BlockBuilder::genesis(); let next_5 = genesis.add_blocks(5); @@ -2418,7 +2414,7 @@ mod tests { #[test] fn epoch_transition_for() { - use ::engines::EpochTransition; + use common_types::engines::epoch::Transition as EpochTransition; let genesis = BlockBuilder::genesis(); let fork_7 = genesis.add_blocks_with(7, || BlockOptions { diff --git a/ethcore/src/blockchain/cache.rs b/ethcore/blockchain/src/cache.rs similarity index 100% rename from ethcore/src/blockchain/cache.rs rename to ethcore/blockchain/src/cache.rs diff --git a/ethcore/src/blockchain/config.rs b/ethcore/blockchain/src/config.rs similarity index 100% rename from ethcore/src/blockchain/config.rs rename to ethcore/blockchain/src/config.rs diff --git a/ethcore/src/blockchain/generator.rs b/ethcore/blockchain/src/generator.rs similarity index 83% rename from ethcore/src/blockchain/generator.rs rename to ethcore/blockchain/src/generator.rs index 213b394fc..8f933bbc8 100644 --- a/ethcore/src/blockchain/generator.rs +++ b/ethcore/blockchain/src/generator.rs @@ -19,51 +19,65 @@ use std::collections::VecDeque; use ethereum_types::{U256, H256, Bloom}; -use header::Header; +use common_types::encoded; +use common_types::header::Header; +use common_types::transaction::SignedTransaction; +use common_types::view; +use common_types::views::BlockView; use rlp::encode; -use transaction::SignedTransaction; -use views::BlockView; -use encoded; +use rlp_derive::RlpEncodable; /// Helper structure, used for encoding blocks. #[derive(Default, Clone, RlpEncodable)] pub struct Block { + /// Block header pub header: Header, + /// Block transactions pub transactions: Vec, + /// Block uncles pub uncles: Vec
} impl Block { + /// Get a copy of the header #[inline] pub fn header(&self) -> Header { self.header.clone() } + /// Get block hash #[inline] pub fn hash(&self) -> H256 { view!(BlockView, &self.encoded().raw()).header_view().hash() } + /// Get block number #[inline] pub fn number(&self) -> u64 { self.header.number() } + /// Get RLP encoding of this block #[inline] pub fn encoded(&self) -> encoded::Block { encoded::Block::new(encode(self)) } + /// Get block difficulty #[inline] pub fn difficulty(&self) -> U256 { *self.header.difficulty() } } +/// Specify block options for generator #[derive(Debug)] pub struct BlockOptions { + /// Difficulty pub difficulty: U256, + /// Set bloom filter pub bloom: Bloom, + /// Transactions included in blocks pub transactions: Vec, } @@ -77,12 +91,14 @@ impl Default for BlockOptions { } } +/// Utility to create blocks #[derive(Clone)] pub struct BlockBuilder { blocks: VecDeque, } impl BlockBuilder { + /// Create new BlockBuilder starting at genesis. pub fn genesis() -> Self { let mut blocks = VecDeque::with_capacity(1); blocks.push_back(Block::default()); @@ -92,21 +108,25 @@ impl BlockBuilder { } } + /// Add new block with default options. #[inline] pub fn add_block(&self) -> Self { self.add_block_with(|| BlockOptions::default()) } + /// Add `count` number of blocks with default options. #[inline] pub fn add_blocks(&self, count: usize) -> Self { self.add_blocks_with(count, || BlockOptions::default()) } + /// Add block with specified options. #[inline] pub fn add_block_with(&self, get_metadata: T) -> Self where T: Fn() -> BlockOptions { self.add_blocks_with(1, get_metadata) } + /// Add a block with given difficulty #[inline] pub fn add_block_with_difficulty(&self, difficulty: T) -> Self where T: Into { let difficulty = difficulty.into(); @@ -116,6 +136,7 @@ impl BlockBuilder { }) } + /// Add a block with given transactions. #[inline] pub fn add_block_with_transactions(&self, transactions: T) -> Self where T: IntoIterator { @@ -126,6 +147,7 @@ impl BlockBuilder { }) } + /// Add a block with given bloom filter. #[inline] pub fn add_block_with_bloom(&self, bloom: Bloom) -> Self { self.add_blocks_with(1, move || BlockOptions { @@ -134,6 +156,7 @@ impl BlockBuilder { }) } + /// Add a bunch of blocks with given metadata. pub fn add_blocks_with(&self, count: usize, get_metadata: T) -> Self where T: Fn() -> BlockOptions { assert!(count > 0, "There must be at least 1 block"); let mut parent_hash = self.last().hash(); @@ -160,18 +183,21 @@ impl BlockBuilder { } } + /// Get a reference to the last generated block. #[inline] pub fn last(&self) -> &Block { self.blocks.back().expect("There is always at least 1 block") } } +/// Generates a blockchain from given block builders (blocks will be concatenated). #[derive(Clone)] pub struct BlockGenerator { builders: VecDeque, } impl BlockGenerator { + /// Create new block generator. pub fn new(builders: T) -> Self where T: IntoIterator { BlockGenerator { builders: builders.into_iter().collect(), diff --git a/ethcore/src/blockchain/import_route.rs b/ethcore/blockchain/src/import_route.rs similarity index 94% rename from ethcore/src/blockchain/import_route.rs rename to ethcore/blockchain/src/import_route.rs index d8b38e633..8ab8d91ea 100644 --- a/ethcore/src/blockchain/import_route.rs +++ b/ethcore/blockchain/src/import_route.rs @@ -17,7 +17,7 @@ //! Import route. use ethereum_types::H256; -use blockchain::block_info::{BlockInfo, BlockLocation}; +use crate::block_info::{BlockInfo, BlockLocation}; /// Import route for newly inserted block. #[derive(Debug, PartialEq, Clone)] @@ -31,6 +31,7 @@ pub struct ImportRoute { } impl ImportRoute { + /// Empty import route. pub fn none() -> Self { ImportRoute { retracted: vec![], @@ -68,8 +69,8 @@ impl From for ImportRoute { #[cfg(test)] mod tests { use ethereum_types::{H256, U256}; - use blockchain::block_info::{BlockInfo, BlockLocation, BranchBecomingCanonChainData}; - use blockchain::ImportRoute; + use crate::block_info::{BlockInfo, BlockLocation, BranchBecomingCanonChainData}; + use super::ImportRoute; #[test] fn import_route_none() { diff --git a/ethcore/src/blockchain/mod.rs b/ethcore/blockchain/src/lib.rs similarity index 88% rename from ethcore/src/blockchain/mod.rs rename to ethcore/blockchain/src/lib.rs index 3a4504051..ad07cff3b 100644 --- a/ethcore/src/blockchain/mod.rs +++ b/ethcore/blockchain/src/lib.rs @@ -16,22 +16,22 @@ //! Blockchain database. +#![warn(missing_docs)] + mod best_block; mod block_info; mod blockchain; mod cache; mod config; -mod extras; mod import_route; mod update; -#[cfg(test)] pub mod generator; pub use self::blockchain::{BlockProvider, BlockChain, BlockChainDB, BlockChainDBHandler}; pub use self::cache::CacheSize; pub use self::config::Config; -pub use self::extras::{BlockReceipts, BlockDetails, TransactionAddress}; pub use self::import_route::ImportRoute; pub use self::update::ExtrasInsert; -pub use types::tree_route::TreeRoute; +pub use ethcore_db::keys::{BlockReceipts, BlockDetails, TransactionAddress}; +pub use common_types::tree_route::TreeRoute; diff --git a/ethcore/src/blockchain/update.rs b/ethcore/blockchain/src/update.rs similarity index 86% rename from ethcore/src/blockchain/update.rs rename to ethcore/blockchain/src/update.rs index 897abb59b..965e0bcd7 100644 --- a/ethcore/src/blockchain/update.rs +++ b/ethcore/blockchain/src/update.rs @@ -15,11 +15,14 @@ // along with Parity. If not, see . use std::collections::HashMap; + +use common_types::BlockNumber; +use common_types::encoded::Block; +use common_types::engines::ForkChoice; +use ethcore_db::keys::{BlockDetails, BlockReceipts, TransactionAddress}; use ethereum_types::{H256, Bloom}; -use header::BlockNumber; -use blockchain::block_info::BlockInfo; -use blockchain::extras::{BlockDetails, BlockReceipts, TransactionAddress}; -use encoded::Block; + +use crate::block_info::BlockInfo; /// Block extras update info. pub struct ExtrasUpdate { @@ -42,7 +45,7 @@ pub struct ExtrasUpdate { /// Extra information in block insertion. pub struct ExtrasInsert { /// The primitive fork choice before applying finalization rules. - pub fork_choice: ::engines::ForkChoice, + pub fork_choice: ForkChoice, /// Is the inserted block considered finalized. pub is_finalized: bool, } diff --git a/ethcore/db/Cargo.toml b/ethcore/db/Cargo.toml new file mode 100644 index 000000000..53ec9f7b8 --- /dev/null +++ b/ethcore/db/Cargo.toml @@ -0,0 +1,17 @@ +[package] +description = "Ethcore DB access utilities" +homepage = "http://parity.io" +license = "GPL-3.0" +name = "ethcore-db" +version = "0.1.0" +authors = ["Parity Technologies "] +edition = "2018" + +[dependencies] +common-types = { path = "../types" } +ethereum-types = "0.4" +heapsize = "0.4" +kvdb = "0.1" +parking_lot = "0.7" +rlp = { version = "0.3.0", features = ["ethereum"] } +rlp_derive = { path = "../../util/rlp-derive" } diff --git a/ethcore/src/cache_manager.rs b/ethcore/db/src/cache_manager.rs similarity index 94% rename from ethcore/src/cache_manager.rs rename to ethcore/db/src/cache_manager.rs index 07a9750a0..dacb51da6 100644 --- a/ethcore/src/cache_manager.rs +++ b/ethcore/db/src/cache_manager.rs @@ -14,11 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +//! Database cache manager + use std::collections::{VecDeque, HashSet}; use std::hash::Hash; const COLLECTION_QUEUE_SIZE: usize = 8; +/// DB cache manager pub struct CacheManager { pref_cache_size: usize, max_cache_size: usize, @@ -27,6 +30,7 @@ pub struct CacheManager { } impl CacheManager where T: Eq + Hash { + /// Create new cache manager with preferred (heap) sizes. pub fn new(pref_cache_size: usize, max_cache_size: usize, bytes_per_cache_entry: usize) -> Self { CacheManager { pref_cache_size: pref_cache_size, @@ -36,6 +40,7 @@ impl CacheManager where T: Eq + Hash { } } + /// Mark element as used. pub fn note_used(&mut self, id: T) { if !self.cache_usage[0].contains(&id) { if let Some(c) = self.cache_usage.iter_mut().skip(1).find(|e| e.contains(&id)) { diff --git a/ethcore/src/db.rs b/ethcore/db/src/db.rs similarity index 100% rename from ethcore/src/db.rs rename to ethcore/db/src/db.rs diff --git a/ethcore/src/blockchain/extras.rs b/ethcore/db/src/keys.rs similarity index 92% rename from ethcore/src/blockchain/extras.rs rename to ethcore/db/src/keys.rs index 1dd51b7c7..d9fc3dcc3 100644 --- a/ethcore/src/blockchain/extras.rs +++ b/ethcore/db/src/keys.rs @@ -19,14 +19,16 @@ use std::io::Write; use std::ops; -use db::Key; -use engines::epoch::{Transition as EpochTransition}; +use common_types::BlockNumber; +use common_types::engines::epoch::Transition as EpochTransition; +use common_types::receipt::Receipt; use ethereum_types::{H256, H264, U256}; -use header::BlockNumber; use heapsize::HeapSizeOf; use kvdb::PREFIX_LEN as DB_PREFIX_LEN; -use receipt::Receipt; use rlp; +use rlp_derive::{RlpEncodableWrapper, RlpDecodableWrapper, RlpEncodable, RlpDecodable}; + +use crate::db::Key; /// Represents index of extra data in database #[derive(Copy, Debug, Hash, Eq, PartialEq, Clone)] @@ -52,6 +54,7 @@ fn with_index(hash: &H256, i: ExtrasIndex) -> H264 { result } +/// Wrapper for block number used as a DB key. pub struct BlockNumberKey([u8; 5]); impl ops::Deref for BlockNumberKey { @@ -100,7 +103,7 @@ impl Key for H256 { } } -impl Key<::engines::epoch::PendingTransition> for H256 { +impl Key for H256 { type Target = H264; fn key(&self) -> H264 { @@ -117,6 +120,7 @@ pub const EPOCH_KEY_PREFIX: &'static [u8; DB_PREFIX_LEN] = &[ ExtrasIndex::EpochTransitions as u8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]; +/// Epoch transitions key pub struct EpochTransitionsKey([u8; EPOCH_KEY_LEN]); impl ops::Deref for EpochTransitionsKey { @@ -217,10 +221,12 @@ impl HeapSizeOf for TransactionAddress { /// Contains all block receipts. #[derive(Clone, RlpEncodableWrapper, RlpDecodableWrapper)] pub struct BlockReceipts { + /// Block receipts pub receipts: Vec, } impl BlockReceipts { + /// Create new block receipts wrapper. pub fn new(receipts: Vec) -> Self { BlockReceipts { receipts: receipts @@ -237,7 +243,9 @@ impl HeapSizeOf for BlockReceipts { /// Candidate transitions to an epoch with specific number. #[derive(Clone, RlpEncodable, RlpDecodable)] pub struct EpochTransitions { + /// Epoch number pub number: u64, + /// List of candidate transitions pub candidates: Vec, } diff --git a/ethcore/db/src/lib.rs b/ethcore/db/src/lib.rs new file mode 100644 index 000000000..1ecfb9adc --- /dev/null +++ b/ethcore/db/src/lib.rs @@ -0,0 +1,26 @@ +// Copyright 2015-2018 Parity Technologies (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 . + +//! Parity Ethereum database access utilities. + +#![warn(missing_docs)] + +mod db; + +pub mod keys; +pub mod cache_manager; + +pub use self::db::*; diff --git a/ethcore/light/Cargo.toml b/ethcore/light/Cargo.toml index 2cef2fbe7..7e0c8aaeb 100644 --- a/ethcore/light/Cargo.toml +++ b/ethcore/light/Cargo.toml @@ -8,9 +8,11 @@ authors = ["Parity Technologies "] [dependencies] log = "0.4" -ethcore = { path = ".."} parity-bytes = "0.1" -ethcore-transaction = { path = "../transaction" } +common-types = { path = "../types" } +ethcore = { path = ".."} +ethcore-db = { path = "../db" } +ethcore-blockchain = { path = "../blockchain" } ethereum-types = "0.4" memorydb = "0.3.0" patricia-trie = "0.3.0" diff --git a/ethcore/light/src/cache.rs b/ethcore/light/src/cache.rs index d720626ab..93f53063a 100644 --- a/ethcore/light/src/cache.rs +++ b/ethcore/light/src/cache.rs @@ -20,15 +20,15 @@ //! Furthermore, stores a "gas price corpus" of relative recency, which is a sorted //! vector of all gas prices from a recent range of blocks. -use ethcore::encoded; -use ethcore::header::BlockNumber; -use ethcore::receipt::Receipt; - -use stats::Corpus; use std::time::{Instant, Duration}; -use heapsize::HeapSizeOf; + +use common_types::encoded; +use common_types::BlockNumber; +use common_types::receipt::Receipt; use ethereum_types::{H256, U256}; +use heapsize::HeapSizeOf; use memory_cache::MemoryLruCache; +use stats::Corpus; /// Configuration for how much data to cache. #[derive(Copy, Clone, Debug, PartialEq, Eq)] diff --git a/ethcore/light/src/cht.rs b/ethcore/light/src/cht.rs index c6665f857..9e0151882 100644 --- a/ethcore/light/src/cht.rs +++ b/ethcore/light/src/cht.rs @@ -23,7 +23,7 @@ //! root has. A correct proof implies that the claimed block is identical to the one //! we discarded. -use ethcore::ids::BlockId; +use common_types::ids::BlockId; use ethereum_types::{H256, U256}; use hashdb::HashDB; use keccak_hasher::KeccakHasher; diff --git a/ethcore/light/src/client/fetch.rs b/ethcore/light/src/client/fetch.rs index b0f735349..bd4bcfe7a 100644 --- a/ethcore/light/src/client/fetch.rs +++ b/ethcore/light/src/client/fetch.rs @@ -18,13 +18,13 @@ use std::sync::Arc; -use ethcore::encoded; +use common_types::encoded; +use common_types::header::Header; +use common_types::receipt::Receipt; use ethcore::engines::{EthEngine, StateDependentProof}; use ethcore::machine::EthereumMachine; -use ethcore::header::Header; -use ethcore::receipt::Receipt; -use futures::future::IntoFuture; use ethereum_types::H256; +use futures::future::IntoFuture; /// Provides full chain data. pub trait ChainDataFetcher: Send + Sync + 'static { diff --git a/ethcore/light/src/client/header_chain.rs b/ethcore/light/src/client/header_chain.rs index f6d903176..8b9e11d4a 100644 --- a/ethcore/light/src/client/header_chain.rs +++ b/ethcore/light/src/client/header_chain.rs @@ -30,12 +30,12 @@ use std::sync::Arc; use cache::Cache; use cht; -use ethcore::block_status::BlockStatus; -use ethcore::encoded; +use common_types::block_status::BlockStatus; +use common_types::encoded; +use common_types::header::Header; +use common_types::ids::BlockId; use ethcore::engines::epoch::{Transition as EpochTransition, PendingTransition as PendingEpochTransition}; use ethcore::error::{Error, EthcoreResult, ErrorKind as EthcoreErrorKind, BlockError}; -use ethcore::header::Header; -use ethcore::ids::BlockId; use ethcore::spec::{Spec, SpecHardcodedSync}; use ethereum_types::{H256, H264, U256}; use heapsize::HeapSizeOf; @@ -862,11 +862,11 @@ mod tests { use super::{HeaderChain, HardcodedSync}; use std::sync::Arc; - use ethereum_types::U256; - use ethcore::ids::BlockId; - use ethcore::header::Header; - use ethcore::spec::Spec; use cache::Cache; + use common_types::header::Header; + use common_types::ids::BlockId; + use ethcore::spec::Spec; + use ethereum_types::U256; use kvdb::KeyValueDB; use kvdb_memorydb; diff --git a/ethcore/light/src/client/mod.rs b/ethcore/light/src/client/mod.rs index e1c823ee2..95173e688 100644 --- a/ethcore/light/src/client/mod.rs +++ b/ethcore/light/src/client/mod.rs @@ -18,21 +18,22 @@ use std::sync::{Weak, Arc}; -use ethcore::block_status::BlockStatus; use ethcore::client::{ClientReport, EnvInfo, ClientIoMessage}; use ethcore::engines::{epoch, EthEngine, EpochChange, EpochTransition, Proof}; use ethcore::machine::EthereumMachine; use ethcore::error::{Error, EthcoreResult}; -use ethcore::ids::BlockId; -use ethcore::header::{BlockNumber, Header}; use ethcore::verification::queue::{self, HeaderQueue}; -use ethcore::blockchain_info::BlockChainInfo; use ethcore::spec::{Spec, SpecHardcodedSync}; -use ethcore::encoded; use io::IoChannel; use parking_lot::{Mutex, RwLock}; use ethereum_types::{H256, U256}; use futures::{IntoFuture, Future}; +use common_types::BlockNumber; +use common_types::block_status::BlockStatus; +use common_types::blockchain_info::BlockChainInfo; +use common_types::encoded; +use common_types::header::Header; +use common_types::ids::BlockId; use kvdb::KeyValueDB; diff --git a/ethcore/light/src/client/service.rs b/ethcore/light/src/client/service.rs index 4b199d6ba..b8a642b2c 100644 --- a/ethcore/light/src/client/service.rs +++ b/ethcore/light/src/client/service.rs @@ -20,8 +20,9 @@ use std::fmt; use std::sync::Arc; +use ethcore_db as db; +use ethcore_blockchain::BlockChainDB; use ethcore::client::ClientIoMessage; -use ethcore::{db, BlockChainDB}; use ethcore::error::Error as CoreError; use ethcore::spec::Spec; use io::{IoContext, IoError, IoHandler, IoService}; diff --git a/ethcore/light/src/lib.rs b/ethcore/light/src/lib.rs index 1102f58bc..6d7c8c1d6 100644 --- a/ethcore/light/src/lib.rs +++ b/ethcore/light/src/lib.rs @@ -54,10 +54,12 @@ extern crate serde_derive; extern crate log; extern crate bincode; +extern crate common_types; +extern crate ethcore_blockchain; +extern crate ethcore_db; extern crate ethcore_io as io; extern crate ethcore_network as network; extern crate parity_bytes as bytes; -extern crate ethcore_transaction as transaction; extern crate ethereum_types; extern crate ethcore; extern crate hashdb; diff --git a/ethcore/light/src/net/mod.rs b/ethcore/light/src/net/mod.rs index cec2c6994..aa729ae5f 100644 --- a/ethcore/light/src/net/mod.rs +++ b/ethcore/light/src/net/mod.rs @@ -18,8 +18,7 @@ //! //! This uses a "Provider" to answer requests. -use transaction::UnverifiedTransaction; - +use common_types::transaction::UnverifiedTransaction; use ethereum_types::{H256, U256}; use io::TimerToken; use kvdb::DBValue; diff --git a/ethcore/light/src/net/tests/mod.rs b/ethcore/light/src/net/tests/mod.rs index 791315f5f..e3d5d3680 100644 --- a/ethcore/light/src/net/tests/mod.rs +++ b/ethcore/light/src/net/tests/mod.rs @@ -17,21 +17,21 @@ //! Tests for the `LightProtocol` implementation. //! These don't test of the higher level logic on top of -use ethcore::blockchain_info::BlockChainInfo; +use common_types::blockchain_info::BlockChainInfo; +use common_types::encoded; +use common_types::ids::BlockId; +use common_types::transaction::{Action, PendingTransaction}; use ethcore::client::{EachBlockWith, TestBlockChainClient}; -use ethcore::encoded; -use ethcore::ids::BlockId; use ethereum_types::{H256, U256, Address}; -use net::{LightProtocol, Params, packet, Peer, Statistics}; use net::context::IoContext; -use net::status::{Capabilities, Status}; use net::load_timer::MOVING_SAMPLE_SIZE; +use net::status::{Capabilities, Status}; +use net::{LightProtocol, Params, packet, Peer, Statistics}; use network::{PeerId, NodeId}; use provider::Provider; -use request; use request::*; +use request; use rlp::{Rlp, RlpStream}; -use transaction::{Action, PendingTransaction}; use std::sync::Arc; use std::time::Instant; diff --git a/ethcore/light/src/on_demand/request.rs b/ethcore/light/src/on_demand/request.rs index a0adc5081..537058be1 100644 --- a/ethcore/light/src/on_demand/request.rs +++ b/ethcore/light/src/on_demand/request.rs @@ -20,11 +20,12 @@ use std::cmp; use std::sync::Arc; use bytes::Bytes; -use ethcore::basic_account::BasicAccount; -use ethcore::encoded; +use common_types::basic_account::BasicAccount; +use common_types::encoded; +use common_types::receipt::Receipt; +use common_types::transaction::SignedTransaction; use ethcore::engines::{EthEngine, StateDependentProof}; use ethcore::machine::EthereumMachine; -use ethcore::receipt::Receipt; use ethcore::state::{self, ProvedExecution}; use ethereum_types::{H256, U256, Address}; use ethtrie::{TrieError, TrieDB}; @@ -35,7 +36,6 @@ use memorydb::MemoryDB; use parking_lot::Mutex; use request::{self as net_request, IncompleteRequest, CompleteRequest, Output, OutputKind, Field}; use rlp::{RlpStream, Rlp}; -use transaction::SignedTransaction; use trie::Trie; use vm::EnvInfo; @@ -1108,10 +1108,10 @@ mod tests { use trie::Recorder; use hash::keccak; - use ::ethcore::client::{BlockChainClient, BlockInfo, TestBlockChainClient, EachBlockWith}; - use ethcore::header::Header; - use ethcore::encoded; - use ethcore::receipt::{Receipt, TransactionOutcome}; + use ethcore::client::{BlockChainClient, BlockInfo, TestBlockChainClient, EachBlockWith}; + use common_types::header::Header; + use common_types::encoded; + use common_types::receipt::{Receipt, TransactionOutcome}; fn make_cache() -> ::cache::Cache { ::cache::Cache::new(Default::default(), Duration::from_secs(1)) diff --git a/ethcore/light/src/on_demand/tests.rs b/ethcore/light/src/on_demand/tests.rs index 5ae798b33..db2f510de 100644 --- a/ethcore/light/src/on_demand/tests.rs +++ b/ethcore/light/src/on_demand/tests.rs @@ -17,13 +17,13 @@ //! Tests for the on-demand service. use cache::Cache; -use ethcore::header::Header; use futures::Future; use network::{PeerId, NodeId}; use net::*; +use common_types::header::Header; use ethereum_types::H256; use parking_lot::Mutex; -use ::request::{self as basic_request, Response}; +use request::{self as basic_request, Response}; use std::sync::Arc; use std::time::{Duration, Instant}; diff --git a/ethcore/light/src/provider.rs b/ethcore/light/src/provider.rs index bfd15dadc..996b98ee1 100644 --- a/ethcore/light/src/provider.rs +++ b/ethcore/light/src/provider.rs @@ -19,13 +19,13 @@ use std::sync::Arc; -use ethcore::blockchain_info::BlockChainInfo; +use common_types::blockchain_info::BlockChainInfo; +use common_types::encoded; +use common_types::ids::BlockId; +use common_types::transaction::PendingTransaction; use ethcore::client::{BlockChainClient, ProvingBlockChainClient, ChainInfo, BlockInfo as ClientBlockInfo}; -use ethcore::ids::BlockId; -use ethcore::encoded; use ethereum_types::H256; use parking_lot::RwLock; -use transaction::PendingTransaction; use cht::{self, BlockInfo}; use client::{LightChainClient, AsLightClient}; @@ -161,7 +161,7 @@ impl Provider for T { fn transaction_index(&self, req: request::CompleteTransactionIndexRequest) -> Option { - use ethcore::ids::TransactionId; + use common_types::ids::TransactionId; self.transaction_receipt(TransactionId::Hash(req.hash)).map(|receipt| request::TransactionIndexResponse { num: receipt.block_number, @@ -265,7 +265,7 @@ impl Provider for T { } fn transaction_proof(&self, req: request::CompleteExecutionRequest) -> Option { - use transaction::Transaction; + use common_types::transaction::Transaction; let id = BlockId::Hash(req.block_hash); let nonce = match self.nonce(&req.from, id) { diff --git a/ethcore/light/src/transaction_queue.rs b/ethcore/light/src/transaction_queue.rs index 912e561b9..585e62f31 100644 --- a/ethcore/light/src/transaction_queue.rs +++ b/ethcore/light/src/transaction_queue.rs @@ -27,7 +27,7 @@ use std::fmt; use std::collections::{BTreeMap, HashMap}; use std::collections::hash_map::Entry; -use transaction::{self, Condition, PendingTransaction, SignedTransaction}; +use common_types::transaction::{self, Condition, PendingTransaction, SignedTransaction}; use ethereum_types::{H256, U256, Address}; use fastmap::H256FastMap; @@ -370,7 +370,7 @@ impl TransactionQueue { mod tests { use super::TransactionQueue; use ethereum_types::Address; - use transaction::{Transaction, PendingTransaction, Condition}; + use common_types::transaction::{Transaction, PendingTransaction, Condition}; #[test] fn queued_senders() { diff --git a/ethcore/light/src/types/request/mod.rs b/ethcore/light/src/types/request/mod.rs index c57e8383e..438edf714 100644 --- a/ethcore/light/src/types/request/mod.rs +++ b/ethcore/light/src/types/request/mod.rs @@ -670,7 +670,7 @@ pub trait ResponseLike { /// Header request. pub mod header { use super::{Field, HashOrNumber, NoSuchOutput, OutputKind, Output}; - use ethcore::encoded; + use common_types::encoded; use rlp::{Encodable, Decodable, DecoderError, RlpStream, Rlp}; /// Potentially incomplete headers request. @@ -753,7 +753,7 @@ pub mod header { impl Decodable for Response { fn decode(rlp: &Rlp) -> Result { - use ethcore::header::Header as FullHeader; + use common_types::header::Header as FullHeader; let mut headers = Vec::new(); @@ -954,7 +954,7 @@ pub mod transaction_index { /// Request and response for block receipts pub mod block_receipts { use super::{Field, NoSuchOutput, OutputKind, Output}; - use ethcore::receipt::Receipt; + use common_types::receipt::Receipt; use ethereum_types::H256; /// Potentially incomplete block receipts request. @@ -1022,7 +1022,7 @@ pub mod block_receipts { /// Request and response for a block body pub mod block_body { use super::{Field, NoSuchOutput, OutputKind, Output}; - use ethcore::encoded; + use common_types::encoded; use rlp::{Encodable, Decodable, DecoderError, RlpStream, Rlp}; use ethereum_types::H256; @@ -1089,8 +1089,8 @@ pub mod block_body { impl Decodable for Response { fn decode(rlp: &Rlp) -> Result { - use ethcore::header::Header as FullHeader; - use transaction::UnverifiedTransaction; + use common_types::header::Header as FullHeader; + use common_types::transaction::UnverifiedTransaction; // check body validity. let _: Vec = rlp.list_at(0)?; @@ -1406,7 +1406,7 @@ pub mod contract_code { /// A request for proof of execution. pub mod execution { use super::{Field, NoSuchOutput, OutputKind, Output}; - use transaction::Action; + use common_types::transaction::Action; use rlp::{Encodable, Decodable, DecoderError, RlpStream, Rlp}; use ethereum_types::{H256, U256, Address}; use kvdb::DBValue; @@ -1629,7 +1629,7 @@ pub mod epoch_signal { #[cfg(test)] mod tests { use super::*; - use ethcore::header::Header; + use common_types::header::Header; fn check_roundtrip(val: T) where T: ::rlp::Encodable + ::rlp::Decodable + PartialEq + ::std::fmt::Debug @@ -1676,7 +1676,7 @@ mod tests { let full_req = Request::Headers(req.clone()); let res = HeadersResponse { headers: vec![ - ::ethcore::encoded::Header::new(::rlp::encode(&Header::default())) + ::common_types::encoded::Header::new(::rlp::encode(&Header::default())) ] }; let full_res = Response::Headers(res.clone()); @@ -1729,7 +1729,7 @@ mod tests { #[test] fn receipts_roundtrip() { - use ethcore::receipt::{Receipt, TransactionOutcome}; + use common_types::receipt::{Receipt, TransactionOutcome}; let req = IncompleteReceiptsRequest { hash: Field::Scalar(Default::default()), }; @@ -1749,7 +1749,7 @@ mod tests { #[test] fn body_roundtrip() { - use transaction::{Transaction, UnverifiedTransaction}; + use common_types::transaction::{Transaction, UnverifiedTransaction}; let req = IncompleteBodyRequest { hash: Field::Scalar(Default::default()), }; @@ -1757,13 +1757,13 @@ mod tests { let full_req = Request::Body(req.clone()); let res = BodyResponse { body: { - let header = ::ethcore::header::Header::default(); + let header = ::common_types::header::Header::default(); let tx = UnverifiedTransaction::from(Transaction::default().fake_sign(Default::default())); let mut stream = RlpStream::new_list(2); stream.begin_list(2).append(&tx).append(&tx) .begin_list(1).append(&header); - ::ethcore::encoded::Body::new(stream.out()) + ::common_types::encoded::Body::new(stream.out()) }, }; let full_res = Response::Body(res.clone()); @@ -1844,7 +1844,7 @@ mod tests { let req = IncompleteExecutionRequest { block_hash: Field::Scalar(Default::default()), from: Default::default(), - action: ::transaction::Action::Create, + action: ::common_types::transaction::Action::Create, gas: 100_000.into(), gas_price: 0.into(), value: 100_000_001.into(), @@ -1874,7 +1874,7 @@ mod tests { let reqs: Vec<_> = (0..10).map(|_| IncompleteExecutionRequest { block_hash: Field::Scalar(Default::default()), from: Default::default(), - action: ::transaction::Action::Create, + action: ::common_types::transaction::Action::Create, gas: 100_000.into(), gas_price: 0.into(), value: 100_000_001.into(), @@ -1892,11 +1892,11 @@ mod tests { #[test] fn responses_vec() { - use ethcore::receipt::{Receipt, TransactionOutcome}; + use common_types::receipt::{Receipt, TransactionOutcome}; let mut stream = RlpStream::new_list(2); stream.begin_list(0).begin_list(0); - let body = ::ethcore::encoded::Body::new(stream.out()); + let body = ::common_types::encoded::Body::new(stream.out()); let reqs = vec![ Response::Headers(HeadersResponse { headers: vec![] }), Response::HeaderProof(HeaderProofResponse { proof: vec![], hash: Default::default(), td: 100.into()}), diff --git a/ethcore/private-tx/Cargo.toml b/ethcore/private-tx/Cargo.toml index d30a161dd..77e0ebea8 100644 --- a/ethcore/private-tx/Cargo.toml +++ b/ethcore/private-tx/Cargo.toml @@ -6,17 +6,15 @@ license = "GPL-3.0" authors = ["Parity Technologies "] [dependencies] +common-types = { path = "../types" } error-chain = { version = "0.12", default-features = false } ethabi = "6.0" -ethabi-derive = "6.0" ethabi-contract = "6.0" +ethabi-derive = "6.0" ethcore = { path = ".." } -parity-bytes = "0.1" -parity-crypto = "0.2" ethcore-io = { path = "../../util/io" } ethcore-logger = { path = "../../logger" } ethcore-miner = { path = "../../miner" } -ethcore-transaction = { path = "../transaction" } ethereum-types = "0.4" ethjson = { path = "../../json" } ethkey = { path = "../../accounts/ethkey" } @@ -25,6 +23,8 @@ futures = "0.1" heapsize = "0.4" keccak-hash = "0.1.2" log = "0.4" +parity-bytes = "0.1" +parity-crypto = "0.2" parking_lot = "0.7" patricia-trie = "0.3.0" patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" } diff --git a/ethcore/private-tx/src/error.rs b/ethcore/private-tx/src/error.rs index 99da149e4..dc778b61d 100644 --- a/ethcore/private-tx/src/error.rs +++ b/ethcore/private-tx/src/error.rs @@ -19,7 +19,7 @@ use rlp::DecoderError; use ethtrie::TrieError; use ethcore::account_provider::SignError; use ethcore::error::{Error as EthcoreError, ExecutionError}; -use transaction::Error as TransactionError; +use types::transaction::Error as TransactionError; use ethkey::Error as KeyError; use txpool::Error as TxPoolError; diff --git a/ethcore/private-tx/src/lib.rs b/ethcore/private-tx/src/lib.rs index 4b9f6d33e..adbd39664 100644 --- a/ethcore/private-tx/src/lib.rs +++ b/ethcore/private-tx/src/lib.rs @@ -25,27 +25,27 @@ mod private_transactions; mod messages; mod error; +extern crate common_types as types; +extern crate ethabi; extern crate ethcore; -extern crate parity_bytes as bytes; -extern crate parity_crypto as crypto; extern crate ethcore_io as io; extern crate ethcore_miner; -extern crate ethcore_transaction as transaction; -extern crate ethabi; extern crate ethereum_types; -extern crate ethkey; extern crate ethjson; +extern crate ethkey; extern crate fetch; extern crate futures; extern crate heapsize; extern crate keccak_hash as hash; +extern crate parity_bytes as bytes; +extern crate parity_crypto as crypto; extern crate parking_lot; extern crate patricia_trie as trie; -extern crate transaction_pool as txpool; extern crate patricia_trie_ethereum as ethtrie; extern crate rlp; -extern crate url; extern crate rustc_hex; +extern crate transaction_pool as txpool; +extern crate url; #[macro_use] extern crate log; #[macro_use] @@ -78,7 +78,7 @@ use ethkey::{Signature, recover, public_to_address}; use io::IoChannel; use ethcore::executive::{Executive, TransactOptions}; use ethcore::executed::{Executed}; -use transaction::{SignedTransaction, Transaction, Action, UnverifiedTransaction}; +use types::transaction::{SignedTransaction, Transaction, Action, UnverifiedTransaction}; use ethcore::{contract_address as ethcore_contract_address}; use ethcore::client::{ Client, ChainNotify, NewBlocks, ChainMessageType, ClientIoMessage, BlockId, diff --git a/ethcore/private-tx/src/messages.rs b/ethcore/private-tx/src/messages.rs index c0825fb59..ba815506e 100644 --- a/ethcore/private-tx/src/messages.rs +++ b/ethcore/private-tx/src/messages.rs @@ -19,7 +19,7 @@ use bytes::Bytes; use hash::keccak; use rlp::Encodable; use ethkey::Signature; -use transaction::signature::{add_chain_replay_protection, check_replay_protection}; +use types::transaction::signature::{add_chain_replay_protection, check_replay_protection}; /// Message with private transaction encrypted #[derive(Default, Debug, Clone, PartialEq, RlpEncodable, RlpDecodable, Eq)] diff --git a/ethcore/private-tx/src/private_transactions.rs b/ethcore/private-tx/src/private_transactions.rs index a0f58f9ca..c3bbe02d4 100644 --- a/ethcore/private-tx/src/private_transactions.rs +++ b/ethcore/private-tx/src/private_transactions.rs @@ -25,7 +25,7 @@ use heapsize::HeapSizeOf; use ethkey::Signature; use messages::PrivateTransaction; use parking_lot::RwLock; -use transaction::{UnverifiedTransaction, SignedTransaction}; +use types::transaction::{UnverifiedTransaction, SignedTransaction}; use txpool; use txpool::{VerifiedTransaction, Verifier}; use error::{Error, ErrorKind}; diff --git a/ethcore/private-tx/tests/private_contract.rs b/ethcore/private-tx/tests/private_contract.rs index 4ec1e18c1..519322da5 100644 --- a/ethcore/private-tx/tests/private_contract.rs +++ b/ethcore/private-tx/tests/private_contract.rs @@ -16,14 +16,14 @@ //! Contract for private transactions tests. -extern crate rustc_hex; +extern crate common_types as types; extern crate ethcore; -extern crate ethkey; -extern crate keccak_hash as hash; extern crate ethcore_io; extern crate ethcore_logger; extern crate ethcore_private_tx; -extern crate ethcore_transaction; +extern crate ethkey; +extern crate keccak_hash as hash; +extern crate rustc_hex; #[macro_use] extern crate log; @@ -31,14 +31,14 @@ extern crate log; use std::sync::Arc; use rustc_hex::FromHex; +use types::ids::BlockId; +use types::transaction::{Transaction, Action}; use ethcore::CreateContractAddress; use ethcore::account_provider::AccountProvider; use ethcore::client::BlockChainClient; -use ethcore::client::BlockId; use ethcore::executive::{contract_address}; use ethcore::miner::Miner; use ethcore::test_helpers::{generate_dummy_client, push_block_with_transactions}; -use ethcore_transaction::{Transaction, Action}; use ethkey::{Secret, KeyPair, Signature}; use hash::keccak; diff --git a/ethcore/service/Cargo.toml b/ethcore/service/Cargo.toml index 9ccacb713..7db0ad277 100644 --- a/ethcore/service/Cargo.toml +++ b/ethcore/service/Cargo.toml @@ -7,6 +7,7 @@ authors = ["Parity Technologies "] ansi_term = "0.10" error-chain = { version = "0.12", default-features = false } ethcore = { path = ".." } +ethcore-blockchain = { path = "../blockchain" } ethcore-io = { path = "../../util/io" } ethcore-private-tx = { path = "../private-tx" } ethcore-sync = { path = "../sync" } @@ -16,6 +17,7 @@ log = "0.4" trace-time = "0.1" [dev-dependencies] +ethcore-db = { path = "../db" } ethcore = { path = "..", features = ["test-helpers"] } tempdir = "0.3" kvdb-rocksdb = "0.1.3" diff --git a/ethcore/service/src/lib.rs b/ethcore/service/src/lib.rs index 8f45c50ef..872ba9973 100644 --- a/ethcore/service/src/lib.rs +++ b/ethcore/service/src/lib.rs @@ -16,6 +16,7 @@ extern crate ansi_term; extern crate ethcore; +extern crate ethcore_blockchain as blockchain; extern crate ethcore_io as io; extern crate ethcore_private_tx; extern crate ethcore_sync as sync; @@ -24,16 +25,17 @@ extern crate kvdb; #[macro_use] extern crate error_chain; - #[macro_use] extern crate log; - #[macro_use] extern crate trace_time; +#[cfg(test)] +extern crate ethcore_db; #[cfg(test)] extern crate tempdir; + mod error; mod service; mod stop_guard; diff --git a/ethcore/service/src/service.rs b/ethcore/service/src/service.rs index 77429a4e5..5dda2ca2b 100644 --- a/ethcore/service/src/service.rs +++ b/ethcore/service/src/service.rs @@ -26,7 +26,7 @@ use io::{IoContext, TimerToken, IoHandler, IoService, IoError}; use stop_guard::StopGuard; use sync::PrivateTxHandler; -use ethcore::{BlockChainDB, BlockChainDBHandler}; +use blockchain::{BlockChainDB, BlockChainDBHandler}; use ethcore::client::{Client, ClientConfig, ChainNotify, ClientIoMessage}; use ethcore::miner::Miner; use ethcore::snapshot::service::{Service as SnapshotService, ServiceParams as SnapServiceParams}; @@ -275,11 +275,11 @@ mod tests { use tempdir::TempDir; + use ethcore_db::NUM_COLUMNS; use ethcore::account_provider::AccountProvider; use ethcore::client::ClientConfig; use ethcore::miner::Miner; use ethcore::spec::Spec; - use ethcore::db::NUM_COLUMNS; use ethcore::test_helpers; use kvdb_rocksdb::{DatabaseConfig, CompactionProfile}; use super::*; diff --git a/ethcore/src/account_provider/mod.rs b/ethcore/src/account_provider/mod.rs index 04bc4f409..c4025685c 100644 --- a/ethcore/src/account_provider/mod.rs +++ b/ethcore/src/account_provider/mod.rs @@ -32,11 +32,11 @@ use ethstore::{ random_string, SecretVaultRef, StoreAccountRef, OpaqueSecret, }; use parking_lot::RwLock; +use types::transaction::{Action, Transaction}; pub use ethstore::ethkey::Signature; pub use ethstore::{Derivation, IndexDerivation, KeyFile}; pub use hardware_wallet::{Error as HardwareError, HardwareWalletManager, KeyPath, TransactionInfo}; -pub use super::transaction::{Action, Transaction}; /// Type of unlock. #[derive(Clone, PartialEq)] diff --git a/ethcore/src/block.rs b/ethcore/src/block.rs index 00da9fa9f..6fa219b06 100644 --- a/ethcore/src/block.rs +++ b/ethcore/src/block.rs @@ -36,59 +36,58 @@ use std::collections::HashSet; use std::sync::Arc; use bytes::Bytes; +use ethereum_types::{H256, U256, Address, Bloom}; + use engines::EthEngine; use error::{Error, BlockError}; -use ethereum_types::{H256, U256, Address, Bloom}; use factory::Factories; -use hash::keccak; -use header::{Header, ExtendedHeader}; -use receipt::{Receipt, TransactionOutcome}; -use rlp::{Rlp, RlpStream, Encodable, Decodable, DecoderError, encode_list}; use state_db::StateDB; use state::State; use trace::Tracing; -use transaction::{UnverifiedTransaction, SignedTransaction, Error as TransactionError}; use triehash::ordered_trie_root; use unexpected::{Mismatch, OutOfBounds}; use verification::PreverifiedBlock; use vm::{EnvInfo, LastHashes}; -/// A block, encoded as it is on the block chain. -#[derive(Default, Debug, Clone, PartialEq)] -pub struct Block { - /// The header of this block. - pub header: Header, - /// The transactions in this block. - pub transactions: Vec, - /// The uncles of this block. - pub uncles: Vec
, +use hash::keccak; +use rlp::{RlpStream, Encodable, encode_list}; +use types::transaction::{SignedTransaction, Error as TransactionError}; +use types::block::Block; +use types::header::{Header, ExtendedHeader}; +use types::receipt::{Receipt, TransactionOutcome}; + +/// Block that is ready for transactions to be added. +/// +/// It's a bit like a Vec, except that whenever a transaction is pushed, we execute it and +/// maintain the system `state()`. We also archive execution receipts in preparation for later block creation. +pub struct OpenBlock<'x> { + block: ExecutedBlock, + engine: &'x EthEngine, } -impl Block { - /// Get the RLP-encoding of the block with the seal. - pub fn rlp_bytes(&self) -> Bytes { - let mut block_rlp = RlpStream::new_list(3); - block_rlp.append(&self.header); - block_rlp.append_list(&self.transactions); - block_rlp.append_list(&self.uncles); - block_rlp.out() - } +/// Just like `OpenBlock`, except that we've applied `Engine::on_close_block`, finished up the non-seal header fields, +/// and collected the uncles. +/// +/// There is no function available to push a transaction. +#[derive(Clone)] +pub struct ClosedBlock { + block: ExecutedBlock, + unclosed_state: State, } -impl Decodable for Block { - fn decode(rlp: &Rlp) -> Result { - if rlp.as_raw().len() != rlp.payload_info()?.total() { - return Err(DecoderError::RlpIsTooBig); - } - if rlp.item_count()? != 3 { - return Err(DecoderError::RlpIncorrectListLen); - } - Ok(Block { - header: rlp.val_at(0)?, - transactions: rlp.list_at(1)?, - uncles: rlp.list_at(2)?, - }) - } +/// Just like `ClosedBlock` except that we can't reopen it and it's faster. +/// +/// We actually store the post-`Engine::on_close_block` state, unlike in `ClosedBlock` where it's the pre. +#[derive(Clone)] +pub struct LockedBlock { + block: ExecutedBlock, +} + +/// A block that has a valid seal. +/// +/// The block's header has valid seal arguments. The block cannot be reversed into a `ClosedBlock` or `OpenBlock`. +pub struct SealedBlock { + block: ExecutedBlock, } /// An internal type for a block's common elements. @@ -216,40 +215,6 @@ impl ::parity_machine::Transactions for ExecutedBlock { } } -/// Block that is ready for transactions to be added. -/// -/// It's a bit like a Vec, except that whenever a transaction is pushed, we execute it and -/// maintain the system `state()`. We also archive execution receipts in preparation for later block creation. -pub struct OpenBlock<'x> { - block: ExecutedBlock, - engine: &'x EthEngine, -} - -/// Just like `OpenBlock`, except that we've applied `Engine::on_close_block`, finished up the non-seal header fields, -/// and collected the uncles. -/// -/// There is no function available to push a transaction. -#[derive(Clone)] -pub struct ClosedBlock { - block: ExecutedBlock, - unclosed_state: State, -} - -/// Just like `ClosedBlock` except that we can't reopen it and it's faster. -/// -/// We actually store the post-`Engine::on_close_block` state, unlike in `ClosedBlock` where it's the pre. -#[derive(Clone)] -pub struct LockedBlock { - block: ExecutedBlock, -} - -/// A block that has a valid seal. -/// -/// The block's header has valid seal arguments. The block cannot be reversed into a `ClosedBlock` or `OpenBlock`. -pub struct SealedBlock { - block: ExecutedBlock, -} - impl<'x> OpenBlock<'x> { /// Create a new `OpenBlock` ready for transaction pushing. pub fn new<'a>( @@ -630,14 +595,15 @@ mod tests { use engines::EthEngine; use vm::LastHashes; use error::Error; - use header::Header; use factory::Factories; use state_db::StateDB; - use views::BlockView; use ethereum_types::Address; use std::sync::Arc; - use transaction::SignedTransaction; use verification::queue::kind::blocks::Unverified; + use types::transaction::SignedTransaction; + use types::header::Header; + use types::view; + use types::views::BlockView; /// Enact the block given by `block_bytes` using `engine` on the database `db` with given `parent` block header fn enact_bytes( diff --git a/ethcore/src/client/ancient_import.rs b/ethcore/src/client/ancient_import.rs index 4586a04ee..0a71dc6d3 100644 --- a/ethcore/src/client/ancient_import.rs +++ b/ethcore/src/client/ancient_import.rs @@ -18,13 +18,13 @@ use std::sync::Arc; -use blockchain::BlockChain; use engines::{EthEngine, EpochVerifier}; -use header::Header; use machine::EthereumMachine; -use rand::Rng; +use blockchain::BlockChain; use parking_lot::RwLock; +use rand::Rng; +use types::header::Header; // do "heavy" verification on ~1/50 blocks, randomly sampled. const HEAVY_VERIFY_RATE: f32 = 0.02; diff --git a/ethcore/src/client/chain_notify.rs b/ethcore/src/client/chain_notify.rs index 47a77397d..8a5ed375a 100644 --- a/ethcore/src/client/chain_notify.rs +++ b/ethcore/src/client/chain_notify.rs @@ -16,7 +16,7 @@ use bytes::Bytes; use ethereum_types::{H256, U256}; -use transaction::UnverifiedTransaction; +use types::transaction::UnverifiedTransaction; use blockchain::ImportRoute; use std::time::Duration; use std::collections::HashMap; diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 1b49d0092..bd8002849 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -14,25 +14,36 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use std::collections::{HashSet, BTreeMap, VecDeque}; use std::cmp; +use std::collections::{HashSet, BTreeMap, VecDeque}; use std::str::FromStr; use std::sync::atomic::{AtomicUsize, AtomicBool, Ordering as AtomicOrdering}; use std::sync::{Arc, Weak}; use std::time::{Instant, Duration}; -// util -use hash::keccak; +use blockchain::{BlockReceipts, BlockChain, BlockChainDB, BlockProvider, TreeRoute, ImportRoute, TransactionAddress, ExtrasInsert}; use bytes::Bytes; +use ethcore_miner::pool::VerifiedTransaction; +use ethereum_types::{H256, Address, U256}; +use evm::Schedule; +use hash::keccak; +use io::IoChannel; use itertools::Itertools; use journaldb; -use trie::{TrieSpec, TrieFactory, Trie}; use kvdb::{DBValue, KeyValueDB, DBTransaction}; +use parking_lot::{Mutex, RwLock}; +use rand::OsRng; +use types::transaction::{self, LocalizedTransaction, UnverifiedTransaction, SignedTransaction, Action}; +use trie::{TrieSpec, TrieFactory, Trie}; +use types::ancestry_action::AncestryAction; +use types::encoded; +use types::filter::Filter; +use types::log_entry::LocalizedLogEntry; +use types::receipt::{Receipt, LocalizedReceipt}; +use types::{BlockNumber, header::{Header, ExtendedHeader}}; +use vm::{EnvInfo, LastHashes}; -// other -use ethereum_types::{H256, Address, U256}; use block::{IsBlock, LockedBlock, Drain, ClosedBlock, OpenBlock, enact_verified, SealedBlock}; -use blockchain::{BlockReceipts, BlockChain, BlockChainDB, BlockProvider, TreeRoute, ImportRoute, TransactionAddress, ExtrasInsert}; use client::ancient_import::AncientVerifier; use client::{ Nonce, Balance, ChainInfo, BlockInfo, CallContract, TransactionInfo, @@ -48,37 +59,24 @@ use client::{ IoClient, BadBlocks, }; use client::bad_blocks; -use encoded; use engines::{EthEngine, EpochTransition, ForkChoice}; use error::{ ImportErrorKind, ExecutionError, CallError, BlockError, QueueError, QueueErrorKind, Error as EthcoreError, EthcoreResult, ErrorKind as EthcoreErrorKind }; -use vm::{EnvInfo, LastHashes}; -use evm::Schedule; use executive::{Executive, Executed, TransactOptions, contract_address}; use factory::{Factories, VmFactory}; -use header::{BlockNumber, Header, ExtendedHeader}; -use io::IoChannel; -use log_entry::LocalizedLogEntry; use miner::{Miner, MinerService}; -use ethcore_miner::pool::VerifiedTransaction; -use parking_lot::{Mutex, RwLock}; -use rand::OsRng; -use receipt::{Receipt, LocalizedReceipt}; use snapshot::{self, io as snapshot_io, SnapshotClient}; use spec::Spec; -use state_db::StateDB; use state::{self, State}; -use trace; -use trace::{TraceDB, ImportRequest as TraceImportRequest, LocalizedTrace, Database as TraceDatabase}; -use transaction::{self, LocalizedTransaction, UnverifiedTransaction, SignedTransaction, Transaction, Action}; -use types::filter::Filter; -use types::ancestry_action::AncestryAction; -use verification; -use verification::{PreverifiedBlock, Verifier, BlockQueue}; -use verification::queue::kind::blocks::Unverified; +use state_db::StateDB; +use trace::{self, TraceDB, ImportRequest as TraceImportRequest, LocalizedTrace, Database as TraceDatabase}; +use transaction_ext::Transaction; use verification::queue::kind::BlockLike; +use verification::queue::kind::blocks::Unverified; +use verification::{PreverifiedBlock, Verifier, BlockQueue}; +use verification; // re-export pub use types::blockchain_info::BlockChainInfo; @@ -1231,7 +1229,7 @@ impl Client { // from the null sender, with 50M gas. fn contract_call_tx(&self, block_id: BlockId, address: Address, data: Bytes) -> SignedTransaction { let from = Address::default(); - Transaction { + transaction::Transaction { nonce: self.nonce(&from, block_id).unwrap_or_else(|| self.engine.account_start_nonce(0)), action: Action::Call(address), gas: U256::from(50_000_000), @@ -2112,7 +2110,7 @@ impl BlockChainClient for Client { fn transact_contract(&self, address: Address, data: Bytes) -> Result<(), transaction::Error> { let authoring_params = self.importer.miner.authoring_params(); - let transaction = Transaction { + let transaction = transaction::Transaction { nonce: self.latest_nonce(&authoring_params.author), action: Action::Call(address), gas: self.importer.miner.sensible_gas_limit(), @@ -2411,7 +2409,7 @@ impl super::traits::EngineClient for Client { BlockChainClient::block_number(self, id) } - fn block_header(&self, id: BlockId) -> Option<::encoded::Header> { + fn block_header(&self, id: BlockId) -> Option { BlockChainClient::block_header(self, id) } } @@ -2520,7 +2518,7 @@ mod tests { use std::sync::atomic::{AtomicBool, Ordering}; use kvdb::DBTransaction; use blockchain::ExtrasInsert; - use encoded; + use types::encoded; let client = generate_dummy_client(0); let genesis = client.chain_info().best_block_hash; @@ -2579,9 +2577,9 @@ mod tests { use hash::keccak; use super::transaction_receipt; use ethkey::KeyPair; - use log_entry::{LogEntry, LocalizedLogEntry}; - use receipt::{Receipt, LocalizedReceipt, TransactionOutcome}; - use transaction::{Transaction, LocalizedTransaction, Action}; + use types::log_entry::{LogEntry, LocalizedLogEntry}; + use types::receipt::{Receipt, LocalizedReceipt, TransactionOutcome}; + use types::transaction::{Transaction, LocalizedTransaction, Action}; // given let key = KeyPair::from_secret_slice(&keccak("test")).unwrap(); diff --git a/ethcore/src/client/evm_test_client.rs b/ethcore/src/client/evm_test_client.rs index 67e187244..0da010150 100644 --- a/ethcore/src/client/evm_test_client.rs +++ b/ethcore/src/client/evm_test_client.rs @@ -21,7 +21,8 @@ use std::sync::Arc; use ethereum_types::{H256, U256, H160}; use {factory, journaldb, trie, kvdb_memorydb}; use kvdb::{self, KeyValueDB}; -use {state, state_db, client, executive, trace, transaction, db, spec, pod_state, log_entry, receipt}; +use {state, state_db, client, executive, trace, db, spec, pod_state}; +use types::{log_entry, receipt, transaction}; use factory::Factories; use evm::{VMType, FinalizationResult}; use vm::{self, ActionParams}; diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index 3c422c49a..b2e1e23f5 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -20,20 +20,35 @@ use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering as AtomicOrder}; use std::sync::Arc; use std::collections::{HashMap, BTreeMap}; use std::mem; -use itertools::Itertools; -use rustc_hex::FromHex; -use hash::keccak; + +use blockchain::{TreeRoute, BlockReceipts}; +use bytes::Bytes; +use db::{NUM_COLUMNS, COL_STATE}; +use ethcore_miner::pool::VerifiedTransaction; use ethereum_types::{H256, U256, Address}; -use parking_lot::RwLock; -use journaldb; +use ethkey::{Generator, Random}; +use ethtrie; +use hash::keccak; +use itertools::Itertools; use kvdb::DBValue; use kvdb_memorydb; -use bytes::Bytes; +use parking_lot::RwLock; use rlp::{Rlp, RlpStream}; -use ethkey::{Generator, Random}; -use ethcore_miner::pool::VerifiedTransaction; -use transaction::{self, Transaction, LocalizedTransaction, SignedTransaction, Action}; -use blockchain::{TreeRoute, BlockReceipts}; +use rustc_hex::FromHex; +use types::transaction::{self, Transaction, LocalizedTransaction, SignedTransaction, Action}; +use types::BlockNumber; +use types::basic_account::BasicAccount; +use types::encoded; +use types::filter::Filter; +use types::header::Header; +use types::log_entry::LocalizedLogEntry; +use types::pruning_info::PruningInfo; +use types::receipt::{Receipt, LocalizedReceipt, TransactionOutcome}; +use types::view; +use types::views::BlockView; +use vm::Schedule; + +use block::{OpenBlock, SealedBlock, ClosedBlock}; use client::{ Nonce, Balance, ChainInfo, BlockInfo, ReopenBlock, CallContract, TransactionInfo, RegistryInfo, PrepareOpenBlock, BlockChainClient, BlockChainInfo, BlockStatus, BlockId, Mode, @@ -42,30 +57,18 @@ use client::{ Call, StateClient, EngineInfo, AccountData, BlockChain, BlockProducer, SealedBlockImporter, IoClient, BadBlocks, }; -use db::{NUM_COLUMNS, COL_STATE}; -use header::{Header as BlockHeader, BlockNumber}; -use filter::Filter; -use log_entry::LocalizedLogEntry; -use receipt::{Receipt, LocalizedReceipt, TransactionOutcome}; +use engines::EthEngine; use error::{Error, EthcoreResult}; -use vm::Schedule; +use executed::CallError; +use executive::Executed; +use journaldb; use miner::{self, Miner, MinerService}; use spec::Spec; -use types::basic_account::BasicAccount; -use types::pruning_info::PruningInfo; +use state::StateInfo; +use state_db::StateDB; +use trace::LocalizedTrace; use verification::queue::QueueInfo; use verification::queue::kind::blocks::Unverified; -use block::{OpenBlock, SealedBlock, ClosedBlock}; -use executive::Executed; -use error::CallError; -use trace::LocalizedTrace; -use state_db::StateDB; -use header::Header; -use encoded; -use engines::EthEngine; -use ethtrie; -use state::StateInfo; -use views::BlockView; /// Test client. pub struct TestBlockChainClient { @@ -244,11 +247,11 @@ impl TestBlockChainClient { /// Add a block to test client. pub fn add_block(&self, with: EachBlockWith, hook: F) - where F: Fn(BlockHeader) -> BlockHeader + where F: Fn(Header) -> Header { let n = self.numbers.read().len(); - let mut header = BlockHeader::new(); + let mut header = Header::new(); header.set_difficulty(From::from(n)); header.set_parent_hash(self.last_hash.read().clone()); header.set_number(n as BlockNumber); @@ -260,7 +263,7 @@ impl TestBlockChainClient { let uncles = match with { EachBlockWith::Uncle | EachBlockWith::UncleAndTransaction => { let mut uncles = RlpStream::new_list(1); - let mut uncle_header = BlockHeader::new(); + let mut uncle_header = Header::new(); uncle_header.set_difficulty(From::from(n)); uncle_header.set_parent_hash(self.last_hash.read().clone()); uncle_header.set_number(n as BlockNumber); @@ -309,7 +312,7 @@ impl TestBlockChainClient { /// Make a bad block by setting invalid parent hash. pub fn corrupt_block_parent(&self, n: BlockNumber) { let hash = self.block_hash(BlockId::Number(n)).unwrap(); - let mut header: BlockHeader = self.block_header(BlockId::Number(n)).unwrap().decode().expect("decoding failed"); + let mut header: Header = self.block_header(BlockId::Number(n)).unwrap().decode().expect("decoding failed"); header.set_parent_hash(H256::from(42)); let mut rlp = RlpStream::new_list(3); rlp.append(&header); @@ -935,7 +938,7 @@ impl super::traits::EngineClient for TestBlockChainClient { BlockChainClient::block_number(self, id) } - fn block_header(&self, id: BlockId) -> Option<::encoded::Header> { + fn block_header(&self, id: BlockId) -> Option { BlockChainClient::block_header(self, id) } } diff --git a/ethcore/src/client/trace.rs b/ethcore/src/client/trace.rs index 5f1b6c4f4..61f9da614 100644 --- a/ethcore/src/client/trace.rs +++ b/ethcore/src/client/trace.rs @@ -16,11 +16,10 @@ //! Bridge between Tracedb and Blockchain. -use ethereum_types::H256; -use header::BlockNumber; -use trace::DatabaseExtras as TraceDatabaseExtras; use blockchain::{BlockChain, BlockProvider, TransactionAddress}; -pub use types::trace_filter::Filter; +use ethereum_types::H256; +use trace::DatabaseExtras as TraceDatabaseExtras; +use types::BlockNumber; impl TraceDatabaseExtras for BlockChain { fn block_hash(&self, block_number: BlockNumber) -> Option { diff --git a/ethcore/src/client/traits.rs b/ethcore/src/client/traits.rs index 55d527013..8ccf78fc2 100644 --- a/ethcore/src/client/traits.rs +++ b/ethcore/src/client/traits.rs @@ -17,40 +17,39 @@ use std::collections::BTreeMap; use std::sync::Arc; +use blockchain::{BlockReceipts, TreeRoute}; +use bytes::Bytes; +use ethcore_miner::pool::VerifiedTransaction; +use ethereum_types::{H256, U256, Address}; +use evm::Schedule; use itertools::Itertools; +use kvdb::DBValue; +use types::transaction::{self, LocalizedTransaction, SignedTransaction}; +use types::BlockNumber; +use types::basic_account::BasicAccount; +use types::block_status::BlockStatus; +use types::blockchain_info::BlockChainInfo; +use types::call_analytics::CallAnalytics; +use types::encoded; +use types::filter::Filter; +use types::header::Header; +use types::ids::*; +use types::log_entry::LocalizedLogEntry; +use types::pruning_info::PruningInfo; +use types::receipt::LocalizedReceipt; +use types::trace_filter::Filter as TraceFilter; +use vm::LastHashes; use block::{OpenBlock, SealedBlock, ClosedBlock}; -use blockchain::{BlockReceipts, TreeRoute}; use client::Mode; -use encoded; -use vm::LastHashes; -use error::{Error, CallError, EthcoreResult}; -use evm::Schedule; +use engines::EthEngine; +use error::{Error, EthcoreResult}; +use executed::CallError; use executive::Executed; -use filter::Filter; -use header::{BlockNumber}; -use log_entry::LocalizedLogEntry; -use receipt::LocalizedReceipt; +use state::StateInfo; use trace::LocalizedTrace; -use transaction::{self, LocalizedTransaction, SignedTransaction}; use verification::queue::QueueInfo as BlockQueueInfo; use verification::queue::kind::blocks::Unverified; -use state::StateInfo; -use header::Header; -use engines::EthEngine; - -use ethereum_types::{H256, U256, Address}; -use ethcore_miner::pool::VerifiedTransaction; -use bytes::Bytes; -use kvdb::DBValue; - -use types::ids::*; -use types::basic_account::BasicAccount; -use types::trace_filter::Filter as TraceFilter; -use types::call_analytics::CallAnalytics; -use types::blockchain_info::BlockChainInfo; -use types::block_status::BlockStatus; -use types::pruning_info::PruningInfo; /// State information to be used during client query pub enum StateOrBlock { diff --git a/ethcore/src/engines/authority_round/mod.rs b/ethcore/src/engines/authority_round/mod.rs index 6cf7f4091..4a5b9b40b 100644 --- a/ethcore/src/engines/authority_round/mod.rs +++ b/ethcore/src/engines/authority_round/mod.rs @@ -34,7 +34,6 @@ use error::{Error, ErrorKind, BlockError}; use ethjson; use machine::{AuxiliaryData, Call, EthereumMachine}; use hash::keccak; -use header::{Header, BlockNumber, ExtendedHeader}; use super::signer::EngineSigner; use super::validator_set::{ValidatorSet, SimpleList, new_validator_set}; use self::finality::RollingFinality; @@ -44,6 +43,8 @@ use itertools::{self, Itertools}; use rlp::{encode, Decodable, DecoderError, Encodable, RlpStream, Rlp}; use ethereum_types::{H256, H520, Address, U128, U256}; use parking_lot::{Mutex, RwLock}; +use types::BlockNumber; +use types::header::{Header, ExtendedHeader}; use types::ancestry_action::AncestryAction; use unexpected::{Mismatch, OutOfBounds}; @@ -1528,7 +1529,7 @@ mod tests { use hash::keccak; use ethereum_types::{Address, H520, H256, U256}; use ethkey::Signature; - use header::Header; + use types::header::Header; use rlp::encode; use block::*; use test_helpers::{ @@ -1537,7 +1538,7 @@ mod tests { }; use account_provider::AccountProvider; use spec::Spec; - use transaction::{Action, Transaction}; + use types::transaction::{Action, Transaction}; use engines::{Seal, Engine, EngineError, EthEngine}; use engines::validator_set::{TestSet, SimpleList}; use error::{Error, ErrorKind}; diff --git a/ethcore/src/engines/basic_authority.rs b/ethcore/src/engines/basic_authority.rs index 034d79107..4740e46b1 100644 --- a/ethcore/src/engines/basic_authority.rs +++ b/ethcore/src/engines/basic_authority.rs @@ -25,9 +25,9 @@ use block::*; use engines::{Engine, Seal, ConstructedVerifier, EngineError}; use error::{BlockError, Error}; use ethjson; -use header::{Header, ExtendedHeader}; use client::EngineClient; use machine::{AuxiliaryData, Call, EthereumMachine}; +use types::header::{Header, ExtendedHeader}; use super::signer::EngineSigner; use super::validator_set::{ValidatorSet, SimpleList, new_validator_set}; @@ -215,7 +215,7 @@ mod tests { use block::*; use test_helpers::get_temp_state_db; use account_provider::AccountProvider; - use header::Header; + use types::header::Header; use spec::Spec; use engines::Seal; use tempdir::TempDir; diff --git a/ethcore/src/engines/instant_seal.rs b/ethcore/src/engines/instant_seal.rs index 5a4eaa642..5a9079167 100644 --- a/ethcore/src/engines/instant_seal.rs +++ b/ethcore/src/engines/instant_seal.rs @@ -95,7 +95,7 @@ mod tests { use ethereum_types::{H520, Address}; use test_helpers::get_temp_state_db; use spec::Spec; - use header::Header; + use types::header::Header; use block::*; use engines::Seal; diff --git a/ethcore/src/engines/mod.rs b/ethcore/src/engines/mod.rs index 2d47002d1..0585319a7 100644 --- a/ethcore/src/engines/mod.rs +++ b/ethcore/src/engines/mod.rs @@ -24,7 +24,6 @@ mod signer; mod validator_set; pub mod block_reward; -pub mod epoch; pub use self::authority_round::AuthorityRound; pub use self::basic_authority::BasicAuthority; @@ -32,20 +31,23 @@ pub use self::epoch::{EpochVerifier, Transition as EpochTransition}; pub use self::instant_seal::{InstantSeal, InstantSealParams}; pub use self::null_engine::NullEngine; +// TODO [ToDr] Remove re-export (#10130) +pub use types::engines::ForkChoice; +pub use types::engines::epoch; + use std::sync::{Weak, Arc}; use std::collections::{BTreeMap, HashMap}; use std::{fmt, error}; -use self::epoch::PendingTransition; - use account_provider::AccountProvider; use builtin::Builtin; use vm::{EnvInfo, Schedule, CreateContractAddress, CallType, ActionValue}; use error::Error; -use header::{Header, BlockNumber}; +use types::BlockNumber; +use types::header::Header; use snapshot::SnapshotComponents; use spec::CommonParams; -use transaction::{self, UnverifiedTransaction, SignedTransaction}; +use types::transaction::{self, UnverifiedTransaction, SignedTransaction}; use ethkey::{Password, Signature}; use parity_machine::{Machine, LocalizedMachine as Localized, TotalScoredHeader}; @@ -58,15 +60,6 @@ use types::ancestry_action::AncestryAction; /// As defined in https://github.com/ethereum/EIPs/pull/210 pub const DEFAULT_BLOCKHASH_CONTRACT: &'static str = "73fffffffffffffffffffffffffffffffffffffffe33141561006a5760014303600035610100820755610100810715156100455760003561010061010083050761010001555b6201000081071515610064576000356101006201000083050761020001555b5061013e565b4360003512151561008457600060405260206040f361013d565b61010060003543031315156100a857610100600035075460605260206060f361013c565b6101006000350715156100c55762010000600035430313156100c8565b60005b156100ea576101006101006000350507610100015460805260206080f361013b565b620100006000350715156101095763010000006000354303131561010c565b60005b1561012f57610100620100006000350507610200015460a052602060a0f361013a565b600060c052602060c0f35b5b5b5b5b"; -/// Fork choice. -#[derive(Debug, PartialEq, Eq)] -pub enum ForkChoice { - /// Choose the new block. - New, - /// Choose the current best block. - Old, -} - /// Voting errors. #[derive(Debug)] pub enum EngineError { @@ -175,7 +168,7 @@ pub fn default_system_or_code_call<'a>(machine: &'a ::machine::EthereumMachine, pub type Headers<'a, H> = Fn(H256) -> Option + 'a; /// Type alias for a function we can query pending transitions by block hash through. -pub type PendingTransitionStore<'a> = Fn(H256) -> Option + 'a; +pub type PendingTransitionStore<'a> = Fn(H256) -> Option + 'a; /// Proof dependent on state. pub trait StateDependentProof: Send + Sync { diff --git a/ethcore/src/engines/null_engine.rs b/ethcore/src/engines/null_engine.rs index af5aedaac..3d5fa7e84 100644 --- a/ethcore/src/engines/null_engine.rs +++ b/ethcore/src/engines/null_engine.rs @@ -14,12 +14,12 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use ethereum_types::U256; use engines::Engine; use engines::block_reward::{self, RewardKind}; -use header::BlockNumber; +use ethereum_types::U256; use machine::WithRewards; use parity_machine::{Header, LiveBlock, WithBalances, TotalScoredHeader}; +use types::BlockNumber; /// Params for a null engine. #[derive(Clone, Default)] diff --git a/ethcore/src/engines/validator_set/contract.rs b/ethcore/src/engines/validator_set/contract.rs index 80cc690ab..9bc75be47 100644 --- a/ethcore/src/engines/validator_set/contract.rs +++ b/ethcore/src/engines/validator_set/contract.rs @@ -21,11 +21,12 @@ use std::sync::Weak; use bytes::Bytes; use ethereum_types::{H256, Address}; +use machine::{AuxiliaryData, Call, EthereumMachine}; use parking_lot::RwLock; +use types::BlockNumber; +use types::header::Header; use client::EngineClient; -use header::{Header, BlockNumber}; -use machine::{AuxiliaryData, Call, EthereumMachine}; use super::{ValidatorSet, SimpleList, SystemCall}; use super::safe_contract::ValidatorSafeContract; @@ -67,7 +68,7 @@ impl ValidatorContract { } impl ValidatorSet for ValidatorContract { - fn default_caller(&self, id: ::ids::BlockId) -> Box { + fn default_caller(&self, id: ::types::ids::BlockId) -> Box { self.validators.default_caller(id) } @@ -139,7 +140,7 @@ mod tests { use bytes::ToPretty; use rlp::encode; use spec::Spec; - use header::Header; + use types::header::Header; use account_provider::AccountProvider; use miner::MinerService; use types::ids::BlockId; diff --git a/ethcore/src/engines/validator_set/mod.rs b/ethcore/src/engines/validator_set/mod.rs index d7018d14e..97de4cd61 100644 --- a/ethcore/src/engines/validator_set/mod.rs +++ b/ethcore/src/engines/validator_set/mod.rs @@ -24,13 +24,16 @@ mod contract; mod multi; use std::sync::Weak; -use ids::BlockId; -use ethereum_types::{H256, Address}; + use bytes::Bytes; +use ethereum_types::{H256, Address}; use ethjson::spec::ValidatorSet as ValidatorSpec; -use client::EngineClient; -use header::{Header, BlockNumber}; use machine::{AuxiliaryData, Call, EthereumMachine}; +use types::BlockNumber; +use types::header::Header; +use types::ids::BlockId; + +use client::EngineClient; #[cfg(test)] pub use self::test::TestSet; diff --git a/ethcore/src/engines/validator_set/multi.rs b/ethcore/src/engines/validator_set/multi.rs index 24fb2d890..176217ffe 100644 --- a/ethcore/src/engines/validator_set/multi.rs +++ b/ethcore/src/engines/validator_set/multi.rs @@ -18,11 +18,14 @@ use std::collections::BTreeMap; use std::sync::Weak; + +use bytes::Bytes; use ethereum_types::{H256, Address}; use parking_lot::RwLock; -use bytes::Bytes; -use ids::BlockId; -use header::{BlockNumber, Header}; +use types::BlockNumber; +use types::header::Header; +use types::ids::BlockId; + use client::EngineClient; use machine::{AuxiliaryData, Call, EthereumMachine}; use super::{SystemCall, ValidatorSet}; @@ -152,7 +155,7 @@ mod tests { use engines::EpochChange; use engines::validator_set::ValidatorSet; use ethkey::Secret; - use header::Header; + use types::header::Header; use miner::MinerService; use spec::Spec; use test_helpers::{generate_dummy_client_with_spec_and_accounts, generate_dummy_client_with_spec_and_data}; diff --git a/ethcore/src/engines/validator_set/safe_contract.rs b/ethcore/src/engines/validator_set/safe_contract.rs index 91083c056..026fda057 100644 --- a/ethcore/src/engines/validator_set/safe_contract.rs +++ b/ethcore/src/engines/validator_set/safe_contract.rs @@ -16,24 +16,26 @@ /// Validator set maintained in a contract, updated using `getValidators` method. +use std::sync::{Weak, Arc}; + use bytes::Bytes; -use client::EngineClient; +use ethabi::FunctionOutputDecoder; use ethereum_types::{H256, U256, Address, Bloom}; use hash::keccak; -use header::Header; -use ids::BlockId; use kvdb::DBValue; -use log_entry::LogEntry; -use machine::{AuxiliaryData, Call, EthereumMachine, AuxiliaryRequest}; use memory_cache::MemoryLruCache; use parking_lot::RwLock; -use receipt::Receipt; use rlp::{Rlp, RlpStream}; -use std::sync::{Weak, Arc}; +use types::header::Header; +use types::ids::BlockId; +use types::log_entry::LogEntry; +use types::receipt::Receipt; +use unexpected::Mismatch; + +use client::EngineClient; +use machine::{AuxiliaryData, Call, EthereumMachine, AuxiliaryRequest}; use super::{SystemCall, ValidatorSet}; use super::simple_list::SimpleList; -use unexpected::Mismatch; -use ethabi::FunctionOutputDecoder; use_contract!(validator_set, "res/contracts/validator_set.json"); @@ -91,7 +93,7 @@ fn encode_first_proof(header: &Header, state_items: &[Vec]) -> Bytes { fn check_first_proof(machine: &EthereumMachine, contract_address: Address, old_header: Header, state_items: &[DBValue]) -> Result, String> { - use transaction::{Action, Transaction}; + use types::transaction::{Action, Transaction}; // TODO: match client contract_call_tx more cleanly without duplication. const PROVIDED_GAS: u64 = 50_000_000; @@ -343,7 +345,7 @@ impl ValidatorSet for ValidatorSafeContract { } } - fn epoch_set(&self, first: bool, machine: &EthereumMachine, _number: ::header::BlockNumber, proof: &[u8]) + fn epoch_set(&self, first: bool, machine: &EthereumMachine, _number: ::types::BlockNumber, proof: &[u8]) -> Result<(SimpleList, Option), ::error::Error> { let rlp = Rlp::new(proof); @@ -444,7 +446,7 @@ mod tests { use types::ids::BlockId; use spec::Spec; use account_provider::AccountProvider; - use transaction::{Transaction, Action}; + use types::transaction::{Transaction, Action}; use client::{ChainInfo, BlockInfo, ImportBlock}; use ethkey::Secret; use miner::MinerService; @@ -532,10 +534,10 @@ mod tests { #[test] fn detects_bloom() { - use header::Header; use engines::EpochChange; use machine::AuxiliaryRequest; - use log_entry::LogEntry; + use types::header::Header; + use types::log_entry::LogEntry; let client = generate_dummy_client_with_spec_and_accounts(Spec::new_validator_safe_contract, None); let engine = client.engine().clone(); @@ -571,7 +573,7 @@ mod tests { #[test] fn initial_contract_is_signal() { - use header::Header; + use types::header::Header; use engines::{EpochChange, Proof}; let client = generate_dummy_client_with_spec_and_accounts(Spec::new_validator_safe_contract, None); diff --git a/ethcore/src/engines/validator_set/simple_list.rs b/ethcore/src/engines/validator_set/simple_list.rs index dc269600d..55782ed6b 100644 --- a/ethcore/src/engines/validator_set/simple_list.rs +++ b/ethcore/src/engines/validator_set/simple_list.rs @@ -20,7 +20,8 @@ use heapsize::HeapSizeOf; use ethereum_types::{H256, Address}; use machine::{AuxiliaryData, Call, EthereumMachine}; -use header::{BlockNumber, Header}; +use types::BlockNumber; +use types::header::Header; use super::ValidatorSet; /// Validator set containing a known set of addresses. @@ -64,7 +65,7 @@ impl HeapSizeOf for SimpleList { } impl ValidatorSet for SimpleList { - fn default_caller(&self, _block_id: ::ids::BlockId) -> Box { + fn default_caller(&self, _block_id: ::types::ids::BlockId) -> Box { Box::new(|_, _| Err("Simple list doesn't require calls.".into())) } diff --git a/ethcore/src/engines/validator_set/test.rs b/ethcore/src/engines/validator_set/test.rs index 9650526e5..c6c904878 100644 --- a/ethcore/src/engines/validator_set/test.rs +++ b/ethcore/src/engines/validator_set/test.rs @@ -19,12 +19,14 @@ use std::str::FromStr; use std::sync::Arc; use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering}; -use heapsize::HeapSizeOf; -use ethereum_types::{H256, Address}; + use bytes::Bytes; +use ethereum_types::{H256, Address}; +use heapsize::HeapSizeOf; +use types::BlockNumber; +use types::header::Header; use machine::{AuxiliaryData, Call, EthereumMachine}; -use header::{Header, BlockNumber}; use super::{ValidatorSet, SimpleList}; /// Set used for testing with a single validator. @@ -57,7 +59,7 @@ impl HeapSizeOf for TestSet { } impl ValidatorSet for TestSet { - fn default_caller(&self, _block_id: ::ids::BlockId) -> Box { + fn default_caller(&self, _block_id: ::types::ids::BlockId) -> Box { Box::new(|_, _| Err("Test set doesn't require calls.".into())) } diff --git a/ethcore/src/error.rs b/ethcore/src/error.rs index 02268747a..48bff82f2 100644 --- a/ethcore/src/error.rs +++ b/ethcore/src/error.rs @@ -18,18 +18,19 @@ use std::{fmt, error}; use std::time::SystemTime; + use ethereum_types::{H256, U256, Address, Bloom}; -use snappy::InvalidInput; -use unexpected::{Mismatch, OutOfBounds}; -use ethtrie::TrieError; -use io::*; -use header::BlockNumber; -use snapshot::Error as SnapshotError; -use engines::EngineError; use ethkey::Error as EthkeyError; -use account_provider::SignError as AccountsError; -use transaction::Error as TransactionError; +use ethtrie::TrieError; use rlp; +use snappy::InvalidInput; +use snapshot::Error as SnapshotError; +use types::transaction::Error as TransactionError; +use types::BlockNumber; +use unexpected::{Mismatch, OutOfBounds}; + +use account_provider::SignError as AccountsError; +use engines::EngineError; pub use executed::{ExecutionError, CallError}; @@ -165,7 +166,7 @@ error_chain! { } foreign_links { - Channel(IoError) #[doc = "Io channel error"]; + Channel(::io::IoError) #[doc = "Io channel error"]; } } @@ -224,7 +225,7 @@ error_chain! { } foreign_links { - Io(IoError) #[doc = "Io create error"]; + Io(::io::IoError) #[doc = "Io create error"]; StdIo(::std::io::Error) #[doc = "Error concerning the Rust standard library's IO subsystem."]; Trie(TrieError) #[doc = "Error concerning TrieDBs."]; Execution(ExecutionError) #[doc = "Error concerning EVM code execution."]; diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index f705f33ef..5a625c630 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -14,21 +14,24 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use std::path::Path; use std::cmp; use std::collections::BTreeMap; +use std::path::Path; use std::sync::Arc; -use hash::{KECCAK_EMPTY_LIST_RLP}; -use engines::block_reward::{self, BlockRewardContract, RewardKind}; -use ethash::{self, quick_get_difficulty, slow_hash_block_number, EthashManager, OptimizeFor}; + use ethereum_types::{H256, H64, U256}; -use unexpected::{OutOfBounds, Mismatch}; -use block::*; -use error::{BlockError, Error}; -use header::{Header, BlockNumber, ExtendedHeader}; -use engines::{self, Engine}; use ethjson; +use hash::{KECCAK_EMPTY_LIST_RLP}; use rlp::Rlp; +use types::header::{Header, ExtendedHeader}; +use types::BlockNumber; +use unexpected::{OutOfBounds, Mismatch}; + +use block::ExecutedBlock; +use engines::block_reward::{self, BlockRewardContract, RewardKind}; +use engines::{self, Engine}; +use error::{BlockError, Error}; +use ethash::{self, quick_get_difficulty, slow_hash_block_number, EthashManager, OptimizeFor}; use machine::EthereumMachine; /// Number of blocks in an ethash snapshot. @@ -482,7 +485,7 @@ mod tests { use block::*; use test_helpers::get_temp_state_db; use error::{BlockError, Error, ErrorKind}; - use header::Header; + use types::header::Header; use spec::Spec; use engines::Engine; use super::super::{new_morden, new_mcip3_test, new_homestead_test_machine}; diff --git a/ethcore/src/ethereum/mod.rs b/ethcore/src/ethereum/mod.rs index 467b978d2..0910ee65e 100644 --- a/ethcore/src/ethereum/mod.rs +++ b/ethcore/src/ethereum/mod.rs @@ -180,7 +180,8 @@ mod tests { use state::*; use super::*; use test_helpers::get_temp_state_db; - use views::BlockView; + use types::view; + use types::views::BlockView; #[test] fn ensure_db_good() { diff --git a/ethcore/src/executed.rs b/ethcore/src/executed.rs index 2dc0c041b..171071118 100644 --- a/ethcore/src/executed.rs +++ b/ethcore/src/executed.rs @@ -21,8 +21,8 @@ use bytes::Bytes; use ethtrie; use vm; use trace::{VMTrace, FlatTrace}; -use log_entry::LogEntry; -use state_diff::StateDiff; +use types::state_diff::StateDiff; +use types::log_entry::LogEntry; use std::{fmt, error}; diff --git a/ethcore/src/executive.rs b/ethcore/src/executive.rs index bfc4e46fa..4517ec543 100644 --- a/ethcore/src/executive.rs +++ b/ethcore/src/executive.rs @@ -21,7 +21,7 @@ use hash::keccak; use ethereum_types::{H256, U256, U512, Address}; use bytes::{Bytes, BytesRef}; use state::{Backend as StateBackend, State, Substate, CleanupMode}; -use error::ExecutionError; +use executed::ExecutionError; use machine::EthereumMachine as Machine; use evm::{CallType, Finalize, FinalizationResult}; use vm::{ @@ -31,7 +31,8 @@ use vm::{ use factory::VmFactory; use externalities::*; use trace::{self, Tracer, VMTracer}; -use transaction::{Action, SignedTransaction}; +use types::transaction::{Action, SignedTransaction}; +use transaction_ext::Transaction; use crossbeam; pub use executed::{Executed, ExecutionResult}; @@ -1179,7 +1180,7 @@ mod tests { use trace::trace; use trace::{FlatTrace, Tracer, NoopTracer, ExecutiveTracer}; use trace::{VMTrace, VMOperation, VMExecutedOperation, MemoryDiff, StorageDiff, VMTracer, NoopVMTracer, ExecutiveVMTracer}; - use transaction::{Action, Transaction}; + use types::transaction::{Action, Transaction}; fn make_frontier_machine(max_depth: usize) -> EthereumMachine { let mut machine = ::ethereum::new_frontier_test_machine(); diff --git a/ethcore/src/externalities.rs b/ethcore/src/externalities.rs index 778ef5cc7..9e488c211 100644 --- a/ethcore/src/externalities.rs +++ b/ethcore/src/externalities.rs @@ -27,7 +27,7 @@ use vm::{ Ext, ContractCreateResult, MessageCallResult, CreateContractAddress, ReturnData, TrapKind }; -use transaction::UNSIGNED_SENDER; +use types::transaction::UNSIGNED_SENDER; use trace::{Tracer, VMTracer}; /// Policy for handling output data on `RETURN` opcode. @@ -340,7 +340,7 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for Externalities<'a, T, V, B> } fn log(&mut self, topics: Vec, data: &[u8]) -> vm::Result<()> { - use log_entry::LogEntry; + use types::log_entry::LogEntry; if self.static_flag { return Err(vm::Error::MutableCallInStaticContext); diff --git a/ethcore/src/json_tests/difficulty.rs b/ethcore/src/json_tests/difficulty.rs index 23a855945..f70696c94 100644 --- a/ethcore/src/json_tests/difficulty.rs +++ b/ethcore/src/json_tests/difficulty.rs @@ -15,7 +15,7 @@ // along with Parity. If not, see . use ethjson; -use header::Header; +use types::header::Header; use ethereum_types::U256; use spec::Spec; diff --git a/ethcore/src/json_tests/state.rs b/ethcore/src/json_tests/state.rs index 733e26802..7dcb6dd81 100644 --- a/ethcore/src/json_tests/state.rs +++ b/ethcore/src/json_tests/state.rs @@ -20,7 +20,7 @@ use pod_state::PodState; use trace; use client::{EvmTestClient, EvmTestError, TransactResult}; use ethjson; -use transaction::SignedTransaction; +use types::transaction::SignedTransaction; use vm::EnvInfo; use super::SKIP_TEST_STATE; use super::HookType; diff --git a/ethcore/src/json_tests/transaction.rs b/ethcore/src/json_tests/transaction.rs index 70021c9e9..b1475225b 100644 --- a/ethcore/src/json_tests/transaction.rs +++ b/ethcore/src/json_tests/transaction.rs @@ -17,10 +17,11 @@ use std::path::Path; use super::test_common::*; use client::EvmTestClient; -use header::Header; use ethjson; use rlp::Rlp; -use transaction::UnverifiedTransaction; +use types::header::Header; +use types::transaction::UnverifiedTransaction; +use transaction_ext::Transaction; /// Run transaction jsontests on a given folder. pub fn run_test_path(p: &Path, skip: &[&'static str], h: &mut H) { @@ -67,7 +68,7 @@ fn do_json_test(json_data: &[u8], start_stop_hook: &mu let minimal = t.gas_required(&spec.engine.schedule(header.number())).into(); if t.gas < minimal { - return Err(::transaction::Error::InsufficientGas { + return Err(::types::transaction::Error::InsufficientGas { minimal, got: t.gas, }.into()); } diff --git a/ethcore/src/lib.rs b/ethcore/src/lib.rs index fd9dd217f..21cf3320b 100644 --- a/ethcore/src/lib.rs +++ b/ethcore/src/lib.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -#![warn(missing_docs)] +#![warn(missing_docs, unused_extern_crates)] //! Ethcore library //! @@ -57,61 +57,65 @@ // error_chain foreign_links. #![recursion_limit="128"] -extern crate blooms_db; +extern crate ansi_term; extern crate bn; extern crate byteorder; -extern crate crossbeam; extern crate common_types as types; +extern crate crossbeam; +extern crate ethabi; extern crate ethash; +extern crate ethcore_blockchain as blockchain; extern crate ethcore_bloom_journal as bloom_journal; -extern crate parity_crypto; +extern crate ethcore_db as db; extern crate ethcore_io as io; -extern crate parity_bytes as bytes; -extern crate ethcore_logger; extern crate ethcore_miner; -#[cfg(feature = "stratum")] -extern crate ethcore_stratum; -extern crate ethcore_transaction as transaction; extern crate ethereum_types; extern crate ethjson; extern crate ethkey; - +extern crate ethstore; extern crate hashdb; +extern crate heapsize; extern crate itertools; +extern crate journaldb; +extern crate keccak_hash as hash; +extern crate keccak_hasher; extern crate kvdb; extern crate kvdb_memorydb; -extern crate kvdb_rocksdb; +extern crate len_caching_lock; extern crate lru_cache; -extern crate num_cpus; +extern crate memory_cache; +extern crate memorydb; extern crate num; +extern crate num_cpus; +extern crate parity_bytes as bytes; +extern crate parity_crypto; extern crate parity_machine; +extern crate parity_snappy as snappy; extern crate parking_lot; +extern crate patricia_trie as trie; +extern crate patricia_trie_ethereum as ethtrie; extern crate rand; extern crate rayon; extern crate rlp; -extern crate rlp_compress; -extern crate keccak_hash as hash; -extern crate keccak_hasher; -extern crate heapsize; -extern crate memorydb; -extern crate patricia_trie as trie; -extern crate patricia_trie_ethereum as ethtrie; -extern crate triehash_ethereum as triehash; -extern crate ansi_term; -extern crate unexpected; -extern crate parity_snappy as snappy; -extern crate ethabi; extern crate rustc_hex; +extern crate serde; extern crate stats; +extern crate triehash_ethereum as triehash; +extern crate unexpected; extern crate using_queue; extern crate vm; extern crate wasm; -extern crate memory_cache; -extern crate journaldb; -extern crate serde; + +#[cfg(feature = "stratum")] +extern crate ethcore_stratum; #[cfg(any(test, feature = "json-tests", feature = "test-helpers"))] extern crate tempdir; -extern crate len_caching_lock; +#[cfg(any(test, feature = "json-tests"))] +extern crate ethcore_logger; +#[cfg(any(test, feature = "test-helpers"))] +extern crate kvdb_rocksdb; +#[cfg(any(test, feature = "test-helpers"))] +extern crate blooms_db; #[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android"))] extern crate hardware_wallet; @@ -143,24 +147,18 @@ extern crate evm; #[cfg(test)] extern crate env_logger; - -pub extern crate ethstore; - -#[macro_use] -pub mod views; +#[cfg(test)] +extern crate rlp_compress; pub mod account_provider; pub mod block; pub mod builtin; pub mod client; -pub mod db; -pub mod encoded; pub mod engines; pub mod error; pub mod ethereum; pub mod executed; pub mod executive; -pub mod header; pub mod machine; pub mod miner; pub mod pod_state; @@ -170,12 +168,11 @@ pub mod spec; pub mod state; pub mod state_db; pub mod trace; +pub mod transaction_ext; pub mod verification; -mod cache_manager; mod account_db; mod externalities; -mod blockchain; mod factory; mod tx_filter; @@ -186,8 +183,6 @@ pub mod json_tests; #[cfg(any(test, feature = "test-helpers"))] pub mod test_helpers; -pub use types::*; pub use executive::contract_address; pub use evm::CreateContractAddress; -pub use blockchain::{BlockChainDB, BlockChainDBHandler}; pub use trie::TrieSpec; diff --git a/ethcore/src/machine.rs b/ethcore/src/machine.rs index 47cea8505..1580c364e 100644 --- a/ethcore/src/machine.rs +++ b/ethcore/src/machine.rs @@ -20,23 +20,24 @@ use std::collections::{BTreeMap, HashMap}; use std::cmp; use std::sync::Arc; +use ethereum_types::{U256, H256, Address}; +use rlp::Rlp; +use types::transaction::{self, SYSTEM_ADDRESS, UNSIGNED_SENDER, UnverifiedTransaction, SignedTransaction}; +use types::BlockNumber; +use types::header::{Header, ExtendedHeader}; +use vm::{CallType, ActionParams, ActionValue, ParamsType}; +use vm::{EnvInfo, Schedule, CreateContractAddress}; + use block::{ExecutedBlock, IsBlock}; use builtin::Builtin; use client::{BlockInfo, CallContract}; use error::Error; use executive::Executive; -use header::{BlockNumber, Header, ExtendedHeader}; use spec::CommonParams; use state::{CleanupMode, Substate}; use trace::{NoopTracer, NoopVMTracer, Tracer, ExecutiveTracer, RewardType, Tracing}; -use transaction::{self, SYSTEM_ADDRESS, UNSIGNED_SENDER, UnverifiedTransaction, SignedTransaction}; use tx_filter::TransactionFilter; -use ethereum_types::{U256, H256, Address}; -use rlp::Rlp; -use vm::{CallType, ActionParams, ActionValue, ParamsType}; -use vm::{EnvInfo, Schedule, CreateContractAddress}; - /// Parity tries to round block.gas_limit to multiple of this constant pub const PARITY_GAS_LIMIT_DETERMINANT: U256 = U256([37, 0, 0, 0]); @@ -408,7 +409,7 @@ pub struct AuxiliaryData<'a> { /// The full block bytes, including the header. pub bytes: Option<&'a [u8]>, /// The block receipts. - pub receipts: Option<&'a [::receipt::Receipt]>, + pub receipts: Option<&'a [::types::receipt::Receipt]>, } /// Type alias for a function we can make calls through synchronously. @@ -526,7 +527,7 @@ mod tests { Default::default(), ethparams, ); - let mut header = ::header::Header::new(); + let mut header = ::types::header::Header::new(); header.set_number(15); let res = machine.verify_transaction_basic(&transaction, &header); @@ -546,8 +547,8 @@ mod tests { ethparams, ); - let mut parent = ::header::Header::new(); - let mut header = ::header::Header::new(); + let mut parent = ::types::header::Header::new(); + let mut header = ::types::header::Header::new(); header.set_number(1); // this test will work for this constant only diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index c73887800..70d35d6de 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -21,39 +21,42 @@ use std::sync::Arc; use ansi_term::Colour; use bytes::Bytes; -use engines::{EthEngine, Seal}; -use error::{Error, ErrorKind, ExecutionError}; use ethcore_miner::gas_pricer::GasPricer; use ethcore_miner::pool::{self, TransactionQueue, VerifiedTransaction, QueueStatus, PrioritizationStrategy}; #[cfg(feature = "work-notify")] use ethcore_miner::work_notify::NotifyWork; use ethereum_types::{H256, U256, Address}; +use ethkey::Password; use io::IoChannel; +use miner::pool_client::{PoolClient, CachedNonceClient, NonceCache}; +use miner; use parking_lot::{Mutex, RwLock}; use rayon::prelude::*; -use transaction::{ +use types::transaction::{ self, Action, UnverifiedTransaction, SignedTransaction, PendingTransaction, }; +use types::BlockNumber; +use types::block::Block; +use types::header::Header; +use types::receipt::RichReceipt; use using_queue::{UsingQueue, GetAction}; use account_provider::{AccountProvider, SignError as AccountError}; -use block::{ClosedBlock, IsBlock, Block, SealedBlock}; +use block::{ClosedBlock, IsBlock, SealedBlock}; use client::{ BlockChain, ChainInfo, CallContract, BlockProducer, SealedBlockImporter, Nonce, TransactionInfo, TransactionId }; use client::{BlockId, ClientIoMessage}; +use engines::{EthEngine, Seal}; +use error::{Error, ErrorKind}; +use executed::ExecutionError; use executive::contract_address; -use header::{Header, BlockNumber}; -use miner; -use miner::pool_client::{PoolClient, CachedNonceClient, NonceCache}; -use receipt::RichReceipt; use spec::Spec; use state::State; -use ethkey::Password; /// Different possible definitions for pending transaction set. #[derive(Debug, PartialEq)] @@ -1284,13 +1287,13 @@ mod tests { use super::*; use ethkey::{Generator, Random}; use hash::keccak; - use header::BlockNumber; use rustc_hex::FromHex; + use types::BlockNumber; use client::{TestBlockChainClient, EachBlockWith, ChainInfo, ImportSealedBlock}; use miner::{MinerService, PendingOrdering}; use test_helpers::{generate_dummy_client, generate_dummy_client_with_spec_and_accounts}; - use transaction::{Transaction}; + use types::transaction::{Transaction}; #[test] fn should_prepare_block_to_seal() { diff --git a/ethcore/src/miner/mod.rs b/ethcore/src/miner/mod.rs index cca6e8c30..95ee00e9c 100644 --- a/ethcore/src/miner/mod.rs +++ b/ethcore/src/miner/mod.rs @@ -33,21 +33,23 @@ use std::sync::Arc; use std::collections::{BTreeSet, BTreeMap}; use bytes::Bytes; -use ethereum_types::{H256, U256, Address}; use ethcore_miner::pool::{VerifiedTransaction, QueueStatus, local_transactions}; +use ethereum_types::{H256, U256, Address}; +use ethkey::Password; +use types::transaction::{self, UnverifiedTransaction, SignedTransaction, PendingTransaction}; +use types::BlockNumber; +use types::block::Block; +use types::header::Header; +use types::receipt::RichReceipt; -use block::{Block, SealedBlock}; +use block::SealedBlock; use client::{ CallContract, RegistryInfo, ScheduleInfo, BlockChain, BlockProducer, SealedBlockImporter, ChainInfo, AccountData, Nonce, }; use error::Error; -use header::{BlockNumber, Header}; -use receipt::RichReceipt; -use transaction::{self, UnverifiedTransaction, SignedTransaction, PendingTransaction}; use state::StateInfo; -use ethkey::Password; /// Provides methods to verify incoming external transactions pub trait TransactionVerifierClient: Send + Sync diff --git a/ethcore/src/miner/pool_client.rs b/ethcore/src/miner/pool_client.rs index 25d9a809c..8be5b1e37 100644 --- a/ethcore/src/miner/pool_client.rs +++ b/ethcore/src/miner/pool_client.rs @@ -25,19 +25,20 @@ use std::{ use ethereum_types::{H256, U256, Address}; use ethcore_miner::pool; use ethcore_miner::pool::client::NonceClient; -use transaction::{ +use types::transaction::{ self, UnverifiedTransaction, SignedTransaction, }; +use types::header::Header; use parking_lot::RwLock; use account_provider::AccountProvider; use client::{TransactionId, BlockInfo, CallContract, Nonce}; use engines::EthEngine; -use header::Header; use miner; use miner::service_transaction_checker::ServiceTransactionChecker; +use transaction_ext::Transaction; /// Cache for state nonces. #[derive(Debug, Clone)] diff --git a/ethcore/src/miner/service_transaction_checker.rs b/ethcore/src/miner/service_transaction_checker.rs index ecae30558..f8b635481 100644 --- a/ethcore/src/miner/service_transaction_checker.rs +++ b/ethcore/src/miner/service_transaction_checker.rs @@ -17,7 +17,7 @@ //! A service transactions contract checker. use client::{RegistryInfo, CallContract, BlockId}; -use transaction::SignedTransaction; +use types::transaction::SignedTransaction; use ethabi::FunctionOutputDecoder; use_contract!(service_transaction, "res/contracts/service_transaction.json"); diff --git a/ethcore/src/snapshot/account.rs b/ethcore/src/snapshot/account.rs index 2ccf910f7..5c2df5ac3 100644 --- a/ethcore/src/snapshot/account.rs +++ b/ethcore/src/snapshot/account.rs @@ -17,7 +17,7 @@ //! Account state encoding and decoding use account_db::{AccountDB, AccountDBMut}; -use basic_account::BasicAccount; +use types::basic_account::BasicAccount; use bytes::Bytes; use ethereum_types::{H256, U256}; use ethtrie::{TrieDB, TrieDBMut}; @@ -207,7 +207,7 @@ pub fn from_fat_rlp( #[cfg(test)] mod tests { use account_db::{AccountDB, AccountDBMut}; - use basic_account::BasicAccount; + use types::basic_account::BasicAccount; use test_helpers::get_temp_state_db; use snapshot::tests::helpers::fill_storage; diff --git a/ethcore/src/snapshot/block.rs b/ethcore/src/snapshot/block.rs index 3a18015e0..8cd65871a 100644 --- a/ethcore/src/snapshot/block.rs +++ b/ethcore/src/snapshot/block.rs @@ -16,14 +16,14 @@ //! Block RLP compression. -use block::Block; -use header::Header; -use hash::keccak; -use views::BlockView; -use rlp::{DecoderError, RlpStream, Rlp}; -use ethereum_types::H256; use bytes::Bytes; +use ethereum_types::H256; +use hash::keccak; +use rlp::{DecoderError, RlpStream, Rlp}; use triehash::ordered_trie_root; +use types::block::Block; +use types::header::Header; +use types::views::BlockView; const HEADER_FIELDS: usize = 8; const BLOCK_FIELDS: usize = 2; @@ -132,13 +132,14 @@ impl AbridgedBlock { #[cfg(test)] mod tests { - use views::BlockView; - use block::Block; use super::AbridgedBlock; - use transaction::{Action, Transaction}; - use ethereum_types::{H256, U256, Address}; use bytes::Bytes; + use ethereum_types::{H256, U256, Address}; + use types::transaction::{Action, Transaction}; + use types::block::Block; + use types::view; + use types::views::BlockView; fn encode_block(b: &Block) -> Bytes { b.rlp_bytes() diff --git a/ethcore/src/snapshot/consensus/authority.rs b/ethcore/src/snapshot/consensus/authority.rs index 1e21d6fcc..43c177b97 100644 --- a/ethcore/src/snapshot/consensus/authority.rs +++ b/ethcore/src/snapshot/consensus/authority.rs @@ -24,21 +24,20 @@ use super::{SnapshotComponents, Rebuilder, ChunkSink}; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; -use blockchain::{BlockChain, BlockChainDB, BlockProvider}; use engines::{EthEngine, EpochVerifier, EpochTransition}; use machine::EthereumMachine; -use ids::BlockId; -use header::Header; -use receipt::Receipt; use snapshot::{Error, ManifestData, Progress}; -use itertools::{Position, Itertools}; -use rlp::{RlpStream, Rlp}; -use ethereum_types::{H256, U256}; -use kvdb::KeyValueDB; +use blockchain::{BlockChain, BlockChainDB, BlockProvider}; use bytes::Bytes; -use encoded; - +use ethereum_types::{H256, U256}; +use itertools::{Position, Itertools}; +use kvdb::KeyValueDB; +use rlp::{RlpStream, Rlp}; +use types::encoded; +use types::header::Header; +use types::ids::BlockId; +use types::receipt::Receipt; /// Snapshot creation and restoration for PoA chains. /// Chunk format: @@ -319,7 +318,7 @@ impl Rebuilder for ChunkRebuilder { } if is_last_chunk { - use block::Block; + use types::block::Block; let last_rlp = rlp.at(num_items - 1)?; let block = Block { diff --git a/ethcore/src/snapshot/consensus/work.rs b/ethcore/src/snapshot/consensus/work.rs index b287ae9bb..7f4c6dfc6 100644 --- a/ethcore/src/snapshot/consensus/work.rs +++ b/ethcore/src/snapshot/consensus/work.rs @@ -35,7 +35,7 @@ use kvdb::KeyValueDB; use bytes::Bytes; use rlp::{RlpStream, Rlp}; use rand::OsRng; -use encoded; +use types::encoded; /// Snapshot creation and restoration for PoW chains. /// This includes blocks from the head of the chain as a @@ -250,7 +250,7 @@ impl Rebuilder for PowRebuilder { let pair = rlp.at(idx)?; let abridged_rlp = pair.at(0)?.as_raw().to_owned(); let abridged_block = AbridgedBlock::from_raw(abridged_rlp); - let receipts: Vec<::receipt::Receipt> = pair.list_at(1)?; + let receipts: Vec<::types::receipt::Receipt> = pair.list_at(1)?; let receipts_root = ordered_trie_root(pair.at(1)?.iter().map(|r| r.as_raw())); let block = abridged_block.to_block(parent_hash, cur_number, receipts_root)?; diff --git a/ethcore/src/snapshot/error.rs b/ethcore/src/snapshot/error.rs index eb1a16278..f0bb7d7ad 100644 --- a/ethcore/src/snapshot/error.rs +++ b/ethcore/src/snapshot/error.rs @@ -18,7 +18,7 @@ use std::fmt; -use ids::BlockId; +use types::ids::BlockId; use ethereum_types::H256; use ethtrie::TrieError; diff --git a/ethcore/src/snapshot/mod.rs b/ethcore/src/snapshot/mod.rs index d52bf55cd..9bcf26e3f 100644 --- a/ethcore/src/snapshot/mod.rs +++ b/ethcore/src/snapshot/mod.rs @@ -28,8 +28,8 @@ use hash::{keccak, KECCAK_NULL_RLP, KECCAK_EMPTY}; use account_db::{AccountDB, AccountDBMut}; use blockchain::{BlockChain, BlockProvider}; use engines::EthEngine; -use header::Header; -use ids::BlockId; +use types::header::Header; +use types::ids::BlockId; use ethereum_types::{H256, U256}; use hashdb::HashDB; diff --git a/ethcore/src/snapshot/service.rs b/ethcore/src/snapshot/service.rs index f547faab1..d85f6028a 100644 --- a/ethcore/src/snapshot/service.rs +++ b/ethcore/src/snapshot/service.rs @@ -33,7 +33,7 @@ use engines::EthEngine; use error::{Error, ErrorKind as SnapshotErrorKind}; use snapshot::{Error as SnapshotError}; use hash::keccak; -use ids::BlockId; +use types::ids::BlockId; use io::IoChannel; diff --git a/ethcore/src/snapshot/tests/helpers.rs b/ethcore/src/snapshot/tests/helpers.rs index 1bcbdb9f4..4a629afb4 100644 --- a/ethcore/src/snapshot/tests/helpers.rs +++ b/ethcore/src/snapshot/tests/helpers.rs @@ -23,7 +23,7 @@ use std::sync::Arc; use hash::{KECCAK_NULL_RLP}; use account_db::AccountDBMut; -use basic_account::BasicAccount; +use types::basic_account::BasicAccount; use blockchain::{BlockChain, BlockChainDB}; use client::{Client, ChainInfo}; use engines::EthEngine; @@ -142,7 +142,7 @@ pub fn compare_dbs(one: &HashDB, two: &HashDB (Box, TempDir) { - use ids::BlockId; + use types::ids::BlockId; let tempdir = TempDir::new("").unwrap(); let path = tempdir.path().join("file"); diff --git a/ethcore/src/snapshot/tests/proof_of_authority.rs b/ethcore/src/snapshot/tests/proof_of_authority.rs index d8c721518..c6e0b20d0 100644 --- a/ethcore/src/snapshot/tests/proof_of_authority.rs +++ b/ethcore/src/snapshot/tests/proof_of_authority.rs @@ -26,7 +26,7 @@ use ethkey::Secret; use snapshot::tests::helpers as snapshot_helpers; use spec::Spec; use test_helpers::generate_dummy_client_with_spec_and_accounts; -use transaction::{Transaction, Action, SignedTransaction}; +use types::transaction::{Transaction, Action, SignedTransaction}; use tempdir::TempDir; use ethereum_types::Address; diff --git a/ethcore/src/snapshot/tests/service.rs b/ethcore/src/snapshot/tests/service.rs index fd070eab8..2718c7e00 100644 --- a/ethcore/src/snapshot/tests/service.rs +++ b/ethcore/src/snapshot/tests/service.rs @@ -22,7 +22,7 @@ use std::sync::Arc; use tempdir::TempDir; use blockchain::BlockProvider; use client::{Client, ClientConfig, ImportBlock, BlockInfo}; -use ids::BlockId; +use types::ids::BlockId; use snapshot::io::{PackedReader, PackedWriter, SnapshotReader, SnapshotWriter}; use snapshot::service::{Service, ServiceParams}; use snapshot::{chunk_state, chunk_secondary, ManifestData, Progress, SnapshotService, RestorationStatus}; @@ -153,7 +153,7 @@ fn guards_delete_folders() { #[test] fn keep_ancient_blocks() { - ::env_logger::init().ok(); + ::env_logger::try_init().ok(); // Test variables const NUM_BLOCKS: u64 = 500; @@ -272,7 +272,7 @@ fn keep_ancient_blocks() { #[test] fn recover_aborted_recovery() { - ::env_logger::init().ok(); + ::env_logger::try_init().ok(); const NUM_BLOCKS: u32 = 400; let gas_prices = vec![1.into(), 2.into(), 3.into(), 999.into()]; diff --git a/ethcore/src/snapshot/tests/state.rs b/ethcore/src/snapshot/tests/state.rs index 82cee2af0..b8cacfab5 100644 --- a/ethcore/src/snapshot/tests/state.rs +++ b/ethcore/src/snapshot/tests/state.rs @@ -20,7 +20,7 @@ use std::sync::Arc; use std::sync::atomic::AtomicBool; use hash::{KECCAK_NULL_RLP, keccak}; -use basic_account::BasicAccount; +use types::basic_account::BasicAccount; use snapshot::account; use snapshot::{chunk_state, Error as SnapshotError, Progress, StateRebuilder, SNAPSHOT_SUBPARTS}; use snapshot::io::{PackedReader, PackedWriter, SnapshotReader, SnapshotWriter}; diff --git a/ethcore/src/snapshot/watcher.rs b/ethcore/src/snapshot/watcher.rs index 0eee7133b..2ef0beb89 100644 --- a/ethcore/src/snapshot/watcher.rs +++ b/ethcore/src/snapshot/watcher.rs @@ -18,7 +18,7 @@ use parking_lot::Mutex; use client::{BlockInfo, Client, ChainNotify, NewBlocks, ClientIoMessage}; -use ids::BlockId; +use types::ids::BlockId; use io::IoChannel; use ethereum_types::H256; diff --git a/ethcore/src/spec/spec.rs b/ethcore/src/spec/spec.rs index 2b1804caa..360e255a5 100644 --- a/ethcore/src/spec/spec.rs +++ b/ethcore/src/spec/spec.rs @@ -29,10 +29,12 @@ use memorydb::MemoryDB; use parking_lot::RwLock; use rlp::{Rlp, RlpStream}; use rustc_hex::{FromHex, ToHex}; +use types::BlockNumber; +use types::encoded; +use types::header::Header; use vm::{EnvInfo, CallType, ActionValue, ActionParams, ParamsType}; use builtin::Builtin; -use encoded; use engines::{ EthEngine, NullEngine, InstantSeal, InstantSealParams, BasicAuthority, AuthorityRound, DEFAULT_BLOCKHASH_CONTRACT @@ -40,7 +42,6 @@ use engines::{ use error::Error; use executive::Executive; use factory::Factories; -use header::{BlockNumber, Header}; use machine::EthereumMachine; use pod_state::PodState; use spec::Genesis; @@ -840,7 +841,7 @@ impl Spec { /// initialize genesis epoch data, using in-memory database for /// constructor. pub fn genesis_epoch_data(&self) -> Result, String> { - use transaction::{Action, Transaction}; + use types::transaction::{Action, Transaction}; use journaldb; use kvdb_memorydb; @@ -989,8 +990,9 @@ mod tests { use super::*; use state::State; use test_helpers::get_temp_state_db; - use views::BlockView; use tempdir::TempDir; + use types::view; + use types::views::BlockView; // https://github.com/paritytech/parity-ethereum/issues/1840 #[test] diff --git a/ethcore/src/state/account.rs b/ethcore/src/state/account.rs index 912547877..6d6f39db9 100644 --- a/ethcore/src/state/account.rs +++ b/ethcore/src/state/account.rs @@ -31,7 +31,7 @@ use ethtrie::{TrieFactory, TrieDB, SecTrieDB, Result as TrieResult}; use pod_account::*; use rlp::{RlpStream, encode}; use lru_cache::LruCache; -use basic_account::BasicAccount; +use types::basic_account::BasicAccount; use std::cell::{RefCell, Cell}; diff --git a/ethcore/src/state/mod.rs b/ethcore/src/state/mod.rs index b2c52e583..ace2e77ec 100644 --- a/ethcore/src/state/mod.rs +++ b/ethcore/src/state/mod.rs @@ -26,7 +26,7 @@ use std::fmt; use std::sync::Arc; use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY}; -use receipt::{Receipt, TransactionOutcome}; +use types::receipt::{Receipt, TransactionOutcome}; use machine::EthereumMachine as Machine; use vm::EnvInfo; use error::Error; @@ -38,7 +38,7 @@ use pod_state::{self, PodState}; use types::basic_account::BasicAccount; use executed::{Executed, ExecutionError}; use types::state_diff::StateDiff; -use transaction::SignedTransaction; +use types::transaction::SignedTransaction; use state_db::StateDB; use factory::VmFactory; @@ -1316,7 +1316,7 @@ mod tests { use machine::EthereumMachine; use vm::EnvInfo; use spec::*; - use transaction::*; + use types::transaction::*; use ethcore_logger::init_log; use trace::{FlatTrace, TraceError, trace}; use evm::CallType; diff --git a/ethcore/src/state/substate.rs b/ethcore/src/state/substate.rs index 5565c8f91..784c5e9ea 100644 --- a/ethcore/src/state/substate.rs +++ b/ethcore/src/state/substate.rs @@ -17,7 +17,7 @@ //! Execution environment substate. use std::collections::HashSet; use ethereum_types::Address; -use log_entry::LogEntry; +use types::log_entry::LogEntry; use evm::{Schedule, CleanDustMode}; use super::CleanupMode; @@ -69,7 +69,7 @@ impl Substate { #[cfg(test)] mod tests { use super::Substate; - use log_entry::LogEntry; + use types::log_entry::LogEntry; #[test] fn created() { diff --git a/ethcore/src/state_db.rs b/ethcore/src/state_db.rs index d103f1081..3cc3dfe08 100644 --- a/ethcore/src/state_db.rs +++ b/ethcore/src/state_db.rs @@ -26,13 +26,14 @@ use db::COL_ACCOUNT_BLOOM; use ethereum_types::{H256, Address}; use hash::keccak; use hashdb::HashDB; -use keccak_hasher::KeccakHasher; -use header::BlockNumber; use journaldb::JournalDB; +use keccak_hasher::KeccakHasher; use kvdb::{KeyValueDB, DBTransaction, DBValue}; use lru_cache::LruCache; use memory_cache::MemoryLruCache; use parking_lot::Mutex; +use types::BlockNumber; + use state::{self, Account}; /// Value used to initialize bloom bitmap size. diff --git a/ethcore/src/test_helpers.rs b/ethcore/src/test_helpers.rs index 9f00f9662..54e35da45 100644 --- a/ethcore/src/test_helpers.rs +++ b/ethcore/src/test_helpers.rs @@ -19,32 +19,35 @@ use std::path::Path; use std::sync::Arc; use std::{fs, io}; -use account_provider::AccountProvider; -use ethereum_types::{H256, U256, Address}; -use block::{OpenBlock, Drain}; + use blockchain::{BlockChain, BlockChainDB, BlockChainDBHandler, Config as BlockChainConfig, ExtrasInsert}; +use blooms_db; use bytes::Bytes; -use client::{Client, ClientConfig, ChainInfo, ImportBlock, ChainNotify, ChainMessageType, PrepareOpenBlock}; +use ethereum_types::{H256, U256, Address}; use ethkey::KeyPair; use evm::Factory as EvmFactory; -use factory::Factories; use hash::keccak; -use header::Header; -use io::*; -use miner::Miner; -use parking_lot::RwLock; -use rlp::{self, RlpStream}; -use spec::Spec; -use state_db::StateDB; -use state::*; -use transaction::{Action, Transaction, SignedTransaction}; -use views::BlockView; -use blooms_db; +use io::IoChannel; use kvdb::KeyValueDB; use kvdb_rocksdb::{self, Database, DatabaseConfig}; +use parking_lot::RwLock; +use rlp::{self, RlpStream}; use tempdir::TempDir; +use types::transaction::{Action, Transaction, SignedTransaction}; +use types::encoded; +use types::header::Header; +use types::view; +use types::views::BlockView; + +use account_provider::AccountProvider; +use block::{OpenBlock, Drain}; +use client::{Client, ClientConfig, ChainInfo, ImportBlock, ChainNotify, ChainMessageType, PrepareOpenBlock}; +use factory::Factories; +use miner::Miner; +use spec::Spec; +use state::*; +use state_db::StateDB; use verification::queue::kind::blocks::Unverified; -use encoded; /// Creates test block with corresponding header pub fn create_test_block(header: &Header) -> Bytes { diff --git a/ethcore/src/tests/blockchain.rs b/ethcore/src/tests/blockchain.rs new file mode 100644 index 000000000..bf38d7842 --- /dev/null +++ b/ethcore/src/tests/blockchain.rs @@ -0,0 +1,61 @@ +// Copyright 2015-2018 Parity Technologies (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 . + +use blockchain::BlockProvider; + +use test_helpers::{ + generate_dummy_blockchain, + generate_dummy_blockchain_with_extra, + generate_dummy_empty_blockchain, +}; + +#[test] +fn can_contain_arbitrary_block_sequence() { + let bc = generate_dummy_blockchain(50); + assert_eq!(bc.best_block_number(), 49); +} + +#[test] +fn can_collect_garbage() { + let bc = generate_dummy_blockchain(3000); + + assert_eq!(bc.best_block_number(), 2999); + let best_hash = bc.best_block_hash(); + let mut block_header = bc.block_header_data(&best_hash); + + while !block_header.is_none() { + block_header = bc.block_header_data(&block_header.unwrap().parent_hash()); + } + assert!(bc.cache_size().blocks > 1024 * 1024); + + for _ in 0..2 { + bc.collect_garbage(); + } + assert!(bc.cache_size().blocks < 1024 * 1024); +} + +#[test] +fn can_contain_arbitrary_block_sequence_with_extra() { + let bc = generate_dummy_blockchain_with_extra(25); + assert_eq!(bc.best_block_number(), 24); +} + +#[test] +fn can_contain_only_genesis_block() { + let bc = generate_dummy_empty_blockchain(); + assert_eq!(bc.best_block_number(), 0); +} + diff --git a/ethcore/src/tests/client.rs b/ethcore/src/tests/client.rs index 8f598a6c2..b8fad28c1 100644 --- a/ethcore/src/tests/client.rs +++ b/ethcore/src/tests/client.rs @@ -16,27 +16,29 @@ use std::str::FromStr; use std::sync::Arc; + +use ethereum_types::{U256, Address}; +use ethkey::KeyPair; use hash::keccak; use io::IoChannel; -use client::{BlockChainClient, Client, ClientConfig, BlockId, ChainInfo, BlockInfo, PrepareOpenBlock, ImportSealedBlock, ImportBlock}; -use state::{self, State, CleanupMode}; -use executive::{Executive, TransactOptions}; -use ethereum; +use tempdir::TempDir; +use types::transaction::{PendingTransaction, Transaction, Action, Condition}; +use types::filter::Filter; +use types::view; +use types::views::BlockView; + use block::IsBlock; +use client::{BlockChainClient, Client, ClientConfig, BlockId, ChainInfo, BlockInfo, PrepareOpenBlock, ImportSealedBlock, ImportBlock}; +use ethereum; +use executive::{Executive, TransactOptions}; +use miner::{Miner, PendingOrdering, MinerService}; +use spec::Spec; +use state::{self, State, CleanupMode}; use test_helpers::{ + self, generate_dummy_client, push_blocks_to_client, get_test_client_with_blocks, get_good_dummy_block_seq, generate_dummy_client_with_data, get_good_dummy_block, get_bad_state_dummy_block }; -use types::filter::Filter; -use ethereum_types::{U256, Address}; -use miner::{Miner, PendingOrdering}; -use spec::Spec; -use views::BlockView; -use ethkey::KeyPair; -use transaction::{PendingTransaction, Transaction, Action, Condition}; -use miner::MinerService; -use tempdir::TempDir; -use test_helpers; use verification::queue::kind::blocks::Unverified; #[test] diff --git a/ethcore/src/tests/evm.rs b/ethcore/src/tests/evm.rs index 25ca8afd0..3da872223 100644 --- a/ethcore/src/tests/evm.rs +++ b/ethcore/src/tests/evm.rs @@ -24,7 +24,7 @@ use executive::Executive; use state::Substate; use test_helpers::get_temp_state_with_factory; use trace::{NoopVMTracer, NoopTracer}; -use transaction::SYSTEM_ADDRESS; +use types::transaction::SYSTEM_ADDRESS; use rustc_hex::FromHex; diff --git a/ethcore/src/tests/mod.rs b/ethcore/src/tests/mod.rs index d1d5b6ef7..900336c3d 100644 --- a/ethcore/src/tests/mod.rs +++ b/ethcore/src/tests/mod.rs @@ -15,5 +15,6 @@ // along with Parity. If not, see . mod client; +mod blockchain; mod evm; mod trace; diff --git a/ethcore/src/tests/trace.rs b/ethcore/src/tests/trace.rs index 24ef37800..3bfb5071f 100644 --- a/ethcore/src/tests/trace.rs +++ b/ethcore/src/tests/trace.rs @@ -26,14 +26,15 @@ use client::*; use test_helpers::get_temp_state_db; use client::{BlockChainClient, Client, ClientConfig}; use std::sync::Arc; -use header::Header; use miner::Miner; -use transaction::{Action, Transaction}; -use views::BlockView; +use types::transaction::{Action, Transaction}; use trace::{RewardType, LocalizedTrace}; use trace::trace::Action::Reward; use test_helpers; use verification::queue::kind::blocks::Unverified; +use types::header::Header; +use types::view; +use types::views::BlockView; #[test] fn can_trace_block_and_uncle_reward() { diff --git a/ethcore/src/trace/db.rs b/ethcore/src/trace/db.rs index 12e628269..e6d026eb7 100644 --- a/ethcore/src/trace/db.rs +++ b/ethcore/src/trace/db.rs @@ -17,16 +17,19 @@ //! Trace database. use std::collections::HashMap; use std::sync::Arc; -use blockchain::{BlockChainDB}; -use heapsize::HeapSizeOf; + + +use blockchain::BlockChainDB; +use db::cache_manager::CacheManager; +use db::{self, Key, Writable, Readable, CacheUpdatePolicy}; use ethereum_types::{H256, H264}; +use heapsize::HeapSizeOf; use kvdb::{DBTransaction}; use parking_lot::RwLock; -use header::BlockNumber; +use types::BlockNumber; + use trace::{LocalizedTrace, Config, Filter, Database as TraceDatabase, ImportRequest, DatabaseExtras}; -use db::{self, Key, Writable, Readable, CacheUpdatePolicy}; -use super::flat::{FlatTrace, FlatBlockTraces, FlatTransactionTraces}; -use cache_manager::CacheManager; +use trace::flat::{FlatTrace, FlatBlockTraces, FlatTransactionTraces}; const TRACE_DB_VER: &'static [u8] = b"1.0"; @@ -333,7 +336,7 @@ mod tests { use std::sync::Arc; use ethereum_types::{H256, U256, Address}; use kvdb::{DBTransaction}; - use header::BlockNumber; + use types::BlockNumber; use trace::{Config, TraceDB, Database as TraceDatabase, DatabaseExtras, ImportRequest}; use trace::{Filter, LocalizedTrace, AddressesFilter, TraceError}; use trace::trace::{Call, Action, Res}; diff --git a/ethcore/src/trace/import.rs b/ethcore/src/trace/import.rs index b720b0b86..af2170760 100644 --- a/ethcore/src/trace/import.rs +++ b/ethcore/src/trace/import.rs @@ -16,7 +16,8 @@ //! Traces import request. use ethereum_types::H256; -use header::BlockNumber; +use types::BlockNumber; + use trace::FlatBlockTraces; /// Traces import request. diff --git a/ethcore/src/trace/mod.rs b/ethcore/src/trace/mod.rs index 87e14f4df..449ce1342 100644 --- a/ethcore/src/trace/mod.rs +++ b/ethcore/src/trace/mod.rs @@ -39,7 +39,7 @@ pub use self::types::filter::{Filter, AddressesFilter}; use ethereum_types::{H256, U256, Address}; use kvdb::DBTransaction; use vm::{Error as VmError, ActionParams}; -use header::BlockNumber; +use types::BlockNumber; /// This trait is used by executive to build traces. pub trait Tracer: Send { diff --git a/ethcore/src/trace/types/localized.rs b/ethcore/src/trace/types/localized.rs index 816eccc93..41eb21dc2 100644 --- a/ethcore/src/trace/types/localized.rs +++ b/ethcore/src/trace/types/localized.rs @@ -18,7 +18,7 @@ use ethereum_types::H256; use super::trace::{Action, Res}; -use header::BlockNumber; +use types::BlockNumber; /// Localized trace. #[derive(Debug, PartialEq, Clone)] diff --git a/ethcore/src/transaction_ext.rs b/ethcore/src/transaction_ext.rs new file mode 100644 index 000000000..6293148c6 --- /dev/null +++ b/ethcore/src/transaction_ext.rs @@ -0,0 +1,44 @@ +// Copyright 2015-2018 Parity Technologies (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 . + +//! Ethereum transaction + +use evm::Schedule; +use types::transaction::{self, Action}; + +/// Extends transaction with gas verification method. +pub trait Transaction { + /// Get the transaction cost in gas for this transaction. + fn gas_required(&self, schedule: &Schedule) -> u64; +} + +impl Transaction for transaction::Transaction { + fn gas_required(&self, schedule: &Schedule) -> u64 { + gas_required_for(match self.action { + Action::Create => true, + Action::Call(_) => false + }, &self.data, schedule) + } +} + +/// Get the transaction cost in gas for the given params. +fn gas_required_for(is_create: bool, data: &[u8], schedule: &Schedule) -> u64 { + data.iter().fold( + (if is_create {schedule.tx_create_gas} else {schedule.tx_gas}) as u64, + |g, b| g + (match *b { 0 => schedule.tx_data_zero_gas, _ => schedule.tx_data_non_zero_gas }) as u64 + ) +} + diff --git a/ethcore/src/tx_filter.rs b/ethcore/src/tx_filter.rs index 4a80c259b..bf1a74a77 100644 --- a/ethcore/src/tx_filter.rs +++ b/ethcore/src/tx_filter.rs @@ -23,7 +23,7 @@ use ethabi::FunctionOutputDecoder; use client::{BlockInfo, CallContract, BlockId}; use parking_lot::Mutex; use spec::CommonParams; -use transaction::{Action, SignedTransaction}; +use types::transaction::{Action, SignedTransaction}; use types::BlockNumber; use hash::KECCAK_EMPTY; @@ -149,7 +149,7 @@ mod test { use io::IoChannel; use ethkey::{Secret, KeyPair}; use super::TransactionFilter; - use transaction::{Transaction, Action}; + use types::transaction::{Transaction, Action}; use tempdir::TempDir; use test_helpers; diff --git a/ethcore/src/verification/canon_verifier.rs b/ethcore/src/verification/canon_verifier.rs index 0ace8987e..f0756ae41 100644 --- a/ethcore/src/verification/canon_verifier.rs +++ b/ethcore/src/verification/canon_verifier.rs @@ -19,7 +19,7 @@ use client::{BlockInfo, CallContract}; use engines::EthEngine; use error::Error; -use header::Header; +use types::header::Header; use super::Verifier; use super::verification; diff --git a/ethcore/src/verification/noop_verifier.rs b/ethcore/src/verification/noop_verifier.rs index d04eec9b1..53c61f7ef 100644 --- a/ethcore/src/verification/noop_verifier.rs +++ b/ethcore/src/verification/noop_verifier.rs @@ -19,7 +19,7 @@ use client::{BlockInfo, CallContract}; use engines::EthEngine; use error::Error; -use header::Header; +use types::header::Header; use super::{verification, Verifier}; /// A no-op verifier -- this will verify everything it's given immediately. diff --git a/ethcore/src/verification/queue/kind.rs b/ethcore/src/verification/queue/kind.rs index 5333cc7e3..625cd44f0 100644 --- a/ethcore/src/verification/queue/kind.rs +++ b/ethcore/src/verification/queue/kind.rs @@ -70,9 +70,9 @@ pub mod blocks { use engines::EthEngine; use error::{Error, ErrorKind, BlockError}; - use header::Header; + use types::header::Header; use verification::{PreverifiedBlock, verify_block_basic, verify_block_unordered}; - use transaction::UnverifiedTransaction; + use types::transaction::UnverifiedTransaction; use heapsize::HeapSizeOf; use ethereum_types::{H256, U256}; @@ -190,7 +190,7 @@ pub mod headers { use engines::EthEngine; use error::Error; - use header::Header; + use types::header::Header; use verification::verify_header_params; use ethereum_types::{H256, U256}; diff --git a/ethcore/src/verification/queue/mod.rs b/ethcore/src/verification/queue/mod.rs index f7de3eaa1..9541ecc1a 100644 --- a/ethcore/src/verification/queue/mod.rs +++ b/ethcore/src/verification/queue/mod.rs @@ -117,9 +117,9 @@ pub enum Status { Unknown, } -impl Into<::block_status::BlockStatus> for Status { - fn into(self) -> ::block_status::BlockStatus { - use ::block_status::BlockStatus; +impl Into<::types::block_status::BlockStatus> for Status { + fn into(self) -> ::types::block_status::BlockStatus { + use ::types::block_status::BlockStatus; match self { Status::Queued => BlockStatus::Queued, Status::Bad => BlockStatus::Bad, @@ -744,8 +744,9 @@ mod tests { use super::kind::blocks::Unverified; use test_helpers::{get_good_dummy_block_seq, get_good_dummy_block}; use error::*; - use views::BlockView; use bytes::Bytes; + use types::view; + use types::views::BlockView; // create a test block queue. // auto_scaling enables verifier adjustment. diff --git a/ethcore/src/verification/verification.rs b/ethcore/src/verification/verification.rs index 3bfe30a44..6382a7a7b 100644 --- a/ethcore/src/verification/verification.rs +++ b/ethcore/src/verification/verification.rs @@ -35,8 +35,8 @@ use blockchain::*; use client::{BlockInfo, CallContract}; use engines::EthEngine; use error::{BlockError, Error}; -use header::{BlockNumber, Header}; -use transaction::SignedTransaction; +use types::{BlockNumber, header::Header}; +use types::transaction::SignedTransaction; use verification::queue::kind::blocks::Unverified; /// Preprocessed block data gathered in `verify_block_unordered` call @@ -378,7 +378,7 @@ mod tests { use std::time::{SystemTime, UNIX_EPOCH}; use ethereum_types::{H256, BloomRef, U256}; use blockchain::{BlockDetails, TransactionAddress, BlockReceipts}; - use encoded; + use types::encoded; use hash::keccak; use engines::EthEngine; use error::BlockError::*; @@ -386,7 +386,7 @@ mod tests { use ethkey::{Random, Generator}; use spec::{CommonParams, Spec}; use test_helpers::{create_test_block_with_data, create_test_block}; - use transaction::{SignedTransaction, Transaction, UnverifiedTransaction, Action}; + use types::transaction::{SignedTransaction, Transaction, UnverifiedTransaction, Action}; use types::log_entry::{LogEntry, LocalizedLogEntry}; use rlp; use triehash::ordered_trie_root; @@ -638,14 +638,18 @@ mod tests { good_uncle1.set_parent_hash(parent8.hash()); good_uncle1.set_difficulty(parent8.difficulty().clone() + diff_inc); good_uncle1.set_timestamp(parent8.timestamp() + 10); - good_uncle1.extra_data_mut().push(1u8); + let mut ex = good_uncle1.extra_data().to_vec(); + ex.push(1u8); + good_uncle1.set_extra_data(ex); let mut good_uncle2 = good.clone(); good_uncle2.set_number(8); good_uncle2.set_parent_hash(parent7.hash()); good_uncle2.set_difficulty(parent7.difficulty().clone() + diff_inc); good_uncle2.set_timestamp(parent7.timestamp() + 10); - good_uncle2.extra_data_mut().push(2u8); + let mut ex = good_uncle2.extra_data().to_vec(); + ex.push(2u8); + good_uncle2.set_extra_data(ex); let good_uncles = vec![ good_uncle1.clone(), good_uncle2.clone() ]; let mut uncles_rlp = RlpStream::new(); @@ -702,12 +706,16 @@ mod tests { TooMuchGasUsed(OutOfBounds { max: Some(header.gas_limit().clone()), min: None, found: header.gas_used().clone() })); header = good.clone(); - header.extra_data_mut().resize(engine.maximum_extra_data_size() + 1, 0u8); + let mut ex = header.extra_data().to_vec(); + ex.resize(engine.maximum_extra_data_size() + 1, 0u8); + header.set_extra_data(ex); check_fail(basic_test(&create_test_block(&header), engine), ExtraDataOutOfBounds(OutOfBounds { max: Some(engine.maximum_extra_data_size()), min: None, found: header.extra_data().len() })); header = good.clone(); - header.extra_data_mut().resize(engine.maximum_extra_data_size() + 1, 0u8); + let mut ex = header.extra_data().to_vec(); + ex.resize(engine.maximum_extra_data_size() + 1, 0u8); + header.set_extra_data(ex); check_fail(basic_test(&create_test_block(&header), engine), ExtraDataOutOfBounds(OutOfBounds { max: Some(engine.maximum_extra_data_size()), min: None, found: header.extra_data().len() })); @@ -778,7 +786,7 @@ mod tests { #[test] fn dust_protection() { use ethkey::{Generator, Random}; - use transaction::{Transaction, Action}; + use types::transaction::{Transaction, Action}; use machine::EthereumMachine; use engines::NullEngine; diff --git a/ethcore/src/verification/verifier.rs b/ethcore/src/verification/verifier.rs index 188254b43..add4d33f6 100644 --- a/ethcore/src/verification/verifier.rs +++ b/ethcore/src/verification/verifier.rs @@ -19,7 +19,7 @@ use client::{BlockInfo, CallContract}; use engines::EthEngine; use error::Error; -use header::Header; +use types::header::Header; use super::verification; /// Should be used to verify blocks. diff --git a/ethcore/sync/Cargo.toml b/ethcore/sync/Cargo.toml index f185ef1ac..7d6a6c27e 100644 --- a/ethcore/sync/Cargo.toml +++ b/ethcore/sync/Cargo.toml @@ -9,28 +9,28 @@ authors = ["Parity Technologies "] [dependencies] common-types = { path = "../types" } -parity-bytes = "0.1" -ethcore-network = { path = "../../util/network" } -ethcore-network-devp2p = { path = "../../util/network-devp2p" } +env_logger = "0.5" +ethcore = { path = ".." } ethcore-io = { path = "../../util/io" } ethcore-light = { path = "../light" } -ethcore-transaction = { path = "../transaction" } -ethcore = { path = ".." } +ethcore-network = { path = "../../util/network" } +ethcore-network-devp2p = { path = "../../util/network-devp2p" } ethereum-types = "0.4" -hashdb = "0.3.0" +ethstore = { path = "../../accounts/ethstore" } fastmap = { path = "../../util/fastmap" } -rlp = { version = "0.3.0", features = ["ethereum"] } +hashdb = "0.3.0" +heapsize = "0.4" keccak-hash = "0.1" keccak-hasher = { path = "../../util/keccak-hasher" } -triehash-ethereum = {version = "0.2", path = "../../util/triehash-ethereum" } kvdb = "0.1" -macros = { path = "../../util/macros" } log = "0.4" -env_logger = "0.5" -rand = "0.4" -heapsize = "0.4" +macros = { path = "../../util/macros" } +parity-bytes = "0.1" parking_lot = "0.7" +rand = "0.4" +rlp = { version = "0.3.0", features = ["ethereum"] } trace-time = "0.1" +triehash-ethereum = {version = "0.2", path = "../../util/triehash-ethereum" } [dev-dependencies] ethcore-io = { path = "../../util/io", features = ["mio"] } diff --git a/ethcore/sync/src/api.rs b/ethcore/sync/src/api.rs index 7d7a1afc7..108d8bf0f 100644 --- a/ethcore/sync/src/api.rs +++ b/ethcore/sync/src/api.rs @@ -28,10 +28,10 @@ use network::{NetworkProtocolHandler, NetworkContext, PeerId, ProtocolId, use types::pruning_info::PruningInfo; use ethereum_types::{H256, H512, U256}; use io::{TimerToken}; -use ethcore::ethstore::ethkey::Secret; +use ethstore::ethkey::Secret; use ethcore::client::{BlockChainClient, ChainNotify, NewBlocks, ChainMessageType}; use ethcore::snapshot::SnapshotService; -use ethcore::header::BlockNumber; +use types::BlockNumber; use sync_io::NetSyncIo; use chain::{ChainSyncApi, SyncStatus as EthSyncStatus}; use std::net::{SocketAddr, AddrParseError}; @@ -48,7 +48,7 @@ use light::net::{ }; use network::IpFilter; use private_tx::PrivateTxHandler; -use transaction::UnverifiedTransaction; +use types::transaction::UnverifiedTransaction; /// Parity sync protocol pub const WARP_SYNC_PROTOCOL_ID: ProtocolId = *b"par"; @@ -594,7 +594,7 @@ impl ChainNotify for EthSync { struct TxRelay(Arc); impl LightHandler for TxRelay { - fn on_transactions(&self, ctx: &EventContext, relay: &[::transaction::UnverifiedTransaction]) { + fn on_transactions(&self, ctx: &EventContext, relay: &[::types::transaction::UnverifiedTransaction]) { trace!(target: "pip", "Relaying {} transactions from peer {}", relay.len(), ctx.peer()); self.0.queue_transactions(relay.iter().map(|tx| ::rlp::encode(tx)).collect(), ctx.peer()) } diff --git a/ethcore/sync/src/block_sync.rs b/ethcore/sync/src/block_sync.rs index 149e31224..ed01643e2 100644 --- a/ethcore/sync/src/block_sync.rs +++ b/ethcore/sync/src/block_sync.rs @@ -23,7 +23,7 @@ use std::cmp; use heapsize::HeapSizeOf; use ethereum_types::H256; use rlp::{self, Rlp}; -use ethcore::header::BlockNumber; +use types::BlockNumber; use ethcore::client::{BlockStatus, BlockId}; use ethcore::error::{ImportErrorKind, QueueErrorKind, BlockError, Error as EthcoreError, ErrorKind as EthcoreErrorKind}; use sync_io::SyncIo; @@ -621,7 +621,6 @@ fn all_expected(values: &[A], expected_values: &[B], is_expected: F) -> mod tests { use super::*; use ethcore::client::TestBlockChainClient; - use ethcore::header::Header as BlockHeader; use ethcore::spec::Spec; use ethkey::{Generator,Random}; use hash::keccak; @@ -629,8 +628,9 @@ mod tests { use rlp::{encode_list,RlpStream}; use tests::helpers::TestIo; use tests::snapshot::TestSnapshotService; - use transaction::{Transaction,SignedTransaction}; + use types::transaction::{Transaction,SignedTransaction}; use triehash_ethereum::ordered_trie_root; + use types::header::Header as BlockHeader; fn dummy_header(number: u64, parent_hash: H256) -> BlockHeader { let mut header = BlockHeader::new(); diff --git a/ethcore/sync/src/blocks.rs b/ethcore/sync/src/blocks.rs index 5f0f6a0c2..5e378eff1 100644 --- a/ethcore/sync/src/blocks.rs +++ b/ethcore/sync/src/blocks.rs @@ -22,9 +22,9 @@ use triehash_ethereum::ordered_trie_root; use bytes::Bytes; use rlp::{Rlp, RlpStream, DecoderError}; use network; -use ethcore::header::Header as BlockHeader; use ethcore::verification::queue::kind::blocks::Unverified; -use transaction::UnverifiedTransaction; +use types::transaction::UnverifiedTransaction; +use types::header::Header as BlockHeader; known_heap_size!(0, HeaderId); @@ -571,7 +571,7 @@ impl BlockCollection { mod test { use super::{BlockCollection, SyncHeader}; use ethcore::client::{TestBlockChainClient, EachBlockWith, BlockId, BlockChainClient}; - use ethcore::header::BlockNumber; + use types::BlockNumber; use ethcore::verification::queue::kind::blocks::Unverified; use rlp::*; diff --git a/ethcore/sync/src/chain/handler.rs b/ethcore/sync/src/chain/handler.rs index e1518d4f5..6a3a50bfd 100644 --- a/ethcore/sync/src/chain/handler.rs +++ b/ethcore/sync/src/chain/handler.rs @@ -17,9 +17,7 @@ use api::WARP_SYNC_PROTOCOL_ID; use block_sync::{BlockDownloaderImportError as DownloaderImportError, DownloadAction}; use bytes::Bytes; -use ethcore::client::{BlockId, BlockStatus}; use ethcore::error::{Error as EthcoreError, ErrorKind as EthcoreErrorKind, ImportErrorKind, BlockError}; -use ethcore::header::BlockNumber; use ethcore::snapshot::{ManifestData, RestorationStatus}; use ethcore::verification::queue::kind::blocks::Unverified; use ethereum_types::{H256, U256}; @@ -27,10 +25,12 @@ use hash::keccak; use network::PeerId; use rlp::Rlp; use snapshot::ChunkType; -use std::cmp; -use std::mem; use std::time::Instant; +use std::{mem, cmp}; use sync_io::SyncIo; +use types::BlockNumber; +use types::block_status::BlockStatus; +use types::ids::BlockId; use super::{ BlockSet, diff --git a/ethcore/sync/src/chain/mod.rs b/ethcore/sync/src/chain/mod.rs index a01b25528..ff976f668 100644 --- a/ethcore/sync/src/chain/mod.rs +++ b/ethcore/sync/src/chain/mod.rs @@ -104,7 +104,6 @@ use parking_lot::{Mutex, RwLock, RwLockWriteGuard}; use bytes::Bytes; use rlp::{RlpStream, DecoderError}; use network::{self, PeerId, PacketId}; -use ethcore::header::{BlockNumber}; use ethcore::client::{BlockChainClient, BlockStatus, BlockId, BlockChainInfo, BlockQueueInfo}; use ethcore::snapshot::{RestorationStatus}; use sync_io::SyncIo; @@ -115,7 +114,8 @@ use snapshot::{Snapshot}; use api::{EthProtocolInfo as PeerInfoDigest, WARP_SYNC_PROTOCOL_ID, PriorityTask}; use private_tx::PrivateTxHandler; use transactions_stats::{TransactionsStats, Stats as TransactionStats}; -use transaction::UnverifiedTransaction; +use types::transaction::UnverifiedTransaction; +use types::BlockNumber; use self::handler::SyncHandler; use self::propagator::SyncPropagator; @@ -1339,9 +1339,9 @@ pub mod tests { use super::*; use ::SyncConfig; use super::{PeerInfo, PeerAsking}; - use ethcore::header::*; use ethcore::client::{BlockChainClient, EachBlockWith, TestBlockChainClient, ChainInfo, BlockInfo}; use ethcore::miner::{MinerService, PendingOrdering}; + use types::header::Header; use private_tx::NoopPrivateTxHandler; pub fn get_dummy_block(order: u32, parent_hash: H256) -> Bytes { diff --git a/ethcore/sync/src/chain/propagator.rs b/ethcore/sync/src/chain/propagator.rs index 899184111..de57ede09 100644 --- a/ethcore/sync/src/chain/propagator.rs +++ b/ethcore/sync/src/chain/propagator.rs @@ -14,18 +14,19 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +use std::cmp; +use std::collections::HashSet; + use bytes::Bytes; use ethereum_types::H256; -use ethcore::client::BlockChainInfo; -use ethcore::header::BlockNumber; use fastmap::H256FastSet; use network::{PeerId, PacketId}; use rand::Rng; use rlp::{Encodable, RlpStream}; use sync_io::SyncIo; -use std::cmp; -use std::collections::HashSet; -use transaction::SignedTransaction; +use types::transaction::SignedTransaction; +use types::BlockNumber; +use types::blockchain_info::BlockChainInfo; use super::{ random, diff --git a/ethcore/sync/src/chain/requester.rs b/ethcore/sync/src/chain/requester.rs index a85874d29..c05c4330f 100644 --- a/ethcore/sync/src/chain/requester.rs +++ b/ethcore/sync/src/chain/requester.rs @@ -17,12 +17,12 @@ use api::WARP_SYNC_PROTOCOL_ID; use block_sync::BlockRequest; use bytes::Bytes; -use ethcore::header::BlockNumber; use ethereum_types::H256; use network::{PeerId, PacketId}; use rlp::RlpStream; use std::time::Instant; use sync_io::SyncIo; +use types::BlockNumber; use super::{ BlockSet, diff --git a/ethcore/sync/src/chain/supplier.rs b/ethcore/sync/src/chain/supplier.rs index eaee584ca..066a586e1 100644 --- a/ethcore/sync/src/chain/supplier.rs +++ b/ethcore/sync/src/chain/supplier.rs @@ -15,13 +15,13 @@ // along with Parity. If not, see . use bytes::Bytes; -use ethcore::client::BlockId; -use ethcore::header::BlockNumber; use ethereum_types::H256; use network::{self, PeerId}; use parking_lot::RwLock; use rlp::{Rlp, RlpStream}; use std::cmp; +use types::BlockNumber; +use types::ids::BlockId; use sync_io::SyncIo; diff --git a/ethcore/sync/src/lib.rs b/ethcore/sync/src/lib.rs index 294ba0cd7..2aa4c391b 100644 --- a/ethcore/sync/src/lib.rs +++ b/ethcore/sync/src/lib.rs @@ -22,19 +22,19 @@ //! extern crate common_types as types; +extern crate env_logger; +extern crate ethcore; +extern crate ethcore_io as io; extern crate ethcore_network as network; extern crate ethcore_network_devp2p as devp2p; -extern crate parity_bytes as bytes; -extern crate ethcore_io as io; -extern crate ethcore_transaction as transaction; -extern crate ethcore; extern crate ethereum_types; -extern crate env_logger; +extern crate ethstore; extern crate fastmap; -extern crate rand; -extern crate parking_lot; -extern crate rlp; extern crate keccak_hash as hash; +extern crate parity_bytes as bytes; +extern crate parking_lot; +extern crate rand; +extern crate rlp; extern crate triehash_ethereum; extern crate ethcore_light as light; diff --git a/ethcore/sync/src/light_sync/mod.rs b/ethcore/sync/src/light_sync/mod.rs index cda250f12..478e6a09d 100644 --- a/ethcore/sync/src/light_sync/mod.rs +++ b/ethcore/sync/src/light_sync/mod.rs @@ -38,7 +38,7 @@ use std::ops::Deref; use std::sync::Arc; use std::time::{Instant, Duration}; -use ethcore::encoded; +use types::encoded; use light::client::{AsLightClient, LightChainClient}; use light::net::{ PeerStatus, Announcement, Handler, BasicContext, diff --git a/ethcore/sync/src/light_sync/response.rs b/ethcore/sync/src/light_sync/response.rs index c3175d6e9..1e312aa20 100644 --- a/ethcore/sync/src/light_sync/response.rs +++ b/ethcore/sync/src/light_sync/response.rs @@ -16,7 +16,7 @@ //! Helpers for decoding and verifying responses for headers. -use ethcore::{encoded, header::Header}; +use types::{encoded, header::Header}; use ethereum_types::H256; use light::request::{HashOrNumber, CompleteHeadersRequest as HeadersRequest}; use rlp::DecoderError; @@ -153,8 +153,8 @@ impl Constraint for Max { #[cfg(test)] mod tests { - use ethcore::encoded; - use ethcore::header::Header; + use types::encoded; + use types::header::Header; use light::request::CompleteHeadersRequest as HeadersRequest; use super::*; diff --git a/ethcore/sync/src/light_sync/sync_round.rs b/ethcore/sync/src/light_sync/sync_round.rs index 71c4cdb5b..cb939ad81 100644 --- a/ethcore/sync/src/light_sync/sync_round.rs +++ b/ethcore/sync/src/light_sync/sync_round.rs @@ -20,8 +20,8 @@ use std::cmp::Ordering; use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque}; use std::fmt; -use ethcore::encoded; -use ethcore::header::Header; +use types::encoded; +use types::header::Header; use light::net::ReqId; use light::request::CompleteHeadersRequest as HeadersRequest; diff --git a/ethcore/sync/src/sync_io.rs b/ethcore/sync/src/sync_io.rs index a5e9f7b2f..4516394aa 100644 --- a/ethcore/sync/src/sync_io.rs +++ b/ethcore/sync/src/sync_io.rs @@ -18,7 +18,7 @@ use std::collections::HashMap; use network::{NetworkContext, PeerId, PacketId, Error, SessionInfo, ProtocolId}; use bytes::Bytes; use ethcore::client::BlockChainClient; -use ethcore::header::BlockNumber; +use types::BlockNumber; use ethcore::snapshot::SnapshotService; use parking_lot::RwLock; diff --git a/ethcore/sync/src/tests/consensus.rs b/ethcore/sync/src/tests/consensus.rs index 4a6871d16..abfba559b 100644 --- a/ethcore/sync/src/tests/consensus.rs +++ b/ethcore/sync/src/tests/consensus.rs @@ -23,7 +23,7 @@ use ethcore::spec::Spec; use ethcore::miner::MinerService; use ethcore::account_provider::AccountProvider; use ethkey::{KeyPair, Secret}; -use transaction::{Action, PendingTransaction, Transaction}; +use types::transaction::{Action, PendingTransaction, Transaction}; use super::helpers::*; use SyncConfig; diff --git a/ethcore/sync/src/tests/helpers.rs b/ethcore/sync/src/tests/helpers.rs index cc4a8ba08..915a3a26a 100644 --- a/ethcore/sync/src/tests/helpers.rs +++ b/ethcore/sync/src/tests/helpers.rs @@ -23,7 +23,6 @@ use network::{self, PeerId, ProtocolId, PacketId, SessionInfo}; use tests::snapshot::*; use ethcore::client::{TestBlockChainClient, BlockChainClient, Client as EthcoreClient, ClientConfig, ChainNotify, NewBlocks, ChainMessageType, ClientIoMessage}; -use ethcore::header::BlockNumber; use ethcore::snapshot::SnapshotService; use ethcore::spec::Spec; use ethcore::account_provider::AccountProvider; @@ -35,6 +34,7 @@ use api::WARP_SYNC_PROTOCOL_ID; use chain::{ChainSync, ETH_PROTOCOL_VERSION_63, PAR_PROTOCOL_VERSION_3, PRIVATE_TRANSACTION_PACKET, SIGNED_PRIVATE_TRANSACTION_PACKET, SyncSupplier}; use SyncConfig; use private_tx::SimplePrivateTxHandler; +use types::BlockNumber; pub trait FlushingBlockChainClient: BlockChainClient { fn flush(&self) {} diff --git a/ethcore/sync/src/tests/private.rs b/ethcore/sync/src/tests/private.rs index 9b39aed76..0a390079b 100644 --- a/ethcore/sync/src/tests/private.rs +++ b/ethcore/sync/src/tests/private.rs @@ -21,7 +21,7 @@ use ethcore::client::{BlockChainClient, BlockId, ClientIoMessage}; use ethcore::spec::Spec; use ethcore::miner::MinerService; use ethcore::CreateContractAddress; -use transaction::{Transaction, Action}; +use types::transaction::{Transaction, Action}; use ethcore::executive::{contract_address}; use ethcore::test_helpers::{push_block_with_transactions}; use ethcore_private_tx::{Provider, ProviderConfig, NoopEncryptor, Importer, SignedPrivateTransaction}; diff --git a/ethcore/sync/src/tests/snapshot.rs b/ethcore/sync/src/tests/snapshot.rs index 2316745c1..bada7c8cd 100644 --- a/ethcore/sync/src/tests/snapshot.rs +++ b/ethcore/sync/src/tests/snapshot.rs @@ -21,8 +21,8 @@ use ethereum_types::H256; use parking_lot::Mutex; use bytes::Bytes; use ethcore::snapshot::{SnapshotService, ManifestData, RestorationStatus}; -use ethcore::header::BlockNumber; use ethcore::client::EachBlockWith; +use types::BlockNumber; use super::helpers::*; use {SyncConfig, WarpSync}; diff --git a/ethcore/sync/src/transactions_stats.rs b/ethcore/sync/src/transactions_stats.rs index 7d5e2ca4a..2f0aa858a 100644 --- a/ethcore/sync/src/transactions_stats.rs +++ b/ethcore/sync/src/transactions_stats.rs @@ -19,9 +19,9 @@ use std::hash::BuildHasher; use std::collections::{HashSet, HashMap}; use ethereum_types::{H256, H512}; use fastmap::H256FastMap; +use types::BlockNumber; type NodeId = H512; -type BlockNumber = u64; #[derive(Debug, PartialEq, Clone)] pub struct Stats { diff --git a/ethcore/transaction/Cargo.toml b/ethcore/transaction/Cargo.toml deleted file mode 100644 index 5e5caef68..000000000 --- a/ethcore/transaction/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "ethcore-transaction" -description = "Transaction type" -version = "0.1.0" -authors = ["Parity Technologies "] - -[dependencies] -ethjson = { path = "../../json" } -ethkey = { path = "../../accounts/ethkey" } -evm = { path = "../evm" } -heapsize = "0.4" -keccak-hash = "0.1" -rlp = { version = "0.3.0", features = ["ethereum"] } -unexpected = { path = "../../util/unexpected" } -ethereum-types = "0.4" - -[dev-dependencies] -rustc-hex= "1.0" - -[features] -json-tests = [] diff --git a/ethcore/types/Cargo.toml b/ethcore/types/Cargo.toml index 2bedb093d..855fd7172 100644 --- a/ethcore/types/Cargo.toml +++ b/ethcore/types/Cargo.toml @@ -5,13 +5,16 @@ version = "0.1.0" authors = ["Parity Technologies "] [dependencies] -rlp = { version = "0.3.0", features = ["ethereum"] } -rlp_derive = { path = "../../util/rlp-derive" } -parity-bytes = "0.1" ethereum-types = "0.4" ethjson = { path = "../../json" } -keccak-hash = "0.1" +ethkey = { path = "../../accounts/ethkey" } heapsize = "0.4" +keccak-hash = "0.1" +parity-bytes = "0.1" +parity-machine = { path = "../../machine" } +rlp = { version = "0.3.0", features = ["ethereum"] } +rlp_derive = { path = "../../util/rlp-derive" } +unexpected = { path = "../../util/unexpected" } [dev-dependencies] rustc-hex= "1.0" diff --git a/ethcore/types/src/block.rs b/ethcore/types/src/block.rs new file mode 100644 index 000000000..e3d89bbe0 --- /dev/null +++ b/ethcore/types/src/block.rs @@ -0,0 +1,77 @@ +// Copyright 2015-2018 Parity Technologies (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 . + +//! Base data structure of this module is `Block`. +//! +//! Blocks can be produced by a local node or they may be received from the network. +//! +//! To create a block locally, we start with an `OpenBlock`. This block is mutable +//! and can be appended to with transactions and uncles. +//! +//! When ready, `OpenBlock` can be closed and turned into a `ClosedBlock`. A `ClosedBlock` can +//! be reopend again by a miner under certain circumstances. On block close, state commit is +//! performed. +//! +//! `LockedBlock` is a version of a `ClosedBlock` that cannot be reopened. It can be sealed +//! using an engine. +//! +//! `ExecutedBlock` is an underlaying data structure used by all structs above to store block +//! related info. + +use bytes::Bytes; + +use header::Header; +use rlp::{Rlp, RlpStream, Decodable, DecoderError}; +use transaction::UnverifiedTransaction; + +/// A block, encoded as it is on the block chain. +#[derive(Default, Debug, Clone, PartialEq)] +pub struct Block { + /// The header of this block. + pub header: Header, + /// The transactions in this block. + pub transactions: Vec, + /// The uncles of this block. + pub uncles: Vec
, +} + +impl Block { + /// Get the RLP-encoding of the block with the seal. + pub fn rlp_bytes(&self) -> Bytes { + let mut block_rlp = RlpStream::new_list(3); + block_rlp.append(&self.header); + block_rlp.append_list(&self.transactions); + block_rlp.append_list(&self.uncles); + block_rlp.out() + } +} + +impl Decodable for Block { + fn decode(rlp: &Rlp) -> Result { + if rlp.as_raw().len() != rlp.payload_info()?.total() { + return Err(DecoderError::RlpIsTooBig); + } + if rlp.item_count()? != 3 { + return Err(DecoderError::RlpIncorrectListLen); + } + Ok(Block { + header: rlp.val_at(0)?, + transactions: rlp.list_at(1)?, + uncles: rlp.list_at(2)?, + }) + } +} + diff --git a/ethcore/types/src/block_status.rs b/ethcore/types/src/block_status.rs index 460fdc297..c1f21cc22 100644 --- a/ethcore/types/src/block_status.rs +++ b/ethcore/types/src/block_status.rs @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +//! General block status + /// General block status #[derive(Debug, Eq, PartialEq)] pub enum BlockStatus { diff --git a/ethcore/src/encoded.rs b/ethcore/types/src/encoded.rs similarity index 99% rename from ethcore/src/encoded.rs rename to ethcore/types/src/encoded.rs index 9573bb5d1..20a7301aa 100644 --- a/ethcore/src/encoded.rs +++ b/ethcore/types/src/encoded.rs @@ -26,11 +26,12 @@ use block::Block as FullBlock; use ethereum_types::{H256, Bloom, U256, Address}; use hash::keccak; -use header::{BlockNumber, Header as FullHeader}; +use header::{Header as FullHeader}; use heapsize::HeapSizeOf; use rlp::{self, Rlp, RlpStream}; use transaction::UnverifiedTransaction; use views::{self, BlockView, HeaderView, BodyView}; +use BlockNumber; /// Owning header view. #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/ethcore/src/engines/epoch.rs b/ethcore/types/src/engines/epoch.rs similarity index 100% rename from ethcore/src/engines/epoch.rs rename to ethcore/types/src/engines/epoch.rs diff --git a/ethcore/types/src/engines/mod.rs b/ethcore/types/src/engines/mod.rs new file mode 100644 index 000000000..0ff1503a6 --- /dev/null +++ b/ethcore/types/src/engines/mod.rs @@ -0,0 +1,29 @@ +// Copyright 2015-2018 Parity Technologies (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 . + +//! Engine-specific types. + +pub mod epoch; + +/// Fork choice. +#[derive(Debug, PartialEq, Eq)] +pub enum ForkChoice { + /// Choose the new block. + New, + /// Choose the current best block. + Old, +} + diff --git a/ethcore/src/header.rs b/ethcore/types/src/header.rs similarity index 98% rename from ethcore/src/header.rs rename to ethcore/types/src/header.rs index 100210b70..a75f9cd6c 100644 --- a/ethcore/src/header.rs +++ b/ethcore/types/src/header.rs @@ -22,8 +22,7 @@ use heapsize::HeapSizeOf; use ethereum_types::{H256, U256, Address, Bloom}; use bytes::Bytes; use rlp::{Rlp, RlpStream, Encodable, DecoderError, Decodable}; - -pub use types::BlockNumber; +use BlockNumber; /// Semantic boolean for when a seal/signature is included. #[derive(Debug, Clone, Copy)] @@ -192,13 +191,6 @@ impl Header { }).collect() } - /// Get a mutable reference to extra_data - #[cfg(test)] - pub fn extra_data_mut(&mut self) -> &mut Bytes { - self.hash = None; - &mut self.extra_data - } - /// Set the number field of the header. pub fn set_parent_hash(&mut self, a: H256) { change_field(&mut self.hash, &mut self.parent_hash, a); diff --git a/ethcore/types/src/lib.rs b/ethcore/types/src/lib.rs index f375fec13..b5b85c5dd 100644 --- a/ethcore/types/src/lib.rs +++ b/ethcore/types/src/lib.rs @@ -15,25 +15,54 @@ // along with Parity. If not, see . //! Types used in the public API +//! +//! This crate stores Parity Etherem specific types that are +//! COMMONLY used across different separate modules of the codebase. +//! It should only focus on data structures, not any logic that relates to them. +//! +//! The interaction between modules should be possible by +//! implementing a required trait that potentially uses some of the data +//! structures from that crate. +//! +//! NOTE If you can specify your data type in the same crate as your trait, please do that. +//! Don't treat this crate as a bag for any types that we use in Parity Ethereum. +//! This one is reserved for types that are shared heavily (like transactions), +//! historically this contains types extracted from `ethcore` crate, if possible +//! we should try to dissolve that crate in favour of more fine-grained crates, +//! by moving the types closer to where they are actually required. + +#![warn(missing_docs, unused_extern_crates)] extern crate ethereum_types; -extern crate parity_bytes as bytes; extern crate ethjson; +extern crate ethkey; +extern crate heapsize; +extern crate keccak_hash as hash; +extern crate parity_bytes as bytes; +extern crate parity_machine; extern crate rlp; +extern crate unexpected; + #[macro_use] extern crate rlp_derive; -extern crate keccak_hash as hash; -extern crate heapsize; #[cfg(test)] extern crate rustc_hex; +#[macro_use] +pub mod views; + pub mod account_diff; +pub mod ancestry_action; pub mod basic_account; +pub mod block; pub mod block_status; pub mod blockchain_info; pub mod call_analytics; +pub mod encoded; +pub mod engines; pub mod filter; +pub mod header; pub mod ids; pub mod log_entry; pub mod pruning_info; @@ -43,9 +72,9 @@ pub mod security_level; pub mod snapshot_manifest; pub mod state_diff; pub mod trace_filter; +pub mod transaction; pub mod tree_route; pub mod verification_queue_info; -pub mod ancestry_action; /// Type for block number. pub type BlockNumber = u64; diff --git a/ethcore/transaction/src/error.rs b/ethcore/types/src/transaction/error.rs similarity index 100% rename from ethcore/transaction/src/error.rs rename to ethcore/types/src/transaction/error.rs diff --git a/ethcore/transaction/src/lib.rs b/ethcore/types/src/transaction/mod.rs similarity index 73% rename from ethcore/transaction/src/lib.rs rename to ethcore/types/src/transaction/mod.rs index 829613cf9..f3e3f0a4e 100644 --- a/ethcore/transaction/src/lib.rs +++ b/ethcore/types/src/transaction/mod.rs @@ -16,20 +16,8 @@ //! Ethereum Transactions -extern crate ethereum_types; -extern crate ethjson; -extern crate ethkey; -extern crate evm; -extern crate heapsize; -extern crate keccak_hash as hash; -extern crate rlp; -extern crate unexpected; - -#[cfg(test)] -extern crate rustc_hex; - mod error; mod transaction; -pub use error::Error; -pub use transaction::*; +pub use self::error::Error; +pub use self::transaction::*; diff --git a/ethcore/transaction/src/transaction.rs b/ethcore/types/src/transaction/transaction.rs similarity index 97% rename from ethcore/transaction/src/transaction.rs rename to ethcore/types/src/transaction/transaction.rs index ee37f6852..dcb249e4a 100644 --- a/ethcore/transaction/src/transaction.rs +++ b/ethcore/types/src/transaction/transaction.rs @@ -17,15 +17,16 @@ //! Transaction data structure. use std::ops::Deref; + use ethereum_types::{H256, H160, Address, U256}; -use error; use ethjson; use ethkey::{self, Signature, Secret, Public, recover, public_to_address}; -use evm::Schedule; use hash::keccak; use heapsize::HeapSizeOf; use rlp::{self, RlpStream, Rlp, DecoderError, Encodable}; +use transaction::error; + type Bytes = Vec; type BlockNumber = u64; @@ -251,19 +252,6 @@ impl Transaction { public: None, } } - - /// Get the transaction cost in gas for the given params. - pub fn gas_required_for(is_create: bool, data: &[u8], schedule: &Schedule) -> u64 { - data.iter().fold( - (if is_create {schedule.tx_create_gas} else {schedule.tx_gas}) as u64, - |g, b| g + (match *b { 0 => schedule.tx_data_zero_gas, _ => schedule.tx_data_non_zero_gas }) as u64 - ) - } - - /// Get the transaction cost in gas for this transaction. - pub fn gas_required(&self, schedule: &Schedule) -> u64 { - Self::gas_required_for(match self.action{Action::Create=>true, Action::Call(_)=>false}, &self.data, schedule) - } } /// Signed transaction information without verified signature. @@ -355,6 +343,7 @@ impl UnverifiedTransaction { &self.unsigned } + /// Returns standardized `v` value (0, 1 or 4 (invalid)) pub fn standard_v(&self) -> u8 { signature::check_replay_protection(self.v) } /// The `v` value that appears in the RLP. diff --git a/ethcore/src/views/block.rs b/ethcore/types/src/views/block.rs similarity index 98% rename from ethcore/src/views/block.rs rename to ethcore/types/src/views/block.rs index 2a7c2ebd5..0d279ea62 100644 --- a/ethcore/src/views/block.rs +++ b/ethcore/types/src/views/block.rs @@ -37,9 +37,9 @@ impl<'a> BlockView<'a> { /// /// ``` /// #[macro_use] - /// extern crate ethcore; + /// extern crate common_types as types; /// - /// use ethcore::views::{BlockView}; + /// use types::views::{BlockView}; /// /// fn main() { /// let bytes : &[u8] = &[]; diff --git a/ethcore/src/views/body.rs b/ethcore/types/src/views/body.rs similarity index 92% rename from ethcore/src/views/body.rs rename to ethcore/types/src/views/body.rs index f1a30949b..ad4346d14 100644 --- a/ethcore/src/views/body.rs +++ b/ethcore/types/src/views/body.rs @@ -19,10 +19,11 @@ use bytes::Bytes; use ethereum_types::H256; use hash::keccak; -use header::{Header, BlockNumber}; +use header::Header; use transaction::{LocalizedTransaction, UnverifiedTransaction}; use views::{TransactionView, HeaderView}; use super::ViewRlp; +use BlockNumber; /// View onto block rlp. pub struct BodyView<'a> { @@ -37,9 +38,9 @@ impl<'a> BodyView<'a> { /// /// ``` /// #[macro_use] - /// extern crate ethcore; + /// extern crate common_types as types; /// - /// use ethcore::views::{BodyView}; + /// use types::views::{BodyView}; /// /// fn main() { /// let bytes : &[u8] = &[]; @@ -149,15 +150,25 @@ impl<'a> BodyView<'a> { #[cfg(test)] mod tests { + use bytes::Bytes; + use rlp::RlpStream; use rustc_hex::FromHex; use super::BodyView; - use blockchain::BlockChain; + use views::BlockView; + + fn block_to_body(block: &[u8]) -> Bytes { + let mut body = RlpStream::new_list(2); + let block_view = view!(BlockView, block); + body.append_raw(block_view.transactions_rlp().as_raw(), 1); + body.append_raw(block_view.uncles_rlp().as_raw(), 1); + body.out() + } #[test] fn test_block_view() { // that's rlp of block created with ethash engine. let rlp = "f90261f901f9a0d405da4e66f1445d455195229624e133f5baafe72b5cf7b3c36c12c8146e98b7a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a05fb2b4bfdef7b314451cb138a534d225c922fc0e5fbe25e451142732c3e25c25a088d2ec6b9860aae1a2c3b299f72b6a5d70d7f7ba4722c78f2c49ba96273c2158a007c6fdfa8eea7e86b81f5b0fc0f78f90cc19f4aa60d323151e0cac660199e9a1b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302008003832fefba82524d84568e932a80a0a0349d8c3df71f1a48a9df7d03fd5f14aeee7d91332c009ecaff0a71ead405bd88ab4e252a7e8c2a23f862f86002018304cb2f94ec0e71ad0a90ffe1909d27dac207f7680abba42d01801ba03a347e72953c860f32b1eb2c78a680d8734b2ea08085d949d729479796f218d5a047ea6239d9e31ccac8af3366f5ca37184d26e7646e3191a3aeb81c4cf74de500c0".from_hex().unwrap(); - let body = BlockChain::block_to_body(&rlp); + let body = block_to_body(&rlp); let view = view!(BodyView, &body); assert_eq!(view.transactions_count(), 1); assert_eq!(view.uncles_count(), 0); diff --git a/ethcore/src/views/header.rs b/ethcore/types/src/views/header.rs similarity index 98% rename from ethcore/src/views/header.rs rename to ethcore/types/src/views/header.rs index 4b7b1225d..761f09128 100644 --- a/ethcore/src/views/header.rs +++ b/ethcore/types/src/views/header.rs @@ -19,9 +19,9 @@ use bytes::Bytes; use ethereum_types::{H256, Bloom, U256, Address}; use hash::keccak; -use header::BlockNumber; use rlp::{self}; use super::ViewRlp; +use BlockNumber; /// View onto block header rlp. pub struct HeaderView<'a> { @@ -36,10 +36,10 @@ impl<'a> HeaderView<'a> { /// /// ``` /// #[macro_use] - /// extern crate ethcore; - /// - /// use ethcore::views::{HeaderView}; - /// + /// extern crate common_types as types; + /// + /// use types::views::{HeaderView}; + /// /// fn main() { /// let bytes : &[u8] = &[]; /// let tx_view = view!(HeaderView, bytes); diff --git a/ethcore/src/views/mod.rs b/ethcore/types/src/views/mod.rs similarity index 100% rename from ethcore/src/views/mod.rs rename to ethcore/types/src/views/mod.rs diff --git a/ethcore/src/views/transaction.rs b/ethcore/types/src/views/transaction.rs similarity index 96% rename from ethcore/src/views/transaction.rs rename to ethcore/types/src/views/transaction.rs index 911fde944..1f4782cd2 100644 --- a/ethcore/src/views/transaction.rs +++ b/ethcore/types/src/views/transaction.rs @@ -18,7 +18,6 @@ use bytes::Bytes; use ethereum_types::{H256, U256}; use hash::keccak; -// use rlp::{Rlp, Decodable}; use super::ViewRlp; /// View onto transaction rlp. @@ -34,10 +33,10 @@ impl<'a> TransactionView<'a> { /// /// ``` /// #[macro_use] - /// extern crate ethcore; - /// - /// use ethcore::views::{TransactionView}; - /// + /// extern crate common_types as types; + /// + /// use types::views::{TransactionView}; + /// /// fn main() { /// let bytes : &[u8] = &[]; /// let tx_view = view!(TransactionView, bytes); diff --git a/ethcore/src/views/view_rlp.rs b/ethcore/types/src/views/view_rlp.rs similarity index 100% rename from ethcore/src/views/view_rlp.rs rename to ethcore/types/src/views/view_rlp.rs diff --git a/ethcore/vm/Cargo.toml b/ethcore/vm/Cargo.toml index 20bbea09a..bd5fb238f 100644 --- a/ethcore/vm/Cargo.toml +++ b/ethcore/vm/Cargo.toml @@ -10,7 +10,6 @@ ethereum-types = "0.4" patricia-trie = "0.3.0" patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" } log = "0.4" -common-types = { path = "../types" } ethjson = { path = "../../json" } rlp = { version = "0.3.0", features = ["ethereum"] } keccak-hash = "0.1" diff --git a/ethcore/vm/src/env_info.rs b/ethcore/vm/src/env_info.rs index bb1c9ecd9..77e67c0f1 100644 --- a/ethcore/vm/src/env_info.rs +++ b/ethcore/vm/src/env_info.rs @@ -20,9 +20,10 @@ use std::cmp; use std::sync::Arc; use hash::keccak; use ethereum_types::{U256, H256, Address}; -use types::BlockNumber; use ethjson; +type BlockNumber = u64; + /// Simple vector of hashes, should be at most 256 items large, can be smaller if being used /// for a block whose number is less than 257. pub type LastHashes = Vec; diff --git a/ethcore/vm/src/lib.rs b/ethcore/vm/src/lib.rs index b48eb1d84..49672d345 100644 --- a/ethcore/vm/src/lib.rs +++ b/ethcore/vm/src/lib.rs @@ -18,7 +18,6 @@ extern crate ethereum_types; extern crate parity_bytes as bytes; -extern crate common_types as types; extern crate ethjson; extern crate rlp; extern crate keccak_hash as hash; diff --git a/evmbin/Cargo.toml b/evmbin/Cargo.toml index e75e2492c..95b532366 100644 --- a/evmbin/Cargo.toml +++ b/evmbin/Cargo.toml @@ -9,15 +9,15 @@ name = "parity-evm" path = "./src/main.rs" [dependencies] +common-types = { path = "../ethcore/types" } docopt = "1.0" env_logger = "0.5" ethcore = { path = "../ethcore", features = ["test-helpers", "json-tests", "to-pod-full"] } -ethjson = { path = "../json" } -parity-bytes = "0.1" -ethcore-transaction = { path = "../ethcore/transaction" } ethereum-types = "0.4" +ethjson = { path = "../json" } evm = { path = "../ethcore/evm" } panic_hook = { path = "../util/panic-hook" } +parity-bytes = "0.1" rustc-hex = "1.0" serde = "1.0" serde_derive = "1.0" diff --git a/evmbin/src/info.rs b/evmbin/src/info.rs index 67df1d284..92726ecd5 100644 --- a/evmbin/src/info.rs +++ b/evmbin/src/info.rs @@ -21,7 +21,7 @@ use ethereum_types::{H256, U256}; use ethcore::client::{self, EvmTestClient, EvmTestError, TransactResult}; use ethcore::{state, state_db, trace, spec, pod_state, TrieSpec}; use ethjson; -use transaction; +use types::transaction; use vm::ActionParams; /// VM execution informant diff --git a/evmbin/src/main.rs b/evmbin/src/main.rs index 41bfbe1bd..f7448352f 100644 --- a/evmbin/src/main.rs +++ b/evmbin/src/main.rs @@ -18,6 +18,7 @@ #![warn(missing_docs)] +extern crate common_types as types; extern crate ethcore; extern crate ethjson; extern crate rustc_hex; @@ -27,7 +28,6 @@ extern crate serde_derive; #[macro_use] extern crate serde_json; extern crate docopt; -extern crate ethcore_transaction as transaction; extern crate parity_bytes as bytes; extern crate ethereum_types; extern crate vm; diff --git a/miner/Cargo.toml b/miner/Cargo.toml index b1372e87b..d37ed692c 100644 --- a/miner/Cargo.toml +++ b/miner/Cargo.toml @@ -15,15 +15,15 @@ url = { version = "1", optional = true } # Miner ansi_term = "0.10" +common-types = { path = "../ethcore/types" } error-chain = "0.12" -ethcore-transaction = { path = "../ethcore/transaction" } ethereum-types = "0.4" futures = "0.1" -parity-runtime = { path = "../util/runtime" } heapsize = "0.4" keccak-hash = "0.1" linked-hash-map = "0.5" log = "0.4" +parity-runtime = { path = "../util/runtime" } parking_lot = "0.7" price-info = { path = "./price-info", optional = true } rlp = { version = "0.3.0", features = ["ethereum"] } diff --git a/miner/local-store/Cargo.toml b/miner/local-store/Cargo.toml index 0198899dc..d16c64407 100644 --- a/miner/local-store/Cargo.toml +++ b/miner/local-store/Cargo.toml @@ -5,9 +5,8 @@ version = "0.1.0" authors = ["Parity Technologies "] [dependencies] -ethcore = { path = "../../ethcore" } +common-types = { path = "../../ethcore/types" } ethcore-io = { path = "../../util/io" } -ethcore-transaction = { path = "../../ethcore/transaction" } kvdb = "0.1" log = "0.4" rlp = { version = "0.3.0", features = ["ethereum"] } @@ -16,6 +15,5 @@ serde_derive = "1.0" serde_json = "1.0" [dev-dependencies] -ethcore = { path = "../../ethcore", features = ["test-helpers"] } ethkey = { path = "../../accounts/ethkey" } kvdb-memorydb = "0.1" diff --git a/miner/local-store/src/lib.rs b/miner/local-store/src/lib.rs index aa75ada8f..f8eaec5a9 100644 --- a/miner/local-store/src/lib.rs +++ b/miner/local-store/src/lib.rs @@ -20,17 +20,15 @@ use std::sync::Arc; use std::fmt; use std::time::Duration; -use transaction::{ +use types::transaction::{ SignedTransaction, PendingTransaction, UnverifiedTransaction, Condition as TransactionCondition }; -use ethcore::client::ClientIoMessage; use io::IoHandler; use rlp::Rlp; use kvdb::KeyValueDB; -extern crate ethcore; -extern crate ethcore_transaction as transaction; +extern crate common_types as types; extern crate ethcore_io as io; extern crate rlp; extern crate serde_json; @@ -73,7 +71,7 @@ impl fmt::Display for Error { #[derive(Serialize, Deserialize)] enum Condition { - Number(::ethcore::header::BlockNumber), + Number(types::BlockNumber), Timestamp(u64), } @@ -204,14 +202,14 @@ impl LocalDataStore { } } -impl IoHandler for LocalDataStore { - fn initialize(&self, io: &::io::IoContext) { +impl IoHandler for LocalDataStore { + fn initialize(&self, io: &::io::IoContext) { if let Err(e) = io.register_timer(UPDATE_TIMER, UPDATE_TIMEOUT) { warn!(target: "local_store", "Error registering local store update timer: {}", e); } } - fn timeout(&self, _io: &::io::IoContext, timer: ::io::TimerToken) { + fn timeout(&self, _io: &::io::IoContext, timer: ::io::TimerToken) { if let UPDATE_TIMER = timer { if let Err(e) = self.update() { debug!(target: "local_store", "Error updating local store: {}", e); @@ -233,7 +231,7 @@ mod tests { use super::NodeInfo; use std::sync::Arc; - use transaction::{Transaction, Condition, PendingTransaction}; + use types::transaction::{Transaction, Condition, PendingTransaction}; use ethkey::{Brain, Generator}; // we want to test: round-trip of good transactions. diff --git a/miner/src/lib.rs b/miner/src/lib.rs index 2288d1db1..de7da33ef 100644 --- a/miner/src/lib.rs +++ b/miner/src/lib.rs @@ -20,13 +20,13 @@ //! Keeps track of transactions and mined block. extern crate ansi_term; -extern crate ethcore_transaction as transaction; +extern crate common_types as types; extern crate ethereum_types; extern crate futures; -extern crate parity_runtime; extern crate heapsize; extern crate keccak_hash as hash; extern crate linked_hash_map; +extern crate parity_runtime; extern crate parking_lot; #[cfg(feature = "price-info")] extern crate price_info; diff --git a/miner/src/pool/client.rs b/miner/src/pool/client.rs index bdf57312e..1b0452cf1 100644 --- a/miner/src/pool/client.rs +++ b/miner/src/pool/client.rs @@ -23,7 +23,7 @@ use std::fmt; use ethereum_types::{U256, H256, H160 as Address}; -use transaction; +use types::transaction; /// Account Details #[derive(Debug, Clone)] diff --git a/miner/src/pool/listener.rs b/miner/src/pool/listener.rs index f5e76e15d..7dcac1f80 100644 --- a/miner/src/pool/listener.rs +++ b/miner/src/pool/listener.rs @@ -120,7 +120,7 @@ impl txpool::Listener for Logger { mod tests { use super::*; use parking_lot::Mutex; - use transaction; + use types::transaction; use txpool::Listener; #[test] diff --git a/miner/src/pool/local_transactions.rs b/miner/src/pool/local_transactions.rs index a71d9244c..f616d1f3a 100644 --- a/miner/src/pool/local_transactions.rs +++ b/miner/src/pool/local_transactions.rs @@ -236,7 +236,7 @@ mod tests { use super::*; use ethereum_types::U256; use ethkey::{Random, Generator}; - use transaction; + use types::transaction; use txpool::Listener; use pool; diff --git a/miner/src/pool/mod.rs b/miner/src/pool/mod.rs index ccfbba7f8..07c056a80 100644 --- a/miner/src/pool/mod.rs +++ b/miner/src/pool/mod.rs @@ -18,7 +18,7 @@ use ethereum_types::{U256, H256, Address}; use heapsize::HeapSizeOf; -use transaction; +use types::transaction; use txpool; mod listener; diff --git a/miner/src/pool/queue.rs b/miner/src/pool/queue.rs index 612ec1af0..1540c8f46 100644 --- a/miner/src/pool/queue.rs +++ b/miner/src/pool/queue.rs @@ -23,8 +23,8 @@ use std::collections::{BTreeMap, BTreeSet, HashMap}; use ethereum_types::{H256, U256, Address}; use parking_lot::RwLock; -use transaction; use txpool::{self, Verifier}; +use types::transaction; use pool::{ self, scoring, verifier, client, ready, listener, diff --git a/miner/src/pool/ready.rs b/miner/src/pool/ready.rs index 26ea35dd4..3a4b9d287 100644 --- a/miner/src/pool/ready.rs +++ b/miner/src/pool/ready.rs @@ -42,8 +42,8 @@ use std::cmp; use std::collections::HashMap; use ethereum_types::{U256, H160 as Address}; -use transaction; use txpool::{self, VerifiedTransaction as PoolVerifiedTransaction}; +use types::transaction; use super::client::NonceClient; use super::VerifiedTransaction; diff --git a/miner/src/pool/tests/client.rs b/miner/src/pool/tests/client.rs index 08b43f12a..ec4d8e796 100644 --- a/miner/src/pool/tests/client.rs +++ b/miner/src/pool/tests/client.rs @@ -18,7 +18,7 @@ use std::sync::{atomic, Arc}; use ethereum_types::{U256, H256, Address}; use rlp::Rlp; -use transaction::{self, Transaction, SignedTransaction, UnverifiedTransaction}; +use types::transaction::{self, Transaction, SignedTransaction, UnverifiedTransaction}; use pool; use pool::client::AccountDetails; diff --git a/miner/src/pool/tests/mod.rs b/miner/src/pool/tests/mod.rs index 2fc68d0ac..c667dacc6 100644 --- a/miner/src/pool/tests/mod.rs +++ b/miner/src/pool/tests/mod.rs @@ -15,7 +15,7 @@ // along with Parity. If not, see . use ethereum_types::U256; -use transaction::{self, PendingTransaction}; +use types::transaction::{self, PendingTransaction}; use txpool; use pool::{verifier, TransactionQueue, PrioritizationStrategy, PendingSettings, PendingOrdering}; @@ -30,7 +30,7 @@ use self::client::TestClient; // to the global use allocator, the value is currently // set to reflect malloc usage. // 50 was enough when using jmalloc. -const TEST_QUEUE_MAX_MEM: usize = 80; +const TEST_QUEUE_MAX_MEM: usize = 100; fn new_queue() -> TransactionQueue { TransactionQueue::new( diff --git a/miner/src/pool/tests/tx.rs b/miner/src/pool/tests/tx.rs index 78cd85024..1b5ec8473 100644 --- a/miner/src/pool/tests/tx.rs +++ b/miner/src/pool/tests/tx.rs @@ -17,7 +17,7 @@ use ethereum_types::{U256, H256}; use ethkey::{Random, Generator}; use rustc_hex::FromHex; -use transaction::{self, Transaction, SignedTransaction, UnverifiedTransaction}; +use types::transaction::{self, Transaction, SignedTransaction, UnverifiedTransaction}; use pool::{verifier, VerifiedTransaction}; diff --git a/miner/src/pool/verifier.rs b/miner/src/pool/verifier.rs index eaa13b3da..b055bb2d2 100644 --- a/miner/src/pool/verifier.rs +++ b/miner/src/pool/verifier.rs @@ -28,8 +28,8 @@ use std::sync::atomic::{self, AtomicUsize}; use ethereum_types::{U256, H256}; use rlp::Encodable; -use transaction; use txpool; +use types::transaction; use super::client::{Client, TransactionType}; use super::VerifiedTransaction; diff --git a/parity/account.rs b/parity/account.rs index e09667379..92297cf7e 100644 --- a/parity/account.rs +++ b/parity/account.rs @@ -15,9 +15,9 @@ // along with Parity. If not, see . use std::path::PathBuf; -use ethcore::ethstore::{EthStore, SecretStore, import_account, import_accounts, read_geth_accounts}; -use ethcore::ethstore::accounts_dir::RootDiskDirectory; -use ethcore::ethstore::SecretVaultRef; +use ethstore::{EthStore, SecretStore, import_account, import_accounts, read_geth_accounts}; +use ethstore::accounts_dir::RootDiskDirectory; +use ethstore::SecretVaultRef; use ethcore::account_provider::{AccountProvider, AccountProviderSettings}; use helpers::{password_prompt, password_from_file}; use params::SpecType; @@ -130,7 +130,7 @@ fn import(i: ImportAccounts) -> Result { fn import_geth(i: ImportFromGethAccounts) -> Result { use std::io::ErrorKind; - use ethcore::ethstore::Error; + use ethstore::Error; let dir = Box::new(keys_dir(i.to, i.spec)?); let secret_store = Box::new(secret_store(dir, None)?); diff --git a/parity/blockchain.rs b/parity/blockchain.rs index d0146eb3e..55903f46d 100644 --- a/parity/blockchain.rs +++ b/parity/blockchain.rs @@ -196,7 +196,7 @@ fn execute_import_light(cmd: ImportBlockchain) -> Result<(), String> { let mut config = LightClientConfig { queue: Default::default(), - chain_column: ::ethcore::db::COL_LIGHT_CHAIN, + chain_column: ethcore_db::COL_LIGHT_CHAIN, verify_full: true, check_seal: cmd.check_seal, no_hardcoded_sync: true, @@ -244,7 +244,7 @@ fn execute_import_light(cmd: ImportBlockchain) -> Result<(), String> { let do_import = |bytes: Vec| { while client.queue_info().is_full() { sleep(Duration::from_secs(1)); } - let header: ::ethcore::header::Header = ::rlp::Rlp::new(&bytes).val_at(0) + let header: ::types::header::Header = ::rlp::Rlp::new(&bytes).val_at(0) .map_err(|e| format!("Bad block: {}", e))?; if client.best_block_header().number() >= header.number() { return Ok(()) } diff --git a/parity/configuration.rs b/parity/configuration.rs index 5644e4dac..9de5c7902 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -27,7 +27,7 @@ use parity_version::{version_data, version}; use bytes::Bytes; use ansi_term::Colour; use sync::{NetworkConfiguration, validate_node_url, self}; -use ethcore::ethstore::ethkey::{Secret, Public}; +use ethstore::ethkey::{Secret, Public}; use ethcore::client::{VMType}; use ethcore::miner::{stratum, MinerOptions}; use ethcore::snapshot::SnapshotConfiguration; diff --git a/parity/db/rocksdb/helpers.rs b/parity/db/rocksdb/helpers.rs index 1b7f05c1a..6a59a939c 100644 --- a/parity/db/rocksdb/helpers.rs +++ b/parity/db/rocksdb/helpers.rs @@ -15,7 +15,7 @@ // along with Parity. If not, see . use std::path::Path; -use ethcore::db::NUM_COLUMNS; +use ethcore_db::NUM_COLUMNS; use ethcore::client::{ClientConfig, DatabaseCompactionProfile}; use super::kvdb_rocksdb::{CompactionProfile, DatabaseConfig}; diff --git a/parity/db/rocksdb/migration.rs b/parity/db/rocksdb/migration.rs index c6489116b..1844f424e 100644 --- a/parity/db/rocksdb/migration.rs +++ b/parity/db/rocksdb/migration.rs @@ -21,7 +21,7 @@ use std::fmt::{Display, Formatter, Error as FmtError}; use super::migration_rocksdb::{Manager as MigrationManager, Config as MigrationConfig, ChangeColumns}; use super::kvdb_rocksdb::{CompactionProfile, DatabaseConfig}; use ethcore::client::DatabaseCompactionProfile; -use ethcore::{self, db}; +use ethcore; use super::helpers; use super::blooms::migrate_blooms; @@ -217,7 +217,7 @@ pub fn migrate(path: &Path, compaction_profile: &DatabaseCompactionProfile) -> R max_open_files: 64, memory_budget: None, compaction: compaction_profile, - columns: db::NUM_COLUMNS, + columns: ethcore_db::NUM_COLUMNS, }; migrate_blooms(&db_path, &db_config).map_err(Error::BloomsDB)?; diff --git a/parity/db/rocksdb/mod.rs b/parity/db/rocksdb/mod.rs index 91160f921..beac78e2b 100644 --- a/parity/db/rocksdb/mod.rs +++ b/parity/db/rocksdb/mod.rs @@ -16,15 +16,16 @@ extern crate kvdb_rocksdb; extern crate migration_rocksdb; +extern crate ethcore_blockchain; use std::{io, fs}; use std::sync::Arc; use std::path::Path; use blooms_db; -use ethcore::{BlockChainDBHandler, BlockChainDB}; -use ethcore::db::NUM_COLUMNS; +use ethcore_db::NUM_COLUMNS; use ethcore::client::{ClientConfig, DatabaseCompactionProfile}; use kvdb::KeyValueDB; +use self::ethcore_blockchain::{BlockChainDBHandler, BlockChainDB}; use self::kvdb_rocksdb::{Database, DatabaseConfig}; use cache::CacheConfig; diff --git a/parity/export_hardcoded_sync.rs b/parity/export_hardcoded_sync.rs index b3121f086..039ce9e66 100644 --- a/parity/export_hardcoded_sync.rs +++ b/parity/export_hardcoded_sync.rs @@ -77,7 +77,7 @@ pub fn execute(cmd: ExportHsyncCmd) -> Result { // start client and create transaction queue. let mut config = light_client::Config { queue: Default::default(), - chain_column: ::ethcore::db::COL_LIGHT_CHAIN, + chain_column: ::ethcore_db::COL_LIGHT_CHAIN, verify_full: true, check_seal: true, no_hardcoded_sync: true, diff --git a/parity/informant.rs b/parity/informant.rs index 5209a8551..067bc741d 100644 --- a/parity/informant.rs +++ b/parity/informant.rs @@ -27,7 +27,7 @@ use ethcore::client::{ BlockId, BlockChainClient, ChainInfo, BlockInfo, BlockChainInfo, BlockQueueInfo, ChainNotify, NewBlocks, ClientReport, Client, ClientIoMessage }; -use ethcore::header::BlockNumber; +use types::BlockNumber; use ethcore::snapshot::{RestorationStatus, SnapshotService as SS}; use ethcore::snapshot::service::Service as SnapshotService; use sync::{LightSyncProvider, LightSync, SyncProvider, ManageNetwork}; diff --git a/parity/lib.rs b/parity/lib.rs index 88330f1ac..960982e29 100644 --- a/parity/lib.rs +++ b/parity/lib.rs @@ -43,8 +43,10 @@ extern crate toml; extern crate blooms_db; extern crate cli_signer; +extern crate common_types as types; extern crate ethcore; extern crate parity_bytes as bytes; +extern crate ethcore_db; extern crate ethcore_io as io; extern crate ethcore_light as light; extern crate ethcore_logger; @@ -53,8 +55,8 @@ extern crate ethcore_network as network; extern crate ethcore_private_tx; extern crate ethcore_service; extern crate ethcore_sync as sync; -extern crate ethcore_transaction as transaction; extern crate ethereum_types; +extern crate ethstore; extern crate ethkey; extern crate kvdb; extern crate parity_hash_fetch as hash_fetch; diff --git a/parity/light_helpers/epoch_fetch.rs b/parity/light_helpers/epoch_fetch.rs index a7d8f4171..6b912bacd 100644 --- a/parity/light_helpers/epoch_fetch.rs +++ b/parity/light_helpers/epoch_fetch.rs @@ -16,12 +16,12 @@ use std::sync::{Arc, Weak}; -use ethcore::encoded; use ethcore::engines::{EthEngine, StateDependentProof}; -use ethcore::header::Header; use ethcore::machine::EthereumMachine; -use ethcore::receipt::Receipt; use sync::LightSync; +use types::encoded; +use types::header::Header; +use types::receipt::Receipt; use futures::{future, Future}; use futures::future::Either; diff --git a/parity/presale.rs b/parity/presale.rs index 16af2fb82..387983968 100644 --- a/parity/presale.rs +++ b/parity/presale.rs @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use ethcore::ethstore::{PresaleWallet, EthStore}; -use ethcore::ethstore::accounts_dir::RootDiskDirectory; +use ethstore::{PresaleWallet, EthStore}; +use ethstore::accounts_dir::RootDiskDirectory; use ethcore::account_provider::{AccountProvider, AccountProviderSettings}; use helpers::{password_prompt, password_from_file}; use params::SpecType; diff --git a/parity/run.rs b/parity/run.rs index 6dad5fd6d..4be9539a5 100644 --- a/parity/run.rs +++ b/parity/run.rs @@ -23,7 +23,7 @@ use ansi_term::Colour; use bytes::Bytes; use ethcore::account_provider::{AccountProvider, AccountProviderSettings}; use ethcore::client::{BlockId, CallContract, Client, Mode, DatabaseCompactionProfile, VMType, BlockChainClient, BlockInfo}; -use ethcore::ethstore::ethkey; +use ethstore::ethkey; use ethcore::miner::{stratum, Miner, MinerService, MinerOptions}; use ethcore::snapshot::{self, SnapshotConfiguration}; use ethcore::spec::{SpecParams, OptimizeFor}; @@ -150,7 +150,7 @@ struct FullNodeInfo { } impl ::local_store::NodeInfo for FullNodeInfo { - fn pending_transactions(&self) -> Vec<::transaction::PendingTransaction> { + fn pending_transactions(&self) -> Vec<::types::transaction::PendingTransaction> { let miner = match self.miner.as_ref() { Some(m) => m, None => return Vec::new(), @@ -210,7 +210,7 @@ fn execute_light_impl(cmd: RunCmd, logger: Arc) -> Result(cmd: RunCmd, logger: Arc, on_client_rq: } }; - let store = ::local_store::create(db.key_value().clone(), ::ethcore::db::COL_NODE_INFO, node_info); + let store = ::local_store::create(db.key_value().clone(), ::ethcore_db::COL_NODE_INFO, node_info); if cmd.no_persistent_txqueue { info!("Running without a persistent transaction queue."); @@ -972,8 +972,8 @@ fn print_running_environment(data_dir: &str, dirs: &Directories, db_dirs: &Datab } fn prepare_account_provider(spec: &SpecType, dirs: &Directories, data_dir: &str, cfg: AccountsConfig, passwords: &[Password]) -> Result { - use ethcore::ethstore::EthStore; - use ethcore::ethstore::accounts_dir::RootDiskDirectory; + use ethstore::EthStore; + use ethstore::accounts_dir::RootDiskDirectory; let path = dirs.keys_path(data_dir); upgrade_key_location(&dirs.legacy_keys_path(cfg.testnet), &path); diff --git a/parity/snapshot.rs b/parity/snapshot.rs index 5f30caad7..43cb69cc0 100644 --- a/parity/snapshot.rs +++ b/parity/snapshot.rs @@ -27,8 +27,8 @@ use ethcore::snapshot::io::{SnapshotReader, PackedReader, PackedWriter}; use ethcore::snapshot::service::Service as SnapshotService; use ethcore::client::{Mode, DatabaseCompactionProfile, VMType}; use ethcore::miner::Miner; -use ethcore::ids::BlockId; use ethcore_service::ClientService; +use types::ids::BlockId; use cache::CacheConfig; use params::{SpecType, Pruning, Switch, tracing_switch_to_bool, fatdb_switch_to_bool}; diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index 9babb4f77..59dc43ab2 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -34,6 +34,7 @@ jsonrpc-ipc-server = { git = "https://github.com/paritytech/jsonrpc.git", branch jsonrpc-macros = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-2.2" } jsonrpc-pubsub = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-2.2" } +common-types = { path = "../ethcore/types" } ethash = { path = "../ethash" } ethcore = { path = "../ethcore", features = ["test-helpers"] } fastmap = { path = "../util/fastmap" } @@ -45,7 +46,6 @@ ethcore-logger = { path = "../logger" } ethcore-miner = { path = "../miner" } ethcore-private-tx = { path = "../ethcore/private-tx" } ethcore-sync = { path = "../ethcore/sync" } -ethcore-transaction = { path = "../ethcore/transaction" } ethereum-types = "0.4" ethjson = { path = "../json" } diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index ca5ed28ba..bd063968e 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -41,6 +41,7 @@ extern crate jsonrpc_http_server as http; extern crate jsonrpc_ipc_server as ipc; extern crate jsonrpc_pubsub; +extern crate common_types as types; extern crate ethash; extern crate ethcore; extern crate fastmap; @@ -52,7 +53,6 @@ extern crate ethcore_logger; extern crate ethcore_miner as miner; extern crate ethcore_private_tx; extern crate ethcore_sync as sync; -extern crate ethcore_transaction as transaction; extern crate ethereum_types; extern crate ethkey; extern crate ethstore; diff --git a/rpc/src/v1/helpers/dispatch.rs b/rpc/src/v1/helpers/dispatch.rs index 67f3c9fd4..a66b08e94 100644 --- a/rpc/src/v1/helpers/dispatch.rs +++ b/rpc/src/v1/helpers/dispatch.rs @@ -32,13 +32,13 @@ use stats::Corpus; use crypto::DEFAULT_MAC; use ethcore::account_provider::AccountProvider; -use ethcore::basic_account::BasicAccount; use ethcore::client::BlockChainClient; -use ethcore::ids::BlockId; use ethcore::miner::{self, MinerService}; use ethkey::{Password, Signature}; use sync::LightSync; -use transaction::{Action, SignedTransaction, PendingTransaction, Transaction, Error as TransactionError}; +use types::transaction::{Action, SignedTransaction, PendingTransaction, Transaction, Error as TransactionError}; +use types::basic_account::BasicAccount; +use types::ids::BlockId; use jsonrpc_core::{BoxFuture, Result, Error}; use jsonrpc_core::futures::{future, Future, Poll, Async}; diff --git a/rpc/src/v1/helpers/errors.rs b/rpc/src/v1/helpers/errors.rs index d75887d8f..f83f66253 100644 --- a/rpc/src/v1/helpers/errors.rs +++ b/rpc/src/v1/helpers/errors.rs @@ -23,12 +23,12 @@ use ethcore::error::{Error as EthcoreError, ErrorKind, CallError}; use ethcore::client::BlockId; use jsonrpc_core::{futures, Result as RpcResult, Error, ErrorCode, Value}; use rlp::DecoderError; -use transaction::Error as TransactionError; +use types::transaction::Error as TransactionError; use ethcore_private_tx::Error as PrivateTransactionError; use vm::Error as VMError; use light::on_demand::error::{Error as OnDemandError, ErrorKind as OnDemandErrorKind}; use ethcore::client::BlockChainClient; -use ethcore::blockchain_info::BlockChainInfo; +use types::blockchain_info::BlockChainInfo; use v1::types::BlockNumber; mod codes { diff --git a/rpc/src/v1/helpers/fake_sign.rs b/rpc/src/v1/helpers/fake_sign.rs index e9ee9b161..866b292c1 100644 --- a/rpc/src/v1/helpers/fake_sign.rs +++ b/rpc/src/v1/helpers/fake_sign.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use transaction::{Transaction, SignedTransaction, Action}; +use types::transaction::{Transaction, SignedTransaction, Action}; use ethereum_types::U256; use jsonrpc_core::Error; diff --git a/rpc/src/v1/helpers/light_fetch.rs b/rpc/src/v1/helpers/light_fetch.rs index 0473ff4c8..2dc587f7a 100644 --- a/rpc/src/v1/helpers/light_fetch.rs +++ b/rpc/src/v1/helpers/light_fetch.rs @@ -19,11 +19,11 @@ use std::cmp; use std::sync::Arc; -use ethcore::basic_account::BasicAccount; -use ethcore::encoded; -use ethcore::filter::Filter as EthcoreFilter; -use ethcore::ids::BlockId; -use ethcore::receipt::Receipt; +use types::basic_account::BasicAccount; +use types::encoded; +use types::filter::Filter as EthcoreFilter; +use types::ids::BlockId; +use types::receipt::Receipt; use ethcore::executed::ExecutionError; use jsonrpc_core::{Result, Error}; @@ -47,7 +47,7 @@ use hash::H256; use parking_lot::Mutex; use fastmap::H256FastMap; use std::collections::BTreeMap; -use transaction::{Action, Transaction as EthTransaction, PendingTransaction, SignedTransaction, LocalizedTransaction}; +use types::transaction::{Action, Transaction as EthTransaction, PendingTransaction, SignedTransaction, LocalizedTransaction}; use v1::helpers::{CallRequest as CallRequestHelper, errors, dispatch}; use v1::types::{BlockNumber, CallRequest, Log, Transaction}; diff --git a/rpc/src/v1/helpers/poll_filter.rs b/rpc/src/v1/helpers/poll_filter.rs index 033c83270..497cd8955 100644 --- a/rpc/src/v1/helpers/poll_filter.rs +++ b/rpc/src/v1/helpers/poll_filter.rs @@ -22,8 +22,8 @@ use std::{ }; use ethereum_types::H256; use parking_lot::Mutex; -use ethcore::filter::Filter; use v1::types::Log; +use types::filter::Filter; pub type BlockNumber = u64; diff --git a/rpc/src/v1/impls/debug.rs b/rpc/src/v1/impls/debug.rs index 60d9dcdc8..d1647f4f8 100644 --- a/rpc/src/v1/impls/debug.rs +++ b/rpc/src/v1/impls/debug.rs @@ -19,7 +19,7 @@ use std::sync::Arc; use ethcore::client::BlockChainClient; -use transaction::LocalizedTransaction; +use types::transaction::LocalizedTransaction; use jsonrpc_core::Result; use v1::traits::Debug; diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index 8cf5104fd..d7692c416 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -27,15 +27,15 @@ use parking_lot::Mutex; use ethash::{self, SeedHashCompute}; use ethcore::account_provider::AccountProvider; use ethcore::client::{BlockChainClient, BlockId, TransactionId, UncleId, StateOrBlock, StateClient, StateInfo, Call, EngineInfo, ProvingBlockChainClient}; -use ethcore::filter::Filter as EthcoreFilter; -use ethcore::header::{BlockNumber as EthBlockNumber}; use ethcore::miner::{self, MinerService}; use ethcore::snapshot::SnapshotService; -use ethcore::encoded; -use sync::SyncProvider; -use miner::external::ExternalMinerService; -use transaction::{SignedTransaction, LocalizedTransaction}; use hash::keccak; +use miner::external::ExternalMinerService; +use sync::SyncProvider; +use types::transaction::{SignedTransaction, LocalizedTransaction}; +use types::BlockNumber as EthBlockNumber; +use types::encoded; +use types::filter::Filter as EthcoreFilter; use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_core::futures::future; @@ -466,7 +466,7 @@ pub fn pending_logs(miner: &M, best_block: EthBlockNumber, filter: &EthcoreFi } fn check_known(client: &C, number: BlockNumber) -> Result<()> where C: BlockChainClient { - use ethcore::block_status::BlockStatus; + use types::block_status::BlockStatus; let id = match number { BlockNumber::Pending => return Ok(()), @@ -625,7 +625,7 @@ impl Eth for EthClient< Box::new(future::done(res)) } - + fn storage_at(&self, address: RpcH160, pos: RpcU256, num: Trailing) -> BoxFuture { let address: Address = RpcH160::into(address); let position: U256 = RpcU256::into(pos); diff --git a/rpc/src/v1/impls/eth_filter.rs b/rpc/src/v1/impls/eth_filter.rs index 2245100f0..097460ece 100644 --- a/rpc/src/v1/impls/eth_filter.rs +++ b/rpc/src/v1/impls/eth_filter.rs @@ -19,11 +19,11 @@ use std::sync::Arc; use std::collections::{BTreeSet, VecDeque}; -use ethcore::miner::{self, MinerService}; -use ethcore::filter::Filter as EthcoreFilter; use ethcore::client::{BlockChainClient, BlockId}; +use ethcore::miner::{self, MinerService}; use ethereum_types::H256; use parking_lot::Mutex; +use types::filter::Filter as EthcoreFilter; use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_core::futures::{future, Future}; diff --git a/rpc/src/v1/impls/eth_pubsub.rs b/rpc/src/v1/impls/eth_pubsub.rs index 0e39f4e31..eaefeac1b 100644 --- a/rpc/src/v1/impls/eth_pubsub.rs +++ b/rpc/src/v1/impls/eth_pubsub.rs @@ -31,16 +31,16 @@ use v1::metadata::Metadata; use v1::traits::EthPubSub; use v1::types::{pubsub, RichHeader, Log}; -use ethcore::encoded; -use ethcore::filter::Filter as EthFilter; use ethcore::client::{BlockChainClient, ChainNotify, NewBlocks, ChainRouteType, BlockId}; -use sync::LightSync; -use light::cache::Cache; -use light::on_demand::OnDemand; -use light::client::{LightChainClient, LightChainNotify}; -use parity_runtime::Executor; use ethereum_types::H256; +use light::cache::Cache; +use light::client::{LightChainClient, LightChainNotify}; +use light::on_demand::OnDemand; +use parity_runtime::Executor; use parking_lot::{RwLock, Mutex}; +use sync::LightSync; +use types::encoded; +use types::filter::Filter as EthFilter; type Client = Sink; diff --git a/rpc/src/v1/impls/light/eth.rs b/rpc/src/v1/impls/light/eth.rs index dffb88abf..045a2f1d8 100644 --- a/rpc/src/v1/impls/light/eth.rs +++ b/rpc/src/v1/impls/light/eth.rs @@ -30,15 +30,15 @@ use light::{cht, TransactionQueue}; use light::on_demand::{request, OnDemand}; use ethcore::account_provider::AccountProvider; -use ethcore::encoded; -use ethcore::filter::Filter as EthcoreFilter; -use ethcore::ids::BlockId; -use sync::LightSync; -use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP}; use ethereum_types::U256; +use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP}; use parking_lot::{RwLock, Mutex}; use rlp::Rlp; -use transaction::SignedTransaction; +use sync::LightSync; +use types::transaction::SignedTransaction; +use types::encoded; +use types::filter::Filter as EthcoreFilter; +use types::ids::BlockId; use v1::impls::eth_filter::Filterable; use v1::helpers::{errors, limit_logs}; diff --git a/rpc/src/v1/impls/light/parity.rs b/rpc/src/v1/impls/light/parity.rs index 397167ad3..74eddeb66 100644 --- a/rpc/src/v1/impls/light/parity.rs +++ b/rpc/src/v1/impls/light/parity.rs @@ -366,7 +366,7 @@ impl Parity for ParityClient { } fn block_header(&self, number: Trailing) -> BoxFuture { - use ethcore::encoded; + use types::encoded; let engine = self.light_dispatch.client.engine().clone(); let from_encoded = move |encoded: encoded::Header| { diff --git a/rpc/src/v1/impls/parity.rs b/rpc/src/v1/impls/parity.rs index c2d57a345..286e5d2ea 100644 --- a/rpc/src/v1/impls/parity.rs +++ b/rpc/src/v1/impls/parity.rs @@ -23,20 +23,20 @@ use ethereum_types::Address; use version::version_data; use crypto::DEFAULT_MAC; -use ethkey::{crypto::ecies, Brain, Generator}; -use ethstore::random_phrase; -use sync::{SyncProvider, ManageNetwork}; use ethcore::account_provider::AccountProvider; use ethcore::client::{BlockChainClient, StateClient, Call}; -use ethcore::ids::BlockId; use ethcore::miner::{self, MinerService}; use ethcore::snapshot::{SnapshotService, RestorationStatus}; use ethcore::state::StateInfo; use ethcore_logger::RotatingLogger; -use updater::{Service as UpdateService}; -use jsonrpc_core::{BoxFuture, Result}; +use ethkey::{crypto::ecies, Brain, Generator}; +use ethstore::random_phrase; use jsonrpc_core::futures::future; +use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_macros::Trailing; +use sync::{SyncProvider, ManageNetwork}; +use types::ids::BlockId; +use updater::{Service as UpdateService}; use v1::helpers::block_import::is_major_importing; use v1::helpers::{self, errors, fake_sign, ipfs, SigningQueue, SignerService, NetworkSettings, verify_signature}; diff --git a/rpc/src/v1/impls/personal.rs b/rpc/src/v1/impls/personal.rs index 97f0eaf62..c9c3e78e5 100644 --- a/rpc/src/v1/impls/personal.rs +++ b/rpc/src/v1/impls/personal.rs @@ -20,7 +20,7 @@ use std::time::Duration; use bytes::{Bytes, ToPretty}; use ethcore::account_provider::AccountProvider; -use transaction::PendingTransaction; +use types::transaction::PendingTransaction; use ethereum_types::{H520, U128, Address}; use ethkey::{public_to_address, recover, Signature}; diff --git a/rpc/src/v1/impls/private.rs b/rpc/src/v1/impls/private.rs index f4894ef57..1d5b69a8a 100644 --- a/rpc/src/v1/impls/private.rs +++ b/rpc/src/v1/impls/private.rs @@ -22,7 +22,7 @@ use rlp::Rlp; use ethcore_private_tx::Provider as PrivateTransactionManager; use ethereum_types::Address; -use transaction::SignedTransaction; +use types::transaction::SignedTransaction; use jsonrpc_core::{Error}; use v1::types::{Bytes, PrivateTransactionReceipt, H160, H256, TransactionRequest, U256, diff --git a/rpc/src/v1/impls/signer.rs b/rpc/src/v1/impls/signer.rs index 15cd21d20..5e909c38c 100644 --- a/rpc/src/v1/impls/signer.rs +++ b/rpc/src/v1/impls/signer.rs @@ -23,7 +23,7 @@ use ethkey; use parity_runtime::Executor; use parking_lot::Mutex; use rlp::Rlp; -use transaction::{SignedTransaction, PendingTransaction}; +use types::transaction::{SignedTransaction, PendingTransaction}; use jsonrpc_core::{Result, BoxFuture, Error}; use jsonrpc_core::futures::{future, Future, IntoFuture}; diff --git a/rpc/src/v1/impls/traces.rs b/rpc/src/v1/impls/traces.rs index 3abddd2f9..825f8c17d 100644 --- a/rpc/src/v1/impls/traces.rs +++ b/rpc/src/v1/impls/traces.rs @@ -20,7 +20,7 @@ use std::sync::Arc; use ethcore::client::{BlockChainClient, CallAnalytics, TransactionId, TraceId, StateClient, StateInfo, Call, BlockId}; use rlp::Rlp; -use transaction::SignedTransaction; +use types::transaction::SignedTransaction; use jsonrpc_core::Result; use jsonrpc_macros::Trailing; diff --git a/rpc/src/v1/tests/eth.rs b/rpc/src/v1/tests/eth.rs index 6892f9912..410428228 100644 --- a/rpc/src/v1/tests/eth.rs +++ b/rpc/src/v1/tests/eth.rs @@ -18,22 +18,22 @@ use std::env; use std::sync::Arc; -use ethereum_types::{H256, Address}; use ethcore::account_provider::AccountProvider; use ethcore::client::{BlockChainClient, Client, ClientConfig, ChainInfo, ImportBlock}; use ethcore::ethereum; -use ethcore::ids::BlockId; use ethcore::miner::Miner; use ethcore::spec::{Genesis, Spec}; use ethcore::test_helpers; -use ethcore::verification::queue::kind::blocks::Unverified; use ethcore::verification::VerifierType; +use ethcore::verification::queue::kind::blocks::Unverified; +use ethereum_types::{H256, Address}; use ethjson::blockchain::BlockChain; use ethjson::spec::ForkSpec; use io::IoChannel; use miner::external::ExternalMiner; -use parking_lot::Mutex; use parity_runtime::Runtime; +use parking_lot::Mutex; +use types::ids::BlockId; use jsonrpc_core::IoHandler; use v1::helpers::dispatch::FullDispatcher; diff --git a/rpc/src/v1/tests/helpers/miner_service.rs b/rpc/src/v1/tests/helpers/miner_service.rs index c867e6854..95d7c4467 100644 --- a/rpc/src/v1/tests/helpers/miner_service.rs +++ b/rpc/src/v1/tests/helpers/miner_service.rs @@ -21,21 +21,23 @@ use std::collections::{BTreeMap, BTreeSet, HashMap}; use bytes::Bytes; use ethcore::account_provider::SignError as AccountError; -use ethcore::block::{Block, SealedBlock, IsBlock}; +use ethcore::block::{SealedBlock, IsBlock}; use ethcore::client::{Nonce, PrepareOpenBlock, StateClient, EngineInfo}; use ethcore::engines::EthEngine; use ethcore::error::Error; -use ethcore::header::{BlockNumber, Header}; -use ethcore::ids::BlockId; use ethcore::miner::{self, MinerService, AuthoringParams}; -use ethcore::receipt::RichReceipt; use ethereum_types::{H256, U256, Address}; +use ethkey::Password; use miner::pool::local_transactions::Status as LocalTransactionStatus; use miner::pool::{verifier, VerifiedTransaction, QueueStatus}; use parking_lot::{RwLock, Mutex}; -use transaction::{self, UnverifiedTransaction, SignedTransaction, PendingTransaction}; +use types::transaction::{self, UnverifiedTransaction, SignedTransaction, PendingTransaction}; use txpool; -use ethkey::Password; +use types::BlockNumber; +use types::block::Block; +use types::header::Header; +use types::ids::BlockId; +use types::receipt::RichReceipt; /// Test miner service. pub struct TestMinerService { diff --git a/rpc/src/v1/tests/mocked/eth.rs b/rpc/src/v1/tests/mocked/eth.rs index aaa7fd0a4..e2585ea05 100644 --- a/rpc/src/v1/tests/mocked/eth.rs +++ b/rpc/src/v1/tests/mocked/eth.rs @@ -19,20 +19,20 @@ use std::collections::HashMap; use std::sync::Arc; use std::time::{Instant, Duration, SystemTime, UNIX_EPOCH}; -use ethereum_types::{H160, H256, U256, Address}; -use parking_lot::Mutex; use ethcore::account_provider::AccountProvider; use ethcore::client::{BlockChainClient, BlockId, EachBlockWith, Executed, TestBlockChainClient, TransactionId}; -use ethcore::log_entry::{LocalizedLogEntry, LogEntry}; use ethcore::miner::MinerService; -use ethcore::receipt::{LocalizedReceipt, TransactionOutcome}; +use ethereum_types::{H160, H256, U256, Address}; use ethkey::Secret; -use sync::SyncState; use miner::external::ExternalMiner; +use parity_runtime::Runtime; +use parking_lot::Mutex; use rlp; use rustc_hex::{FromHex, ToHex}; -use transaction::{Transaction, Action}; -use parity_runtime::Runtime; +use sync::SyncState; +use types::transaction::{Transaction, Action}; +use types::log_entry::{LocalizedLogEntry, LogEntry}; +use types::receipt::{LocalizedReceipt, TransactionOutcome}; use jsonrpc_core::IoHandler; use v1::{Eth, EthClient, EthClientOptions, EthFilter, EthFilterClient, EthSigning, SigningUnsafeClient}; @@ -584,7 +584,7 @@ fn rpc_eth_transaction_count_by_number_pending() { fn rpc_eth_pending_transaction_by_hash() { use ethereum_types::H256; use rlp; - use transaction::SignedTransaction; + use types::transaction::SignedTransaction; let tester = EthTester::default(); { diff --git a/rpc/src/v1/tests/mocked/eth_pubsub.rs b/rpc/src/v1/tests/mocked/eth_pubsub.rs index 2eb1295d8..077b16404 100644 --- a/rpc/src/v1/tests/mocked/eth_pubsub.rs +++ b/rpc/src/v1/tests/mocked/eth_pubsub.rs @@ -84,9 +84,9 @@ fn should_subscribe_to_new_heads() { #[test] fn should_subscribe_to_logs() { - use ethcore::log_entry::{LocalizedLogEntry, LogEntry}; - use ethcore::ids::BlockId; use ethcore::client::BlockInfo; + use types::log_entry::{LocalizedLogEntry, LogEntry}; + use types::ids::BlockId; // given let el = Runtime::with_thread_count(1); diff --git a/rpc/src/v1/tests/mocked/parity.rs b/rpc/src/v1/tests/mocked/parity.rs index d978a4ac7..074a704fe 100644 --- a/rpc/src/v1/tests/mocked/parity.rs +++ b/rpc/src/v1/tests/mocked/parity.rs @@ -17,12 +17,12 @@ use std::sync::Arc; use ethcore::account_provider::AccountProvider; use ethcore::client::{TestBlockChainClient, Executed, TransactionId}; -use ethcore::receipt::{LocalizedReceipt, TransactionOutcome}; use ethcore_logger::RotatingLogger; use ethereum_types::{Address, U256, H256}; use ethstore::ethkey::{Generator, Random}; use miner::pool::local_transactions::Status as LocalTransactionStatus; use sync::ManageNetwork; +use types::receipt::{LocalizedReceipt, TransactionOutcome}; use jsonrpc_core::IoHandler; use v1::{Parity, ParityClient}; @@ -433,11 +433,11 @@ fn rpc_parity_transactions_stats() { fn rpc_parity_local_transactions() { let deps = Dependencies::new(); let io = deps.default_client(); - let tx = ::transaction::Transaction { + let tx = ::types::transaction::Transaction { value: 5.into(), gas: 3.into(), gas_price: 2.into(), - action: ::transaction::Action::Create, + action: ::types::transaction::Action::Create, data: vec![1, 2, 3], nonce: 0.into(), }.fake_sign(3.into()); diff --git a/rpc/src/v1/tests/mocked/parity_set.rs b/rpc/src/v1/tests/mocked/parity_set.rs index 6438a6661..e1617ed38 100644 --- a/rpc/src/v1/tests/mocked/parity_set.rs +++ b/rpc/src/v1/tests/mocked/parity_set.rs @@ -210,7 +210,7 @@ fn rpc_parity_set_hash_content() { #[test] fn rpc_parity_remove_transaction() { - use transaction::{Transaction, Action}; + use types::transaction::{Transaction, Action}; let miner = miner_service(); let client = client_service(); diff --git a/rpc/src/v1/tests/mocked/personal.rs b/rpc/src/v1/tests/mocked/personal.rs index 143b19fa8..58e41144c 100644 --- a/rpc/src/v1/tests/mocked/personal.rs +++ b/rpc/src/v1/tests/mocked/personal.rs @@ -23,7 +23,7 @@ use ethcore::account_provider::AccountProvider; use ethcore::client::TestBlockChainClient; use jsonrpc_core::IoHandler; use parking_lot::Mutex; -use transaction::{Action, Transaction}; +use types::transaction::{Action, Transaction}; use parity_runtime::Runtime; use hash::keccak; diff --git a/rpc/src/v1/tests/mocked/signer.rs b/rpc/src/v1/tests/mocked/signer.rs index 679645baf..cd749f0f8 100644 --- a/rpc/src/v1/tests/mocked/signer.rs +++ b/rpc/src/v1/tests/mocked/signer.rs @@ -24,7 +24,7 @@ use ethcore::client::TestBlockChainClient; use parity_runtime::Runtime; use parking_lot::Mutex; use rlp::encode; -use transaction::{Transaction, Action, SignedTransaction}; +use types::transaction::{Transaction, Action, SignedTransaction}; use serde_json; use jsonrpc_core::IoHandler; diff --git a/rpc/src/v1/tests/mocked/signing.rs b/rpc/src/v1/tests/mocked/signing.rs index dba0fbd22..c3cccd63b 100644 --- a/rpc/src/v1/tests/mocked/signing.rs +++ b/rpc/src/v1/tests/mocked/signing.rs @@ -38,7 +38,7 @@ use ethkey::Secret; use ethstore::ethkey::{Generator, Random}; use parking_lot::Mutex; use serde_json; -use transaction::{Transaction, Action, SignedTransaction}; +use types::transaction::{Transaction, Action, SignedTransaction}; use parity_runtime::{Runtime, Executor}; struct SigningTester { diff --git a/rpc/src/v1/types/block.rs b/rpc/src/v1/types/block.rs index 8d8121766..73511ab38 100644 --- a/rpc/src/v1/types/block.rs +++ b/rpc/src/v1/types/block.rs @@ -17,10 +17,10 @@ use std::ops::Deref; use std::collections::BTreeMap; -use ethcore::encoded::Header as EthHeader; - -use serde::{Serialize, Serializer}; use serde::ser::Error; +use serde::{Serialize, Serializer}; +use types::encoded::Header as EthHeader; + use v1::types::{Bytes, Transaction, H160, H256, H2048, U256}; /// Block Transactions diff --git a/rpc/src/v1/types/filter.rs b/rpc/src/v1/types/filter.rs index a0663b920..fbed2fd84 100644 --- a/rpc/src/v1/types/filter.rs +++ b/rpc/src/v1/types/filter.rs @@ -14,12 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use serde::{Deserialize, Deserializer, Serialize, Serializer}; -use serde::de::{Error, DeserializeOwned}; -use serde_json::{Value, from_value}; use jsonrpc_core::{Error as RpcError}; -use ethcore::filter::Filter as EthFilter; -use ethcore::client::BlockId; +use serde::de::{Error, DeserializeOwned}; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use serde_json::{Value, from_value}; +use types::filter::Filter as EthFilter; +use types::ids::BlockId; + use v1::types::{BlockNumber, H160, H256, Log}; use v1::helpers::errors::invalid_params; @@ -149,8 +150,8 @@ mod tests { use ethereum_types::H256; use super::{VariadicValue, Topic, Filter}; use v1::types::BlockNumber; - use ethcore::filter::Filter as EthFilter; - use ethcore::client::BlockId; + use types::filter::Filter as EthFilter; + use types::ids::BlockId; #[test] fn topic_deserialization() { diff --git a/rpc/src/v1/types/log.rs b/rpc/src/v1/types/log.rs index eaef71f75..9074ffeda 100644 --- a/rpc/src/v1/types/log.rs +++ b/rpc/src/v1/types/log.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use ethcore::log_entry::{LocalizedLogEntry, LogEntry}; +use types::log_entry::{LocalizedLogEntry, LogEntry}; use v1::types::{Bytes, H160, H256, U256}; /// Log diff --git a/rpc/src/v1/types/receipt.rs b/rpc/src/v1/types/receipt.rs index a5cbfd533..32f74f1cb 100644 --- a/rpc/src/v1/types/receipt.rs +++ b/rpc/src/v1/types/receipt.rs @@ -15,7 +15,7 @@ // along with Parity. If not, see . use v1::types::{Log, H160, H256, H2048, U256, U64}; -use ethcore::receipt::{Receipt as EthReceipt, RichReceipt, LocalizedReceipt, TransactionOutcome}; +use types::receipt::{Receipt as EthReceipt, RichReceipt, LocalizedReceipt, TransactionOutcome}; /// Receipt #[derive(Debug, Serialize)] diff --git a/rpc/src/v1/types/trace.rs b/rpc/src/v1/types/trace.rs index 323766542..8de499ff2 100644 --- a/rpc/src/v1/types/trace.rs +++ b/rpc/src/v1/types/trace.rs @@ -15,15 +15,17 @@ // along with Parity. If not, see . use std::collections::BTreeMap; -use serde::{Serialize, Serializer}; -use serde::ser::SerializeStruct; -use ethcore::trace::{FlatTrace, LocalizedTrace as EthLocalizedTrace, trace, TraceError}; -use ethcore::trace as et; -use ethcore::state_diff; -use ethcore::account_diff; + use ethcore::client::Executed; +use ethcore::trace as et; +use ethcore::trace::{FlatTrace, LocalizedTrace as EthLocalizedTrace, trace, TraceError}; use ethereum_types::H256 as EthH256; +use serde::ser::SerializeStruct; +use serde::{Serialize, Serializer}; +use types::account_diff; +use types::state_diff; use vm; + use v1::types::{Bytes, H160, H256, U256}; #[derive(Debug, Serialize)] diff --git a/rpc/src/v1/types/transaction.rs b/rpc/src/v1/types/transaction.rs index ebf983edb..0b2547a38 100644 --- a/rpc/src/v1/types/transaction.rs +++ b/rpc/src/v1/types/transaction.rs @@ -20,7 +20,7 @@ use serde::{Serialize, Serializer}; use serde::ser::SerializeStruct; use ethcore::{contract_address, CreateContractAddress}; use miner; -use transaction::{LocalizedTransaction, Action, PendingTransaction, SignedTransaction}; +use types::transaction::{LocalizedTransaction, Action, PendingTransaction, SignedTransaction}; use v1::types::{Bytes, H160, H256, U256, H512, U64, TransactionCondition}; /// Transaction diff --git a/rpc/src/v1/types/transaction_condition.rs b/rpc/src/v1/types/transaction_condition.rs index c4f7720c9..29a3d8b1d 100644 --- a/rpc/src/v1/types/transaction_condition.rs +++ b/rpc/src/v1/types/transaction_condition.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use transaction; +use types::transaction; /// Represents condition on minimum block number or block timestamp. #[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)] diff --git a/secret-store/Cargo.toml b/secret-store/Cargo.toml index f431b6fbd..5941c8602 100644 --- a/secret-store/Cargo.toml +++ b/secret-store/Cargo.toml @@ -7,6 +7,7 @@ authors = ["Parity Technologies "] [dependencies] byteorder = "1.0" +common-types = { path = "../ethcore/types" } log = "0.4" parking_lot = "0.7" hyper = { version = "0.12", default-features = false } @@ -26,7 +27,6 @@ parity-bytes = "0.1" parity-crypto = "0.2" ethcore-logger = { path = "../logger" } ethcore-sync = { path = "../ethcore/sync" } -ethcore-transaction = { path = "../ethcore/transaction" } ethereum-types = "0.4" kvdb = "0.1" keccak-hash = "0.1" diff --git a/secret-store/src/lib.rs b/secret-store/src/lib.rs index 1acbde380..d0a430e21 100644 --- a/secret-store/src/lib.rs +++ b/secret-store/src/lib.rs @@ -15,25 +15,25 @@ // along with Parity. If not, see . extern crate byteorder; +extern crate common_types; extern crate ethabi; extern crate ethcore; -extern crate parity_bytes as bytes; -extern crate parity_crypto as crypto; extern crate ethcore_logger as logger; extern crate ethcore_sync as sync; -extern crate ethcore_transaction as transaction; extern crate ethereum_types; extern crate ethkey; extern crate hyper; extern crate keccak_hash as hash; extern crate kvdb; +extern crate parity_bytes as bytes; +extern crate parity_crypto as crypto; +extern crate parity_runtime; extern crate parking_lot; extern crate rustc_hex; extern crate serde; extern crate serde_json; extern crate tiny_keccak; extern crate tokio; -extern crate parity_runtime; extern crate tokio_io; extern crate tokio_service; extern crate url; diff --git a/secret-store/src/listener/service_contract.rs b/secret-store/src/listener/service_contract.rs index 545ce8000..4bb99eb5a 100644 --- a/secret-store/src/listener/service_contract.rs +++ b/secret-store/src/listener/service_contract.rs @@ -16,10 +16,10 @@ use std::sync::Arc; use parking_lot::RwLock; +use common_types::filter::Filter; use ethabi::RawLog; use ethabi::FunctionOutputDecoder; use ethcore::client::{Client, BlockChainClient, BlockId, CallContract}; -use ethcore::filter::Filter; use ethkey::{Public, public_to_address}; use hash::keccak; use bytes::Bytes; diff --git a/secret-store/src/trusted_client.rs b/secret-store/src/trusted_client.rs index 24db21460..669888e58 100644 --- a/secret-store/src/trusted_client.rs +++ b/secret-store/src/trusted_client.rs @@ -16,11 +16,11 @@ use std::sync::{Arc, Weak}; use bytes::Bytes; +use common_types::transaction::{Transaction, SignedTransaction, Action}; use ethereum_types::Address; use ethcore::client::{Client, BlockChainClient, ChainInfo, Nonce, BlockId, RegistryInfo}; use ethcore::miner::{Miner, MinerService}; use sync::SyncProvider; -use transaction::{Transaction, SignedTransaction, Action}; use helpers::{get_confirmed_block_hash, REQUEST_CONFIRMATIONS_REQUIRED}; use {Error, NodeKeyPair, ContractAddress}; diff --git a/updater/Cargo.toml b/updater/Cargo.toml index 329a150e9..dd3417f88 100644 --- a/updater/Cargo.toml +++ b/updater/Cargo.toml @@ -6,23 +6,24 @@ license = "GPL-3.0" authors = ["Parity Technologies "] [dependencies] +common-types = { path = "../ethcore/types" } +ethabi = "6.0" +ethabi-contract = "6.0" +ethabi-derive = "6.0" +ethcore = { path = "../ethcore" } +ethcore-sync = { path = "../ethcore/sync" } +ethereum-types = "0.4" keccak-hash = "0.1" lazy_static = "1.0" log = "0.4" -ethabi = "6.0" -ethabi-derive = "6.0" -ethabi-contract = "6.0" -target_info = "0.1" -semver = "0.9" -ethcore = { path = "../ethcore" } parity-bytes = "0.1" -ethcore-sync = { path = "../ethcore/sync" } -ethereum-types = "0.4" -parking_lot = "0.7" parity-hash-fetch = { path = "hash-fetch" } -parity-version = { path = "../util/version" } parity-path = "0.1" +parity-version = { path = "../util/version" } +parking_lot = "0.7" rand = "0.4" +semver = "0.9" +target_info = "0.1" [dev-dependencies] ethcore = { path = "../ethcore", features = ["test-helpers"] } diff --git a/updater/src/lib.rs b/updater/src/lib.rs index 611572fac..56c7065db 100644 --- a/updater/src/lib.rs +++ b/updater/src/lib.rs @@ -18,16 +18,17 @@ #![warn(missing_docs)] +extern crate common_types; extern crate ethabi; extern crate ethcore; -extern crate parity_bytes as bytes; extern crate ethcore_sync as sync; extern crate ethereum_types; extern crate keccak_hash as hash; +extern crate parity_bytes as bytes; extern crate parity_hash_fetch as hash_fetch; +extern crate parity_path; extern crate parity_version as version; extern crate parking_lot; -extern crate parity_path; extern crate rand; extern crate semver; extern crate target_info; diff --git a/updater/src/updater.rs b/updater/src/updater.rs index 4b968625a..8c8539d11 100644 --- a/updater/src/updater.rs +++ b/updater/src/updater.rs @@ -25,9 +25,9 @@ use parking_lot::{Mutex, MutexGuard}; use rand::{self, Rng}; use target_info::Target; -use ethcore::BlockNumber; +use common_types::BlockNumber; +use common_types::filter::Filter; use ethcore::client::{BlockId, BlockChainClient, ChainNotify, NewBlocks}; -use ethcore::filter::Filter; use ethereum_types::H256; use hash_fetch::{self as fetch, HashFetch}; use parity_path::restrict_permissions_owner;