Skip to content

Commit

Permalink
Allow disable FrontierBlockImport (#127)
Browse files Browse the repository at this point in the history
* allow to disable index

* allow disable ethereum indexing
  • Loading branch information
xlc committed Sep 14, 2020
1 parent 34ed45f commit e2eb816
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
40 changes: 23 additions & 17 deletions consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl std::convert::From<Error> for ConsensusError {
pub struct FrontierBlockImport<B: BlockT, I, C> {
inner: I,
client: Arc<C>,
enabled: bool,
_marker: PhantomData<B>,
}

Expand All @@ -68,6 +69,7 @@ impl<Block: BlockT, I: Clone + BlockImport<Block>, C> Clone for FrontierBlockImp
FrontierBlockImport {
inner: self.inner.clone(),
client: self.client.clone(),
enabled: self.enabled,
_marker: PhantomData,
}
}
Expand All @@ -83,10 +85,12 @@ impl<B, I, C> FrontierBlockImport<B, I, C> where
pub fn new(
inner: I,
client: Arc<C>,
enabled: bool,
) -> Self {
Self {
inner,
client,
enabled,
_marker: PhantomData,
}
}
Expand Down Expand Up @@ -122,23 +126,25 @@ impl<B, I, C> BlockImport<B> for FrontierBlockImport<B, I, C> where
)
}

let log = find_frontier_log::<B>(&block.header)?;
let hash = block.post_hash();

match log {
ConsensusLog::EndBlock {
block_hash, transaction_hashes,
} => {
aux_schema::write_block_hash(block_hash, hash, insert_closure!());

for (index, transaction_hash) in transaction_hashes.into_iter().enumerate() {
aux_schema::write_transaction_metadata(
transaction_hash,
(block_hash, index as u32),
insert_closure!(),
);
}
},
if self.enabled {
let log = find_frontier_log::<B>(&block.header)?;
let hash = block.post_hash();

match log {
ConsensusLog::EndBlock {
block_hash, transaction_hashes,
} => {
aux_schema::write_block_hash(block_hash, hash, insert_closure!());

for (index, transaction_hash) in transaction_hashes.into_iter().enumerate() {
aux_schema::write_transaction_metadata(
transaction_hash,
(block_hash, index as u32),
insert_closure!(),
);
}
},
}
}

self.inner.import_block(block, new_cache).map_err(Into::into)
Expand Down
3 changes: 2 additions & 1 deletion template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ pub fn new_partial(config: &Configuration, manual_seal: bool) -> Result<

let frontier_block_import = FrontierBlockImport::new(
grandpa_block_import.clone(),
client.clone()
client.clone(),
true
);

let aura_block_import = sc_consensus_aura::AuraBlockImport::<_, _, _, AuraPair>::new(
Expand Down

0 comments on commit e2eb816

Please sign in to comment.