Skip to content

Commit

Permalink
update some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjiao committed Feb 26, 2024
1 parent 93c12e4 commit bb060a1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
23 changes: 17 additions & 6 deletions chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ impl BlockChain {
None => self.current_header(),
};

debug!("jacktest: creating block template, previous header: {:?}", previous_header.number());
debug!(
"jacktest: creating block template, previous header: {:?}",
previous_header.number()
);

self.create_block_template_by_header(
author,
Expand All @@ -266,7 +269,11 @@ impl BlockChain {
block_gas_limit: Option<u64>,
tips: Option<Vec<HashValue>>,
) -> Result<(BlockTemplate, ExcludedTxns)> {
debug!("jacktest: parent hash: {:?}, number: {:?}", previous_header.id(), previous_header.number());
debug!(
"jacktest: parent hash: {:?}, number: {:?}",
previous_header.id(),
previous_header.number()
);
let current_number = previous_header.number().saturating_add(1);
let epoch = self.epoch();
let on_chain_block_gas_limit = epoch.block_gas_limit();
Expand Down Expand Up @@ -987,14 +994,20 @@ impl ChainReader for BlockChain {
fn find_ancestor(&self, another: &dyn ChainReader) -> Result<Option<BlockIdAndNumber>> {
let other_header_number = another.current_header().number();
let self_header_number = self.current_header().number();
debug!("jacktest: self_header_number: {}, other_header_number: {}", self_header_number, other_header_number);
debug!(
"jacktest: self_header_number: {}, other_header_number: {}",
self_header_number, other_header_number
);
let min_number = std::cmp::min(other_header_number, self_header_number);
debug!("jacktest: min_number: {}", min_number);
let mut ancestor = None;
for block_number in (0..=min_number).rev() {
let block_id_1 = another.get_hash_by_number(block_number)?;
let block_id_2 = self.get_hash_by_number(block_number)?;
debug!("jacktest: block number: {}, block_id_1: {:?}, block_id_2: {:?}", block_number, block_id_1, block_id_2);
debug!(
"jacktest: block number: {}, block_id_1: {:?}, block_id_2: {:?}",
block_number, block_id_1, block_id_2
);
match (block_id_1, block_id_2) {
(Some(block_id_1), Some(block_id_2)) => {
if block_id_1 == block_id_2 {
Expand Down Expand Up @@ -1147,8 +1160,6 @@ impl ChainReader for BlockChain {
}

fn dag_fork_height(&self) -> Result<BlockNumber> {
// todo: change return type to Result<BlockNumber>,
// try to handle db io error
match self.dag.block_dag_config() {
BlockDAGType::BlockDAGFormal => Ok(self
.statedb
Expand Down
5 changes: 3 additions & 2 deletions miner/src/create_block_template/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,10 @@ where
fn uncles_prune(&mut self) {
if !self.uncles.is_empty() {
let epoch = self.chain.epoch();
// epoch的end_number是开区间,当前块已经生成但还没有apply,所以应该在epoch(最终状态)
// 的倒数第二块处理时清理uncles
if epoch.end_block_number() == (self.chain.current_header().number() + 2) {
// 1. The last block of current epoch is `end_block_number`-1,
// 2. If current block number is `end_block_number`-2, then last block has been mined but un-applied to db,
// 3. So current uncles should be cleared now.
self.uncles.clear();
}
}
Expand Down
22 changes: 11 additions & 11 deletions types/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ impl std::fmt::Display for BlockHeaderExtra {

impl<'de> Deserialize<'de> for BlockHeaderExtra {
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where
D: Deserializer<'de>,
where
D: Deserializer<'de>,
{
if deserializer.is_human_readable() {
let s = <String>::deserialize(deserializer)?;
Expand All @@ -123,8 +123,8 @@ impl<'de> Deserialize<'de> for BlockHeaderExtra {

impl Serialize for BlockHeaderExtra {
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: Serializer,
where
S: Serializer,
{
if serializer.is_human_readable() {
format!("0x{}", hex::encode(self.0)).serialize(serializer)
Expand All @@ -135,7 +135,7 @@ impl Serialize for BlockHeaderExtra {
}

#[derive(
Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Deserialize, Serialize, JsonSchema,
Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Deserialize, Serialize, JsonSchema,
)]
pub struct BlockIdAndNumber {
pub id: HashValue,
Expand Down Expand Up @@ -485,8 +485,8 @@ impl BlockHeader {

impl<'de> Deserialize<'de> for BlockHeader {
fn deserialize<D>(deserializer: D) -> Result<Self, <D as Deserializer<'de>>::Error>
where
D: Deserializer<'de>,
where
D: Deserializer<'de>,
{
#[derive(Deserialize)]
#[serde(rename = "BlockHeader")]
Expand Down Expand Up @@ -731,7 +731,7 @@ impl BlockHeaderBuilder {
}

#[derive(
Default, Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize, CryptoHasher, CryptoHash,
Default, Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize, CryptoHasher, CryptoHash,
)]
pub struct BlockBody {
/// The transactions in this block.
Expand Down Expand Up @@ -801,8 +801,8 @@ pub struct Block {

impl Block {
pub fn new<B>(header: BlockHeader, body: B) -> Self
where
B: Into<BlockBody>,
where
B: Into<BlockBody>,
{
Block {
header,
Expand Down Expand Up @@ -954,7 +954,7 @@ impl Sample for Block {
/// `BlockInfo` is the object we store in the storage. It consists of the
/// block as well as the execution result of this block.
#[derive(
Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize, CryptoHasher, CryptoHash, JsonSchema,
Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize, CryptoHasher, CryptoHash, JsonSchema,
)]
pub struct BlockInfo {
/// Block id
Expand Down

0 comments on commit bb060a1

Please sign in to comment.