Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
miner: Excluded transactions from blacklisted addresses during create…
… block template
  • Loading branch information
sanlee42 committed Mar 7, 2024
1 parent 50d34f8 commit 7811626
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions chain/open-block/src/lib.rs
Expand Up @@ -10,6 +10,7 @@ use starcoin_logger::prelude::*;
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 @@ impl OpenedBlock {
/// 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());
}
!is_blacklisted
})
.map(Transaction::UserTransaction)
.collect();

Expand All @@ -165,8 +174,6 @@ impl OpenedBlock {
.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,12 @@ impl OpenedBlock {
Ok(block_template)
}
}

pub struct AddressFilter;
impl AddressFilter {
const BLACKLIST: Vec<AccountAddress> = vec![]; //TODO: Fill in
const ACTIVATION_BLOCK_NUMBER: BlockNumber = 16801958;
pub fn is_blacklisted(raw_txn: &SignedUserTransaction, block_number: BlockNumber) -> bool {
block_number > Self::ACTIVATION_BLOCK_NUMBER && Self::BLACKLIST.contains(&raw_txn.sender())
}
}

0 comments on commit 7811626

Please sign in to comment.