This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
block cleanup #9117
Merged
Merged
block cleanup #9117
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a0610a7
blockchain insert expects owned block instead of block reference
debris b09d311
reduce a number of times a block is deserialized
debris 21d429b
Merge branch 'master' into block_insert
debris 306bb01
removed cached uncle_bytes from block
debris e60d907
removed is_finalized from OpenBlock
debris 35c63ee
removed unused parity_machine::WithMetadata trait
debris 09d4961
removed commented out code
debris 21d3de2
Merge branch 'master' into block_insert
debris 461a428
Merge branch 'master' into block_insert
debris e64a006
remove unused metadata from block
debris a598be7
Merge branch 'master' into block_insert
debris 10d05d7
remove unused metadata from block
debris 8409d11
Merge branch 'master' into block_insert
debris 9e894e2
BlockDetails extras may have at most 5 elements
debris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,6 @@ use types::ancestry_action::AncestryAction; | |
use verification; | ||
use verification::{PreverifiedBlock, Verifier}; | ||
use verification::queue::BlockQueue; | ||
use views::BlockView; | ||
use parity_machine::{Finalizable, WithMetadata}; | ||
|
||
// re-export | ||
|
@@ -212,7 +211,7 @@ pub struct Client { | |
/// Queued ancient blocks, make sure they are imported in order. | ||
queued_ancient_blocks: Arc<RwLock<( | ||
HashSet<H256>, | ||
VecDeque<(Header, Bytes, Bytes)> | ||
VecDeque<(Header, encoded::Block, Bytes)> | ||
)>>, | ||
ancient_blocks_import_lock: Arc<Mutex<()>>, | ||
/// Consensus messages import queue | ||
|
@@ -299,7 +298,7 @@ impl Importer { | |
|
||
let transactions_len = closed_block.transactions().len(); | ||
|
||
let route = self.commit_block(closed_block, &header, &bytes, client); | ||
let route = self.commit_block(closed_block, &header, encoded::Block::new(bytes), client); | ||
import_results.push(route); | ||
|
||
client.report.write().accrue_block(&header, transactions_len); | ||
|
@@ -433,9 +432,8 @@ impl Importer { | |
/// | ||
/// The block is guaranteed to be the next best blocks in the | ||
/// first block sequence. Does no sealing or transaction validation. | ||
fn import_old_block(&self, header: &Header, block_bytes: &[u8], receipts_bytes: &[u8], db: &KeyValueDB, chain: &BlockChain) -> Result<H256, ::error::Error> { | ||
fn import_old_block(&self, header: &Header, block: encoded::Block, receipts_bytes: &[u8], db: &KeyValueDB, chain: &BlockChain) -> Result<(), ::error::Error> { | ||
let receipts = ::rlp::decode_list(receipts_bytes); | ||
let hash = header.hash(); | ||
let _import_lock = self.import_lock.lock(); | ||
|
||
{ | ||
|
@@ -446,20 +444,20 @@ impl Importer { | |
|
||
// Commit results | ||
let mut batch = DBTransaction::new(); | ||
chain.insert_unordered_block(&mut batch, block_bytes, receipts, None, false, true); | ||
chain.insert_unordered_block(&mut batch, block, receipts, None, false, true); | ||
// Final commit to the DB | ||
db.write_buffered(batch); | ||
chain.commit(); | ||
} | ||
db.flush().expect("DB flush failed."); | ||
Ok(hash) | ||
Ok(()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this value was never used, therefore not needed |
||
} | ||
|
||
// NOTE: the header of the block passed here is not necessarily sealed, as | ||
// it is for reconstructing the state transition. | ||
// | ||
// The header passed is from the original block data and is sealed. | ||
fn commit_block<B>(&self, block: B, header: &Header, block_data: &[u8], client: &Client) -> ImportRoute where B: IsBlock + Drain { | ||
fn commit_block<B>(&self, block: B, header: &Header, block_data: encoded::Block, client: &Client) -> ImportRoute where B: IsBlock + Drain { | ||
let hash = &header.hash(); | ||
let number = header.number(); | ||
let parent = header.parent_hash(); | ||
|
@@ -469,7 +467,7 @@ impl Importer { | |
let receipts = block.receipts().to_owned(); | ||
let traces = block.traces().clone().drain(); | ||
|
||
assert_eq!(header.hash(), view!(BlockView, block_data).header_view().hash()); | ||
debug_assert_eq!(header.hash(), block_data.header_view().hash()); | ||
|
||
//let traces = From::from(block.traces().clone().unwrap_or_else(Vec::new)); | ||
|
||
|
@@ -522,7 +520,7 @@ impl Importer { | |
// state. | ||
self.check_epoch_end_signal( | ||
&header, | ||
block_data, | ||
block_data.raw(), | ||
&receipts, | ||
&state, | ||
&chain, | ||
|
@@ -1331,7 +1329,7 @@ impl ChainInfo for Client { | |
} | ||
|
||
impl BlockInfo for Client { | ||
fn block_header(&self, id: BlockId) -> Option<::encoded::Header> { | ||
fn block_header(&self, id: BlockId) -> Option<encoded::Header> { | ||
let chain = self.chain.read(); | ||
|
||
Self::block_hash(&chain, id).and_then(|hash| chain.block_header_data(&hash)) | ||
|
@@ -2055,7 +2053,7 @@ impl IoClient for Client { | |
{ | ||
let mut queued = self.queued_ancient_blocks.write(); | ||
queued.0.insert(hash); | ||
queued.1.push_back((header, block_bytes, receipts_bytes)); | ||
queued.1.push_back((header, encoded::Block::new(block_bytes), receipts_bytes)); | ||
} | ||
|
||
let queued = self.queued_ancient_blocks.clone(); | ||
|
@@ -2071,7 +2069,7 @@ impl IoClient for Client { | |
let hash = header.hash(); | ||
let result = client.importer.import_old_block( | ||
&header, | ||
&block_bytes, | ||
block_bytes, | ||
&receipts_bytes, | ||
&**client.db.read().key_value(), | ||
&*client.chain.read(), | ||
|
@@ -2196,7 +2194,7 @@ impl ImportSealedBlock for Client { | |
let block_data = block.rlp_bytes(); | ||
let header = block.header().clone(); | ||
|
||
let route = self.importer.commit_block(block, &header, &block_data, self); | ||
let route = self.importer.commit_block(block, &header, encoded::Block::new(block_data), self); | ||
trace!(target: "client", "Imported sealed block #{} ({})", number, h); | ||
self.state_db.write().sync_cache(&route.enacted, &route.retracted, false); | ||
route | ||
|
@@ -2375,6 +2373,7 @@ mod tests { | |
use std::sync::atomic::{AtomicBool, Ordering}; | ||
use kvdb::DBTransaction; | ||
use blockchain::ExtrasInsert; | ||
use encoded; | ||
|
||
let client = generate_dummy_client(0); | ||
let genesis = client.chain_info().best_block_hash; | ||
|
@@ -2387,7 +2386,7 @@ mod tests { | |
let another_client = client.clone(); | ||
thread::spawn(move || { | ||
let mut batch = DBTransaction::new(); | ||
another_client.chain.read().insert_block(&mut batch, &new_block, Vec::new(), ExtrasInsert { | ||
another_client.chain.read().insert_block(&mut batch, encoded::Block::new(new_block), Vec::new(), ExtrasInsert { | ||
fork_choice: ::engines::ForkChoice::New, | ||
is_finalized: false, | ||
metadata: None, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in future, I'd like this function (and blockchain.rs functions) to take as argument some
MetaBlock
that contains both plain block and it's encoded version. Currently we are encoding and then decoding stuff that we just encoded. That's not efficient