Skip to content

Commit

Permalink
Merge pull request #95 from TheWaWaR/update-ckb-to-v0.21
Browse files Browse the repository at this point in the history
chore: Update ckb to rc/v0.21
  • Loading branch information
doitian authored Sep 21, 2019
2 parents ac35220 + df1cd48 commit 90bc747
Show file tree
Hide file tree
Showing 22 changed files with 932 additions and 923 deletions.
1,533 changes: 753 additions & 780 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[package]
name = "ckb-cli"
version = "0.20.0"
version = "0.21.0"
license = "MIT"
authors = ["Linfeng Qian <[email protected]>", "Nervos Core Dev <[email protected]>"]
edition = "2018"

[dependencies]
ckb-jsonrpc-types = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.20" }
ckb-hash = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.20" }
ckb-crypto = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.20", features = ["secp"] }
ckb-build-info = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.20" }
ckb-types = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.20" }
ckb-util = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.20" }
ckb-jsonrpc-types = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.21" }
ckb-hash = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.21" }
ckb-crypto = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.21", features = ["secp"] }
ckb-build-info = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.21" }
ckb-types = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.21" }
ckb-util = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.21" }
ckb-sdk = { path = "ckb-sdk" }
ckb-index = { path = "ckb-index" }
ckb-resource = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.20" }
ckb-resource = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.21" }

jsonrpc-client-core = "0.5.0"
secp256k1 = {version = "0.15.0" }
Expand Down Expand Up @@ -47,7 +47,7 @@ tui = "0.6.0"
termion = "1.5"

[build-dependencies]
ckb-build-info = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.20" }
ckb-build-info = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.21" }

[workspace]
members = ["ckb-sdk", "ckb-index", "ckb-sdk-types"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ci: fmt clippy test
git diff --exit-code Cargo.lock

integration:
bash devtools/ci/integration.sh rc/v0.20
bash devtools/ci/integration.sh rc/v0.21

prod: ## Build binary with release profile.
cargo build --release
10 changes: 6 additions & 4 deletions ckb-index/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ckb-index"
version = "0.20.0"
version = "0.21.0"
authors = ["Linfeng Qian <[email protected]>", "Nervos Core Dev <[email protected]>"]
edition = "2018"
license = "MIT"
Expand All @@ -10,8 +10,10 @@ serde = { version = "1.0", features = ["rc"] }
serde_derive = "1.0"
bincode = "1.1.4"
log = "0.4.6"
rocksdb = { version = "0.12.2", default-features = false }
failure = "0.1.5"

ckb-types = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.20" }
ckb-types = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.21" }
ckb-sdk = { path = "../ckb-sdk" }

[dependencies.rocksdb]
git = "https://github.com/nervosnetwork/rust-rocksdb"
rev = "14d2991"
4 changes: 2 additions & 2 deletions ckb-index/src/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use types::BlockDeltaInfo;
// [reference]: https://stackoverflow.com/a/33571804
pub struct IndexDatabase<'a> {
db: &'a DB,
cf: ColumnFamily<'a>,
cf: &'a ColumnFamily,
// network: NetworkType,
genesis_info: GenesisInfo,
last_header: Option<HeaderView>,
Expand All @@ -37,7 +37,7 @@ pub struct IndexDatabase<'a> {
impl<'a> IndexDatabase<'a> {
pub fn from_db(
db: &'a DB,
cf: ColumnFamily<'a>,
cf: &'a ColumnFamily,
network: NetworkType,
genesis_info: GenesisInfo,
enable_explorer: bool,
Expand Down
13 changes: 7 additions & 6 deletions ckb-index/src/kvdb/rocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ use std::collections::{BTreeMap, HashMap};
use std::mem;
use std::ops::Bound;

use rocksdb::ops::{GetCF, IterateCF, WriteOps};
use rocksdb::{ColumnFamily, DBIterator, Direction, IteratorMode, WriteBatch, DB};

use super::{KVReader, KVTxn};

pub struct RocksReader<'a> {
cf: ColumnFamily<'a>,
cf: &'a ColumnFamily,
db: &'a DB,
}

impl<'a> RocksReader<'a> {
pub fn new(db: &'a DB, cf: ColumnFamily<'a>) -> RocksReader<'a> {
pub fn new(db: &'a DB, cf: &'a ColumnFamily) -> RocksReader<'a> {
RocksReader { db, cf }
}
}
Expand Down Expand Up @@ -49,14 +50,14 @@ impl<'a> Iterator for ReaderIter<'a> {
}

pub struct RocksTxn<'a> {
cf: ColumnFamily<'a>,
cf: &'a ColumnFamily,
db: &'a DB,
removed: HashMap<Vec<u8>, bool>,
inserted: BTreeMap<Vec<u8>, Vec<u8>>,
}

impl<'a> RocksTxn<'a> {
pub fn new(db: &'a DB, cf: ColumnFamily<'a>) -> RocksTxn<'a> {
pub fn new(db: &'a DB, cf: &'a ColumnFamily) -> RocksTxn<'a> {
RocksTxn {
cf,
db,
Expand Down Expand Up @@ -141,7 +142,7 @@ impl<'a> TxnIter<'a> {
let mode = IteratorMode::From(key_start, Direction::Forward);
let iter = txn
.db
.iterator_cf(txn.cf, mode)
.iterator_cf(&txn.cf, mode)
.expect("RocksReader iterator_cf failed");
let mut reader_iter = ReaderIter { iter };
let next_mem_pair = txn
Expand Down Expand Up @@ -204,7 +205,7 @@ impl<'a> Iterator for TxnIter<'a> {
}
}

fn get_cf(db: &DB, cf: ColumnFamily, key: &[u8]) -> Option<Vec<u8>> {
fn get_cf(db: &DB, cf: &ColumnFamily, key: &[u8]) -> Option<Vec<u8>> {
db.get_cf(cf, key)
.expect("RocksReader get_cf failed")
.map(|value| value.to_vec())
Expand Down
14 changes: 8 additions & 6 deletions ckb-index/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use std::thread;
use std::time::{Duration, Instant};

use ckb_types::H256;
use rocksdb::{ColumnFamily, Options, DB};
use rocksdb::{
ops::{GetColumnFamilys, OpenCF},
ColumnFamily, Options, DB,
};

use crate::{Error, ROCKSDB_COL_INDEX_DB};

Expand Down Expand Up @@ -42,16 +45,15 @@ where
pub fn with_index_db<P, T, F>(path: P, genesis_hash: H256, func: F) -> Result<T, Error>
where
P: AsRef<Path>,
F: FnOnce(&DB, ColumnFamily) -> Result<T, Error>,
F: FnOnce(&DB, &ColumnFamily) -> Result<T, Error>,
{
let mut directory = path.as_ref().to_path_buf();
directory.push(format!("{:#x}", genesis_hash));
std::fs::create_dir_all(&directory)?;
with_rocksdb(directory, None, |db| {
let cf = db.cf_handle(ROCKSDB_COL_INDEX_DB).unwrap_or_else(|| {
db.create_cf(ROCKSDB_COL_INDEX_DB, &Options::default())
.unwrap_or_else(|_| panic!("Create ColumnFamily {} failed", ROCKSDB_COL_INDEX_DB))
});
let cf = db
.cf_handle(ROCKSDB_COL_INDEX_DB)
.expect("Get ColumnFamily failed");
func(db, cf)
})
}
13 changes: 7 additions & 6 deletions ckb-sdk-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ckb-sdk-types"
version = "0.20.0"
version = "0.21.0"
authors = ["Linfeng Qian <[email protected]>", "Nervos Core Dev <[email protected]>"]
edition = "2018"
license = "MIT"
Expand All @@ -9,10 +9,11 @@ license = "MIT"
serde = { version = "1.0", features = ["rc"] }
serde_derive = "1.0"

ckb-types = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.20" }
ckb-script = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.20" }
ckb-jsonrpc-types = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.20" }
ckb-hash = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.20" }
ckb-types = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.21" }
ckb-script = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.21" }
ckb-jsonrpc-types = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.21" }
ckb-hash = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.21" }
ckb-error = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.21" }

[dev-dependencies]
ckb-crypto = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.20", features = ["secp"] }
ckb-crypto = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.21", features = ["secp"] }
8 changes: 6 additions & 2 deletions ckb-sdk-types/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use ckb_types::{
bytes::Bytes,
core::{
cell::{CellMeta, CellMetaBuilder, CellProvider, CellStatus, HeaderChecker},
error::OutPointError,
BlockExt, DepType, EpochExt, HeaderView, TransactionView,
},
packed::{Byte32, CellDep, CellInput, CellOutput, OutPoint, OutPointVec, Transaction},
Expand Down Expand Up @@ -167,8 +168,11 @@ impl Resource {
}

impl<'a> HeaderChecker for Resource {
fn is_valid(&self, block_hash: &Byte32) -> bool {
self.required_headers.contains_key(block_hash)
fn check_valid(&self, block_hash: &Byte32) -> Result<(), ckb_error::Error> {
if !self.required_headers.contains_key(block_hash) {
return Err(OutPointError::InvalidHeader(block_hash.clone()).into());
}
Ok(())
}
}

Expand Down
14 changes: 7 additions & 7 deletions ckb-sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ckb-sdk"
version = "0.20.0"
version = "0.21.0"
authors = ["Linfeng Qian <[email protected]>", "Nervos Core Dev <[email protected]>"]
edition = "2018"
license = "MIT"
Expand All @@ -27,10 +27,10 @@ chrono = "0.4.6"
failure = "0.1.5"
lazy_static = "1.4.0"

ckb-types = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.20" }
ckb-script = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.20" }
ckb-jsonrpc-types = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.20" }
ckb-hash = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.20" }
ckb-resource = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.20" }
ckb-crypto = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.20", features = ["secp"] }
ckb-types = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.21" }
ckb-script = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.21" }
ckb-jsonrpc-types = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.21" }
ckb-hash = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.21" }
ckb-resource = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.21" }
ckb-crypto = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.21", features = ["secp"] }
ckb-sdk-types = { path = "../ckb-sdk-types" }
18 changes: 9 additions & 9 deletions ckb-sdk/src/rpc/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ckb_jsonrpc_types::{
BannedAddress, BlockNumber, BlockReward, BlockView, CellOutputWithOutPoint, CellTransaction,
BannedAddr, BlockNumber, BlockReward, BlockView, CellOutputWithOutPoint, CellTransaction,
CellWithStatus, ChainInfo, EpochNumber, EpochView, HeaderView, LiveCell, LockHashIndexState,
Node, OutPoint, PeerState, Timestamp, Transaction, TransactionWithStatus, TxPoolInfo, Unsigned,
Node, OutPoint, PeerState, Timestamp, Transaction, TransactionWithStatus, TxPoolInfo, Uint64,
};
use jsonrpc_client_core::{expand_params, jsonrpc_client};
use jsonrpc_client_http::{HttpHandle, HttpTransport};
Expand Down Expand Up @@ -34,7 +34,7 @@ pub struct OptionEpochView(pub Option<EpochView>);
pub struct PeerStates(pub Vec<PeerState>);

#[derive(Serialize, Deserialize)]
pub struct BannedAddresses(pub Vec<BannedAddress>);
pub struct BannedAddres(pub Vec<BannedAddr>);

#[derive(Serialize, Deserialize)]
pub struct OptionBlockReward(pub Option<BlockReward>);
Expand All @@ -56,7 +56,7 @@ jsonrpc_client!(pub struct RpcClient {
pub fn get_epoch_by_number(&mut self, number: EpochNumber) -> RpcRequest<OptionEpochView>;
pub fn get_header(&mut self, hash: H256) -> RpcRequest<OptionHeaderView>;
pub fn get_header_by_number(&mut self, number: BlockNumber) -> RpcRequest<OptionHeaderView>;
pub fn get_live_cell(&mut self, out_point: OutPoint) -> RpcRequest<CellWithStatus>;
pub fn get_live_cell(&mut self, out_point: OutPoint, with_data: bool) -> RpcRequest<CellWithStatus>;
pub fn get_tip_block_number(&mut self) -> RpcRequest<BlockNumber>;
pub fn get_tip_header(&mut self) -> RpcRequest<HeaderView>;
pub fn get_transaction(&mut self, hash: H256) -> RpcRequest<OptionTransactionWithStatus>;
Expand All @@ -66,15 +66,15 @@ jsonrpc_client!(pub struct RpcClient {
pub fn get_live_cells_by_lock_hash(
&mut self,
lock_hash: H256,
page: Unsigned,
per_page: Unsigned,
page: Uint64,
per_page: Uint64,
reverse_order: Option<bool>
) -> RpcRequest<LiveCells>;
pub fn get_transactions_by_lock_hash(
&mut self,
lock_hash: H256,
page: Unsigned,
per_page: Unsigned,
page: Uint64,
per_page: Uint64,
reverse_order: Option<bool>
) -> RpcRequest<CellTransactions>;
pub fn index_lock_hash(
Expand All @@ -84,7 +84,7 @@ jsonrpc_client!(pub struct RpcClient {
) -> RpcRequest<LockHashIndexState>;

// Net
pub fn get_banned_addresses(&mut self) -> RpcRequest<BannedAddresses>;
pub fn get_banned_addresses(&mut self) -> RpcRequest<BannedAddres>;
pub fn get_peers(&mut self) -> RpcRequest<Nodes>;
pub fn local_node_info(&mut self) -> RpcRequest<Node>;
pub fn set_ban(
Expand Down
Loading

0 comments on commit 90bc747

Please sign in to comment.