From 4f5aadf31c8aab576c2f8a3f6fcda753917b1883 Mon Sep 17 00:00:00 2001 From: zhangsoledad <787953403@qq.com> Date: Fri, 12 Apr 2019 11:45:11 +0800 Subject: [PATCH] chore: bump rust toolchain to 1.34.0 --- .travis.yml | 4 +-- Cargo.lock | 3 +- chain/src/tests/util.rs | 2 +- core/src/block.rs | 6 ++-- core/src/cell.rs | 6 ++-- core/src/uncle.rs | 11 ++++++++ docker/hub/Dockerfile | 12 ++++---- docs/get-ckb.md | 4 +-- miner/src/block_assembler.rs | 12 ++++---- miner/src/miner.rs | 2 +- network/src/lib.rs | 2 +- network/src/network.rs | 8 +++--- network/src/protocols/mod.rs | 15 ++++------ protocol/src/builder.rs | 4 +-- protocol/src/convert.rs | 2 +- rpc/src/module/chain.rs | 2 +- rpc/src/module/miner.rs | 2 +- rpc/src/module/pool.rs | 2 +- rpc/src/module/trace.rs | 2 +- rust-toolchain | 2 +- shared/src/store.rs | 2 +- sync/src/relayer/block_proposal_process.rs | 2 +- .../src/relayer/block_transactions_process.rs | 2 +- sync/src/relayer/compact_block.rs | 2 +- sync/src/relayer/compact_block_process.rs | 2 +- .../src/relayer/get_block_proposal_process.rs | 2 +- .../relayer/get_block_transactions_process.rs | 2 +- sync/src/relayer/mod.rs | 5 ++-- sync/src/relayer/transaction_process.rs | 2 +- sync/src/synchronizer/block_process.rs | 2 +- sync/src/synchronizer/get_blocks_process.rs | 2 +- sync/src/synchronizer/get_headers_process.rs | 2 +- sync/src/synchronizer/headers_process.rs | 5 ++-- sync/src/synchronizer/mod.rs | 6 ++-- sync/src/tests/relayer.rs | 4 +-- test/src/node.rs | 2 +- test/src/specs/mining.rs | 2 +- test/src/specs/pool.rs | 4 +-- util/build-info/src/lib.rs | 4 +-- util/jsonrpc-types/src/block_template.rs | 7 ++--- util/jsonrpc-types/src/blockchain.rs | 2 +- util/jsonrpc-types/src/proposal_short_id.rs | 2 +- util/src/lib.rs | 3 -- util/src/unstable/mod.rs | 3 -- util/src/unstable/try_convert.rs | 28 ------------------- verification/Cargo.toml | 1 - verification/src/block_verifier.rs | 15 +++------- verification/src/tests/commit_verifier.rs | 4 +-- verification/src/transaction_verifier.rs | 4 +-- 49 files changed, 97 insertions(+), 129 deletions(-) delete mode 100644 util/src/unstable/try_convert.rs diff --git a/.travis.yml b/.travis.yml index 3ef3e8e942..0db4e08f49 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,10 +16,10 @@ env: matrix: include: - - rust: 1.33.0 + - rust: 1.34.0 os: osx env: FMT=true CHECK=true TEST=true REL_PKG=darwin_amd64.zip - - rust: 1.33.0 + - rust: 1.34.0 os: linux env: TEST=true REL_PKG=linux_amd64.tar.gz diff --git a/Cargo.lock b/Cargo.lock index 44ce5bc7e4..d0f5899e88 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,3 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. [[package]] name = "MacTypes-sys" version = "2.1.0" @@ -716,7 +718,6 @@ dependencies = [ "ckb-chain-spec 0.9.0-pre", "ckb-core 0.9.0-pre", "ckb-db 0.9.0-pre", - "ckb-merkle-tree 0.9.0-pre", "ckb-notify 0.9.0-pre", "ckb-pow 0.9.0-pre", "ckb-script 0.9.0-pre", diff --git a/chain/src/tests/util.rs b/chain/src/tests/util.rs index 58780902c7..ef96d2ab11 100644 --- a/chain/src/tests/util.rs +++ b/chain/src/tests/util.rs @@ -67,7 +67,7 @@ pub(crate) fn gen_block( .proposal_transactions( proposal_transactions .iter() - .map(|tx| tx.proposal_short_id()) + .map(Transaction::proposal_short_id) .collect(), ) .with_header_builder(header_builder) diff --git a/core/src/block.rs b/core/src/block.rs index 15d0c2b735..2f8a9112ba 100644 --- a/core/src/block.rs +++ b/core/src/block.rs @@ -72,7 +72,7 @@ impl Block { self.commit_transactions() .iter() .skip(1) - .map(|tx| tx.witness_hash()), + .map(Transaction::witness_hash), ); merkle_root(&witnesses[..]) } @@ -82,7 +82,7 @@ impl Block { &self .commit_transactions .iter() - .map(|t| t.hash()) + .map(Transaction::hash) .collect::>(), ) } @@ -92,7 +92,7 @@ impl Block { &self .proposal_transactions .iter() - .map(|t| t.hash()) + .map(ProposalShortId::hash) .collect::>(), ) } diff --git a/core/src/cell.rs b/core/src/cell.rs index 5f46a62e38..3e1bab4f5b 100644 --- a/core/src/cell.rs +++ b/core/src/cell.rs @@ -180,15 +180,15 @@ impl ResolvedTransaction { } pub fn is_double_spend(&self) -> bool { - self.cells_iter().any(|state| state.is_dead()) + self.cells_iter().any(CellStatus::is_dead) } pub fn is_orphan(&self) -> bool { - self.cells_iter().any(|state| state.is_unknown()) + self.cells_iter().any(CellStatus::is_unknown) } pub fn is_fully_resolved(&self) -> bool { - self.cells_iter().all(|state| state.is_live()) + self.cells_iter().all(CellStatus::is_live) } pub fn fee(&self) -> Capacity { diff --git a/core/src/uncle.rs b/core/src/uncle.rs index 7e892a2de5..9c7f042f55 100644 --- a/core/src/uncle.rs +++ b/core/src/uncle.rs @@ -3,6 +3,7 @@ use crate::header::Header; use crate::transaction::ProposalShortId; use crate::BlockNumber; use bincode::serialize; +use ckb_merkle_tree::merkle_root; use hash::blake2b_256; use numext_fixed_hash::H256; use serde_derive::{Deserialize, Serialize}; @@ -41,6 +42,16 @@ impl UncleBlock { pub fn proposal_transactions(&self) -> &[ProposalShortId] { &self.proposal_transactions } + + pub fn cal_txs_proposal_root(&self) -> H256 { + merkle_root( + &self + .proposal_transactions + .iter() + .map(ProposalShortId::hash) + .collect::>(), + ) + } } pub fn uncles_hash(uncles: &[UncleBlock]) -> H256 { diff --git a/docker/hub/Dockerfile b/docker/hub/Dockerfile index e071deecd3..b58a96f378 100644 --- a/docker/hub/Dockerfile +++ b/docker/hub/Dockerfile @@ -3,7 +3,7 @@ FROM ubuntu:bionic as ckb-builder ENV RUSTUP_HOME=/usr/local/rustup \ CARGO_HOME=/usr/local/cargo \ PATH=/usr/local/cargo/bin:$PATH \ - RUST_VERSION=1.33.0 + RUST_VERSION=1.34.0 RUN set -eux; \ apt-get update; \ @@ -19,13 +19,13 @@ RUN set -eux; \ RUN dpkgArch="$(dpkg --print-architecture)"; \ case "${dpkgArch##*-}" in \ - amd64) rustArch='x86_64-unknown-linux-gnu'; rustupSha256='2d4ddf4e53915a23dda722608ed24e5c3f29ea1688da55aa4e98765fc6223f71' ;; \ - armhf) rustArch='armv7-unknown-linux-gnueabihf'; rustupSha256='be85f50dc70ee239c5bb6acb60080797841a1e7c45fbf6bae15d6bd4b37ce0e5' ;; \ - arm64) rustArch='aarch64-unknown-linux-gnu'; rustupSha256='454f00a86be75ab070149bac1f541a7b39e5d3383d6da96ad2b929867ed40167' ;; \ - i386) rustArch='i686-unknown-linux-gnu'; rustupSha256='179e3b39f11037a708874e750081f7c0d3e1a6a4c431c2ecee2295acc7b696af' ;; \ + amd64) rustArch='x86_64-unknown-linux-gnu'; rustupSha256='ce09d3de51432b34a8ff73c7aaa1edb64871b2541d2eb474441cedb8bf14c5fa' ;; \ + armhf) rustArch='armv7-unknown-linux-gnueabihf'; rustupSha256='bf140b03a49abb87a601ad29ca326b4e6721be39868c90ad17cd0b76014f1789' ;; \ + arm64) rustArch='aarch64-unknown-linux-gnu'; rustupSha256='76010a472d90714f781d5a4ce618f0e1f8ce3a8b8476ce35a34b2f6ab67a8026' ;; \ + i386) rustArch='i686-unknown-linux-gnu'; rustupSha256='bde10f3e1a267923224792bb26b605b1189733c9d0c806da955e5c5c45b2868c' ;; \ *) echo >&2 "unsupported architecture: ${dpkgArch}"; exit 1 ;; \ esac; \ - url="https://static.rust-lang.org/rustup/archive/1.16.0/${rustArch}/rustup-init"; \ + url="https://static.rust-lang.org/rustup/archive/1.17.0/${rustArch}/rustup-init"; \ wget "$url"; \ echo "${rustupSha256} *rustup-init" | sha256sum -c -; \ chmod +x rustup-init diff --git a/docs/get-ckb.md b/docs/get-ckb.md index 80550561e8..3966be8004 100644 --- a/docs/get-ckb.md +++ b/docs/get-ckb.md @@ -13,13 +13,13 @@ branch. ### Install Build Dependencies -CKB is currently tested mainly with `stable-1.33.0` on Linux and macOS. +CKB is currently tested mainly with `stable-1.34.0` on Linux and macOS. We recommend installing Rust through [rustup](https://www.rustup.rs/) ```bash # Get rustup from rustup.rs, then in your `ckb` folder: -rustup override set 1.33.0 +rustup override set 1.34.0 ``` Report new breakage is welcome. diff --git a/miner/src/block_assembler.rs b/miner/src/block_assembler.rs index 077c59f70b..24991a3ce3 100644 --- a/miner/src/block_assembler.rs +++ b/miner/src/block_assembler.rs @@ -20,7 +20,7 @@ use lru_cache::LruCache; use numext_fixed_hash::H256; use numext_fixed_uint::U256; use std::cmp; -use std::sync::{atomic::AtomicUsize, atomic::Ordering, Arc}; +use std::sync::{atomic::AtomicU64, atomic::AtomicUsize, atomic::Ordering, Arc}; use std::thread; use stop_handler::{SignalSender, StopHandler}; @@ -89,7 +89,7 @@ pub struct BlockAssembler { candidate_uncles: LruCache>, config: BlockAssemblerConfig, work_id: AtomicUsize, - last_uncles_updated_at: AtomicUsize, + last_uncles_updated_at: AtomicU64, template_caches: Mutex>, } @@ -100,7 +100,7 @@ impl BlockAssembler { config, candidate_uncles: LruCache::new(MAX_CANDIDATE_UNCLES), work_id: AtomicUsize::new(0), - last_uncles_updated_at: AtomicUsize::new(0), + last_uncles_updated_at: AtomicU64::new(0), template_caches: Mutex::new(LruCache::new(TEMPLATE_CACHE_SIZE)), } } @@ -137,7 +137,7 @@ impl BlockAssembler { let hash = uncle_block.header().hash().clone(); self.candidate_uncles.insert(hash, uncle_block); self.last_uncles_updated_at - .store(unix_time_as_millis() as usize, Ordering::SeqCst); + .store(unix_time_as_millis(), Ordering::SeqCst); } _ => { error!(target: "miner", "new_uncle_receiver closed"); @@ -229,7 +229,7 @@ impl BlockAssembler { self.transform_params(cycles_limit, bytes_limit, max_version); let uncles_count_limit = self.shared.consensus().max_uncles_num() as u32; - let last_uncles_updated_at = self.last_uncles_updated_at.load(Ordering::SeqCst) as u64; + let last_uncles_updated_at = self.last_uncles_updated_at.load(Ordering::SeqCst); let chain_state = self.shared.chain_state().lock(); let last_txs_updated_at = chain_state.get_last_txs_updated_at(); @@ -435,11 +435,11 @@ mod tests { use ckb_shared::shared::SharedBuilder; use ckb_shared::store::ChainKVStore; use ckb_traits::ChainProvider; - use ckb_util::TryInto; use ckb_verification::{BlockVerifier, HeaderResolverWrapper, HeaderVerifier, Verifier}; use jsonrpc_types::{BlockTemplate, CellbaseTemplate}; use numext_fixed_hash::H256; use numext_fixed_uint::U256; + use std::convert::TryInto; use std::sync::Arc; fn start_chain( diff --git a/miner/src/miner.rs b/miner/src/miner.rs index b0d00fa648..63b3ffe3cd 100644 --- a/miner/src/miner.rs +++ b/miner/src/miner.rs @@ -4,12 +4,12 @@ use ckb_core::block::{Block, BlockBuilder}; use ckb_core::header::{HeaderBuilder, RawHeader, Seal}; use ckb_core::BlockNumber; use ckb_pow::PowEngine; -use ckb_util::TryInto; use crossbeam_channel::Receiver; use failure::Error; use jsonrpc_types::{BlockTemplate, CellbaseTemplate}; use log::{debug, error, info}; use rand::{thread_rng, Rng}; +use std::convert::TryInto; use std::sync::Arc; pub struct Miner { diff --git a/network/src/lib.rs b/network/src/lib.rs index 1cf44cf891..b637d70623 100644 --- a/network/src/lib.rs +++ b/network/src/lib.rs @@ -24,7 +24,7 @@ pub use crate::{ pub use p2p::{ context::{ProtocolContext, ProtocolContextMutRef, ServiceContext, SessionContext}, multiaddr, - secio::PeerId, + secio::{PeerId, PublicKey}, service::{ServiceControl, SessionType}, ProtocolId, SessionId, }; diff --git a/network/src/network.rs b/network/src/network.rs index 471202e1d2..3970739be4 100644 --- a/network/src/network.rs +++ b/network/src/network.rs @@ -11,7 +11,7 @@ use crate::protocols::{feeler::Feeler, DefaultCKBProtocolContext}; use crate::Peer; use crate::{ Behaviour, CKBProtocol, CKBProtocolContext, NetworkConfig, PeerIndex, ProtocolId, - ProtocolVersion, ServiceContext, ServiceControl, SessionId, SessionType, + ProtocolVersion, PublicKey, ServiceContext, ServiceControl, SessionId, SessionType, }; use ckb_util::RwLock; use fnv::{FnvHashMap, FnvHashSet}; @@ -390,7 +390,7 @@ impl ServiceHandle for EventHandler { let peer_id = session_context .remote_pubkey .as_ref() - .map(|pubkey| pubkey.peer_id()) + .map(PublicKey::peer_id) .expect("Secio must enabled"); let peer_store = self.network_state.peer_store(); @@ -413,7 +413,7 @@ impl ServiceHandle for EventHandler { let peer_id = session_context .remote_pubkey .as_ref() - .map(|pubkey| pubkey.peer_id()) + .map(PublicKey::peer_id) .expect("Secio must enabled"); if let Ok(parsed_version) = version.parse::() { match self.network_state.accept_connection( @@ -505,7 +505,7 @@ impl NetworkService { // == Build p2p service struct let mut protocol_metas = protocols .into_iter() - .map(|protocol| protocol.build()) + .map(CKBProtocol::build) .collect::>(); protocol_metas.push(feeler_protocol.build()); protocol_metas.push(ping_meta); diff --git a/network/src/protocols/mod.rs b/network/src/protocols/mod.rs index 2cc61791b3..105e20dd21 100644 --- a/network/src/protocols/mod.rs +++ b/network/src/protocols/mod.rs @@ -8,7 +8,8 @@ use crate::{ errors::{Error, PeerError}, peer_store::{Behaviour, Status}, peers_registry::RegisterResult, - NetworkState, PeerIndex, ProtocolContext, ProtocolContextMutRef, ServiceControl, SessionInfo, + NetworkState, PeerIndex, ProtocolContext, ProtocolContextMutRef, PublicKey, ServiceControl, + SessionInfo, }; use bytes::Bytes; use log::{debug, error, info, trace, warn}; @@ -75,7 +76,7 @@ impl CKBProtocol { let supported_versions = self .supported_versions .iter() - .map(|v| v.to_string()) + .map(ToString::to_string) .collect::>(); MetaBuilder::default() .id(self.id) @@ -147,7 +148,7 @@ impl ServiceProtocol for CKBHandler { session .remote_pubkey .as_ref() - .map(|pubkey| pubkey.peer_id()) + .map(PublicKey::peer_id) .expect("remote_pubkey existence checked"), parsed_version.expect("parsed_version existence checked"), ) @@ -201,11 +202,7 @@ impl ServiceProtocol for CKBHandler { fn disconnected(&mut self, mut context: ProtocolContextMutRef) { let session = context.session; - if let Some(peer_id) = session - .remote_pubkey - .as_ref() - .map(|pubkey| pubkey.peer_id()) - { + if let Some(peer_id) = session.remote_pubkey.as_ref().map(PublicKey::peer_id) { debug!( target: "network", "ckb protocol disconnect, addr: {}, protocol: {}, peer_id: {:?}", @@ -235,7 +232,7 @@ impl ServiceProtocol for CKBHandler { if let Some((peer_id, _peer_index)) = session .remote_pubkey .as_ref() - .map(|pubkey| pubkey.peer_id()) + .map(PublicKey::peer_id) .and_then(|peer_id| { self.network_state .get_peer_index(&peer_id) diff --git a/protocol/src/builder.rs b/protocol/src/builder.rs index 7f1c44bff2..9faabfe18d 100644 --- a/protocol/src/builder.rs +++ b/protocol/src/builder.rs @@ -412,7 +412,7 @@ impl<'a> FilteredBlock<'a> { &block .commit_transactions() .iter() - .map(|tx| tx.hash()) + .map(Transaction::hash) .collect::>(), transactions_index, ); @@ -637,8 +637,8 @@ mod tests { use ckb_core::block::BlockBuilder; use ckb_core::header::HeaderBuilder; use ckb_core::transaction::TransactionBuilder; - use ckb_util::TryInto; use flatbuffers::get_root; + use std::convert::TryInto; #[test] fn build_and_convert_header() { diff --git a/protocol/src/convert.rs b/protocol/src/convert.rs index b6540f22e1..d6e77c60de 100644 --- a/protocol/src/convert.rs +++ b/protocol/src/convert.rs @@ -2,10 +2,10 @@ use crate::cast; use crate::protocol_generated::ckb::protocol as ckb_protocol; use crate::FlatbuffersVectorIterator; use ckb_core; -use ckb_util::{TryFrom, TryInto}; use failure::Error as FailureError; use numext_fixed_hash::H256; use numext_fixed_uint::U256; +use std::convert::{TryFrom, TryInto}; impl From<&H256> for ckb_protocol::H256 { fn from(h256: &H256) -> Self { diff --git a/rpc/src/module/chain.rs b/rpc/src/module/chain.rs index c0dbf56461..31e5838226 100644 --- a/rpc/src/module/chain.rs +++ b/rpc/src/module/chain.rs @@ -2,11 +2,11 @@ use ckb_core::cell::CellProvider; use ckb_core::BlockNumber; use ckb_shared::{index::ChainIndex, shared::Shared}; use ckb_traits::ChainProvider; -use ckb_util::TryInto; use jsonrpc_core::{Error, Result}; use jsonrpc_derive::rpc; use jsonrpc_types::{Block, CellOutputWithOutPoint, CellWithStatus, Header, OutPoint, Transaction}; use numext_fixed_hash::H256; +use std::convert::TryInto; #[rpc] pub trait ChainRpc { diff --git a/rpc/src/module/miner.rs b/rpc/src/module/miner.rs index d81b4b8d76..ce24cbe90b 100644 --- a/rpc/src/module/miner.rs +++ b/rpc/src/module/miner.rs @@ -7,7 +7,6 @@ use ckb_protocol::RelayMessage; use ckb_shared::{index::ChainIndex, shared::Shared}; use ckb_sync::NetworkProtocol; use ckb_traits::ChainProvider; -use ckb_util::TryInto; use ckb_verification::{HeaderResolverWrapper, HeaderVerifier, Verifier}; use flatbuffers::FlatBufferBuilder; use jsonrpc_core::{Error, Result}; @@ -16,6 +15,7 @@ use jsonrpc_types::{Block, BlockTemplate}; use log::{debug, warn}; use numext_fixed_hash::H256; use std::collections::HashSet; +use std::convert::TryInto; use std::sync::Arc; #[rpc] diff --git a/rpc/src/module/pool.rs b/rpc/src/module/pool.rs index 20aba0cb51..ad2f0f79b6 100644 --- a/rpc/src/module/pool.rs +++ b/rpc/src/module/pool.rs @@ -7,7 +7,6 @@ use ckb_shared::shared::Shared; use ckb_shared::tx_pool::types::PoolEntry; use ckb_sync::NetworkProtocol; use ckb_traits::chain_provider::ChainProvider; -use ckb_util::TryInto; use ckb_verification::TransactionError; use flatbuffers::FlatBufferBuilder; use jsonrpc_core::{Error, Result}; @@ -15,6 +14,7 @@ use jsonrpc_derive::rpc; use jsonrpc_types::Transaction; use log::{debug, warn}; use numext_fixed_hash::H256; +use std::convert::TryInto; #[rpc] pub trait PoolRpc { diff --git a/rpc/src/module/trace.rs b/rpc/src/module/trace.rs index b6b1e1fb38..0ca39e7564 100644 --- a/rpc/src/module/trace.rs +++ b/rpc/src/module/trace.rs @@ -8,7 +8,6 @@ use ckb_shared::tx_pool::types::PoolEntry; use ckb_shared::tx_pool::TxTrace; use ckb_sync::NetworkProtocol; use ckb_traits::chain_provider::ChainProvider; -use ckb_util::TryInto; use ckb_verification::TransactionError; use flatbuffers::FlatBufferBuilder; use jsonrpc_core::{Error, Result}; @@ -16,6 +15,7 @@ use jsonrpc_derive::rpc; use jsonrpc_types::Transaction; use log::{debug, warn}; use numext_fixed_hash::H256; +use std::convert::TryInto; #[rpc] pub trait TraceRpc { diff --git a/rust-toolchain b/rust-toolchain index 7aa332e416..2b17ffd504 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.33.0 +1.34.0 diff --git a/shared/src/store.rs b/shared/src/store.rs index 1ad3238d3a..2b79099135 100644 --- a/shared/src/store.rs +++ b/shared/src/store.rs @@ -124,7 +124,7 @@ impl ChainStore for ChainKVStore { txs }) }) - .map(|txs| txs.into_iter().map(|tx| tx.build()).collect()) + .map(|txs| txs.into_iter().map(TransactionBuilder::build).collect()) } fn get_block_ext(&self, block_hash: &H256) -> Option { diff --git a/sync/src/relayer/block_proposal_process.rs b/sync/src/relayer/block_proposal_process.rs index 26f35bb6cc..6d55f077ea 100644 --- a/sync/src/relayer/block_proposal_process.rs +++ b/sync/src/relayer/block_proposal_process.rs @@ -2,9 +2,9 @@ use crate::relayer::Relayer; use ckb_protocol::{cast, BlockProposal, FlatbuffersVectorIterator}; use ckb_shared::index::ChainIndex; use ckb_traits::chain_provider::ChainProvider; -use ckb_util::TryInto; use failure::Error as FailureError; use log::warn; +use std::convert::TryInto; pub struct BlockProposalProcess<'a, CI> { message: &'a BlockProposal<'a>, diff --git a/sync/src/relayer/block_transactions_process.rs b/sync/src/relayer/block_transactions_process.rs index e4a1be469d..8e9c8480f9 100644 --- a/sync/src/relayer/block_transactions_process.rs +++ b/sync/src/relayer/block_transactions_process.rs @@ -3,8 +3,8 @@ use ckb_core::transaction::Transaction; use ckb_network::{CKBProtocolContext, PeerIndex}; use ckb_protocol::{cast, BlockTransactions, FlatbuffersVectorIterator}; use ckb_shared::index::ChainIndex; -use ckb_util::TryInto; use failure::Error as FailureError; +use std::convert::TryInto; use std::sync::Arc; pub struct BlockTransactionsProcess<'a, CI> { diff --git a/sync/src/relayer/compact_block.rs b/sync/src/relayer/compact_block.rs index be0bb428bd..1dbaed77fb 100644 --- a/sync/src/relayer/compact_block.rs +++ b/sync/src/relayer/compact_block.rs @@ -2,8 +2,8 @@ use ckb_core::header::Header; use ckb_core::transaction::{IndexTransaction, ProposalShortId}; use ckb_core::uncle::UncleBlock; use ckb_protocol::{self, cast, FlatbuffersVectorIterator}; -use ckb_util::{TryFrom, TryInto}; use failure::Error as FailureError; +use std::convert::{TryFrom, TryInto}; pub type ShortTransactionID = [u8; 6]; diff --git a/sync/src/relayer/compact_block_process.rs b/sync/src/relayer/compact_block_process.rs index f4e8ce7113..12a3c1742c 100644 --- a/sync/src/relayer/compact_block_process.rs +++ b/sync/src/relayer/compact_block_process.rs @@ -6,13 +6,13 @@ use ckb_protocol::{CompactBlock as FbsCompactBlock, RelayMessage}; use ckb_shared::index::ChainIndex; use ckb_shared::shared::Shared; use ckb_traits::{BlockMedianTimeContext, ChainProvider}; -use ckb_util::TryInto; use ckb_verification::{HeaderResolverWrapper, HeaderVerifier, Verifier}; use failure::Error as FailureError; use flatbuffers::FlatBufferBuilder; use fnv::FnvHashMap; use log::warn; use numext_fixed_hash::H256; +use std::convert::TryInto; use std::sync::Arc; pub struct CompactBlockProcess<'a, CI> { diff --git a/sync/src/relayer/get_block_proposal_process.rs b/sync/src/relayer/get_block_proposal_process.rs index 535c89fa28..94aed05ba2 100644 --- a/sync/src/relayer/get_block_proposal_process.rs +++ b/sync/src/relayer/get_block_proposal_process.rs @@ -2,10 +2,10 @@ use crate::relayer::Relayer; use ckb_network::{CKBProtocolContext, PeerIndex}; use ckb_protocol::{cast, GetBlockProposal, RelayMessage}; use ckb_shared::index::ChainIndex; -use ckb_util::TryInto; use failure::Error as FailureError; use flatbuffers::FlatBufferBuilder; use log::warn; +use std::convert::TryInto; pub struct GetBlockProposalProcess<'a, CI> { message: &'a GetBlockProposal<'a>, diff --git a/sync/src/relayer/get_block_transactions_process.rs b/sync/src/relayer/get_block_transactions_process.rs index 7a979282c7..317c706849 100644 --- a/sync/src/relayer/get_block_transactions_process.rs +++ b/sync/src/relayer/get_block_transactions_process.rs @@ -2,10 +2,10 @@ use crate::relayer::Relayer; use ckb_network::{CKBProtocolContext, PeerIndex}; use ckb_protocol::{cast, GetBlockTransactions, RelayMessage}; use ckb_shared::index::ChainIndex; -use ckb_util::TryInto; use failure::Error as FailureError; use flatbuffers::FlatBufferBuilder; use log::{debug, warn}; +use std::convert::TryInto; pub struct GetBlockTransactionsProcess<'a, CI> { message: &'a GetBlockTransactions<'a>, diff --git a/sync/src/relayer/mod.rs b/sync/src/relayer/mod.rs index ade9943c80..55d8aba254 100644 --- a/sync/src/relayer/mod.rs +++ b/sync/src/relayer/mod.rs @@ -21,6 +21,7 @@ use bytes::Bytes; use ckb_chain::chain::ChainController; use ckb_core::block::{Block, BlockBuilder}; use ckb_core::transaction::{ProposalShortId, Transaction}; +use ckb_core::uncle::UncleBlock; use ckb_network::{Behaviour, CKBProtocolContext, CKBProtocolHandler, PeerIndex}; use ckb_protocol::{ cast, get_root, short_transaction_id, short_transaction_id_keys, RelayMessage, RelayPayload, @@ -148,7 +149,7 @@ impl Relayer { block .uncles .iter() - .flat_map(|uncle| uncle.proposal_transactions()), + .flat_map(UncleBlock::proposal_transactions), ) .filter(|x| !chain_state.contains_proposal_id(x) && inflight.insert(**x)) .cloned() @@ -233,7 +234,7 @@ impl Relayer { // append remain transactions short_ids_iter.for_each(|short_id| block_transactions.push(txs_map.remove(short_id))); - let missing = block_transactions.iter().any(|tx| tx.is_none()); + let missing = block_transactions.iter().any(Option::is_none); if !missing { let txs = block_transactions diff --git a/sync/src/relayer/transaction_process.rs b/sync/src/relayer/transaction_process.rs index 89af16ec89..75fd66ea21 100644 --- a/sync/src/relayer/transaction_process.rs +++ b/sync/src/relayer/transaction_process.rs @@ -5,11 +5,11 @@ use ckb_protocol::{RelayMessage, ValidTransaction as FbsValidTransaction}; use ckb_shared::index::ChainIndex; use ckb_shared::tx_pool::types::PoolError; use ckb_traits::chain_provider::ChainProvider; -use ckb_util::TryInto; use ckb_verification::TransactionError; use failure::Error as FailureError; use flatbuffers::FlatBufferBuilder; use log::{debug, warn}; +use std::convert::TryInto; use std::time::Duration; const DEFAULT_BAN_TIME: Duration = Duration::from_secs(3600 * 24 * 3); diff --git a/sync/src/synchronizer/block_process.rs b/sync/src/synchronizer/block_process.rs index 2a1a722082..3a6a3bb89e 100644 --- a/sync/src/synchronizer/block_process.rs +++ b/sync/src/synchronizer/block_process.rs @@ -3,9 +3,9 @@ use ckb_core::block::Block; use ckb_network::{CKBProtocolContext, PeerIndex}; use ckb_protocol::Block as PBlock; use ckb_shared::index::ChainIndex; -use ckb_util::TryInto; use failure::Error as FailureError; use log::debug; +use std::convert::TryInto; pub struct BlockProcess<'a, CI: ChainIndex + 'a> { message: &'a PBlock<'a>, diff --git a/sync/src/synchronizer/get_blocks_process.rs b/sync/src/synchronizer/get_blocks_process.rs index 3ec64179cf..7879a73698 100644 --- a/sync/src/synchronizer/get_blocks_process.rs +++ b/sync/src/synchronizer/get_blocks_process.rs @@ -2,10 +2,10 @@ use crate::synchronizer::Synchronizer; use ckb_network::{CKBProtocolContext, PeerIndex}; use ckb_protocol::{cast, GetBlocks, SyncMessage}; use ckb_shared::index::ChainIndex; -use ckb_util::TryInto; use failure::Error as FailureError; use flatbuffers::FlatBufferBuilder; use log::{debug, warn}; +use std::convert::TryInto; pub struct GetBlocksProcess<'a, CI: ChainIndex + 'a> { message: &'a GetBlocks<'a>, diff --git a/sync/src/synchronizer/get_headers_process.rs b/sync/src/synchronizer/get_headers_process.rs index 1ce91b5265..4aa80d4cbe 100644 --- a/sync/src/synchronizer/get_headers_process.rs +++ b/sync/src/synchronizer/get_headers_process.rs @@ -4,11 +4,11 @@ use ckb_core::header::Header; use ckb_network::{Behaviour, CKBProtocolContext, PeerIndex}; use ckb_protocol::{cast, GetHeaders, SyncMessage}; use ckb_shared::index::ChainIndex; -use ckb_util::TryInto; use failure::Error as FailureError; use flatbuffers::FlatBufferBuilder; use log::{debug, info, warn}; use numext_fixed_hash::H256; +use std::convert::TryInto; pub struct GetHeadersProcess<'a, CI: ChainIndex + 'a> { message: &'a GetHeaders<'a>, diff --git a/sync/src/synchronizer/headers_process.rs b/sync/src/synchronizer/headers_process.rs index 3b1d606a1a..d1808f8d8a 100644 --- a/sync/src/synchronizer/headers_process.rs +++ b/sync/src/synchronizer/headers_process.rs @@ -1,15 +1,16 @@ use crate::synchronizer::{BlockStatus, Synchronizer}; +use crate::types::HeaderView; use crate::MAX_HEADERS_LEN; use ckb_core::{header::Header, BlockNumber}; use ckb_network::{CKBProtocolContext, PeerIndex}; use ckb_protocol::{cast, FlatbuffersVectorIterator, Headers}; use ckb_shared::index::ChainIndex; use ckb_traits::{BlockMedianTimeContext, ChainProvider}; -use ckb_util::TryInto; use ckb_verification::{Error as VerifyError, HeaderResolver, HeaderVerifier, Verifier}; use failure::Error as FailureError; use log::{self, debug, log_enabled, warn}; use numext_fixed_uint::U256; +use std::convert::TryInto; use std::sync::Arc; pub struct HeadersProcess<'a, CI: ChainIndex + 'a> { @@ -271,7 +272,7 @@ where own.hash(), own.total_difficulty(), self.peer, - peer_state.as_ref().map(|state| state.number()), + peer_state.as_ref().map(HeaderView::number), peer_state.as_ref().map(|state| format!("{:x}", state.hash())), peer_state.as_ref().map(|state| format!("{}", state.total_difficulty())), ); diff --git a/sync/src/synchronizer/mod.rs b/sync/src/synchronizer/mod.rs index bca271f5b5..e6a4a98922 100644 --- a/sync/src/synchronizer/mod.rs +++ b/sync/src/synchronizer/mod.rs @@ -337,7 +337,7 @@ impl Synchronizer { self.header_map .read() .get(hash) - .map(|view| view.inner()) + .map(HeaderView::inner) .cloned() .or_else(|| self.shared.block_header(hash)) } @@ -581,7 +581,7 @@ impl Synchronizer { chain_state.total_difficulty().clone(), ) }; - if best_known_header.map(|h| h.total_difficulty()) + if best_known_header.map(HeaderView::total_difficulty) >= Some(&local_total_difficulty) { if state.chain_sync.timeout != 0 { @@ -592,7 +592,7 @@ impl Synchronizer { } } else if state.chain_sync.timeout == 0 || (best_known_header.is_some() - && best_known_header.map(|h| h.total_difficulty()) + && best_known_header.map(HeaderView::total_difficulty) >= state.chain_sync.total_difficulty.as_ref()) { // Our best block known by this peer is behind our tip, and we're either noticing diff --git a/sync/src/tests/relayer.rs b/sync/src/tests/relayer.rs index 54d95ce875..6bb52d0732 100644 --- a/sync/src/tests/relayer.rs +++ b/sync/src/tests/relayer.rs @@ -6,7 +6,7 @@ use ckb_chain_spec::consensus::Consensus; use ckb_core::block::BlockBuilder; use ckb_core::header::HeaderBuilder; use ckb_core::script::Script; -use ckb_core::transaction::{CellInput, CellOutput, OutPoint, TransactionBuilder}; +use ckb_core::transaction::{CellInput, CellOutput, OutPoint, Transaction, TransactionBuilder}; use ckb_db::memorydb::MemoryKeyValueDB; use ckb_network::ProtocolId; use ckb_notify::NotifyService; @@ -249,7 +249,7 @@ fn relay_compact_block_with_missing_indexs() { BlockBuilder::default() .commit_transaction(cellbase) - .proposal_transactions(txs.iter().map(|tx| tx.proposal_short_id()).collect()) + .proposal_transactions(txs.iter().map(Transaction::proposal_short_id).collect()) .with_header_builder(header_builder) }; diff --git a/test/src/node.rs b/test/src/node.rs index 601894f9c3..f4a3495b61 100644 --- a/test/src/node.rs +++ b/test/src/node.rs @@ -5,12 +5,12 @@ use ckb_core::header::{HeaderBuilder, Seal}; use ckb_core::script::Script; use ckb_core::transaction::{CellInput, CellOutput, OutPoint, Transaction, TransactionBuilder}; use ckb_core::BlockNumber; -use ckb_util::TryInto; use jsonrpc_client_http::{HttpHandle, HttpTransport}; use jsonrpc_types::{BlockTemplate, CellbaseTemplate}; use log::info; use numext_fixed_hash::H256; use rand; +use std::convert::TryInto; use std::io::Error; use std::process::{Child, Command, Stdio}; diff --git a/test/src/specs/mining.rs b/test/src/specs/mining.rs index a6d402f631..701341e198 100644 --- a/test/src/specs/mining.rs +++ b/test/src/specs/mining.rs @@ -1,8 +1,8 @@ use crate::{Net, Spec}; use ckb_core::block::Block; use ckb_core::transaction::ProposalShortId; -use ckb_util::TryInto; use log::info; +use std::convert::TryInto; pub struct MiningBasic; diff --git a/test/src/specs/pool.rs b/test/src/specs/pool.rs index 7bfbbe3d98..af620507ce 100644 --- a/test/src/specs/pool.rs +++ b/test/src/specs/pool.rs @@ -1,5 +1,5 @@ use crate::{sleep, Net, Spec}; -use ckb_shared::tx_pool::trace::Action; +use ckb_shared::tx_pool::trace::{Action, TxTrace}; use log::info; pub struct PoolReconcile; @@ -83,7 +83,7 @@ impl Spec for PoolTrace { .unwrap() .unwrap() .iter() - .map(|trace| trace.action()) + .map(TxTrace::action) .cloned() .collect(); diff --git a/util/build-info/src/lib.rs b/util/build-info/src/lib.rs index 7e72605fa2..eacce8feca 100644 --- a/util/build-info/src/lib.rs +++ b/util/build-info/src/lib.rs @@ -22,8 +22,8 @@ macro_rules! get_version { }; let host_compiler = $crate::get_channel(); - let commit_describe = option_env!("COMMIT_DESCRIBE").map(|s| s.to_string()); - let commit_date = option_env!("COMMIT_DATE").map(|s| s.to_string()); + let commit_describe = option_env!("COMMIT_DESCRIBE").map(ToString::to_string); + let commit_date = option_env!("COMMIT_DATE").map(ToString::to_string); Version { major, minor, diff --git a/util/jsonrpc-types/src/block_template.rs b/util/jsonrpc-types/src/block_template.rs index 5cc989845c..371cefd88b 100644 --- a/util/jsonrpc-types/src/block_template.rs +++ b/util/jsonrpc-types/src/block_template.rs @@ -1,14 +1,13 @@ use crate::proposal_short_id::ProposalShortId; use crate::{Header, Transaction}; +use ckb_core::transaction::Transaction as CoreTransaction; +use ckb_core::uncle::UncleBlock as CoreUncleBlock; use ckb_core::{Cycle, Version}; -use ckb_util::{TryFrom, TryInto}; use failure::Error as FailureError; use numext_fixed_hash::H256; use numext_fixed_uint::U256; use serde_derive::{Deserialize, Serialize}; - -use ckb_core::transaction::Transaction as CoreTransaction; -use ckb_core::uncle::UncleBlock as CoreUncleBlock; +use std::convert::{TryFrom, TryInto}; #[derive(Clone, Default, Serialize, Deserialize, PartialEq, Eq, Hash, Debug)] pub struct BlockTemplate { diff --git a/util/jsonrpc-types/src/blockchain.rs b/util/jsonrpc-types/src/blockchain.rs index 8ba4f522bf..f7ecc7e84b 100644 --- a/util/jsonrpc-types/src/blockchain.rs +++ b/util/jsonrpc-types/src/blockchain.rs @@ -9,11 +9,11 @@ use ckb_core::transaction::{ }; use ckb_core::uncle::UncleBlock as CoreUncleBlock; use ckb_core::{BlockNumber, Capacity}; -use ckb_util::{TryFrom, TryInto}; use failure::Error as FailureError; use numext_fixed_hash::H256; use numext_fixed_uint::U256; use serde_derive::{Deserialize, Serialize}; +use std::convert::{TryFrom, TryInto}; #[derive(Clone, Default, Serialize, Deserialize, PartialEq, Eq, Hash, Debug)] pub struct Script { diff --git a/util/jsonrpc-types/src/proposal_short_id.rs b/util/jsonrpc-types/src/proposal_short_id.rs index 53a1c8d9ae..b2e64dccff 100644 --- a/util/jsonrpc-types/src/proposal_short_id.rs +++ b/util/jsonrpc-types/src/proposal_short_id.rs @@ -1,7 +1,7 @@ use ckb_core::transaction::ProposalShortId as CoreProposalShortId; -use ckb_util::TryFrom; use failure::Error as FailureError; use faster_hex::{hex_decode, hex_encode}; +use std::convert::TryFrom; use std::fmt; #[derive(Clone, Default, PartialEq, Eq, Hash, Debug)] diff --git a/util/src/lib.rs b/util/src/lib.rs index bf111fca80..4523c0f415 100644 --- a/util/src/lib.rs +++ b/util/src/lib.rs @@ -1,6 +1,3 @@ -mod unstable; - -pub use crate::unstable::{TryFrom, TryInto}; pub use parking_lot::{ self, Condvar, Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard, }; diff --git a/util/src/unstable/mod.rs b/util/src/unstable/mod.rs index 30abac43e2..e69de29bb2 100644 --- a/util/src/unstable/mod.rs +++ b/util/src/unstable/mod.rs @@ -1,3 +0,0 @@ -pub mod try_convert; - -pub use try_convert::{TryFrom, TryInto}; diff --git a/util/src/unstable/try_convert.rs b/util/src/unstable/try_convert.rs deleted file mode 100644 index cfe8a76dfd..0000000000 --- a/util/src/unstable/try_convert.rs +++ /dev/null @@ -1,28 +0,0 @@ -pub trait TryInto: Sized { - /// The type returned in the event of a conversion error. - type Error; - - /// Performs the conversion. - fn try_into(self) -> Result; -} - -/// Attempt to construct `Self` via a conversion. -pub trait TryFrom: Sized { - /// The type returned in the event of a conversion error. - type Error; - - /// Performs the conversion. - fn try_from(value: T) -> Result; -} - -// TryFrom implies TryInto -impl TryInto for T -where - U: TryFrom, -{ - type Error = U::Error; - - fn try_into(self) -> Result { - U::try_from(self) - } -} diff --git a/verification/Cargo.toml b/verification/Cargo.toml index 7a754a24e8..62c94cb11b 100644 --- a/verification/Cargo.toml +++ b/verification/Cargo.toml @@ -10,7 +10,6 @@ ckb-core = { path = "../core" } ckb-script = { path = "../script" } ckb-pow = { path = "../pow" } faketime = "0.2.0" -ckb-merkle-tree = {path = "../util/merkle-tree"} numext-fixed-hash = { version = "0.1", features = ["support_rand", "support_heapsize", "support_serde"] } numext-fixed-uint = { version = "0.1", features = ["support_rand", "support_heapsize", "support_serde"] } rayon = "1.0" diff --git a/verification/src/block_verifier.rs b/verification/src/block_verifier.rs index 338200e888..03eddb3fd8 100644 --- a/verification/src/block_verifier.rs +++ b/verification/src/block_verifier.rs @@ -3,10 +3,9 @@ use crate::header_verifier::HeaderResolver; use crate::{InputVerifier, TransactionVerifier, Verifier}; use ckb_core::cell::ResolvedTransaction; use ckb_core::header::Header; -use ckb_core::transaction::{Capacity, CellInput}; +use ckb_core::transaction::{Capacity, CellInput, Transaction}; use ckb_core::Cycle; use ckb_core::{block::Block, BlockNumber}; -use ckb_merkle_tree::merkle_root; use ckb_traits::{BlockMedianTimeContext, ChainProvider}; use fnv::FnvHashSet; use lru_cache::LruCache; @@ -308,13 +307,7 @@ impl UnclesVerifier { return Err(Error::Uncles(UnclesError::InvalidInclude(uncle_hash))); } - let proposals = uncle - .proposal_transactions() - .iter() - .map(|id| id.hash()) - .collect::>(); - - if uncle_header.txs_proposal() != &merkle_root(&proposals[..]) { + if uncle_header.txs_proposal() != &uncle.cal_txs_proposal_root() { return Err(Error::Uncles(UnclesError::ProposalTransactionsRoot)); } @@ -366,7 +359,7 @@ impl TransactionsVerifier { { // verify cellbase reward let cellbase = &resolved[0]; - let fee: Capacity = resolved.iter().skip(1).map(|rt| rt.fee()).sum(); + let fee: Capacity = resolved.iter().skip(1).map(ResolvedTransaction::fee).sum(); if cellbase.transaction.outputs_capacity() > block_reward + fee { return Err(Error::Cellbase(CellbaseError::InvalidReward)); } @@ -453,7 +446,7 @@ impl CommitVerifier { .commit_transactions() .par_iter() .skip(1) - .map(|tx| tx.proposal_short_id()) + .map(Transaction::proposal_short_id) .collect(); let difference: Vec<_> = committed_ids.difference(&proposal_txs_ids).collect(); diff --git a/verification/src/tests/commit_verifier.rs b/verification/src/tests/commit_verifier.rs index 2d3dbb07e5..37aa9abf78 100644 --- a/verification/src/tests/commit_verifier.rs +++ b/verification/src/tests/commit_verifier.rs @@ -128,7 +128,7 @@ fn test_proposal() { //proposal in block(1) let proposed = 1; - let proposal_ids: Vec<_> = txs20.iter().map(|tx| tx.proposal_short_id()).collect(); + let proposal_ids: Vec<_> = txs20.iter().map(Transaction::proposal_short_id).collect(); let block: Block = gen_block(&parent, vec![], proposal_ids, vec![]); chain_controller .process_block(Arc::new(block.clone())) @@ -189,7 +189,7 @@ fn test_uncle_proposal() { //proposal in block(1) let proposed = 1; - let proposal_ids: Vec<_> = txs20.iter().map(|tx| tx.proposal_short_id()).collect(); + let proposal_ids: Vec<_> = txs20.iter().map(Transaction::proposal_short_id).collect(); let uncle: Block = gen_block(&parent, vec![], proposal_ids, vec![]); let block: Block = gen_block(&parent, vec![], vec![], vec![uncle.into()]); chain_controller diff --git a/verification/src/transaction_verifier.rs b/verification/src/transaction_verifier.rs index 5439ff04e1..f1989a39f3 100644 --- a/verification/src/transaction_verifier.rs +++ b/verification/src/transaction_verifier.rs @@ -1,7 +1,7 @@ use crate::error::TransactionError; use ckb_core::transaction::{Capacity, Transaction, TX_VERSION}; use ckb_core::{ - cell::{CellMeta, ResolvedTransaction}, + cell::{CellMeta, CellStatus, ResolvedTransaction}, BlockNumber, Cycle, }; use ckb_script::TransactionScriptsVerifier; @@ -200,7 +200,7 @@ impl<'a> CapacityVerifier<'a> { .resolved_transaction .input_cells .iter() - .filter_map(|state| state.get_live()) + .filter_map(CellStatus::get_live) .fold(0, |acc, cell| acc + cell.cell_output.capacity); let outputs_total = self