Skip to content

add filter in service.rs #1673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions node/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Service and ServiceFactory implementation. Specialized wrapper over substrate service.

use sp_core::U256;
use fp_consensus::{FindLogError, ensure_log};
use fp_rpc::EthereumRuntimeRPCApi;
use futures::{FutureExt, channel::mpsc, future};
@@ -266,6 +267,22 @@ where
}

async fn import_block(&self, block: BlockImportParams<B>) -> Result<ImportResult, Self::Error> {
// Filter blocks from before safe block
let hash = block.post_hash();
let hash_str = format!("{:?}", hash);
let block_number: U256 = block.header.number().clone().into();
log::warn!( "check import_block: hash: {:?}, number: {:?}", hash_str, block_number );
if hash_str.starts_with("0xe2fb") {
log::warn!("🚫 Rejecting known bad block with hash prefix 0xe2fb");
return Err(ConsensusError::ClientImport(format!(
"Rejected known bad block: {}",
hash_str
)));
}
if block.header.number().clone().into() < sp_core::U256::from(5_614_089) {
log::warn!("🛡️ Rejecting block #{} below safe height", 5_614_089);
return Err(ConsensusError::ClientImport("Block number below safe block".into()));
}
// Import like Frontier, but fallback to grandpa import for errors
match ensure_log(block.header.digest()).map_err(Error::from) {
Ok(()) => self.inner.import_block(block).await.map_err(Into::into),