Skip to content

Commit ce89534

Browse files
committed
Enforce block connection ordering in unit and functional tests
This expands the assertions on block ordering to apply to `#[cfg(test)]` builds in addition to normal builds, requiring that unit and functional tests have syntactically-valid (ie the previous block hash pointer and the heights match the blocks) blockchains. This requires a reasonably nontrivial diff in the functional tests however it is mostly straightforward changes.
1 parent dccf7fe commit ce89534

File tree

4 files changed

+188
-292
lines changed

4 files changed

+188
-292
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3302,16 +3302,10 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
33023302

33033303
let _persistence_guard = PersistenceNotifierGuard::new(&self.total_consistency_lock, &self.persistence_notifier);
33043304

3305-
3306-
// This assertion should be enforced in tests, however we have a number of tests that
3307-
// were written before this requirement and do not meet it.
3308-
#[cfg(not(test))]
3309-
{
3310-
assert_eq!(*self.last_block_hash.read().unwrap(), header.prev_blockhash,
3311-
"Blocks must be connected in chain-order - the connected header must build on the last connected header");
3312-
assert_eq!(self.latest_block_height.load(Ordering::Acquire) as u64, height as u64 - 1,
3313-
"Blocks must be connected in chain-order - the connected header must build on the last connected header");
3314-
}
3305+
assert_eq!(*self.last_block_hash.read().unwrap(), header.prev_blockhash,
3306+
"Blocks must be connected in chain-order - the connected header must build on the last connected header");
3307+
assert_eq!(self.latest_block_height.load(Ordering::Acquire) as u64, height as u64 - 1,
3308+
"Blocks must be connected in chain-order - the connected header must build on the last connected header");
33153309
self.latest_block_height.store(height as usize, Ordering::Release);
33163310
*self.last_block_hash.write().unwrap() = block_hash;
33173311

0 commit comments

Comments
 (0)