Skip to content

Commit 1b94b6a

Browse files
committed
move cfxcore types to independent crate
1 parent 10740c6 commit 1b94b6a

File tree

18 files changed

+136
-103
lines changed

18 files changed

+136
-103
lines changed

Cargo.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cfxcore/core/src/block_data_manager/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use cfx_storage::{
1414
StorageManagerTrait,
1515
};
1616
use cfx_types::{Bloom, Space, H256};
17+
pub use cfxcore_types::block_data_manager::block_data_types;
1718
use db::SystemDB;
1819
use malloc_size_of::{new_malloc_size_ops, MallocSizeOf, MallocSizeOfOps};
1920
use malloc_size_of_derive::MallocSizeOf as DeriveMallocSizeOf;
@@ -30,7 +31,6 @@ use std::{
3031
sync::Arc,
3132
};
3233
use threadpool::ThreadPool;
33-
pub mod block_data_types;
3434
pub mod db_gc_manager;
3535
pub mod db_manager;
3636
pub mod tx_data_manager;

crates/cfxcore/core/src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,23 @@ pub mod message;
1818
pub mod block_data_manager;
1919
pub mod cache_config;
2020
pub mod cache_manager;
21-
pub mod channel;
2221
pub mod client;
2322
pub mod consensus;
24-
mod core_error;
2523
pub mod db;
2624
pub mod errors;
2725
pub mod genesis_block;
2826
pub mod light_protocol;
29-
pub mod node_type;
3027
pub mod pos;
3128
pub mod pow;
32-
pub mod state_exposer;
3329
pub mod statistics;
3430
pub mod sync;
3531
pub mod transaction_pool;
36-
pub mod unique_id;
3732
pub mod verification;
3833

34+
pub use cfxcore_types::{
35+
channel, core_error, node_type, state_exposer, unique_id,
36+
};
37+
3938
pub use crate::{
4039
block_data_manager::BlockDataManager,
4140
channel::Notifications,

crates/cfxcore/core/src/state_exposer/mod.rs

Lines changed: 0 additions & 41 deletions
This file was deleted.

crates/cfxcore/types/Cargo.toml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,21 @@ edition.workspace = true
1515
[dependencies]
1616
cfx-types = { workspace = true }
1717
malloc_size_of = { workspace = true }
18-
malloc_size_of_derive = { workspace = true }
18+
malloc_size_of_derive = { workspace = true }
19+
rlp = { workspace = true }
20+
rlp_derive = { workspace = true }
21+
cfx-internal-common = { workspace = true }
22+
parking_lot = { workspace = true }
23+
lazy_static = { workspace = true }
24+
primitives = { workspace = true }
25+
cfx-execute-helper = { workspace = true }
26+
smart-default = { workspace = true }
27+
tokio = { workspace = true, features = ["full"] }
28+
futures = { workspace = true, features = ["compat"] }
29+
log = { workspace = true }
30+
cfx-bytes = { workspace = true }
31+
thiserror = { workspace = true }
32+
unexpected = { workspace = true }
33+
34+
[dev-dependencies]
35+
rand = { workspace = true }

crates/cfxcore/core/src/block_data_manager/block_data_types.rs renamed to crates/cfxcore/types/src/block_data_manager/block_data_types.rs

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use cfx_internal_common::{
33
impl_db_encoding_as_rlp, DatabaseDecodable, DatabaseEncodable,
44
};
55
use cfx_types::{Address, Bloom, H256, U256};
6-
pub use cfxcore_types::block_data_manager::BlockStatus;
76
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
87
use malloc_size_of_derive::MallocSizeOf as DeriveMallocSizeOf;
98
use primitives::BlockReceipts;
@@ -53,25 +52,6 @@ impl Decodable for BlockExecutionResult {
5352
}
5453
}
5554

56-
#[derive(
57-
RlpEncodable, RlpDecodable, Clone, Copy, Debug, DeriveMallocSizeOf,
58-
)]
59-
pub struct BlockRewardResult {
60-
pub total_reward: U256,
61-
pub base_reward: U256,
62-
pub tx_fee: U256,
63-
}
64-
65-
impl Default for BlockRewardResult {
66-
fn default() -> Self {
67-
BlockRewardResult {
68-
total_reward: U256::from(0),
69-
base_reward: U256::from(0),
70-
tx_fee: U256::from(0),
71-
}
72-
}
73-
}
74-
7555
pub type BlockRewardsInfo = BlockDataWithMultiVersion<H256, BlockRewardResult>;
7656

7757
#[derive(Clone, Debug, DeriveMallocSizeOf)]
@@ -339,6 +319,50 @@ impl PosRewardInfo {
339319
}
340320
}
341321

322+
/// The validity status of a block. If a block's status among all honest nodes
323+
/// is guaranteed to have no conflict, which means if some honest nodes think a
324+
/// block is not `Pending`, their decision will be the same status.
325+
#[derive(Copy, Clone, PartialEq, DeriveMallocSizeOf)]
326+
pub enum BlockStatus {
327+
Valid = 0,
328+
Invalid = 1,
329+
PartialInvalid = 2,
330+
Pending = 3,
331+
}
332+
333+
impl BlockStatus {
334+
pub fn from_db_status(db_status: u8) -> Self {
335+
match db_status {
336+
0 => BlockStatus::Valid,
337+
1 => BlockStatus::Invalid,
338+
2 => BlockStatus::PartialInvalid,
339+
3 => BlockStatus::Pending,
340+
_ => panic!("Read unknown block status from db"),
341+
}
342+
}
343+
344+
pub fn to_db_status(&self) -> u8 { *self as u8 }
345+
}
346+
347+
#[derive(
348+
RlpEncodable, RlpDecodable, Clone, Copy, Debug, DeriveMallocSizeOf,
349+
)]
350+
pub struct BlockRewardResult {
351+
pub total_reward: U256,
352+
pub base_reward: U256,
353+
pub tx_fee: U256,
354+
}
355+
356+
impl Default for BlockRewardResult {
357+
fn default() -> Self {
358+
BlockRewardResult {
359+
total_reward: U256::from(0),
360+
base_reward: U256::from(0),
361+
tx_fee: U256::from(0),
362+
}
363+
}
364+
}
365+
342366
pub fn db_encode_list<T>(list: &[T]) -> Vec<u8>
343367
where T: DatabaseEncodable {
344368
let mut rlp_stream = RlpStream::new();
@@ -363,6 +387,6 @@ impl_db_encoding_as_rlp!(BlockExecutionResult);
363387
impl_db_encoding_as_rlp!(LocalBlockInfo);
364388
impl_db_encoding_as_rlp!(CheckpointHashes);
365389
impl_db_encoding_as_rlp!(EpochExecutionContext);
366-
impl_db_encoding_as_rlp!(BlockRewardResult);
367390
impl_db_encoding_as_rlp!(BlamedHeaderVerifiedRoots);
368391
impl_db_encoding_as_rlp!(PosRewardInfo);
392+
impl_db_encoding_as_rlp!(BlockRewardResult);
Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1 @@
1-
use malloc_size_of_derive::MallocSizeOf as DeriveMallocSizeOf;
2-
3-
/// The validity status of a block. If a block's status among all honest nodes
4-
/// is guaranteed to have no conflict, which means if some honest nodes think a
5-
/// block is not `Pending`, their decision will be the same status.
6-
#[derive(Copy, Clone, PartialEq, DeriveMallocSizeOf)]
7-
pub enum BlockStatus {
8-
Valid = 0,
9-
Invalid = 1,
10-
PartialInvalid = 2,
11-
Pending = 3,
12-
}
13-
14-
impl BlockStatus {
15-
pub fn from_db_status(db_status: u8) -> Self {
16-
match db_status {
17-
0 => BlockStatus::Valid,
18-
1 => BlockStatus::Invalid,
19-
2 => BlockStatus::PartialInvalid,
20-
3 => BlockStatus::Pending,
21-
_ => panic!("Read unknown block status from db"),
22-
}
23-
}
24-
25-
pub fn to_db_status(&self) -> u8 { *self as u8 }
26-
}
1+
pub mod block_data_types;

crates/cfxcore/core/src/channel.rs renamed to crates/cfxcore/types/src/channel.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use crate::UniqueId;
66
use cfx_types::H256;
7+
use log::warn;
78
use parking_lot::RwLock;
89
use std::{collections::BTreeMap, sync::Arc, time::Duration};
910
use tokio::{runtime, sync::mpsc, time::timeout};

crates/cfxcore/core/src/core_error.rs renamed to crates/cfxcore/types/src/core_error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Conflux is free software and distributed under GNU General Public License.
33
// See http://www.gnu.org/licenses/
44

5-
use crate::message::Bytes;
5+
use cfx_bytes::Bytes;
66
use cfx_types::{Address, SpaceMap, H256, U256};
77
use primitives::{filter::FilterError, transaction::TransactionError};
88
use std::{error, fmt, time::SystemTime};

crates/cfxcore/types/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
pub mod block_data_manager;
2+
pub mod channel;
3+
pub mod core_error;
4+
pub mod node_type;
25
pub mod state_exposer;
6+
pub mod unique_id;
7+
8+
pub use unique_id::UniqueId;

0 commit comments

Comments
 (0)