@@ -14,7 +14,7 @@ import (
1414)
1515
1616const (
17- cltv uint32 = 5
17+ cltv uint32 = 100000
1818)
1919
2020var (
@@ -121,10 +121,8 @@ func shutdown(d *DecayedLog) {
121121
122122// TestDecayedLogGarbageCollector tests the ability of the garbage collector
123123// to delete expired cltv values every time a block is received. Expired cltv
124- // values are cltv values that are <= current block height.
124+ // values are cltv values that are < current block height.
125125func TestDecayedLogGarbageCollector (t * testing.T ) {
126- t .Parallel ()
127-
128126 d , notifier , hashedSecret , err := startup (true )
129127 if err != nil {
130128 t .Fatalf ("Unable to start up DecayedLog: %v" , err )
@@ -137,37 +135,52 @@ func TestDecayedLogGarbageCollector(t *testing.T) {
137135 t .Fatalf ("Unable to store in channeldb: %v" , err )
138136 }
139137
138+ // Wait for database write (GC is in a goroutine)
139+ time .Sleep (500 * time .Millisecond )
140+
140141 // Send block notifications to garbage collector. The garbage collector
141- // should remove the entry we just added to sharedHashBucket as it will
142- // expire by the 6th block notification.
143- for i := 0 ; i < 6 ; i ++ {
144- notifier .epochChan <- & chainntnfs.BlockEpoch {
145- Height : int32 (100 + i ),
146- }
142+ // should remove the entry by block 100001.
143+
144+ // Send block 100000
145+ notifier .epochChan <- & chainntnfs.BlockEpoch {
146+ Height : 100000 ,
147+ }
148+
149+ // Assert that hashedSecret is still in the sharedHashBucket
150+ val , err := d .Get (hashedSecret [:])
151+ if err != nil {
152+ t .Fatalf ("Get failed - received an error upon Get: %v" , err )
153+ }
154+
155+ if val != cltv {
156+ t .Fatalf ("GC incorrectly deleted CLTV" )
157+ }
158+
159+ // Send block 100001 (expiry block)
160+ notifier .epochChan <- & chainntnfs.BlockEpoch {
161+ Height : 100001 ,
147162 }
148163
149164 // Wait for database write (GC is in a goroutine)
150165 time .Sleep (500 * time .Millisecond )
151166
152167 // Assert that hashedSecret is not in the sharedHashBucket
153- val , err : = d .Get (hashedSecret [:])
168+ val , err = d .Get (hashedSecret [:])
154169 if err != nil {
155- t .Fatalf ("Delete failed - received an error upon Get: %v" , err )
170+ t .Fatalf ("Get failed - received an error upon Get: %v" , err )
156171 }
157172
158173 if val != math .MaxUint32 {
159- t .Fatalf ("cltv was not deleted" )
174+ t .Fatalf ("CLTV was not deleted" )
160175 }
161176}
162177
163178// TestDecayedLogPersistentGarbageCollector tests the persistence property of
164- // the garbage collector. A block will be sent to the garbage collector, the
165- // garbage collector will be shut down, and then a much later block will be sent
166- // (past the expiry of our test CLTV) that causes the <sharedHash, cltv) key- pair
167- // to be deleted .
179+ // the garbage collector. The garbage collector will be restarted immediately and
180+ // a block that expires the stored CLTV value will be sent to the ChainNotifier.
181+ // We test that this causes the <hashedSecret, CLTV> pair to be deleted even
182+ // on GC restarts .
168183func TestDecayedLogPersistentGarbageCollector (t * testing.T ) {
169- t .Parallel ()
170-
171184 d , notifier , hashedSecret , err := startup (true )
172185 if err != nil {
173186 t .Fatalf ("Unable to start up DecayedLog: %v" , err )
@@ -179,11 +192,6 @@ func TestDecayedLogPersistentGarbageCollector(t *testing.T) {
179192 t .Fatalf ("Unable to store in channeldb: %v" , err )
180193 }
181194
182- // Send a single block notification to the garbage collector.
183- notifier .epochChan <- & chainntnfs.BlockEpoch {
184- Height : int32 (100 ),
185- }
186-
187195 // Wait for database write (GC is in a goroutine)
188196 time .Sleep (500 * time .Millisecond )
189197
@@ -195,9 +203,10 @@ func TestDecayedLogPersistentGarbageCollector(t *testing.T) {
195203 t .Fatalf ("Unable to restart DecayedLog: %v" , err )
196204 }
197205
198- // Send a much later block notification to the garbage collector.
206+ // Send a block notification to the garbage collector that expires
207+ // the stored CLTV.
199208 notifier .epochChan <- & chainntnfs.BlockEpoch {
200- Height : int32 (150 ),
209+ Height : int32 (100001 ),
201210 }
202211
203212 // Wait for database write (GC is in a goroutine)
@@ -214,12 +223,10 @@ func TestDecayedLogPersistentGarbageCollector(t *testing.T) {
214223 }
215224}
216225
217- // TestDecayedLogInsertionAndRetrieval inserts a cltv value into the nested
226+ // TestDecayedLogInsertionAndRetrieval inserts a cltv value into the
218227// sharedHashBucket and then deletes it and finally asserts that we can no
219228// longer retrieve it.
220229func TestDecayedLogInsertionAndDeletion (t * testing.T ) {
221- t .Parallel ()
222-
223230 d , _ , hashedSecret , err := startup (false )
224231 if err != nil {
225232 t .Fatalf ("Unable to start up DecayedLog: %v" , err )
@@ -256,8 +263,6 @@ func TestDecayedLogInsertionAndDeletion(t *testing.T) {
256263// cltv value is indeed still stored in the sharedHashBucket. We then delete
257264// the cltv value and check that it persists upon startup.
258265func TestDecayedLogStartAndStop (t * testing.T ) {
259- t .Parallel ()
260-
261266 d , _ , hashedSecret , err := startup (false )
262267 if err != nil {
263268 t .Fatalf ("Unable to start up DecayedLog: %v" , err )
@@ -322,8 +327,6 @@ func TestDecayedLogStartAndStop(t *testing.T) {
322327// via the nested sharedHashBucket and finally asserts that the original stored
323328// and retrieved cltv values are equal.
324329func TestDecayedLogStorageAndRetrieval (t * testing.T ) {
325- t .Parallel ()
326-
327330 d , _ , hashedSecret , err := startup (false )
328331 if err != nil {
329332 t .Fatalf ("Unable to start up DecayedLog: %v" , err )
0 commit comments