Skip to content

Commit

Permalink
core/rawdb: separate raw database access to own package (ethereum#16666)
Browse files Browse the repository at this point in the history
  • Loading branch information
karalabe authored and kimmyeonghun committed Jul 4, 2018
1 parent f97998f commit c03f833
Show file tree
Hide file tree
Showing 50 changed files with 1,289 additions and 509 deletions.
15 changes: 12 additions & 3 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/ethersocial/go-esn/consensus/ethash"
"github.com/ethersocial/go-esn/core"
"github.com/ethersocial/go-esn/core/bloombits"
"github.com/ethersocial/go-esn/core/rawdb"
"github.com/ethersocial/go-esn/core/state"
"github.com/ethersocial/go-esn/core/types"
"github.com/ethersocial/go-esn/core/vm"
Expand Down Expand Up @@ -159,7 +160,7 @@ func (b *SimulatedBackend) StorageAt(ctx context.Context, contract common.Addres

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

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

func (fb *filterBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
return core.GetBlockReceipts(fb.db, hash, core.GetBlockNumber(fb.db, hash)), nil
number := rawdb.ReadHeaderNumber(fb.db, hash)
if number == nil {
return nil, nil
}
return rawdb.ReadReceipts(fb.db, hash, *number), nil
}

func (fb *filterBackend) GetLogs(ctx context.Context, hash common.Hash) ([][]*types.Log, error) {
receipts := core.GetBlockReceipts(fb.db, hash, core.GetBlockNumber(fb.db, hash))
number := rawdb.ReadHeaderNumber(fb.db, hash)
if number == nil {
return nil, nil
}
receipts := rawdb.ReadReceipts(fb.db, hash, *number)
if receipts == nil {
return nil, nil
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/gesn/dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"testing"

"github.com/ethersocial/go-esn/common"
"github.com/ethersocial/go-esn/core"
"github.com/ethersocial/go-esn/core/rawdb"
"github.com/ethersocial/go-esn/ethdb"
"github.com/ethersocial/go-esn/params"
)
Expand Down Expand Up @@ -131,8 +131,8 @@ func testDAOForkBlockNewChain(t *testing.T, test int, genesis string, expectBloc
if genesis != "" {
genesisHash = daoGenesisHash
}
config, err := core.GetChainConfig(db, genesisHash)
if err != nil {
config := rawdb.ReadChainConfig(db, genesisHash)
if config == nil {
t.Errorf("test %d: failed to retrieve chain config: %v", test, err)
return // we want to return here, the other checks can't make it past this point (nil panic).
}
Expand Down
7 changes: 3 additions & 4 deletions cmd/utils/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

"github.com/ethersocial/go-esn/common"
"github.com/ethersocial/go-esn/core"
"github.com/ethersocial/go-esn/core/rawdb"
"github.com/ethersocial/go-esn/core/types"
"github.com/ethersocial/go-esn/crypto"
"github.com/ethersocial/go-esn/ethdb"
Expand Down Expand Up @@ -271,15 +272,13 @@ func ImportPreimages(db *ethdb.LDBDatabase, fn string) error {
// Accumulate the preimages and flush when enough ws gathered
preimages[crypto.Keccak256Hash(blob)] = common.CopyBytes(blob)
if len(preimages) > 1024 {
if err := core.WritePreimages(db, 0, preimages); err != nil {
return err
}
rawdb.WritePreimages(db, 0, preimages)
preimages = make(map[common.Hash][]byte)
}
}
// Flush the last batch preimage data
if len(preimages) > 0 {
return core.WritePreimages(db, 0, preimages)
rawdb.WritePreimages(db, 0, preimages)
}
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion consensus/clique/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/ethersocial/go-esn/common"
"github.com/ethersocial/go-esn/core"
"github.com/ethersocial/go-esn/core/rawdb"
"github.com/ethersocial/go-esn/core/types"
"github.com/ethersocial/go-esn/crypto"
"github.com/ethersocial/go-esn/ethdb"
Expand Down Expand Up @@ -81,7 +82,7 @@ func (r *testerChainReader) GetBlock(common.Hash, uint64) *types.Block { panic
func (r *testerChainReader) GetHeaderByHash(common.Hash) *types.Header { panic("not supported") }
func (r *testerChainReader) GetHeaderByNumber(number uint64) *types.Header {
if number == 0 {
return core.GetHeader(r.db, core.GetCanonicalHash(r.db, 0), 0)
return rawdb.ReadHeader(r.db, rawdb.ReadCanonicalHash(r.db, 0), 0)
}
panic("not supported")
}
Expand Down
18 changes: 10 additions & 8 deletions core/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/ethersocial/go-esn/common"
"github.com/ethersocial/go-esn/common/math"
"github.com/ethersocial/go-esn/consensus/ethash"
"github.com/ethersocial/go-esn/core/rawdb"
"github.com/ethersocial/go-esn/core/types"
"github.com/ethersocial/go-esn/core/vm"
"github.com/ethersocial/go-esn/crypto"
Expand Down Expand Up @@ -234,13 +235,15 @@ func makeChainForBench(db ethdb.Database, full bool, count uint64) {
ReceiptHash: types.EmptyRootHash,
}
hash = header.Hash()
WriteHeader(db, header)
WriteCanonicalHash(db, hash, n)
WriteTd(db, hash, n, big.NewInt(int64(n+1)))

rawdb.WriteHeader(db, header)
rawdb.WriteCanonicalHash(db, hash, n)
rawdb.WriteTd(db, hash, n, big.NewInt(int64(n+1)))

if full || n == 0 {
block := types.NewBlockWithHeader(header)
WriteBody(db, hash, n, block.Body())
WriteBlockReceipts(db, hash, n, nil)
rawdb.WriteBody(db, hash, n, block.Body())
rawdb.WriteReceipts(db, hash, n, nil)
}
}
}
Expand Down Expand Up @@ -292,11 +295,10 @@ func benchReadChain(b *testing.B, full bool, count uint64) {
header := chain.GetHeaderByNumber(n)
if full {
hash := header.Hash()
GetBody(db, hash, n)
GetBlockReceipts(db, hash, n)
rawdb.ReadBody(db, hash, n)
rawdb.ReadReceipts(db, hash, n)
}
}

chain.Stop()
db.Close()
}
Expand Down
Loading

0 comments on commit c03f833

Please sign in to comment.