Skip to content

Commit 45adc33

Browse files
committed
chore: address remaining PR feedback and get tests to pass
1 parent 9731059 commit 45adc33

File tree

6 files changed

+129
-147
lines changed

6 files changed

+129
-147
lines changed

stackslib/src/burnchains/burnchain.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,10 @@ impl Burnchain {
702702
}
703703

704704
pub fn get_burnchaindb_path(&self) -> String {
705+
if self.working_dir.as_str() == ":memory:" {
706+
return ":memory:".to_string();
707+
}
708+
705709
let chainstate_dir = Burnchain::get_chainstate_path_str(&self.working_dir);
706710
let mut db_pathbuf = PathBuf::from(&chainstate_dir);
707711
db_pathbuf.push("burnchain.sqlite");
@@ -743,12 +747,14 @@ impl Burnchain {
743747
/// Open just the burnchain database
744748
pub fn open_burnchain_db(&self, readwrite: bool) -> Result<BurnchainDB, burnchain_error> {
745749
let burnchain_db_path = self.get_burnchaindb_path();
746-
if let Err(e) = fs::metadata(&burnchain_db_path) {
747-
warn!(
748-
"Failed to stat burnchain DB path '{}': {:?}",
749-
&burnchain_db_path, &e
750-
);
751-
return Err(burnchain_error::DBError(db_error::NoDBError));
750+
if burnchain_db_path != ":memory:" {
751+
if let Err(e) = fs::metadata(&burnchain_db_path) {
752+
warn!(
753+
"Failed to stat burnchain DB path '{}': {:?}",
754+
&burnchain_db_path, &e
755+
);
756+
return Err(burnchain_error::DBError(db_error::NoDBError));
757+
}
752758
}
753759
test_debug!(
754760
"Open burnchain DB at {} (rw? {})",

stackslib/src/burnchains/db.rs

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,33 +1000,38 @@ impl BurnchainDB {
10001000
readwrite: bool,
10011001
) -> Result<BurnchainDB, BurnchainError> {
10021002
let mut create_flag = false;
1003-
let open_flags = match fs::metadata(path) {
1004-
Err(e) => {
1005-
if e.kind() == io::ErrorKind::NotFound {
1006-
// need to create
1007-
if readwrite {
1008-
create_flag = true;
1009-
let ppath = Path::new(path);
1010-
let pparent_path = ppath
1011-
.parent()
1012-
.unwrap_or_else(|| panic!("BUG: no parent of '{}'", path));
1013-
fs::create_dir_all(&pparent_path)
1014-
.map_err(|e| BurnchainError::from(DBError::IOError(e)))?;
1015-
1016-
OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_CREATE
1003+
let open_flags = if path == ":memory:" {
1004+
create_flag = true;
1005+
OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_CREATE
1006+
} else {
1007+
match fs::metadata(path) {
1008+
Err(e) => {
1009+
if e.kind() == io::ErrorKind::NotFound {
1010+
// need to create
1011+
if readwrite {
1012+
create_flag = true;
1013+
let ppath = Path::new(path);
1014+
let pparent_path = ppath
1015+
.parent()
1016+
.unwrap_or_else(|| panic!("BUG: no parent of '{}'", path));
1017+
fs::create_dir_all(&pparent_path)
1018+
.map_err(|e| BurnchainError::from(DBError::IOError(e)))?;
1019+
1020+
OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_CREATE
1021+
} else {
1022+
return Err(BurnchainError::from(DBError::NoDBError));
1023+
}
10171024
} else {
1018-
return Err(BurnchainError::from(DBError::NoDBError));
1025+
return Err(BurnchainError::from(DBError::IOError(e)));
10191026
}
1020-
} else {
1021-
return Err(BurnchainError::from(DBError::IOError(e)));
10221027
}
1023-
}
1024-
Ok(_md) => {
1025-
// can just open
1026-
if readwrite {
1027-
OpenFlags::SQLITE_OPEN_READ_WRITE
1028-
} else {
1029-
OpenFlags::SQLITE_OPEN_READ_ONLY
1028+
Ok(_md) => {
1029+
// can just open
1030+
if readwrite {
1031+
OpenFlags::SQLITE_OPEN_READ_WRITE
1032+
} else {
1033+
OpenFlags::SQLITE_OPEN_READ_ONLY
1034+
}
10301035
}
10311036
}
10321037
};
@@ -1089,7 +1094,7 @@ impl BurnchainDB {
10891094
let conn = sqlite_open(path, open_flags, true)?;
10901095
let mut db = BurnchainDB { conn };
10911096

1092-
if readwrite {
1097+
if readwrite || path == ":memory:" {
10931098
db.add_indexes()?;
10941099
}
10951100
Ok(db)

stackslib/src/net/download/nakamoto/download_state_machine.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,16 +1418,19 @@ impl NakamotoDownloadStateMachine {
14181418
chainstate: &StacksChainState,
14191419
ibd: bool,
14201420
) -> HashMap<ConsensusHash, Vec<NakamotoBlock>> {
1421-
debug!("NakamotoDownloadStateMachine in state {}", &self.state);
1421+
debug!(
1422+
"run_downloads: burnchain_height={}, network.burnchain_tip.block_height={}, state={}",
1423+
burnchain_height, network.burnchain_tip.block_height, &self.state;
1424+
"has_network_inventories" => network.inv_state_nakamoto.is_some(),
1425+
"next_unconfirmed_check" => self.last_unconfirmed_download_check_ms.saturating_add(CHECK_UNCONFIRMED_TENURES_MS) / 1000,
1426+
"timestamp_ms" => get_epoch_time_ms(),
1427+
);
1428+
14221429
let Some(invs) = network.inv_state_nakamoto.as_ref() else {
14231430
// nothing to do
1424-
debug!("No network inventories");
14251431
return HashMap::new();
14261432
};
1427-
debug!(
1428-
"run_downloads: burnchain_height={}, network.burnchain_tip.block_height={}, state={}",
1429-
burnchain_height, network.burnchain_tip.block_height, &self.state
1430-
);
1433+
14311434
self.update_available_tenures(
14321435
&invs.inventories,
14331436
&sortdb.pox_constants,
@@ -1441,12 +1444,6 @@ impl NakamotoDownloadStateMachine {
14411444
.saturating_add(CHECK_UNCONFIRMED_TENURES_MS)
14421445
> get_epoch_time_ms()
14431446
{
1444-
debug!(
1445-
"Throttle checking for unconfirmed tenures until {}",
1446-
self.last_unconfirmed_download_check_ms
1447-
.saturating_add(CHECK_UNCONFIRMED_TENURES_MS)
1448-
/ 1000
1449-
);
14501447
false
14511448
} else {
14521449
let do_fetch = Self::need_unconfirmed_tenures(

0 commit comments

Comments
 (0)