succesful merge

This commit is contained in:
greg 2018-04-19 12:33:47 -04:00
commit 4584f0732b
9 changed files with 102 additions and 34 deletions

View file

@ -28,8 +28,6 @@ import (
"strconv"
"strings"
"github.com/syndtr/goleveldb/leveldb"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
@ -59,6 +57,9 @@ import (
"github.com/ethereum/go-ethereum/params"
whisper "github.com/ethereum/go-ethereum/whisper/whisperv5"
"gopkg.in/urfave/cli.v1"
// @shyft
"database/sql"
)
var (
@ -1250,7 +1251,13 @@ 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)
// @NOTE:shyft instantiate BlockExplorerDB here?
connStr := "user=postgres dbname=shyftdb sslmode=disable"
blockExplorerDb, err := sql.Open("postgres", connStr)
if err != nil {
return nil, nil
}
fmt.Println("Calling NewBlock CHAIN in flags.go ******************************")
chain, err = core.NewBlockChain(chainDb, blockExplorerDb,cache, config, engine, vmcfg)
if err != nil {

View file

@ -29,8 +29,6 @@ import (
"sync/atomic"
"time"
"github.com/syndtr/goleveldb/leveldb"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/mclock"
"github.com/ethereum/go-ethereum/consensus"
@ -48,6 +46,9 @@ import (
"github.com/ethereum/go-ethereum/trie"
"github.com/hashicorp/golang-lru"
"gopkg.in/karalabe/cookiejar.v2/collections/prque"
// @shyft
"database/sql"
)
var (
@ -95,7 +96,7 @@ type BlockChain struct {
cacheConfig *CacheConfig // Cache configuration for pruning
db ethdb.Database // Low level persistent database to store final content in
blockExplorerDb *leveldb.DB
blockExplorerDb *sql.DB
triegc *prque.Prque // Priority queue mapping block numbers to tries to gc
gcproc time.Duration // Accumulates canonical block processing for trie dumping
@ -140,7 +141,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 *leveldb.DB, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, engine consensus.Engine, vmConfig vm.Config) (*BlockChain, error) {
func NewBlockChain(db ethdb.Database, blockExplorerDb *sql.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,

View file

@ -20,8 +20,6 @@ import (
"fmt"
"math/big"
"github.com/syndtr/goleveldb/leveldb"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/misc"
@ -30,6 +28,9 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/params"
// @shyft
"database/sql"
)
// So we can deterministically seed different blockchains
@ -168,7 +169,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.
blockExplorerDb, _ := leveldb.OpenFile("./foo_data/", nil)
connStr := "user=postgres dbname=shyftdb sslmode=disable"
blockExplorerDb, _ := sql.Open("postgres", connStr)
blockchain, _ := NewBlockChain(db, blockExplorerDb,nil, config, engine, vm.Config{})
defer blockchain.Stop()
@ -251,7 +253,8 @@ func newCanonical(engine consensus.Engine, n int, full bool) (ethdb.Database, *B
gspec := new(Genesis)
db, _ := ethdb.NewMemDatabase()
genesis := gspec.MustCommit(db)
blockExplorerDb, err := leveldb.OpenFile("./foo_data/", nil)
connStr := "user=postgres dbname=shyftdb sslmode=disable"
blockExplorerDb, _ := sql.Open("postgres", connStr)
blockchain, _ := NewBlockChain(db, blockExplorerDb, nil, params.AllEthashProtocolChanges, engine, vm.Config{})
// Create and inject the requested chain
if n == 0 {

View file

@ -24,7 +24,6 @@ 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"
@ -48,6 +47,9 @@ import (
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc"
// @shyft
"database/sql"
)
type LesServer interface {
@ -74,7 +76,7 @@ type Ethereum struct {
// DB interfaces
chainDb ethdb.Database // Block chain database
blockExplorerDb *leveldb.DB
blockExplorerDb *sql.DB
eventMux *event.TypeMux
engine consensus.Engine
@ -116,7 +118,9 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
// @NOTE:shyft instantiate BlockExplorerDB here
// @TODO: Create Genesis Block
blockExplorerDb, err := leveldb.OpenFile("./shyftData/geth/blockExplorerDb/", nil)
// @NOTE:shyft instantiate BlockExplorerDB here?
connStr := "user=postgres dbname=shyftdb sslmode=disable"
blockExplorerDb, err := sql.Open("postgres", connStr)
if err != nil {
return nil, err
}

View file

@ -0,0 +1 @@
CREATE DATABASE shyftdb

View file

@ -0,0 +1,16 @@
CREATE TABLE IF NOT EXISTS blocks (
hash text primary key,
coinbase text,
number bigint
);
CREATE TABLE IF NOT EXISTS txs (
from_addr text,
blockhash text,
amount bigint,
gasprice bigint,
gas numeric,
nonce numeric,
data bytea,
block text references blocks(hash)
);

View file

@ -0,0 +1 @@
psql -U postgres -d shyftdb -f create_tables.psql

View file

@ -0,0 +1 @@
psql -U postgres -f create_shyftdb.psql

View file

@ -11,6 +11,9 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"database/sql"
_ "github.com/lib/pq"
)
@ -48,29 +51,59 @@ type ShyftAccountEntry struct {
Txs []string
}
func WriteBlock(db *leveldb.DB, block *types.Block) error {
fmt.Println("+++++++++++++++++++++++++++ BLOCK NUMBER", block.Number())
fmt.Println("+++++++++++++++++++++++++++ # of TX", len(block.Transactions()))
leng := block.Transactions().Len()
var tx_strs = make([]string, leng)
hash := block.Header().Hash().Bytes()
//func WriteBlock(db *leveldb.DB, block *types.Block) error {
// fmt.Println("+++++++++++++++++++++++++++ BLOCK NUMBER", block.Number())
// fmt.Println("+++++++++++++++++++++++++++ # of TX", len(block.Transactions()))
// leng := block.Transactions().Len()
// var tx_strs = make([]string, leng)
// hash := block.Header().Hash().Bytes()
//
// buf := &bytes.Buffer{}
// gob.NewEncoder(buf).Encode(tx_strs)
// bs := buf.Bytes()
//
// key := append([]byte("bk-")[:], hash[:]...)
// if err := db.Put(key, bs, nil); err != nil {
// log.Crit("Failed to store block", "err", err)
// return nil // Do we want to force an exit here?
// }
// WriteMinerReward(db, block)
//
// if block.Transactions().Len() > 0 {
// for i, tx := range block.Transactions() {
// tx_strs[i] = WriteTransactions(db, tx, block.Header().Hash())
// }
// }
buf := &bytes.Buffer{}
gob.NewEncoder(buf).Encode(tx_strs)
bs := buf.Bytes()
func WriteBlock(sqldb *sql.DB, block *types.Block) error {
key := append([]byte("bk-")[:], hash[:]...)
if err := db.Put(key, bs, nil); err != nil {
log.Crit("Failed to store block", "err", err)
return nil // Do we want to force an exit here?
}
WriteMinerReward(db, block)
//hash := block.Header().Hash().Bytes()
coinbase := block.Header().Coinbase.String()
number := block.Header().Number.String()
// if block.Transactions().Len() > 0 {
// for i, tx := range block.Transactions() {
// tx_strs[i] = WriteTransactions(db, tx, block.Header().Hash())
// //tx_bytes[i] = tx.Hash().Bytes()
// }
// }
//connStr := "user=postgres dbname=shyftdb sslmode=disable"
//sqldb, err := sql.Open("postgres", connStr)
//if merr := sqldb.Ping(); merr != nil {
// fmt.Println("ping ERROR")
// fmt.Println(merr)
//}
//sqldb.Exec("INSERT INTO block(hash, miner) VALUES ($1)", block)
//qerr := sqldb.QueryRow(`INSERT INTO block(hash, miner) VALUES('bark', 'willow')`).Scan(&fun)
res, qerr := sqldb.Exec(`INSERT INTO blocks(hash, coinbase, number) VALUES(($1), ($2), ($3))`, block.Header().Hash().Hex(), coinbase, number) //.Scan(&fun)
fmt.Println("insert ERROR")
fmt.Println(qerr)
fmt.Println(res)
fmt.Println(number)
if block.Transactions().Len() > 0 {
for i, tx := range block.Transactions() {
tx_strs[i] = WriteTransactions(db, tx, block.Header().Hash())
}
}
return nil
}