Skip to content
Open
Show file tree
Hide file tree
Changes from 18 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
300 changes: 173 additions & 127 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ members = [
"crates/util/treap-map",
"crates/util/version",
"crates/util/serde_utils",
"crates/util/rlp_bool",
"crates/execution/geth-tracer",
"crates/rpc/rpc-eth-types",
"crates/rpc/rpc-primitives",
Expand Down Expand Up @@ -172,6 +173,7 @@ cfx-stratum = { path = "./crates/stratum" }
txgen = { path = "./crates/transactiongen" }
blockgen = { path = "./crates/blockgen" }
serde-utils = { path = "./crates/util/serde_utils" }
rlp-bool = { path = "./crates/util/rlp_bool" }
db = { path = "./crates/dbs/db" }
cfx-db-errors = { path = "./crates/dbs/db-errors" }
cfx-statedb = { path = "./crates/dbs/statedb" }
Expand Down Expand Up @@ -327,7 +329,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 @@ -426,12 +428,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
4 changes: 3 additions & 1 deletion crates/cfxcore/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ rangetools = { workspace = true }
rayon = { workspace = true }
rlp = { workspace = true }
rlp_derive = { workspace = true }
bytes = { workspace = true }
rustc-hex = { workspace = true }
secret-store = { workspace = true }
serde = { workspace = true, features = ["rc"] }
Expand Down Expand Up @@ -117,6 +118,7 @@ cfx-rpc-utils = { workspace = true }
cfx-util-macros = { workspace = true }
cfxcore-types = { workspace = true }
cfxcore-pow = { workspace = true }
rlp-bool = { workspace = true }

[dev-dependencies]
cfx-storage = { workspace = true, features = ["testonly_code"] }
Expand All @@ -135,4 +137,4 @@ consensus_bench = []
fuzzing = ["proptest", "proptest-derive"]

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(mirai)'] }
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(mirai)'] }
9 changes: 5 additions & 4 deletions crates/cfxcore/core/examples/snapshot_merge_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use std::{
str::FromStr, sync::Arc, time::Instant,
};

use rlp_bool::CompatibleBool;
// cargo run --release -p cfxcore --example snapshot_merge_test
// cargo run --release -p cfxcore --example snapshot_merge_test -- --help
fn main() -> Result<(), Error> {
Expand Down Expand Up @@ -92,7 +93,7 @@ fn main() -> Result<(), Error> {
merkle_root: Default::default(),
parent_snapshot_epoch_id: NULL_EPOCH,
pivot_chain_parts: vec![snapshot1_epoch],
serve_one_step_sync: false,
serve_one_step_sync: CompatibleBool(false),
snapshot_info_kept_to_provide_sync: Default::default(),
};
let (mut snapshot_info_map_locked, snapshot_info1) = snapshot_db_manager
Expand Down Expand Up @@ -163,7 +164,7 @@ fn main() -> Result<(), Error> {
merkle_root: snapshot_info1.merkle_root,
parent_snapshot_epoch_id: snapshot1_epoch,
pivot_chain_parts: vec![snapshot2_epoch],
serve_one_step_sync: false,
serve_one_step_sync: CompatibleBool(false),
snapshot_info_kept_to_provide_sync: Default::default(),
};
let (mut snapshot_info_map_locked, snapshot_info2) = snapshot_db_manager
Expand Down Expand Up @@ -198,7 +199,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 Expand Up @@ -230,7 +231,7 @@ fn main() -> Result<(), Error> {
merkle_root: Default::default(),
parent_snapshot_epoch_id: NULL_EPOCH,
pivot_chain_parts: vec![snapshot3_epoch],
serve_one_step_sync: false,
serve_one_step_sync: CompatibleBool(false),
snapshot_info_kept_to_provide_sync: Default::default(),
};
let (mut snapshot_info_map_locked, snapshot_info3) = snapshot_db_manager
Expand Down
7 changes: 4 additions & 3 deletions crates/cfxcore/core/src/block_data_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ use cfx_internal_common::{
use db_gc_manager::GCProgress;
use metrics::{register_meter_with_group, Meter, MeterTimer};
use primitives::pos::PosBlockId;
use rlp_bool::CompatibleBool;
use std::{hash::Hash, path::Path, time::Duration};

lazy_static! {
Expand Down Expand Up @@ -272,7 +273,7 @@ impl BlockDataManager {
&TransactionIndex {
block_hash: cur_era_genesis_hash,
real_index: index,
is_phantom: false,
is_phantom: CompatibleBool(false),
// FIXME(thegaram): do we allow EVM txs in genesis?
rpc_index: Some(index),
},
Expand Down Expand Up @@ -1304,7 +1305,7 @@ impl BlockDataManager {
&TransactionIndex {
block_hash: *block_hash,
real_index: tx_idx,
is_phantom: false,
is_phantom: CompatibleBool(false),
rpc_index: Some(rpc_index),
},
);
Expand All @@ -1315,7 +1316,7 @@ impl BlockDataManager {
&TransactionIndex {
block_hash: *block_hash,
real_index: tx_idx,
is_phantom: true,
is_phantom: CompatibleBool(true),
rpc_index: Some(evm_tx_index),
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ impl ConsensusGraph {
}
let trace = LocalizedTrace {
action: trace.action,
valid: trace.valid,
valid: trace.valid.into(),
epoch_hash: pivot_hash,
epoch_number: epoch_number.into(),
block_hash,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use cfx_executor::{
},
};
use cfx_vm_types::Env;

use rlp_bool::CompatibleBool;
pub enum VirtualCall<'a> {
GethTrace(GethTask<'a>),
}
Expand Down Expand Up @@ -329,7 +329,7 @@ impl ConsensusExecutionHandler {
&TransactionIndex {
block_hash: block.hash(),
real_index: idx,
is_phantom: false,
is_phantom: CompatibleBool(false),
rpc_index: Some(rpc_index),
},
);
Expand All @@ -349,7 +349,7 @@ impl ConsensusExecutionHandler {
&TransactionIndex {
block_hash: block.hash(),
real_index: idx,
is_phantom: true,
is_phantom: CompatibleBool(true),
rpc_index: Some(*evm_tx_index),
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use parking_lot::RwLock;
use primitives::{
Receipt, SignedTransaction, TransactionIndex, TransactionStatus,
};
use rlp_bool::CompatibleBool;
use std::{future::Future, sync::Arc};

#[derive(Debug)]
Expand Down Expand Up @@ -357,7 +358,7 @@ impl TxInfos {
let tx_index = TransactionIndex {
block_hash,
real_index: tx_index_in_block,
is_phantom: false,
is_phantom: CompatibleBool(false),
rpc_index: None,
};

Expand Down
4 changes: 3 additions & 1 deletion crates/cfxcore/core/src/light_protocol/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ use primitives::{
};
use rand::prelude::SliceRandom;
use rlp::Rlp;
use rlp_bool::CompatibleBool;
use std::{
sync::{Arc, Weak},
time::{Duration, Instant},
Expand Down Expand Up @@ -248,7 +249,8 @@ impl Provider {
TransactionInfo {
tx_index:
TransactionIndex {
is_phantom: true, ..
is_phantom: CompatibleBool(true),
..
},
..
},
Expand Down
15 changes: 8 additions & 7 deletions crates/cfxcore/core/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub type RequestId = u64;
pub type MsgId = u16;
const MSG_ID_MAX: u16 = 1 << 14;

use bytes::{BufMut, BytesMut};
pub use cfx_bytes::Bytes;
pub use priority_send_queue::SendQueuePriority;
use rlp::{Decodable, Rlp};
Expand Down Expand Up @@ -60,16 +61,16 @@ pub trait Message:
// If true, message may be throttled when sent to remote peer.
fn is_size_sensitive(&self) -> bool { false }
fn msg_id(&self) -> MsgId;
fn push_msg_id_leb128_encoding(&self, buffer: &mut Vec<u8>) {
fn push_msg_id_leb128_encoding(&self, buffer: &mut BytesMut) {
let msg_id = self.msg_id();
assert!(msg_id < MSG_ID_MAX);
let msg_id_msb = (msg_id >> 7) as u8;
let mut msg_id_lsb = (msg_id as u8) & 0x7f;
if msg_id_msb != 0 {
buffer.push(msg_id_msb);
buffer.put_u8(msg_id_msb);
msg_id_lsb |= 0x80;
}
buffer.push(msg_id_lsb);
buffer.put_u8(msg_id_lsb);
}
fn msg_name(&self) -> &'static str;
fn priority(&self) -> SendQueuePriority { SendQueuePriority::High }
Expand Down Expand Up @@ -187,7 +188,7 @@ macro_rules! build_msg_basic {
fn encode(&self) -> Vec<u8> {
let mut encoded = self.rlp_bytes();
self.push_msg_id_leb128_encoding(&mut encoded);
encoded
encoded.into()
}
}
};
Expand Down Expand Up @@ -278,10 +279,10 @@ mod test {
#[test]
fn test_message_id_encode_decode() {
for msg_id in 0..MSG_ID_MAX {
let mut buf = vec![];
let message = TestMessage { msg_id };
buf.extend_from_slice(&message.rlp_bytes());
message.push_msg_id_leb128_encoding(&mut buf);
let mut encoded = message.rlp_bytes();
message.push_msg_id_leb128_encoding(&mut encoded);
let buf = encoded.as_ref();
match decode_msg(&buf) {
None => assert!(false, "Can not decode message"),
Some((decoded_msg_id, rlp)) => {
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
5 changes: 3 additions & 2 deletions crates/cfxcore/core/src/sync/message/capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ use crate::{
use malloc_size_of_derive::MallocSizeOf as DeriveMallocSizeOf;
use network::{node_table::NodeId, NetworkContext};
use rlp::{Decodable, DecoderError, Encodable, Rlp, RlpStream};
use rlp_bool::CompatibleBool;

#[derive(Debug, Eq, PartialEq, Clone, Copy, DeriveMallocSizeOf)]
pub enum DynamicCapability {
NormalPhase(bool), // provide tx relay
ServeHeaders(bool), // provide block header downloads
NormalPhase(CompatibleBool), // provide tx relay
ServeHeaders(CompatibleBool), // provide block header downloads
}

impl DynamicCapability {
Expand Down
4 changes: 2 additions & 2 deletions crates/cfxcore/core/src/sync/message/get_block_txn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use crate::{
};
use cfx_types::H256;
use malloc_size_of_derive::MallocSizeOf as DeriveMallocSizeOf;
use rlp_bool::CompatibleBool;
use rlp_derive::{RlpDecodable, RlpEncodable};
use std::{any::Any, time::Duration};

#[derive(
Debug,
PartialEq,
Expand Down Expand Up @@ -63,7 +63,7 @@ impl Request for GetBlockTxn {
request_id: 0,
// request_block_need_public can only be true in catch_up_mode,
// where GetBlockTxn can not be initiated.
with_public: false,
with_public: CompatibleBool(false),
hashes: vec![self.block_hash.clone()],
preferred_node_type: None,
}))
Expand Down
8 changes: 4 additions & 4 deletions crates/cfxcore/core/src/sync/message/get_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ use cfx_types::H256;
use malloc_size_of_derive::MallocSizeOf as DeriveMallocSizeOf;
use primitives::Block;
use rlp::{Decodable, DecoderError, Encodable, Rlp, RlpStream};
use rlp_bool::CompatibleBool;
use std::{any::Any, time::Duration};

#[derive(Debug, PartialEq, Default, Clone, DeriveMallocSizeOf)]
pub struct GetBlocks {
pub request_id: RequestId,
pub with_public: bool,
pub with_public: CompatibleBool,
pub hashes: Vec<H256>,
// This field specifies what node type of peers this
// request needs to be sent to.
Expand Down Expand Up @@ -167,8 +167,8 @@ impl GetBlocks {

impl Handleable for GetBlocks {
fn handle(self, ctx: &Context) -> Result<(), Error> {
let blocks = self.get_blocks(ctx, self.with_public);
if self.with_public {
let blocks = self.get_blocks(ctx, self.with_public.into());
if self.with_public.into() {
self.send_response_with_public(ctx, blocks)
} else {
self.send_response(ctx, blocks)
Expand Down
4 changes: 2 additions & 2 deletions crates/cfxcore/core/src/sync/message/get_compact_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use crate::{
use cfx_parameters::sync::{MAX_BLOCKS_TO_SEND, MAX_HEADERS_TO_SEND};
use cfx_types::H256;
use malloc_size_of_derive::MallocSizeOf as DeriveMallocSizeOf;
use rlp_bool::CompatibleBool;
use rlp_derive::{RlpDecodable, RlpEncodable};
use std::{any::Any, time::Duration};

#[derive(
Debug, PartialEq, Default, RlpDecodable, RlpEncodable, DeriveMallocSizeOf,
)]
Expand Down Expand Up @@ -58,7 +58,7 @@ impl Request for GetCompactBlocks {
fn resend(&self) -> Option<Box<dyn Request>> {
Some(Box::new(GetBlocks {
request_id: 0,
with_public: true,
with_public: CompatibleBool(true),
hashes: self.hashes.iter().cloned().collect(),
preferred_node_type: None,
}))
Expand Down
Loading
Loading