Commit 2df5861 1 parent 67e1dc3 commit 2df5861 Copy full SHA for 2df5861
File tree 2 files changed +22
-3
lines changed
2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ impl Drop for CPInner {
38
38
// that no recursive drop calls can happen even with multiple threads.
39
39
match Arc :: try_unwrap ( arc_node) . ok ( ) {
40
40
Some ( mut node) => {
41
- // Keep goign backwards
41
+ // Keep going backwards
42
42
current = node. prev . take ( ) ;
43
43
// Don't call `drop` on `CPInner` since that risks it becoming recursive.
44
44
core:: mem:: forget ( node) ;
Original file line number Diff line number Diff line change 1
- use bdk_core:: CheckPoint ;
2
- use bdk_testenv:: block_id;
1
+ use bdk_core:: { BlockId , CheckPoint } ;
2
+ use bdk_testenv:: { block_id, hash } ;
3
3
4
4
/// Inserting a block that already exists in the checkpoint chain must always succeed.
5
5
#[ test]
@@ -32,3 +32,22 @@ fn checkpoint_insert_existing() {
32
32
}
33
33
}
34
34
}
35
+
36
+ #[ test]
37
+ fn checkpoint_destruction_is_sound ( ) {
38
+ // Prior to the fix in https://github.com/bitcoindevkit/bdk/pull/1731
39
+ // this could have caused a stack overflow due to drop recursion in Arc.
40
+ // We test that a long linked list can clean itself up without blowing
41
+ // out the stack.
42
+ let mut cp = CheckPoint :: new ( BlockId {
43
+ height : 0 ,
44
+ hash : hash ! ( "g" ) ,
45
+ } ) ;
46
+ let end = 10_000 ;
47
+ for height in 1u32 ..end {
48
+ let hash = bitcoin:: hashes:: Hash :: hash ( height. to_be_bytes ( ) . as_slice ( ) ) ;
49
+ let block = BlockId { height, hash } ;
50
+ cp = cp. push ( block) . unwrap ( ) ;
51
+ }
52
+ assert_eq ! ( cp. iter( ) . count( ) as u32 , end) ;
53
+ }
You can’t perform that action at this time.
0 commit comments