Skip to content

Commit

Permalink
Merge pull request #168 from Ethernal-Tech/remove-multiple-leveldb-in…
Browse files Browse the repository at this point in the history
…stances

2nd leveldb database instance removal
  • Loading branch information
oliverbundalo authored Mar 27, 2024
2 parents c756706 + 98bec50 commit 111586d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 28 deletions.
38 changes: 11 additions & 27 deletions blockchain/storagev2/leveldb/leveldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,16 @@ type levelDB struct {
}

var tableMapper = map[uint8][]byte{
// Main DB
storagev2.BODY: []byte("b"), // DB key = block number + block hash + mapper, value = block body
storagev2.DIFFICULTY: []byte("d"), // DB key = block number + block hash + mapper, value = block total diffculty
storagev2.HEADER: []byte("h"), // DB key = block number + block hash + mapper, value = block header
storagev2.RECEIPTS: []byte("r"), // DB key = block number + block hash + mapper, value = block receipts
storagev2.CANONICAL: {}, // DB key = block number + mapper, value = block hash

// Lookup DB
storagev2.FORK: {}, // DB key = FORK_KEY + mapper, value = fork hashes
storagev2.HEAD_HASH: {}, // DB key = HEAD_HASH_KEY + mapper, value = head hash
storagev2.HEAD_NUMBER: {}, // DB key = HEAD_NUMBER_KEY + mapper, value = head number
storagev2.BLOCK_LOOKUP: {}, // DB key = block hash + mapper, value = block number
storagev2.TX_LOOKUP: {}, // DB key = tx hash + mapper, value = block number
storagev2.BODY: []byte("b"), // DB key = block number + block hash + mapper, value = block body
storagev2.DIFFICULTY: []byte("d"), // DB key = block number + block hash + mapper, value = block total diffculty
storagev2.HEADER: []byte("h"), // DB key = block number + block hash + mapper, value = block header
storagev2.RECEIPTS: []byte("r"), // DB key = block number + block hash + mapper, value = block receipts
storagev2.CANONICAL: {}, // DB key = block number + mapper, value = block hash
storagev2.FORK: {}, // DB key = FORK_KEY + mapper, value = fork hashes
storagev2.HEAD_HASH: {}, // DB key = HEAD_HASH_KEY + mapper, value = head hash
storagev2.HEAD_NUMBER: {}, // DB key = HEAD_NUMBER_KEY + mapper, value = head number
storagev2.BLOCK_LOOKUP: {}, // DB key = block hash + mapper, value = block number
storagev2.TX_LOOKUP: {}, // DB key = tx hash + mapper, value = block number
}

// NewLevelDBStorage creates the new storage reference with leveldb default options
Expand All @@ -44,21 +41,8 @@ func NewLevelDBStorage(path string, logger hclog.Logger) (*storagev2.Storage, er
return nil, err
}

// Open Lookup
// Set default options
options = &opt.Options{
BlockCacheCapacity: 64 * opt.MiB,
WriteBuffer: opt.DefaultWriteBuffer,
}
path += "/lookup"

lookup, err := openLevelDBStorage(path, options)
if err != nil {
return nil, err
}

ldbs[0] = &levelDB{maindb}
ldbs[1] = &levelDB{lookup}
ldbs[1] = nil

return storagev2.Open(logger.Named("leveldb"), ldbs)
}
Expand Down
7 changes: 6 additions & 1 deletion blockchain/storagev2/storage.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//nolint:stylecheck
package storagev2

import (
Expand Down Expand Up @@ -39,6 +38,8 @@ const (
)

// Lookup tables
//
//nolint:stylecheck // needed because linter considers _ in name as an error
const (
FORK = uint8(0) | LOOKUP_INDEX
HEAD_HASH = uint8(2) | LOOKUP_INDEX
Expand All @@ -47,14 +48,18 @@ const (
TX_LOOKUP = uint8(8) | LOOKUP_INDEX
)

//nolint:stylecheck // needed because linter considers _ in name as an error
const MAX_TABLES = uint8(20)

// Database indexes
//
//nolint:stylecheck // needed because linter considers _ in name as an error
const (
MAINDB_INDEX = uint8(0)
LOOKUP_INDEX = uint8(1)
)

//nolint:stylecheck // needed because linter considers _ in name as an error
var (
FORK_KEY = []byte("0000000f")
HEAD_HASH_KEY = []byte("0000000h")
Expand Down

0 comments on commit 111586d

Please sign in to comment.