Skip to content

Commit 6cf0ab3

Browse files
authored
core/rawdb: separate raw database access to own package (#16666)
1 parent 5463ed9 commit 6cf0ab3

52 files changed

Lines changed: 1289 additions & 1296 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎accounts/abi/bind/backends/simulated.go‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/ethereum/go-ethereum/consensus/ethash"
3232
"github.com/ethereum/go-ethereum/core"
3333
"github.com/ethereum/go-ethereum/core/bloombits"
34+
"github.com/ethereum/go-ethereum/core/rawdb"
3435
"github.com/ethereum/go-ethereum/core/state"
3536
"github.com/ethereum/go-ethereum/core/types"
3637
"github.com/ethereum/go-ethereum/core/vm"
@@ -159,7 +160,7 @@ func (b *SimulatedBackend) StorageAt(ctx context.Context, contract common.Addres
159160

160161
// TransactionReceipt returns the receipt of a transaction.
161162
func (b *SimulatedBackend) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) {
162-
receipt, _, _, _ := core.GetReceipt(b.database, txHash)
163+
receipt, _, _, _ := rawdb.ReadReceipt(b.database, txHash)
163164
return receipt, nil
164165
}
165166

@@ -430,11 +431,19 @@ func (fb *filterBackend) HeaderByNumber(ctx context.Context, block rpc.BlockNumb
430431
}
431432

432433
func (fb *filterBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
433-
return core.GetBlockReceipts(fb.db, hash, core.GetBlockNumber(fb.db, hash)), nil
434+
number := rawdb.ReadHeaderNumber(fb.db, hash)
435+
if number == nil {
436+
return nil, nil
437+
}
438+
return rawdb.ReadReceipts(fb.db, hash, *number), nil
434439
}
435440

436441
func (fb *filterBackend) GetLogs(ctx context.Context, hash common.Hash) ([][]*types.Log, error) {
437-
receipts := core.GetBlockReceipts(fb.db, hash, core.GetBlockNumber(fb.db, hash))
442+
number := rawdb.ReadHeaderNumber(fb.db, hash)
443+
if number == nil {
444+
return nil, nil
445+
}
446+
receipts := rawdb.ReadReceipts(fb.db, hash, *number)
438447
if receipts == nil {
439448
return nil, nil
440449
}

‎cmd/geth/dao_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"testing"
2525

2626
"github.com/ethereum/go-ethereum/common"
27-
"github.com/ethereum/go-ethereum/core"
27+
"github.com/ethereum/go-ethereum/core/rawdb"
2828
"github.com/ethereum/go-ethereum/ethdb"
2929
"github.com/ethereum/go-ethereum/params"
3030
)
@@ -131,8 +131,8 @@ func testDAOForkBlockNewChain(t *testing.T, test int, genesis string, expectBloc
131131
if genesis != "" {
132132
genesisHash = daoGenesisHash
133133
}
134-
config, err := core.GetChainConfig(db, genesisHash)
135-
if err != nil {
134+
config := rawdb.ReadChainConfig(db, genesisHash)
135+
if config == nil {
136136
t.Errorf("test %d: failed to retrieve chain config: %v", test, err)
137137
return // we want to return here, the other checks can't make it past this point (nil panic).
138138
}

‎cmd/utils/cmd.go‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929

3030
"github.com/ethereum/go-ethereum/common"
3131
"github.com/ethereum/go-ethereum/core"
32+
"github.com/ethereum/go-ethereum/core/rawdb"
3233
"github.com/ethereum/go-ethereum/core/types"
3334
"github.com/ethereum/go-ethereum/crypto"
3435
"github.com/ethereum/go-ethereum/ethdb"
@@ -271,15 +272,13 @@ func ImportPreimages(db *ethdb.LDBDatabase, fn string) error {
271272
// Accumulate the preimages and flush when enough ws gathered
272273
preimages[crypto.Keccak256Hash(blob)] = common.CopyBytes(blob)
273274
if len(preimages) > 1024 {
274-
if err := core.WritePreimages(db, 0, preimages); err != nil {
275-
return err
276-
}
275+
rawdb.WritePreimages(db, 0, preimages)
277276
preimages = make(map[common.Hash][]byte)
278277
}
279278
}
280279
// Flush the last batch preimage data
281280
if len(preimages) > 0 {
282-
return core.WritePreimages(db, 0, preimages)
281+
rawdb.WritePreimages(db, 0, preimages)
283282
}
284283
return nil
285284
}

‎consensus/clique/snapshot_test.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
"github.com/ethereum/go-ethereum/common"
2626
"github.com/ethereum/go-ethereum/core"
27+
"github.com/ethereum/go-ethereum/core/rawdb"
2728
"github.com/ethereum/go-ethereum/core/types"
2829
"github.com/ethereum/go-ethereum/crypto"
2930
"github.com/ethereum/go-ethereum/ethdb"
@@ -81,7 +82,7 @@ func (r *testerChainReader) GetBlock(common.Hash, uint64) *types.Block { panic
8182
func (r *testerChainReader) GetHeaderByHash(common.Hash) *types.Header { panic("not supported") }
8283
func (r *testerChainReader) GetHeaderByNumber(number uint64) *types.Header {
8384
if number == 0 {
84-
return core.GetHeader(r.db, core.GetCanonicalHash(r.db, 0), 0)
85+
return rawdb.ReadHeader(r.db, rawdb.ReadCanonicalHash(r.db, 0), 0)
8586
}
8687
panic("not supported")
8788
}

‎core/bench_test.go‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/ethereum/go-ethereum/common"
2727
"github.com/ethereum/go-ethereum/common/math"
2828
"github.com/ethereum/go-ethereum/consensus/ethash"
29+
"github.com/ethereum/go-ethereum/core/rawdb"
2930
"github.com/ethereum/go-ethereum/core/types"
3031
"github.com/ethereum/go-ethereum/core/vm"
3132
"github.com/ethereum/go-ethereum/crypto"
@@ -234,13 +235,15 @@ func makeChainForBench(db ethdb.Database, full bool, count uint64) {
234235
ReceiptHash: types.EmptyRootHash,
235236
}
236237
hash = header.Hash()
237-
WriteHeader(db, header)
238-
WriteCanonicalHash(db, hash, n)
239-
WriteTd(db, hash, n, big.NewInt(int64(n+1)))
238+
239+
rawdb.WriteHeader(db, header)
240+
rawdb.WriteCanonicalHash(db, hash, n)
241+
rawdb.WriteTd(db, hash, n, big.NewInt(int64(n+1)))
242+
240243
if full || n == 0 {
241244
block := types.NewBlockWithHeader(header)
242-
WriteBody(db, hash, n, block.Body())
243-
WriteBlockReceipts(db, hash, n, nil)
245+
rawdb.WriteBody(db, hash, n, block.Body())
246+
rawdb.WriteReceipts(db, hash, n, nil)
244247
}
245248
}
246249
}
@@ -292,11 +295,10 @@ func benchReadChain(b *testing.B, full bool, count uint64) {
292295
header := chain.GetHeaderByNumber(n)
293296
if full {
294297
hash := header.Hash()
295-
GetBody(db, hash, n)
296-
GetBlockReceipts(db, hash, n)
298+
rawdb.ReadBody(db, hash, n)
299+
rawdb.ReadReceipts(db, hash, n)
297300
}
298301
}
299-
300302
chain.Stop()
301303
db.Close()
302304
}

0 commit comments

Comments
 (0)