Skip to content

Commit 985b5f2

Browse files
committed
Merge pull request #1801 from fjl/ethdb
all: move common.Database to ethdb and add NewBatch
2 parents 1cc2f08 + b252589 commit 985b5f2

26 files changed

+142
-125
lines changed

cmd/geth/blocktestcmd.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
"github.com/codegangsta/cli"
2424
"github.com/ethereum/go-ethereum/cmd/utils"
25-
"github.com/ethereum/go-ethereum/common"
2625
"github.com/ethereum/go-ethereum/eth"
2726
"github.com/ethereum/go-ethereum/ethdb"
2827
"github.com/ethereum/go-ethereum/tests"
@@ -103,7 +102,7 @@ func runBlockTest(ctx *cli.Context) {
103102

104103
func runOneBlockTest(ctx *cli.Context, test *tests.BlockTest) (*eth.Ethereum, error) {
105104
cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx)
106-
cfg.NewDB = func(path string) (common.Database, error) { return ethdb.NewMemDatabase() }
105+
cfg.NewDB = func(path string) (ethdb.Database, error) { return ethdb.NewMemDatabase() }
107106
cfg.MaxPeers = 0 // disable network
108107
cfg.Shh = false // disable whisper
109108
cfg.NAT = nil // disable port mapping

cmd/geth/chaincmd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/ethereum/go-ethereum/core"
3030
"github.com/ethereum/go-ethereum/core/state"
3131
"github.com/ethereum/go-ethereum/core/types"
32+
"github.com/ethereum/go-ethereum/ethdb"
3233
"github.com/ethereum/go-ethereum/logger/glog"
3334
)
3435

@@ -191,7 +192,7 @@ func hashish(x string) bool {
191192
return err != nil
192193
}
193194

194-
func closeAll(dbs ...common.Database) {
195+
func closeAll(dbs ...ethdb.Database) {
195196
for _, db := range dbs {
196197
db.Close()
197198
}

cmd/geth/js_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func testREPL(t *testing.T, config func(*eth.Config)) (string, *testjethre, *eth
103103
Name: "test",
104104
SolcPath: testSolcPath,
105105
PowTest: true,
106-
NewDB: func(path string) (common.Database, error) { return db, nil },
106+
NewDB: func(path string) (ethdb.Database, error) { return db, nil },
107107
}
108108
if config != nil {
109109
config(conf)

cmd/utils/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ func SetupEth(ctx *cli.Context) {
508508
}
509509

510510
// MakeChain creates a chain manager from set command line flags.
511-
func MakeChain(ctx *cli.Context) (chain *core.ChainManager, chainDb common.Database) {
511+
func MakeChain(ctx *cli.Context) (chain *core.ChainManager, chainDb ethdb.Database) {
512512
datadir := ctx.GlobalString(DataDirFlag.Name)
513513
cache := ctx.GlobalInt(CacheFlag.Name)
514514

common/natspec/natspec_e2e_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func testEth(t *testing.T) (ethereum *eth.Ethereum, err error) {
143143
MaxPeers: 0,
144144
PowTest: true,
145145
Etherbase: common.HexToAddress(testAddress),
146-
NewDB: func(path string) (common.Database, error) { return db, nil },
146+
NewDB: func(path string) (ethdb.Database, error) { return db, nil },
147147
})
148148

149149
if err != nil {

core/bench_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func genUncles(i int, gen *BlockGen) {
144144

145145
func benchInsertChain(b *testing.B, disk bool, gen func(int, *BlockGen)) {
146146
// Create the database in memory or in a temporary directory.
147-
var db common.Database
147+
var db ethdb.Database
148148
if !disk {
149149
db, _ = ethdb.NewMemDatabase()
150150
} else {

core/block_processor.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/ethereum/go-ethereum/core/state"
2727
"github.com/ethereum/go-ethereum/core/types"
2828
"github.com/ethereum/go-ethereum/crypto"
29+
"github.com/ethereum/go-ethereum/ethdb"
2930
"github.com/ethereum/go-ethereum/event"
3031
"github.com/ethereum/go-ethereum/logger"
3132
"github.com/ethereum/go-ethereum/logger/glog"
@@ -41,7 +42,7 @@ const (
4142
)
4243

4344
type BlockProcessor struct {
44-
chainDb common.Database
45+
chainDb ethdb.Database
4546
// Mutex for locking the block processor. Blocks can only be handled one at a time
4647
mutex sync.Mutex
4748
// Canonical block chain
@@ -68,7 +69,7 @@ type GasPool interface {
6869
SubGas(gas, price *big.Int) error
6970
}
7071

71-
func NewBlockProcessor(db common.Database, pow pow.PoW, chainManager *ChainManager, eventMux *event.TypeMux) *BlockProcessor {
72+
func NewBlockProcessor(db ethdb.Database, pow pow.PoW, chainManager *ChainManager, eventMux *event.TypeMux) *BlockProcessor {
7273
sm := &BlockProcessor{
7374
chainDb: db,
7475
mem: make(map[string]*big.Int),

core/chain_makers.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/ethereum/go-ethereum/common"
2323
"github.com/ethereum/go-ethereum/core/state"
2424
"github.com/ethereum/go-ethereum/core/types"
25+
"github.com/ethereum/go-ethereum/ethdb"
2526
"github.com/ethereum/go-ethereum/event"
2627
"github.com/ethereum/go-ethereum/pow"
2728
)
@@ -142,7 +143,7 @@ func (b *BlockGen) PrevBlock(index int) *types.Block {
142143
// Blocks created by GenerateChain do not contain valid proof of work
143144
// values. Inserting them into ChainManager requires use of FakePow or
144145
// a similar non-validating proof of work implementation.
145-
func GenerateChain(parent *types.Block, db common.Database, n int, gen func(int, *BlockGen)) []*types.Block {
146+
func GenerateChain(parent *types.Block, db ethdb.Database, n int, gen func(int, *BlockGen)) []*types.Block {
146147
statedb := state.New(parent.Root(), db)
147148
blocks := make(types.Blocks, n)
148149
genblock := func(i int, h *types.Header) *types.Block {
@@ -185,7 +186,7 @@ func makeHeader(parent *types.Block, state *state.StateDB) *types.Header {
185186

186187
// newCanonical creates a new deterministic canonical chain by running
187188
// InsertChain on the result of makeChain.
188-
func newCanonical(n int, db common.Database) (*BlockProcessor, error) {
189+
func newCanonical(n int, db ethdb.Database) (*BlockProcessor, error) {
189190
evmux := &event.TypeMux{}
190191

191192
WriteTestNetGenesisBlock(db, 0)
@@ -201,7 +202,7 @@ func newCanonical(n int, db common.Database) (*BlockProcessor, error) {
201202
return bman, err
202203
}
203204

204-
func makeChain(parent *types.Block, n int, db common.Database, seed int) []*types.Block {
205+
func makeChain(parent *types.Block, n int, db ethdb.Database, seed int) []*types.Block {
205206
return GenerateChain(parent, db, n, func(i int, b *BlockGen) {
206207
b.SetCoinbase(common.Address{0: byte(seed), 19: byte(i)})
207208
})

core/chain_manager.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/ethereum/go-ethereum/common"
3131
"github.com/ethereum/go-ethereum/core/state"
3232
"github.com/ethereum/go-ethereum/core/types"
33+
"github.com/ethereum/go-ethereum/ethdb"
3334
"github.com/ethereum/go-ethereum/event"
3435
"github.com/ethereum/go-ethereum/logger"
3536
"github.com/ethereum/go-ethereum/logger/glog"
@@ -60,7 +61,7 @@ const (
6061

6162
type ChainManager struct {
6263
//eth EthManager
63-
chainDb common.Database
64+
chainDb ethdb.Database
6465
processor types.BlockProcessor
6566
eventMux *event.TypeMux
6667
genesisBlock *types.Block
@@ -90,7 +91,7 @@ type ChainManager struct {
9091
pow pow.PoW
9192
}
9293

93-
func NewChainManager(chainDb common.Database, pow pow.PoW, mux *event.TypeMux) (*ChainManager, error) {
94+
func NewChainManager(chainDb ethdb.Database, pow pow.PoW, mux *event.TypeMux) (*ChainManager, error) {
9495
headerCache, _ := lru.New(headerCacheLimit)
9596
bodyCache, _ := lru.New(bodyCacheLimit)
9697
bodyRLPCache, _ := lru.New(bodyCacheLimit)

core/chain_manager_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func thePow() pow.PoW {
4646
return pow
4747
}
4848

49-
func theChainManager(db common.Database, t *testing.T) *ChainManager {
49+
func theChainManager(db ethdb.Database, t *testing.T) *ChainManager {
5050
var eventMux event.TypeMux
5151
WriteTestNetGenesisBlock(db, 0)
5252
chainMan, err := NewChainManager(db, thePow(), &eventMux)
@@ -380,7 +380,7 @@ func makeChainWithDiff(genesis *types.Block, d []int, seed byte) []*types.Block
380380
return chain
381381
}
382382

383-
func chm(genesis *types.Block, db common.Database) *ChainManager {
383+
func chm(genesis *types.Block, db ethdb.Database) *ChainManager {
384384
var eventMux event.TypeMux
385385
bc := &ChainManager{chainDb: db, genesisBlock: genesis, eventMux: &eventMux, pow: FakePow{}}
386386
bc.headerCache, _ = lru.New(100)

0 commit comments

Comments
 (0)