Skip to content
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

miner: Excluded transactions from blacklisted addresses during create block template #4008

Merged
merged 6 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
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
28 changes: 24 additions & 4 deletions chain/open-block/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use starcoin_state_api::{ChainStateReader, ChainStateWriter};
use starcoin_statedb::ChainStateDB;
use starcoin_storage::Store;
use starcoin_types::block::BlockNumber;
use starcoin_types::genesis_config::{ChainId, ConsensusStrategy};
use starcoin_types::vm_error::KeptVMStatus;
use starcoin_types::{
Expand Down Expand Up @@ -136,9 +137,17 @@
/// as the internal state may be corrupted.
/// TODO: make the function can be called again even last call returns error.
pub fn push_txns(&mut self, user_txns: Vec<SignedUserTransaction>) -> Result<ExcludedTxns> {
let mut discard_txns: Vec<SignedUserTransaction> = Vec::new();
let mut txns: Vec<_> = user_txns
.iter()
.cloned()
.into_iter()
.filter(|txn| {
let is_blacklisted = AddressFilter::is_blacklisted(txn, self.block_number());
// Discard the txns send by the account in black list after a block number.
if is_blacklisted {
discard_txns.push(txn.clone());

Check warning on line 147 in chain/open-block/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

chain/open-block/src/lib.rs#L147

Added line #L147 was not covered by tests
}
!is_blacklisted
})
.map(Transaction::UserTransaction)
.collect();

Expand All @@ -165,8 +174,6 @@
.map(|t| t.try_into().expect("user txn"))
.collect()
};

let mut discard_txns: Vec<SignedUserTransaction> = Vec::new();
debug_assert_eq!(txns.len(), txn_outputs.len());
for (txn, output) in txns.into_iter().zip(txn_outputs.into_iter()) {
let txn_hash = txn.id();
Expand Down Expand Up @@ -288,3 +295,16 @@
Ok(block_template)
}
}
pub struct AddressFilter;
//static BLACKLIST: [&str; 0] = [];
impl AddressFilter {
const ACTIVATION_BLOCK_NUMBER: BlockNumber = 16801958;
pub fn is_blacklisted(_raw_txn: &SignedUserTransaction, block_number: BlockNumber) -> bool {
block_number > Self::ACTIVATION_BLOCK_NUMBER
/*&& BLACKLIST
.iter()
.map(|&s| AccountAddress::from_str(s).expect("account address decode must success"))
.any(|x| x == raw_txn.sender())
*/
}
}
14 changes: 14 additions & 0 deletions chain/src/verifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
};
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 @@
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 @@
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,

Check warning on line 91 in chain/src/verifier/mod.rs

View check run for this annotation

Codecov / codecov/patch

chain/src/verifier/mod.rs#L91

Added line #L91 was not covered by tests
!AddressFilter::is_blacklisted(txn, block_number),
"Invalid block: the sender of transaction in block must be not blacklisted"

Check warning on line 93 in chain/src/verifier/mod.rs

View check run for this annotation

Codecov / codecov/patch

chain/src/verifier/mod.rs#L93

Added line #L93 was not covered by tests
);
}
Ok(())
}

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