Skip to content

Commit

Permalink
mdbx: remove unused table names and keys (#11506)
Browse files Browse the repository at this point in the history
  • Loading branch information
battlmonstr authored Aug 7, 2024
1 parent f1621bc commit d919ab7
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 166 deletions.
1 change: 0 additions & 1 deletion cmd/integration/commands/refetence_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ var stateBuckets = []string{
kv.E2AccountsHistory,
kv.E2StorageHistory,
kv.TxLookup,
kv.ContractTEVMCode,
}

var cmdWarmup = &cobra.Command{
Expand Down
1 change: 0 additions & 1 deletion cmd/pics/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ var bucketLabels = map[string]string{
kv.StorageChangeSet: "Storage Changes",
kv.IncarnationMap: "Incarnations",
kv.Senders: "Transaction Senders",
kv.ContractTEVMCode: "Contract TEVM code",
}

/*dbutils.PlainContractCode,
Expand Down
23 changes: 1 addition & 22 deletions core/genesis_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ import (
state2 "github.com/erigontech/erigon-lib/state"

"github.com/erigontech/erigon/common"
"github.com/erigontech/erigon/consensus/ethash"
"github.com/erigontech/erigon/consensus/merge"
"github.com/erigontech/erigon/core/rawdb"
"github.com/erigontech/erigon/core/state"
"github.com/erigontech/erigon/core/tracing"
Expand Down Expand Up @@ -266,26 +264,7 @@ func write(tx kv.RwTx, g *types.Genesis, dirs datadir.Dirs, logger log.Logger) (
return nil, nil, err
}

// We support ethash/merge for issuance (for now)
if g.Config.Consensus != chain.EtHashConsensus {
return block, statedb, nil
}
// Issuance is the sum of allocs
genesisIssuance := big.NewInt(0)
for _, account := range g.Alloc {
genesisIssuance.Add(genesisIssuance, account.Balance)
}

// BlockReward can be present at genesis
if block.Header().Difficulty.Cmp(merge.ProofOfStakeDifficulty) != 0 {
blockReward, _ := ethash.AccumulateRewards(g.Config, block.Header(), nil)
// Set BlockReward
genesisIssuance.Add(genesisIssuance, blockReward.ToBig())
}
if err := rawdb.WriteTotalIssued(tx, 0, genesisIssuance); err != nil {
return nil, nil, err
}
return block, statedb, rawdb.WriteTotalBurnt(tx, 0, libcommon.Big0)
return block, statedb, nil
}

// GenesisBlockForTesting creates and writes a block in which addr has the given wei balance.
Expand Down
25 changes: 0 additions & 25 deletions core/rawdb/accessors_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1085,31 +1085,6 @@ func TruncateBlocks(ctx context.Context, tx kv.RwTx, blockFrom uint64) error {
return nil
})
}
func ReadTotalIssued(db kv.Getter, number uint64) (*big.Int, error) {
data, err := db.GetOne(kv.Issuance, hexutility.EncodeTs(number))
if err != nil {
return nil, err
}

return new(big.Int).SetBytes(data), nil
}

func WriteTotalIssued(db kv.Putter, number uint64, totalIssued *big.Int) error {
return db.Put(kv.Issuance, hexutility.EncodeTs(number), totalIssued.Bytes())
}

func ReadTotalBurnt(db kv.Getter, number uint64) (*big.Int, error) {
data, err := db.GetOne(kv.Issuance, append([]byte("burnt"), hexutility.EncodeTs(number)...))
if err != nil {
return nil, err
}

return new(big.Int).SetBytes(data), nil
}

func WriteTotalBurnt(db kv.Putter, number uint64, totalBurnt *big.Int) error {
return db.Put(kv.Issuance, append([]byte("burnt"), hexutility.EncodeTs(number)...), totalBurnt.Bytes())
}

func ReadHeaderByNumber(db kv.Getter, number uint64) *types.Header {
hash, err := ReadCanonicalHash(db, number)
Expand Down
11 changes: 8 additions & 3 deletions erigon-lib/kv/mdbx/kv_migrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ func TestBucketCRUD(t *testing.T) {
db, tx := memdb.NewTestTx(t)

normalBucket := kv.ChaindataTables[15]
deprecatedBucket := kv.ChaindataDeprecatedTables[0]
deprecatedBucket := "none"
if len(kv.ChaindataDeprecatedTables) > 0 {
deprecatedBucket = kv.ChaindataDeprecatedTables[0]
}
migrator := tx

// check thad buckets have unique DBI's
Expand All @@ -63,8 +66,10 @@ func TestBucketCRUD(t *testing.T) {
require.NoError(migrator.CreateBucket(deprecatedBucket))
require.True(migrator.ExistsBucket(deprecatedBucket))

require.NoError(migrator.DropBucket(deprecatedBucket))
require.False(migrator.ExistsBucket(deprecatedBucket))
if deprecatedBucket != "none" {
require.NoError(migrator.DropBucket(deprecatedBucket))
require.False(migrator.ExistsBucket(deprecatedBucket))
}

require.NoError(migrator.CreateBucket(deprecatedBucket))
require.True(migrator.ExistsBucket(deprecatedBucket))
Expand Down
129 changes: 15 additions & 114 deletions erigon-lib/kv/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,6 @@ const (
//key - address
//value - incarnation of account when it was last deleted
IncarnationMap = "IncarnationMap"

//TEVMCode -
//key - contract code hash
//value - contract TEVM code
ContractTEVMCode = "TEVMCode"
)

/*
Expand Down Expand Up @@ -304,15 +299,9 @@ const (
// 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)
Expand All @@ -331,9 +320,6 @@ const (
// 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
Expand All @@ -344,13 +330,6 @@ const (
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"
BorFinality = "BorFinality"
Expand Down Expand Up @@ -412,16 +391,7 @@ const (
// and `Tbl{Account,Storage,Code,Commitment}Idx` for inverted indices
TblPruningProgress = "PruningProgress"

Snapshots = "Snapshots" // name -> hash

//State Reconstitution
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
Expand All @@ -431,15 +401,11 @@ const (

// Erigon-CL Objects

// [slot] => [Beacon state]
BeaconState = "BeaconState"
// [slot] => [signature + block without execution payload]
BeaconBlocks = "BeaconBlock"

EffectiveBalancesDump = "EffectiveBalancesDump"
BalancesDump = "BalancesDump"
// [slot] => [attestation list (custom encoding)]
Attestetations = "Attestetations"

// [slot] => [Canonical block root]
CanonicalBlockRoots = "CanonicalBlockRoots"
Expand All @@ -456,7 +422,6 @@ const (
LastBeaconSnapshotKey = "LastBeaconSnapshotKey"

BlockRootToKzgCommitments = "BlockRootToKzgCommitments"
KzgCommitmentToBlob = "KzgCommitmentToBlob"

// [Block Root] => [Parent Root]
BlockRootToParentRoot = "BlockRootToParentRoot"
Expand All @@ -466,8 +431,6 @@ const (
// BlockRoot => Beacon Block Header
BeaconBlockHeaders = "BeaconBlockHeaders"

// Period (one every 27 hours) => LightClientUpdate
LightClientUpdates = "LightClientUpdates"
// Beacon historical data
// ValidatorIndex => [Field]
ValidatorPublicKeys = "ValidatorPublickeys"
Expand All @@ -487,14 +450,12 @@ const (
SlotData = "SlotData"
EpochData = "EpochData"
// State fields
InactivityScores = "InactivityScores"
PreviousEpochParticipation = "PreviousEpochParticipation"
CurrentEpochParticipation = "CurrentEpochParticipation"
NextSyncCommittee = "NextSyncCommittee"
CurrentSyncCommittee = "CurrentSyncCommittee"
HistoricalRoots = "HistoricalRoots"
HistoricalSummaries = "HistoricalSummaries"
Eth1DataVotes = "Eth1DataVotes"
InactivityScores = "InactivityScores"
NextSyncCommittee = "NextSyncCommittee"
CurrentSyncCommittee = "CurrentSyncCommittee"
HistoricalRoots = "HistoricalRoots"
HistoricalSummaries = "HistoricalSummaries"
Eth1DataVotes = "Eth1DataVotes"

IntraRandaoMixes = "IntraRandaoMixes" // [validator_index+slot] => [randao_mix]
RandaoMixes = "RandaoMixes" // [validator_index+slot] => [randao_mix]
Expand All @@ -509,38 +470,19 @@ const (

// 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")
PruneBlocks = []byte("pruneBlocks")
PruneBlocksType = []byte("pruneBlocksType")
PruneTypeOlder = []byte("older")
PruneHistory = []byte("pruneHistory")
PruneBlocks = []byte("pruneBlocks")

DBSchemaVersionKey = []byte("dbVersion")
GenesisKey = []byte("genesis")

BittorrentPeerID = "peerID"
CurrentHeadersSnapshotHash = []byte("CurrentHeadersSnapshotHash")
CurrentHeadersSnapshotBlock = []byte("CurrentHeadersSnapshotBlock")
CurrentBodiesSnapshotHash = []byte("CurrentBodiesSnapshotHash")
CurrentBodiesSnapshotBlock = []byte("CurrentBodiesSnapshotBlock")
PlainStateVersion = []byte("PlainStateVersion")
BittorrentPeerID = "peerID"

PlainStateVersion = []byte("PlainStateVersion")

HighestFinalizedKey = []byte("HighestFinalized")
LightClientStore = []byte("LightClientStore")
LightClientFinalityUpdate = []byte("LightClientFinalityUpdate")
LightClientOptimisticUpdate = []byte("LightClientOptimisticUpdate")
LastNewBlockSeen = []byte("LastNewBlockSeen") // last seen block hash
HighestFinalizedKey = []byte("HighestFinalized")
LastNewBlockSeen = []byte("LastNewBlockSeen") // last seen block hash

StatesProcessingKey = []byte("StatesProcessing")
MinimumPrunableStepDomainKey = []byte("MinimumPrunableStepDomainKey")
Expand All @@ -560,13 +502,10 @@ var ChaindataTables = []string{
Receipts,
TxLookup,
ConfigTable,
CurrentExecutionPayload,
DatabaseInfo,
IncarnationMap,
ContractTEVMCode,
CliqueSeparate,
CliqueLastSnapshot,
CliqueSnapshot,
SyncStageProgress,
PlainState,
PlainContractCode,
Expand Down Expand Up @@ -595,11 +534,6 @@ var ChaindataTables = []string{
HeaderTD,
Epoch,
PendingEpoch,
Issuance,
StateAccounts,
StateStorage,
StateCode,
StateCommitment,
BorReceipts,
BorFinality,
BorTxLookup,
Expand Down Expand Up @@ -648,20 +582,11 @@ var ChaindataTables = []string{

TblPruningProgress,

Snapshots,
MaxTxNum,

RAccountKeys,
RAccountIdx,
RStorageKeys,
RStorageIdx,
RCodeKeys,
RCodeIdx,

VerkleRoots,
VerkleTrie,
// Beacon stuff
BeaconState,
BeaconBlocks,
CanonicalBlockRoots,
BlockRootToSlot,
Expand All @@ -670,14 +595,11 @@ var ChaindataTables = []string{
BlockRootToParentRoot,
BeaconBlockHeaders,
HighestFinalized,
Attestetations,
LightClientUpdates,
BlockRootToBlockHash,
BlockRootToBlockNumber,
LastBeaconSnapshot,
// Blob Storage
BlockRootToKzgCommitments,
KzgCommitmentToBlob,
// State Reconstitution
ValidatorPublicKeys,
InvertedValidatorPublicKeys,
Expand All @@ -694,8 +616,6 @@ var ChaindataTables = []string{
RandaoMixes,
Proposers,
StatesProcessingProgress,
PreviousEpochParticipation,
CurrentEpochParticipation,
InactivityScores,
NextSyncCommittee,
CurrentSyncCommittee,
Expand Down Expand Up @@ -734,10 +654,7 @@ var ReconTables = []string{
}

// ChaindataDeprecatedTables - list of buckets which can be programmatically deleted - for example after migration
var ChaindataDeprecatedTables = []string{
Clique,
TransitionBlockKey,
}
var ChaindataDeprecatedTables = []string{}

// Diagnostics tables
var DiagnosticsTables = []string{
Expand Down Expand Up @@ -823,13 +740,6 @@ var ChaindataTablesCfg = TableCfg{
TblTracesToKeys: {Flags: DupSort},
TblTracesToIdx: {Flags: DupSort},
TblPruningProgress: {Flags: DupSort},

RAccountKeys: {Flags: DupSort},
RAccountIdx: {Flags: DupSort},
RStorageKeys: {Flags: DupSort},
RStorageIdx: {Flags: DupSort},
RCodeKeys: {Flags: DupSort},
RCodeIdx: {Flags: DupSort},
}

var BorTablesCfg = TableCfg{
Expand Down Expand Up @@ -1034,12 +944,3 @@ func (iip Appendable) String() string {
return "unknown Appendable"
}
}

func String2Appendable(in string) (Appendable, error) {
switch in {
//case "receipts":
// return ReceiptsAppendable, nil
default:
return Appendable(MaxUint16), fmt.Errorf("unknown Appendable name: %s", in)
}
}

0 comments on commit d919ab7

Please sign in to comment.