@@ -20,7 +20,10 @@ import
20
20
forks,
21
21
presets,
22
22
state_transition],
23
- " ." / [beacon_chain_db_light_client, filepath]
23
+ " ." / [beacon_chain_db_light_client,
24
+ beacon_chain_db_quarantine,
25
+ db_utils,
26
+ filepath]
24
27
25
28
from ./ spec/ datatypes/ capella import BeaconState
26
29
from ./ spec/ datatypes/ deneb import TrustedSignedBeaconBlock
@@ -153,6 +156,10 @@ type
153
156
# #
154
157
# # See `summaries` for an index in the other direction.
155
158
159
+ quarantine: QuarantineDB
160
+ # # Pending data that passed basic checks including proposer signature
161
+ # # but that is not fully validated / trusted yet.
162
+
156
163
lcData: LightClientDataDB
157
164
# # Persistent light client data to avoid expensive recomputations
158
165
@@ -593,6 +600,36 @@ proc new*(T: type BeaconChainDB,
593
600
if cfg.FULU_FORK_EPOCH != FAR_FUTURE_EPOCH :
594
601
columns = kvStore db.openKvStore (" fulu_columns" ).expectDb ()
595
602
603
+ let quarantine = db.initQuarantineDB (QuarantineDBNames (
604
+ # TODO Set these to non-empty string to actually use them
605
+ # once we have a new quarantine implemented. If empty string is used,
606
+ # no database table is created!
607
+ phase0Blocks:
608
+ " " , # "blocks_quarantine"
609
+ altairBlocks:
610
+ " " , # "altair_blocks_quarantine"
611
+ bellatrixBlocks:
612
+ " " , # "bellatrix_blocks_quarantine"
613
+ capellaBlocks:
614
+ " " , # "capella_blocks_quarantine"
615
+ denebBlocks:
616
+ " " , # "deneb_blocks_quarantine"
617
+ electraBlocks:
618
+ " " , # "electra_blocks_quarantine"
619
+ fuluBlocks:
620
+ if cfg.FULU_FORK_EPOCH != FAR_FUTURE_EPOCH :
621
+ " " # "fulu_blocks_quarantine"
622
+ else :
623
+ " " ,
624
+ denebDataSidecars:
625
+ " " , # "deneb_blobs_quarantine"
626
+ fuluDataSidecars:
627
+ if cfg.FULU_FORK_EPOCH != FAR_FUTURE_EPOCH :
628
+ " " # "fulu_columns_quarantine"
629
+ else :
630
+ " " )).expectDb ()
631
+ static : doAssert ConsensusFork .high == ConsensusFork .Fulu
632
+
596
633
# Versions prior to 1.4.0 (altair) stored validators in `immutable_validators`
597
634
# which stores validator keys in compressed format - this is
598
635
# slow to load and has been superceded by `immutable_validators2` which uses
@@ -634,6 +671,7 @@ proc new*(T: type BeaconChainDB,
634
671
stateDiffs: stateDiffs,
635
672
summaries: summaries,
636
673
finalizedBlocks: finalizedBlocks,
674
+ quarantine: quarantine,
637
675
lcData: lcData
638
676
)
639
677
@@ -657,6 +695,9 @@ proc new*(T: type BeaconChainDB,
657
695
dir, " nbc" , readOnly = readOnly, manualCheckpoint = true ).expectDb ()
658
696
BeaconChainDB .new (db, cfg)
659
697
698
+ template getQuarantineDB * (db: BeaconChainDB ): QuarantineDB =
699
+ db.quarantine
700
+
660
701
template getLightClientDataDB * (db: BeaconChainDB ): LightClientDataDB =
661
702
db.lcData
662
703
@@ -683,18 +724,6 @@ proc decodeSnappySSZ[T](data: openArray[byte], output: var T): bool =
683
724
err = e.msg, typ = name (T), dataLen = data.len
684
725
false
685
726
686
- proc decodeSZSSZ [T](data: openArray [byte ], output: var T): bool =
687
- try :
688
- let decompressed = decodeFramed (data, checkIntegrity = false )
689
- readSszBytes (decompressed, output, updateRoot = false )
690
- true
691
- except CatchableError as e:
692
- # If the data can't be deserialized, it could be because it's from a
693
- # version of the software that uses a different SSZ encoding
694
- warn " Unable to deserialize data, old database?" ,
695
- err = e.msg, typ = name (T), dataLen = data.len
696
- false
697
-
698
727
func encodeSSZ * (v: auto ): seq [byte ] =
699
728
try :
700
729
SSZ .encode (v)
@@ -708,14 +737,6 @@ func encodeSnappySSZ(v: auto): seq[byte] =
708
737
# In-memory encode shouldn't fail!
709
738
raiseAssert err.msg
710
739
711
- func encodeSZSSZ (v: auto ): seq [byte ] =
712
- # https://github.com/google/snappy/blob/main/framing_format.txt
713
- try :
714
- encodeFramed (SSZ .encode (v))
715
- except CatchableError as err:
716
- # In-memory encode shouldn't fail!
717
- raiseAssert err.msg
718
-
719
740
proc getRaw (db: KvStoreRef , key: openArray [byte ], T: type Eth2Digest ): Opt [T] =
720
741
var res: Opt [T]
721
742
proc decode (data: openArray [byte ]) =
@@ -796,6 +817,7 @@ proc close*(db: BeaconChainDB) =
796
817
if db.db == nil : return
797
818
798
819
# Close things roughly in reverse order
820
+ db.quarantine.close ()
799
821
if not isNil (db.columns):
800
822
discard db.columns.close ()
801
823
if not isNil (db.blobs):
@@ -1131,7 +1153,7 @@ proc getBlobSidecar*(db: BeaconChainDB, root: Eth2Digest, index: BlobIndex,
1131
1153
value: var BlobSidecar ): bool =
1132
1154
db.blobs.getSZSSZ (blobkey (root, index), value) == GetResult .found
1133
1155
1134
- proc getDataColumnSidecarSZ * (db: BeaconChainDB , root: Eth2Digest ,
1156
+ proc getDataColumnSidecarSZ * (db: BeaconChainDB , root: Eth2Digest ,
1135
1157
index: ColumnIndex , data: var seq [byte ]): bool =
1136
1158
let dataPtr = addr data # Short-lived
1137
1159
func decode (data: openArray [byte ]) =
0 commit comments