24
24
import java .util .Collection ;
25
25
import java .util .Collections ;
26
26
import java .util .Comparator ;
27
+ import java .util .HashSet ;
27
28
import java .util .List ;
28
29
import java .util .Map ;
29
30
import java .util .Optional ;
31
+ import java .util .Set ;
30
32
import java .util .concurrent .atomic .AtomicReference ;
31
33
import java .util .concurrent .locks .Lock ;
32
34
import java .util .concurrent .locks .ReadWriteLock ;
48
50
import tech .pegasys .teku .infrastructure .async .AsyncRunner ;
49
51
import tech .pegasys .teku .infrastructure .async .SafeFuture ;
50
52
import tech .pegasys .teku .infrastructure .collections .LimitedMap ;
53
+ import tech .pegasys .teku .infrastructure .collections .LimitedSet ;
51
54
import tech .pegasys .teku .infrastructure .metrics .SettableGauge ;
52
55
import tech .pegasys .teku .infrastructure .metrics .TekuMetricCategory ;
53
56
import tech .pegasys .teku .infrastructure .unsigned .UInt64 ;
64
67
import tech .pegasys .teku .spec .datastructures .forkchoice .VoteTracker ;
65
68
import tech .pegasys .teku .spec .datastructures .forkchoice .VoteUpdater ;
66
69
import tech .pegasys .teku .spec .datastructures .hashtree .HashTree ;
70
+ import tech .pegasys .teku .spec .datastructures .operations .InclusionList ;
67
71
import tech .pegasys .teku .spec .datastructures .state .AnchorPoint ;
68
72
import tech .pegasys .teku .spec .datastructures .state .BlockRootAndState ;
69
73
import tech .pegasys .teku .spec .datastructures .state .Checkpoint ;
@@ -106,6 +110,10 @@ class Store extends CacheableStore {
106
110
private final Map <Bytes32 , SignedBeaconBlock > blocks ;
107
111
private final CachingTaskQueue <SlotAndBlockRoot , BeaconState > checkpointStates ;
108
112
private final Map <SlotAndBlockRoot , List <BlobSidecar >> blobSidecars ;
113
+ private final Map <SlotAndBlockRoot , List <InclusionList >> inclusionLists ;
114
+ private final Map <SlotAndBlockRoot , Set <UInt64 >> inclusionListEquivocators ;
115
+ private final Set <Bytes32 > unsatisfiedInclusionListBlocks ;
116
+
109
117
private UInt64 timeMillis ;
110
118
private UInt64 genesisTime ;
111
119
private AnchorPoint finalizedAnchor ;
@@ -139,7 +147,10 @@ private Store(
139
147
final Map <Bytes32 , SignedBeaconBlock > blocks ,
140
148
final CachingTaskQueue <SlotAndBlockRoot , BeaconState > checkpointStates ,
141
149
final Optional <Map <Bytes32 , StateAndBlockSummary >> maybeEpochStates ,
142
- final Map <SlotAndBlockRoot , List <BlobSidecar >> blobSidecars ) {
150
+ final Map <SlotAndBlockRoot , List <BlobSidecar >> blobSidecars ,
151
+ final Map <SlotAndBlockRoot , List <InclusionList >> inclusionLists ,
152
+ final Map <SlotAndBlockRoot , Set <UInt64 >> inclusionListEquivocators ,
153
+ final Set <Bytes32 > unsatisfiedInclusionListBlocks ) {
143
154
checkArgument (
144
155
time .isGreaterThanOrEqualTo (genesisTime ),
145
156
"Time must be greater than or equal to genesisTime" );
@@ -164,6 +175,9 @@ private Store(
164
175
this .bestJustifiedCheckpoint = bestJustifiedCheckpoint ;
165
176
this .blocks = blocks ;
166
177
this .blobSidecars = blobSidecars ;
178
+ this .inclusionLists = inclusionLists ;
179
+ this .inclusionListEquivocators = inclusionListEquivocators ;
180
+ this .unsatisfiedInclusionListBlocks = unsatisfiedInclusionListBlocks ;
167
181
this .highestVotedValidatorIndex =
168
182
votes .keySet ().stream ().max (Comparator .naturalOrder ()).orElse (UInt64 .ZERO );
169
183
this .votes =
@@ -242,6 +256,13 @@ static UpdatableStore create(
242
256
final Map <SlotAndBlockRoot , List <BlobSidecar >> blobSidecars =
243
257
LimitedMap .createSynchronizedNatural (config .getBlockCacheSize ());
244
258
259
+ final Map <SlotAndBlockRoot , List <InclusionList >> inclusionLists =
260
+ LimitedMap .createSynchronizedNatural (config .getInclusionListCacheSize ());
261
+ final Map <SlotAndBlockRoot , Set <UInt64 >> inclusionListEquivocators =
262
+ LimitedMap .createSynchronizedNatural (config .getInclusionListCacheSize ());
263
+ final Set <Bytes32 > unsatisfiedInclusionListBlocks =
264
+ LimitedSet .createSynchronized (config .getInclusionListCacheSize ());
265
+
245
266
return new Store (
246
267
metricsSystem ,
247
268
spec ,
@@ -262,7 +283,10 @@ static UpdatableStore create(
262
283
blocks ,
263
284
checkpointStateTaskQueue ,
264
285
maybeEpochStates ,
265
- blobSidecars );
286
+ blobSidecars ,
287
+ inclusionLists ,
288
+ inclusionListEquivocators ,
289
+ unsatisfiedInclusionListBlocks );
266
290
}
267
291
268
292
public static UpdatableStore create (
@@ -625,6 +649,21 @@ public Optional<Boolean> isFfgCompetitive(final Bytes32 headRoot, final Bytes32
625
649
headUnrealizedJustifiedCheckpoint .equals (parentUnrealizedJustifiedCheckpoint ));
626
650
}
627
651
652
+ @ Override
653
+ public boolean satisfiesInclusionList (final Bytes32 blockRoot ) {
654
+ return unsatisfiedInclusionListBlocks .contains (blockRoot );
655
+ }
656
+
657
+ @ Override
658
+ public Optional <List <InclusionList >> getInclusionList (final SlotAndBlockRoot slotAndBlockRoot ) {
659
+ readLock .lock ();
660
+ try {
661
+ return Optional .ofNullable (inclusionLists .get (slotAndBlockRoot ));
662
+ } finally {
663
+ readLock .unlock ();
664
+ }
665
+ }
666
+
628
667
private Optional <ProtoNodeData > getBlockDataFromForkChoiceStrategy (final Bytes32 root ) {
629
668
readLock .lock ();
630
669
try {
@@ -734,6 +773,28 @@ void cacheBlocks(final Collection<BlockAndCheckpoints> blockAndCheckpoints) {
734
773
blockCountGauge .ifPresent (gauge -> gauge .set (blocks .size ()));
735
774
}
736
775
776
+ /** Non-synchronized, no lock, unsafe if Store is not locked externally */
777
+ @ Override
778
+ void cacheUnsatisfiedInclusionListBlock (final Bytes32 blockRoot ) {
779
+ unsatisfiedInclusionListBlocks .add (blockRoot );
780
+ }
781
+
782
+ /** Non-synchronized, no lock, unsafe if Store is not locked externally */
783
+ @ Override
784
+ void cacheInclusionListEquivocator (
785
+ final SlotAndBlockRoot slotAndBlockRoot , final UInt64 validatorIndex ) {
786
+ inclusionListEquivocators
787
+ .computeIfAbsent (slotAndBlockRoot , key -> new HashSet <>())
788
+ .add (validatorIndex );
789
+ }
790
+
791
+ /** Non-synchronized, no lock, unsafe if Store is not locked externally */
792
+ @ Override
793
+ void cacheInclusionList (
794
+ final SlotAndBlockRoot slotAndBlockRoot , final InclusionList inclusionList ) {
795
+ inclusionLists .computeIfAbsent (slotAndBlockRoot , key -> new ArrayList <>()).add (inclusionList );
796
+ }
797
+
737
798
/** Non-synchronized, no lock, unsafe if Store is not locked externally */
738
799
@ Override
739
800
void cacheTimeMillis (final UInt64 timeMillis ) {
0 commit comments