Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
doitian committed Dec 13, 2019
2 parents 6ca7bbb + 800b2d6 commit 97e0bf8
Show file tree
Hide file tree
Showing 48 changed files with 5,854 additions and 2,559 deletions.
1,203 changes: 614 additions & 589 deletions Cargo.lock

Large diffs are not rendered by default.

19 changes: 10 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.25.2"
version = "0.26.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.25" }
ckb-hash = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.25" }
ckb-crypto = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.25", features = ["secp"] }
ckb-build-info = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.25" }
ckb-types = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.25" }
ckb-util = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.25" }
ckb-jsonrpc-types = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.26.0-rc2" }
ckb-hash = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.26.0-rc2" }
ckb-crypto = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.26.0-rc2", features = ["secp"] }
ckb-build-info = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.26.0-rc2" }
ckb-types = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.26.0-rc2" }
ckb-util = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.26.0-rc2" }
ckb-sdk = { path = "ckb-sdk" }
ckb-index = { path = "ckb-index" }
ckb-resource = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.25" }
ckb-resource = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.26.0-rc2" }

jsonrpc-client-core = "0.5.0"
secp256k1 = {version = "0.15.0" }
Expand All @@ -33,6 +33,7 @@ colored = "^1.6.0"
atty = "^0.2.10"
rustyline = "4.0.0"
shell-words = "0.1.0"
eaglesong = "0.1"
regex = "1.1.6"
dirs = "1.0.5"
url = "1.7.2"
Expand All @@ -47,7 +48,7 @@ tui = "0.6.0"
termion = "1.5"

[build-dependencies]
ckb-build-info = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.25" }
ckb-build-info = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.26.0-rc2" }

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

integration:
bash devtools/ci/integration.sh rc/v0.25
bash devtools/ci/integration.sh v0.25.1

prod: ## Build binary with release profile.
cargo build --release

security-audit: ## Use cargo-audit to audit Cargo.lock for crates with security vulnerabilities.
@cargo +nightly install cargo-audit -Z install-upgrade
@cargo +nightly install cargo-audit
cargo audit
# expecting to see "Success No vulnerable packages found"

Expand Down
4 changes: 2 additions & 2 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.25.2"
version = "0.26.0"
authors = ["Linfeng Qian <[email protected]>", "Nervos Core Dev <[email protected]>"]
edition = "2018"
license = "MIT"
Expand All @@ -11,7 +11,7 @@ serde_derive = "1.0"
bincode = "1.1.4"
log = "0.4.6"
failure = "0.1.5"
ckb-types = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.25" }
ckb-types = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.26.0-rc2" }
ckb-sdk = { path = "../ckb-sdk" }

[dependencies.rocksdb]
Expand Down
30 changes: 8 additions & 22 deletions ckb-index/src/index/key.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::types::{BlockDeltaInfo, CellIndex, HashType, HeaderInfo, LiveCellInfo, TxInfo};
use ckb_sdk::{Address, NetworkType};
use ckb_sdk::NetworkType;
use ckb_types::{
packed::{Header, OutPoint, Script},
prelude::*,
Expand All @@ -24,8 +24,6 @@ pub enum KeyType {
GlobalHash = 100,
// key => value: {type}:{tx-hash} => {TxInfo}
TxMap = 101,
// key => value: {type}:{Address} => {lock-hash}
SecpAddrLock = 102,
// >> Save recent headers for rollback a fork and for statistics
// key => value: {type}:{block-number} => {HeaderInfo}
RecentHeader = 103,
Expand Down Expand Up @@ -72,7 +70,6 @@ impl KeyType {

100 => KeyType::GlobalHash,
101 => KeyType::TxMap,
102 => KeyType::SecpAddrLock,
103 => KeyType::RecentHeader,
104 => KeyType::BlockDelta,

Expand Down Expand Up @@ -102,7 +99,6 @@ pub enum Key {

GlobalHash(H256),
TxMap(H256),
SecpAddrLock(Address),
RecentHeader(u64),
BlockDelta(u64),

Expand Down Expand Up @@ -139,11 +135,6 @@ impl Key {
bytes.extend(tx_hash.as_bytes().to_vec());
bytes
}
Key::SecpAddrLock(address) => {
let mut bytes = KeyType::SecpAddrLock.to_bytes();
bytes.extend(bincode::serialize(address).unwrap());
bytes
}
Key::RecentHeader(number) => {
let mut bytes = KeyType::RecentHeader.to_bytes();
bytes.extend(number.to_be_bytes().to_vec());
Expand Down Expand Up @@ -262,10 +253,6 @@ impl Key {
let tx_hash = H256::from_slice(args_bytes).unwrap();
Key::TxMap(tx_hash)
}
KeyType::SecpAddrLock => {
let address = bincode::deserialize(args_bytes).unwrap();
Key::SecpAddrLock(address)
}
KeyType::RecentHeader => {
assert_eq!(args_bytes.len(), 8);
let mut number_bytes = [0u8; 8];
Expand Down Expand Up @@ -364,7 +351,6 @@ impl Key {
Key::TotalCapacity => KeyType::TotalCapacity,
Key::GlobalHash(..) => KeyType::GlobalHash,
Key::TxMap(..) => KeyType::TxMap,
Key::SecpAddrLock(..) => KeyType::SecpAddrLock,
Key::RecentHeader(..) => KeyType::RecentHeader,
Key::BlockDelta(..) => KeyType::BlockDelta,
Key::LiveCellMap(..) => KeyType::LiveCellMap,
Expand All @@ -386,7 +372,13 @@ impl Key {
(Key::GenesisHash.to_bytes(), value.as_bytes().to_vec())
}
pub(crate) fn pair_network(value: NetworkType) -> (Vec<u8>, Vec<u8>) {
(Key::Network.to_bytes(), vec![value as u8])
let value_byte = match value {
NetworkType::Mainnet => 0,
NetworkType::Testnet => 1,
NetworkType::Staging => 254,
NetworkType::Dev => 255,
};
(Key::Network.to_bytes(), vec![value_byte])
}
pub(crate) fn pair_last_header(value: &Header) -> (Vec<u8>, Vec<u8>) {
(Key::LastHeader.to_bytes(), value.as_slice().to_vec())
Expand All @@ -404,12 +396,6 @@ impl Key {
bincode::serialize(value).unwrap(),
)
}
pub(crate) fn pair_secp_addr_lock(address: Address, value: &H256) -> (Vec<u8>, Vec<u8>) {
(
Key::SecpAddrLock(address).to_bytes(),
value.as_bytes().to_vec(),
)
}
pub(crate) fn pair_recent_header(value: &HeaderInfo) -> (Vec<u8>, Vec<u8>) {
(
Key::RecentHeader(value.header().number()).to_bytes(),
Expand Down
37 changes: 12 additions & 25 deletions ckb-index/src/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::collections::BTreeMap;
use std::fmt;
use std::io;

use ckb_sdk::{Address, GenesisInfo, NetworkType};
use ckb_sdk::{AddressPayload, GenesisInfo, NetworkType};
use ckb_types::{
core::{BlockView, HeaderView},
packed::{Byte32, Header, OutPoint, Script},
Expand Down Expand Up @@ -51,7 +51,13 @@ impl<'a> IndexDatabase<'a> {
.map(|bytes| Byte32::from_slice(&bytes).unwrap());
let network_opt = reader
.get(&Key::Network.to_bytes())
.map(|bytes| NetworkType::from_u8(bytes[0]).unwrap());
.map(|bytes| match bytes[0] {
0 => NetworkType::Mainnet,
1 => NetworkType::Testnet,
254 => NetworkType::Staging,
255 => NetworkType::Dev,
_ => panic!("Corrupted index database (network field)"),
});
(genesis_hash_opt, network_opt)
};
if let Some(genesis_hash) = genesis_hash_opt {
Expand Down Expand Up @@ -160,13 +166,10 @@ impl<'a> IndexDatabase<'a> {
self.last_number().map(|number| number + 1)
}

fn get_address_inner(&self, reader: &RocksReader, lock_hash: Byte32) -> Option<Address> {
fn get_address_inner(&self, reader: &RocksReader, lock_hash: Byte32) -> Option<AddressPayload> {
reader
.get(&Key::LockScript(lock_hash.unpack()).to_bytes())
.and_then(|bytes| {
let script = Script::new_unchecked(bytes.into());
Address::from_lock_arg(&script.args().raw_data()).ok()
})
.map(|bytes| AddressPayload::from(Script::new_unchecked(bytes.into())))
}

pub fn get_capacity(&self, lock_hash: Byte32) -> Option<u64> {
Expand All @@ -180,25 +183,13 @@ impl<'a> IndexDatabase<'a> {
})
}

pub fn get_lock_hash_by_address(&self, address: Address) -> Option<Byte32> {
let reader = RocksReader::new(self.db, self.cf);
reader
.get(&Key::SecpAddrLock(address).to_bytes())
.map(|bytes| Byte32::from_slice(&bytes).unwrap())
}

pub fn get_lock_script_by_hash(&self, lock_hash: Byte32) -> Option<Script> {
let reader = RocksReader::new(self.db, self.cf);
reader
.get(&Key::LockScript(lock_hash.unpack()).to_bytes())
.map(|bytes| Script::new_unchecked(bytes.into()))
}

// pub fn get_address(&self, lock_hash: Byte32) -> Option<Address> {
// let reader = env_read.read().unwrap();
// self.get_address_inner(&reader, lock_hash)
// }

pub fn get_live_cells_by_lock<F: FnMut(usize, &LiveCellInfo) -> (bool, bool)>(
&self,
lock_hash: Byte32,
Expand Down Expand Up @@ -268,7 +259,7 @@ impl<'a> IndexDatabase<'a> {
infos
}

pub fn get_top_n(&self, n: usize) -> Vec<(Byte32, Option<Address>, u64)> {
pub fn get_top_n(&self, n: usize) -> Vec<(Byte32, Option<AddressPayload>, u64)> {
let reader = RocksReader::new(self.db, self.cf);
let key_prefix: Vec<u8> = KeyType::LockTotalCapacityIndex.to_bytes();

Expand Down Expand Up @@ -311,12 +302,9 @@ impl<'a> IndexDatabase<'a> {
blocks
};

let secp_data_hash = self.genesis_info.secp_data_hash();
let secp_type_hash = self.genesis_info.secp_type_hash();
let mut txn = RocksTxn::new(self.db, self.cf);
for block in blocks {
let block_delta_info =
BlockDeltaInfo::from_block(&block, &txn, secp_data_hash, secp_type_hash);
let block_delta_info = BlockDeltaInfo::from_block(&block, &txn);
let number = block_delta_info.number();
let hash = block_delta_info.hash();
let result = block_delta_info.apply(&mut txn, self.enable_explorer);
Expand Down Expand Up @@ -344,7 +332,6 @@ impl<'a> IndexDatabase<'a> {
KeyType::Network,
KeyType::LastHeader,
KeyType::TotalCapacity,
KeyType::SecpAddrLock,
KeyType::RecentHeader,
KeyType::BlockDelta,
KeyType::LiveCellMap,
Expand Down
13 changes: 2 additions & 11 deletions ckb-index/src/index/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use serde_derive::{Deserialize, Serialize};

use super::key::{Key, KeyType};
use crate::{KVReader, KVTxn};
use ckb_sdk::Address;

const KEEP_RECENT_HEADERS: u64 = 10_000;
const KEEP_RECENT_BLOCKS: u64 = 200;
Expand Down Expand Up @@ -65,8 +64,6 @@ impl BlockDeltaInfo {
pub(crate) fn from_block<'r, T: KVReader<'r>>(
block: &BlockView,
reader: &'r T,
_secp_data_hash: &Byte32,
secp_type_hash: &Byte32,
) -> BlockDeltaInfo {
let block_header: HeaderView = block.header().clone();
let block_number = block_header.number();
Expand Down Expand Up @@ -193,7 +190,7 @@ impl BlockDeltaInfo {
.unwrap_or(0);
LockInfo::new(lock_capacity)
});
lock_info.set_script(lock.clone(), secp_type_hash);
lock_info.set_script(lock.clone());
lock_info.add_output(capacity);
}

Expand Down Expand Up @@ -349,7 +346,6 @@ impl BlockDeltaInfo {
for (lock_hash, info) in &self.locks {
let LockInfo {
script_opt,
address_opt,
old_total_capacity,
new_total_capacity,
..
Expand All @@ -363,9 +359,6 @@ impl BlockDeltaInfo {
&Script::new_unchecked(script.clone()),
));
}
if let Some(address) = address_opt {
txn.put_pair(Key::pair_secp_addr_lock(address.clone(), &lock_hash));
}

if old_total_capacity != new_total_capacity {
log::debug!(
Expand Down Expand Up @@ -541,7 +534,6 @@ impl BlockDeltaInfo {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LockInfo {
script_opt: Option<Bytes>,
address_opt: Option<Address>,
old_total_capacity: u64,
new_total_capacity: u64,
inputs_capacity: u64,
Expand All @@ -552,15 +544,14 @@ impl LockInfo {
fn new(old_total_capacity: u64) -> LockInfo {
LockInfo {
script_opt: None,
address_opt: None,
old_total_capacity,
new_total_capacity: old_total_capacity,
inputs_capacity: 0,
outputs_capacity: 0,
}
}

fn set_script(&mut self, script: Script, _secp_type_hash: &Byte32) {
fn set_script(&mut self, script: Script) {
self.script_opt = Some(script.as_slice().into());
}

Expand Down
3 changes: 2 additions & 1 deletion ckb-index/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ pub use index::{
pub use kvdb::{KVReader, KVTxn, RocksReader, RocksTxn};
pub use util::{with_index_db, with_rocksdb};

const ROCKSDB_COL_INDEX_DB: &str = "index-db";
pub const ROCKSDB_COL_INDEX_DB: &str = "index-db";
pub const VERSION: usize = 1;
14 changes: 7 additions & 7 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.25.2"
version = "0.26.0"
authors = ["Linfeng Qian <[email protected]>", "Nervos Core Dev <[email protected]>"]
edition = "2018"
license = "MIT"
Expand All @@ -9,14 +9,14 @@ license = "MIT"
serde = { version = "1.0", features = ["rc"] }
serde_derive = "1.0"

ckb-types = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.25" }
ckb-script = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.25", default-features = false }
ckb-jsonrpc-types = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.25" }
ckb-hash = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.25" }
ckb-error = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.25" }
ckb-types = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.26.0-rc2" }
ckb-script = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.26.0-rc2", default-features = false }
ckb-jsonrpc-types = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.26.0-rc2" }
ckb-hash = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.26.0-rc2" }
ckb-error = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.26.0-rc2" }

[dev-dependencies]
ckb-crypto = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.25", features = ["secp"] }
ckb-crypto = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.26.0-rc2", features = ["secp"] }

[features]
default = ["ckb-script/default"]
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.25.2"
version = "0.26.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.25" }
ckb-script = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.25" }
ckb-jsonrpc-types = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.25" }
ckb-hash = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.25" }
ckb-resource = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.25" }
ckb-crypto = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.25", features = ["secp"] }
ckb-types = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.26.0-rc2" }
ckb-script = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.26.0-rc2" }
ckb-jsonrpc-types = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.26.0-rc2" }
ckb-hash = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.26.0-rc2" }
ckb-resource = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.26.0-rc2" }
ckb-crypto = { git = "https://github.com/nervosnetwork/ckb", tag = "v0.26.0-rc2", features = ["secp"] }
ckb-sdk-types = { path = "../ckb-sdk-types" }
Loading

0 comments on commit 97e0bf8

Please sign in to comment.