diff options
author | Péter Szilágyi <peterke@gmail.com> | 2019-03-07 16:21:40 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-07 16:21:40 +0800 |
commit | 72b21db2d31d77d956c09353457a0c2db45249b0 (patch) | |
tree | c0c750bfbbc5b5d8e9622847b676c1f4d99f4020 /les | |
parent | f2d63103541ee3746ff0834e7c69d188af3572d2 (diff) | |
parent | 054412e33528e53f6deae940c870217b614707b9 (diff) | |
download | go-tangerine-72b21db2d31d77d956c09353457a0c2db45249b0.tar go-tangerine-72b21db2d31d77d956c09353457a0c2db45249b0.tar.gz go-tangerine-72b21db2d31d77d956c09353457a0c2db45249b0.tar.bz2 go-tangerine-72b21db2d31d77d956c09353457a0c2db45249b0.tar.lz go-tangerine-72b21db2d31d77d956c09353457a0c2db45249b0.tar.xz go-tangerine-72b21db2d31d77d956c09353457a0c2db45249b0.tar.zst go-tangerine-72b21db2d31d77d956c09353457a0c2db45249b0.zip |
Merge pull request #19021 from karalabe/database-cleanup
all: clean up and properly abstract database accesses
Diffstat (limited to 'les')
-rw-r--r-- | les/backend.go | 2 | ||||
-rw-r--r-- | les/freeclient_test.go | 4 | ||||
-rw-r--r-- | les/handler.go | 4 | ||||
-rw-r--r-- | les/handler_test.go | 9 | ||||
-rw-r--r-- | les/helper_test.go | 5 | ||||
-rw-r--r-- | les/odr_requests.go | 2 | ||||
-rw-r--r-- | les/ulc_test.go | 14 |
7 files changed, 19 insertions, 21 deletions
diff --git a/les/backend.go b/les/backend.go index 67ddf17e4..bc4d0f21d 100644 --- a/les/backend.go +++ b/les/backend.go @@ -79,7 +79,7 @@ type LightEthereum struct { } func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) { - chainDb, err := eth.CreateDB(ctx, config, "lightchaindata") + chainDb, err := ctx.OpenDatabase("lightchaindata", config.DatabaseCache, config.DatabaseHandles, "eth/db/chaindata/") if err != nil { return nil, err } diff --git a/les/freeclient_test.go b/les/freeclient_test.go index dc8b51a8d..191822264 100644 --- a/les/freeclient_test.go +++ b/les/freeclient_test.go @@ -24,7 +24,7 @@ import ( "time" "github.com/ethereum/go-ethereum/common/mclock" - "github.com/ethereum/go-ethereum/ethdb" + "github.com/ethereum/go-ethereum/core/rawdb" ) func TestFreeClientPoolL10C100(t *testing.T) { @@ -44,7 +44,7 @@ const testFreeClientPoolTicks = 500000 func testFreeClientPool(t *testing.T, connLimit, clientCount int) { var ( clock mclock.Simulated - db = ethdb.NewMemDatabase() + db = rawdb.NewMemoryDatabase() connected = make([]bool, clientCount) connTicks = make([]int, clientCount) disconnCh = make(chan int, clientCount) diff --git a/les/handler.go b/les/handler.go index 0352f5b03..9efe7d9e1 100644 --- a/les/handler.go +++ b/les/handler.go @@ -938,7 +938,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { return errResp(ErrRequestRejected, "") } go func() { - trieDb := trie.NewDatabase(ethdb.NewTable(pm.chainDb, light.ChtTablePrefix)) + trieDb := trie.NewDatabase(rawdb.NewTable(pm.chainDb, light.ChtTablePrefix)) for i, req := range req.Reqs { if i != 0 && !task.waitOrStop() { return @@ -1003,7 +1003,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { var prefix string if root, prefix = pm.getHelperTrie(req.Type, req.TrieIdx); root != (common.Hash{}) { - auxTrie, _ = trie.New(root, trie.NewDatabase(ethdb.NewTable(pm.chainDb, prefix))) + auxTrie, _ = trie.New(root, trie.NewDatabase(rawdb.NewTable(pm.chainDb, prefix))) } } if req.AuxReq == auxRoot { diff --git a/les/handler_test.go b/les/handler_test.go index e9033729e..5cf31b8f5 100644 --- a/les/handler_test.go +++ b/les/handler_test.go @@ -30,7 +30,6 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/eth/downloader" - "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/light" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/params" @@ -405,7 +404,7 @@ func testGetCHTProofs(t *testing.T, protocol int) { switch protocol { case 1: root := light.GetChtRoot(server.db, 0, bc.GetHeaderByNumber(frequency-1).Hash()) - trie, _ := trie.New(root, trie.NewDatabase(ethdb.NewTable(server.db, light.ChtTablePrefix))) + trie, _ := trie.New(root, trie.NewDatabase(rawdb.NewTable(server.db, light.ChtTablePrefix))) var proof light.NodeList trie.Prove(key, 0, &proof) @@ -413,7 +412,7 @@ func testGetCHTProofs(t *testing.T, protocol int) { case 2: root := light.GetChtRoot(server.db, (frequency/config.ChtSize)-1, bc.GetHeaderByNumber(frequency-1).Hash()) - trie, _ := trie.New(root, trie.NewDatabase(ethdb.NewTable(server.db, light.ChtTablePrefix))) + trie, _ := trie.New(root, trie.NewDatabase(rawdb.NewTable(server.db, light.ChtTablePrefix))) trie.Prove(key, 0, &proofsV2.Proofs) } // Assemble the requests for the different protocols @@ -480,7 +479,7 @@ func TestGetBloombitsProofs(t *testing.T) { var proofs HelperTrieResps root := light.GetBloomTrieRoot(server.db, 0, bc.GetHeaderByNumber(config.BloomTrieSize-1).Hash()) - trie, _ := trie.New(root, trie.NewDatabase(ethdb.NewTable(server.db, light.BloomTrieTablePrefix))) + trie, _ := trie.New(root, trie.NewDatabase(rawdb.NewTable(server.db, light.BloomTrieTablePrefix))) trie.Prove(key, 0, &proofs.Proofs) // Send the proof request and verify the response @@ -493,7 +492,7 @@ func TestGetBloombitsProofs(t *testing.T) { } func TestTransactionStatusLes2(t *testing.T) { - db := ethdb.NewMemDatabase() + db := rawdb.NewMemoryDatabase() pm := newTestProtocolManagerMust(t, false, 0, nil, nil, nil, db, nil) chain := pm.blockchain.(*core.BlockChain) config := core.DefaultTxPoolConfig diff --git a/les/helper_test.go b/les/helper_test.go index a8097708e..020c69e17 100644 --- a/les/helper_test.go +++ b/les/helper_test.go @@ -30,6 +30,7 @@ import ( "github.com/ethereum/go-ethereum/common/mclock" "github.com/ethereum/go-ethereum/consensus/ethash" "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/crypto" @@ -331,7 +332,7 @@ type TestEntity struct { // newServerEnv creates a server testing environment with a connected test peer for testing purpose. func newServerEnv(t *testing.T, blocks int, protocol int, waitIndexers func(*core.ChainIndexer, *core.ChainIndexer, *core.ChainIndexer)) (*TestEntity, func()) { - db := ethdb.NewMemDatabase() + db := rawdb.NewMemoryDatabase() cIndexer, bIndexer, btIndexer := testIndexers(db, nil, light.TestServerIndexerConfig) pm := newTestProtocolManagerMust(t, false, blocks, testChainGen, nil, nil, db, nil) @@ -363,7 +364,7 @@ func newServerEnv(t *testing.T, blocks int, protocol int, waitIndexers func(*cor // newClientServerEnv creates a client/server arch environment with a connected les server and light client pair // for testing purpose. func newClientServerEnv(t *testing.T, blocks int, protocol int, waitIndexers func(*core.ChainIndexer, *core.ChainIndexer, *core.ChainIndexer), newPeer bool) (*TestEntity, *TestEntity, func()) { - db, ldb := ethdb.NewMemDatabase(), ethdb.NewMemDatabase() + db, ldb := rawdb.NewMemoryDatabase(), rawdb.NewMemoryDatabase() peers, lPeers := newPeerSet(), newPeerSet() dist := newRequestDistributor(lPeers, make(chan struct{}), &mclock.System{}) diff --git a/les/odr_requests.go b/les/odr_requests.go index 7b7876762..6bd4a2931 100644 --- a/les/odr_requests.go +++ b/les/odr_requests.go @@ -558,7 +558,7 @@ func (r *BloomRequest) Validate(db ethdb.Database, msg *Msg) error { // readTraceDB stores the keys of database reads. We use this to check that received node // sets contain only the trie nodes necessary to make proofs pass. type readTraceDB struct { - db trie.DatabaseReader + db ethdb.Reader reads map[string]struct{} } diff --git a/les/ulc_test.go b/les/ulc_test.go index 69ea62059..81986fa1e 100644 --- a/les/ulc_test.go +++ b/les/ulc_test.go @@ -1,21 +1,19 @@ package les import ( + "crypto/ecdsa" "fmt" + "math/big" + "net" "reflect" "testing" "time" - "net" - - "crypto/ecdsa" - "math/big" - "github.com/ethereum/go-ethereum/common/mclock" "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/eth" - "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/light" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/enode" @@ -198,7 +196,7 @@ func connectPeers(full, light pairPeer, version int) (*peer, *peer, error) { // newFullPeerPair creates node with full sync mode func newFullPeerPair(t *testing.T, index int, numberOfblocks int, chainGen func(int, *core.BlockGen)) pairPeer { - db := ethdb.NewMemDatabase() + db := rawdb.NewMemoryDatabase() pmFull := newTestProtocolManagerMust(t, false, numberOfblocks, chainGen, nil, nil, db, nil) @@ -220,7 +218,7 @@ func newLightPeer(t *testing.T, ulcConfig *eth.ULCConfig) pairPeer { peers := newPeerSet() dist := newRequestDistributor(peers, make(chan struct{}), &mclock.System{}) rm := newRetrieveManager(peers, dist, nil) - ldb := ethdb.NewMemDatabase() + ldb := rawdb.NewMemoryDatabase() odr := NewLesOdr(ldb, light.DefaultClientIndexerConfig, rm) |