From 39d3c7c15e7069d196a43c5fa14a9eee296f260b Mon Sep 17 00:00:00 2001 From: Park Juhyung Date: Thu, 16 Apr 2020 17:10:48 +0900 Subject: [PATCH 1/4] Rename import_headers to import_verified_headers Client::import_header function receives a header that is not verified. Importer::import_headers assumes that received headers are verified. To reduce misunderstanding, I renamed the function. --- core/src/client/client.rs | 4 ++-- core/src/client/importer.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/client/client.rs b/core/src/client/client.rs index 54ea12bfd5..2fb9bf0e71 100644 --- a/core/src/client/client.rs +++ b/core/src/client/client.rs @@ -152,7 +152,7 @@ impl Client { /// This is triggered by a message coming from a header queue when the header is ready for insertion pub fn import_verified_headers(&self) -> usize { - self.importer.import_verified_headers(self) + self.importer.import_verified_headers_from_queue(self) } /// This is triggered by a message coming from a block queue when the block is ready for insertion @@ -455,7 +455,7 @@ impl ImportBlock for Client { let block_data = block.rlp_bytes(); let header = block.header(); - self.importer.import_headers(vec![header], self, &import_lock); + self.importer.import_verified_headers(vec![header], self, &import_lock); let update_result = self.importer.commit_block(block, header, &block_data, self); cinfo!(CLIENT, "Imported closed block #{} ({})", number, h); diff --git a/core/src/client/importer.rs b/core/src/client/importer.rs index 29f213f391..72ff5b583b 100644 --- a/core/src/client/importer.rs +++ b/core/src/client/importer.rs @@ -94,7 +94,7 @@ impl Importer { { let headers: Vec<_> = blocks.iter().map(|block| &block.header).collect(); - self.import_headers(headers, client, &import_lock); + self.import_verified_headers(headers, client, &import_lock); } for block in blocks { @@ -255,14 +255,14 @@ impl Importer { } /// This is triggered by a message coming from a header queue when the header is ready for insertion - pub fn import_verified_headers(&self, client: &Client) -> usize { + pub fn import_verified_headers_from_queue(&self, client: &Client) -> usize { const MAX_HEADERS_TO_IMPORT: usize = 1_000; let lock = self.import_lock.lock(); let headers = self.header_queue.drain(MAX_HEADERS_TO_IMPORT); - self.import_headers(&headers, client, &lock) + self.import_verified_headers(&headers, client, &lock) } - pub fn import_headers<'a>( + pub fn import_verified_headers<'a>( &'a self, headers: impl IntoIterator, client: &Client, From d3d32b261873d35d80dff8d06a0ed66d38e80932 Mon Sep 17 00:00:00 2001 From: Park Juhyung Date: Thu, 16 Apr 2020 17:32:35 +0900 Subject: [PATCH 2/4] Change deprecated "bootstrap" word in a comment Previously we called a block received by snapshot sync as "bootstrap block". Now we're calling it "floating block". --- core/src/blockchain/blockchain.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/blockchain/blockchain.rs b/core/src/blockchain/blockchain.rs index a9a4d99655..cd62679bb8 100644 --- a/core/src/blockchain/blockchain.rs +++ b/core/src/blockchain/blockchain.rs @@ -112,7 +112,7 @@ impl BlockChain { let header = block.header_view(); let hash = header.hash(); - ctrace!(BLOCKCHAIN, "Inserting bootstrap block #{}({}) to the blockchain.", header.number(), hash); + ctrace!(BLOCKCHAIN, "Inserting floating block #{}({}) to the blockchain.", header.number(), hash); if self.is_known(&hash) { cdebug!(BLOCKCHAIN, "Block #{}({}) is already known.", header.number(), hash); From 4408de64431e49f234ca8673a1d19df9feb1fb6e Mon Sep 17 00:00:00 2001 From: Park Juhyung Date: Thu, 16 Apr 2020 17:37:22 +0900 Subject: [PATCH 3/4] Rename import_closed_block to import_generated_block The name `import_closed_block` does not give enough context. --- core/src/client/client.rs | 2 +- core/src/client/mod.rs | 4 ++-- core/src/client/test_client.rs | 2 +- core/src/miner/miner.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/client/client.rs b/core/src/client/client.rs index 2fb9bf0e71..df7f3ce4c8 100644 --- a/core/src/client/client.rs +++ b/core/src/client/client.rs @@ -445,7 +445,7 @@ impl ImportBlock for Client { self.importer.force_update_best_block(hash, self) } - fn import_closed_block(&self, block: &ClosedBlock) -> ImportResult { + fn import_generated_block(&self, block: &ClosedBlock) -> ImportResult { let h = block.header().hash(); let update_result = { // scope for self.import_lock diff --git a/core/src/client/mod.rs b/core/src/client/mod.rs index e4ce4e70f0..34c2bbe1ee 100644 --- a/core/src/client/mod.rs +++ b/core/src/client/mod.rs @@ -172,8 +172,8 @@ pub trait ImportBlock { /// Forcefully update the best block fn force_update_best_block(&self, hash: &BlockHash); - /// Import closed block. Skips all verifications. - fn import_closed_block(&self, block: &ClosedBlock) -> ImportResult; + /// Import closed block. Skips all verifications. This block is generated by this instance. + fn import_generated_block(&self, block: &ClosedBlock) -> ImportResult; /// Set reseal min timer as reseal_min_period, for creating blocks with transactions which are pending because of reseal_min_period fn set_min_timer(&self); diff --git a/core/src/client/test_client.rs b/core/src/client/test_client.rs index f4e577d777..805fa4fcd4 100644 --- a/core/src/client/test_client.rs +++ b/core/src/client/test_client.rs @@ -474,7 +474,7 @@ impl ImportBlock for TestBlockChainClient { unimplemented!() } - fn import_closed_block(&self, _block: &ClosedBlock) -> ImportResult { + fn import_generated_block(&self, _block: &ClosedBlock) -> ImportResult { Ok(H256::default().into()) } diff --git a/core/src/miner/miner.rs b/core/src/miner/miner.rs index 50ca1b8889..5e35f01c06 100644 --- a/core/src/miner/miner.rs +++ b/core/src/miner/miner.rs @@ -379,7 +379,7 @@ impl Miner { self.engine.proposal_generated(&block); } - chain.import_closed_block(&block).is_ok() + chain.import_generated_block(&block).is_ok() } /// Are we allowed to do a non-mandatory reseal? From 83da1249302ca48b320cd56ce4e9d3474d803018 Mon Sep 17 00:00:00 2001 From: Park Juhyung Date: Thu, 16 Apr 2020 17:41:48 +0900 Subject: [PATCH 4/4] Add a comment in the import_trusted_{header, block} import_trusted_{header, block} are called by snapshot code. They can import header and block that don't have parents. We need a better name for them. --- core/src/client/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/client/mod.rs b/core/src/client/mod.rs index 34c2bbe1ee..9a0e674776 100644 --- a/core/src/client/mod.rs +++ b/core/src/client/mod.rs @@ -163,10 +163,12 @@ pub trait ImportBlock { /// Import a trusted header into the blockchain /// Trusted header doesn't go through any verifications and doesn't update the best header + /// The trusted header may not have parent. fn import_trusted_header(&self, header: Header) -> Result; /// Import a trusted block into the blockchain /// Trusted block doesn't go through any verifications and doesn't update the best block + /// The trusted block may not have parent. fn import_trusted_block(&self, block: &Block) -> Result; /// Forcefully update the best block