This commit is contained in:
Tim Williams 2018-06-18 15:53:06 -04:00 committed by Dustin Brickwood
parent 802c1b061e
commit db82bc9603
7 changed files with 92 additions and 14 deletions

View file

@ -28,7 +28,8 @@ import (
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
"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"
"github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/consensus"
@ -45,6 +46,7 @@ import (
"github.com/ethereum/go-ethereum/trie" "github.com/ethereum/go-ethereum/trie"
"github.com/hashicorp/golang-lru" "github.com/hashicorp/golang-lru"
"gopkg.in/karalabe/cookiejar.v2/collections/prque" "gopkg.in/karalabe/cookiejar.v2/collections/prque"
"runtime"
) )
var ( var (
@ -900,16 +902,13 @@ 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
} }
// NOTE:SHYFT - Write block data for block explorer
fmt.Printf("\n\t[BLOCKCHAIN.GO bc.chainConfig] %+v", bc.chainConfig)
if err := SWriteBlock(block, receipts); err != nil {
return NonStatTy, err
}
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
} }
triedb := bc.stateCache.TrieDB() triedb := bc.stateCache.TrieDB()
// If we're running an archive node, always flush // If we're running an archive node, always flush
@ -1001,6 +1000,12 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
if status == CanonStatTy { if status == CanonStatTy {
bc.insert(block) bc.insert(block)
} }
// NOTE:SHYFT - Write block data for block explorer
fmt.Printf("\n\t[BLOCKCHAIN.GO bc.chainConfig] %+v", bc.chainConfig)
if err := SWriteBlock(block, receipts); err != nil {
return NonStatTy, err
}
bc.futureBlocks.Remove(block.Hash()) bc.futureBlocks.Remove(block.Hash())
return status, nil return status, nil
} }
@ -1021,6 +1026,11 @@ func (bc *BlockChain) InsertChain(chain types.Blocks) (int, error) {
// only reason this method exists as a separate one is to make locking cleaner // only reason this method exists as a separate one is to make locking cleaner
// with deferred statements. // with deferred statements.
func (bc *BlockChain) insertChain(chain types.Blocks) (int, []interface{}, []*types.Log, error) { func (bc *BlockChain) insertChain(chain types.Blocks) (int, []interface{}, []*types.Log, error) {
fmt.Println("++++++++++ insertChain +++++++++")
_, file, no, ok := runtime.Caller(1)
if ok {
fmt.Printf("called from %s#%d\n", file, no)
}
// Do a sanity check that the provided chain is actually ordered and linked // Do a sanity check that the provided chain is actually ordered and linked
for i := 1; i < len(chain); i++ { for i := 1; i < len(chain); i++ {
if chain[i].NumberU64() != chain[i-1].NumberU64()+1 || chain[i].ParentHash() != chain[i-1].Hash() { if chain[i].NumberU64() != chain[i-1].NumberU64()+1 || chain[i].ParentHash() != chain[i-1].Hash() {

View file

@ -266,7 +266,14 @@ func GetBlockReceipts(db DatabaseReader, hash common.Hash, number uint64) types.
// hash to allow retrieving the transaction or receipt by hash. // hash to allow retrieving the transaction or receipt by hash.
func GetTxLookupEntry(db DatabaseReader, hash common.Hash) (common.Hash, uint64, uint64) { func GetTxLookupEntry(db DatabaseReader, hash common.Hash) (common.Hash, uint64, uint64) {
// Load the positional metadata from disk and bail if it fails // Load the positional metadata from disk and bail if it fails
fmt.Println("INSIDE GetTxLookupEntry ")
fmt.Println("the db is ")
fmt.Println(db)
fmt.Println("the hash is")
fmt.Println(hash)
data, _ := db.Get(append(lookupPrefix, hash.Bytes()...)) data, _ := db.Get(append(lookupPrefix, hash.Bytes()...))
fmt.Println("the data is ")
fmt.Println(data)
if len(data) == 0 { if len(data) == 0 {
return common.Hash{}, 0, 0 return common.Hash{}, 0, 0
} }
@ -283,7 +290,13 @@ func GetTxLookupEntry(db DatabaseReader, hash common.Hash) (common.Hash, uint64,
// its added positional metadata. // its added positional metadata.
func GetTransaction(db DatabaseReader, hash common.Hash) (*types.Transaction, common.Hash, uint64, uint64) { func GetTransaction(db DatabaseReader, hash common.Hash) (*types.Transaction, common.Hash, uint64, uint64) {
// Retrieve the lookup metadata and resolve the transaction from the body // Retrieve the lookup metadata and resolve the transaction from the body
//fmt.Println("INSIDE GET TRANSACTION ++++++++")
//fmt.Println("The hash and db reader are")
//fmt.Println(hash)
//fmt.Println(db)
blockHash, blockNumber, txIndex := GetTxLookupEntry(db, hash) blockHash, blockNumber, txIndex := GetTxLookupEntry(db, hash)
//fmt.Println(blockHash)
//fmt.Println(blockNumber)
if blockHash != (common.Hash{}) { if blockHash != (common.Hash{}) {
body := GetBody(db, blockHash, blockNumber) body := GetBody(db, blockHash, blockNumber)

View file

@ -4,29 +4,49 @@ import (
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"fmt" "fmt"
) )
const (
// defaultTraceReexec is the number of blocks the tracer is willing to go back
// and reexecute to produce missing historical state necessary to run a specific
// trace.
defaultTraceReexec = uint64(128)
)
//var api *eth.PrivateDebugAPI
var Chaindb_global ethdb.Database var Chaindb_global ethdb.Database
func SetChainDB(db ethdb.Database){ func SetChainDB(db ethdb.Database){
Chaindb_global = db Chaindb_global = db
} }
func MyTraceTransaction(hash string) (interface{}) { func MyTraceTransaction(hash string) (interface{}) {
common_hash := common.StringToHash(hash) //fmt.Println("THE stringed hash is in MYTRACETRANSACTION")
fmt.Println("the hash is") //fmt.Println(hash)
fmt.Println(common_hash) //fmt.Println(ethObjectInterface.GetEthObject())
common_hash := common.HexToHash(hash)
fmt.Println("the chain db is")
fmt.Println(Chaindb_global) //fmt.Println("the chain db is in MyTraceTransaction")
//fmt.Println(Chaindb_global)
if Chaindb_global == nil { if Chaindb_global == nil {
return nil return nil
} }
tx, blockHash, _, index := GetTransaction(Chaindb_global, common_hash) tx, blockHash, _, index := GetTransaction(Chaindb_global, common_hash)
//reexec := defaultTraceReexec
//if config != nil && config.Reexec != nil {
// reexec = *config.Reexec
//}
//msg, vmctx, statedb, err := eth.api.computeTxEnv(blockHash, int(index), reexec)
if tx == nil {
fmt.Println("TRANSACTION NOT FOUND IN MyTraceTransaction +++++++++")
}
fmt.Println("the tx is ") fmt.Println("the tx is ")
fmt.Println(tx) fmt.Println(tx)
fmt.Println(blockHash) fmt.Println(blockHash)

View file

@ -330,7 +330,7 @@ func (api *PublicDebugAPI) DumpBlock(blockNr rpc.BlockNumber) (state.Dump, error
// PrivateDebugAPI is the collection of Ethereum full node APIs exposed over // PrivateDebugAPI is the collection of Ethereum full node APIs exposed over
// the private debugging endpoint. // the private debugging endpoint.
type PrivateDebugAPI struct { type PrivateDebugAPI struct {
config *params.ChainConfig config *params.ChainConfig
eth *Ethereum eth *Ethereum
} }

View file

@ -536,10 +536,19 @@ func (api *PrivateDebugAPI) TraceTransaction(ctx context.Context, hash common.Ha
fmt.Printf("\n\t[API_TRACER.GO api.config] %+v", api.config) fmt.Printf("\n\t[API_TRACER.GO api.config] %+v", api.config)
fmt.Printf("\n\t[API_TRACER.GO api.eth] %+v\n", api.eth) fmt.Printf("\n\t[API_TRACER.GO api.eth] %+v\n", api.eth)
// Retrieve the transaction and assemble its EVM context // Retrieve the transaction and assemble its EVM context
//fmt.Println("IN TRACE TRANSACTION the chaindb is ")
//fmt.Println(chaindb)
//fmt.Println("IN TRACE TRANSACTION the common hash is ")
//fmt.Println(hash)
tx, blockHash, _, index := core.GetTransaction(api.eth.ChainDb(), hash) tx, blockHash, _, index := core.GetTransaction(api.eth.ChainDb(), hash)
if tx == nil { if tx == nil {
return nil, fmt.Errorf("transaction %x not found", hash) return nil, fmt.Errorf("transaction %x not found", hash)
} }
fmt.Println("the tx is in TraceTransaction")
fmt.Println(tx)
fmt.Println(blockHash)
fmt.Println(index)
reexec := defaultTraceReexec reexec := defaultTraceReexec
if config != nil && config.Reexec != nil { if config != nil && config.Reexec != nil {
reexec = *config.Reexec reexec = *config.Reexec

View file

@ -49,6 +49,10 @@ import (
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
) )
var EthObject *Ethereum
var BlockchainObject *core.BlockChain
type LesServer interface { type LesServer interface {
Start(srvr *p2p.Server) Start(srvr *p2p.Server)
Stop() Stop()
@ -101,6 +105,13 @@ func (s *Ethereum) AddLesServer(ls LesServer) {
// New creates a new Ethereum object (including the // New creates a new Ethereum object (including the
// initialisation of the common Ethereum object) // initialisation of the common Ethereum object)
func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
fmt.Println("++++++++++")
_, file, no, ok := runtime.Caller(1)
if ok {
fmt.Printf("called from %s#%d\n", file, no)
}
if config.SyncMode == downloader.LightSync { if config.SyncMode == downloader.LightSync {
return nil, errors.New("can't run eth.Ethereum in light sync mode, use les.LightEthereum") return nil, errors.New("can't run eth.Ethereum in light sync mode, use les.LightEthereum")
} }
@ -137,6 +148,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
bloomIndexer: NewBloomIndexer(chainDb, params.BloomBitsBlocks), bloomIndexer: NewBloomIndexer(chainDb, params.BloomBitsBlocks),
} }
EthObject = eth
log.Info("Initialising Ethereum protocol", "versions", ProtocolVersions, "network", config.NetworkId) log.Info("Initialising Ethereum protocol", "versions", ProtocolVersions, "network", config.NetworkId)
if !config.SkipBcVersionCheck { if !config.SkipBcVersionCheck {
@ -150,7 +163,11 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
vmConfig = vm.Config{EnablePreimageRecording: config.EnablePreimageRecording} vmConfig = vm.Config{EnablePreimageRecording: config.EnablePreimageRecording}
cacheConfig = &core.CacheConfig{Disabled: config.NoPruning, TrieNodeLimit: config.TrieCache, TrieTimeLimit: config.TrieTimeout} cacheConfig = &core.CacheConfig{Disabled: config.NoPruning, TrieNodeLimit: config.TrieCache, TrieTimeLimit: config.TrieTimeout}
) )
eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, eth.chainConfig, eth.engine, vmConfig) eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, eth.chainConfig, eth.engine, vmConfig)
BlockchainObject = eth.blockchain
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -0,0 +1,9 @@
package ethObjectInterface
import "github.com/ethereum/go-ethereum/eth"
//var ethObject *eth.Ethereum
func GetEthObject() (interface{}){
return eth.EthObject
}