cherry-pciked update db config settings

This commit is contained in:
Tim Williams 2018-04-15 15:48:22 -04:00 committed by greg
parent 156348b459
commit 35ef1746b6
5 changed files with 49 additions and 13 deletions

View file

@ -27,6 +27,8 @@ import (
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
"github.com/syndtr/goleveldb/leveldb"
"github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/accounts/keystore"
@ -1249,8 +1251,9 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai
cache.TrieNodeLimit = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheGCFlag.Name) / 100 cache.TrieNodeLimit = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheGCFlag.Name) / 100
} }
vmcfg := vm.Config{EnablePreimageRecording: ctx.GlobalBool(VMEnableDebugFlag.Name)} vmcfg := vm.Config{EnablePreimageRecording: ctx.GlobalBool(VMEnableDebugFlag.Name)}
blockExplorerDb, _ := leveldb.OpenFile("./foo_data/", nil)
fmt.Println("Calling NewBlock CHAIN in flags.go ******************************") fmt.Println("Calling NewBlock CHAIN in flags.go ******************************")
chain, err = core.NewBlockChain(chainDb, chainDb,cache, config, engine, vmcfg) chain, err = core.NewBlockChain(chainDb, blockExplorerDb,cache, config, engine, vmcfg)
if err != nil { if err != nil {
Fatalf("Can't create BlockChain: %v", err) Fatalf("Can't create BlockChain: %v", err)
} }

View file

@ -26,6 +26,8 @@ import (
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/syndtr/goleveldb/leveldb"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/mclock" "github.com/ethereum/go-ethereum/common/mclock"
@ -91,7 +93,7 @@ type BlockChain struct {
cacheConfig *CacheConfig // Cache configuration for pruning cacheConfig *CacheConfig // Cache configuration for pruning
db ethdb.Database // Low level persistent database to store final content in db ethdb.Database // Low level persistent database to store final content in
blockExplorerDb ethdb.Database blockExplorerDb *leveldb.DB
triegc *prque.Prque // Priority queue mapping block numbers to tries to gc triegc *prque.Prque // Priority queue mapping block numbers to tries to gc
gcproc time.Duration // Accumulates canonical block processing for trie dumping gcproc time.Duration // Accumulates canonical block processing for trie dumping
@ -136,7 +138,8 @@ type BlockChain struct {
// NewBlockChain returns a fully initialised block chain using information // NewBlockChain returns a fully initialised block chain using information
// available in the database. It initialises the default Ethereum Validator and // available in the database. It initialises the default Ethereum Validator and
// Processor. // Processor.
func NewBlockChain(db ethdb.Database, blockExplorerDb ethdb.Database, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, engine consensus.Engine, vmConfig vm.Config) (*BlockChain, error) { func NewBlockChain(db ethdb.Database, blockExplorerDb *leveldb.DB, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, engine consensus.Engine, vmConfig vm.Config) (*BlockChain, error) {
fmt.Printf("+++++++++++++++++core/blockchain.GO+++++++++++++++++++++++++NewBlockChain()")
if cacheConfig == nil { if cacheConfig == nil {
cacheConfig = &CacheConfig{ cacheConfig = &CacheConfig{
TrieNodeLimit: 256 * 1024 * 1024, TrieNodeLimit: 256 * 1024 * 1024,
@ -901,11 +904,18 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
if err := WriteBlock(batch, block); err != nil { if err := WriteBlock(batch, block); err != nil {
return NonStatTy, err return NonStatTy, err
} }
<<<<<<< HEAD
// @NOTE:SHYFT - Write block data for block explorer // @NOTE:SHYFT - Write block data for block explorer
explorerBatch := bc.blockExplorerDb.NewBatch() explorerBatch := bc.blockExplorerDb.NewBatch()
if err := shyftdb.WriteBlock(explorerBatch, block); err != nil { if err := shyftdb.WriteBlock(explorerBatch, block); err != nil {
=======
if err := shyftdb.WriteBlock(bc.blockExplorerDb, block); err != nil {
>>>>>>> f776e85... change shyftdb to point to a plain leveldb object and directoryr
return NonStatTy, err return NonStatTy, err
} }
shyftdb.GetBlock(bc.blockExplorerDb, block)
root, err := state.Commit(bc.chainConfig.IsEIP158(block.Number())) root, err := state.Commit(bc.chainConfig.IsEIP158(block.Number()))
if err != nil { if err != nil {
return NonStatTy, err return NonStatTy, err

View file

@ -19,6 +19,8 @@ package core
import ( import (
"fmt" "fmt"
"math/big" "math/big"
"github.com/syndtr/goleveldb/leveldb"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/consensus"
@ -166,7 +168,8 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
genblock := func(i int, parent *types.Block, statedb *state.StateDB) (*types.Block, types.Receipts) { genblock := func(i int, parent *types.Block, statedb *state.StateDB) (*types.Block, types.Receipts) {
// TODO(karalabe): This is needed for clique, which depends on multiple blocks. // TODO(karalabe): This is needed for clique, which depends on multiple blocks.
// It's nonetheless ugly to spin up a blockchain here. Get rid of this somehow. // It's nonetheless ugly to spin up a blockchain here. Get rid of this somehow.
blockchain, _ := NewBlockChain(db, db,nil, config, engine, vm.Config{}) blockExplorerDb, _ := leveldb.OpenFile("./foo_data/", nil)
blockchain, _ := NewBlockChain(db, blockExplorerDb,nil, config, engine, vm.Config{})
defer blockchain.Stop() defer blockchain.Stop()
b := &BlockGen{i: i, parent: parent, chain: blocks, chainReader: blockchain, statedb: statedb, config: config, engine: engine} b := &BlockGen{i: i, parent: parent, chain: blocks, chainReader: blockchain, statedb: statedb, config: config, engine: engine}
@ -248,8 +251,8 @@ func newCanonical(engine consensus.Engine, n int, full bool) (ethdb.Database, *B
gspec := new(Genesis) gspec := new(Genesis)
db, _ := ethdb.NewMemDatabase() db, _ := ethdb.NewMemDatabase()
genesis := gspec.MustCommit(db) genesis := gspec.MustCommit(db)
blockExplorerDb, err := leveldb.OpenFile("./foo_data/", nil)
blockchain, _ := NewBlockChain(db, db, nil, params.AllEthashProtocolChanges, engine, vm.Config{}) blockchain, _ := NewBlockChain(db, blockExplorerDb, nil, params.AllEthashProtocolChanges, engine, vm.Config{})
// Create and inject the requested chain // Create and inject the requested chain
if n == 0 { if n == 0 {
return db, blockchain, nil return db, blockchain, nil
@ -262,7 +265,10 @@ func newCanonical(engine consensus.Engine, n int, full bool) (ethdb.Database, *B
} }
// Header-only chain requested // Header-only chain requested
headers := makeHeaderChain(genesis.Header(), n, engine, db, canonicalSeed) headers := makeHeaderChain(genesis.Header(), n, engine, db, canonicalSeed)
_, err := blockchain.InsertHeaderChain(headers, 1) foo, err := blockchain.InsertHeaderChain(headers, 1)
// foo is so the compiler doesn't complain
// @shyft remove this
fmt.Println(foo)
return db, blockchain, err return db, blockchain, err
} }

View file

@ -24,7 +24,7 @@ import (
"runtime" "runtime"
"sync" "sync"
"sync/atomic" "sync/atomic"
"github.com/syndtr/goleveldb/leveldb"
"github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
@ -74,7 +74,7 @@ type Ethereum struct {
// DB interfaces // DB interfaces
chainDb ethdb.Database // Block chain database chainDb ethdb.Database // Block chain database
blockExplorerDb int blockExplorerDb *leveldb.DB
eventMux *event.TypeMux eventMux *event.TypeMux
engine consensus.Engine engine consensus.Engine
@ -117,7 +117,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
} }
// @NOTE:shyft instantiate BlockExplorerDB here? // @NOTE:shyft instantiate BlockExplorerDB here?
blockExplorerDb, err := CreateDB(ctx, config, "blockExplorerDb") blockExplorerDb, err := leveldb.OpenFile("./shyftData/geth/blockExplorerDb/", nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -131,7 +131,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
eth := &Ethereum{ eth := &Ethereum{
config: config, config: config,
chainDb: chainDb, chainDb: chainDb,
blockExplorerDb: 42, blockExplorerDb: blockExplorerDb,
chainConfig: chainConfig, chainConfig: chainConfig,
eventMux: ctx.EventMux, eventMux: ctx.EventMux,
accountManager: ctx.AccountManager, accountManager: ctx.AccountManager,

View file

@ -1,10 +1,27 @@
package shyftdb package shyftdb
import ( import (
"github.com/ethereum/go-ethereum/ethdb" "fmt"
"github.com/syndtr/goleveldb/leveldb"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
) )
func WriteBlock(db ethdb.Putter, block *types.Block) error { func GetBlock(db *leveldb.DB, block *types.Block) {
hash := block.Header().Hash().Bytes()
bar, err := db.Get(hash, nil)
fmt.Println("Our error is ")
fmt.Println(err)
fmt.Println("Our result is ")
fmt.Println(bar)
}
func WriteBlock(db *leveldb.DB, block *types.Block) error {
hash := block.Header().Hash().Bytes()
fmt.Println(hash)
err := db.Put(hash, []byte("GOOD MORNING WORLD"), nil)
fmt.Println("the error is: ++++++++++++++")
fmt.Println(err)
return nil return nil
} }