Skip to content

Commit 20e8c7b

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 3358f6d commit 20e8c7b

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
@@ -3271,16 +3271,10 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
32713271

32723272
let _persistence_guard = PersistenceNotifierGuard::new(&self.total_consistency_lock, &self.persistence_notifier);
32733273

3274-
3275-
// This assertion should be enforced in tests, however we have a number of tests that
3276-
// were written before this requirement and do not meet it.
3277-
#[cfg(not(test))]
3278-
{
3279-
assert_eq!(*self.last_block_hash.read().unwrap(), header.prev_blockhash,
3280-
"Blocks must be connected in chain-order - the connected header must build on the last connected header");
3281-
assert_eq!(self.latest_block_height.load(Ordering::Acquire) as u64, height as u64 - 1,
3282-
"Blocks must be connected in chain-order - the connected header must build on the last connected header");
3283-
}
3274+
assert_eq!(*self.last_block_hash.read().unwrap(), header.prev_blockhash,
3275+
"Blocks must be connected in chain-order - the connected header must build on the last connected header");
3276+
assert_eq!(self.latest_block_height.load(Ordering::Acquire) as u64, height as u64 - 1,
3277+
"Blocks must be connected in chain-order - the connected header must build on the last connected header");
32843278
self.latest_block_height.store(height as usize, Ordering::Release);
32853279
*self.last_block_hash.write().unwrap() = block_hash;
32863280

0 commit comments

Comments
 (0)