diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index bc43a3d705..a230ed1e4c 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -27,6 +27,8 @@ import ( "runtime" "strconv" "strings" + + "github.com/syndtr/goleveldb/leveldb" "github.com/ethereum/go-ethereum/accounts" "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 } vmcfg := vm.Config{EnablePreimageRecording: ctx.GlobalBool(VMEnableDebugFlag.Name)} + blockExplorerDb, _ := leveldb.OpenFile("./foo_data/", nil) 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 { Fatalf("Can't create BlockChain: %v", err) } diff --git a/core/blockchain.go b/core/blockchain.go index caed887cde..18d0c101a1 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -26,6 +26,8 @@ import ( "sync" "sync/atomic" "time" + + "github.com/syndtr/goleveldb/leveldb" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/mclock" @@ -91,7 +93,7 @@ type BlockChain struct { cacheConfig *CacheConfig // Cache configuration for pruning 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 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 // available in the database. It initialises the default Ethereum Validator and // 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 { cacheConfig = &CacheConfig{ TrieNodeLimit: 256 * 1024 * 1024, @@ -901,11 +904,18 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types. if err := WriteBlock(batch, block); err != nil { return NonStatTy, err } +<<<<<<< HEAD // @NOTE:SHYFT - Write block data for block explorer explorerBatch := bc.blockExplorerDb.NewBatch() 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 } + shyftdb.GetBlock(bc.blockExplorerDb, block) + root, err := state.Commit(bc.chainConfig.IsEIP158(block.Number())) if err != nil { return NonStatTy, err diff --git a/core/chain_makers.go b/core/chain_makers.go index 06e6849871..bd6ba265ba 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -19,6 +19,8 @@ package core import ( "fmt" "math/big" + + "github.com/syndtr/goleveldb/leveldb" "github.com/ethereum/go-ethereum/common" "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) { // 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. - 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() 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) db, _ := ethdb.NewMemDatabase() genesis := gspec.MustCommit(db) - - blockchain, _ := NewBlockChain(db, db, nil, params.AllEthashProtocolChanges, engine, vm.Config{}) + blockExplorerDb, err := leveldb.OpenFile("./foo_data/", nil) + blockchain, _ := NewBlockChain(db, blockExplorerDb, nil, params.AllEthashProtocolChanges, engine, vm.Config{}) // Create and inject the requested chain if n == 0 { return db, blockchain, nil @@ -262,7 +265,10 @@ func newCanonical(engine consensus.Engine, n int, full bool) (ethdb.Database, *B } // Header-only chain requested 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 } diff --git a/eth/backend.go b/eth/backend.go index d02b970264..f0f77dcb7c 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -24,7 +24,7 @@ import ( "runtime" "sync" "sync/atomic" - + "github.com/syndtr/goleveldb/leveldb" "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" @@ -74,7 +74,7 @@ type Ethereum struct { // DB interfaces chainDb ethdb.Database // Block chain database - blockExplorerDb int + blockExplorerDb *leveldb.DB eventMux *event.TypeMux engine consensus.Engine @@ -117,7 +117,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { } // @NOTE:shyft instantiate BlockExplorerDB here? - blockExplorerDb, err := CreateDB(ctx, config, "blockExplorerDb") + blockExplorerDb, err := leveldb.OpenFile("./shyftData/geth/blockExplorerDb/", nil) if err != nil { return nil, err } @@ -131,7 +131,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { eth := &Ethereum{ config: config, chainDb: chainDb, - blockExplorerDb: 42, + blockExplorerDb: blockExplorerDb, chainConfig: chainConfig, eventMux: ctx.EventMux, accountManager: ctx.AccountManager, diff --git a/shyftdb/shyft_database_util.go b/shyftdb/shyft_database_util.go index 71c2b22779..470531259e 100644 --- a/shyftdb/shyft_database_util.go +++ b/shyftdb/shyft_database_util.go @@ -1,10 +1,27 @@ package shyftdb import ( - "github.com/ethereum/go-ethereum/ethdb" + "fmt" + + "github.com/syndtr/goleveldb/leveldb" "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 } \ No newline at end of file