Skip to content

Commit

Permalink
Revert "Reset to main 16801958 and forbid the tx"
Browse files Browse the repository at this point in the history
This reverts commit d0e1ed2.

Revert "Forbid all txns and reset block number to 21306000 on barnard"

This reverts commit 5a6816c.

Revert "cargo fmt"

This reverts commit 8e7d414.

Revert "testing blacklist"

This reverts commit 29845e9.

Revert "verifier: Verify if the block contain txn in blacklist"

This reverts commit 09d21fc.

Revert "miner: Excluded transactions from blacklisted addresses during create block template"

This reverts commit 7811626.

Revert "rollback chain head (#4010)"

This reverts commit a953701.
  • Loading branch information
sanlee42 committed Mar 11, 2024
1 parent 216781c commit 4b46c77
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 160 deletions.
28 changes: 4 additions & 24 deletions chain/open-block/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ 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 @@ -137,17 +136,9 @@ 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
.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
})
.iter()
.cloned()
.map(Transaction::UserTransaction)
.collect();

Expand All @@ -174,6 +165,8 @@ 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 @@ -295,16 +288,3 @@ impl OpenedBlock {
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: 0 additions & 14 deletions chain/src/verifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ 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 @@ -69,7 +68,6 @@ 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 @@ -84,18 +82,6 @@ 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
1 change: 0 additions & 1 deletion node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ impl NodeService {
let start_time = SystemTime::now();
storage_instance.check_upgrade()?;
storage_instance.barnard_hard_fork(config.clone())?;
storage_instance.dragon_hard_fork(config.clone())?;
let upgrade_time = SystemTime::now().duration_since(start_time)?;
let storage = Arc::new(Storage::new(storage_instance)?);
registry.put_shared(storage.clone()).await?;
Expand Down
18 changes: 1 addition & 17 deletions storage/src/chain_info/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::storage::{ColumnFamily, InnerStorage, KVStore};
use crate::{StorageVersion, CHAIN_INFO_PREFIX_NAME};
use anyhow::Result;
use starcoin_crypto::HashValue;
use starcoin_types::startup_info::{BarnardHardFork, DragonHardFork, SnapshotRange, StartupInfo};
use starcoin_types::startup_info::{BarnardHardFork, SnapshotRange, StartupInfo};
use std::convert::{TryFrom, TryInto};

#[derive(Clone)]
Expand All @@ -28,7 +28,6 @@ impl ChainInfoStorage {
const STORAGE_VERSION_KEY: &'static str = "storage_version";
const SNAPSHOT_RANGE_KEY: &'static str = "snapshot_height";
const BARNARD_HARD_FORK: &'static str = "barnard_hard_fork";
const DRAGON_HARD_FORK: &'static str = "dragon_hard_fork";

pub fn get_startup_info(&self) -> Result<Option<StartupInfo>> {
self.get(Self::STARTUP_INFO_KEY.as_bytes())
Expand Down Expand Up @@ -112,19 +111,4 @@ impl ChainInfoStorage {
barnard_hard_fork.try_into()?,
)
}

pub fn get_dragon_hard_fork(&self) -> Result<Option<DragonHardFork>> {
self.get(Self::DRAGON_HARD_FORK.as_bytes())
.and_then(|bytes| match bytes {
Some(bytes) => Ok(Some(bytes.try_into()?)),
None => Ok(None),
})
}

pub fn save_dragon_hard_fork(&self, dragon_hard_fork: DragonHardFork) -> Result<()> {
self.put_sync(
Self::DRAGON_HARD_FORK.as_bytes().to_vec(),
dragon_hard_fork.try_into()?,
)
}
}
8 changes: 0 additions & 8 deletions storage/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,6 @@ impl StorageInstance {
}
Ok(())
}

pub fn dragon_hard_fork(&mut self, config: Arc<NodeConfig>) -> Result<()> {
if config.net().id().chain_id().is_main() {
info!("dragon_hard_fork in");
return DBUpgrade::dragon_hard_fork(self);
}
Ok(())
}
}

impl InnerStore for StorageInstance {
Expand Down
60 changes: 1 addition & 59 deletions storage/src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use once_cell::sync::Lazy;
use starcoin_crypto::HashValue;
use starcoin_logger::prelude::{debug, info, warn};
use starcoin_types::block::BlockNumber;
use starcoin_types::startup_info::{BarnardHardFork, DragonHardFork, StartupInfo};
use starcoin_types::startup_info::{BarnardHardFork, StartupInfo};
use starcoin_types::transaction::Transaction;
use std::cmp::Ordering;

Expand All @@ -30,14 +30,6 @@ pub static BARNARD_HARD_FORK_HASH: Lazy<HashValue> = Lazy::new(|| {
.expect("")
});

pub static DRAGON_HARD_FORK_HEIGHT: BlockNumber = 16801958;
pub static DRAGON_HARD_FORK_HASH: Lazy<HashValue> = Lazy::new(|| {
HashValue::from_hex_literal(
"0xbef8d0af3b358af9fe25f7383fd2580679c54fe2ce7ff7a7434785ba6d11b943",
)
.expect("")
});

impl DBUpgrade {
pub fn check_upgrade(instance: &mut StorageInstance) -> Result<()> {
let version_in_db = {
Expand Down Expand Up @@ -241,54 +233,4 @@ impl DBUpgrade {
}
Ok(())
}

pub fn dragon_hard_fork(instance: &mut StorageInstance) -> Result<()> {
let block_storage = BlockStorage::new(instance.clone());
let chain_info_storage = ChainInfoStorage::new(instance.clone());
let hard_fork = chain_info_storage.get_dragon_hard_fork()?;

let fork_info = DragonHardFork::new(DRAGON_HARD_FORK_HEIGHT, *DRAGON_HARD_FORK_HASH);
if hard_fork == Some(fork_info.clone()) {
info!("dragon hard forked");
return Ok(());
}

let block = block_storage.get_block_by_hash(*DRAGON_HARD_FORK_HASH)?;
if let Some(block) = block {
if block.header().number() == DRAGON_HARD_FORK_HEIGHT {
info!("dragon hard fork rollback height");
let mut to_deleted = vec![];
let mut iter = block_storage.header_store.iter()?;
iter.seek_to_first();
for item in iter {
let (id, block_header) = item?;
if block_header.number() > DRAGON_HARD_FORK_HEIGHT {
to_deleted.push(id);
}
}
let block_info_storage = BlockInfoStorage::new(instance.clone());
let mut processed_count = 0;
for id in to_deleted {
block_info_storage.remove(id)?;
block_storage.delete_block(id)?;
processed_count += 1;
if processed_count % 10000 == 0 {
info!(
"dragon hard fork rollback height processed items: {}",
processed_count
);
}
}
if processed_count % 10000 != 0 {
info!(
"dragon hard fork rollback height processed items: {}",
processed_count
);
}
chain_info_storage.save_dragon_hard_fork(fork_info)?;
chain_info_storage.save_startup_info(StartupInfo::new(*DRAGON_HARD_FORK_HASH))?;
}
}
Ok(())
}
}
37 changes: 0 additions & 37 deletions types/src/startup_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,40 +281,3 @@ impl TryInto<Vec<u8>> for BarnardHardFork {
self.encode()
}
}

#[derive(Eq, PartialEq, Hash, Deserialize, Serialize, Clone, Debug)]
pub struct DragonHardFork {
// block whose number is greater than `number` will be purged
number: BlockNumber,
hash: HashValue,
}

impl DragonHardFork {
pub fn new(number: BlockNumber, hash: HashValue) -> Self {
Self { number, hash }
}

pub fn get_number(&self) -> BlockNumber {
self.number
}

pub fn get_hash(&self) -> HashValue {
self.hash
}
}

impl TryFrom<Vec<u8>> for DragonHardFork {
type Error = anyhow::Error;

fn try_from(value: Vec<u8>) -> Result<Self> {
DragonHardFork::decode(value.as_slice())
}
}

impl TryInto<Vec<u8>> for DragonHardFork {
type Error = anyhow::Error;

fn try_into(self) -> Result<Vec<u8>> {
self.encode()
}
}

0 comments on commit 4b46c77

Please sign in to comment.