From 5a2fecb63194d844232b3f5f88aae1ef390d6809 Mon Sep 17 00:00:00 2001 From: sanlee42 Date: Mon, 19 Feb 2024 22:57:55 +0800 Subject: [PATCH 1/6] miner: Excluded transactions from blacklisted addresses during create block template --- chain/open-block/src/lib.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/chain/open-block/src/lib.rs b/chain/open-block/src/lib.rs index 7df7510ecd..0c9b65908a 100644 --- a/chain/open-block/src/lib.rs +++ b/chain/open-block/src/lib.rs @@ -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::{ @@ -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) -> Result { + let mut discard_txns: Vec = 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(); @@ -165,8 +174,6 @@ impl OpenedBlock { .map(|t| t.try_into().expect("user txn")) .collect() }; - - let mut discard_txns: Vec = 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(); @@ -288,3 +295,12 @@ impl OpenedBlock { Ok(block_template) } } + +pub struct AddressFilter; +impl AddressFilter { + const BLACKLIST: Vec = 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()) + } +} From ea7f41b4d76eef46a54e7ea6d41cc75018be42af Mon Sep 17 00:00:00 2001 From: sanlee42 Date: Tue, 20 Feb 2024 00:14:31 +0800 Subject: [PATCH 2/6] verifier: Verify if the block contain txn in blacklist --- chain/open-block/src/lib.rs | 1 - chain/src/verifier/mod.rs | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/chain/open-block/src/lib.rs b/chain/open-block/src/lib.rs index 0c9b65908a..1feef824eb 100644 --- a/chain/open-block/src/lib.rs +++ b/chain/open-block/src/lib.rs @@ -295,7 +295,6 @@ impl OpenedBlock { Ok(block_template) } } - pub struct AddressFilter; impl AddressFilter { const BLACKLIST: Vec = vec![]; //TODO: Fill in diff --git a/chain/src/verifier/mod.rs b/chain/src/verifier/mod.rs index 247129eb35..3994d99f8d 100644 --- a/chain/src/verifier/mod.rs +++ b/chain/src/verifier/mod.rs @@ -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}; @@ -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)?; @@ -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( current_chain: &R, uncles: &[BlockHeader], From f1fdb4164a0cdf22fa4bc0c257cc1ab5034449d2 Mon Sep 17 00:00:00 2001 From: sanlee42 Date: Tue, 20 Feb 2024 19:40:03 +0800 Subject: [PATCH 3/6] testing blacklist --- chain/open-block/src/lib.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/chain/open-block/src/lib.rs b/chain/open-block/src/lib.rs index 1feef824eb..74da19bf9f 100644 --- a/chain/open-block/src/lib.rs +++ b/chain/open-block/src/lib.rs @@ -23,6 +23,7 @@ use starcoin_types::{ }, U256, }; +use std::str::FromStr; use std::{convert::TryInto, sync::Arc}; pub struct OpenedBlock { @@ -296,10 +297,15 @@ impl OpenedBlock { } } pub struct AddressFilter; +static BLACKLIST: [&str; 2] = ["0x5d3729704311db3ac10ee04d08054543","0xda507619aedef9755faf2111cd63d3c5"]; impl AddressFilter { - const BLACKLIST: Vec = vec![]; //TODO: Fill in - const ACTIVATION_BLOCK_NUMBER: BlockNumber = 16801958; + const ACTIVATION_BLOCK_NUMBER: BlockNumber = 10; pub fn is_blacklisted(raw_txn: &SignedUserTransaction, block_number: BlockNumber) -> bool { - block_number > Self::ACTIVATION_BLOCK_NUMBER && Self::BLACKLIST.contains(&raw_txn.sender()) + let blacklist: Vec = BLACKLIST + .iter() + .map(|&s| AccountAddress::from_str(s).expect("account address decode must success")) + .collect(); + + block_number > Self::ACTIVATION_BLOCK_NUMBER && blacklist.contains(&raw_txn.sender()) } } From 6c17cf2ea69cc0359cd43edc8dafd0d781c998c3 Mon Sep 17 00:00:00 2001 From: sanlee42 Date: Tue, 27 Feb 2024 09:31:19 +0800 Subject: [PATCH 4/6] cargo fmt --- chain/open-block/src/lib.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/chain/open-block/src/lib.rs b/chain/open-block/src/lib.rs index 74da19bf9f..ee1a277b79 100644 --- a/chain/open-block/src/lib.rs +++ b/chain/open-block/src/lib.rs @@ -297,15 +297,14 @@ impl OpenedBlock { } } pub struct AddressFilter; -static BLACKLIST: [&str; 2] = ["0x5d3729704311db3ac10ee04d08054543","0xda507619aedef9755faf2111cd63d3c5"]; +static BLACKLIST: [&str; 0] = []; impl AddressFilter { - const ACTIVATION_BLOCK_NUMBER: BlockNumber = 10; + const ACTIVATION_BLOCK_NUMBER: BlockNumber = 16801958; pub fn is_blacklisted(raw_txn: &SignedUserTransaction, block_number: BlockNumber) -> bool { - let blacklist: Vec = BLACKLIST - .iter() - .map(|&s| AccountAddress::from_str(s).expect("account address decode must success")) - .collect(); - - block_number > Self::ACTIVATION_BLOCK_NUMBER && blacklist.contains(&raw_txn.sender()) + 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()) } } From 80b0b432e916cb936ed523906092b489de0f2fc6 Mon Sep 17 00:00:00 2001 From: sanlee42 Date: Wed, 6 Mar 2024 11:13:58 +0800 Subject: [PATCH 5/6] Forbid all txns and reset block number to 21306000 on barnard --- chain/open-block/src/lib.rs | 16 ++++++++-------- storage/src/upgrade.rs | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/chain/open-block/src/lib.rs b/chain/open-block/src/lib.rs index ee1a277b79..36096dbb04 100644 --- a/chain/open-block/src/lib.rs +++ b/chain/open-block/src/lib.rs @@ -23,7 +23,6 @@ use starcoin_types::{ }, U256, }; -use std::str::FromStr; use std::{convert::TryInto, sync::Arc}; pub struct OpenedBlock { @@ -297,14 +296,15 @@ impl OpenedBlock { } } pub struct AddressFilter; -static BLACKLIST: [&str; 0] = []; +//static BLACKLIST: [&str; 0] = []; impl AddressFilter { - const ACTIVATION_BLOCK_NUMBER: BlockNumber = 16801958; - pub fn is_blacklisted(raw_txn: &SignedUserTransaction, block_number: BlockNumber) -> bool { + const ACTIVATION_BLOCK_NUMBER: BlockNumber = 21306000; + 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()) + /*&& BLACKLIST + .iter() + .map(|&s| AccountAddress::from_str(s).expect("account address decode must success")) + .any(|x| x == raw_txn.sender()) + */ } } diff --git a/storage/src/upgrade.rs b/storage/src/upgrade.rs index d4a57a38e1..f37631a80b 100644 --- a/storage/src/upgrade.rs +++ b/storage/src/upgrade.rs @@ -22,10 +22,10 @@ use std::cmp::Ordering; pub struct DBUpgrade; -pub static BARNARD_HARD_FORK_HEIGHT: BlockNumber = 16057420; +pub static BARNARD_HARD_FORK_HEIGHT: BlockNumber = 21306000; pub static BARNARD_HARD_FORK_HASH: Lazy = Lazy::new(|| { HashValue::from_hex_literal( - "0x602bb269e3a221510f82b0b812304e767457f73ac3203663bd401ef3d29bcc97", + "0x3ba2430287c538668c2a3d96a98b57c1ec843f48b5a4e870149ec6289b80413b", ) .expect("") }); From 82b6c1eb43cbe0a7a923340aa507cceef9ee2259 Mon Sep 17 00:00:00 2001 From: sanlee42 Date: Thu, 7 Mar 2024 11:17:40 +0800 Subject: [PATCH 6/6] Reset to main 16801958 and forbid the tx --- chain/open-block/src/lib.rs | 2 +- storage/src/upgrade.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/chain/open-block/src/lib.rs b/chain/open-block/src/lib.rs index 36096dbb04..54104c4440 100644 --- a/chain/open-block/src/lib.rs +++ b/chain/open-block/src/lib.rs @@ -298,7 +298,7 @@ impl OpenedBlock { pub struct AddressFilter; //static BLACKLIST: [&str; 0] = []; impl AddressFilter { - const ACTIVATION_BLOCK_NUMBER: BlockNumber = 21306000; + const ACTIVATION_BLOCK_NUMBER: BlockNumber = 16801958; pub fn is_blacklisted(_raw_txn: &SignedUserTransaction, block_number: BlockNumber) -> bool { block_number > Self::ACTIVATION_BLOCK_NUMBER /*&& BLACKLIST diff --git a/storage/src/upgrade.rs b/storage/src/upgrade.rs index f37631a80b..d4a57a38e1 100644 --- a/storage/src/upgrade.rs +++ b/storage/src/upgrade.rs @@ -22,10 +22,10 @@ use std::cmp::Ordering; pub struct DBUpgrade; -pub static BARNARD_HARD_FORK_HEIGHT: BlockNumber = 21306000; +pub static BARNARD_HARD_FORK_HEIGHT: BlockNumber = 16057420; pub static BARNARD_HARD_FORK_HASH: Lazy = Lazy::new(|| { HashValue::from_hex_literal( - "0x3ba2430287c538668c2a3d96a98b57c1ec843f48b5a4e870149ec6289b80413b", + "0x602bb269e3a221510f82b0b812304e767457f73ac3203663bd401ef3d29bcc97", ) .expect("") });