Generate txhashset archives on 720 block intervals. (#2813)
* generate txhashset archives on 250 block intervals. * moved txhashset_archive_interval to global and added a simple test. * cleaning up the tests and adding license. * increasing cleanup duration to 24 hours to prevent premature deletion of the current txhashset archive * bug fixes and changing request_state to request height using archive_interval. * removing stopstate from chain_test_helper to fix compile issue
This commit is contained in:
@@ -372,6 +372,10 @@ 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,
|
||||
|
||||
@@ -160,6 +160,9 @@ 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
|
||||
@@ -168,18 +171,18 @@ impl StateSync {
|
||||
.get_block_header(&header_head.prev_block_h)
|
||||
.map_err(|e| {
|
||||
error!(
|
||||
"chain error dirung getting a block header {}: {:?}",
|
||||
"chain error during getting a block header {}: {:?}",
|
||||
&header_head.prev_block_h, e
|
||||
);
|
||||
p2p::Error::Internal
|
||||
})?;
|
||||
for _ in 0..threshold {
|
||||
while txhashset_head.height > txhashset_height {
|
||||
txhashset_head = self
|
||||
.chain
|
||||
.get_previous_header(&txhashset_head)
|
||||
.map_err(|e| {
|
||||
error!(
|
||||
"chain error dirung getting a previous block header {}: {:?}",
|
||||
"chain error during getting a previous block header {}: {:?}",
|
||||
txhashset_head.hash(),
|
||||
e
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user