Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
282 changes: 156 additions & 126 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ reqwest = "0.12"

# crypto & hash
#fixed-hash = "0.5"
keccak-hash = "0.5"
keccak-hash = "0.11.0"
tiny-keccak = "2.0.2"
bls-signatures = { git = "https://github.com/Conflux-Chain/bls-signatures.git", rev = "fb52187df92d27c365642cb7e7b2aaf60437cf9c", default-features = false, features = [
"multicore",
Expand Down Expand Up @@ -423,12 +423,12 @@ chrono = "0.4"
duration-str = "0.17"

# parity crates
rlp = "0.4.0"
rlp = "0.6.1"
rlp_derive = { package = "rlp-derive", version = "0.2.0" }
panic_hook = { git = "https://github.com/Conflux-Chain/conflux-parity-deps.git", rev = "09da4dfeecd754df2034d4e71a260277aaaf9783" }
dir = { git = "https://github.com/Conflux-Chain/conflux-parity-deps.git", rev = "09da4dfeecd754df2034d4e71a260277aaaf9783" }
unexpected = { git = "https://github.com/Conflux-Chain/conflux-parity-deps.git", rev = "09da4dfeecd754df2034d4e71a260277aaaf9783" }
ethereum-types = "0.9"
ethereum-types = "0.15.1"
parity-wordlist = "1.3.0"
parity-crypto = "0.9.0"
parity-path = "0.1"
Expand Down
2 changes: 1 addition & 1 deletion crates/cfx_key/src/extended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ mod derivation {

// 0x00 (padding) -- private_key -- index
// 0 -- 1..33 -- 33..end
private.to_big_endian(&mut data[1..33]);
private.write_as_big_endian(&mut data[1..33]);
index.store(&mut data[33..(33 + T::len())]);

hmac_pair(&data, private_key, chain_code)
Expand Down
2 changes: 1 addition & 1 deletion crates/cfx_types/src/contract_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn cal_contract_address(
// future.
buffer[0] = 0x0;
buffer[1..(1 + 20)].copy_from_slice(&sender[..]);
nonce.to_little_endian(&mut buffer[(1 + 20)..(1 + 20 + 32)]);
nonce.write_as_little_endian(&mut buffer[(1 + 20)..(1 + 20 + 32)]);
buffer[(1 + 20 + 32)..].copy_from_slice(&code_hash[..]);
// In Conflux, we use the first four bits to indicate the type of
// the address. For contract address, the bits will be
Expand Down
2 changes: 1 addition & 1 deletion crates/cfx_types/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn parse_hex_string<F: FromStr>(hex_str: &str) -> Result<F, F::Err> {

pub fn u256_to_h256_be(value: U256) -> H256 {
let mut buf = [0u8; 32];
value.to_big_endian(&mut buf);
value.write_as_big_endian(&mut buf);
H256::from(buf)
}

Expand Down
2 changes: 1 addition & 1 deletion crates/cfxcore/core/examples/snapshot_merge_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ fn main() -> Result<(), Error> {
assert!(value.is_some(), "Address {:?} does not exist", addr);
let account_bytes = rlp::encode(account);
let get_bytes = value.unwrap();
assert_eq!(account_bytes.as_slice(), get_bytes.as_ref());
assert_eq!(account_bytes.as_ref(), get_bytes.as_ref());
}
// TODO Make snapshot3 to compare the snapshot merkle_root
let state_root_3 = StateRootWithAuxInfo::genesis(&MERKLE_NULL_NODE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl<Version: Decodable, T: Decodable> Decodable
impl<Version: Encodable, T: Encodable> DatabaseEncodable
for DataVersionTuple<Version, T>
{
fn db_encode(&self) -> Vec<u8> { rlp::encode(self) }
fn db_encode(&self) -> Vec<u8> { rlp::encode(self).into() }
}

impl<Version: Decodable, T: Decodable> DatabaseDecodable
Expand Down Expand Up @@ -370,7 +370,7 @@ where T: DatabaseEncodable {
for e in list {
rlp_stream.append_raw(&e.db_encode(), 1);
}
rlp_stream.drain()
rlp_stream.as_raw().into()
}

pub fn db_decode_list<T>(bytes: &[u8]) -> Result<Vec<T>, DecoderError>
Expand Down
2 changes: 1 addition & 1 deletion crates/cfxcore/core/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ macro_rules! build_msg_basic {
fn msg_name(&self) -> &'static str { $name_str }

fn encode(&self) -> Vec<u8> {
let mut encoded = self.rlp_bytes();
let mut encoded = self.rlp_bytes().into();
self.push_msg_id_leb128_encoding(&mut encoded);
encoded
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl VrfProposer {
proposal_threshold_u256: U256, epoch_state: EpochState,
) -> Self {
let mut proposal_threshold = [0 as u8; HashValue::LENGTH];
proposal_threshold_u256.to_big_endian(&mut proposal_threshold);
proposal_threshold_u256.write_as_big_endian(&mut proposal_threshold);
Self {
author,
vrf_private_key,
Expand Down
6 changes: 3 additions & 3 deletions crates/cfxcore/core/src/pow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,13 @@ impl ProofOfWorkConfig {
// withholding attack among mining pools.
pub fn nonce_to_lower_bound(nonce: &U256) -> U256 {
let mut buf = [0u8; 32];
nonce.to_big_endian(&mut buf[..]);
nonce.write_as_big_endian(&mut buf[..]);
for i in 16..32 {
buf[i] = 0;
}
buf[0] = buf[0] & 0x7f;
// Note that U256::from assumes big_endian of the bytes
let lower_bound = U256::from(buf);
let lower_bound = U256::from_big_endian(buf.as_ref());
lower_bound
}

Expand Down Expand Up @@ -291,7 +291,7 @@ impl PowComputer {
for i in 0..32 {
buf[i] = block_hash[i];
}
nonce.to_little_endian(&mut buf[32..64]);
nonce.write_as_little_endian(&mut buf[32..64]);
let intermediate = keccak_hash(&buf[..]);
let mut tmp = [0u8; 32];
for i in 0..32 {
Expand Down
16 changes: 8 additions & 8 deletions crates/cfxcore/core/src/sync/message/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl Message for GetBlockHashesResponse {
fn priority(&self) -> SendQueuePriority { SendQueuePriority::Low }

fn encode(&self) -> Vec<u8> {
let mut encoded = self.rlp_bytes();
let mut encoded = self.rlp_bytes().into();
self.push_msg_id_leb128_encoding(&mut encoded);
encoded
}
Expand All @@ -112,7 +112,7 @@ impl Message for Transactions {
fn msg_name(&self) -> &'static str { "Transactions" }

fn encode(&self) -> Vec<u8> {
let mut encoded = self.rlp_bytes();
let mut encoded = self.rlp_bytes().into();
self.push_msg_id_leb128_encoding(&mut encoded);
encoded
}
Expand All @@ -128,7 +128,7 @@ impl Message for GetBlocksResponse {
fn msg_name(&self) -> &'static str { "GetBlocksResponse" }

fn encode(&self) -> Vec<u8> {
let mut encoded = self.rlp_bytes();
let mut encoded = self.rlp_bytes().into();
self.push_msg_id_leb128_encoding(&mut encoded);
encoded
}
Expand All @@ -148,7 +148,7 @@ impl Message for GetBlocksWithPublicResponse {
fn msg_name(&self) -> &'static str { "GetBlocksWithPublicResponse" }

fn encode(&self) -> Vec<u8> {
let mut encoded = self.rlp_bytes();
let mut encoded = self.rlp_bytes().into();
self.push_msg_id_leb128_encoding(&mut encoded);
encoded
}
Expand All @@ -164,7 +164,7 @@ impl Message for GetBlockTxnResponse {
fn msg_name(&self) -> &'static str { "GetBlockTxnResponse" }

fn encode(&self) -> Vec<u8> {
let mut encoded = self.rlp_bytes();
let mut encoded = self.rlp_bytes().into();
self.push_msg_id_leb128_encoding(&mut encoded);
encoded
}
Expand All @@ -182,7 +182,7 @@ impl Message for TransactionDigests {
fn priority(&self) -> SendQueuePriority { SendQueuePriority::Normal }

fn encode(&self) -> Vec<u8> {
let mut encoded = self.rlp_bytes();
let mut encoded = self.rlp_bytes().into();
self.push_msg_id_leb128_encoding(&mut encoded);
encoded
}
Expand All @@ -200,7 +200,7 @@ impl Message for GetTransactionsResponse {
fn priority(&self) -> SendQueuePriority { SendQueuePriority::Normal }

fn encode(&self) -> Vec<u8> {
let mut encoded = self.rlp_bytes();
let mut encoded = self.rlp_bytes().into();
self.push_msg_id_leb128_encoding(&mut encoded);
encoded
}
Expand All @@ -223,7 +223,7 @@ impl Message for GetTransactionsFromTxHashesResponse {
fn priority(&self) -> SendQueuePriority { SendQueuePriority::Normal }

fn encode(&self) -> Vec<u8> {
let mut encoded = self.rlp_bytes();
let mut encoded = self.rlp_bytes().into();
self.push_msg_id_leb128_encoding(&mut encoded);
encoded
}
Expand Down
4 changes: 2 additions & 2 deletions crates/cfxcore/core/src/sync/message/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ impl Message for GetTransactions {
fn priority(&self) -> SendQueuePriority { SendQueuePriority::Normal }

fn encode(&self) -> Vec<u8> {
let mut encoded = self.rlp_bytes();
let mut encoded = self.rlp_bytes().into();
self.push_msg_id_leb128_encoding(&mut encoded);
encoded
}
Expand Down Expand Up @@ -472,7 +472,7 @@ impl Message for GetTransactionsFromTxHashes {
fn priority(&self) -> SendQueuePriority { SendQueuePriority::Normal }

fn encode(&self) -> Vec<u8> {
let mut encoded = self.rlp_bytes();
let mut encoded = self.rlp_bytes().into();
self.push_msg_id_leb128_encoding(&mut encoded);
encoded
}
Expand Down
5 changes: 4 additions & 1 deletion crates/cfxcore/core/src/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ fn block_receipts_trie(block_receipts: &Vec<Receipt>) -> SimpleMpt {
make_simple_mpt(
block_receipts
.iter()
.map(|receipt| receipt.rlp_bytes().into_boxed_slice())
.map(|receipt| {
let vec_u8: Vec<u8> = receipt.rlp_bytes().into();
vec_u8.into_boxed_slice()
})
.collect(),
)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/cfxcore/internal_common/src/block_data_db_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub trait DatabaseDecodable: Sized {
macro_rules! impl_db_encoding_as_rlp {
($type:ty) => {
impl $crate::DatabaseEncodable for $type {
fn db_encode(&self) -> Vec<u8> { rlp::encode(self) }
fn db_encode(&self) -> Vec<u8> { rlp::encode(self).to_vec() }
}

impl $crate::DatabaseDecodable for $type {
Expand All @@ -39,7 +39,7 @@ impl DatabaseEncodable for BlockHeader {
fn db_encode(&self) -> Bytes {
let mut rlp_stream = RlpStream::new();
self.stream_rlp_with_pow_hash(&mut rlp_stream);
rlp_stream.drain()
rlp_stream.as_raw().into()
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/client/src/rpc/impls/cfx/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ impl RpcImpl {
.expect("failed to convert scaled risk to bigInt");
let (sign, big_endian_bytes) = scaled_risk.to_bytes_be();
assert_ne!(sign, num_bigint::Sign::Minus);
let rpc_result = U256::from(big_endian_bytes.as_slice());
let rpc_result = U256::from_big_endian(big_endian_bytes.as_slice());
Ok(Some(rpc_result.into()))
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/client/src/rpc/impls/cfx/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ impl RpcImpl {
accounts,
)?;

Self::send_tx_helper(light, Bytes::new(tx.rlp_bytes()))
Self::send_tx_helper(light, Bytes::new(tx.rlp_bytes().into()))
};

fut.boxed()
Expand Down
7 changes: 2 additions & 5 deletions crates/dbs/statedb/src/statedb_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,8 @@ impl StateDbExt for StateDbGeneric {
if value.is_default() {
self.delete(key, debug_record)
} else {
self.set_raw(
key,
::rlp::encode(value).into_boxed_slice(),
debug_record,
)
let value_vec = Vec::from(::rlp::encode(value));
self.set_raw(key, value_vec.into_boxed_slice(), debug_record)
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/dbs/storage/src/impls/delta_mpt/cow_node_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ impl CowNodeRef {
.value
.try_into()
.expect("not exceed i64::MAX"),
trie_node.rlp_bytes().as_slice(),
trie_node.rlp_bytes().as_ref(),
)?;
commit_transaction.info.row_number =
commit_transaction.info.row_number.get_next()?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn test_no_alloc_in_empty_children_table() {

let rlp_bytes = empty_children_table.to_ref().rlp_bytes();
let rlp_parsed =
ChildrenTableManagedDeltaMpt::decode(&Rlp::new(rlp_bytes.as_slice()))
ChildrenTableManagedDeltaMpt::decode(&Rlp::new(rlp_bytes.as_ref()))
.unwrap();
let decoded_table = ChildrenTableDeltaMpt::from(rlp_parsed);
decoded_table.assert_no_alloc_in_empty_children_table();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ fn test_node_ref_delta_mpt_compact_encode_decode() {
let x = NodeRefDeltaMptCompact::new(1234);
let rlp_bytes = x.rlp_bytes();
assert_eq!(
NodeRefDeltaMptCompact::decode(&Rlp::new(rlp_bytes.as_slice()))
.unwrap(),
NodeRefDeltaMptCompact::decode(&Rlp::new(rlp_bytes.as_ref())).unwrap(),
x
);
}
Expand All @@ -31,7 +30,7 @@ fn test_full_children_table_encode_decode() {
}
let rlp_bytes = children_table.to_ref().rlp_bytes();

let rlp = &Rlp::new(rlp_bytes.as_slice());
let rlp = &Rlp::new(rlp_bytes.as_ref());
// Assert that the rlp has 16 items.
assert_eq!(rlp.item_count().unwrap(), 16);

Expand All @@ -53,7 +52,7 @@ fn test_non_empty_children_table_encode_decode() {
}
let rlp_bytes = children_table.to_ref().rlp_bytes();
let rlp_parsed =
ChildrenTableManagedDeltaMpt::decode(&Rlp::new(rlp_bytes.as_slice()))
ChildrenTableManagedDeltaMpt::decode(&Rlp::new(rlp_bytes.as_ref()))
.unwrap();
assert_eq!(children_table, rlp_parsed.into());
}
Expand All @@ -63,7 +62,7 @@ fn test_empty_children_table_encode_decode() {
let empty_children_table: ChildrenTableDeltaMpt = Default::default();
let rlp_bytes = empty_children_table.to_ref().rlp_bytes();
let rlp_parsed =
ChildrenTableManagedDeltaMpt::decode(&Rlp::new(rlp_bytes.as_slice()))
ChildrenTableManagedDeltaMpt::decode(&Rlp::new(rlp_bytes.as_ref()))
.unwrap();
assert_eq!(
ChildrenTableDeltaMpt::from(rlp_parsed).get_children_count(),
Expand Down Expand Up @@ -94,7 +93,7 @@ fn test_trie_node_encode_decode() {
);
let rlp_bytes = x.rlp_bytes();
let rlp_parsed = MemOptimizedTrieNode::<DeltaMptsCacheAlgoData>::decode(
&Rlp::new(rlp_bytes.as_slice()),
&Rlp::new(rlp_bytes.as_ref()),
)
.unwrap();

Expand Down
3 changes: 2 additions & 1 deletion crates/dbs/storage/src/impls/storage_db/snapshot_mpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,10 @@ impl<
&mut self, path: &dyn CompressedPathTrait, trie_node: &SnapshotMptNode,
) -> Result<()> {
let key = mpt_node_path_to_db_key(path);
let value_vec = Vec::from(trie_node.rlp_bytes());
self.db
.borrow_mut()
.put(&key, &trie_node.rlp_bytes().into_boxed_slice())?;
.put(&key, &value_vec.into_boxed_slice())?;
Ok(())
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/dbs/storage/src/tests/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ fn test_snapshot_random_read_performance() {
let account_key =
StorageKey::new_account_key(&address).with_native_space();
state_0
.set(account_key, rlp::encode(&account).into())
.set(account_key, rlp::encode(&account).as_ref().into())
.expect("Failed to set key");
}

Expand Down Expand Up @@ -381,7 +381,7 @@ fn simulate_transactions(
} else {
account.balance += U256::one();
}
values[i] = Some(rlp::encode(&account).into());
values[i] = Some(rlp::encode(&account).as_ref().into());
}
*update_ms += now.elapsed().as_millis() as u32;

Expand Down
2 changes: 1 addition & 1 deletion crates/dbs/storage/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub trait StateRootWithAuxInfoToFromRlpBytes {

/// Only used by storage benchmark due to incompatibility of rlp crate version.
impl StateRootWithAuxInfoToFromRlpBytes for StateRootWithAuxInfo {
fn to_rlp_bytes(&self) -> Vec<u8> { self.rlp_bytes() }
fn to_rlp_bytes(&self) -> Vec<u8> { self.rlp_bytes().into() }

fn from_rlp_bytes(bytes: &[u8]) -> Result<Self> {
Ok(Self::decode(&Rlp::new(bytes))?)
Expand Down
2 changes: 1 addition & 1 deletion crates/execution/executor/src/builtin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ impl Bn128PairingImpl {
};

let mut buf = [0u8; 32];
ret_val.to_big_endian(&mut buf);
ret_val.write_as_big_endian(&mut buf);
output.write(0, &buf);

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/execution/executor/src/executive/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2325,7 +2325,7 @@ fn test_tload() {
assert!(apply_state);

let mut key = [0u8; 32];
U256::from(2).to_big_endian(&mut key);
U256::from(2).write_as_big_endian(&mut key);
assert_eq!(
state
.storage_at(&contract_address_with_space, &key)
Expand Down
Loading
Loading