Skip to content

Commit

Permalink
Merge pull request #5393 from stacks-network/fix/relayer-drain-channel
Browse files Browse the repository at this point in the history
Fix: snappy downloader
  • Loading branch information
jcnelson authored Nov 7, 2024
2 parents 2456645 + 4c59af8 commit 9c5d822
Show file tree
Hide file tree
Showing 23 changed files with 1,950 additions and 502 deletions.
18 changes: 12 additions & 6 deletions stackslib/src/burnchains/burnchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,10 @@ impl Burnchain {
}

pub fn get_burnchaindb_path(&self) -> String {
if self.working_dir.as_str() == ":memory:" {
return ":memory:".to_string();
}

let chainstate_dir = Burnchain::get_chainstate_path_str(&self.working_dir);
let mut db_pathbuf = PathBuf::from(&chainstate_dir);
db_pathbuf.push("burnchain.sqlite");
Expand Down Expand Up @@ -743,12 +747,14 @@ impl Burnchain {
/// Open just the burnchain database
pub fn open_burnchain_db(&self, readwrite: bool) -> Result<BurnchainDB, burnchain_error> {
let burnchain_db_path = self.get_burnchaindb_path();
if let Err(e) = fs::metadata(&burnchain_db_path) {
warn!(
"Failed to stat burnchain DB path '{}': {:?}",
&burnchain_db_path, &e
);
return Err(burnchain_error::DBError(db_error::NoDBError));
if burnchain_db_path != ":memory:" {
if let Err(e) = fs::metadata(&burnchain_db_path) {
warn!(
"Failed to stat burnchain DB path '{}': {:?}",
&burnchain_db_path, &e
);
return Err(burnchain_error::DBError(db_error::NoDBError));
}
}
test_debug!(
"Open burnchain DB at {} (rw? {})",
Expand Down
55 changes: 30 additions & 25 deletions stackslib/src/burnchains/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,33 +1000,38 @@ impl BurnchainDB {
readwrite: bool,
) -> Result<BurnchainDB, BurnchainError> {
let mut create_flag = false;
let open_flags = match fs::metadata(path) {
Err(e) => {
if e.kind() == io::ErrorKind::NotFound {
// need to create
if readwrite {
create_flag = true;
let ppath = Path::new(path);
let pparent_path = ppath
.parent()
.unwrap_or_else(|| panic!("BUG: no parent of '{}'", path));
fs::create_dir_all(&pparent_path)
.map_err(|e| BurnchainError::from(DBError::IOError(e)))?;

OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_CREATE
let open_flags = if path == ":memory:" {
create_flag = true;
OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_CREATE
} else {
match fs::metadata(path) {
Err(e) => {
if e.kind() == io::ErrorKind::NotFound {
// need to create
if readwrite {
create_flag = true;
let ppath = Path::new(path);
let pparent_path = ppath
.parent()
.unwrap_or_else(|| panic!("BUG: no parent of '{}'", path));
fs::create_dir_all(&pparent_path)
.map_err(|e| BurnchainError::from(DBError::IOError(e)))?;

OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_CREATE
} else {
return Err(BurnchainError::from(DBError::NoDBError));
}
} else {
return Err(BurnchainError::from(DBError::NoDBError));
return Err(BurnchainError::from(DBError::IOError(e)));
}
} else {
return Err(BurnchainError::from(DBError::IOError(e)));
}
}
Ok(_md) => {
// can just open
if readwrite {
OpenFlags::SQLITE_OPEN_READ_WRITE
} else {
OpenFlags::SQLITE_OPEN_READ_ONLY
Ok(_md) => {
// can just open
if readwrite {
OpenFlags::SQLITE_OPEN_READ_WRITE
} else {
OpenFlags::SQLITE_OPEN_READ_ONLY
}
}
}
};
Expand Down Expand Up @@ -1089,7 +1094,7 @@ impl BurnchainDB {
let conn = sqlite_open(path, open_flags, true)?;
let mut db = BurnchainDB { conn };

if readwrite {
if readwrite || path == ":memory:" {
db.add_indexes()?;
}
Ok(db)
Expand Down
2 changes: 1 addition & 1 deletion stackslib/src/chainstate/nakamoto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ pub trait StacksDBIndexed {
fn get(&mut self, tip: &StacksBlockId, key: &str) -> Result<Option<String>, DBError>;
fn sqlite(&self) -> &Connection;

/// Get the ancestor block hash given a height
/// Get the ancestor block hash given a coinbase height
fn get_ancestor_block_id(
&mut self,
coinbase_height: u64,
Expand Down
Loading

0 comments on commit 9c5d822

Please sign in to comment.