File tree 2 files changed +26
-2
lines changed
ethereum/statetransition/src
main/java/tech/pegasys/teku/statetransition/blobs
test/java/tech/pegasys/teku/statetransition/blobs
2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change 38
38
* with UNKNOWN_BLOCK and will be tracked in the block pendingPool.
39
39
*/
40
40
public class DataUnavailableBlockPool implements FinalizedCheckpointChannel {
41
+ public static final int MAX_CAPACITY = 10 ;
41
42
private static final Logger LOG = LogManager .getLogger ();
42
43
43
44
private static final Duration WAIT_BEFORE_RETRY = Duration .ofSeconds (1 );
44
45
45
46
// this is a queue of chain tips
46
47
private final Queue <SignedBeaconBlock > awaitingDataAvailabilityQueue =
47
- new ArrayBlockingQueue <>(10 );
48
+ new ArrayBlockingQueue <>(MAX_CAPACITY );
48
49
private final Spec spec ;
49
50
private final BlockManager blockManager ;
50
51
private final BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool ;
@@ -72,9 +73,11 @@ public synchronized void addDataUnavailableBlock(final SignedBeaconBlock block)
72
73
73
74
boolean wasEmpty = awaitingDataAvailabilityQueue .isEmpty ();
74
75
if (!awaitingDataAvailabilityQueue .offer (block )) {
76
+ final SignedBeaconBlock oldestBlock = awaitingDataAvailabilityQueue .poll ();
77
+ awaitingDataAvailabilityQueue .add (block );
75
78
LOG .info (
76
79
"Discarding block {} as data unavailable retry pool capacity exceeded" ,
77
- block ::toLogString );
80
+ oldestBlock ::toLogString );
78
81
return ;
79
82
}
80
83
if (wasEmpty ) {
Original file line number Diff line number Diff line change 21
21
import static org .mockito .Mockito .verifyNoMoreInteractions ;
22
22
import static org .mockito .Mockito .when ;
23
23
import static tech .pegasys .teku .spec .datastructures .validator .BroadcastValidationLevel .NOT_REQUIRED ;
24
+ import static tech .pegasys .teku .statetransition .blobs .DataUnavailableBlockPool .MAX_CAPACITY ;
24
25
26
+ import java .util .List ;
25
27
import java .util .Optional ;
28
+ import java .util .stream .IntStream ;
26
29
import org .junit .jupiter .api .BeforeEach ;
27
30
import org .junit .jupiter .api .Test ;
28
31
import tech .pegasys .teku .infrastructure .async .SafeFuture ;
@@ -197,4 +200,22 @@ void shouldPruneBlocksOlderThanFinalizedSlot() {
197
200
assertThat (dataUnavailableBlockPool .containsBlock (blockAtSlot10 )).isFalse ();
198
201
assertThat (dataUnavailableBlockPool .containsBlock (blockAtSlot11 )).isFalse ();
199
202
}
203
+
204
+ @ Test
205
+ void shouldDiscardOldestWhenFull () {
206
+ final List <SignedBeaconBlock > blocks =
207
+ IntStream .range (0 , MAX_CAPACITY )
208
+ .mapToObj (dataStructureUtil ::randomSignedBeaconBlock )
209
+ .toList ();
210
+ blocks .forEach (dataUnavailableBlockPool ::addDataUnavailableBlock );
211
+
212
+ assertThat (dataUnavailableBlockPool .containsBlock (blocks .get (0 ))).isTrue ();
213
+
214
+ final SignedBeaconBlock newBlock = dataStructureUtil .randomSignedBeaconBlock ();
215
+
216
+ dataUnavailableBlockPool .addDataUnavailableBlock (newBlock );
217
+
218
+ assertThat (dataUnavailableBlockPool .containsBlock (blocks .get (0 ))).isFalse ();
219
+ assertThat (dataUnavailableBlockPool .containsBlock (newBlock )).isTrue ();
220
+ }
200
221
}
You can’t perform that action at this time.
0 commit comments