forked from ledgerwatch/erigon-lib
-
Notifications
You must be signed in to change notification settings - Fork 2
/
tables.go
executable file
·798 lines (659 loc) · 26.2 KB
/
tables.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
/*
Copyright 2021 Erigon contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package kv
import (
"sort"
"strings"
"github.com/gateway-fm/cdk-erigon-lib/gointerfaces/types"
"fmt"
)
// DBSchemaVersion versions list
// 5.0 - BlockTransaction table now has canonical ids (txs of non-canonical blocks moving to NonCanonicalTransaction table)
// 6.0 - BlockTransaction table now has system-txs before and after block (records are absent if block has no system-tx, but sequence increasing)
var DBSchemaVersion = types.VersionReply{Major: 6, Minor: 0, Patch: 0}
// ChaindataTables
// Dictionary:
// "Plain State" - state where keys arent' hashed. "CurrentState" - same, but keys are hashed. "PlainState" used for blocks execution. "CurrentState" used mostly for Merkle root calculation.
// "incarnation" - uint64 number - how much times given account was SelfDestruct'ed.
/*
PlainState logical layout:
Contains Accounts:
key - address (unhashed)
value - account encoded for storage
Contains Storage:
key - address (unhashed) + incarnation + storage key (unhashed)
value - storage value(common.hash)
Physical layout:
PlainState and HashedStorage utilises DupSort feature of MDBX (store multiple values inside 1 key).
-------------------------------------------------------------
key | value
-------------------------------------------------------------
[acc_hash] | [acc_value]
[acc_hash]+[inc] | [storage1_hash]+[storage1_value]
| [storage2_hash]+[storage2_value] // this value has no own key. it's 2nd value of [acc_hash]+[inc] key.
| [storage3_hash]+[storage3_value]
| ...
[acc_hash]+[old_inc] | [storage1_hash]+[storage1_value]
| ...
[acc2_hash] | [acc2_value]
...
*/
const PlainState = "PlainState"
// PlainContractCode -
// key - address+incarnation
// value - code hash
const PlainContractCode = "PlainCodeHash"
/*
AccountChangeSet and StorageChangeSet - of block N store values of state before block N changed them.
Because values "after" change stored in PlainState.
Logical format:
key - blockNum_u64 + key_in_plain_state
value - value_in_plain_state_before_blockNum_changes
Example: If block N changed account A from value X to Y. Then:
AccountChangeSet has record: bigEndian(N) + A -> X
PlainState has record: A -> Y
See also: docs/programmers_guide/db_walkthrough.MD#table-history-of-accounts
As you can see if block N changes much accounts - then all records have repetitive prefix `bigEndian(N)`.
MDBX can store such prefixes only once - by DupSort feature (see `docs/programmers_guide/dupsort.md`).
Both buckets are DupSort-ed and have physical format:
AccountChangeSet:
key - blockNum_u64
value - address + account(encoded)
StorageChangeSet:
key - blockNum_u64 + address + incarnation_u64
value - plain_storage_key + value
*/
const AccountChangeSet = "AccountChangeSet"
const StorageChangeSet = "StorageChangeSet"
const (
//HashedAccounts
// key - address hash
// value - account encoded for storage
// Contains Storage:
//key - address hash + incarnation + storage key hash
//value - storage value(common.hash)
HashedAccounts = "HashedAccount"
HashedStorage = "HashedStorage"
)
/*
AccountsHistory and StorageHistory - indices designed to serve next 2 type of requests:
1. what is smallest block number >= X where account A changed
2. get last shard of A - to append there new block numbers
Task 1. is part of "get historical state" operation (see `core/state:GetAsOf`):
If `db.Seek(A+bigEndian(X))` returns non-last shard -
then get block number from shard value Y := RoaringBitmap(shard_value).GetGte(X)
and with Y go to ChangeSets: db.Get(ChangeSets, Y+A)
If `db.Seek(A+bigEndian(X))` returns last shard -
then we go to PlainState: db.Get(PlainState, A)
Format:
- index split to shards by 2Kb - RoaringBitmap encoded sorted list of block numbers
(to avoid performance degradation of popular accounts or look deep into history.
Also 2Kb allows avoid Overflow pages inside DB.)
- if shard is not last - then key has suffix 8 bytes = bigEndian(max_block_num_in_this_shard)
- if shard is last - then key has suffix 8 bytes = 0xFF
It allows:
- server task 1. by 1 db operation db.Seek(A+bigEndian(X))
- server task 2. by 1 db operation db.Get(A+0xFF)
see also: docs/programmers_guide/db_walkthrough.MD#table-change-sets
AccountsHistory:
key - address + shard_id_u64
value - roaring bitmap - list of block where it changed
StorageHistory
key - address + storage_key + shard_id_u64
value - roaring bitmap - list of block where it changed
*/
const AccountsHistory = "AccountHistory"
const StorageHistory = "StorageHistory"
const (
//key - contract code hash
//value - contract code
Code = "Code"
//key - addressHash+incarnation
//value - code hash
ContractCode = "HashedCodeHash"
// IncarnationMap for deleted accounts
//key - address
//value - incarnation of account when it was last deleted
IncarnationMap = "IncarnationMap"
//TEVMCode -
//key - contract code hash
//value - contract TEVM code
ContractTEVMCode = "TEVMCode"
)
/*
TrieOfAccounts and TrieOfStorage
hasState,groups - mark prefixes existing in hashed_account table
hasTree - mark prefixes existing in trie_account table (not related with branchNodes)
hasHash - mark prefixes which hashes are saved in current trie_account record (actually only hashes of branchNodes can be saved)
@see UnmarshalTrieNode
@see integrity.Trie
+-----------------------------------------------------------------------------------------------------+
| DB record: 0x0B, hasState: 0b1011, hasTree: 0b1001, hasHash: 0b1001, hashes: [x,x] |
+-----------------------------------------------------------------------------------------------------+
| | |
v | v
+---------------------------------------------+ | +--------------------------------------+
| DB record: 0x0B00, hasState: 0b10001 | | | DB record: 0x0B03, hasState: 0b10010 |
| hasTree: 0, hasHash: 0b10000, hashes: [x] | | | hasTree: 0, hasHash: 0, hashes: [] |
+---------------------------------------------+ | +--------------------------------------+
| | | | |
v v v v v
+------------------+ +----------------------+ +---------------+ +---------------+ +---------------+
| Account: | | BranchNode: 0x0B0004 | | Account: | | Account: | | Account: |
| 0x0B0000... | | has no record in | | 0x0B01... | | 0x0B0301... | | 0x0B0304... |
| in HashedAccount | | TrieAccount | | | | | | |
+------------------+ +----------------------+ +---------------+ +---------------+ +---------------+
| |
v v
+---------------+ +---------------+
| Account: | | Account: |
| 0x0B000400... | | 0x0B000401... |
+---------------+ +---------------+
Invariants:
- hasTree is subset of hasState
- hasHash is subset of hasState
- first level in account_trie always exists if hasState>0
- TrieStorage record of account.root (length=40) must have +1 hash - it's account.root
- each record in TrieAccount table must have parent (may be not direct) and this parent must have correct bit in hasTree bitmap
- if hasState has bit - then HashedAccount table must have record according to this bit
- each TrieAccount record must cover some state (means hasState is always > 0)
- TrieAccount records with length=1 can satisfy (hasBranch==0&&hasHash==0) condition
- Other records in TrieAccount and TrieStorage must (hasTree!=0 || hasHash!=0)
*/
const TrieOfAccounts = "TrieAccount"
const TrieOfStorage = "TrieStorage"
// Mapping [block number] => [Verkle Root]
const VerkleRoots = "VerkleRoots"
// Mapping [Verkle Root] => [Rlp-Encoded Verkle Node]
const VerkleTrie = "VerkleTrie"
const (
// DatabaseInfo is used to store information about data layout.
DatabaseInfo = "DbInfo"
// Data item prefixes (use single byte to avoid mixing data types, avoid `i`, used for indexes).
HeaderNumber = "HeaderNumber" // header_hash -> num_u64
HeaderCanonical = "CanonicalHeader" // block_num_u64 -> header hash
Headers = "Header" // block_num_u64 + hash -> header (RLP)
HeaderTD = "HeadersTotalDifficulty" // block_num_u64 + hash -> td (RLP)
BlockBody = "BlockBody" // block_num_u64 + hash -> block body
// EthTx - stores only txs of canonical blocks. As a result - id's used in this table are also
// canonical - same across all nodex in network - regardless reorgs. Transactions of
// non-canonical blocs are not removed, but moved to NonCanonicalTransaction - then during re-org don't
// need re-download block from network.
// Also this table has system-txs before and after block: if
// block has no system-tx - records are absent, but sequence increasing
EthTx = "BlockTransaction" // tbl_sequence_u64 -> rlp(tx)
NonCanonicalTxs = "NonCanonicalTransaction" // tbl_sequence_u64 -> rlp(tx)
MaxTxNum = "MaxTxNum" // block_number_u64 -> max_tx_num_in_block_u64
// EthTxV3 - stores only txs of canonical blocks. Here key is txID + block_hash.
EthTxV3 = "BlockTransactionV3" // tbl_sequence_u64 -> rlp(tx)
Receipts = "Receipt" // block_num_u64 -> canonical block receipts (non-canonical are not stored)
Log = "TransactionLog" // block_num_u64 + txId -> logs of transaction
// Stores bitmap indices - in which block numbers saw logs of given 'address' or 'topic'
// [addr or topic] + [2 bytes inverted shard number] -> bitmap(blockN)
// indices are sharded - because some bitmaps are >1Mb and when new incoming blocks process it
// updates ~300 of bitmaps - by append small amount new values. It cause much big writes (MDBX does copy-on-write).
//
// if last existing shard size merge it with delta
// if serialized size of delta > ShardLimit - break down to multiple shards
// shard number - it's biggest value in bitmap
LogTopicIndex = "LogTopicIndex"
LogAddressIndex = "LogAddressIndex"
// CallTraceSet is the name of the table that contain the mapping of block number to the set (sorted) of all accounts
// touched by call traces. It is DupSort-ed table
// 8-byte BE block number -> account address -> two bits (one for "from", another for "to")
CallTraceSet = "CallTraceSet"
// Indices for call traces - have the same format as LogTopicIndex and LogAddressIndex
// Store bitmap indices - in which block number we saw calls from (CallFromIndex) or to (CallToIndex) some addresses
CallFromIndex = "CallFromIndex"
CallToIndex = "CallToIndex"
// Cumulative indexes for estimation of stage execution
CumulativeGasIndex = "CumulativeGasIndex"
CumulativeTransactionIndex = "CumulativeTransactionIndex"
TxLookup = "BlockTransactionLookup" // hash -> transaction/receipt lookup metadata
ConfigTable = "Config" // config prefix for the db
// Progress of sync stages: stageName -> stageData
SyncStageProgress = "SyncStage"
Clique = "Clique"
CliqueSeparate = "CliqueSeparate"
CliqueSnapshot = "CliqueSnapshot"
CliqueLastSnapshot = "CliqueLastSnapshot"
// Proof-of-stake
// Beacon chain head that is been executed at the current time
CurrentExecutionPayload = "CurrentExecutionPayload"
// Node database tables (see nodedb.go)
// NodeRecords stores P2P node records (ENR)
NodeRecords = "NodeRecord"
// Inodes stores P2P discovery service info about the nodes
Inodes = "Inode"
// Transaction senders - stored separately from the block bodies
Senders = "TxSender" // block_num_u64 + blockHash -> sendersList (no serialization format, every 20 bytes is new sender)
// headBlockKey tracks the latest know full block's hash.
HeadBlockKey = "LastBlock"
HeadHeaderKey = "LastHeader"
// headBlockHash, safeBlockHash, finalizedBlockHash of the latest Engine API forkchoice
LastForkchoice = "LastForkchoice"
// TransitionBlockKey tracks the last proof-of-work block
TransitionBlockKey = "TransitionBlock"
// migrationName -> serialized SyncStageProgress and SyncStageUnwind buckets
// it stores stages progress to understand in which context was executed migration
// in case of bug-report developer can ask content of this bucket
Migrations = "Migration"
Sequence = "Sequence" // tbl_name -> seq_u64
Epoch = "DevEpoch" // block_num_u64+block_hash->transition_proof
PendingEpoch = "DevPendingEpoch" // block_num_u64+block_hash->transition_proof
Issuance = "Issuance" // block_num_u64->RLP(issuance+burnt[0 if < london])
StateAccounts = "StateAccounts"
StateStorage = "StateStorage"
StateCode = "StateCode"
StateCommitment = "StateCommitment"
// BOR
BorReceipts = "BorReceipt"
BorTxLookup = "BlockBorTransactionLookup" // transaction_hash -> block_num_u64
BorSeparate = "BorSeparate"
// Downloader
BittorrentCompletion = "BittorrentCompletion"
BittorrentInfo = "BittorrentInfo"
// Domains and Inverted Indices
AccountKeys = "AccountKeys"
AccountVals = "AccountVals"
AccountHistoryKeys = "AccountHistoryKeys"
AccountHistoryVals = "AccountHistoryVals"
AccountIdx = "AccountIdx"
StorageKeys = "StorageKeys"
StorageVals = "StorageVals"
StorageHistoryKeys = "StorageHistoryKeys"
StorageHistoryVals = "StorageHistoryVals"
StorageIdx = "StorageIdx"
CodeKeys = "CodeKeys"
CodeVals = "CodeVals"
CodeHistoryKeys = "CodeHistoryKeys"
CodeHistoryVals = "CodeHistoryVals"
CodeIdx = "CodeIdx"
CommitmentKeys = "CommitmentKeys"
CommitmentVals = "CommitmentVals"
CommitmentHistoryKeys = "CommitmentHistoryKeys"
CommitmentHistoryVals = "CommitmentHistoryVals"
CommitmentIdx = "CommitmentIdx"
LogAddressKeys = "LogAddressKeys"
LogAddressIdx = "LogAddressIdx"
LogTopicsKeys = "LogTopicsKeys"
LogTopicsIdx = "LogTopicsIdx"
TracesFromKeys = "TracesFromKeys"
TracesFromIdx = "TracesFromIdx"
TracesToKeys = "TracesToKeys"
TracesToIdx = "TracesToIdx"
Snapshots = "Snapshots" // name -> hash
RAccountKeys = "RAccountKeys"
RAccountIdx = "RAccountIdx"
RStorageKeys = "RStorageKeys"
RStorageIdx = "RStorageIdx"
RCodeKeys = "RCodeKeys"
RCodeIdx = "RCodeIdx"
PlainStateR = "PlainStateR" // temporary table for PlainState reconstitution
PlainStateD = "PlainStateD" // temporary table for PlainStare reconstitution, deletes
CodeR = "CodeR" // temporary table for Code reconstitution
CodeD = "CodeD" // temporary table for Code reconstitution, deletes
PlainContractR = "PlainContractR" // temporary table for PlainContract reconstitution
PlainContractD = "PlainContractD" // temporary table for PlainContract reconstitution, deletes
// Erigon-CL Objects
// [slot] => [Beacon state]
BeaconState = "BeaconState"
// [slot] => [signature + block without execution payload]
BeaconBlocks = "BeaconBlock"
// [slot] => [attestation list (custom encoding)]
Attestetations = "Attestetations"
// [slot] => [Finalized block root]
FinalizedBlockRoots = "FinalizedBlockRoots"
// [Root (block root/state root/eth1 root)] => Slot
RootSlotIndex = "RootSlotIndex"
// LightClientStore => LightClientStore object
// LightClientFinalityUpdate => latest finality update
// LightClientOptimisticUpdate => latest optimistic update
LightClient = "LightClient"
// Period (one every 27 hours) => LightClientUpdate
LightClientUpdates = "LightClientUpdates"
// zkevm
L1VERIFICATIONS = "hermez_l1Verifications" // l1blockno, batchno -> l1txhash
L1SEQUENCES = "hermez_l1Sequences" // l1blockno, batchno -> l1txhash
FORKIDS = "hermez_forkIds" // batchNo -> forkId
FORKID_BLOCK = "hermez_forkIdBlock" // forkId -> startBlock
BLOCKBATCHES = "hermez_blockBatches" // l2blockno -> batchno
GLOBAL_EXIT_ROOTS = "hermez_globalExitRootsSaved" // GER -> true
BLOCK_GLOBAL_EXIT_ROOTS = "hermez_globalExitRoots" // l2blockno -> GER
GLOBAL_EXIT_ROOTS_BATCHES = "hermez_globalExitRoots_batches" // batchkno -> GER
TX_PRICE_PERCENTAGE = "hermez_txPricePercentage" // txHash -> txPricePercentage
STATE_ROOTS = "hermez_stateRoots" // l2blockno -> stateRoot
L1_INFO_TREE_UPDATES = "l1_info_tree_updates" // index -> L1InfoTreeUpdate
BLOCK_L1_INFO_TREE_INDEX = "block_l1_info_tree_index" // block number -> l1 info tree index
L1_INJECTED_BATCHES = "l1_injected_batches" // index increasing by 1 -> injected batch for the start of the chain
BLOCK_INFO_ROOTS = "block_info_roots" // block number -> block info root hash
L1_BLOCK_HASHES = "l1_block_hashes" // l1 block hash -> true
BLOCK_L1_BLOCK_HASHES = "block_l1_block_hashes" // block number -> l1 block hash
L1_BLOCK_HASH_GER = "l1_block_hash_ger" // l1 block hash -> GER
INTERMEDIATE_TX_STATEROOTS = "hermez_intermediate_tx_stateRoots" // l2blockno -> stateRoot
BATCH_WITNESSES = "hermez_batch_witnesses" // batch number -> witness
BATCH_COUNTERS = "hermez_batch_counters" // batch number -> counters
)
// Keys
var (
//StorageModeTEVM - does not translate EVM to TEVM
StorageModeTEVM = []byte("smTEVM")
PruneTypeOlder = []byte("older")
PruneTypeBefore = []byte("before")
PruneHistory = []byte("pruneHistory")
PruneHistoryType = []byte("pruneHistoryType")
PruneReceipts = []byte("pruneReceipts")
PruneReceiptsType = []byte("pruneReceiptsType")
PruneTxIndex = []byte("pruneTxIndex")
PruneTxIndexType = []byte("pruneTxIndexType")
PruneCallTraces = []byte("pruneCallTraces")
PruneCallTracesType = []byte("pruneCallTracesType")
DBSchemaVersionKey = []byte("dbVersion")
BittorrentPeerID = "peerID"
CurrentHeadersSnapshotHash = []byte("CurrentHeadersSnapshotHash")
CurrentHeadersSnapshotBlock = []byte("CurrentHeadersSnapshotBlock")
CurrentBodiesSnapshotHash = []byte("CurrentBodiesSnapshotHash")
CurrentBodiesSnapshotBlock = []byte("CurrentBodiesSnapshotBlock")
PlainStateVersion = []byte("PlainStateVersion")
LightClientStore = []byte("LightClientStore")
LightClientFinalityUpdate = []byte("LightClientFinalityUpdate")
LightClientOptimisticUpdate = []byte("LightClientOptimisticUpdate")
)
// ChaindataTables - list of all buckets. App will panic if some bucket is not in this list.
// This list will be sorted in `init` method.
// ChaindataTablesCfg - can be used to find index in sorted version of ChaindataTables list by name
var ChaindataTables = []string{
AccountsHistory,
StorageHistory,
Code,
ContractCode,
HeaderNumber,
BlockBody,
Receipts,
TxLookup,
ConfigTable,
CurrentExecutionPayload,
DatabaseInfo,
IncarnationMap,
ContractTEVMCode,
CliqueSeparate,
CliqueLastSnapshot,
CliqueSnapshot,
SyncStageProgress,
PlainState,
PlainContractCode,
AccountChangeSet,
StorageChangeSet,
Senders,
HeadBlockKey,
HeadHeaderKey,
LastForkchoice,
Migrations,
LogTopicIndex,
LogAddressIndex,
CallTraceSet,
CallFromIndex,
CallToIndex,
CumulativeGasIndex,
CumulativeTransactionIndex,
Log,
Sequence,
EthTx,
EthTxV3,
NonCanonicalTxs,
TrieOfAccounts,
TrieOfStorage,
HashedAccounts,
HashedStorage,
HeaderCanonical,
Headers,
HeaderTD,
Epoch,
PendingEpoch,
Issuance,
StateAccounts,
StateStorage,
StateCode,
StateCommitment,
BorReceipts,
BorTxLookup,
BorSeparate,
AccountKeys,
AccountVals,
AccountHistoryKeys,
AccountHistoryVals,
AccountIdx,
StorageKeys,
StorageVals,
StorageHistoryKeys,
StorageHistoryVals,
StorageIdx,
CodeKeys,
CodeVals,
CodeHistoryKeys,
CodeHistoryVals,
CodeIdx,
CommitmentKeys,
CommitmentVals,
CommitmentHistoryKeys,
CommitmentHistoryVals,
CommitmentIdx,
LogAddressKeys,
LogAddressIdx,
LogTopicsKeys,
LogTopicsIdx,
TracesFromKeys,
TracesFromIdx,
TracesToKeys,
TracesToIdx,
Snapshots,
MaxTxNum,
RAccountKeys,
RAccountIdx,
RStorageKeys,
RStorageIdx,
RCodeKeys,
RCodeIdx,
VerkleRoots,
VerkleTrie,
// Beacon stuff
BeaconState,
BeaconBlocks,
FinalizedBlockRoots,
RootSlotIndex,
Attestetations,
LightClient,
LightClientUpdates,
// zkevm
L1VERIFICATIONS,
L1SEQUENCES,
FORKIDS,
FORKID_BLOCK,
BLOCKBATCHES,
GLOBAL_EXIT_ROOTS,
BLOCK_GLOBAL_EXIT_ROOTS,
GLOBAL_EXIT_ROOTS_BATCHES,
TX_PRICE_PERCENTAGE,
STATE_ROOTS,
L1_INFO_TREE_UPDATES,
BLOCK_L1_INFO_TREE_INDEX,
L1_INJECTED_BATCHES,
BLOCK_INFO_ROOTS,
L1_BLOCK_HASHES,
BLOCK_L1_BLOCK_HASHES,
L1_BLOCK_HASH_GER,
INTERMEDIATE_TX_STATEROOTS,
BATCH_WITNESSES,
BATCH_COUNTERS,
}
const (
RecentLocalTransaction = "RecentLocalTransaction" // sequence_u64 -> tx_hash
PoolTransaction = "PoolTransaction" // txHash -> sender_id_u64+tx_rlp
PoolInfo = "PoolInfo" // option_key -> option_value
)
var TxPoolTables = []string{
RecentLocalTransaction,
PoolTransaction,
PoolInfo,
}
var SentryTables = []string{}
var DownloaderTables = []string{
BittorrentCompletion,
BittorrentInfo,
}
var ReconTables = []string{
PlainStateR,
PlainStateD,
CodeR,
CodeD,
PlainContractR,
PlainContractD,
}
// ChaindataDeprecatedTables - list of buckets which can be programmatically deleted - for example after migration
var ChaindataDeprecatedTables = []string{
Clique,
TransitionBlockKey,
}
type CmpFunc func(k1, k2, v1, v2 []byte) int
type TableCfg map[string]TableCfgItem
type Bucket string
type DBI uint
type TableFlags uint
const (
Default TableFlags = 0x00
ReverseKey TableFlags = 0x02
DupSort TableFlags = 0x04
IntegerKey TableFlags = 0x08
IntegerDup TableFlags = 0x20
ReverseDup TableFlags = 0x40
)
type TableCfgItem struct {
Flags TableFlags
// AutoDupSortKeysConversion - enables some keys transformation - to change db layout without changing app code.
// Use it wisely - it helps to do experiments with DB format faster, but better reduce amount of Magic in app.
// If good DB format found, push app code to accept this format and then disable this property.
AutoDupSortKeysConversion bool
IsDeprecated bool
DBI DBI
// DupFromLen - if user provide key of this length, then next transformation applied:
// v = append(k[DupToLen:], v...)
// k = k[:DupToLen]
// And opposite at retrieval
// Works only if AutoDupSortKeysConversion enabled
DupFromLen int
DupToLen int
}
var ChaindataTablesCfg = TableCfg{
HashedStorage: {
Flags: DupSort,
AutoDupSortKeysConversion: true,
DupFromLen: 72,
DupToLen: 40,
},
AccountChangeSet: {Flags: DupSort},
StorageChangeSet: {Flags: DupSort},
PlainState: {
Flags: DupSort,
AutoDupSortKeysConversion: true,
DupFromLen: 60,
DupToLen: 28,
},
CallTraceSet: {Flags: DupSort},
AccountKeys: {Flags: DupSort},
AccountHistoryKeys: {Flags: DupSort},
AccountHistoryVals: {Flags: DupSort},
AccountIdx: {Flags: DupSort},
StorageKeys: {Flags: DupSort},
StorageHistoryKeys: {Flags: DupSort},
StorageHistoryVals: {Flags: DupSort},
StorageIdx: {Flags: DupSort},
CodeKeys: {Flags: DupSort},
CodeHistoryKeys: {Flags: DupSort},
CodeIdx: {Flags: DupSort},
CommitmentKeys: {Flags: DupSort},
CommitmentHistoryKeys: {Flags: DupSort},
CommitmentIdx: {Flags: DupSort},
LogAddressKeys: {Flags: DupSort},
LogAddressIdx: {Flags: DupSort},
LogTopicsKeys: {Flags: DupSort},
LogTopicsIdx: {Flags: DupSort},
TracesFromKeys: {Flags: DupSort},
TracesFromIdx: {Flags: DupSort},
TracesToKeys: {Flags: DupSort},
TracesToIdx: {Flags: DupSort},
RAccountKeys: {Flags: DupSort},
RAccountIdx: {Flags: DupSort},
RStorageKeys: {Flags: DupSort},
RStorageIdx: {Flags: DupSort},
RCodeKeys: {Flags: DupSort},
RCodeIdx: {Flags: DupSort},
}
var TxpoolTablesCfg = TableCfg{}
var SentryTablesCfg = TableCfg{}
var DownloaderTablesCfg = TableCfg{}
var ReconTablesCfg = TableCfg{
PlainStateD: {Flags: DupSort},
CodeD: {Flags: DupSort},
PlainContractD: {Flags: DupSort},
}
func sortBuckets() {
sort.SliceStable(ChaindataTables, func(i, j int) bool {
return strings.Compare(ChaindataTables[i], ChaindataTables[j]) < 0
})
}
func init() {
fmt.Println("[cdk-erigon-lib] timestamp 2024-03-12:16:34")
reinit()
}
func reinit() {
sortBuckets()
for _, name := range ChaindataTables {
_, ok := ChaindataTablesCfg[name]
if !ok {
ChaindataTablesCfg[name] = TableCfgItem{}
}
}
for _, name := range ChaindataDeprecatedTables {
_, ok := ChaindataTablesCfg[name]
if !ok {
ChaindataTablesCfg[name] = TableCfgItem{}
}
tmp := ChaindataTablesCfg[name]
tmp.IsDeprecated = true
ChaindataTablesCfg[name] = tmp
}
for _, name := range TxPoolTables {
_, ok := TxpoolTablesCfg[name]
if !ok {
TxpoolTablesCfg[name] = TableCfgItem{}
}
}
for _, name := range SentryTables {
_, ok := SentryTablesCfg[name]
if !ok {
SentryTablesCfg[name] = TableCfgItem{}
}
}
for _, name := range DownloaderTables {
_, ok := DownloaderTablesCfg[name]
if !ok {
DownloaderTablesCfg[name] = TableCfgItem{}
}
}
for _, name := range ReconTables {
_, ok := ReconTablesCfg[name]
if !ok {
ReconTablesCfg[name] = TableCfgItem{}
}
}
}