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

Revert #2813 #2920

Merged
merged 2 commits into from
Jun 26, 2019
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
21 changes: 0 additions & 21 deletions chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,27 +685,6 @@ impl Chain {
))
}

/// To support the ability to download the txhashset from multiple peers in parallel,
/// the peers must all agree on the exact binary representation of the txhashset.
/// This means compacting and rewinding to the exact same header.
/// Since compaction is a heavy operation, peers can agree to compact every 12 hours,
/// and no longer support requesting arbitrary txhashsets.
/// Here we return the header of the txhashset we are currently offering to peers.
pub fn txhashset_archive_header(&self) -> Result<BlockHeader, Error> {
let sync_threshold = global::state_sync_threshold() as u64;
let body_head = self.head()?;
let archive_interval = global::txhashset_archive_interval();
let mut txhashset_height = body_head.height.saturating_sub(sync_threshold);
txhashset_height = txhashset_height.saturating_sub(txhashset_height % archive_interval);

debug!(
"txhashset_archive_header: body_head - {}, {}, txhashset height - {}",
body_head.last_block_h, body_head.height, txhashset_height,
);

self.get_header_by_height(txhashset_height)
}

// Special handling to make sure the whole kernel set matches each of its
// roots in each block header, without truncation. We go back header by
// header, rewind and check each root. This fixes a potential weakness in
Expand Down
4 changes: 2 additions & 2 deletions chain/src/txhashset/txhashset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1432,10 +1432,10 @@ pub fn zip_read(root_dir: String, header: &BlockHeader) -> Result<File, Error> {
} else {
// clean up old zips.
// Theoretically, we only need clean-up those zip files older than STATE_SYNC_THRESHOLD.
// But practically, these zip files are not small ones, we just keep the zips in last 24 hours
// But practically, these zip files are not small ones, we just keep the zips in last one hour
let data_dir = Path::new(&root_dir);
let pattern = format!("{}_", TXHASHSET_ZIP);
if let Ok(n) = clean_files_by_prefix(data_dir.clone(), &pattern, 24 * 60 * 60) {
if let Ok(n) = clean_files_by_prefix(data_dir.clone(), &pattern, 60 * 60) {
debug!(
"{} zip files have been clean up in folder: {:?}",
n, data_dir
Expand Down
118 changes: 0 additions & 118 deletions chain/tests/chain_test_helper.rs

This file was deleted.

25 changes: 0 additions & 25 deletions chain/tests/test_txhashset_archive.rs

This file was deleted.

24 changes: 3 additions & 21 deletions core/src/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ pub const AUTOMATED_TESTING_COINBASE_MATURITY: u64 = 3;
pub const USER_TESTING_COINBASE_MATURITY: u64 = 3;

/// Testing cut through horizon in blocks
pub const AUTOMATED_TESTING_CUT_THROUGH_HORIZON: u32 = 20;

/// Testing cut through horizon in blocks
pub const USER_TESTING_CUT_THROUGH_HORIZON: u32 = 70;
pub const TESTING_CUT_THROUGH_HORIZON: u32 = 70;

/// Testing state sync threshold in blocks
pub const TESTING_STATE_SYNC_THRESHOLD: u32 = 20;
Expand Down Expand Up @@ -85,12 +82,6 @@ pub const PEER_EXPIRATION_REMOVE_TIME: i64 = PEER_EXPIRATION_DAYS * 24 * 3600;
/// For a node configured as "archival_mode = true" only the txhashset will be compacted.
pub const COMPACTION_CHECK: u64 = DAY_HEIGHT;

/// Automated testing number of blocks to reuse a txhashset zip for.
pub const AUTOMATED_TESTING_TXHASHSET_ARCHIVE_INTERVAL: u64 = 10;

/// Number of blocks to reuse a txhashset zip for.
pub const TXHASHSET_ARCHIVE_INTERVAL: u64 = 12 * 60;

/// Types of chain a server can run with, dictates the genesis block and
/// and mining parameters used.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
Expand Down Expand Up @@ -254,8 +245,8 @@ pub fn max_block_weight() -> usize {
pub fn cut_through_horizon() -> u32 {
let param_ref = CHAIN_TYPE.read();
match *param_ref {
ChainTypes::AutomatedTesting => AUTOMATED_TESTING_CUT_THROUGH_HORIZON,
ChainTypes::UserTesting => USER_TESTING_CUT_THROUGH_HORIZON,
ChainTypes::AutomatedTesting => TESTING_CUT_THROUGH_HORIZON,
ChainTypes::UserTesting => TESTING_CUT_THROUGH_HORIZON,
_ => CUT_THROUGH_HORIZON,
}
}
Expand All @@ -270,15 +261,6 @@ pub fn state_sync_threshold() -> u32 {
}
}

/// Number of blocks to reuse a txhashset zip for.
pub fn txhashset_archive_interval() -> u64 {
let param_ref = CHAIN_TYPE.read();
match *param_ref {
ChainTypes::AutomatedTesting => AUTOMATED_TESTING_TXHASHSET_ARCHIVE_INTERVAL,
_ => TXHASHSET_ARCHIVE_INTERVAL,
}
}

/// Are we in automated testing mode?
pub fn is_automated_testing_mode() -> bool {
let param_ref = CHAIN_TYPE.read();
Expand Down
1 change: 1 addition & 0 deletions core/src/pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub fn verify_size(bh: &BlockHeader) -> Result<(), Error> {
pub fn mine_genesis_block() -> Result<Block, Error> {
let mut gen = genesis::genesis_dev();
if global::is_user_testing_mode() || global::is_automated_testing_mode() {
gen = genesis::genesis_dev();
gen.header.timestamp = Utc::now();
}

Expand Down
4 changes: 0 additions & 4 deletions p2p/src/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,6 @@ impl ChainAdapter for TrackingAdapter {
self.adapter.txhashset_read(h)
}

fn txhashset_archive_header(&self) -> Result<core::BlockHeader, chain::Error> {
self.adapter.txhashset_archive_header()
}

fn txhashset_receive_ready(&self) -> bool {
self.adapter.txhashset_receive_ready()
}
Expand Down
4 changes: 0 additions & 4 deletions p2p/src/peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,6 @@ impl ChainAdapter for Peers {
self.adapter.txhashset_read(h)
}

fn txhashset_archive_header(&self) -> Result<core::BlockHeader, chain::Error> {
self.adapter.txhashset_archive_header()
}

fn txhashset_receive_ready(&self) -> bool {
self.adapter.txhashset_receive_ready()
}
Expand Down
14 changes: 6 additions & 8 deletions p2p/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,22 +293,20 @@ impl MessageHandler for Protocol {

Type::TxHashSetRequest => {
let sm_req: TxHashSetRequest = msg.body()?;

let txhashset_header = self.adapter.txhashset_archive_header()?;
let txhashset_header_hash = txhashset_header.hash();
debug!(
"handle_payload: txhashset request for {} at {}, response with {} at {}",
sm_req.hash, sm_req.height, txhashset_header.height, txhashset_header_hash,
"handle_payload: txhashset req for {} at {}",
sm_req.hash, sm_req.height
);
let txhashset = self.adapter.txhashset_read(txhashset_header_hash);

let txhashset = self.adapter.txhashset_read(sm_req.hash);

if let Some(txhashset) = txhashset {
let file_sz = txhashset.reader.metadata()?.len();
let mut resp = Response::new(
Type::TxHashSetArchive,
&TxHashSetArchive {
height: txhashset_header.height as u64,
hash: txhashset_header_hash,
height: sm_req.height as u64,
hash: sm_req.hash,
bytes: file_sz,
},
writer,
Expand Down
4 changes: 0 additions & 4 deletions p2p/src/serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,6 @@ impl ChainAdapter for DummyAdapter {
unimplemented!()
}

fn txhashset_archive_header(&self) -> Result<core::BlockHeader, chain::Error> {
unimplemented!()
}

fn txhashset_receive_ready(&self) -> bool {
false
}
Expand Down
3 changes: 0 additions & 3 deletions p2p/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,6 @@ pub trait ChainAdapter: Sync + Send {
/// at the provided block hash.
fn txhashset_read(&self, h: Hash) -> Option<TxHashSetRead>;

/// Header of the txhashset archive currently being served to peers.
fn txhashset_archive_header(&self) -> Result<core::BlockHeader, chain::Error>;

/// Whether the node is ready to accept a new txhashset. If this isn't the
/// case, the archive is provided without being requested and likely an
/// attack attempt. This should be checked *before* downloading the whole
Expand Down
4 changes: 0 additions & 4 deletions servers/src/common/adapters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,6 @@ impl p2p::ChainAdapter for NetToChainAdapter {
}
}

fn txhashset_archive_header(&self) -> Result<core::BlockHeader, chain::Error> {
self.chain().txhashset_archive_header()
}

fn txhashset_receive_ready(&self) -> bool {
match self.sync_state.status() {
SyncStatus::TxHashsetDownload { .. } => true,
Expand Down
5 changes: 1 addition & 4 deletions servers/src/grin/sync/state_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@ impl StateSync {

fn request_state(&self, header_head: &chain::Tip) -> Result<Arc<Peer>, p2p::Error> {
let threshold = global::state_sync_threshold() as u64;
let archive_interval = global::txhashset_archive_interval();
let mut txhashset_height = header_head.height.saturating_sub(threshold);
txhashset_height = txhashset_height.saturating_sub(txhashset_height % archive_interval);

if let Some(peer) = self.peers.most_work_peer() {
// ask for txhashset at state_sync_threshold
Expand All @@ -176,7 +173,7 @@ impl StateSync {
);
p2p::Error::Internal
})?;
while txhashset_head.height > txhashset_height {
for _ in 0..threshold {
txhashset_head = self
.chain
.get_previous_header(&txhashset_head)
Expand Down