From b47e064f8e5248582094036404891e6132428db5 Mon Sep 17 00:00:00 2001 From: Thibaut Sardan <33178835+Tbaut@users.noreply.github.com> Date: Thu, 13 Dec 2018 17:53:36 +0100 Subject: [PATCH] Backports for stable 2.1.10 (#10046) * bump stable to 2.1.10 * RPC: parity_getBlockReceipts (#9527) * Block receipts RPC. * Use lazy evaluation of block receipts (ecrecover). * Optimize transaction_receipt to prevent performance regression. * Fix RPC grumbles. * Add block & transaction receipt tests. * Fix conversion to block id. * Update a few parity-common dependencies (#9663) * Update a few parity-common dependencies * cleanup * cleanup * revert update of ethereum/tests * better reporting of network rlp errors * Use rlp 0.3.0-beta.1 * fix util function get_dummy_blocks * Already a Vec * encode_list returns vec already * Address grumble * No need for betas * Fix double spaces * Fix empty steps (#9939) * Don't send empty step twice or empty step then block. * Perform basic validation of locally sealed blocks. * Don't include empty step twice. * Strict empty steps validation (#10041) * Add two failings tests for strict empty steps. * Implement strict validation of empty steps. * ethcore: enable constantinople on ethereum (#10031) * ethcore: change blockreward to 2e18 for foundation after constantinople * ethcore: delay diff bomb by 2e6 blocks for foundation after constantinople * ethcore: enable eip-{145,1014,1052,1283} for foundation after constantinople * Change test miner max memory to malloc reports. (#10024) * Bump crossbeam. (#10048) * Revert "Bump crossbeam. (#10048)" This reverts commit ed1db0c2d3d3b8e6bfde3124fb03b093a264e241. --- Cargo.lock | 128 ++++--- Cargo.toml | 4 +- ethcore/Cargo.toml | 8 +- ethcore/light/Cargo.toml | 8 +- ethcore/light/src/cht.rs | 13 +- ethcore/light/src/client/header_chain.rs | 2 +- ethcore/light/src/net/tests/mod.rs | 2 +- ethcore/light/src/on_demand/request.rs | 16 +- ethcore/light/src/provider.rs | 2 +- ethcore/light/src/types/request/mod.rs | 2 +- ethcore/private-tx/Cargo.toml | 4 +- ethcore/private-tx/src/lib.rs | 10 +- ethcore/res/ethereum/foundation.json | 12 +- ethcore/src/account_db.rs | 52 +-- ethcore/src/blockchain/blockchain.rs | 5 - ethcore/src/blockchain/generator.rs | 2 +- ethcore/src/client/client.rs | 124 ++++--- ethcore/src/client/test_client.rs | 6 +- ethcore/src/client/traits.rs | 7 +- ethcore/src/engines/authority_round/mod.rs | 346 ++++++++++-------- ethcore/src/engines/basic_authority.rs | 4 +- ethcore/src/engines/instant_seal.rs | 2 +- ethcore/src/engines/tendermint/message.rs | 6 +- ethcore/src/engines/tendermint/mod.rs | 26 +- ethcore/src/engines/validator_set/contract.rs | 4 +- .../engines/validator_set/safe_contract.rs | 2 +- ethcore/src/engines/validator_set/test.rs | 10 +- ethcore/src/ethereum/ethash.rs | 10 +- ethcore/src/header.rs | 2 +- ethcore/src/json_tests/trie.rs | 3 +- ethcore/src/miner/miner.rs | 28 +- ethcore/src/miner/mod.rs | 9 +- ethcore/src/miner/stratum.rs | 2 +- ethcore/src/pod_account.rs | 3 +- ethcore/src/snapshot/account.rs | 2 +- ethcore/src/snapshot/mod.rs | 11 +- ethcore/src/snapshot/tests/helpers.rs | 6 +- ethcore/src/state/account.rs | 16 +- ethcore/src/state/backend.rs | 53 +-- ethcore/src/state/mod.rs | 6 +- ethcore/src/state_db.rs | 10 +- ethcore/src/test_helpers.rs | 2 +- ethcore/src/views/body.rs | 4 +- ethcore/sync/Cargo.toml | 6 +- ethcore/sync/src/api.rs | 2 +- ethcore/sync/src/block_sync.rs | 2 +- ethcore/sync/src/chain/handler.rs | 4 +- ethcore/sync/src/chain/mod.rs | 2 +- ethcore/sync/src/chain/supplier.rs | 2 +- ethcore/sync/src/light_sync/response.rs | 8 +- ethcore/transaction/Cargo.toml | 2 +- ethcore/types/Cargo.toml | 2 +- ethcore/vm/Cargo.toml | 4 +- ipfs/Cargo.toml | 2 +- ipfs/src/route.rs | 4 +- json/src/spec/authority_round.rs | 2 + local-store/Cargo.toml | 2 +- local-store/src/lib.rs | 2 +- miner/Cargo.toml | 2 +- miner/src/pool/tests/mod.rs | 26 +- rpc/Cargo.toml | 4 +- rpc/src/v1/helpers/work.rs | 47 +++ rpc/src/v1/impls/eth.rs | 26 +- rpc/src/v1/impls/light/eth.rs | 35 +- rpc/src/v1/impls/light/parity.rs | 20 +- rpc/src/v1/impls/parity.rs | 38 +- rpc/src/v1/impls/personal.rs | 2 +- rpc/src/v1/tests/helpers/miner_service.rs | 32 +- rpc/src/v1/tests/mocked/eth.rs | 2 +- rpc/src/v1/tests/mocked/parity.rs | 34 +- rpc/src/v1/traits/parity.rs | 8 +- rpc/src/v1/types/block_number.rs | 25 ++ rpc/src/v1/types/mod.rs | 2 +- rpc/src/v1/types/transaction.rs | 4 +- util/journaldb/Cargo.toml | 6 +- util/journaldb/src/archivedb.rs | 10 +- util/journaldb/src/as_hash_db_impls.rs | 33 +- util/journaldb/src/earlymergedb.rs | 10 +- util/journaldb/src/overlaydb.rs | 10 +- util/journaldb/src/overlayrecentdb.rs | 16 +- util/journaldb/src/refcounteddb.rs | 8 +- util/journaldb/src/traits.rs | 8 +- util/keccak-hasher/Cargo.toml | 2 +- util/network-devp2p/Cargo.toml | 2 +- util/network-devp2p/src/discovery.rs | 12 +- util/network/Cargo.toml | 2 +- util/network/src/error.rs | 9 +- util/patricia-trie-ethereum/Cargo.toml | 8 +- util/patricia-trie-ethereum/src/lib.rs | 12 +- .../src/rlp_node_codec.rs | 11 +- util/rlp_compress/Cargo.toml | 2 +- util/rlp_compress/src/lib.rs | 2 +- util/rlp_derive/Cargo.toml | 2 +- util/rlp_derive/tests/rlp.rs | 4 +- util/triehash-ethereum/Cargo.toml | 2 +- util/triehash-ethereum/src/lib.rs | 6 +- util/version/Cargo.toml | 4 +- whisper/Cargo.toml | 2 +- 98 files changed, 863 insertions(+), 647 deletions(-) create mode 100644 rpc/src/v1/helpers/work.rs diff --git a/Cargo.lock b/Cargo.lock index d116b27f5f7..07f51eec12b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -270,7 +270,7 @@ dependencies = [ "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)", - "rlp 0.2.4 (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", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -542,7 +542,7 @@ dependencies = [ "evm 0.1.0", "fake-hardware-wallet 0.0.1", "hardware-wallet 1.12.0", - "hashdb 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "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)", "itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", "journaldb 0.2.0", @@ -556,7 +556,7 @@ dependencies = [ "lru-cache 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "macros 0.1.0", "memory-cache 0.1.0", - "memorydb 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "memorydb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -564,11 +564,11 @@ dependencies = [ "parity-machine 0.1.0", "parity-snappy 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", - "patricia-trie 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "patricia-trie 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "patricia-trie-ethereum 0.1.0", "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.2.4 (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)", @@ -623,7 +623,7 @@ dependencies = [ "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "fastmap 0.1.0", "futures 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)", - "hashdb 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "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)", "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)", @@ -632,13 +632,13 @@ dependencies = [ "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)", "memory-cache 0.1.0", - "memorydb 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "memorydb 0.3.0 (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.6.4 (registry+https://github.com/rust-lang/crates.io-index)", - "patricia-trie 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "patricia-trie 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "patricia-trie-ethereum 0.1.0", "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.2.4 (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", "serde 1.0.78 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.78 (registry+https://github.com/rust-lang/crates.io-index)", @@ -686,7 +686,7 @@ dependencies = [ "parity-reactor 0.1.0", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "price-info 1.12.0", - "rlp 0.2.4 (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)", "trace-time 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "transaction-pool 1.13.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -706,7 +706,7 @@ dependencies = [ "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", "parity-crypto 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-snappy 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -734,7 +734,7 @@ dependencies = [ "parity-snappy 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.78 (registry+https://github.com/rust-lang/crates.io-index)", @@ -769,10 +769,10 @@ dependencies = [ "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-crypto 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", - "patricia-trie 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "patricia-trie 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "patricia-trie-ethereum 0.1.0", "rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.2.4 (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", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.78 (registry+https://github.com/rust-lang/crates.io-index)", @@ -874,7 +874,7 @@ dependencies = [ "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethkey 0.3.0", "fastmap 0.1.0", - "hashdb 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "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)", "ipnetwork 0.12.8 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -886,7 +886,7 @@ dependencies = [ "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.2.4 (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)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "trace-time 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -903,7 +903,7 @@ dependencies = [ "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.2.4 (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", ] @@ -1210,11 +1210,8 @@ dependencies = [ [[package]] name = "hashdb" -version = "0.2.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", -] [[package]] name = "heapsize" @@ -1399,17 +1396,17 @@ dependencies = [ "ethcore-logger 1.12.0", "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "fastmap 0.1.0", - "hashdb 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "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)", "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hasher 0.1.1", "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)", - "memorydb 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "memorydb 0.3.0 (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.6.4 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1523,7 +1520,7 @@ name = "keccak-hasher" version = "0.1.1" dependencies = [ "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hashdb 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "hashdb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "plain_hasher 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1730,14 +1727,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "memorydb" -version = "0.2.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hashdb 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "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)", "plain_hasher 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2007,7 +2003,7 @@ version = "1.12.0" dependencies = [ "jni 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "panic_hook 0.1.0", - "parity-ethereum 2.1.9", + "parity-ethereum 2.1.10", ] [[package]] @@ -2023,7 +2019,7 @@ dependencies = [ [[package]] name = "parity-ethereum" -version = "2.1.9" +version = "2.1.10" dependencies = [ "ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2073,13 +2069,13 @@ dependencies = [ "parity-rpc 1.12.0", "parity-rpc-client 1.4.0", "parity-updater 1.12.0", - "parity-version 2.1.9", + "parity-version 2.1.10", "parity-whisper 0.1.0", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "registrar 0.0.1", - "rlp 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "rpassword 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "rpc-cli 1.4.0", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2131,7 +2127,7 @@ dependencies = [ "jsonrpc-http-server 8.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.11)", "multihash 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicase 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2146,7 +2142,7 @@ dependencies = [ "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)", - "rlp 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.78 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.78 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2238,12 +2234,12 @@ dependencies = [ "parity-crypto 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-reactor 0.1.0", "parity-updater 1.12.0", - "parity-version 2.1.9", + "parity-version 2.1.10", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", - "patricia-trie 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "patricia-trie 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.2.4 (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)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.78 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2328,7 +2324,7 @@ dependencies = [ "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-hash-fetch 1.12.0", "parity-path 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-version 2.1.9", + "parity-version 2.1.10", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2338,10 +2334,10 @@ dependencies = [ [[package]] name = "parity-version" -version = "2.1.9" +version = "2.1.10" dependencies = [ "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "target_info 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2375,7 +2371,7 @@ dependencies = [ "parity-crypto 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.78 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.78 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2420,11 +2416,11 @@ dependencies = [ [[package]] name = "patricia-trie" -version = "0.2.2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hashdb 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "hashdb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2436,13 +2432,13 @@ version = "0.1.0" dependencies = [ "elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hashdb 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "hashdb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hasher 0.1.1", - "memorydb 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "memorydb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "patricia-trie 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "patricia-trie 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2820,13 +2816,23 @@ dependencies = [ "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rlp" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rlp_compress" version = "0.1.0" dependencies = [ "elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2834,7 +2840,7 @@ name = "rlp_derive" version = "0.1.0" dependencies = [ "quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "syn 0.13.11 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3554,12 +3560,11 @@ dependencies = [ [[package]] name = "triehash" -version = "0.2.3" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hashdb 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "hashdb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3568,7 +3573,7 @@ version = "0.2.0" dependencies = [ "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hasher 0.1.1", - "triehash 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "triehash 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3702,9 +3707,9 @@ dependencies = [ "keccak-hash 0.1.2 (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)", - "patricia-trie 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "patricia-trie 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "patricia-trie-ethereum 0.1.0", - "rlp 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3958,7 +3963,7 @@ dependencies = [ "checksum getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "0a7292d30132fb5424b354f5dc02512a86e4c516fe544bb7a25e7f266951b797" "checksum globset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "464627f948c3190ae3d04b1bc6d7dca2f785bda0ac01278e6db129ad383dbeb6" "checksum hamming 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "65043da274378d68241eb9a8f8f8aa54e349136f7b8e12f63e3ef44043cc30e1" -"checksum hashdb 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f1c71fc577cde89b3345d5f2880fecaf462a32e96c619f431279bdaf1ba5ddb1" +"checksum hashdb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d91261ee336dd046ac7df28306cb297b7a7228bd1ae25e9a57f4ed5e0ab628c7" "checksum heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1679e6ea370dee694f91f1dc469bf94cf8f52051d147aec3e1f9497c6fc22461" "checksum heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea04fa3ead4e05e51a7c806fc07271fdbde4e246a6c6d1efd52e72230b771b82" "checksum hex 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d6a22814455d41612f41161581c2883c0c6a1c41852729b17d5ed88f01e153aa" @@ -4011,7 +4016,7 @@ dependencies = [ "checksum memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2ffa2c986de11a9df78620c01eeaaf27d94d3ff02bf81bfcca953102dd0c6ff" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum memory_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71d96e3f3c0b6325d8ccd83c33b28acb183edcb6c67938ba104ec546854b0882" -"checksum memorydb 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f72c93304ad51e21230ecbd0d2b58a3f94703bf9339d14aed88c3aaf5e8b7a56" +"checksum memorydb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e143fbad9f90d2158bca3c4b09015276a6de6f085a77088943901cb26828780f" "checksum mime 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "4b082692d3f6cf41b453af73839ce3dfc212c4411cbb2441dff80a716e38bd79" "checksum mime_guess 2.0.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "30de2e4613efcba1ec63d8133f344076952090c122992a903359be5a4f99c3ed" "checksum mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)" = "71646331f2619b1026cc302f87a2b8b648d5c6dd6937846a16cc8ce0f347f432" @@ -4049,7 +4054,7 @@ dependencies = [ "checksum parity-wordlist 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d0dec124478845b142f68b446cbee953d14d4b41f1bc0425024417720dce693" "checksum parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f0802bff09003b291ba756dc7e79313e51cc31667e94afbe847def490424cde5" "checksum parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad7f7e6ebdc79edff6fdcb87a55b620174f7a989e3eb31b65231f4af57f00b8c" -"checksum patricia-trie 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "46be3bf26e050bcaac60d0a8373f912a4734bb8bd4bf5ecda66ee997b86bddfc" +"checksum patricia-trie 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "10438ba40c2f6e9ceca55277d8e7f6a5dafd58cabd802e6d97e16f02aab83a03" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)" = "9c3659d1ee90221741f65dd128d9998311b0e40c5d3c23a62445938214abce4f" "checksum phf 0.7.23 (registry+https://github.com/rust-lang/crates.io-index)" = "cec29da322b242f4c3098852c77a0ca261c9c01b806cae85a5572a1eb94db9a6" @@ -4089,6 +4094,7 @@ dependencies = [ "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" "checksum ring 0.12.1 (git+https://github.com/paritytech/ring)" = "" "checksum rlp 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "524c5ad554859785dfc8469df3ed5e0b5784d4d335877ed47c8d90fc0eb238fe" +"checksum rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "16d1effe9845d54f90e7be8420ee49e5c94623140b97ee4bc6fb5bfddb745720" "checksum rpassword 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b273c91bd242ca03ad6d71c143b6f17a48790e61f21a6c78568fa2b6774a24a4" "checksum rprompt 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1601f32bc5858aae3cbfa1c645c96c4d820cc5c16be0194f089560c00b6eb625" "checksum rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a" @@ -4167,7 +4173,7 @@ dependencies = [ "checksum transient-hashmap 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aeb4b191d033a35edfce392a38cdcf9790b6cebcb30fa690c312c29da4dc433e" "checksum trezor-sys 1.0.0 (git+https://github.com/paritytech/trezor-sys)" = "" "checksum trie-standardmap 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0e26f52976a57a0859616d6fcec87092ac35d08eabbd78dc3dabee93b480ea5f" -"checksum triehash 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3da77dc2c88bac48769c53f2c7675d99d522a7fc8130da3fadf29d7c6f94c9ac" +"checksum triehash 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cd9cb3a626dd9a19a1b5f84087143b19409db793d902c5ddee4b6212020713f1" "checksum try-lock 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee2aa4715743892880f70885373966c83d73ef1b0838a664ef0c76fffd35e7c2" "checksum ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd2be2d6639d0f8fe6cdda291ad456e23629558d466e2789d2c3e9892bda285d" "checksum uint 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "754ba11732b9161b94c41798e5197e5e75388d012f760c42adb5000353e98646" diff --git a/Cargo.toml b/Cargo.toml index 1efa9f8a7d7..dbc6eafddef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ description = "Parity Ethereum client" name = "parity-ethereum" # NOTE Make sure to update util/version/Cargo.toml as well -version = "2.1.9" +version = "2.1.10" license = "GPL-3.0" authors = ["Parity Technologies "] @@ -46,7 +46,7 @@ ethcore-transaction = { path = "ethcore/transaction" } ethereum-types = "0.4" node-filter = { path = "ethcore/node_filter" } ethkey = { path = "ethkey" } -rlp = { version = "0.2.4", features = ["ethereum"] } +rlp = { version = "0.3.0", features = ["ethereum"] } rpc-cli = { path = "rpc_cli" } parity-hash-fetch = { path = "hash-fetch" } parity-ipfs-api = { path = "ipfs" } diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index 098eb5f1763..7e276250e95 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -16,9 +16,9 @@ crossbeam = "0.3" ethash = { path = "../ethash" } ethcore-bloom-journal = { path = "../util/bloom" } parity-bytes = "0.1" -hashdb = "0.2.1" -memorydb = "0.2.1" -patricia-trie = "0.2" +hashdb = "0.3.0" +memorydb = "0.3.0" +patricia-trie = "0.3.0" patricia-trie-ethereum = { path = "../util/patricia-trie-ethereum" } parity-crypto = "0.1" error-chain = { version = "0.12", default-features = false } @@ -47,7 +47,7 @@ parity-machine = { path = "../machine" } parking_lot = "0.6" rayon = "1.0" rand = "0.4" -rlp = { version = "0.2.4", features = ["ethereum"] } +rlp = { version = "0.3.0", features = ["ethereum"] } rlp_compress = { path = "../util/rlp_compress" } rlp_derive = { path = "../util/rlp_derive" } kvdb = "0.1" diff --git a/ethcore/light/Cargo.toml b/ethcore/light/Cargo.toml index 8790e2fbd89..4d58abaa33a 100644 --- a/ethcore/light/Cargo.toml +++ b/ethcore/light/Cargo.toml @@ -12,16 +12,16 @@ ethcore = { path = ".."} parity-bytes = "0.1" ethcore-transaction = { path = "../transaction" } ethereum-types = "0.4" -memorydb = "0.2.1" -patricia-trie = "0.2" +memorydb = "0.3.0" +patricia-trie = "0.3.0" patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" } ethcore-network = { path = "../../util/network" } ethcore-io = { path = "../../util/io" } -hashdb = "0.2.1" +hashdb = "0.3.0" heapsize = "0.4" vm = { path = "../vm" } fastmap = { path = "../../util/fastmap" } -rlp = { version = "0.2.4", features = ["ethereum"] } +rlp = { version = "0.3.0", features = ["ethereum"] } rlp_derive = { path = "../../util/rlp_derive" } smallvec = "0.6" futures = "0.1" diff --git a/ethcore/light/src/cht.rs b/ethcore/light/src/cht.rs index a8e57b04aba..c6665f85759 100644 --- a/ethcore/light/src/cht.rs +++ b/ethcore/light/src/cht.rs @@ -27,6 +27,7 @@ use ethcore::ids::BlockId; use ethereum_types::{H256, U256}; use hashdb::HashDB; use keccak_hasher::KeccakHasher; +use kvdb::DBValue; use memorydb::MemoryDB; use bytes::Bytes; use trie::{TrieMut, Trie, Recorder}; @@ -52,13 +53,13 @@ pub const SIZE: u64 = 2048; /// A canonical hash trie. This is generic over any database it can query. /// See module docs for more details. #[derive(Debug, Clone)] -pub struct CHT> { +pub struct CHT> { db: DB, root: H256, // the root of this CHT. number: u64, } -impl> CHT { +impl> CHT { /// Query the root of the CHT. pub fn root(&self) -> H256 { self.root } @@ -92,10 +93,10 @@ pub struct BlockInfo { /// Build an in-memory CHT from a closure which provides necessary information /// about blocks. If the fetcher ever fails to provide the info, the CHT /// will not be generated. -pub fn build(cht_num: u64, mut fetcher: F) -> Option>> +pub fn build(cht_num: u64, mut fetcher: F) -> Option>> where F: FnMut(BlockId) -> Option { - let mut db = MemoryDB::::new(); + let mut db = MemoryDB::::new(); // start from the last block by number and work backwards. let last_num = start_number(cht_num + 1) - 1; @@ -134,7 +135,7 @@ pub fn compute_root(cht_num: u64, iterable: I) -> Option let start_num = start_number(cht_num) as usize; for (i, (h, td)) in iterable.into_iter().take(SIZE as usize).enumerate() { - v.push((key!(i + start_num).into_vec(), val!(h, td).into_vec())) + v.push((key!(i + start_num), val!(h, td))) } if v.len() == SIZE as usize { @@ -149,7 +150,7 @@ pub fn compute_root(cht_num: u64, iterable: I) -> Option /// verify the given trie branch and extract the canonical hash and total difficulty. // TODO: better support for partially-checked queries. pub fn check_proof(proof: &[Bytes], num: u64, root: H256) -> Option<(H256, U256)> { - let mut db = MemoryDB::::new(); + let mut db = MemoryDB::::new(); for node in proof { db.insert(&node[..]); } let res = match TrieDB::new(&db, &root) { diff --git a/ethcore/light/src/client/header_chain.rs b/ethcore/light/src/client/header_chain.rs index c3a119473bb..939ba6d8bc4 100644 --- a/ethcore/light/src/client/header_chain.rs +++ b/ethcore/light/src/client/header_chain.rs @@ -218,7 +218,7 @@ impl HeaderChain { ) -> Result { let mut live_epoch_proofs = ::std::collections::HashMap::default(); - let genesis = ::rlp::encode(&spec.genesis_header()).into_vec(); + let genesis = ::rlp::encode(&spec.genesis_header()); let decoded_header = spec.genesis_header(); let chain = if let Some(current) = db.get(col, CURRENT_KEY)? { diff --git a/ethcore/light/src/net/tests/mod.rs b/ethcore/light/src/net/tests/mod.rs index 75ddf0e188f..791315f5f20 100644 --- a/ethcore/light/src/net/tests/mod.rs +++ b/ethcore/light/src/net/tests/mod.rs @@ -151,7 +151,7 @@ impl Provider for TestProvider { fn storage_proof(&self, req: request::CompleteStorageRequest) -> Option { Some(StorageResponse { - proof: vec![::rlp::encode(&req.key_hash).into_vec()], + proof: vec![::rlp::encode(&req.key_hash)], value: req.key_hash | req.address_hash, }) } diff --git a/ethcore/light/src/on_demand/request.rs b/ethcore/light/src/on_demand/request.rs index 76ecf879d00..a0adc508136 100644 --- a/ethcore/light/src/on_demand/request.rs +++ b/ethcore/light/src/on_demand/request.rs @@ -1156,7 +1156,7 @@ mod tests { header.set_number(10_000); header.set_extra_data(b"test_header".to_vec()); let hash = header.hash(); - let raw_header = encoded::Header::new(::rlp::encode(&header).into_vec()); + let raw_header = encoded::Header::new(::rlp::encode(&header)); let cache = Mutex::new(make_cache()); assert!(HeaderByHash(hash.into()).check_response(&cache, &hash.into(), &[raw_header]).is_ok()) @@ -1177,14 +1177,14 @@ mod tests { headers.reverse(); // because responses are in reverse order let raw_headers = headers.iter() - .map(|hdr| encoded::Header::new(::rlp::encode(hdr).into_vec())) + .map(|hdr| encoded::Header::new(::rlp::encode(hdr))) .collect::>(); let mut invalid_successor = Header::new(); invalid_successor.set_number(11); invalid_successor.set_parent_hash(headers[1].hash()); - let raw_invalid_successor = encoded::Header::new(::rlp::encode(&invalid_successor).into_vec()); + let raw_invalid_successor = encoded::Header::new(::rlp::encode(&invalid_successor)); let cache = Mutex::new(make_cache()); @@ -1247,10 +1247,10 @@ mod tests { let mut body_stream = RlpStream::new_list(2); body_stream.begin_list(0).begin_list(0); - let req = Body(encoded::Header::new(::rlp::encode(&header).into_vec()).into()); + let req = Body(encoded::Header::new(::rlp::encode(&header)).into()); let cache = Mutex::new(make_cache()); - let response = encoded::Body::new(body_stream.drain().into_vec()); + let response = encoded::Body::new(body_stream.drain()); assert!(req.check_response(&cache, &response).is_ok()) } @@ -1270,7 +1270,7 @@ mod tests { header.set_receipts_root(receipts_root); - let req = BlockReceipts(encoded::Header::new(::rlp::encode(&header).into_vec()).into()); + let req = BlockReceipts(encoded::Header::new(::rlp::encode(&header)).into()); let cache = Mutex::new(make_cache()); assert!(req.check_response(&cache, &receipts).is_ok()) @@ -1318,7 +1318,7 @@ mod tests { header.set_state_root(root.clone()); let req = Account { - header: encoded::Header::new(::rlp::encode(&header).into_vec()).into(), + header: encoded::Header::new(::rlp::encode(&header)).into(), address: addr, }; @@ -1332,7 +1332,7 @@ mod tests { let code_hash = keccak(&code); let header = Header::new(); let req = Code { - header: encoded::Header::new(::rlp::encode(&header).into_vec()).into(), + header: encoded::Header::new(::rlp::encode(&header)).into(), code_hash: code_hash.into(), }; diff --git a/ethcore/light/src/provider.rs b/ethcore/light/src/provider.rs index 2ac3ebd9178..72344620653 100644 --- a/ethcore/light/src/provider.rs +++ b/ethcore/light/src/provider.rs @@ -176,7 +176,7 @@ impl Provider for T { } fn block_receipts(&self, req: request::CompleteReceiptsRequest) -> Option { - BlockChainClient::block_receipts(self, &req.hash) + BlockChainClient::encoded_block_receipts(self, &req.hash) .map(|x| ::request::ReceiptsResponse { receipts: ::rlp::decode_list(&x) }) } diff --git a/ethcore/light/src/types/request/mod.rs b/ethcore/light/src/types/request/mod.rs index a6e53bc10c6..c57e8383ed4 100644 --- a/ethcore/light/src/types/request/mod.rs +++ b/ethcore/light/src/types/request/mod.rs @@ -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()).into_vec()) + ::ethcore::encoded::Header::new(::rlp::encode(&Header::default())) ] }; let full_res = Response::Headers(res.clone()); diff --git a/ethcore/private-tx/Cargo.toml b/ethcore/private-tx/Cargo.toml index ed098c182a1..acda533a8b0 100644 --- a/ethcore/private-tx/Cargo.toml +++ b/ethcore/private-tx/Cargo.toml @@ -26,10 +26,10 @@ heapsize = "0.4" keccak-hash = "0.1.2" log = "0.4" parking_lot = "0.6" -patricia-trie = "0.2" +patricia-trie = "0.3.0" patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" } rand = "0.3" -rlp = { version = "0.2.4", features = ["ethereum"] } +rlp = { version = "0.3.0", features = ["ethereum"] } rlp_derive = { path = "../../util/rlp_derive" } rustc-hex = "1.0" serde = "1.0" diff --git a/ethcore/private-tx/src/lib.rs b/ethcore/private-tx/src/lib.rs index 24727fe0f5b..a83e9ba11a6 100644 --- a/ethcore/private-tx/src/lib.rs +++ b/ethcore/private-tx/src/lib.rs @@ -219,7 +219,7 @@ impl Provider where { let private_state_hash = self.calculate_state_hash(&private_state, contract_nonce); trace!(target: "privatetx", "Hashed effective private state for sender: {:?}", private_state_hash); self.transactions_for_signing.write().add_transaction(private.hash(), signed_transaction, contract_validators, private_state, contract_nonce)?; - self.broadcast_private_transaction(private.hash(), private.rlp_bytes().into_vec()); + self.broadcast_private_transaction(private.hash(), private.rlp_bytes()); Ok(Receipt { hash: tx_hash, contract_address: Some(contract), @@ -258,13 +258,13 @@ impl Provider where { match transaction.validator_account { None => { trace!(target: "privatetx", "Propagating transaction further"); - self.broadcast_private_transaction(private_hash, transaction.private_transaction.rlp_bytes().into_vec()); + self.broadcast_private_transaction(private_hash, transaction.private_transaction.rlp_bytes()); return Ok(()); } Some(validator_account) => { if !self.validator_accounts.contains(&validator_account) { trace!(target: "privatetx", "Propagating transaction further"); - self.broadcast_private_transaction(private_hash, transaction.private_transaction.rlp_bytes().into_vec()); + self.broadcast_private_transaction(private_hash, transaction.private_transaction.rlp_bytes()); return Ok(()); } let tx_action = transaction.transaction.action.clone(); @@ -290,7 +290,7 @@ impl Provider where { let signed_state = signed_state.expect("Error was checked before"); let signed_private_transaction = SignedPrivateTransaction::new(private_hash, signed_state, None); trace!(target: "privatetx", "Sending signature for private transaction: {:?}", signed_private_transaction); - self.broadcast_signed_private_transaction(signed_private_transaction.hash(), signed_private_transaction.rlp_bytes().into_vec()); + self.broadcast_signed_private_transaction(signed_private_transaction.hash(), signed_private_transaction.rlp_bytes()); } else { bail!("Incorrect type of action for the transaction"); } @@ -315,7 +315,7 @@ impl Provider where { let desc = match self.transactions_for_signing.read().get(&private_hash) { None => { // Not our transaction, broadcast further to peers - self.broadcast_signed_private_transaction(signed_tx.hash(), signed_tx.rlp_bytes().into_vec()); + self.broadcast_signed_private_transaction(signed_tx.hash(), signed_tx.rlp_bytes()); return Ok(()); }, Some(desc) => desc, diff --git a/ethcore/res/ethereum/foundation.json b/ethcore/res/ethereum/foundation.json index dd508eae677..6d2b53f2a68 100644 --- a/ethcore/res/ethereum/foundation.json +++ b/ethcore/res/ethereum/foundation.json @@ -9,7 +9,8 @@ "durationLimit": "0x0d", "blockReward": { "0": "0x4563918244F40000", - "4370000": "0x29A2241AF62C0000" + "4370000": "0x29A2241AF62C0000", + "7080000": "0x1BC16D674EC80000" }, "homesteadTransition": "0x118c30", "daoHardforkTransition": "0x1d4c00", @@ -134,7 +135,8 @@ ], "eip100bTransition": 4370000, "difficultyBombDelays": { - "4370000": 3000000 + "4370000": 3000000, + "7080000": 2000000 } } } @@ -159,7 +161,11 @@ "eip140Transition": 4370000, "eip211Transition": 4370000, "eip214Transition": 4370000, - "eip658Transition": 4370000 + "eip658Transition": 4370000, + "eip145Transition": 7080000, + "eip1014Transition": 7080000, + "eip1052Transition": 7080000, + "eip1283Transition": 7080000 }, "genesis": { "seal": { diff --git a/ethcore/src/account_db.rs b/ethcore/src/account_db.rs index dd05d22cbc6..c028beeb1cf 100644 --- a/ethcore/src/account_db.rs +++ b/ethcore/src/account_db.rs @@ -58,7 +58,7 @@ impl Default for Factory { impl Factory { /// Create a read-only accountdb. /// This will panic when write operations are called. - pub fn readonly<'db>(&self, db: &'db HashDB, address_hash: H256) -> Box + 'db> { + pub fn readonly<'db>(&self, db: &'db HashDB, address_hash: H256) -> Box + 'db> { match *self { Factory::Mangled => Box::new(AccountDB::from_hash(db, address_hash)), Factory::Plain => Box::new(Wrapping(db)), @@ -66,7 +66,7 @@ impl Factory { } /// Create a new mutable hashdb. - pub fn create<'db>(&self, db: &'db mut HashDB, address_hash: H256) -> Box + 'db> { + pub fn create<'db>(&self, db: &'db mut HashDB, address_hash: H256) -> Box + 'db> { match *self { Factory::Mangled => Box::new(AccountDBMut::from_hash(db, address_hash)), Factory::Plain => Box::new(WrappingMut(db)), @@ -78,19 +78,19 @@ impl Factory { /// DB backend wrapper for Account trie /// Transforms trie node keys for the database pub struct AccountDB<'db> { - db: &'db HashDB, + db: &'db HashDB, address_hash: H256, } impl<'db> AccountDB<'db> { /// Create a new AccountDB from an address. #[cfg(test)] - pub fn new(db: &'db HashDB, address: &Address) -> Self { + pub fn new(db: &'db HashDB, address: &Address) -> Self { Self::from_hash(db, keccak(address)) } /// Create a new AcountDB from an address' hash. - pub fn from_hash(db: &'db HashDB, address_hash: H256) -> Self { + pub fn from_hash(db: &'db HashDB, address_hash: H256) -> Self { AccountDB { db: db, address_hash: address_hash, @@ -98,12 +98,12 @@ impl<'db> AccountDB<'db> { } } -impl<'db> AsHashDB for AccountDB<'db> { - fn as_hashdb(&self) -> &HashDB { self } - fn as_hashdb_mut(&mut self) -> &mut HashDB { self } +impl<'db> AsHashDB for AccountDB<'db> { + fn as_hashdb(&self) -> &HashDB { self } + fn as_hashdb_mut(&mut self) -> &mut HashDB { self } } -impl<'db> HashDB for AccountDB<'db> { +impl<'db> HashDB for AccountDB<'db> { fn keys(&self) -> HashMap { unimplemented!() } @@ -137,19 +137,19 @@ impl<'db> HashDB for AccountDB<'db> { /// DB backend wrapper for Account trie pub struct AccountDBMut<'db> { - db: &'db mut HashDB, + db: &'db mut HashDB, address_hash: H256, } impl<'db> AccountDBMut<'db> { /// Create a new AccountDB from an address. #[cfg(test)] - pub fn new(db: &'db mut HashDB, address: &Address) -> Self { + pub fn new(db: &'db mut HashDB, address: &Address) -> Self { Self::from_hash(db, keccak(address)) } /// Create a new AcountDB from an address' hash. - pub fn from_hash(db: &'db mut HashDB, address_hash: H256) -> Self { + pub fn from_hash(db: &'db mut HashDB, address_hash: H256) -> Self { AccountDBMut { db: db, address_hash: address_hash, @@ -162,7 +162,7 @@ impl<'db> AccountDBMut<'db> { } } -impl<'db> HashDB for AccountDBMut<'db>{ +impl<'db> HashDB for AccountDBMut<'db>{ fn keys(&self) -> HashMap { unimplemented!() } @@ -208,19 +208,19 @@ impl<'db> HashDB for AccountDBMut<'db>{ } } -impl<'db> AsHashDB for AccountDBMut<'db> { - fn as_hashdb(&self) -> &HashDB { self } - fn as_hashdb_mut(&mut self) -> &mut HashDB { self } +impl<'db> AsHashDB for AccountDBMut<'db> { + fn as_hashdb(&self) -> &HashDB { self } + fn as_hashdb_mut(&mut self) -> &mut HashDB { self } } -struct Wrapping<'db>(&'db HashDB); +struct Wrapping<'db>(&'db HashDB); -impl<'db> AsHashDB for Wrapping<'db> { - fn as_hashdb(&self) -> &HashDB { self } - fn as_hashdb_mut(&mut self) -> &mut HashDB { self } +impl<'db> AsHashDB for Wrapping<'db> { + fn as_hashdb(&self) -> &HashDB { self } + fn as_hashdb_mut(&mut self) -> &mut HashDB { self } } -impl<'db> HashDB for Wrapping<'db> { +impl<'db> HashDB for Wrapping<'db> { fn keys(&self) -> HashMap { unimplemented!() } @@ -252,13 +252,13 @@ impl<'db> HashDB for Wrapping<'db> { } } -struct WrappingMut<'db>(&'db mut HashDB); -impl<'db> AsHashDB for WrappingMut<'db> { - fn as_hashdb(&self) -> &HashDB { self } - fn as_hashdb_mut(&mut self) -> &mut HashDB { self } +struct WrappingMut<'db>(&'db mut HashDB); +impl<'db> AsHashDB for WrappingMut<'db> { + fn as_hashdb(&self) -> &HashDB { self } + fn as_hashdb_mut(&mut self) -> &mut HashDB { self } } -impl<'db> HashDB for WrappingMut<'db>{ +impl<'db> HashDB for WrappingMut<'db>{ fn keys(&self) -> HashMap { unimplemented!() } diff --git a/ethcore/src/blockchain/blockchain.rs b/ethcore/src/blockchain/blockchain.rs index d9448286f1f..5785aa10343 100644 --- a/ethcore/src/blockchain/blockchain.rs +++ b/ethcore/src/blockchain/blockchain.rs @@ -160,11 +160,6 @@ pub trait BlockProvider { .and_then(|n| body.view().localized_transaction_at(&address.block_hash, n, address.index))) } - /// Get transaction receipt. - fn transaction_receipt(&self, address: &TransactionAddress) -> Option { - self.block_receipts(&address.block_hash).and_then(|br| br.receipts.into_iter().nth(address.index)) - } - /// Get a list of transactions for a given block. /// Returns None if block does not exist. fn transactions(&self, hash: &H256) -> Option> { diff --git a/ethcore/src/blockchain/generator.rs b/ethcore/src/blockchain/generator.rs index 44d4e038c5c..213b394fc9d 100644 --- a/ethcore/src/blockchain/generator.rs +++ b/ethcore/src/blockchain/generator.rs @@ -51,7 +51,7 @@ impl Block { #[inline] pub fn encoded(&self) -> encoded::Block { - encoded::Block::new(encode(self).into_vec()) + encoded::Block::new(encode(self)) } #[inline] diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 5b7fb3c8044..73c3cde90d3 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -1795,26 +1795,49 @@ impl BlockChainClient for Client { } fn transaction_receipt(&self, id: TransactionId) -> Option { + // NOTE Don't use block_receipts here for performance reasons + let address = self.transaction_address(id)?; + let hash = address.block_hash; let chain = self.chain.read(); - self.transaction_address(id) - .and_then(|address| chain.block_number(&address.block_hash).and_then(|block_number| { - let transaction = chain.block_body(&address.block_hash) - .and_then(|body| body.view().localized_transaction_at(&address.block_hash, block_number, address.index)); - - let previous_receipts = (0..address.index + 1) - .map(|index| { - let mut address = address.clone(); - address.index = index; - chain.transaction_receipt(&address) - }) - .collect(); - match (transaction, previous_receipts) { - (Some(transaction), Some(previous_receipts)) => { - Some(transaction_receipt(self.engine().machine(), transaction, previous_receipts)) - }, - _ => None, - } - })) + let number = chain.block_number(&hash)?; + let body = chain.block_body(&hash)?; + let mut receipts = chain.block_receipts(&hash)?.receipts; + receipts.truncate(address.index + 1); + + let transaction = body.view().localized_transaction_at(&hash, number, address.index)?; + let receipt = receipts.pop()?; + let gas_used = receipts.last().map_or_else(|| 0.into(), |r| r.gas_used); + let no_of_logs = receipts.into_iter().map(|receipt| receipt.logs.len()).sum::(); + + let receipt = transaction_receipt(self.engine().machine(), transaction, receipt, gas_used, no_of_logs); + Some(receipt) + } + + fn block_receipts(&self, id: BlockId) -> Option> { + let hash = self.block_hash(id)?; + + let chain = self.chain.read(); + let receipts = chain.block_receipts(&hash)?; + let number = chain.block_number(&hash)?; + let body = chain.block_body(&hash)?; + let engine = self.engine.clone(); + + let mut gas_used = 0.into(); + let mut no_of_logs = 0; + + Some(body + .view() + .localized_transactions(&hash, number) + .into_iter() + .zip(receipts.receipts) + .map(move |(transaction, receipt)| { + let result = transaction_receipt(engine.machine(), transaction, receipt, gas_used, no_of_logs); + gas_used = result.cumulative_gas_used; + no_of_logs += result.logs.len(); + result + }) + .collect() + ) } fn tree_route(&self, from: &H256, to: &H256) -> Option { @@ -1833,8 +1856,8 @@ impl BlockChainClient for Client { self.state_db.read().journal_db().state(hash) } - fn block_receipts(&self, hash: &H256) -> Option { - self.chain.read().block_receipts(hash).map(|receipts| ::rlp::encode(&receipts).into_vec()) + fn encoded_block_receipts(&self, hash: &H256) -> Option { + self.chain.read().block_receipts(hash).map(|receipts| ::rlp::encode(&receipts)) } fn queue_info(&self) -> BlockQueueInfo { @@ -2249,8 +2272,7 @@ impl ScheduleInfo for Client { } impl ImportSealedBlock for Client { - fn import_sealed_block(&self, block: SealedBlock) -> ImportResult { - let h = block.header().hash(); + fn import_sealed_block(&self, block: SealedBlock) -> EthcoreResult { let start = Instant::now(); let header = block.header().clone(); let route = { @@ -2396,16 +2418,14 @@ impl Drop for Client { /// Returns `LocalizedReceipt` given `LocalizedTransaction` /// and a vector of receipts from given block up to transaction index. -fn transaction_receipt(machine: &::machine::EthereumMachine, mut tx: LocalizedTransaction, mut receipts: Vec) -> LocalizedReceipt { - assert_eq!(receipts.len(), tx.transaction_index + 1, "All previous receipts are provided."); - +fn transaction_receipt( + machine: &::machine::EthereumMachine, + mut tx: LocalizedTransaction, + receipt: Receipt, + prior_gas_used: U256, + prior_no_of_logs: usize, +) -> LocalizedReceipt { let sender = tx.sender(); - let receipt = receipts.pop().expect("Current receipt is provided; qed"); - let prior_gas_used = match tx.transaction_index { - 0 => 0.into(), - i => receipts.get(i - 1).expect("All previous receipts are provided; qed").gas_used, - }; - let no_of_logs = receipts.into_iter().map(|receipt| receipt.logs.len()).sum::(); let transaction_hash = tx.hash(); let block_hash = tx.block_hash; let block_number = tx.block_number; @@ -2434,7 +2454,7 @@ fn transaction_receipt(machine: &::machine::EthereumMachine, mut tx: LocalizedTr transaction_hash: transaction_hash, transaction_index: transaction_index, transaction_log_index: i, - log_index: no_of_logs + i, + log_index: prior_no_of_logs + i, }).collect(), log_bloom: receipt.log_bloom, outcome: receipt.outcome, @@ -2482,6 +2502,33 @@ mod tests { assert!(client.tree_route(&genesis, &new_hash).is_none()); } + #[test] + fn should_return_block_receipts() { + use client::{BlockChainClient, BlockId, TransactionId}; + use test_helpers::{generate_dummy_client_with_data}; + + let client = generate_dummy_client_with_data(2, 2, &[1.into(), 1.into()]); + let receipts = client.block_receipts(BlockId::Latest).unwrap(); + + assert_eq!(receipts.len(), 2); + assert_eq!(receipts[0].transaction_index, 0); + assert_eq!(receipts[0].block_number, 2); + assert_eq!(receipts[0].cumulative_gas_used, 53_000.into()); + assert_eq!(receipts[0].gas_used, 53_000.into()); + + assert_eq!(receipts[1].transaction_index, 1); + assert_eq!(receipts[1].block_number, 2); + assert_eq!(receipts[1].cumulative_gas_used, 106_000.into()); + assert_eq!(receipts[1].gas_used, 53_000.into()); + + + let receipt = client.transaction_receipt(TransactionId::Hash(receipts[0].transaction_hash)); + assert_eq!(receipt, Some(receipts[0].clone())); + + let receipt = client.transaction_receipt(TransactionId::Hash(receipts[1].transaction_hash)); + assert_eq!(receipt, Some(receipts[1].clone())); + } + #[test] fn should_return_correct_log_index() { use hash::keccak; @@ -2525,20 +2572,15 @@ mod tests { topics: vec![], data: vec![], }]; - let receipts = vec![Receipt { - outcome: TransactionOutcome::StateRoot(state_root), - gas_used: 5.into(), - log_bloom: Default::default(), - logs: vec![logs[0].clone()], - }, Receipt { + let receipt = Receipt { outcome: TransactionOutcome::StateRoot(state_root), gas_used: gas_used, log_bloom: Default::default(), logs: logs.clone(), - }]; + }; // when - let receipt = transaction_receipt(&machine, transaction, receipts); + let receipt = transaction_receipt(&machine, transaction, receipt, 5.into(), 1); // then assert_eq!(receipt, LocalizedReceipt { diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index 09f00515e84..9dac15439ce 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -686,6 +686,10 @@ impl BlockChainClient for TestBlockChainClient { self.receipts.read().get(&id).cloned() } + fn block_receipts(&self, _id: BlockId) -> Option> { + Some(self.receipts.read().values().cloned().collect()) + } + fn logs(&self, filter: Filter) -> Result, BlockId> { match self.error_on_logs.read().as_ref() { Some(id) => return Err(id.clone()), @@ -785,7 +789,7 @@ impl BlockChainClient for TestBlockChainClient { None } - fn block_receipts(&self, hash: &H256) -> Option { + fn encoded_block_receipts(&self, hash: &H256) -> Option { // starts with 'f' ? if *hash > H256::from("f000000000000000000000000000000000000000000000000000000000000000") { let receipt = BlockReceipts::new(vec![Receipt::new( diff --git a/ethcore/src/client/traits.rs b/ethcore/src/client/traits.rs index 719fce91644..4341cee49b4 100644 --- a/ethcore/src/client/traits.rs +++ b/ethcore/src/client/traits.rs @@ -42,7 +42,7 @@ use engines::EthEngine; use ethereum_types::{H256, U256, Address}; use ethcore_miner::pool::VerifiedTransaction; use bytes::Bytes; -use hashdb::DBValue; +use kvdb::DBValue; use types::ids::*; use types::basic_account::BasicAccount; @@ -281,6 +281,9 @@ pub trait BlockChainClient : Sync + Send + AccountData + BlockChain + CallContra /// Get transaction receipt with given hash. fn transaction_receipt(&self, id: TransactionId) -> Option; + /// Get localized receipts for all transaction in given block. + fn block_receipts(&self, id: BlockId) -> Option>; + /// Get a tree route between `from` and `to`. /// See `BlockChain::tree_route`. fn tree_route(&self, from: &H256, to: &H256) -> Option; @@ -292,7 +295,7 @@ pub trait BlockChainClient : Sync + Send + AccountData + BlockChain + CallContra fn state_data(&self, hash: &H256) -> Option; /// Get raw block receipts data by block header hash. - fn block_receipts(&self, hash: &H256) -> Option; + fn encoded_block_receipts(&self, hash: &H256) -> Option; /// Get block queue information. fn queue_info(&self) -> BlockQueueInfo; diff --git a/ethcore/src/engines/authority_round/mod.rs b/ethcore/src/engines/authority_round/mod.rs index 094c85b067b..caa50a57581 100644 --- a/ethcore/src/engines/authority_round/mod.rs +++ b/ethcore/src/engines/authority_round/mod.rs @@ -80,6 +80,8 @@ pub struct AuthorityRoundParams { pub empty_steps_transition: u64, /// Number of accepted empty steps. pub maximum_empty_steps: usize, + /// Transition block to strict empty steps validation. + pub strict_empty_steps_transition: u64, } const U16_MAX: usize = ::std::u16::MAX as usize; @@ -109,6 +111,7 @@ impl From for AuthorityRoundParams { maximum_uncle_count: p.maximum_uncle_count.map_or(0, Into::into), empty_steps_transition: p.empty_steps_transition.map_or(u64::max_value(), |n| ::std::cmp::max(n.into(), 1)), maximum_empty_steps: p.maximum_empty_steps.map_or(0, Into::into), + strict_empty_steps_transition: p.strict_empty_steps_transition.map_or(0, Into::into), } } } @@ -420,6 +423,7 @@ pub struct AuthorityRound { maximum_uncle_count_transition: u64, maximum_uncle_count: usize, empty_steps_transition: u64, + strict_empty_steps_transition: u64, maximum_empty_steps: usize, machine: EthereumMachine, } @@ -673,6 +677,7 @@ impl AuthorityRound { maximum_uncle_count: our_params.maximum_uncle_count, empty_steps_transition: our_params.empty_steps_transition, maximum_empty_steps: our_params.maximum_empty_steps, + strict_empty_steps_transition: our_params.strict_empty_steps_transition, machine: machine, }); @@ -1011,7 +1016,7 @@ impl Engine for AuthorityRound { let empty_steps_rlp = if header.number() >= self.empty_steps_transition { let empty_steps: Vec<_> = empty_steps.iter().map(|e| e.sealed()).collect(); - Some(::rlp::encode_list(&empty_steps).into_vec()) + Some(::rlp::encode_list(&empty_steps)) } else { None }; @@ -1033,8 +1038,8 @@ impl Engine for AuthorityRound { } let mut fields = vec![ - encode(&step).into_vec(), - encode(&(&H520::from(signature) as &[u8])).into_vec(), + encode(&step), + encode(&(&H520::from(signature) as &[u8])), ]; if let Some(empty_steps_rlp) = empty_steps_rlp { @@ -1186,8 +1191,11 @@ impl Engine for AuthorityRound { // reported as there's no way to tell whether the empty step message was never sent or simply not included. let empty_steps_len = if header.number() >= self.empty_steps_transition { let validate_empty_steps = || -> Result { + let strict_empty_steps = header.number() >= self.strict_empty_steps_transition; let empty_steps = header_empty_steps(header)?; let empty_steps_len = empty_steps.len(); + let mut prev_empty_step = 0; + for empty_step in empty_steps { if empty_step.step <= parent_step || empty_step.step >= step { Err(EngineError::InsufficientProof( @@ -1203,7 +1211,20 @@ impl Engine for AuthorityRound { Err(EngineError::InsufficientProof( format!("invalid empty step proof: {:?}", empty_step)))?; } + + if strict_empty_steps { + if empty_step.step <= prev_empty_step { + Err(EngineError::InsufficientProof(format!( + "{} empty step: {:?}", + if empty_step.step == prev_empty_step { "duplicate" } else { "unordered" }, + empty_step + )))?; + } + + prev_empty_step = empty_step.step; + } } + Ok(empty_steps_len) }; @@ -1459,10 +1480,40 @@ mod tests { use spec::Spec; use transaction::{Action, Transaction}; use engines::{Seal, Engine, EngineError, EthEngine}; - use engines::validator_set::TestSet; + use engines::validator_set::{TestSet, SimpleList}; use error::{Error, ErrorKind}; use super::{AuthorityRoundParams, AuthorityRound, EmptyStep, SealedEmptyStep, calculate_score}; + fn aura(f: F) -> Arc where + F: FnOnce(&mut AuthorityRoundParams), + { + let mut params = AuthorityRoundParams { + step_duration: 1, + start_step: Some(1), + validators: Box::new(TestSet::default()), + validate_score_transition: 0, + validate_step_transition: 0, + immediate_transitions: true, + maximum_uncle_count_transition: 0, + maximum_uncle_count: 0, + empty_steps_transition: u64::max_value(), + maximum_empty_steps: 0, + block_reward: Default::default(), + block_reward_contract_transition: 0, + block_reward_contract: Default::default(), + strict_empty_steps_transition: 0, + }; + + // mutate aura params + f(&mut params); + + // create engine + let mut c_params = ::spec::CommonParams::default(); + c_params.gas_limit_bound_divisor = 5.into(); + let machine = ::machine::EthereumMachine::regular(c_params, Default::default()); + AuthorityRound::new(params, machine).unwrap() + } + #[test] fn has_valid_metadata() { let engine = Spec::new_test_round().engine; @@ -1481,7 +1532,7 @@ mod tests { fn can_do_signature_verification_fail() { let engine = Spec::new_test_round().engine; let mut header: Header = Header::default(); - header.set_seal(vec![encode(&H520::default()).into_vec()]); + header.set_seal(vec![encode(&H520::default())]); let verify_result = engine.verify_block_external(&header); assert!(verify_result.is_err()); @@ -1558,7 +1609,7 @@ mod tests { let tap = AccountProvider::transient_provider(); let addr = tap.insert_account(keccak("0").into(), &"0".into()).unwrap(); let mut parent_header: Header = Header::default(); - parent_header.set_seal(vec![encode(&0usize).into_vec()]); + parent_header.set_seal(vec![encode(&0usize)]); parent_header.set_gas_limit("222222".parse::().unwrap()); let mut header: Header = Header::default(); header.set_number(1); @@ -1571,12 +1622,12 @@ mod tests { // Spec starts with step 2. header.set_difficulty(calculate_score(0, 2, 0)); let signature = tap.sign(addr, Some("0".into()), header.bare_hash()).unwrap(); - header.set_seal(vec![encode(&2usize).into_vec(), encode(&(&*signature as &[u8])).into_vec()]); + header.set_seal(vec![encode(&2usize), encode(&(&*signature as &[u8]))]); assert!(engine.verify_block_family(&header, &parent_header).is_ok()); assert!(engine.verify_block_external(&header).is_err()); header.set_difficulty(calculate_score(0, 1, 0)); let signature = tap.sign(addr, Some("0".into()), header.bare_hash()).unwrap(); - header.set_seal(vec![encode(&1usize).into_vec(), encode(&(&*signature as &[u8])).into_vec()]); + header.set_seal(vec![encode(&1usize), encode(&(&*signature as &[u8]))]); assert!(engine.verify_block_family(&header, &parent_header).is_ok()); assert!(engine.verify_block_external(&header).is_ok()); } @@ -1587,7 +1638,7 @@ mod tests { let addr = tap.insert_account(keccak("0").into(), &"0".into()).unwrap(); let mut parent_header: Header = Header::default(); - parent_header.set_seal(vec![encode(&0usize).into_vec()]); + parent_header.set_seal(vec![encode(&0usize)]); parent_header.set_gas_limit("222222".parse::().unwrap()); let mut header: Header = Header::default(); header.set_number(1); @@ -1600,10 +1651,10 @@ mod tests { // Spec starts with step 2. header.set_difficulty(calculate_score(0, 1, 0)); let signature = tap.sign(addr, Some("0".into()), header.bare_hash()).unwrap(); - header.set_seal(vec![encode(&1usize).into_vec(), encode(&(&*signature as &[u8])).into_vec()]); + header.set_seal(vec![encode(&1usize), encode(&(&*signature as &[u8]))]); assert!(engine.verify_block_family(&header, &parent_header).is_ok()); assert!(engine.verify_block_external(&header).is_ok()); - header.set_seal(vec![encode(&5usize).into_vec(), encode(&(&*signature as &[u8])).into_vec()]); + header.set_seal(vec![encode(&5usize), encode(&(&*signature as &[u8]))]); assert!(engine.verify_block_basic(&header).is_err()); } @@ -1613,7 +1664,7 @@ mod tests { let addr = tap.insert_account(keccak("0").into(), &"0".into()).unwrap(); let mut parent_header: Header = Header::default(); - parent_header.set_seal(vec![encode(&4usize).into_vec()]); + parent_header.set_seal(vec![encode(&4usize)]); parent_header.set_gas_limit("222222".parse::().unwrap()); let mut header: Header = Header::default(); header.set_number(1); @@ -1625,10 +1676,10 @@ mod tests { let signature = tap.sign(addr, Some("0".into()), header.bare_hash()).unwrap(); // Two validators. // Spec starts with step 2. - header.set_seal(vec![encode(&5usize).into_vec(), encode(&(&*signature as &[u8])).into_vec()]); + header.set_seal(vec![encode(&5usize), encode(&(&*signature as &[u8]))]); header.set_difficulty(calculate_score(4, 5, 0)); assert!(engine.verify_block_family(&header, &parent_header).is_ok()); - header.set_seal(vec![encode(&3usize).into_vec(), encode(&(&*signature as &[u8])).into_vec()]); + header.set_seal(vec![encode(&3usize), encode(&(&*signature as &[u8]))]); header.set_difficulty(calculate_score(4, 3, 0)); assert!(engine.verify_block_family(&header, &parent_header).is_err()); } @@ -1636,36 +1687,17 @@ mod tests { #[test] fn reports_skipped() { let last_benign = Arc::new(AtomicUsize::new(0)); - let params = AuthorityRoundParams { - step_duration: 1, - start_step: Some(1), - validators: Box::new(TestSet::new(Default::default(), last_benign.clone())), - validate_score_transition: 0, - validate_step_transition: 0, - immediate_transitions: true, - maximum_uncle_count_transition: 0, - maximum_uncle_count: 0, - empty_steps_transition: u64::max_value(), - maximum_empty_steps: 0, - block_reward: Default::default(), - block_reward_contract_transition: 0, - block_reward_contract: Default::default(), - }; - - let aura = { - let mut c_params = ::spec::CommonParams::default(); - c_params.gas_limit_bound_divisor = 5.into(); - let machine = ::machine::EthereumMachine::regular(c_params, Default::default()); - AuthorityRound::new(params, machine).unwrap() - }; + let aura = aura(|p| { + p.validators = Box::new(TestSet::new(Default::default(), last_benign.clone())); + }); let mut parent_header: Header = Header::default(); - parent_header.set_seal(vec![encode(&1usize).into_vec()]); + parent_header.set_seal(vec![encode(&1usize)]); parent_header.set_gas_limit("222222".parse::().unwrap()); let mut header: Header = Header::default(); header.set_difficulty(calculate_score(1, 3, 0)); header.set_gas_limit("222222".parse::().unwrap()); - header.set_seal(vec![encode(&3usize).into_vec()]); + header.set_seal(vec![encode(&3usize)]); // Do not report when signer not present. assert!(aura.verify_block_family(&header, &parent_header).is_ok()); @@ -1686,29 +1718,9 @@ mod tests { #[test] fn test_uncles_transition() { - let last_benign = Arc::new(AtomicUsize::new(0)); - let params = AuthorityRoundParams { - step_duration: 1, - start_step: Some(1), - validators: Box::new(TestSet::new(Default::default(), last_benign.clone())), - validate_score_transition: 0, - validate_step_transition: 0, - immediate_transitions: true, - maximum_uncle_count_transition: 1, - maximum_uncle_count: 0, - empty_steps_transition: u64::max_value(), - maximum_empty_steps: 0, - block_reward: Default::default(), - block_reward_contract_transition: 0, - block_reward_contract: Default::default(), - }; - - let aura = { - let mut c_params = ::spec::CommonParams::default(); - c_params.gas_limit_bound_divisor = 5.into(); - let machine = ::machine::EthereumMachine::regular(c_params, Default::default()); - AuthorityRound::new(params, machine).unwrap() - }; + let aura = aura(|params| { + params.maximum_uncle_count_transition = 1; + }); assert_eq!(aura.maximum_uncle_count(0), 2); assert_eq!(aura.maximum_uncle_count(1), 0); @@ -1742,27 +1754,9 @@ mod tests { #[test] #[should_panic(expected="authority_round: step duration can't be zero")] fn test_step_duration_zero() { - let last_benign = Arc::new(AtomicUsize::new(0)); - let params = AuthorityRoundParams { - step_duration: 0, - start_step: Some(1), - validators: Box::new(TestSet::new(Default::default(), last_benign.clone())), - validate_score_transition: 0, - validate_step_transition: 0, - immediate_transitions: true, - maximum_uncle_count_transition: 0, - maximum_uncle_count: 0, - empty_steps_transition: u64::max_value(), - maximum_empty_steps: 0, - block_reward: Default::default(), - block_reward_contract_transition: 0, - block_reward_contract: Default::default(), - }; - - let mut c_params = ::spec::CommonParams::default(); - c_params.gas_limit_bound_divisor = 5.into(); - let machine = ::machine::EthereumMachine::regular(c_params, Default::default()); - AuthorityRound::new(params, machine).unwrap(); + aura(|params| { + params.step_duration = 0; + }); } fn setup_empty_steps() -> (Spec, Arc, Vec
) { @@ -1790,6 +1784,23 @@ mod tests { SealedEmptyStep { signature, step } } + fn set_empty_steps_seal(header: &mut Header, step: u64, block_signature: ðkey::Signature, empty_steps: &[SealedEmptyStep]) { + header.set_seal(vec![ + encode(&(step as usize)), + encode(&(&**block_signature as &[u8])), + ::rlp::encode_list(&empty_steps), + ]); + } + + fn assert_insufficient_proof(result: Result, contains: &str) { + match result { + Err(Error(ErrorKind::Engine(EngineError::InsufficientProof(ref s)), _)) =>{ + assert!(s.contains(contains), "Expected {:?} to contain {:?}", s, contains); + }, + e => assert!(false, "Unexpected result: {:?}", e), + } + } + #[test] fn broadcast_empty_step_message() { let (spec, tap, accounts) = setup_empty_steps(); @@ -1816,7 +1827,7 @@ mod tests { assert_eq!(engine.generate_seal(b1.block(), &genesis_header), Seal::None); // spec starts with step 2 - let empty_step_rlp = encode(&empty_step(engine, 2, &genesis_header.hash())).into_vec(); + let empty_step_rlp = encode(&empty_step(engine, 2, &genesis_header.hash())); // we've received the message assert!(notify.messages.read().contains(&empty_step_rlp)); @@ -1874,8 +1885,8 @@ mod tests { let empty_step2 = sealed_empty_step(engine, 2, &genesis_header.hash()); let empty_steps = ::rlp::encode_list(&vec![empty_step2]); - assert_eq!(seal[0], encode(&3usize).into_vec()); - assert_eq!(seal[2], empty_steps.into_vec()); + assert_eq!(seal[0], encode(&3usize)); + assert_eq!(seal[2], empty_steps); } } @@ -1928,8 +1939,8 @@ mod tests { let empty_steps = ::rlp::encode_list(&vec![empty_step2, empty_step3]); - assert_eq!(seal[0], encode(&4usize).into_vec()); - assert_eq!(seal[2], empty_steps.into_vec()); + assert_eq!(seal[0], encode(&4usize)); + assert_eq!(seal[2], empty_steps); } } @@ -1978,7 +1989,7 @@ mod tests { let engine = &*spec.engine; let mut parent_header: Header = Header::default(); - parent_header.set_seal(vec![encode(&0usize).into_vec()]); + parent_header.set_seal(vec![encode(&0usize)]); parent_header.set_gas_limit("222222".parse::().unwrap()); let mut header: Header = Header::default(); @@ -1991,46 +2002,31 @@ mod tests { // empty step with invalid step let empty_steps = vec![SealedEmptyStep { signature: 0.into(), step: 2 }]; - header.set_seal(vec![ - encode(&2usize).into_vec(), - encode(&(&*signature as &[u8])).into_vec(), - ::rlp::encode_list(&empty_steps).into_vec(), - ]); + set_empty_steps_seal(&mut header, 2, &signature, &empty_steps); - assert!(match engine.verify_block_family(&header, &parent_header) { - Err(Error(ErrorKind::Engine(EngineError::InsufficientProof(ref s)), _)) - if s.contains("invalid step") => true, - _ => false, - }); + assert_insufficient_proof( + engine.verify_block_family(&header, &parent_header), + "invalid step" + ); // empty step with invalid signature let empty_steps = vec![SealedEmptyStep { signature: 0.into(), step: 1 }]; - header.set_seal(vec![ - encode(&2usize).into_vec(), - encode(&(&*signature as &[u8])).into_vec(), - ::rlp::encode_list(&empty_steps).into_vec(), - ]); + set_empty_steps_seal(&mut header, 2, &signature, &empty_steps); - assert!(match engine.verify_block_family(&header, &parent_header) { - Err(Error(ErrorKind::Engine(EngineError::InsufficientProof(ref s)), _)) - if s.contains("invalid empty step proof") => true, - _ => false, - }); + assert_insufficient_proof( + engine.verify_block_family(&header, &parent_header), + "invalid empty step proof" + ); // empty step with valid signature from incorrect proposer for step engine.set_signer(tap.clone(), addr1, "1".into()); let empty_steps = vec![sealed_empty_step(engine, 1, &parent_header.hash())]; - header.set_seal(vec![ - encode(&2usize).into_vec(), - encode(&(&*signature as &[u8])).into_vec(), - ::rlp::encode_list(&empty_steps).into_vec(), - ]); + set_empty_steps_seal(&mut header, 2, &signature, &empty_steps); - assert!(match engine.verify_block_family(&header, &parent_header) { - Err(Error(ErrorKind::Engine(EngineError::InsufficientProof(ref s)), _)) - if s.contains("invalid empty step proof") => true, - _ => false, - }); + assert_insufficient_proof( + engine.verify_block_family(&header, &parent_header), + "invalid empty step proof" + ); // valid empty steps engine.set_signer(tap.clone(), addr1, "1".into()); @@ -2041,11 +2037,7 @@ mod tests { let empty_steps = vec![empty_step2, empty_step3]; header.set_difficulty(calculate_score(0, 4, 2)); let signature = tap.sign(addr1, Some("1".into()), header.bare_hash()).unwrap(); - header.set_seal(vec![ - encode(&4usize).into_vec(), - encode(&(&*signature as &[u8])).into_vec(), - ::rlp::encode_list(&empty_steps).into_vec(), - ]); + set_empty_steps_seal(&mut header, 4, &signature, &empty_steps); assert!(engine.verify_block_family(&header, &parent_header).is_ok()); } @@ -2157,28 +2149,11 @@ mod tests { #[test] fn test_empty_steps() { - let last_benign = Arc::new(AtomicUsize::new(0)); - let params = AuthorityRoundParams { - step_duration: 4, - start_step: Some(1), - validators: Box::new(TestSet::new(Default::default(), last_benign.clone())), - validate_score_transition: 0, - validate_step_transition: 0, - immediate_transitions: true, - maximum_uncle_count_transition: 0, - maximum_uncle_count: 0, - empty_steps_transition: 0, - maximum_empty_steps: 10, - block_reward: Default::default(), - block_reward_contract_transition: 0, - block_reward_contract: Default::default(), - }; - - let mut c_params = ::spec::CommonParams::default(); - c_params.gas_limit_bound_divisor = 5.into(); - let machine = ::machine::EthereumMachine::regular(c_params, Default::default()); - let engine = AuthorityRound::new(params, machine).unwrap(); - + let engine = aura(|p| { + p.step_duration = 4; + p.empty_steps_transition = 0; + p.maximum_empty_steps = 0; + }); let parent_hash: H256 = 1.into(); let signature = H520::default(); @@ -2202,4 +2177,85 @@ mod tests { assert_eq!(engine.empty_steps(0, 3, parent_hash), vec![]); assert_eq!(engine.empty_steps(0, 4, parent_hash), vec![step(3)]); } + + #[test] + fn should_reject_duplicate_empty_steps() { + // given + let (_spec, tap, accounts) = setup_empty_steps(); + let engine = aura(|p| { + p.validators = Box::new(SimpleList::new(accounts.clone())); + p.step_duration = 4; + p.empty_steps_transition = 0; + p.maximum_empty_steps = 0; + }); + + let mut parent = Header::default(); + parent.set_seal(vec![encode(&0usize)]); + + let mut header = Header::default(); + header.set_number(parent.number() + 1); + header.set_parent_hash(parent.hash()); + header.set_author(accounts[0]); + + // when + engine.set_signer(tap.clone(), accounts[1], "0".into()); + let empty_steps = vec![ + sealed_empty_step(&*engine, 1, &parent.hash()), + sealed_empty_step(&*engine, 1, &parent.hash()), + ]; + let step = 2; + let signature = tap.sign(accounts[0], Some("1".into()), header.bare_hash()).unwrap(); + set_empty_steps_seal(&mut header, step, &signature, &empty_steps); + header.set_difficulty(calculate_score(0, step, empty_steps.len())); + + // then + assert_insufficient_proof( + engine.verify_block_family(&header, &parent), + "duplicate empty step" + ); + } + + #[test] + fn should_reject_empty_steps_out_of_order() { + // given + let (_spec, tap, accounts) = setup_empty_steps(); + let engine = aura(|p| { + p.validators = Box::new(SimpleList::new(accounts.clone())); + p.step_duration = 4; + p.empty_steps_transition = 0; + p.maximum_empty_steps = 0; + }); + + let mut parent = Header::default(); + parent.set_seal(vec![encode(&0usize)]); + + let mut header = Header::default(); + header.set_number(parent.number() + 1); + header.set_parent_hash(parent.hash()); + header.set_author(accounts[0]); + + // when + engine.set_signer(tap.clone(), accounts[1], "0".into()); + let es1 = sealed_empty_step(&*engine, 1, &parent.hash()); + engine.set_signer(tap.clone(), accounts[0], "1".into()); + let es2 = sealed_empty_step(&*engine, 2, &parent.hash()); + + let mut empty_steps = vec![es2, es1]; + + let step = 3; + let signature = tap.sign(accounts[1], Some("0".into()), header.bare_hash()).unwrap(); + set_empty_steps_seal(&mut header, step, &signature, &empty_steps); + header.set_difficulty(calculate_score(0, step, empty_steps.len())); + + // then make sure it's rejected because of the order + assert_insufficient_proof( + engine.verify_block_family(&header, &parent), + "unordered empty step" + ); + + // now try to fix the order + empty_steps.reverse(); + set_empty_steps_seal(&mut header, step, &signature, &empty_steps); + assert_eq!(engine.verify_block_family(&header, &parent).unwrap(), ()); + } } diff --git a/ethcore/src/engines/basic_authority.rs b/ethcore/src/engines/basic_authority.rs index e73b1046192..58eb5ea225f 100644 --- a/ethcore/src/engines/basic_authority.rs +++ b/ethcore/src/engines/basic_authority.rs @@ -110,7 +110,7 @@ impl Engine for BasicAuthority { if self.validators.contains(header.parent_hash(), author) { // account should be pernamently unlocked, otherwise sealing will fail if let Ok(signature) = self.sign(header.bare_hash()) { - return Seal::Regular(vec![::rlp::encode(&(&H520::from(signature) as &[u8])).into_vec()]); + return Seal::Regular(vec![::rlp::encode(&(&H520::from(signature) as &[u8]))]); } else { trace!(target: "basicauthority", "generate_seal: FAIL: accounts secret key unavailable"); } @@ -234,7 +234,7 @@ mod tests { fn can_do_signature_verification_fail() { let engine = new_test_authority().engine; let mut header: Header = Header::default(); - header.set_seal(vec![::rlp::encode(&H520::default()).into_vec()]); + header.set_seal(vec![::rlp::encode(&H520::default())]); let verify_result = engine.verify_block_external(&header); assert!(verify_result.is_err()); diff --git a/ethcore/src/engines/instant_seal.rs b/ethcore/src/engines/instant_seal.rs index c1b5de4ab5d..5a4eaa642ef 100644 --- a/ethcore/src/engines/instant_seal.rs +++ b/ethcore/src/engines/instant_seal.rs @@ -120,7 +120,7 @@ mod tests { assert!(engine.verify_block_basic(&header).is_ok()); - header.set_seal(vec![::rlp::encode(&H520::default()).into_vec()]); + header.set_seal(vec![::rlp::encode(&H520::default())]); assert!(engine.verify_block_unordered(&header).is_ok()); } diff --git a/ethcore/src/engines/tendermint/message.rs b/ethcore/src/engines/tendermint/message.rs index 7d76c32a275..137148667de 100644 --- a/ethcore/src/engines/tendermint/message.rs +++ b/ethcore/src/engines/tendermint/message.rs @@ -231,7 +231,7 @@ mod tests { }, block_hash: Some(keccak("1")), }; - let raw_rlp = ::rlp::encode(&message).into_vec(); + let raw_rlp = ::rlp::encode(&message); let rlp = Rlp::new(&raw_rlp); assert_eq!(Ok(message), rlp.as_val()); @@ -268,8 +268,8 @@ mod tests { fn proposal_message() { let mut header = Header::default(); let seal = vec![ - ::rlp::encode(&0u8).into_vec(), - ::rlp::encode(&H520::default()).into_vec(), + ::rlp::encode(&0u8), + ::rlp::encode(&H520::default()), Vec::new() ]; diff --git a/ethcore/src/engines/tendermint/mod.rs b/ethcore/src/engines/tendermint/mod.rs index 70d78147e42..d4a76e430a3 100644 --- a/ethcore/src/engines/tendermint/mod.rs +++ b/ethcore/src/engines/tendermint/mod.rs @@ -407,9 +407,9 @@ impl Tendermint { let precommits = self.votes.round_signatures(vote_step, &bh); trace!(target: "engine", "Collected seal: {:?}", precommits); let seal = vec![ - ::rlp::encode(&vote_step.view).into_vec(), + ::rlp::encode(&vote_step.view), ::rlp::NULL_RLP.to_vec(), - ::rlp::encode_list(&precommits).into_vec() + ::rlp::encode_list(&precommits) ]; self.submit_seal(bh, seal); self.votes.throw_out_old(&vote_step); @@ -491,8 +491,8 @@ impl Engine for Tendermint { *self.proposal.write() = bh; *self.proposal_parent.write() = header.parent_hash().clone(); Seal::Proposal(vec![ - ::rlp::encode(&view).into_vec(), - ::rlp::encode(&signature).into_vec(), + ::rlp::encode(&view), + ::rlp::encode(&signature), ::rlp::EMPTY_LIST_RLP.to_vec() ]) } else { @@ -520,7 +520,7 @@ impl Engine for Tendermint { self.broadcast_message(rlp.as_raw().to_vec()); if let Some(double) = self.votes.vote(message.clone(), sender) { let height = message.vote_step.height as BlockNumber; - self.validators.report_malicious(&sender, height, height, ::rlp::encode(&double).into_vec()); + self.validators.report_malicious(&sender, height, height, ::rlp::encode(&double)); return Err(EngineError::DoubleVote(sender)); } trace!(target: "engine", "Handling a valid {:?} from {}.", message, sender); @@ -823,8 +823,8 @@ mod tests { let vote_info = message_info_rlp(&VoteStep::new(header.number() as Height, view, Step::Propose), Some(header.bare_hash())); let signature = tap.sign(*author, None, keccak(vote_info)).unwrap(); vec![ - ::rlp::encode(&view).into_vec(), - ::rlp::encode(&H520::from(signature)).into_vec(), + ::rlp::encode(&view), + ::rlp::encode(&H520::from(signature)), ::rlp::EMPTY_LIST_RLP.to_vec() ] } @@ -928,7 +928,7 @@ mod tests { let signature1 = tap.sign(proposer, None, keccak(&vote_info)).unwrap(); seal[1] = ::rlp::NULL_RLP.to_vec(); - seal[2] = ::rlp::encode_list(&vec![H520::from(signature1.clone())]).into_vec(); + seal[2] = ::rlp::encode_list(&vec![H520::from(signature1.clone())]); header.set_seal(seal.clone()); // One good signature is not enough. @@ -940,7 +940,7 @@ mod tests { let voter = insert_and_unlock(&tap, "0"); let signature0 = tap.sign(voter, None, keccak(&vote_info)).unwrap(); - seal[2] = ::rlp::encode_list(&vec![H520::from(signature1.clone()), H520::from(signature0.clone())]).into_vec(); + seal[2] = ::rlp::encode_list(&vec![H520::from(signature1.clone()), H520::from(signature0.clone())]); header.set_seal(seal.clone()); assert!(engine.verify_block_external(&header).is_ok()); @@ -948,7 +948,7 @@ mod tests { let bad_voter = insert_and_unlock(&tap, "101"); let bad_signature = tap.sign(bad_voter, None, keccak(vote_info)).unwrap(); - seal[2] = ::rlp::encode_list(&vec![H520::from(signature1), H520::from(bad_signature)]).into_vec(); + seal[2] = ::rlp::encode_list(&vec![H520::from(signature1), H520::from(bad_signature)]); header.set_seal(seal); // One good and one bad signature. @@ -1084,7 +1084,7 @@ mod tests { let signature0 = tap.sign(voter, None, keccak(&vote_info)).unwrap(); seal[1] = ::rlp::NULL_RLP.to_vec(); - seal[2] = ::rlp::encode_list(&vec![H520::from(signature1.clone())]).into_vec(); + seal[2] = ::rlp::encode_list(&vec![H520::from(signature1.clone())]); header.set_seal(seal.clone()); let epoch_verifier = super::EpochVerifier { @@ -1112,7 +1112,7 @@ mod tests { _ => panic!(), } - seal[2] = ::rlp::encode_list(&vec![H520::from(signature1.clone()), H520::from(signature0.clone())]).into_vec(); + seal[2] = ::rlp::encode_list(&vec![H520::from(signature1.clone()), H520::from(signature0.clone())]); header.set_seal(seal.clone()); assert!(epoch_verifier.verify_light(&header).is_ok()); @@ -1120,7 +1120,7 @@ mod tests { let bad_voter = insert_and_unlock(&tap, "101"); let bad_signature = tap.sign(bad_voter, None, keccak(&vote_info)).unwrap(); - seal[2] = ::rlp::encode_list(&vec![H520::from(signature1), H520::from(bad_signature)]).into_vec(); + seal[2] = ::rlp::encode_list(&vec![H520::from(signature1), H520::from(bad_signature)]); header.set_seal(seal); // One good and one bad signature. diff --git a/ethcore/src/engines/validator_set/contract.rs b/ethcore/src/engines/validator_set/contract.rs index e4fcc83cb80..6529ca65bd2 100644 --- a/ethcore/src/engines/validator_set/contract.rs +++ b/ethcore/src/engines/validator_set/contract.rs @@ -174,7 +174,7 @@ mod tests { // Check a block that is a bit in future, reject it but don't report the validator. let mut header = Header::default(); - let seal = vec![encode(&4u8).into_vec(), encode(&(&H520::default() as &[u8])).into_vec()]; + let seal = vec![encode(&4u8), encode(&(&H520::default() as &[u8]))]; header.set_seal(seal); header.set_author(v1); header.set_number(2); @@ -185,7 +185,7 @@ mod tests { // Now create one that is more in future. That one should be rejected and validator should be reported. let mut header = Header::default(); - let seal = vec![encode(&8u8).into_vec(), encode(&(&H520::default() as &[u8])).into_vec()]; + let seal = vec![encode(&8u8), encode(&(&H520::default() as &[u8]))]; header.set_seal(seal); header.set_author(v1); header.set_number(2); diff --git a/ethcore/src/engines/validator_set/safe_contract.rs b/ethcore/src/engines/validator_set/safe_contract.rs index adaa63f0b42..1cc23e686ac 100644 --- a/ethcore/src/engines/validator_set/safe_contract.rs +++ b/ethcore/src/engines/validator_set/safe_contract.rs @@ -158,7 +158,7 @@ fn decode_first_proof(rlp: &Rlp) -> Result<(Header, Vec), ::error::Erro fn encode_proof(header: &Header, receipts: &[Receipt]) -> Bytes { let mut stream = RlpStream::new_list(2); stream.append(header).append_list(receipts); - stream.drain().into_vec() + stream.drain() } fn decode_proof(rlp: &Rlp) -> Result<(Header, Vec), ::error::Error> { diff --git a/ethcore/src/engines/validator_set/test.rs b/ethcore/src/engines/validator_set/test.rs index 6459803d191..9650526e577 100644 --- a/ethcore/src/engines/validator_set/test.rs +++ b/ethcore/src/engines/validator_set/test.rs @@ -34,12 +34,18 @@ pub struct TestSet { last_benign: Arc, } +impl Default for TestSet { + fn default() -> Self { + TestSet::new(Default::default(), Default::default()) + } +} + impl TestSet { pub fn new(last_malicious: Arc, last_benign: Arc) -> Self { TestSet { validator: SimpleList::new(vec![Address::from_str("7d577a597b2742b498cb5cf0c26cdcd726d39e6e").unwrap()]), - last_malicious: last_malicious, - last_benign: last_benign, + last_malicious, + last_benign, } } } diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index 3bb56315704..7fd578701cd 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -681,7 +681,7 @@ mod tests { fn can_do_difficulty_verification_fail() { let engine = test_spec().engine; let mut header: Header = Header::default(); - header.set_seal(vec![rlp::encode(&H256::zero()).into_vec(), rlp::encode(&H64::zero()).into_vec()]); + header.set_seal(vec![rlp::encode(&H256::zero()), rlp::encode(&H64::zero())]); let verify_result = engine.verify_block_basic(&header); @@ -696,7 +696,7 @@ mod tests { fn can_do_proof_of_work_verification_fail() { let engine = test_spec().engine; let mut header: Header = Header::default(); - header.set_seal(vec![rlp::encode(&H256::zero()).into_vec(), rlp::encode(&H64::zero()).into_vec()]); + header.set_seal(vec![rlp::encode(&H256::zero()), rlp::encode(&H64::zero())]); header.set_difficulty(U256::from_str("ffffffffffffffffffffffffffffffffffffffffffffaaaaaaaaaaaaaaaaaaaa").unwrap()); let verify_result = engine.verify_block_basic(&header); @@ -737,7 +737,7 @@ mod tests { fn can_do_seal256_verification_fail() { let engine = test_spec().engine; let mut header: Header = Header::default(); - header.set_seal(vec![rlp::encode(&H256::zero()).into_vec(), rlp::encode(&H64::zero()).into_vec()]); + header.set_seal(vec![rlp::encode(&H256::zero()), rlp::encode(&H64::zero())]); let verify_result = engine.verify_block_unordered(&header); match verify_result { @@ -751,7 +751,7 @@ mod tests { fn can_do_proof_of_work_unordered_verification_fail() { let engine = test_spec().engine; let mut header: Header = Header::default(); - header.set_seal(vec![rlp::encode(&H256::from("b251bd2e0283d0658f2cadfdc8ca619b5de94eca5742725e2e757dd13ed7503d")).into_vec(), rlp::encode(&H64::zero()).into_vec()]); + header.set_seal(vec![rlp::encode(&H256::from("b251bd2e0283d0658f2cadfdc8ca619b5de94eca5742725e2e757dd13ed7503d")), rlp::encode(&H64::zero())]); header.set_difficulty(U256::from_str("ffffffffffffffffffffffffffffffffffffffffffffaaaaaaaaaaaaaaaaaaaa").unwrap()); let verify_result = engine.verify_block_unordered(&header); @@ -944,7 +944,7 @@ mod tests { let tempdir = TempDir::new("").unwrap(); let ethash = Ethash::new(tempdir.path(), ethparams, machine, None); let mut header = Header::default(); - header.set_seal(vec![rlp::encode(&H256::from("b251bd2e0283d0658f2cadfdc8ca619b5de94eca5742725e2e757dd13ed7503d")).into_vec(), rlp::encode(&H64::zero()).into_vec()]); + header.set_seal(vec![rlp::encode(&H256::from("b251bd2e0283d0658f2cadfdc8ca619b5de94eca5742725e2e757dd13ed7503d")), rlp::encode(&H64::zero())]); let info = ethash.extra_info(&header); assert_eq!(info["nonce"], "0x0000000000000000"); assert_eq!(info["mixHash"], "0xb251bd2e0283d0658f2cadfdc8ca619b5de94eca5742725e2e757dd13ed7503d"); diff --git a/ethcore/src/header.rs b/ethcore/src/header.rs index 7896282fc27..100210b70bc 100644 --- a/ethcore/src/header.rs +++ b/ethcore/src/header.rs @@ -449,7 +449,7 @@ mod tests { let header_rlp = "f901f9a0d405da4e66f1445d455195229624e133f5baafe72b5cf7b3c36c12c8146e98b7a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a05fb2b4bfdef7b314451cb138a534d225c922fc0e5fbe25e451142732c3e25c25a088d2ec6b9860aae1a2c3b299f72b6a5d70d7f7ba4722c78f2c49ba96273c2158a007c6fdfa8eea7e86b81f5b0fc0f78f90cc19f4aa60d323151e0cac660199e9a1b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302008003832fefba82524d84568e932a80a0a0349d8c3df71f1a48a9df7d03fd5f14aeee7d91332c009ecaff0a71ead405bd88ab4e252a7e8c2a23".from_hex().unwrap(); let header: Header = rlp::decode(&header_rlp).expect("error decoding header"); - let encoded_header = rlp::encode(&header).into_vec(); + let encoded_header = rlp::encode(&header); assert_eq!(header_rlp, encoded_header); } diff --git a/ethcore/src/json_tests/trie.rs b/ethcore/src/json_tests/trie.rs index 0466c4de1f1..2d1f8d1fec3 100644 --- a/ethcore/src/json_tests/trie.rs +++ b/ethcore/src/json_tests/trie.rs @@ -20,6 +20,7 @@ use ethtrie::RlpCodec; use ethereum_types::H256; use memorydb::MemoryDB; use keccak_hasher::KeccakHasher; +use kvdb::DBValue; use super::HookType; @@ -36,7 +37,7 @@ fn test_trie(json: &[u8], trie: TrieSpec, start_stop_h for (name, test) in tests.into_iter() { start_stop_hook(&name, HookType::OnStart); - let mut memdb = MemoryDB::::new(); + let mut memdb = MemoryDB::::new(); let mut root = H256::default(); let mut t = factory.create(&mut memdb, &mut root); diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index 1a0d34b10b7..987d895ab04 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -50,7 +50,7 @@ use executive::contract_address; use header::{Header, BlockNumber}; use miner; use miner::pool_client::{PoolClient, CachedNonceClient, NonceCache}; -use receipt::{Receipt, RichReceipt}; +use receipt::RichReceipt; use spec::Spec; use state::State; use ethkey::Password; @@ -1039,19 +1039,17 @@ impl miner::MinerService for Miner { self.transaction_queue.status() } - fn pending_receipt(&self, best_block: BlockNumber, hash: &H256) -> Option { + fn pending_receipts(&self, best_block: BlockNumber) -> Option> { self.map_existing_pending_block(|pending| { - let txs = pending.transactions(); - txs.iter() - .map(|t| t.hash()) - .position(|t| t == *hash) - .map(|index| { - let receipts = pending.receipts(); + let receipts = pending.receipts(); + pending.transactions() + .into_iter() + .enumerate() + .map(|(index, tx)| { let prev_gas = if index == 0 { Default::default() } else { receipts[index - 1].gas_used }; - let tx = &txs[index]; let receipt = &receipts[index]; RichReceipt { - transaction_hash: hash.clone(), + transaction_hash: tx.hash(), transaction_index: index, cumulative_gas_used: receipt.gas_used, gas_used: receipt.gas_used - prev_gas, @@ -1067,15 +1065,7 @@ impl miner::MinerService for Miner { outcome: receipt.outcome.clone(), } }) - }, best_block).and_then(|x| x) - } - - fn pending_receipts(&self, best_block: BlockNumber) -> Option> { - self.map_existing_pending_block(|pending| { - let hashes = pending.transactions().iter().map(|t| t.hash()); - let receipts = pending.receipts().iter().cloned(); - - hashes.zip(receipts).collect() + .collect() }, best_block) } diff --git a/ethcore/src/miner/mod.rs b/ethcore/src/miner/mod.rs index cc56bf01f94..4ba1b036115 100644 --- a/ethcore/src/miner/mod.rs +++ b/ethcore/src/miner/mod.rs @@ -44,7 +44,7 @@ use client::{ }; use error::Error; use header::{BlockNumber, Header}; -use receipt::{RichReceipt, Receipt}; +use receipt::RichReceipt; use transaction::{self, UnverifiedTransaction, SignedTransaction, PendingTransaction}; use state::StateInfo; use ethkey::Password; @@ -95,10 +95,13 @@ pub trait MinerService : Send + Sync { // Pending block /// Get a list of all pending receipts from pending block. - fn pending_receipts(&self, best_block: BlockNumber) -> Option>; + fn pending_receipts(&self, best_block: BlockNumber) -> Option>; /// Get a particular receipt from pending block. - fn pending_receipt(&self, best_block: BlockNumber, hash: &H256) -> Option; + fn pending_receipt(&self, best_block: BlockNumber, hash: &H256) -> Option { + let receipts = self.pending_receipts(best_block)?; + receipts.into_iter().find(|r| &r.transaction_hash == hash) + } /// Get `Some` `clone()` of the current pending block's state or `None` if we're not sealing. fn pending_state(&self, latest_block_number: BlockNumber) -> Option; diff --git a/ethcore/src/miner/stratum.rs b/ethcore/src/miner/stratum.rs index 38c881bb1b3..65dc7d21358 100644 --- a/ethcore/src/miner/stratum.rs +++ b/ethcore/src/miner/stratum.rs @@ -138,7 +138,7 @@ impl JobDispatcher for StratumJobDispatcher { ); self.with_core_result(|client, miner| { - let seal = vec![encode(&payload.mix_hash).into_vec(), encode(&payload.nonce).into_vec()]; + let seal = vec![encode(&payload.mix_hash), encode(&payload.nonce)]; let import = miner.submit_seal(payload.pow_hash, seal) .and_then(|block| client.import_sealed_block(block)); diff --git a/ethcore/src/pod_account.rs b/ethcore/src/pod_account.rs index f35f0517780..33e84474eb6 100644 --- a/ethcore/src/pod_account.rs +++ b/ethcore/src/pod_account.rs @@ -20,6 +20,7 @@ use itertools::Itertools; use hash::{keccak}; use ethereum_types::{H256, U256}; use hashdb::HashDB; +use kvdb::DBValue; use keccak_hasher::KeccakHasher; use triehash::sec_trie_root; use bytes::Bytes; @@ -67,7 +68,7 @@ impl PodAccount { } /// Place additional data into given hash DB. - pub fn insert_additional(&self, db: &mut HashDB, factory: &TrieFactory) { + pub fn insert_additional(&self, db: &mut HashDB, factory: &TrieFactory) { match self.code { Some(ref c) if !c.is_empty() => { db.insert(c); } _ => {} diff --git a/ethcore/src/snapshot/account.rs b/ethcore/src/snapshot/account.rs index 13ab4b227ff..2ccf910f773 100644 --- a/ethcore/src/snapshot/account.rs +++ b/ethcore/src/snapshot/account.rs @@ -123,7 +123,7 @@ pub fn to_fat_rlps(account_hash: &H256, acc: &BasicAccount, acct_db: &AccountDB, let stream = ::std::mem::replace(&mut account_stream, RlpStream::new_list(2)); chunks.push(stream.out()); target_chunk_size = max_chunk_size; - leftover = Some(pair.into_vec()); + leftover = Some(pair); break; } }, diff --git a/ethcore/src/snapshot/mod.rs b/ethcore/src/snapshot/mod.rs index f05719e06b1..fbe6d6a166b 100644 --- a/ethcore/src/snapshot/mod.rs +++ b/ethcore/src/snapshot/mod.rs @@ -34,12 +34,11 @@ use ids::BlockId; use ethereum_types::{H256, U256}; use hashdb::HashDB; use keccak_hasher::KeccakHasher; -use kvdb::DBValue; use snappy; use bytes::Bytes; use parking_lot::Mutex; use journaldb::{self, Algorithm, JournalDB}; -use kvdb::KeyValueDB; +use kvdb::{KeyValueDB, DBValue}; use trie::{Trie, TrieMut}; use ethtrie::{TrieDB, TrieDBMut}; use rlp::{RlpStream, Rlp}; @@ -152,7 +151,7 @@ pub fn take_snapshot( engine: &EthEngine, chain: &BlockChain, block_at: H256, - state_db: &HashDB, + state_db: &HashDB, writer: W, p: &Progress, processing_threads: usize, @@ -322,7 +321,7 @@ impl<'a> StateChunker<'a> { /// /// Returns a list of hashes of chunks created, or any error it may /// have encountered. -pub fn chunk_state<'a>(db: &HashDB, root: &H256, writer: &Mutex, progress: &'a Progress, part: Option) -> Result, Error> { +pub fn chunk_state<'a>(db: &HashDB, root: &H256, writer: &Mutex, progress: &'a Progress, part: Option) -> Result, Error> { let account_trie = TrieDB::new(db, &root)?; let mut chunker = StateChunker { @@ -494,7 +493,7 @@ struct RebuiltStatus { // rebuild a set of accounts and their storage. // returns a status detailing newly-loaded code and accounts missing code. fn rebuild_accounts( - db: &mut HashDB, + db: &mut HashDB, account_fat_rlps: Rlp, out_chunk: &mut [(H256, Bytes)], known_code: &HashMap, @@ -541,7 +540,7 @@ fn rebuild_accounts( } } - ::rlp::encode(&acc).into_vec() + ::rlp::encode(&acc) }; *out = (hash, thin_rlp); diff --git a/ethcore/src/snapshot/tests/helpers.rs b/ethcore/src/snapshot/tests/helpers.rs index 19f50e94690..1bcbdb9f483 100644 --- a/ethcore/src/snapshot/tests/helpers.rs +++ b/ethcore/src/snapshot/tests/helpers.rs @@ -62,7 +62,7 @@ impl StateProducer { /// Tick the state producer. This alters the state, writing new data into /// the database. - pub fn tick(&mut self, rng: &mut R, db: &mut HashDB) { + pub fn tick(&mut self, rng: &mut R, db: &mut HashDB) { // modify existing accounts. let mut accounts_to_modify: Vec<_> = { let trie = TrieDB::new(&*db, &self.state_root).unwrap(); @@ -80,7 +80,7 @@ impl StateProducer { let mut account: BasicAccount = ::rlp::decode(&*account_data).expect("error decoding basic account"); let acct_db = AccountDBMut::from_hash(db, *address_hash); fill_storage(acct_db, &mut account.storage_root, &mut self.storage_seed); - *account_data = DBValue::from_vec(::rlp::encode(&account).into_vec()); + *account_data = DBValue::from_vec(::rlp::encode(&account)); } // sweep again to alter account trie. @@ -131,7 +131,7 @@ pub fn fill_storage(mut db: AccountDBMut, root: &mut H256, seed: &mut H256) { } /// Compare two state dbs. -pub fn compare_dbs(one: &HashDB, two: &HashDB) { +pub fn compare_dbs(one: &HashDB, two: &HashDB) { let keys = one.keys(); for key in keys.keys() { diff --git a/ethcore/src/state/account.rs b/ethcore/src/state/account.rs index a03312ca42f..160152fc70b 100644 --- a/ethcore/src/state/account.rs +++ b/ethcore/src/state/account.rs @@ -213,7 +213,7 @@ impl Account { /// Get (and cache) the contents of the trie's storage at `key`. /// Takes modified storage into account. - pub fn storage_at(&self, db: &HashDB, key: &H256) -> TrieResult { + pub fn storage_at(&self, db: &HashDB, key: &H256) -> TrieResult { if let Some(value) = self.cached_storage_at(key) { return Ok(value); } @@ -226,7 +226,7 @@ impl Account { /// Get (and cache) the contents of the trie's storage at `key`. /// Does not take modified storage into account. - pub fn original_storage_at(&self, db: &HashDB, key: &H256) -> TrieResult { + pub fn original_storage_at(&self, db: &HashDB, key: &H256) -> TrieResult { if let Some(value) = self.cached_original_storage_at(key) { return Ok(value); } @@ -248,7 +248,7 @@ impl Account { } } - fn get_and_cache_storage(storage_root: &H256, storage_cache: &mut LruCache, db: &HashDB, key: &H256) -> TrieResult { + fn get_and_cache_storage(storage_root: &H256, storage_cache: &mut LruCache, db: &HashDB, key: &H256) -> TrieResult { let db = SecTrieDB::new(db, storage_root)?; let panicky_decoder = |bytes:&[u8]| ::rlp::decode(&bytes).expect("decoding db value failed"); let item: U256 = db.get_with(key, panicky_decoder)?.unwrap_or_else(U256::zero); @@ -354,7 +354,7 @@ impl Account { /// Provide a database to get `code_hash`. Should not be called if it is a contract without code. Returns the cached code, if successful. #[must_use] - pub fn cache_code(&mut self, db: &HashDB) -> Option> { + pub fn cache_code(&mut self, db: &HashDB) -> Option> { // TODO: fill out self.code_cache; trace!("Account::cache_code: ic={}; self.code_hash={:?}, self.code_cache={}", self.is_cached(), self.code_hash, self.code_cache.pretty()); @@ -384,7 +384,7 @@ impl Account { /// Provide a database to get `code_size`. Should not be called if it is a contract without code. Returns whether /// the cache succeeds. #[must_use] - pub fn cache_code_size(&mut self, db: &HashDB) -> bool { + pub fn cache_code_size(&mut self, db: &HashDB) -> bool { // TODO: fill out self.code_cache; trace!("Account::cache_code_size: ic={}; self.code_hash={:?}, self.code_cache={}", self.is_cached(), self.code_hash, self.code_cache.pretty()); self.code_size.is_some() || @@ -473,7 +473,7 @@ impl Account { } /// Commit the `storage_changes` to the backing DB and update `storage_root`. - pub fn commit_storage(&mut self, trie_factory: &TrieFactory, db: &mut HashDB) -> TrieResult<()> { + pub fn commit_storage(&mut self, trie_factory: &TrieFactory, db: &mut HashDB) -> TrieResult<()> { let mut t = trie_factory.from_existing(db, &mut self.storage_root)?; for (k, v) in self.storage_changes.drain() { // cast key and value to trait type, @@ -490,7 +490,7 @@ impl Account { } /// Commit any unsaved code. `code_hash` will always return the hash of the `code_cache` after this. - pub fn commit_code(&mut self, db: &mut HashDB) { + pub fn commit_code(&mut self, db: &mut HashDB) { trace!("Commiting code of {:?} - {:?}, {:?}", self, self.code_filth == Filth::Dirty, self.code_cache.is_empty()); match (self.code_filth == Filth::Dirty, self.code_cache.is_empty()) { (true, true) => { @@ -579,7 +579,7 @@ impl Account { /// trie. /// `storage_key` is the hash of the desired storage key, meaning /// this will only work correctly under a secure trie. - pub fn prove_storage(&self, db: &HashDB, storage_key: H256) -> TrieResult<(Vec, H256)> { + pub fn prove_storage(&self, db: &HashDB, storage_key: H256) -> TrieResult<(Vec, H256)> { let mut recorder = Recorder::new(); let trie = TrieDB::new(db, &self.storage_root)?; diff --git a/ethcore/src/state/backend.rs b/ethcore/src/state/backend.rs index d07124d8d70..df364af9235 100644 --- a/ethcore/src/state/backend.rs +++ b/ethcore/src/state/backend.rs @@ -28,16 +28,17 @@ use state::Account; use parking_lot::Mutex; use ethereum_types::{Address, H256}; use memorydb::MemoryDB; -use hashdb::{AsHashDB, HashDB, DBValue}; +use hashdb::{AsHashDB, HashDB}; +use kvdb::DBValue; use keccak_hasher::KeccakHasher; /// State backend. See module docs for more details. pub trait Backend: Send { /// Treat the backend as a read-only hashdb. - fn as_hashdb(&self) -> &HashDB; + fn as_hashdb(&self) -> &HashDB; /// Treat the backend as a writeable hashdb. - fn as_hashdb_mut(&mut self) -> &mut HashDB; + fn as_hashdb_mut(&mut self) -> &mut HashDB; /// Add an account entry to the cache. fn add_to_account_cache(&mut self, addr: Address, data: Option, modified: bool); @@ -76,18 +77,18 @@ pub trait Backend: Send { // TODO: when account lookup moved into backends, this won't rely as tenuously on intended // usage. #[derive(Clone, PartialEq)] -pub struct ProofCheck(MemoryDB); +pub struct ProofCheck(MemoryDB); impl ProofCheck { /// Create a new `ProofCheck` backend from the given state items. pub fn new(proof: &[DBValue]) -> Self { - let mut db = MemoryDB::::new(); + let mut db = MemoryDB::::new(); for item in proof { db.insert(item); } ProofCheck(db) } } -impl HashDB for ProofCheck { +impl HashDB for ProofCheck { fn keys(&self) -> HashMap { self.0.keys() } fn get(&self, key: &H256) -> Option { self.0.get(key) @@ -108,14 +109,14 @@ impl HashDB for ProofCheck { fn remove(&mut self, _key: &H256) { } } -impl AsHashDB for ProofCheck { - fn as_hashdb(&self) -> &HashDB { self } - fn as_hashdb_mut(&mut self) -> &mut HashDB { self } +impl AsHashDB for ProofCheck { + fn as_hashdb(&self) -> &HashDB { self } + fn as_hashdb_mut(&mut self) -> &mut HashDB { self } } impl Backend for ProofCheck { - fn as_hashdb(&self) -> &HashDB { self } - fn as_hashdb_mut(&mut self) -> &mut HashDB { self } + fn as_hashdb(&self) -> &HashDB { self } + fn as_hashdb_mut(&mut self) -> &mut HashDB { self } fn add_to_account_cache(&mut self, _addr: Address, _data: Option, _modified: bool) {} fn cache_code(&self, _hash: H256, _code: Arc>) {} fn get_cached_account(&self, _addr: &Address) -> Option> { None } @@ -134,18 +135,18 @@ impl Backend for ProofCheck { /// The proof-of-execution can be extracted with `extract_proof`. /// /// This doesn't cache anything or rely on the canonical state caches. -pub struct Proving> { +pub struct Proving> { base: H, // state we're proving values from. - changed: MemoryDB, // changed state via insertions. + changed: MemoryDB, // changed state via insertions. proof: Mutex>, } -impl + Send + Sync> AsHashDB for Proving { - fn as_hashdb(&self) -> &HashDB { self } - fn as_hashdb_mut(&mut self) -> &mut HashDB { self } +impl + Send + Sync> AsHashDB for Proving { + fn as_hashdb(&self) -> &HashDB { self } + fn as_hashdb_mut(&mut self) -> &mut HashDB { self } } -impl + Send + Sync> HashDB for Proving { +impl + Send + Sync> HashDB for Proving { fn keys(&self) -> HashMap { let mut keys = self.base.as_hashdb().keys(); keys.extend(self.changed.keys()); @@ -182,10 +183,10 @@ impl + Send + Sync> HashDB for Proving + Send + Sync> Backend for Proving { - fn as_hashdb(&self) -> &HashDB { self } +impl + Send + Sync> Backend for Proving { + fn as_hashdb(&self) -> &HashDB { self } - fn as_hashdb_mut(&mut self) -> &mut HashDB { self } + fn as_hashdb_mut(&mut self) -> &mut HashDB { self } fn add_to_account_cache(&mut self, _: Address, _: Option, _: bool) { } @@ -204,13 +205,13 @@ impl + Send + Sync> Backend for Proving { fn is_known_null(&self, _: &Address) -> bool { false } } -impl> Proving { +impl> Proving { /// Create a new `Proving` over a base database. /// This will store all values ever fetched from that base. pub fn new(base: H) -> Self { Proving { base: base, - changed: MemoryDB::::new(), + changed: MemoryDB::::new(), proof: Mutex::new(HashSet::new()), } } @@ -222,7 +223,7 @@ impl> Proving { } } -impl + Clone> Clone for Proving { +impl + Clone> Clone for Proving { fn clone(&self) -> Self { Proving { base: self.base.clone(), @@ -236,12 +237,12 @@ impl + Clone> Clone for Proving { /// it. Doesn't cache anything. pub struct Basic(pub H); -impl + Send + Sync> Backend for Basic { - fn as_hashdb(&self) -> &HashDB { +impl + Send + Sync> Backend for Basic { + fn as_hashdb(&self) -> &HashDB { self.0.as_hashdb() } - fn as_hashdb_mut(&mut self) -> &mut HashDB { + fn as_hashdb_mut(&mut self) -> &mut HashDB { self.0.as_hashdb_mut() } diff --git a/ethcore/src/state/mod.rs b/ethcore/src/state/mod.rs index 197496d4c76..f1377e26645 100644 --- a/ethcore/src/state/mod.rs +++ b/ethcore/src/state/mod.rs @@ -227,7 +227,7 @@ pub fn check_proof( /// Prove a `virtual` transaction on the given state. /// Returns `None` when the transacion could not be proved, /// and a proof otherwise. -pub fn prove_transaction_virtual + Send + Sync>( +pub fn prove_transaction_virtual + Send + Sync>( db: H, root: H256, transaction: &SignedTransaction, @@ -618,7 +618,7 @@ impl State { &self, address: &Address, key: &H256, f_cached_at: FCachedStorageAt, f_at: FStorageAt, ) -> TrieResult where FCachedStorageAt: Fn(&Account, &H256) -> Option, - FStorageAt: Fn(&Account, &HashDB, &H256) -> TrieResult + FStorageAt: Fn(&Account, &HashDB, &H256) -> TrieResult { // Storage key search and update works like this: // 1. If there's an entry for the account in the local cache check for the key and return it if found. @@ -1014,7 +1014,7 @@ impl State { /// Load required account data from the databases. Returns whether the cache succeeds. #[must_use] - fn update_account_cache(require: RequireCache, account: &mut Account, state_db: &B, db: &HashDB) -> bool { + fn update_account_cache(require: RequireCache, account: &mut Account, state_db: &B, db: &HashDB) -> bool { if let RequireCache::None = require { return true; } diff --git a/ethcore/src/state_db.rs b/ethcore/src/state_db.rs index d614fe42f84..d103f1081aa 100644 --- a/ethcore/src/state_db.rs +++ b/ethcore/src/state_db.rs @@ -29,7 +29,7 @@ use hashdb::HashDB; use keccak_hasher::KeccakHasher; use header::BlockNumber; use journaldb::JournalDB; -use kvdb::{KeyValueDB, DBTransaction}; +use kvdb::{KeyValueDB, DBTransaction, DBValue}; use lru_cache::LruCache; use memory_cache::MemoryLruCache; use parking_lot::Mutex; @@ -312,12 +312,12 @@ impl StateDB { } /// Conversion method to interpret self as `HashDB` reference - pub fn as_hashdb(&self) -> &HashDB { + pub fn as_hashdb(&self) -> &HashDB { self.db.as_hashdb() } /// Conversion method to interpret self as mutable `HashDB` reference - pub fn as_hashdb_mut(&mut self) -> &mut HashDB { + pub fn as_hashdb_mut(&mut self) -> &mut HashDB { self.db.as_hashdb_mut() } @@ -412,9 +412,9 @@ impl StateDB { } impl state::Backend for StateDB { - fn as_hashdb(&self) -> &HashDB { self.db.as_hashdb() } + fn as_hashdb(&self) -> &HashDB { self.db.as_hashdb() } - fn as_hashdb_mut(&mut self) -> &mut HashDB { + fn as_hashdb_mut(&mut self) -> &mut HashDB { self.db.as_hashdb_mut() } diff --git a/ethcore/src/test_helpers.rs b/ethcore/src/test_helpers.rs index 06cfe703050..bf9ab020481 100644 --- a/ethcore/src/test_helpers.rs +++ b/ethcore/src/test_helpers.rs @@ -90,7 +90,7 @@ pub fn create_test_block_with_data(header: &Header, transactions: &[SignedTransa rlp.append(header); rlp.begin_list(transactions.len()); for t in transactions { - rlp.append_raw(&rlp::encode(t).into_vec(), 1); + rlp.append_raw(&rlp::encode(t), 1); } rlp.append_list(&uncles); rlp.out() diff --git a/ethcore/src/views/body.rs b/ethcore/src/views/body.rs index 6560140cad1..f1a30949b32 100644 --- a/ethcore/src/views/body.rs +++ b/ethcore/src/views/body.rs @@ -38,9 +38,9 @@ impl<'a> BodyView<'a> { /// ``` /// #[macro_use] /// extern crate ethcore; - /// + /// /// use ethcore::views::{BodyView}; - /// + /// /// fn main() { /// let bytes : &[u8] = &[]; /// let body_view = view!(BodyView, bytes); diff --git a/ethcore/sync/Cargo.toml b/ethcore/sync/Cargo.toml index 37c1d61c766..a736813a559 100644 --- a/ethcore/sync/Cargo.toml +++ b/ethcore/sync/Cargo.toml @@ -17,10 +17,10 @@ ethcore-light = { path = "../light" } ethcore-transaction = { path = "../transaction" } ethcore = { path = ".." } ethereum-types = "0.4" -hashdb = "0.2.1" -fastmap = { path = "../../util/fastmap" } -rlp = { version = "0.2.4", features = ["ethereum"] } rustc-hex = "1.0" +hashdb = "0.3.0" +fastmap = { path = "../../util/fastmap" } +rlp = { version = "0.3.0", features = ["ethereum"] } keccak-hash = "0.1" keccak-hasher = { path = "../../util/keccak-hasher" } triehash-ethereum = {version = "0.2", path = "../../util/triehash-ethereum" } diff --git a/ethcore/sync/src/api.rs b/ethcore/sync/src/api.rs index c55dee485d9..4296a4c2d07 100644 --- a/ethcore/sync/src/api.rs +++ b/ethcore/sync/src/api.rs @@ -541,7 +541,7 @@ struct TxRelay(Arc); impl LightHandler for TxRelay { fn on_transactions(&self, ctx: &EventContext, relay: &[::transaction::UnverifiedTransaction]) { trace!(target: "pip", "Relaying {} transactions from peer {}", relay.len(), ctx.peer()); - self.0.queue_transactions(relay.iter().map(|tx| ::rlp::encode(tx).into_vec()).collect(), 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 7cca71b026e..54fe63da424 100644 --- a/ethcore/sync/src/block_sync.rs +++ b/ethcore/sync/src/block_sync.rs @@ -800,7 +800,7 @@ mod tests { for i in 0..4 { // Construct the block body let mut uncles = if i > 0 { - encode_list(&[dummy_header(i - 1, H256::random())]).into_vec() + encode_list(&[dummy_header(i - 1, H256::random())]) } else { ::rlp::EMPTY_LIST_RLP.to_vec() }; diff --git a/ethcore/sync/src/chain/handler.rs b/ethcore/sync/src/chain/handler.rs index bbb3db3288e..e388920f640 100644 --- a/ethcore/sync/src/chain/handler.rs +++ b/ethcore/sync/src/chain/handler.rs @@ -772,9 +772,7 @@ mod tests { let block = Rlp::new(&block_data); - let result = SyncHandler::on_peer_new_block(&mut sync, &mut io, 0, &block); - - assert!(result.is_ok()); + SyncHandler::on_peer_new_block(&mut sync, &mut io, 0, &block).expect("result to be ok"); } #[test] diff --git a/ethcore/sync/src/chain/mod.rs b/ethcore/sync/src/chain/mod.rs index f5a0e30b8da..1a0f99b921d 100644 --- a/ethcore/sync/src/chain/mod.rs +++ b/ethcore/sync/src/chain/mod.rs @@ -1203,7 +1203,7 @@ pub mod tests { } pub fn get_dummy_blocks(order: u32, parent_hash: H256) -> Bytes { - let mut rlp = RlpStream::new_list(1); + let mut rlp = RlpStream::new_list(2); rlp.append_raw(&get_dummy_block(order, parent_hash), 1); let difficulty: U256 = (100 * order).into(); rlp.append(&difficulty); diff --git a/ethcore/sync/src/chain/supplier.rs b/ethcore/sync/src/chain/supplier.rs index e2113b0b1c2..201e0d9f35a 100644 --- a/ethcore/sync/src/chain/supplier.rs +++ b/ethcore/sync/src/chain/supplier.rs @@ -226,7 +226,7 @@ impl SyncSupplier { let mut added_receipts = 0usize; let mut data = Bytes::new(); for i in 0..count { - if let Some(mut receipts_bytes) = io.chain().block_receipts(&rlp.val_at::(i)?) { + if let Some(mut receipts_bytes) = io.chain().encoded_block_receipts(&rlp.val_at::(i)?) { data.append(&mut receipts_bytes); added_receipts += receipts_bytes.len(); added_headers += 1; diff --git a/ethcore/sync/src/light_sync/response.rs b/ethcore/sync/src/light_sync/response.rs index 161461c2a59..c3175d6e9d0 100644 --- a/ethcore/sync/src/light_sync/response.rs +++ b/ethcore/sync/src/light_sync/response.rs @@ -179,7 +179,7 @@ mod tests { parent_hash = Some(header.hash()); - encoded::Header::new(::rlp::encode(&header).into_vec()) + encoded::Header::new(::rlp::encode(&header)) }).collect(); assert!(verify(&headers, &request).is_ok()); @@ -205,7 +205,7 @@ mod tests { parent_hash = Some(header.hash()); - encoded::Header::new(::rlp::encode(&header).into_vec()) + encoded::Header::new(::rlp::encode(&header)) }).collect(); assert!(verify(&headers, &request).is_ok()); @@ -231,7 +231,7 @@ mod tests { parent_hash = Some(header.hash()); - encoded::Header::new(::rlp::encode(&header).into_vec()) + encoded::Header::new(::rlp::encode(&header)) }).collect(); assert_eq!(verify(&headers, &request), Err(BasicError::TooManyHeaders(20, 25))); @@ -250,7 +250,7 @@ mod tests { let mut header = Header::default(); header.set_number(x); - encoded::Header::new(::rlp::encode(&header).into_vec()) + encoded::Header::new(::rlp::encode(&header)) }).collect(); assert_eq!(verify(&headers, &request), Err(BasicError::WrongSkip(5, Some(2)))); diff --git a/ethcore/transaction/Cargo.toml b/ethcore/transaction/Cargo.toml index eaf562fcded..1481f87160c 100644 --- a/ethcore/transaction/Cargo.toml +++ b/ethcore/transaction/Cargo.toml @@ -10,7 +10,7 @@ ethkey = { path = "../../ethkey" } evm = { path = "../evm" } heapsize = "0.4" keccak-hash = "0.1" -rlp = { version = "0.2.4", features = ["ethereum"] } +rlp = { version = "0.3.0", features = ["ethereum"] } unexpected = { path = "../../util/unexpected" } ethereum-types = "0.4" diff --git a/ethcore/types/Cargo.toml b/ethcore/types/Cargo.toml index 75cf68ad11e..1833db871ce 100644 --- a/ethcore/types/Cargo.toml +++ b/ethcore/types/Cargo.toml @@ -5,7 +5,7 @@ version = "0.1.0" authors = ["Parity Technologies "] [dependencies] -rlp = { version = "0.2.4", features = ["ethereum"] } +rlp = { version = "0.3.0", features = ["ethereum"] } rlp_derive = { path = "../../util/rlp_derive" } parity-bytes = "0.1" ethereum-types = "0.4" diff --git a/ethcore/vm/Cargo.toml b/ethcore/vm/Cargo.toml index 4ea807089e4..20bbea09aec 100644 --- a/ethcore/vm/Cargo.toml +++ b/ethcore/vm/Cargo.toml @@ -7,10 +7,10 @@ authors = ["Parity Technologies "] byteorder = "1.0" parity-bytes = "0.1" ethereum-types = "0.4" -patricia-trie = "0.2" +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.2.4", features = ["ethereum"] } +rlp = { version = "0.3.0", features = ["ethereum"] } keccak-hash = "0.1" diff --git a/ipfs/Cargo.toml b/ipfs/Cargo.toml index 516694f5f91..f7d92c10ca1 100644 --- a/ipfs/Cargo.toml +++ b/ipfs/Cargo.toml @@ -11,7 +11,7 @@ parity-bytes = "0.1" ethereum-types = "0.4" jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.11" } jsonrpc-http-server = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.11" } -rlp = { version = "0.2.4", features = ["ethereum"] } +rlp = { version = "0.3.0", features = ["ethereum"] } cid = "0.2" multihash = "0.7" unicase = "2.0" diff --git a/ipfs/src/route.rs b/ipfs/src/route.rs index 8f57fc4d102..b004c8ebfcb 100644 --- a/ipfs/src/route.rs +++ b/ipfs/src/route.rs @@ -80,7 +80,7 @@ impl IpfsHandler { fn block_list(&self, hash: H256) -> Result { let uncles = self.client().find_uncles(&hash).ok_or(Error::BlockNotFound)?; - Ok(Out::OctetStream(rlp::encode_list(&uncles).into_vec())) + Ok(Out::OctetStream(rlp::encode_list(&uncles))) } /// Get transaction by hash and return as raw binary. @@ -88,7 +88,7 @@ impl IpfsHandler { let tx_id = TransactionId::Hash(hash); let tx = self.client().transaction(tx_id).ok_or(Error::TransactionNotFound)?; - Ok(Out::OctetStream(rlp::encode(&*tx).into_vec())) + Ok(Out::OctetStream(rlp::encode(&*tx))) } /// Get state trie node by hash and return as raw binary. diff --git a/json/src/spec/authority_round.rs b/json/src/spec/authority_round.rs index b4fcf4d78cb..444f0cbe9c4 100644 --- a/json/src/spec/authority_round.rs +++ b/json/src/spec/authority_round.rs @@ -67,6 +67,8 @@ pub struct AuthorityRoundParams { /// Maximum number of accepted empty steps. #[serde(rename="maximumEmptySteps")] pub maximum_empty_steps: Option, + /// Strict validation of empty steps transition block. + pub strict_empty_steps_transition: Option, } /// Authority engine deserialization. diff --git a/local-store/Cargo.toml b/local-store/Cargo.toml index 47edcc15b43..b92ba4cc43f 100644 --- a/local-store/Cargo.toml +++ b/local-store/Cargo.toml @@ -10,7 +10,7 @@ ethcore-io = { path = "../util/io" } ethcore-transaction = { path = "../ethcore/transaction" } kvdb = "0.1" log = "0.4" -rlp = { version = "0.2.4", features = ["ethereum"] } +rlp = { version = "0.3.0", features = ["ethereum"] } serde = "1.0" serde_derive = "1.0" serde_json = "1.0" diff --git a/local-store/src/lib.rs b/local-store/src/lib.rs index 13d238ed6ad..aa75ada8fc0 100644 --- a/local-store/src/lib.rs +++ b/local-store/src/lib.rs @@ -125,7 +125,7 @@ impl TransactionEntry { impl From for TransactionEntry { fn from(pending: PendingTransaction) -> Self { TransactionEntry { - rlp_bytes: ::rlp::encode(&pending.transaction).into_vec(), + rlp_bytes: ::rlp::encode(&pending.transaction), condition: pending.condition.map(Into::into), } } diff --git a/miner/Cargo.toml b/miner/Cargo.toml index d5839bf8208..f94d086e53d 100644 --- a/miner/Cargo.toml +++ b/miner/Cargo.toml @@ -27,7 +27,7 @@ linked-hash-map = "0.5" log = "0.4" parking_lot = "0.6" price-info = { path = "../price-info", optional = true } -rlp = { version = "0.2.4", features = ["ethereum"] } +rlp = { version = "0.3.0", features = ["ethereum"] } trace-time = "0.1" transaction-pool = "1.13" diff --git a/miner/src/pool/tests/mod.rs b/miner/src/pool/tests/mod.rs index 30a3e5130bd..2fc68d0ac71 100644 --- a/miner/src/pool/tests/mod.rs +++ b/miner/src/pool/tests/mod.rs @@ -26,12 +26,18 @@ pub mod client; use self::tx::{Tx, TxExt, PairExt}; use self::client::TestClient; +// max mem for 3 transaction, this is relative +// 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; + fn new_queue() -> TransactionQueue { TransactionQueue::new( txpool::Options { max_count: 3, max_per_sender: 3, - max_mem_usage: 50 + max_mem_usage: TEST_QUEUE_MAX_MEM }, verifier::Options { minimal_gas_price: 1.into(), @@ -49,7 +55,7 @@ fn should_return_correct_nonces_when_dropped_because_of_limit() { txpool::Options { max_count: 3, max_per_sender: 1, - max_mem_usage: 50 + max_mem_usage: TEST_QUEUE_MAX_MEM }, verifier::Options { minimal_gas_price: 1.into(), @@ -103,7 +109,7 @@ fn should_never_drop_local_transactions_from_different_senders() { txpool::Options { max_count: 3, max_per_sender: 1, - max_mem_usage: 50 + max_mem_usage: TEST_QUEUE_MAX_MEM }, verifier::Options { minimal_gas_price: 1.into(), @@ -477,7 +483,7 @@ fn should_prefer_current_transactions_when_hitting_the_limit() { txpool::Options { max_count: 1, max_per_sender: 2, - max_mem_usage: 50 + max_mem_usage: TEST_QUEUE_MAX_MEM }, verifier::Options { minimal_gas_price: 1.into(), @@ -707,7 +713,7 @@ fn should_accept_local_transactions_below_min_gas_price() { txpool::Options { max_count: 3, max_per_sender: 3, - max_mem_usage: 50 + max_mem_usage: TEST_QUEUE_MAX_MEM }, verifier::Options { minimal_gas_price: 10.into(), @@ -890,7 +896,7 @@ fn should_include_local_transaction_to_a_full_pool() { txpool::Options { max_count: 1, max_per_sender: 2, - max_mem_usage: 50 + max_mem_usage: TEST_QUEUE_MAX_MEM }, verifier::Options { minimal_gas_price: 1.into(), @@ -922,7 +928,7 @@ fn should_avoid_verifying_transaction_already_in_pool() { txpool::Options { max_count: 1, max_per_sender: 2, - max_mem_usage: 50 + max_mem_usage: TEST_QUEUE_MAX_MEM }, verifier::Options { minimal_gas_price: 1.into(), @@ -957,7 +963,7 @@ fn should_avoid_reverifying_recently_rejected_transactions() { txpool::Options { max_count: 1, max_per_sender: 2, - max_mem_usage: 50 + max_mem_usage: TEST_QUEUE_MAX_MEM }, verifier::Options { minimal_gas_price: 1.into(), @@ -999,7 +1005,7 @@ fn should_reject_early_in_case_gas_price_is_less_than_min_effective() { txpool::Options { max_count: 1, max_per_sender: 2, - max_mem_usage: 50 + max_mem_usage: TEST_QUEUE_MAX_MEM }, verifier::Options { minimal_gas_price: 1.into(), @@ -1039,7 +1045,7 @@ fn should_not_reject_early_in_case_gas_price_is_less_than_min_effective() { txpool::Options { max_count: 1, max_per_sender: 2, - max_mem_usage: 50 + max_mem_usage: TEST_QUEUE_MAX_MEM }, verifier::Options { minimal_gas_price: 1.into(), diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index 84568391f38..f2d31970499 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -58,8 +58,8 @@ keccak-hash = "0.1.2" parity-reactor = { path = "../util/reactor" } parity-updater = { path = "../updater" } parity-version = { path = "../util/version" } -patricia-trie = "0.2" -rlp = { version = "0.2.4", features = ["ethereum"] } +patricia-trie = "0.3.0" +rlp = { version = "0.3.0", features = ["ethereum"] } stats = { path = "../util/stats" } vm = { path = "../ethcore/vm" } diff --git a/rpc/src/v1/helpers/work.rs b/rpc/src/v1/helpers/work.rs new file mode 100644 index 00000000000..18047e546dc --- /dev/null +++ b/rpc/src/v1/helpers/work.rs @@ -0,0 +1,47 @@ +// 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 . + +//! Helpers for submit a POW work. + +use std::sync::Arc; + +use rlp; +use ethcore::miner::{BlockChainClient, MinerService}; +use ethereum_types::{H64 as EthcoreH64, H256 as EthcoreH256}; +use jsonrpc_core::Error; +use v1::types::{H64, H256}; +use v1::helpers::errors; + +// Submit a POW work and return the block's hash +pub fn submit_work_detail(client: &Arc, miner: &Arc, nonce: H64, pow_hash: H256, mix_hash: H256) -> Result { + // TODO [ToDr] Should disallow submissions in case of PoA? + let nonce: EthcoreH64 = nonce.into(); + let pow_hash: EthcoreH256 = pow_hash.into(); + let mix_hash: EthcoreH256 = mix_hash.into(); + trace!(target: "miner", "submit_work_detail: Decoded: nonce={}, pow_hash={}, mix_hash={}", nonce, pow_hash, mix_hash); + let seal = vec![rlp::encode(&mix_hash), rlp::encode(&nonce)]; + let import = miner.submit_seal(pow_hash, seal) + .and_then(|block| client.import_sealed_block(block)); + match import { + Ok(hash) => { + Ok(hash.into()) + }, + Err(err) => { + warn!(target: "miner", "Cannot submit work - {:?}.", err); + Err(errors::cannot_submit_work(err)) + }, + } +} diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index e19bfaa2975..6b9a553529f 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -29,7 +29,6 @@ use ethcore::account_provider::AccountProvider; use ethcore::client::{BlockChainClient, BlockId, TransactionId, UncleId, StateOrBlock, StateClient, StateInfo, Call, EngineInfo}; use ethcore::filter::Filter as EthcoreFilter; use ethcore::header::{BlockNumber as EthBlockNumber}; -use ethcore::log_entry::LogEntry; use ethcore::miner::{self, MinerService}; use ethcore::snapshot::SnapshotService; use ethcore::encoded; @@ -419,11 +418,11 @@ impl EthClient(miner: &M, best_block: EthBlockNumber, filter: &EthcoreFilter) -> Vec where M: MinerService { let receipts = miner.pending_receipts(best_block).unwrap_or_default(); - let pending_logs = receipts.into_iter() - .flat_map(|(hash, r)| r.logs.into_iter().map(|l| (hash.clone(), l)).collect::>()) - .collect::>(); - - pending_logs.into_iter() + receipts.into_iter() + .flat_map(|r| { + let hash = r.transaction_hash; + r.logs.into_iter().map(move |l| (hash, l)) + }) .filter(|pair| filter.matches(&pair.1)) .map(|pair| { let mut log = Log::from(pair.1); @@ -673,16 +672,17 @@ impl Eth for EthClient< } fn transaction_receipt(&self, hash: RpcH256) -> BoxFuture> { - let best_block = self.client.chain_info().best_block_number; let hash: H256 = hash.into(); - match (self.miner.pending_receipt(best_block, &hash), self.options.allow_pending_receipt_query) { - (Some(receipt), true) => Box::new(future::ok(Some(receipt.into()))), - _ => { - let receipt = self.client.transaction_receipt(TransactionId::Hash(hash)); - Box::new(future::ok(receipt.map(Into::into))) + if self.options.allow_pending_receipt_query { + let best_block = self.client.chain_info().best_block_number; + if let Some(receipt) = self.miner.pending_receipt(best_block, &hash) { + return Box::new(future::ok(Some(receipt.into()))); } } + + let receipt = self.client.transaction_receipt(TransactionId::Hash(hash)); + Box::new(future::ok(receipt.map(Into::into))) } fn uncle_by_block_hash_and_index(&self, hash: RpcH256, index: Index) -> BoxFuture> { @@ -795,7 +795,7 @@ impl Eth for EthClient< let mix_hash: H256 = mix_hash.into(); trace!(target: "miner", "submit_work: Decoded: nonce={}, pow_hash={}, mix_hash={}", nonce, pow_hash, mix_hash); - let seal = vec![rlp::encode(&mix_hash).into_vec(), rlp::encode(&nonce).into_vec()]; + let seal = vec![rlp::encode(&mix_hash).to_vec(), rlp::encode(&nonce).to_vec()]; let import = self.miner.submit_seal(pow_hash, seal) .and_then(|block| self.client.import_sealed_block(block)); diff --git a/rpc/src/v1/impls/light/eth.rs b/rpc/src/v1/impls/light/eth.rs index 67e2c72ab61..27c46759545 100644 --- a/rpc/src/v1/impls/light/eth.rs +++ b/rpc/src/v1/impls/light/eth.rs @@ -46,7 +46,7 @@ use v1::helpers::{SyncPollFilter, PollManager}; use v1::helpers::light_fetch::{self, LightFetch}; use v1::traits::Eth; use v1::types::{ - RichBlock, Block, BlockTransactions, BlockNumber, Bytes, SyncStatus, SyncInfo, + RichBlock, Block, BlockTransactions, BlockNumber, LightBlockNumber, Bytes, SyncStatus, SyncInfo, Transaction, CallRequest, Index, Filter, Log, Receipt, Work, H64 as RpcH64, H256 as RpcH256, H160 as RpcH160, U256 as RpcU256, }; @@ -67,23 +67,6 @@ pub struct EthClient { gas_price_percentile: usize, } -impl EthClient { - fn num_to_id(num: BlockNumber) -> BlockId { - // Note: Here we treat `Pending` as `Latest`. - // Since light clients don't produce pending blocks - // (they don't have state) we can safely fallback to `Latest`. - match num { - BlockNumber::Num(n) => BlockId::Number(n), - BlockNumber::Earliest => BlockId::Earliest, - BlockNumber::Latest => BlockId::Latest, - BlockNumber::Pending => { - warn!("`Pending` is deprecated and may be removed in future versions. Falling back to `Latest`"); - BlockId::Latest - } - } - } -} - impl Clone for EthClient { fn clone(&self) -> Self { // each instance should have its own poll manager. @@ -285,7 +268,7 @@ impl Eth for EthClient { } fn balance(&self, address: RpcH160, num: Trailing) -> BoxFuture { - Box::new(self.fetcher().account(address.into(), Self::num_to_id(num.unwrap_or_default())) + Box::new(self.fetcher().account(address.into(), num.unwrap_or_default().to_block_id()) .map(|acc| acc.map_or(0.into(), |a| a.balance).into())) } @@ -298,11 +281,11 @@ impl Eth for EthClient { } fn block_by_number(&self, num: BlockNumber, include_txs: bool) -> BoxFuture> { - Box::new(self.rich_block(Self::num_to_id(num), include_txs).map(Some)) + Box::new(self.rich_block(num.to_block_id(), include_txs).map(Some)) } fn transaction_count(&self, address: RpcH160, num: Trailing) -> BoxFuture { - Box::new(self.fetcher().account(address.into(), Self::num_to_id(num.unwrap_or_default())) + Box::new(self.fetcher().account(address.into(), num.unwrap_or_default().to_block_id()) .map(|acc| acc.map_or(0.into(), |a| a.nonce).into())) } @@ -325,7 +308,7 @@ impl Eth for EthClient { fn block_transaction_count_by_number(&self, num: BlockNumber) -> BoxFuture> { let (sync, on_demand) = (self.sync.clone(), self.on_demand.clone()); - Box::new(self.fetcher().header(Self::num_to_id(num)).and_then(move |hdr| { + Box::new(self.fetcher().header(num.to_block_id()).and_then(move |hdr| { if hdr.transactions_root() == KECCAK_NULL_RLP { Either::A(future::ok(Some(U256::from(0).into()))) } else { @@ -357,7 +340,7 @@ impl Eth for EthClient { fn block_uncles_count_by_number(&self, num: BlockNumber) -> BoxFuture> { let (sync, on_demand) = (self.sync.clone(), self.on_demand.clone()); - Box::new(self.fetcher().header(Self::num_to_id(num)).and_then(move |hdr| { + Box::new(self.fetcher().header(num.to_block_id()).and_then(move |hdr| { if hdr.uncles_hash() == KECCAK_EMPTY_LIST_RLP { Either::B(future::ok(Some(U256::from(0).into()))) } else { @@ -371,7 +354,7 @@ impl Eth for EthClient { } fn code_at(&self, address: RpcH160, num: Trailing) -> BoxFuture { - Box::new(self.fetcher().code(address.into(), Self::num_to_id(num.unwrap_or_default())).map(Into::into)) + Box::new(self.fetcher().code(address.into(), num.unwrap_or_default().to_block_id()).map(Into::into)) } fn send_raw_transaction(&self, raw: Bytes) -> Result { @@ -438,7 +421,7 @@ impl Eth for EthClient { } fn transaction_by_block_number_and_index(&self, num: BlockNumber, idx: Index) -> BoxFuture> { - Box::new(self.fetcher().block(Self::num_to_id(num)).map(move |block| { + Box::new(self.fetcher().block(num.to_block_id()).map(move |block| { light_fetch::extract_transaction_at_index(block, idx.value()) })) } @@ -482,7 +465,7 @@ impl Eth for EthClient { fn uncle_by_block_number_and_index(&self, num: BlockNumber, idx: Index) -> BoxFuture> { let client = self.client.clone(); - Box::new(self.fetcher().block(Self::num_to_id(num)).map(move |block| { + Box::new(self.fetcher().block(num.to_block_id()).map(move |block| { extract_uncle_at_index(block, idx, client) })) } diff --git a/rpc/src/v1/impls/light/parity.rs b/rpc/src/v1/impls/light/parity.rs index f74886e619f..4ab456e6836 100644 --- a/rpc/src/v1/impls/light/parity.rs +++ b/rpc/src/v1/impls/light/parity.rs @@ -26,7 +26,6 @@ use ethstore::random_phrase; use sync::LightSyncProvider; use ethcore::account_provider::AccountProvider; use ethcore_logger::RotatingLogger; -use ethcore::ids::BlockId; use light::client::LightChainClient; @@ -42,9 +41,9 @@ use v1::types::{ Bytes, U256, U64, H160, H256, H512, CallRequest, Peers, Transaction, RpcSettings, Histogram, TransactionStats, LocalTransactionStatus, - BlockNumber, ConsensusCapability, VersionInfo, + BlockNumber, LightBlockNumber, ConsensusCapability, VersionInfo, OperationsInfo, ChainStatus, - AccountInfo, HwAccountInfo, Header, RichHeader, + AccountInfo, HwAccountInfo, Header, RichHeader, Receipt, }; use Host; @@ -403,18 +402,15 @@ impl Parity for ParityClient { extra_info: extra_info, }) }; - // Note: Here we treat `Pending` as `Latest`. - // Since light clients don't produce pending blocks - // (they don't have state) we can safely fallback to `Latest`. - let id = match number.unwrap_or_default() { - BlockNumber::Num(n) => BlockId::Number(n), - BlockNumber::Earliest => BlockId::Earliest, - BlockNumber::Latest | BlockNumber::Pending => BlockId::Latest, - }; - + let id = number.unwrap_or_default().to_block_id(); Box::new(self.fetcher().header(id).and_then(from_encoded)) } + fn block_receipts(&self, number: Trailing) -> BoxFuture> { + let id = number.unwrap_or_default().to_block_id(); + Box::new(self.fetcher().receipts(id).and_then(|receipts| Ok(receipts.into_iter().map(Into::into).collect()))) + } + fn ipfs_cid(&self, content: Bytes) -> Result { ipfs::cid(content) } diff --git a/rpc/src/v1/impls/parity.rs b/rpc/src/v1/impls/parity.rs index 3e20d582141..bbf75411eae 100644 --- a/rpc/src/v1/impls/parity.rs +++ b/rpc/src/v1/impls/parity.rs @@ -45,7 +45,7 @@ use v1::types::{ TransactionStats, LocalTransactionStatus, BlockNumber, ConsensusCapability, VersionInfo, OperationsInfo, ChainStatus, - AccountInfo, HwAccountInfo, RichHeader, + AccountInfo, HwAccountInfo, RichHeader, Receipt, block_number_to_id }; use Host; @@ -332,7 +332,7 @@ impl Parity for ParityClient where fn ws_url(&self) -> Result { helpers::to_url(&self.ws_address) - .ok_or_else(|| errors::ws_disabled()) + .ok_or_else(errors::ws_disabled) } fn next_nonce(&self, address: H160) -> BoxFuture { @@ -387,7 +387,8 @@ impl Parity for ParityClient where let (header, extra) = if number == BlockNumber::Pending { let info = self.client.chain_info(); - let header = try_bf!(self.miner.pending_block_header(info.best_block_number).ok_or(errors::unknown_block())); + let header = + try_bf!(self.miner.pending_block_header(info.best_block_number).ok_or_else(errors::unknown_block)); (header.encoded(), None) } else { @@ -398,7 +399,7 @@ impl Parity for ParityClient where BlockNumber::Pending => unreachable!(), // Already covered }; - let header = try_bf!(self.client.block_header(id.clone()).ok_or(errors::unknown_block())); + let header = try_bf!(self.client.block_header(id.clone()).ok_or_else(errors::unknown_block)); let info = self.client.block_extra_info(id).expect(EXTRA_INFO_PROOF); (header, Some(info)) @@ -410,6 +411,27 @@ impl Parity for ParityClient where })) } + fn block_receipts(&self, number: Trailing) -> BoxFuture> { + let number = number.unwrap_or_default(); + + let id = match number { + BlockNumber::Pending => { + let info = self.client.chain_info(); + let receipts = try_bf!(self.miner.pending_receipts(info.best_block_number).ok_or_else(errors::unknown_block)); + return Box::new(future::ok(receipts + .into_iter() + .map(Into::into) + .collect() + )) + }, + BlockNumber::Num(num) => BlockId::Number(num), + BlockNumber::Earliest => BlockId::Earliest, + BlockNumber::Latest => BlockId::Latest, + }; + let receipts = try_bf!(self.client.block_receipts(id).ok_or_else(errors::unknown_block)); + Box::new(future::ok(receipts.into_iter().map(Into::into).collect())) + } + fn ipfs_cid(&self, content: Bytes) -> Result { ipfs::cid(content) } @@ -427,8 +449,8 @@ impl Parity for ParityClient where let (mut state, header) = if num == BlockNumber::Pending { let info = self.client.chain_info(); - let state = self.miner.pending_state(info.best_block_number).ok_or(errors::state_pruned())?; - let header = self.miner.pending_block_header(info.best_block_number).ok_or(errors::state_pruned())?; + let state = self.miner.pending_state(info.best_block_number).ok_or_else(errors::state_pruned)?; + let header = self.miner.pending_block_header(info.best_block_number).ok_or_else(errors::state_pruned)?; (state, header) } else { @@ -439,8 +461,8 @@ impl Parity for ParityClient where BlockNumber::Pending => unreachable!(), // Already covered }; - let state = self.client.state_at(id).ok_or(errors::state_pruned())?; - let header = self.client.block_header(id).ok_or(errors::state_pruned())?.decode().map_err(errors::decode)?; + let state = self.client.state_at(id).ok_or_else(errors::state_pruned)?; + let header = self.client.block_header(id).ok_or_else(errors::state_pruned)?.decode().map_err(errors::decode)?; (state, header) }; diff --git a/rpc/src/v1/impls/personal.rs b/rpc/src/v1/impls/personal.rs index 9def0244767..a83fff926a2 100644 --- a/rpc/src/v1/impls/personal.rs +++ b/rpc/src/v1/impls/personal.rs @@ -175,7 +175,7 @@ impl Personal for PersonalClient { .and_then(|(pending_tx, dispatcher)| { let chain_id = pending_tx.chain_id(); trace!(target: "miner", "send_transaction: dispatching tx: {} for chain ID {:?}", - ::rlp::encode(&*pending_tx).into_vec().pretty(), chain_id); + ::rlp::encode(&*pending_tx).pretty(), chain_id); dispatcher.dispatch_transaction(pending_tx).map(Into::into) }) diff --git a/rpc/src/v1/tests/helpers/miner_service.rs b/rpc/src/v1/tests/helpers/miner_service.rs index e26290e48eb..088b1d45ddb 100644 --- a/rpc/src/v1/tests/helpers/miner_service.rs +++ b/rpc/src/v1/tests/helpers/miner_service.rs @@ -28,7 +28,7 @@ use ethcore::error::Error; use ethcore::header::{BlockNumber, Header}; use ethcore::ids::BlockId; use ethcore::miner::{self, MinerService, AuthoringParams}; -use ethcore::receipt::{Receipt, RichReceipt}; +use ethcore::receipt::RichReceipt; use ethereum_types::{H256, U256, Address}; use miner::pool::local_transactions::Status as LocalTransactionStatus; use miner::pool::{verifier, VerifiedTransaction, QueueStatus}; @@ -46,7 +46,7 @@ pub struct TestMinerService { /// Pre-existed local transactions pub local_transactions: Mutex>, /// Pre-existed pending receipts - pub pending_receipts: Mutex>, + pub pending_receipts: Mutex>, /// Next nonces. pub next_nonces: RwLock>, /// Password held by Engine. @@ -58,11 +58,11 @@ pub struct TestMinerService { impl Default for TestMinerService { fn default() -> TestMinerService { TestMinerService { - imported_transactions: Mutex::new(Vec::new()), - pending_transactions: Mutex::new(HashMap::new()), - local_transactions: Mutex::new(BTreeMap::new()), - pending_receipts: Mutex::new(BTreeMap::new()), - next_nonces: RwLock::new(HashMap::new()), + imported_transactions: Default::default(), + pending_transactions: Default::default(), + local_transactions: Default::default(), + pending_receipts: Default::default(), + next_nonces: Default::default(), password: RwLock::new("".into()), authoring_params: RwLock::new(AuthoringParams { author: Address::zero(), @@ -230,23 +230,7 @@ impl MinerService for TestMinerService { }).collect() } - fn pending_receipt(&self, _best_block: BlockNumber, hash: &H256) -> Option { - // Not much point implementing this since the logic is complex and the only thing it relies on is pending_receipts, which is already tested. - self.pending_receipts(0).unwrap().get(hash).map(|r| - RichReceipt { - transaction_hash: Default::default(), - transaction_index: Default::default(), - cumulative_gas_used: r.gas_used.clone(), - gas_used: r.gas_used.clone(), - contract_address: None, - logs: r.logs.clone(), - log_bloom: r.log_bloom, - outcome: r.outcome.clone(), - } - ) - } - - fn pending_receipts(&self, _best_block: BlockNumber) -> Option> { + fn pending_receipts(&self, _best_block: BlockNumber) -> Option> { Some(self.pending_receipts.lock().clone()) } diff --git a/rpc/src/v1/tests/mocked/eth.rs b/rpc/src/v1/tests/mocked/eth.rs index 2bf8f50e240..ff364cf7f0c 100644 --- a/rpc/src/v1/tests/mocked/eth.rs +++ b/rpc/src/v1/tests/mocked/eth.rs @@ -981,7 +981,7 @@ fn rpc_eth_send_raw_transaction() { let signature = tester.accounts_provider.sign(address, None, t.hash(None)).unwrap(); let t = t.with_signature(signature, None); - let rlp = rlp::encode(&t).into_vec().to_hex(); + let rlp = rlp::encode(&t).to_hex(); let req = r#"{ "jsonrpc": "2.0", diff --git a/rpc/src/v1/tests/mocked/parity.rs b/rpc/src/v1/tests/mocked/parity.rs index 68251d30b9b..8ac8e44eb29 100644 --- a/rpc/src/v1/tests/mocked/parity.rs +++ b/rpc/src/v1/tests/mocked/parity.rs @@ -16,7 +16,8 @@ use std::sync::Arc; use ethcore::account_provider::AccountProvider; -use ethcore::client::{TestBlockChainClient, Executed}; +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}; @@ -531,3 +532,34 @@ fn rpc_parity_call() { assert_eq!(io.handle_request_sync(request), Some(response.to_owned())); } + +#[test] +fn rpc_parity_block_receipts() { + let deps = Dependencies::new(); + deps.client.receipts.write() + .insert(TransactionId::Hash(1.into()), LocalizedReceipt { + transaction_hash: 1.into(), + transaction_index: 0, + block_hash: 3.into(), + block_number: 0, + cumulative_gas_used: 21_000.into(), + gas_used: 21_000.into(), + contract_address: None, + logs: vec![], + log_bloom: 1.into(), + outcome: TransactionOutcome::Unknown, + to: None, + from: 9.into(), + }); + let io = deps.default_client(); + + let request = r#"{ + "jsonrpc": "2.0", + "method": "parity_getBlockReceipts", + "params": [], + "id": 1 + }"#; + let response = r#"{"jsonrpc":"2.0","result":[{"blockHash":"0x0000000000000000000000000000000000000000000000000000000000000003","blockNumber":"0x0","contractAddress":null,"cumulativeGasUsed":"0x5208","from":"0x0000000000000000000000000000000000000009","gasUsed":"0x5208","logs":[],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001","root":null,"status":null,"to":null,"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000001","transactionIndex":"0x0"}],"id":1}"#; + + assert_eq!(io.handle_request_sync(request), Some(response.to_owned())); +} diff --git a/rpc/src/v1/traits/parity.rs b/rpc/src/v1/traits/parity.rs index 76df05bbc64..c71e6d8dc6a 100644 --- a/rpc/src/v1/traits/parity.rs +++ b/rpc/src/v1/traits/parity.rs @@ -27,7 +27,7 @@ use v1::types::{ TransactionStats, LocalTransactionStatus, BlockNumber, ConsensusCapability, VersionInfo, OperationsInfo, ChainStatus, - AccountInfo, HwAccountInfo, RichHeader, + AccountInfo, HwAccountInfo, RichHeader, Receipt, }; build_rpc_trait! { @@ -211,6 +211,12 @@ build_rpc_trait! { #[rpc(name = "parity_getBlockHeaderByNumber")] fn block_header(&self, Trailing) -> BoxFuture; + /// Get block receipts. + /// Allows you to fetch receipts from the entire block at once. + /// If no parameter is provided defaults to `latest`. + #[rpc(name = "parity_getBlockReceipts")] + fn block_receipts(&self, Trailing) -> BoxFuture>; + /// Get IPFS CIDv0 given protobuf encoded bytes. #[rpc(name = "parity_cidV0")] fn ipfs_cid(&self, Bytes) -> Result; diff --git a/rpc/src/v1/types/block_number.rs b/rpc/src/v1/types/block_number.rs index b92a0d4a3fe..085886998e2 100644 --- a/rpc/src/v1/types/block_number.rs +++ b/rpc/src/v1/types/block_number.rs @@ -54,6 +54,31 @@ impl BlockNumber { } } +/// BlockNumber to BlockId conversion +/// +/// NOTE use only for light clients. +pub trait LightBlockNumber { + /// Convert block number to block id. + fn to_block_id(self) -> BlockId; +} + +impl LightBlockNumber for BlockNumber { + fn to_block_id(self) -> BlockId { + // NOTE Here we treat `Pending` as `Latest`. + // Since light clients don't produce pending blocks + // (they don't have state) we can safely fallback to `Latest`. + match self { + BlockNumber::Num(n) => BlockId::Number(n), + BlockNumber::Earliest => BlockId::Earliest, + BlockNumber::Latest => BlockId::Latest, + BlockNumber::Pending => { + warn!("`Pending` is deprecated and may be removed in future versions. Falling back to `Latest`"); + BlockId::Latest + } + } + } +} + impl Serialize for BlockNumber { fn serialize(&self, serializer: S) -> Result where S: Serializer { match *self { diff --git a/rpc/src/v1/types/mod.rs b/rpc/src/v1/types/mod.rs index fe35dd50a09..eb8c0dc226c 100644 --- a/rpc/src/v1/types/mod.rs +++ b/rpc/src/v1/types/mod.rs @@ -49,7 +49,7 @@ pub mod pubsub; pub use self::account_info::{AccountInfo, ExtAccountInfo, HwAccountInfo}; pub use self::bytes::Bytes; pub use self::block::{RichBlock, Block, BlockTransactions, Header, RichHeader, Rich}; -pub use self::block_number::{BlockNumber, block_number_to_id}; +pub use self::block_number::{BlockNumber, LightBlockNumber, block_number_to_id}; pub use self::call_request::CallRequest; pub use self::confirmations::{ ConfirmationPayload, ConfirmationRequest, ConfirmationResponse, ConfirmationResponseWithToken, diff --git a/rpc/src/v1/types/transaction.rs b/rpc/src/v1/types/transaction.rs index 8518e149743..4d930159a0d 100644 --- a/rpc/src/v1/types/transaction.rs +++ b/rpc/src/v1/types/transaction.rs @@ -200,7 +200,7 @@ impl Transaction { Action::Create => Some(contract_address(scheme, &t.sender(), &t.nonce, &t.data).0.into()), Action::Call(_) => None, }, - raw: ::rlp::encode(&t.signed).into_vec().into(), + raw: ::rlp::encode(&t.signed).into(), public_key: t.recover_public().ok().map(Into::into), chain_id: t.chain_id().map(U64::from), standard_v: t.standard_v().into(), @@ -234,7 +234,7 @@ impl Transaction { Action::Create => Some(contract_address(scheme, &t.sender(), &t.nonce, &t.data).0.into()), Action::Call(_) => None, }, - raw: ::rlp::encode(&t).into_vec().into(), + raw: ::rlp::encode(&t).into(), public_key: t.public_key().map(Into::into), chain_id: t.chain_id().map(U64::from), standard_v: t.standard_v().into(), diff --git a/util/journaldb/Cargo.toml b/util/journaldb/Cargo.toml index cd91984088f..709664a534f 100644 --- a/util/journaldb/Cargo.toml +++ b/util/journaldb/Cargo.toml @@ -8,15 +8,15 @@ license = "GPL3" [dependencies] parity-bytes = "0.1" ethereum-types = "0.4" -hashdb = "0.2.1" +hashdb = "0.3.0" heapsize = "0.4" keccak-hasher = { path = "../keccak-hasher" } kvdb = "0.1" log = "0.4" -memorydb = "0.2.1" +memorydb = "0.3.0" parking_lot = "0.6" fastmap = { path = "../../util/fastmap" } -rlp = { version = "0.2.4", features = ["ethereum"] } +rlp = { version = "0.3.0", features = ["ethereum"] } [dev-dependencies] ethcore-logger = { path = "../../logger" } diff --git a/util/journaldb/src/archivedb.rs b/util/journaldb/src/archivedb.rs index 3993887e470..86ed6cf5132 100644 --- a/util/journaldb/src/archivedb.rs +++ b/util/journaldb/src/archivedb.rs @@ -25,7 +25,7 @@ use bytes::Bytes; use ethereum_types::H256; use hashdb::*; use keccak_hasher::KeccakHasher; -use kvdb::{KeyValueDB, DBTransaction}; +use kvdb::{KeyValueDB, DBTransaction, DBValue}; use rlp::{encode, decode}; use super::{DB_PREFIX_LEN, LATEST_ERA_KEY, error_key_already_exists, error_negatively_reference_hash}; use super::memorydb::*; @@ -39,7 +39,7 @@ use traits::JournalDB; /// immediately. As this is an "archive" database, nothing is ever removed. This means /// that the states of any block the node has ever processed will be accessible. pub struct ArchiveDB { - overlay: MemoryDB, + overlay: MemoryDB, backing: Arc, latest_era: Option, column: Option, @@ -64,7 +64,7 @@ impl ArchiveDB { } } -impl HashDB for ArchiveDB { +impl HashDB for ArchiveDB { fn keys(&self) -> HashMap { let mut ret: HashMap = self.backing.iter(self.column) .map(|(key, _)| (H256::from_slice(&*key), 1)) @@ -193,7 +193,7 @@ impl JournalDB for ArchiveDB { &self.backing } - fn consolidate(&mut self, with: MemoryDB) { + fn consolidate(&mut self, with: MemoryDB) { self.overlay.consolidate(with); } } @@ -202,7 +202,7 @@ impl JournalDB for ArchiveDB { mod tests { use keccak::keccak; - use hashdb::{HashDB, DBValue}; + use hashdb::HashDB; use super::*; use {kvdb_memorydb, JournalDB}; diff --git a/util/journaldb/src/as_hash_db_impls.rs b/util/journaldb/src/as_hash_db_impls.rs index bd3b0e2d76f..648e370a015 100644 --- a/util/journaldb/src/as_hash_db_impls.rs +++ b/util/journaldb/src/as_hash_db_impls.rs @@ -22,28 +22,29 @@ use earlymergedb::EarlyMergeDB; use overlayrecentdb::OverlayRecentDB; use refcounteddb::RefCountedDB; use overlaydb::OverlayDB; +use kvdb::DBValue; -impl AsHashDB for ArchiveDB { - fn as_hashdb(&self) -> &HashDB { self } - fn as_hashdb_mut(&mut self) -> &mut HashDB { self } +impl AsHashDB for ArchiveDB { + fn as_hashdb(&self) -> &HashDB { self } + fn as_hashdb_mut(&mut self) -> &mut HashDB { self } } -impl AsHashDB for EarlyMergeDB { - fn as_hashdb(&self) -> &HashDB { self } - fn as_hashdb_mut(&mut self) -> &mut HashDB { self } +impl AsHashDB for EarlyMergeDB { + fn as_hashdb(&self) -> &HashDB { self } + fn as_hashdb_mut(&mut self) -> &mut HashDB { self } } -impl AsHashDB for OverlayRecentDB { - fn as_hashdb(&self) -> &HashDB { self } - fn as_hashdb_mut(&mut self) -> &mut HashDB { self } +impl AsHashDB for OverlayRecentDB { + fn as_hashdb(&self) -> &HashDB { self } + fn as_hashdb_mut(&mut self) -> &mut HashDB { self } } -impl AsHashDB for RefCountedDB { - fn as_hashdb(&self) -> &HashDB { self } - fn as_hashdb_mut(&mut self) -> &mut HashDB { self } +impl AsHashDB for RefCountedDB { + fn as_hashdb(&self) -> &HashDB { self } + fn as_hashdb_mut(&mut self) -> &mut HashDB { self } } -impl AsHashDB for OverlayDB { - fn as_hashdb(&self) -> &HashDB { self } - fn as_hashdb_mut(&mut self) -> &mut HashDB { self } -} \ No newline at end of file +impl AsHashDB for OverlayDB { + fn as_hashdb(&self) -> &HashDB { self } + fn as_hashdb_mut(&mut self) -> &mut HashDB { self } +} diff --git a/util/journaldb/src/earlymergedb.rs b/util/journaldb/src/earlymergedb.rs index 68b8675af58..e50df30733e 100644 --- a/util/journaldb/src/earlymergedb.rs +++ b/util/journaldb/src/earlymergedb.rs @@ -26,7 +26,7 @@ use ethereum_types::H256; use hashdb::*; use heapsize::HeapSizeOf; use keccak_hasher::KeccakHasher; -use kvdb::{KeyValueDB, DBTransaction}; +use kvdb::{KeyValueDB, DBTransaction, DBValue}; use memorydb::*; use parking_lot::RwLock; use rlp::{encode, decode}; @@ -107,7 +107,7 @@ enum RemoveFrom { /// /// TODO: `store_reclaim_period` pub struct EarlyMergeDB { - overlay: MemoryDB, + overlay: MemoryDB, backing: Arc, refs: Option>>>, latest_era: Option, @@ -287,7 +287,7 @@ impl EarlyMergeDB { } } -impl HashDB for EarlyMergeDB { +impl HashDB for EarlyMergeDB { fn keys(&self) -> HashMap { let mut ret: HashMap = self.backing.iter(self.column) .map(|(key, _)| (H256::from_slice(&*key), 1)) @@ -514,7 +514,7 @@ impl JournalDB for EarlyMergeDB { Ok(ops) } - fn consolidate(&mut self, with: MemoryDB) { + fn consolidate(&mut self, with: MemoryDB) { self.overlay.consolidate(with); } } @@ -523,7 +523,7 @@ impl JournalDB for EarlyMergeDB { mod tests { use keccak::keccak; - use hashdb::{HashDB, DBValue}; + use hashdb::HashDB; use super::*; use super::super::traits::JournalDB; use ethcore_logger::init_log; diff --git a/util/journaldb/src/overlaydb.rs b/util/journaldb/src/overlaydb.rs index f4b20b2193b..259e756bd94 100644 --- a/util/journaldb/src/overlaydb.rs +++ b/util/journaldb/src/overlaydb.rs @@ -26,8 +26,8 @@ use rlp::{Rlp, RlpStream, Encodable, DecoderError, Decodable, encode, decode}; use hashdb::*; use keccak_hasher::KeccakHasher; use memorydb::*; -use kvdb::{KeyValueDB, DBTransaction}; -use super::error_negatively_reference_hash; +use kvdb::{KeyValueDB, DBTransaction, DBValue}; +use super::{error_negatively_reference_hash}; /// Implementation of the `HashDB` trait for a disk-backed database with a memory overlay. /// @@ -39,7 +39,7 @@ use super::error_negatively_reference_hash; /// queries have an immediate effect in terms of these functions. #[derive(Clone)] pub struct OverlayDB { - overlay: MemoryDB, + overlay: MemoryDB, backing: Arc, column: Option, } @@ -140,7 +140,7 @@ impl OverlayDB { fn payload(&self, key: &H256) -> Option { self.backing.get(self.column, key) .expect("Low-level database error. Some issue with your hard disk?") - .map(|d| decode(&d).expect("decoding db value failed")) + .map(|ref d| decode(d).expect("decoding db value failed") ) } /// Put the refs and value of the given key, possibly deleting it from the db. @@ -155,7 +155,7 @@ impl OverlayDB { } } -impl HashDB for OverlayDB { +impl HashDB for OverlayDB { fn keys(&self) -> HashMap { let mut ret: HashMap = self.backing.iter(self.column) .map(|(key, _)| { diff --git a/util/journaldb/src/overlayrecentdb.rs b/util/journaldb/src/overlayrecentdb.rs index 1549d3baa34..017447bcc4b 100644 --- a/util/journaldb/src/overlayrecentdb.rs +++ b/util/journaldb/src/overlayrecentdb.rs @@ -26,7 +26,7 @@ use ethereum_types::H256; use hashdb::*; use heapsize::HeapSizeOf; use keccak_hasher::KeccakHasher; -use kvdb::{KeyValueDB, DBTransaction}; +use kvdb::{KeyValueDB, DBTransaction, DBValue}; use memorydb::*; use parking_lot::RwLock; use fastmap::H256FastMap; @@ -66,7 +66,7 @@ use util::DatabaseKey; /// 7. Delete ancient record from memory and disk. pub struct OverlayRecentDB { - transaction_overlay: MemoryDB, + transaction_overlay: MemoryDB, backing: Arc, journal_overlay: Arc>, column: Option, @@ -120,7 +120,7 @@ impl<'a> Encodable for DatabaseValueRef<'a> { #[derive(PartialEq)] struct JournalOverlay { - backing_overlay: MemoryDB, // Nodes added in the history period + backing_overlay: MemoryDB, // Nodes added in the history period pending_overlay: H256FastMap, // Nodes being transfered from backing_overlay to backing db journal: HashMap>, latest_era: Option, @@ -323,10 +323,10 @@ impl JournalDB for OverlayRecentDB { index, }; - batch.put_vec(self.column, &encode(&db_key), encoded_value.into_vec()); + batch.put_vec(self.column, &encode(&db_key), encoded_value.to_vec()); if journal_overlay.latest_era.map_or(true, |e| now > e) { trace!(target: "journaldb", "Set latest era to {}", now); - batch.put_vec(self.column, &LATEST_ERA_KEY, encode(&now).into_vec()); + batch.put_vec(self.column, &LATEST_ERA_KEY, encode(&now).to_vec()); journal_overlay.latest_era = Some(now); } @@ -434,12 +434,12 @@ impl JournalDB for OverlayRecentDB { Ok(ops) } - fn consolidate(&mut self, with: MemoryDB) { + fn consolidate(&mut self, with: MemoryDB) { self.transaction_overlay.consolidate(with); } } -impl HashDB for OverlayRecentDB { +impl HashDB for OverlayRecentDB { fn keys(&self) -> HashMap { let mut ret: HashMap = self.backing.iter(self.column) .map(|(key, _)| (H256::from_slice(&*key), 1)) @@ -493,7 +493,7 @@ mod tests { use keccak::keccak; use super::*; - use hashdb::{HashDB, DBValue}; + use hashdb::HashDB; use ethcore_logger::init_log; use {kvdb_memorydb, JournalDB}; diff --git a/util/journaldb/src/refcounteddb.rs b/util/journaldb/src/refcounteddb.rs index 7cbe9022d81..99b3d8d738e 100644 --- a/util/journaldb/src/refcounteddb.rs +++ b/util/journaldb/src/refcounteddb.rs @@ -25,7 +25,7 @@ use ethereum_types::H256; use hashdb::*; use heapsize::HeapSizeOf; use keccak_hasher::KeccakHasher; -use kvdb::{KeyValueDB, DBTransaction}; +use kvdb::{KeyValueDB, DBTransaction, DBValue}; use memorydb::MemoryDB; use overlaydb::OverlayDB; use rlp::{encode, decode}; @@ -80,7 +80,7 @@ impl RefCountedDB { } } -impl HashDB for RefCountedDB { +impl HashDB for RefCountedDB { fn keys(&self) -> HashMap { self.forward.keys() } fn get(&self, key: &H256) -> Option { self.forward.get(key) } fn contains(&self, key: &H256) -> bool { self.forward.contains(key) } @@ -199,7 +199,7 @@ impl JournalDB for RefCountedDB { self.forward.commit_to_batch(batch) } - fn consolidate(&mut self, mut with: MemoryDB) { + fn consolidate(&mut self, mut with: MemoryDB) { for (key, (value, rc)) in with.drain() { for _ in 0..rc { self.emplace(key, value.clone()); @@ -216,7 +216,7 @@ impl JournalDB for RefCountedDB { mod tests { use keccak::keccak; - use hashdb::{HashDB, DBValue}; + use hashdb::HashDB; use super::*; use {JournalDB, kvdb_memorydb}; diff --git a/util/journaldb/src/traits.rs b/util/journaldb/src/traits.rs index 075a546005b..1d6aae5f6bf 100644 --- a/util/journaldb/src/traits.rs +++ b/util/journaldb/src/traits.rs @@ -21,13 +21,13 @@ use std::sync::Arc; use bytes::Bytes; use ethereum_types::H256; -use hashdb::*; +use hashdb::HashDB; use keccak_hasher::KeccakHasher; -use kvdb::{self, DBTransaction}; +use kvdb::{self, DBTransaction, DBValue}; /// A `HashDB` which can manage a short-term journal potentially containing many forks of mutually /// exclusive actions. -pub trait JournalDB: HashDB { +pub trait JournalDB: HashDB { /// Return a copy of ourself, in a box. fn boxed_clone(&self) -> Box; @@ -78,7 +78,7 @@ pub trait JournalDB: HashDB { fn flush(&self) {} /// Consolidate all the insertions and deletions in the given memory overlay. - fn consolidate(&mut self, overlay: ::memorydb::MemoryDB); + fn consolidate(&mut self, overlay: ::memorydb::MemoryDB); /// Commit all changes in a single batch #[cfg(test)] diff --git a/util/keccak-hasher/Cargo.toml b/util/keccak-hasher/Cargo.toml index 027dd5d2cc8..f61e461e29e 100644 --- a/util/keccak-hasher/Cargo.toml +++ b/util/keccak-hasher/Cargo.toml @@ -8,5 +8,5 @@ license = "GPL-3.0" [dependencies] ethereum-types = "0.4" tiny-keccak = "1.4.2" -hashdb = "0.2.1" +hashdb = "0.3.0" plain_hasher = "0.2" diff --git a/util/network-devp2p/Cargo.toml b/util/network-devp2p/Cargo.toml index c4574774736..112595ad9ea 100644 --- a/util/network-devp2p/Cargo.toml +++ b/util/network-devp2p/Cargo.toml @@ -26,7 +26,7 @@ ethcore-logger = { path ="../../logger" } ethcore-network = { path = "../network" } ethereum-types = "0.4" ethkey = { path = "../../ethkey" } -rlp = { version = "0.2.4", features = ["ethereum"] } +rlp = { version = "0.3.0", features = ["ethereum"] } parity-path = "0.1" ipnetwork = "0.12.6" keccak-hash = "0.1" diff --git a/util/network-devp2p/src/discovery.rs b/util/network-devp2p/src/discovery.rs index 8ef244cbd11..abf6cf4d0f8 100644 --- a/util/network-devp2p/src/discovery.rs +++ b/util/network-devp2p/src/discovery.rs @@ -435,7 +435,6 @@ impl<'a> Discovery<'a> { let signed = &packet[(32 + 65)..]; let signature = H520::from_slice(&packet[32..(32 + 65)]); let node_id = recover(&signature.into(), &keccak(signed))?; - let packet_id = signed[0]; let rlp = Rlp::new(&signed[1..]); match packet_id { @@ -470,7 +469,6 @@ impl<'a> Discovery<'a> { let ping_to = NodeEndpoint::from_rlp(&rlp.at(2)?)?; let timestamp: u64 = rlp.val_at(3)?; self.check_timestamp(timestamp)?; - let mut response = RlpStream::new_list(3); let pong_to = NodeEndpoint { address: from.clone(), @@ -1063,7 +1061,7 @@ mod tests { 4be2be5a685a80971ddcfa80cb422cdd0101ec04cb847f000001820cfa8215a8d790000000000000\ 000000000000000000018208ae820d058443b9a3550102\ ".from_hex().unwrap(); - assert!(discovery.on_packet(&packet, from.clone()).is_ok()); + let _ = discovery.on_packet(&packet, from.clone()).expect("packet to be ok"); let packet = "\ 577be4349c4dd26768081f58de4c6f375a7a22f3f7adda654d1428637412c3d7fe917cadc56d4e5e\ @@ -1075,7 +1073,7 @@ mod tests { 7084a95398b6a21eac920fe3dd1345ec0a7ef39367ee69ddf092cbfe5b93e5e568ebc491983c09c7\ 6d922dc3\ ".from_hex().unwrap(); - assert!(discovery.on_packet(&packet, from.clone()).is_ok()); + let _ = discovery.on_packet(&packet, from.clone()).expect("packet to be ok"); let packet = "\ 09b2428d83348d27cdf7064ad9024f526cebc19e4958f0fdad87c15eb598dd61d08423e0bf66b206\ @@ -1085,7 +1083,7 @@ mod tests { a355c6010203c2040506a0c969a58f6f9095004c0177a6b47f451530cab38966a25cca5cb58f0555 42124e\ ".from_hex().unwrap(); - assert!(discovery.on_packet(&packet, from.clone()).is_ok()); + let _ = discovery.on_packet(&packet, from.clone()).expect("packet to be ok"); let packet = "\ c7c44041b9f7c7e41934417ebac9a8e1a4c6298f74553f2fcfdcae6ed6fe53163eb3d2b52e39fe91\ @@ -1095,7 +1093,7 @@ mod tests { 7bf5ccd1fc7f8443b9a35582999983999999280dc62cc8255c73471e0a61da0c89acdc0e035e260a\ dd7fc0c04ad9ebf3919644c91cb247affc82b69bd2ca235c71eab8e49737c937a2c396\ ".from_hex().unwrap(); - assert!(discovery.on_packet(&packet, from.clone()).is_ok()); + let _ = discovery.on_packet(&packet, from.clone()).expect("packet to be ok"); let packet = "\ c679fc8fe0b8b12f06577f2e802d34f6fa257e6137a995f6f4cbfc9ee50ed3710faf6e66f932c4c8\ @@ -1111,7 +1109,7 @@ mod tests { 197101a4b2b47dd2d47295286fc00cc081bb542d760717d1bdd6bec2c37cd72eca367d6dd3b9df73\ 8443b9a355010203b525a138aa34383fec3d2719a0\ ".from_hex().unwrap(); - assert!(discovery.on_packet(&packet, from.clone()).is_ok()); + let _ = discovery.on_packet(&packet, from.clone()).expect("packet to be ok"); } #[test] diff --git a/util/network/Cargo.toml b/util/network/Cargo.toml index b6beeb3e06a..51c3dc67113 100644 --- a/util/network/Cargo.toml +++ b/util/network/Cargo.toml @@ -13,7 +13,7 @@ ethcore-io = { path = "../io" } ethereum-types = "0.4" ethkey = { path = "../../ethkey" } ipnetwork = "0.12.6" -rlp = { version = "0.2.4", features = ["ethereum"] } +rlp = { version = "0.3.0", features = ["ethereum"] } libc = "0.2" parity-snappy = "0.1" diff --git a/util/network/src/error.rs b/util/network/src/error.rs index 4233b9e058b..e7b0d6eda4b 100644 --- a/util/network/src/error.rs +++ b/util/network/src/error.rs @@ -85,6 +85,7 @@ error_chain! { foreign_links { SocketIo(IoError) #[doc = "Socket IO error."]; Decompression(snappy::InvalidInput) #[doc = "Decompression error."]; + Rlp(rlp::DecoderError) #[doc = "Rlp decoder error."]; } errors { @@ -172,12 +173,6 @@ impl From for Error { } } -impl From for Error { - fn from(_err: rlp::DecoderError) -> Self { - ErrorKind::Auth.into() - } -} - impl From for Error { fn from(_err: ethkey::Error) -> Self { ErrorKind::Auth.into() @@ -210,7 +205,7 @@ fn test_errors() { assert_eq!(DisconnectReason::Unknown, r); match *>::from(rlp::DecoderError::RlpIsTooBig).kind() { - ErrorKind::Auth => {}, + ErrorKind::Rlp(_) => {}, _ => panic!("Unexpected error"), } diff --git a/util/patricia-trie-ethereum/Cargo.toml b/util/patricia-trie-ethereum/Cargo.toml index a4121a0ba80..e6880691a12 100644 --- a/util/patricia-trie-ethereum/Cargo.toml +++ b/util/patricia-trie-ethereum/Cargo.toml @@ -6,14 +6,14 @@ description = "Merkle-Patricia Trie (Ethereum Style)" license = "GPL-3.0" [dependencies] -patricia-trie = "0.2" +patricia-trie = "0.3.0" keccak-hasher = { version = "0.1.1", path = "../keccak-hasher" } -hashdb = "0.2" -rlp = { version = "0.2.4", features = ["ethereum"] } +hashdb = "0.3.0" +rlp = "0.3.0" parity-bytes = "0.1" ethereum-types = "0.4" elastic-array = "0.10" [dev-dependencies] -memorydb = "0.2.1" +memorydb = "0.3.0" keccak-hash = "0.1.2" diff --git a/util/patricia-trie-ethereum/src/lib.rs b/util/patricia-trie-ethereum/src/lib.rs index c6a4d36c7e1..aa83e330cd9 100644 --- a/util/patricia-trie-ethereum/src/lib.rs +++ b/util/patricia-trie-ethereum/src/lib.rs @@ -48,6 +48,7 @@ pub type RlpCodec = RlpNodeCodec; /// extern crate keccak_hasher; /// extern crate memorydb; /// extern crate ethereum_types; +/// extern crate elastic_array; /// /// use trie::*; /// use hashdb::*; @@ -55,10 +56,12 @@ pub type RlpCodec = RlpNodeCodec; /// use memorydb::*; /// use ethereum_types::H256; /// use ethtrie::{TrieDB, TrieDBMut}; +/// use elastic_array::ElasticArray128; /// +/// type DBValue = ElasticArray128; /// /// fn main() { -/// let mut memdb = MemoryDB::::new(); +/// let mut memdb = MemoryDB::::new(); /// let mut root = H256::new(); /// TrieDBMut::new(&mut memdb, &mut root).insert(b"foo", b"bar").unwrap(); /// let t = TrieDB::new(&memdb, &root).unwrap(); @@ -89,16 +92,19 @@ pub type FatDB<'db> = trie::FatDB<'db, KeccakHasher, RlpCodec>; /// extern crate keccak_hasher; /// extern crate memorydb; /// extern crate ethereum_types; +/// extern crate elastic_array; /// /// use keccak_hash::KECCAK_NULL_RLP; /// use ethtrie::{TrieDBMut, trie::TrieMut}; -/// use hashdb::DBValue; /// use keccak_hasher::KeccakHasher; /// use memorydb::*; /// use ethereum_types::H256; +/// use elastic_array::ElasticArray128; +/// +/// type DBValue = ElasticArray128; /// /// fn main() { -/// let mut memdb = MemoryDB::::new(); +/// let mut memdb = MemoryDB::::new(); /// let mut root = H256::new(); /// let mut t = TrieDBMut::new(&mut memdb, &mut root); /// assert!(t.is_empty()); diff --git a/util/patricia-trie-ethereum/src/rlp_node_codec.rs b/util/patricia-trie-ethereum/src/rlp_node_codec.rs index 414a129efe8..50482c47b9b 100644 --- a/util/patricia-trie-ethereum/src/rlp_node_codec.rs +++ b/util/patricia-trie-ethereum/src/rlp_node_codec.rs @@ -16,7 +16,7 @@ //! `NodeCodec` implementation for Rlp -use elastic_array::{ElasticArray1024, ElasticArray128}; +use elastic_array::ElasticArray128; use ethereum_types::H256; use hashdb::Hasher; use keccak_hasher::KeccakHasher; @@ -72,20 +72,20 @@ impl NodeCodec for RlpNodeCodec { fn is_empty_node(data: &[u8]) -> bool { Rlp::new(data).is_empty() } - fn empty_node() -> ElasticArray1024 { + fn empty_node() -> Vec { let mut stream = RlpStream::new(); stream.append_empty_data(); stream.drain() } - fn leaf_node(partial: &[u8], value: &[u8]) -> ElasticArray1024 { + fn leaf_node(partial: &[u8], value: &[u8]) -> Vec { let mut stream = RlpStream::new_list(2); stream.append(&partial); stream.append(&value); stream.drain() } - fn ext_node(partial: &[u8], child_ref: ChildReference<::Out>) -> ElasticArray1024 { + fn ext_node(partial: &[u8], child_ref: ChildReference<::Out>) -> Vec { let mut stream = RlpStream::new_list(2); stream.append(&partial); match child_ref { @@ -98,7 +98,8 @@ impl NodeCodec for RlpNodeCodec { stream.drain() } - fn branch_node(children: I, value: Option>) -> ElasticArray1024 + // fn branch_node(children: I, value: Option>) -> Vec + fn branch_node(children: I, value: Option>) -> Vec where I: IntoIterator::Out>>> { let mut stream = RlpStream::new_list(17); diff --git a/util/rlp_compress/Cargo.toml b/util/rlp_compress/Cargo.toml index 63a58bc4462..4bd34bce13e 100644 --- a/util/rlp_compress/Cargo.toml +++ b/util/rlp_compress/Cargo.toml @@ -4,6 +4,6 @@ version = "0.1.0" authors = ["Parity Technologies "] [dependencies] -rlp = "0.2.4" +rlp = { version = "0.3.0", features = ["ethereum"] } elastic-array = "0.10" lazy_static = "1.0" diff --git a/util/rlp_compress/src/lib.rs b/util/rlp_compress/src/lib.rs index af5b09aac79..38dabcd86b8 100644 --- a/util/rlp_compress/src/lib.rs +++ b/util/rlp_compress/src/lib.rs @@ -64,7 +64,7 @@ fn map_rlp ElasticArray1024>(rlp: &Rlp, f: F) -> ElasticArray for subrlp in rlp.iter() { stream.append_raw(&f(&subrlp), 1); } - stream.drain() + stream.drain().as_slice().into() } /// Stores RLPs used for compression diff --git a/util/rlp_derive/Cargo.toml b/util/rlp_derive/Cargo.toml index 87fc89312f6..64edff4de83 100644 --- a/util/rlp_derive/Cargo.toml +++ b/util/rlp_derive/Cargo.toml @@ -12,4 +12,4 @@ syn = "0.13" quote = "0.5" [dev-dependencies] -rlp = "0.2.4" +rlp = { version = "0.3.0", features = ["ethereum"] } diff --git a/util/rlp_derive/tests/rlp.rs b/util/rlp_derive/tests/rlp.rs index 7115b87c965..41cfed17c08 100644 --- a/util/rlp_derive/tests/rlp.rs +++ b/util/rlp_derive/tests/rlp.rs @@ -37,7 +37,7 @@ fn test_encode_foo() { }; let expected = vec![0xc4, 0x83, b'c', b'a', b't']; - let out = encode(&foo).into_vec(); + let out = encode(&foo); assert_eq!(out, expected); let decoded = decode(&expected).expect("decode failure"); @@ -51,7 +51,7 @@ fn test_encode_foo_wrapper() { }; let expected = vec![0x83, b'c', b'a', b't']; - let out = encode(&foo).into_vec(); + let out = encode(&foo); assert_eq!(out, expected); let decoded = decode(&expected).expect("decode failure"); diff --git a/util/triehash-ethereum/Cargo.toml b/util/triehash-ethereum/Cargo.toml index 152e9cbdf7b..e46d5d69076 100644 --- a/util/triehash-ethereum/Cargo.toml +++ b/util/triehash-ethereum/Cargo.toml @@ -6,6 +6,6 @@ description = "Trie-root helpers, ethereum style" license = "GPL-3.0" [dependencies] -triehash = { version = "0.2.3", features = ["ethereum"] } +triehash = { version = "0.3.0", features = ["ethereum"] } ethereum-types = "0.4" keccak-hasher = { path = "../keccak-hasher" } diff --git a/util/triehash-ethereum/src/lib.rs b/util/triehash-ethereum/src/lib.rs index 7de77473c5b..55aa74760e2 100644 --- a/util/triehash-ethereum/src/lib.rs +++ b/util/triehash-ethereum/src/lib.rs @@ -49,7 +49,7 @@ where I: IntoIterator, V: AsRef<[u8]>, { - triehash::ordered_trie_root::(input) + triehash::ordered_trie_root::(input) } #[cfg(test)] @@ -81,7 +81,7 @@ mod tests { let data = &["cake", "pie", "candy"]; assert_eq!( ordered_trie_root(data), - triehash::ordered_trie_root::(data) + triehash::ordered_trie_root::(data) ); } -} \ No newline at end of file +} diff --git a/util/version/Cargo.toml b/util/version/Cargo.toml index 8ab5e0040aa..562fa1241e7 100644 --- a/util/version/Cargo.toml +++ b/util/version/Cargo.toml @@ -3,7 +3,7 @@ [package] name = "parity-version" # NOTE: this value is used for Parity Ethereum version string (via env CARGO_PKG_VERSION) -version = "2.1.9" +version = "2.1.10" authors = ["Parity Technologies "] build = "build.rs" @@ -22,7 +22,7 @@ kovan = { forkBlock = 6600000, critical = false } [dependencies] parity-bytes = "0.1" -rlp = { version = "0.2.4", features = ["ethereum"] } +rlp = { version = "0.3.0", features = ["ethereum"] } target_info = "0.1" [build-dependencies] diff --git a/whisper/Cargo.toml b/whisper/Cargo.toml index 4cf8379921b..2bf3718278c 100644 --- a/whisper/Cargo.toml +++ b/whisper/Cargo.toml @@ -17,7 +17,7 @@ mem = { path = "../util/mem" } ordered-float = "0.5" parking_lot = "0.6" rand = "0.4" -rlp = { version = "0.2.4", features = ["ethereum"] } +rlp = { version = "0.3.0", features = ["ethereum"] } serde = "1.0" serde_derive = "1.0" serde_json = "1.0"