Skip to content

Commit 6fe1873

Browse files
committed
chore: remove needless asserts that had occasionally caused issues in stress tests
1 parent c17586a commit 6fe1873

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

stackslib/src/net/stackerdb/sync.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,12 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
248248
let local_write_timestamps = self
249249
.stackerdbs
250250
.get_slot_write_timestamps(&self.smart_contract_id)?;
251-
assert_eq!(local_slot_versions.len(), local_write_timestamps.len());
251+
252+
if local_slot_versions.len() != local_write_timestamps.len() {
253+
let msg = format!("Local slot versions ({}) out of sync with DB slot versions ({}); abandoning sync and trying again", local_slot_versions.len(), local_write_timestamps.len());
254+
warn!("{}", &msg);
255+
return Err(net_error::Transient(msg));
256+
}
252257

253258
let mut need_chunks: HashMap<usize, (StackerDBGetChunkData, Vec<NeighborAddress>)> =
254259
HashMap::new();
@@ -270,11 +275,10 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
270275
}
271276

272277
for (naddr, chunk_inv) in self.chunk_invs.iter() {
273-
assert_eq!(
274-
chunk_inv.slot_versions.len(),
275-
local_slot_versions.len(),
276-
"FATAL: did not validate StackerDBChunkInvData"
277-
);
278+
if chunk_inv.slot_versions.len() != local_slot_versions.len() {
279+
// remote peer and our DB are out of sync, so just skip this
280+
continue;
281+
}
278282

279283
if *local_version >= chunk_inv.slot_versions[i] {
280284
// remote peer has same view as local peer, or stale
@@ -358,11 +362,10 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
358362
for (i, local_version) in local_slot_versions.iter().enumerate() {
359363
let mut local_chunk = None;
360364
for (naddr, chunk_inv) in self.chunk_invs.iter() {
361-
assert_eq!(
362-
chunk_inv.slot_versions.len(),
363-
local_slot_versions.len(),
364-
"FATAL: did not validate StackerDBChunkData"
365-
);
365+
if chunk_inv.slot_versions.len() != local_slot_versions.len() {
366+
// remote peer and our DB are out of sync, so just skip this
367+
continue;
368+
}
366369

367370
if *local_version <= chunk_inv.slot_versions[i] {
368371
// remote peer has same or newer view than local peer

stackslib/src/util_lib/db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ pub fn get_ancestor_block_hash<T: MarfTrieId>(
730730
block_height: u64,
731731
tip_block_hash: &T,
732732
) -> Result<Option<T>, Error> {
733-
assert!(block_height < u32::MAX as u64);
733+
assert!(block_height <= u32::MAX as u64);
734734
let mut read_only = index.reopen_readonly()?;
735735
let bh = read_only.get_block_at_height(block_height as u32, tip_block_hash)?;
736736
Ok(bh)

0 commit comments

Comments
 (0)