Skip to content

Commit 451ecf9

Browse files
committed
debug
1 parent 158ba34 commit 451ecf9

File tree

6 files changed

+53
-14
lines changed

6 files changed

+53
-14
lines changed

chain/src/chain_service.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ impl ChainService {
9292
fn asynchronous_process_block(&self, lonely_block: LonelyBlock) {
9393
let block_number = lonely_block.block().number();
9494
let block_hash = lonely_block.block().hash();
95+
debug!(
96+
"[ChainService] asynchronous_process_block {}-{}",
97+
block_number, block_hash
98+
);
9599
// Skip verifying a genesis block if its hash is equal to our genesis hash,
96100
// otherwise, return error and ban peer.
97101
if block_number < 1 {

ckb-bin/src/setup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::{path::PathBuf, str::FromStr};
1515
use crate::cli;
1616

1717
// 500_000 total difficulty
18-
const MIN_CHAIN_WORK_500K: U256 = u256!("0x3314412053c82802a7");
18+
const MIN_CHAIN_WORK_500K: U256 = u256!("0x0");
1919

2020
/// A struct including all the information to start the ckb process.
2121
pub struct Setup {

shared/src/shared.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -423,19 +423,21 @@ impl Shared {
423423
match self.block_status_map().get(block_hash) {
424424
Some(status_ref) => *status_ref.value(),
425425
None => {
426-
if self.header_map().contains_key(block_hash) {
427-
BlockStatus::HEADER_VALID
428-
} else {
429-
let verified = self
430-
.snapshot()
431-
.get_block_ext(block_hash)
432-
.map(|block_ext| block_ext.verified);
433-
match verified {
434-
None => BlockStatus::UNKNOWN,
435-
Some(None) => BlockStatus::BLOCK_STORED,
436-
Some(Some(true)) => BlockStatus::BLOCK_VALID,
437-
Some(Some(false)) => BlockStatus::BLOCK_INVALID,
426+
let verified = self
427+
.snapshot()
428+
.get_block_ext(block_hash)
429+
.map(|block_ext| block_ext.verified);
430+
match verified {
431+
None => {
432+
if self.header_map().contains_key(block_hash) {
433+
BlockStatus::HEADER_VALID
434+
} else {
435+
BlockStatus::UNKNOWN
436+
}
438437
}
438+
Some(None) => BlockStatus::BLOCK_STORED,
439+
Some(Some(true)) => BlockStatus::BLOCK_VALID,
440+
Some(Some(false)) => BlockStatus::BLOCK_INVALID,
439441
}
440442
}
441443
}

sync/src/synchronizer/headers_process.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,13 @@ impl<'a> HeadersProcess<'a> {
253253

254254
// Batch insert all valid headers in ONE transaction
255255
if !headers_to_insert.is_empty() {
256+
debug!(
257+
"Calling insert_valid_headers_batch for {} headers",
258+
headers_to_insert.len()
259+
);
256260
shared.insert_valid_headers_batch(self.peer, &headers_to_insert);
261+
} else {
262+
debug!("No new headers to insert (all already valid)");
257263
}
258264

259265
self.debug();

sync/src/synchronizer/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,12 +453,18 @@ impl Synchronizer {
453453
//TODO: process block which we don't request
454454
pub fn asynchronous_process_remote_block(&self, remote_block: RemoteBlock) {
455455
let block_hash = remote_block.block.hash();
456+
let block_number = remote_block.block.number();
456457
let status = self.shared.active_chain().get_block_status(&block_hash);
458+
debug!(
459+
"asynchronous_process_remote_block {}-{}, status: {:?}",
460+
block_number, block_hash, status
461+
);
457462
// NOTE: Filtering `BLOCK_STORED` but not `BLOCK_RECEIVED`, is for avoiding
458463
// stopping synchronization even when orphan_pool maintains dirty items by bugs.
459464
if status.contains(BlockStatus::BLOCK_STORED) {
460465
error!("Block {} already stored", block_hash);
461466
} else if status.contains(BlockStatus::HEADER_VALID) {
467+
debug!("Calling accept_remote_block for {}-{}", block_number, block_hash);
462468
self.shared.accept_remote_block(&self.chain, remote_block);
463469
} else {
464470
debug!(

sync/src/types/mod.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,16 +1083,28 @@ impl SyncShared {
10831083
}
10841084

10851085
pub(crate) fn accept_remote_block(&self, chain: &ChainController, remote_block: RemoteBlock) {
1086+
let block_number = remote_block.block.number();
1087+
let block_hash = remote_block.block.header().hash();
1088+
debug!(
1089+
"accept_remote_block {}-{}",
1090+
block_number,
1091+
block_hash
1092+
);
10861093
{
10871094
let entry = self
10881095
.shared()
10891096
.block_status_map()
1090-
.entry(remote_block.block.header().hash());
1097+
.entry(block_hash.clone());
10911098
if let dashmap::mapref::entry::Entry::Vacant(entry) = entry {
10921099
entry.insert(BlockStatus::BLOCK_RECEIVED);
10931100
}
10941101
}
10951102

1103+
debug!(
1104+
"Calling chain.asynchronous_process_remote_block for {}-{}",
1105+
block_number,
1106+
block_hash
1107+
);
10961108
chain.asynchronous_process_remote_block(remote_block)
10971109
}
10981110

@@ -1211,6 +1223,15 @@ impl SyncShared {
12111223
// Commit ONCE - single fsync for all headers
12121224
db_txn.commit().expect("commit should be ok");
12131225

1226+
debug!(
1227+
"insert_valid_headers_batch committed {} headers, range: {}-{} to {}-{}",
1228+
headers.len(),
1229+
headers.first().map(|h| h.number()).unwrap_or(0),
1230+
headers.first().map(|h| h.hash()).unwrap_or_default(),
1231+
headers.last().map(|h| h.number()).unwrap_or(0),
1232+
headers.last().map(|h| h.hash()).unwrap_or_default()
1233+
);
1234+
12141235
last_header_index
12151236
}
12161237

0 commit comments

Comments
 (0)