Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
verifier: Verify if the block contain txn in blacklist
  • Loading branch information
sanlee42 committed Mar 7, 2024
1 parent 7811626 commit 09d21fc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 0 additions & 1 deletion chain/open-block/src/lib.rs
Expand Up @@ -295,7 +295,6 @@ impl OpenedBlock {
Ok(block_template)
}
}

pub struct AddressFilter;
impl AddressFilter {
const BLACKLIST: Vec<AccountAddress> = vec![]; //TODO: Fill in
Expand Down
14 changes: 14 additions & 0 deletions chain/src/verifier/mod.rs
Expand Up @@ -8,6 +8,7 @@ use starcoin_chain_api::{
};
use starcoin_consensus::{Consensus, ConsensusVerifyError};
use starcoin_logger::prelude::debug;
use starcoin_open_block::AddressFilter;
use starcoin_types::block::{Block, BlockHeader, ALLOWED_FUTURE_BLOCKTIME};
use std::{collections::HashSet, str::FromStr};

Expand Down Expand Up @@ -68,6 +69,7 @@ pub trait BlockVerifier {
watch(CHAIN_WATCH_NAME, "n11");
//verify header
let new_block_header = new_block.header();
Self::verify_blacklisted_txns(&new_block)?;
Self::verify_header(current_chain, new_block_header)?;
watch(CHAIN_WATCH_NAME, "n12");
StaticVerifier::verify_body_hash(&new_block)?;
Expand All @@ -82,6 +84,18 @@ pub trait BlockVerifier {
Ok(VerifiedBlock(new_block))
}

fn verify_blacklisted_txns(new_block: &Block) -> Result<()> {
let block_number = new_block.header().number();
for txn in new_block.transactions() {
verify_block!(
VerifyBlockField::Body,
!AddressFilter::is_blacklisted(txn, block_number),
"Invalid block: the sender of transaction in block must be not blacklisted"
);
}
Ok(())
}

fn verify_uncles<R>(
current_chain: &R,
uncles: &[BlockHeader],
Expand Down

0 comments on commit 09d21fc

Please sign in to comment.