aboutsummaryrefslogtreecommitdiffstats
path: root/les
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2018-09-24 20:57:49 +0800
committerPéter Szilágyi <peterke@gmail.com>2019-03-06 19:35:03 +0800
commit054412e33528e53f6deae940c870217b614707b9 (patch)
tree7ffc999bb39384e1bfa8c71d80923879fc2e866b /les
parent15eee47ebf878b4eff3c2359b9eaa57bba397448 (diff)
downloadgo-tangerine-054412e33528e53f6deae940c870217b614707b9.tar
go-tangerine-054412e33528e53f6deae940c870217b614707b9.tar.gz
go-tangerine-054412e33528e53f6deae940c870217b614707b9.tar.bz2
go-tangerine-054412e33528e53f6deae940c870217b614707b9.tar.lz
go-tangerine-054412e33528e53f6deae940c870217b614707b9.tar.xz
go-tangerine-054412e33528e53f6deae940c870217b614707b9.tar.zst
go-tangerine-054412e33528e53f6deae940c870217b614707b9.zip
all: clean up and proerly abstract database access
Diffstat (limited to 'les')
-rw-r--r--les/backend.go2
-rw-r--r--les/freeclient_test.go4
-rw-r--r--les/handler.go4
-rw-r--r--les/handler_test.go9
-rw-r--r--les/helper_test.go5
-rw-r--r--les/odr_requests.go2
-rw-r--r--les/ulc_test.go14
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)